treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / arch / sparc / kernel / auxio_64.c
blob4843f48bfe85f7f2543bde7d1670230ecefe2bc3
1 // SPDX-License-Identifier: GPL-2.0
2 /* auxio.c: Probing for the Sparc AUXIO register at boot time.
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
6 * Refactoring for unified NCR/PCIO support 2002 Eric Brower (ebrower@usa.net)
7 */
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/ioport.h>
13 #include <linux/of_device.h>
15 #include <asm/prom.h>
16 #include <asm/io.h>
17 #include <asm/auxio.h>
19 void __iomem *auxio_register = NULL;
20 EXPORT_SYMBOL(auxio_register);
22 enum auxio_type {
23 AUXIO_TYPE_NODEV,
24 AUXIO_TYPE_SBUS,
25 AUXIO_TYPE_EBUS
28 static enum auxio_type auxio_devtype = AUXIO_TYPE_NODEV;
29 static DEFINE_SPINLOCK(auxio_lock);
31 static void __auxio_rmw(u8 bits_on, u8 bits_off, int ebus)
33 if (auxio_register) {
34 unsigned long flags;
35 u8 regval, newval;
37 spin_lock_irqsave(&auxio_lock, flags);
39 regval = (ebus ?
40 (u8) readl(auxio_register) :
41 sbus_readb(auxio_register));
42 newval = regval | bits_on;
43 newval &= ~bits_off;
44 if (!ebus)
45 newval &= ~AUXIO_AUX1_MASK;
46 if (ebus)
47 writel((u32) newval, auxio_register);
48 else
49 sbus_writeb(newval, auxio_register);
51 spin_unlock_irqrestore(&auxio_lock, flags);
55 static void __auxio_set_bit(u8 bit, int on, int ebus)
57 u8 bits_on = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
58 u8 bits_off = 0;
60 if (!on) {
61 u8 tmp = bits_off;
62 bits_off = bits_on;
63 bits_on = tmp;
65 __auxio_rmw(bits_on, bits_off, ebus);
68 void auxio_set_led(int on)
70 int ebus = auxio_devtype == AUXIO_TYPE_EBUS;
71 u8 bit;
73 bit = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
74 __auxio_set_bit(bit, on, ebus);
76 EXPORT_SYMBOL(auxio_set_led);
78 static void __auxio_sbus_set_lte(int on)
80 __auxio_set_bit(AUXIO_AUX1_LTE, on, 0);
83 void auxio_set_lte(int on)
85 switch(auxio_devtype) {
86 case AUXIO_TYPE_SBUS:
87 __auxio_sbus_set_lte(on);
88 break;
89 case AUXIO_TYPE_EBUS:
90 /* FALL-THROUGH */
91 default:
92 break;
95 EXPORT_SYMBOL(auxio_set_lte);
97 static const struct of_device_id auxio_match[] = {
99 .name = "auxio",
104 MODULE_DEVICE_TABLE(of, auxio_match);
106 static int auxio_probe(struct platform_device *dev)
108 struct device_node *dp = dev->dev.of_node;
109 unsigned long size;
111 if (of_node_name_eq(dp->parent, "ebus")) {
112 auxio_devtype = AUXIO_TYPE_EBUS;
113 size = sizeof(u32);
114 } else if (of_node_name_eq(dp->parent, "sbus")) {
115 auxio_devtype = AUXIO_TYPE_SBUS;
116 size = 1;
117 } else {
118 printk("auxio: Unknown parent bus type [%pOFn]\n",
119 dp->parent);
120 return -ENODEV;
122 auxio_register = of_ioremap(&dev->resource[0], 0, size, "auxio");
123 if (!auxio_register)
124 return -ENODEV;
126 printk(KERN_INFO "AUXIO: Found device at %pOF\n", dp);
128 if (auxio_devtype == AUXIO_TYPE_EBUS)
129 auxio_set_led(AUXIO_LED_ON);
131 return 0;
134 static struct platform_driver auxio_driver = {
135 .probe = auxio_probe,
136 .driver = {
137 .name = "auxio",
138 .of_match_table = auxio_match,
142 static int __init auxio_init(void)
144 return platform_driver_register(&auxio_driver);
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.
151 fs_initcall(auxio_init);