blob: 3efd3c5af6a910181c47ba0075d7a95ae036beaf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* auxio.c: Probing for the Sparc AUXIO register at boot time.
2 *
3 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
4 *
5 * Refactoring for unified NCR/PCIO support 2002 Eric Brower (ebrower@usa.net)
6 */
7
David S. Millerdda9beb2006-06-25 02:08:47 -07008#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/kernel.h>
10#include <linux/init.h>
11#include <linux/ioport.h>
Stephen Rothwell764f2572008-08-07 15:33:36 -070012#include <linux/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
David S. Millerf2ad06a2006-06-29 15:22:22 -070014#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/auxio.h>
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018void __iomem *auxio_register = NULL;
David S. Millerdda9beb2006-06-25 02:08:47 -070019EXPORT_SYMBOL(auxio_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21enum auxio_type {
22 AUXIO_TYPE_NODEV,
23 AUXIO_TYPE_SBUS,
24 AUXIO_TYPE_EBUS
25};
26
27static enum auxio_type auxio_devtype = AUXIO_TYPE_NODEV;
28static DEFINE_SPINLOCK(auxio_lock);
29
David S. Miller86821d12008-10-29 23:18:41 -070030static void __auxio_rmw(u8 bits_on, u8 bits_off, int ebus)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
32 if (auxio_register) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 unsigned long flags;
David S. Miller86821d12008-10-29 23:18:41 -070034 u8 regval, newval;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36 spin_lock_irqsave(&auxio_lock, flags);
37
David S. Miller86821d12008-10-29 23:18:41 -070038 regval = (ebus ?
39 (u8) readl(auxio_register) :
40 sbus_readb(auxio_register));
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 newval = regval | bits_on;
42 newval &= ~bits_off;
David S. Miller86821d12008-10-29 23:18:41 -070043 if (!ebus)
44 newval &= ~AUXIO_AUX1_MASK;
45 if (ebus)
46 writel((u32) newval, auxio_register);
47 else
48 sbus_writeb(newval, auxio_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50 spin_unlock_irqrestore(&auxio_lock, flags);
51 }
52}
53
David S. Miller86821d12008-10-29 23:18:41 -070054static void __auxio_set_bit(u8 bit, int on, int ebus)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
David S. Miller86821d12008-10-29 23:18:41 -070056 u8 bits_on = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
57 u8 bits_off = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
David S. Miller86821d12008-10-29 23:18:41 -070059 if (!on) {
60 u8 tmp = bits_off;
61 bits_off = bits_on;
62 bits_on = tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 }
David S. Miller86821d12008-10-29 23:18:41 -070064 __auxio_rmw(bits_on, bits_off, ebus);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
67void auxio_set_led(int on)
68{
David S. Miller86821d12008-10-29 23:18:41 -070069 int ebus = auxio_devtype == AUXIO_TYPE_EBUS;
70 u8 bit;
71
72 bit = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
73 __auxio_set_bit(bit, on, ebus);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
Sam Ravnborg917c3662009-01-08 16:58:20 -080075EXPORT_SYMBOL(auxio_set_led);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
David S. Miller86821d12008-10-29 23:18:41 -070077static void __auxio_sbus_set_lte(int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
David S. Miller86821d12008-10-29 23:18:41 -070079 __auxio_set_bit(AUXIO_AUX1_LTE, on, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
82void auxio_set_lte(int on)
83{
84 switch(auxio_devtype) {
85 case AUXIO_TYPE_SBUS:
86 __auxio_sbus_set_lte(on);
87 break;
88 case AUXIO_TYPE_EBUS:
89 /* FALL-THROUGH */
90 default:
91 break;
92 }
93}
Sam Ravnborg917c3662009-01-08 16:58:20 -080094EXPORT_SYMBOL(auxio_set_lte);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
David S. Millerfd098312008-08-31 01:23:17 -070096static struct of_device_id __initdata auxio_match[] = {
David S. Millerb5ba0742006-06-23 22:46:49 -070097 {
98 .name = "auxio",
99 },
100 {},
101};
102
103MODULE_DEVICE_TABLE(of, auxio_match);
104
Grant Likelycd4cd732010-07-22 16:04:30 -0600105static int __devinit auxio_probe(struct platform_device *dev,
106 const struct of_device_id *match)
David S. Millerb5ba0742006-06-23 22:46:49 -0700107{
Grant Likely61c7a082010-04-13 16:12:29 -0700108 struct device_node *dp = dev->dev.of_node;
David S. Miller36a59bd2006-06-29 14:36:35 -0700109 unsigned long size;
David S. Millerb5ba0742006-06-23 22:46:49 -0700110
David S. Miller36a59bd2006-06-29 14:36:35 -0700111 if (!strcmp(dp->parent->name, "ebus")) {
112 auxio_devtype = AUXIO_TYPE_EBUS;
113 size = sizeof(u32);
114 } else if (!strcmp(dp->parent->name, "sbus")) {
115 auxio_devtype = AUXIO_TYPE_SBUS;
116 size = 1;
117 } else {
118 printk("auxio: Unknown parent bus type [%s]\n",
119 dp->parent->name);
120 return -ENODEV;
121 }
122 auxio_register = of_ioremap(&dev->resource[0], 0, size, "auxio");
David S. Millerb5ba0742006-06-23 22:46:49 -0700123 if (!auxio_register)
124 return -ENODEV;
125
David S. Miller36a59bd2006-06-29 14:36:35 -0700126 printk(KERN_INFO "AUXIO: Found device at %s\n",
127 dp->full_name);
David S. Millerb5ba0742006-06-23 22:46:49 -0700128
David S. Miller36a59bd2006-06-29 14:36:35 -0700129 if (auxio_devtype == AUXIO_TYPE_EBUS)
130 auxio_set_led(AUXIO_LED_ON);
David S. Millerb5ba0742006-06-23 22:46:49 -0700131
132 return 0;
133}
134
David S. Miller36a59bd2006-06-29 14:36:35 -0700135static struct of_platform_driver auxio_driver = {
David S. Miller36a59bd2006-06-29 14:36:35 -0700136 .probe = auxio_probe,
Grant Likely40182942010-04-13 16:13:02 -0700137 .driver = {
138 .name = "auxio",
139 .owner = THIS_MODULE,
140 .of_match_table = auxio_match,
Stephen Rothwella2cd1552007-10-10 23:27:34 -0700141 },
David S. Millerb5ba0742006-06-23 22:46:49 -0700142};
David S. Millerb5ba0742006-06-23 22:46:49 -0700143
David S. Miller36a59bd2006-06-29 14:36:35 -0700144static int __init auxio_init(void)
David S. Millerb5ba0742006-06-23 22:46:49 -0700145{
Grant Likely1ab1d632010-06-24 15:14:37 -0600146 return of_register_platform_driver(&auxio_driver);
David S. Millerb5ba0742006-06-23 22:46:49 -0700147}
148
149/* Must be after subsys_initcall() so that busses are probed. Must
150 * be before device_initcall() because things like the floppy driver
151 * need to use the AUXIO register.
152 */
David S. Miller36a59bd2006-06-29 14:36:35 -0700153fs_initcall(auxio_init);