1// SPDX-License-Identifier: GPL-2.0
2/* auxio.c: Probing for the Sparc AUXIO register at boot time.
3 *
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
5 *
6 * Refactoring for unified NCR/PCIO support 2002 Eric Brower (ebrower@usa.net)
7 */
8
9#include <linux/module.h>
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/ioport.h>
13#include <linux/of.h>
14#include <linux/platform_device.h>
15
16#include <asm/prom.h>
17#include <asm/io.h>
18#include <asm/auxio.h>
19
20void __iomem *auxio_register = NULL;
21EXPORT_SYMBOL(auxio_register);
22
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_rmw(u8 bits_on, u8 bits_off, int ebus)
33{
34 if (auxio_register) {
35 unsigned long flags;
36 u8 regval, newval;
37
38 spin_lock_irqsave(&auxio_lock, flags);
39
40 regval = (ebus ?
41 (u8) readl(addr: auxio_register) :
42 sbus_readb(auxio_register));
43 newval = regval | bits_on;
44 newval &= ~bits_off;
45 if (!ebus)
46 newval &= ~AUXIO_AUX1_MASK;
47 if (ebus)
48 writel(val: (u32) newval, addr: auxio_register);
49 else
50 sbus_writeb(newval, auxio_register);
51
52 spin_unlock_irqrestore(lock: &auxio_lock, flags);
53 }
54}
55
56static void __auxio_set_bit(u8 bit, int on, int ebus)
57{
58 u8 bits_on = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
59 u8 bits_off = 0;
60
61 if (!on) {
62 u8 tmp = bits_off;
63 bits_off = bits_on;
64 bits_on = tmp;
65 }
66 __auxio_rmw(bits_on, bits_off, ebus);
67}
68
69void auxio_set_led(int on)
70{
71 int ebus = auxio_devtype == AUXIO_TYPE_EBUS;
72 u8 bit;
73
74 bit = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
75 __auxio_set_bit(bit, on, ebus);
76}
77EXPORT_SYMBOL(auxio_set_led);
78
79static void __auxio_sbus_set_lte(int on)
80{
81 __auxio_set_bit(bit: AUXIO_AUX1_LTE, on, ebus: 0);
82}
83
84void auxio_set_lte(int on)
85{
86 switch(auxio_devtype) {
87 case AUXIO_TYPE_SBUS:
88 __auxio_sbus_set_lte(on);
89 break;
90 case AUXIO_TYPE_EBUS:
91 default:
92 break;
93 }
94}
95EXPORT_SYMBOL(auxio_set_lte);
96
97static const struct of_device_id auxio_match[] = {
98 {
99 .name = "auxio",
100 },
101 {},
102};
103
104MODULE_DEVICE_TABLE(of, auxio_match);
105
106static int auxio_probe(struct platform_device *dev)
107{
108 struct device_node *dp = dev->dev.of_node;
109 unsigned long size;
110
111 if (of_node_name_eq(np: dp->parent, name: "ebus")) {
112 auxio_devtype = AUXIO_TYPE_EBUS;
113 size = sizeof(u32);
114 } else if (of_node_name_eq(np: dp->parent, name: "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;
121 }
122 auxio_register = of_ioremap(&dev->resource[0], 0, size, "auxio");
123 if (!auxio_register)
124 return -ENODEV;
125
126 printk(KERN_INFO "AUXIO: Found device at %pOF\n", dp);
127
128 if (auxio_devtype == AUXIO_TYPE_EBUS)
129 auxio_set_led(AUXIO_LED_ON);
130
131 return 0;
132}
133
134static struct platform_driver auxio_driver = {
135 .probe = auxio_probe,
136 .driver = {
137 .name = "auxio",
138 .of_match_table = auxio_match,
139 },
140};
141
142static int __init auxio_init(void)
143{
144 return platform_driver_register(&auxio_driver);
145}
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 */
151fs_initcall(auxio_init);
152

source code of linux/arch/sparc/kernel/auxio_64.c