blob: c2c69c167d182456ec4ae1d93c6c3a6fed0b35c0 [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
8#include <linux/config.h>
David S. Millerdda9beb2006-06-25 02:08:47 -07009#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/ioport.h>
13
14#include <asm/oplib.h>
15#include <asm/io.h>
16#include <asm/sbus.h>
17#include <asm/ebus.h>
18#include <asm/auxio.h>
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020void __iomem *auxio_register = NULL;
David S. Millerdda9beb2006-06-25 02:08:47 -070021EXPORT_SYMBOL(auxio_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23enum auxio_type {
24 AUXIO_TYPE_NODEV,
25 AUXIO_TYPE_SBUS,
26 AUXIO_TYPE_EBUS
27};
28
29static enum auxio_type auxio_devtype = AUXIO_TYPE_NODEV;
30static DEFINE_SPINLOCK(auxio_lock);
31
32static void __auxio_sbus_set(u8 bits_on, u8 bits_off)
33{
34 if (auxio_register) {
35 unsigned char regval;
36 unsigned long flags;
37 unsigned char newval;
38
39 spin_lock_irqsave(&auxio_lock, flags);
40
41 regval = sbus_readb(auxio_register);
42 newval = regval | bits_on;
43 newval &= ~bits_off;
44 newval &= ~AUXIO_AUX1_MASK;
45 sbus_writeb(newval, auxio_register);
46
47 spin_unlock_irqrestore(&auxio_lock, flags);
48 }
49}
50
51static void __auxio_ebus_set(u8 bits_on, u8 bits_off)
52{
53 if (auxio_register) {
54 unsigned char regval;
55 unsigned long flags;
56 unsigned char newval;
57
58 spin_lock_irqsave(&auxio_lock, flags);
59
60 regval = (u8)readl(auxio_register);
61 newval = regval | bits_on;
62 newval &= ~bits_off;
63 writel((u32)newval, auxio_register);
64
65 spin_unlock_irqrestore(&auxio_lock, flags);
66 }
67}
68
69static inline void __auxio_ebus_set_led(int on)
70{
71 (on) ? __auxio_ebus_set(AUXIO_PCIO_LED, 0) :
72 __auxio_ebus_set(0, AUXIO_PCIO_LED) ;
73}
74
75static inline void __auxio_sbus_set_led(int on)
76{
77 (on) ? __auxio_sbus_set(AUXIO_AUX1_LED, 0) :
78 __auxio_sbus_set(0, AUXIO_AUX1_LED) ;
79}
80
81void auxio_set_led(int on)
82{
83 switch(auxio_devtype) {
84 case AUXIO_TYPE_SBUS:
85 __auxio_sbus_set_led(on);
86 break;
87 case AUXIO_TYPE_EBUS:
88 __auxio_ebus_set_led(on);
89 break;
90 default:
91 break;
92 }
93}
94
95static inline void __auxio_sbus_set_lte(int on)
96{
97 (on) ? __auxio_sbus_set(AUXIO_AUX1_LTE, 0) :
98 __auxio_sbus_set(0, AUXIO_AUX1_LTE) ;
99}
100
101void auxio_set_lte(int on)
102{
103 switch(auxio_devtype) {
104 case AUXIO_TYPE_SBUS:
105 __auxio_sbus_set_lte(on);
106 break;
107 case AUXIO_TYPE_EBUS:
108 /* FALL-THROUGH */
109 default:
110 break;
111 }
112}
113
David S. Millerb5ba0742006-06-23 22:46:49 -0700114static void __devinit auxio_report_dev(struct device_node *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
David S. Millerb5ba0742006-06-23 22:46:49 -0700116 printk(KERN_INFO "AUXIO: Found device at %s\n",
117 dp->full_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
David S. Millerb5ba0742006-06-23 22:46:49 -0700119
120static struct of_device_id auxio_match[] = {
121 {
122 .name = "auxio",
123 },
124 {},
125};
126
127MODULE_DEVICE_TABLE(of, auxio_match);
128
129#ifdef CONFIG_SBUS
130static int __devinit auxio_sbus_probe(struct of_device *dev, const struct of_device_id *match)
131{
132 struct sbus_dev *sdev = to_sbus_device(&dev->dev);
133
134 auxio_devtype = AUXIO_TYPE_SBUS;
135 auxio_register = sbus_ioremap(&sdev->resource[0], 0,
136 sdev->reg_addrs[0].reg_size,
137 "auxiliaryIO");
138 if (!auxio_register)
139 return -ENODEV;
140
141 auxio_report_dev(dev->node);
142 return 0;
143}
144
145static struct of_platform_driver auxio_sbus_driver = {
146 .name = "auxio",
147 .match_table = auxio_match,
148 .probe = auxio_sbus_probe,
149};
150#endif
151
152#ifdef CONFIG_PCI
153static int __devinit auxio_ebus_probe(struct of_device *dev, const struct of_device_id *match)
154{
155 struct linux_ebus_device *edev = to_ebus_device(&dev->dev);
156
157 auxio_devtype = AUXIO_TYPE_EBUS;
158 auxio_register = ioremap(edev->resource[0].start, sizeof(u32));
159 if (!auxio_register)
160 return -ENODEV;
161
162 auxio_report_dev(dev->node);
163
164 auxio_set_led(AUXIO_LED_ON);
165
166 return 0;
167}
168
169static struct of_platform_driver auxio_ebus_driver = {
170 .name = "auxio",
171 .match_table = auxio_match,
172 .probe = auxio_ebus_probe,
173};
174#endif
175
176static int __init auxio_probe(void)
177{
178#ifdef CONFIG_SBUS
179 of_register_driver(&auxio_sbus_driver, &sbus_bus_type);
180#endif
181#ifdef CONFIG_PCI
182 of_register_driver(&auxio_ebus_driver, &ebus_bus_type);
183#endif
184
185 return 0;
186}
187
188/* Must be after subsys_initcall() so that busses are probed. Must
189 * be before device_initcall() because things like the floppy driver
190 * need to use the AUXIO register.
191 */
192fs_initcall(auxio_probe);