Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* 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 | ||
dda9beb4 | 8 | #include <linux/module.h> |
1da177e4 LT |
9 | #include <linux/kernel.h> |
10 | #include <linux/init.h> | |
11 | #include <linux/ioport.h> | |
764f2579 | 12 | #include <linux/of_device.h> |
1da177e4 | 13 | |
f2ad06a2 | 14 | #include <asm/prom.h> |
1da177e4 | 15 | #include <asm/io.h> |
1da177e4 LT |
16 | #include <asm/auxio.h> |
17 | ||
1da177e4 | 18 | void __iomem *auxio_register = NULL; |
dda9beb4 | 19 | EXPORT_SYMBOL(auxio_register); |
1da177e4 LT |
20 | |
21 | enum auxio_type { | |
22 | AUXIO_TYPE_NODEV, | |
23 | AUXIO_TYPE_SBUS, | |
24 | AUXIO_TYPE_EBUS | |
25 | }; | |
26 | ||
27 | static enum auxio_type auxio_devtype = AUXIO_TYPE_NODEV; | |
28 | static DEFINE_SPINLOCK(auxio_lock); | |
29 | ||
86821d18 | 30 | static void __auxio_rmw(u8 bits_on, u8 bits_off, int ebus) |
1da177e4 LT |
31 | { |
32 | if (auxio_register) { | |
1da177e4 | 33 | unsigned long flags; |
86821d18 | 34 | u8 regval, newval; |
1da177e4 LT |
35 | |
36 | spin_lock_irqsave(&auxio_lock, flags); | |
37 | ||
86821d18 DM |
38 | regval = (ebus ? |
39 | (u8) readl(auxio_register) : | |
40 | sbus_readb(auxio_register)); | |
1da177e4 LT |
41 | newval = regval | bits_on; |
42 | newval &= ~bits_off; | |
86821d18 DM |
43 | if (!ebus) |
44 | newval &= ~AUXIO_AUX1_MASK; | |
45 | if (ebus) | |
46 | writel((u32) newval, auxio_register); | |
47 | else | |
48 | sbus_writeb(newval, auxio_register); | |
1da177e4 LT |
49 | |
50 | spin_unlock_irqrestore(&auxio_lock, flags); | |
51 | } | |
52 | } | |
53 | ||
86821d18 | 54 | static void __auxio_set_bit(u8 bit, int on, int ebus) |
1da177e4 | 55 | { |
86821d18 DM |
56 | u8 bits_on = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED); |
57 | u8 bits_off = 0; | |
1da177e4 | 58 | |
86821d18 DM |
59 | if (!on) { |
60 | u8 tmp = bits_off; | |
61 | bits_off = bits_on; | |
62 | bits_on = tmp; | |
1da177e4 | 63 | } |
86821d18 | 64 | __auxio_rmw(bits_on, bits_off, ebus); |
1da177e4 LT |
65 | } |
66 | ||
67 | void auxio_set_led(int on) | |
68 | { | |
86821d18 DM |
69 | 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); | |
1da177e4 | 74 | } |
917c3660 | 75 | EXPORT_SYMBOL(auxio_set_led); |
1da177e4 | 76 | |
86821d18 | 77 | static void __auxio_sbus_set_lte(int on) |
1da177e4 | 78 | { |
86821d18 | 79 | __auxio_set_bit(AUXIO_AUX1_LTE, on, 0); |
1da177e4 LT |
80 | } |
81 | ||
82 | void 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 | } | |
917c3660 | 94 | EXPORT_SYMBOL(auxio_set_lte); |
1da177e4 | 95 | |
fd098316 | 96 | static struct of_device_id __initdata auxio_match[] = { |
b5ba0740 DM |
97 | { |
98 | .name = "auxio", | |
99 | }, | |
100 | {}, | |
101 | }; | |
102 | ||
103 | MODULE_DEVICE_TABLE(of, auxio_match); | |
104 | ||
36a59bd8 | 105 | static int __devinit auxio_probe(struct of_device *dev, const struct of_device_id *match) |
b5ba0740 | 106 | { |
36a59bd8 DM |
107 | struct device_node *dp = dev->node; |
108 | unsigned long size; | |
109 | ||
110 | if (!strcmp(dp->parent->name, "ebus")) { | |
111 | auxio_devtype = AUXIO_TYPE_EBUS; | |
112 | size = sizeof(u32); | |
113 | } else if (!strcmp(dp->parent->name, "sbus")) { | |
114 | auxio_devtype = AUXIO_TYPE_SBUS; | |
115 | size = 1; | |
116 | } else { | |
117 | printk("auxio: Unknown parent bus type [%s]\n", | |
118 | dp->parent->name); | |
b5ba0740 | 119 | return -ENODEV; |
36a59bd8 DM |
120 | } |
121 | auxio_register = of_ioremap(&dev->resource[0], 0, size, "auxio"); | |
b5ba0740 DM |
122 | if (!auxio_register) |
123 | return -ENODEV; | |
124 | ||
36a59bd8 DM |
125 | printk(KERN_INFO "AUXIO: Found device at %s\n", |
126 | dp->full_name); | |
b5ba0740 | 127 | |
36a59bd8 DM |
128 | if (auxio_devtype == AUXIO_TYPE_EBUS) |
129 | auxio_set_led(AUXIO_LED_ON); | |
b5ba0740 DM |
130 | |
131 | return 0; | |
132 | } | |
133 | ||
36a59bd8 | 134 | static struct of_platform_driver auxio_driver = { |
b5ba0740 | 135 | .match_table = auxio_match, |
36a59bd8 | 136 | .probe = auxio_probe, |
a2cd1558 SR |
137 | .driver = { |
138 | .name = "auxio", | |
139 | }, | |
b5ba0740 | 140 | }; |
b5ba0740 | 141 | |
36a59bd8 | 142 | static int __init auxio_init(void) |
b5ba0740 | 143 | { |
37b7754a | 144 | return of_register_driver(&auxio_driver, &of_platform_bus_type); |
1da177e4 | 145 | } |
b5ba0740 DM |
146 | |
147 | /* Must be after subsys_initcall() so that busses are probed. Must | |
148 | * be before device_initcall() because things like the floppy driver | |
149 | * need to use the AUXIO register. | |
150 | */ | |
36a59bd8 | 151 | fs_initcall(auxio_init); |