]> err.no Git - linux-2.6/blob - arch/sparc64/kernel/auxio.c
[SPARC64] auxio: Convert to pure of_device driver.
[linux-2.6] / arch / sparc64 / kernel / auxio.c
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
8 #include <linux/config.h>
9 #include <linux/module.h>
10 #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
20 void __iomem *auxio_register = NULL;
21 EXPORT_SYMBOL(auxio_register);
22
23 enum auxio_type {
24         AUXIO_TYPE_NODEV,
25         AUXIO_TYPE_SBUS,
26         AUXIO_TYPE_EBUS
27 };
28
29 static enum auxio_type auxio_devtype = AUXIO_TYPE_NODEV;
30 static DEFINE_SPINLOCK(auxio_lock);
31
32 static 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
51 static 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
69 static 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
75 static 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
81 void 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
95 static 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
101 void 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
114 static struct of_device_id auxio_match[] = {
115         {
116                 .name = "auxio",
117         },
118         {},
119 };
120
121 MODULE_DEVICE_TABLE(of, auxio_match);
122
123 static int __devinit auxio_probe(struct of_device *dev, const struct of_device_id *match)
124 {
125         struct device_node *dp = dev->node;
126         unsigned long size;
127
128         if (!strcmp(dp->parent->name, "ebus")) {
129                 auxio_devtype = AUXIO_TYPE_EBUS;
130                 size = sizeof(u32);
131         } else if (!strcmp(dp->parent->name, "sbus")) {
132                 auxio_devtype = AUXIO_TYPE_SBUS;
133                 size = 1;
134         } else {
135                 printk("auxio: Unknown parent bus type [%s]\n",
136                        dp->parent->name);
137                 return -ENODEV;
138         }
139         auxio_register = of_ioremap(&dev->resource[0], 0, size, "auxio");
140         if (!auxio_register)
141                 return -ENODEV;
142
143         printk(KERN_INFO "AUXIO: Found device at %s\n",
144                dp->full_name);
145
146         if (auxio_devtype == AUXIO_TYPE_EBUS)
147                 auxio_set_led(AUXIO_LED_ON);
148
149         return 0;
150 }
151
152 static struct of_platform_driver auxio_driver = {
153         .name           = "auxio",
154         .match_table    = auxio_match,
155         .probe          = auxio_probe,
156 };
157
158 static int __init auxio_init(void)
159 {
160         return of_register_driver(&auxio_driver, &of_bus_type);
161 }
162
163 /* Must be after subsys_initcall() so that busses are probed.  Must
164  * be before device_initcall() because things like the floppy driver
165  * need to use the AUXIO register.
166  */
167 fs_initcall(auxio_init);