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