0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/module.h>
0010 #include <linux/kernel.h>
0011 #include <linux/init.h>
0012 #include <linux/ioport.h>
0013 #include <linux/of_device.h>
0014
0015 #include <asm/prom.h>
0016 #include <asm/io.h>
0017 #include <asm/auxio.h>
0018
0019 void __iomem *auxio_register = NULL;
0020 EXPORT_SYMBOL(auxio_register);
0021
0022 enum auxio_type {
0023 AUXIO_TYPE_NODEV,
0024 AUXIO_TYPE_SBUS,
0025 AUXIO_TYPE_EBUS
0026 };
0027
0028 static enum auxio_type auxio_devtype = AUXIO_TYPE_NODEV;
0029 static DEFINE_SPINLOCK(auxio_lock);
0030
0031 static void __auxio_rmw(u8 bits_on, u8 bits_off, int ebus)
0032 {
0033 if (auxio_register) {
0034 unsigned long flags;
0035 u8 regval, newval;
0036
0037 spin_lock_irqsave(&auxio_lock, flags);
0038
0039 regval = (ebus ?
0040 (u8) readl(auxio_register) :
0041 sbus_readb(auxio_register));
0042 newval = regval | bits_on;
0043 newval &= ~bits_off;
0044 if (!ebus)
0045 newval &= ~AUXIO_AUX1_MASK;
0046 if (ebus)
0047 writel((u32) newval, auxio_register);
0048 else
0049 sbus_writeb(newval, auxio_register);
0050
0051 spin_unlock_irqrestore(&auxio_lock, flags);
0052 }
0053 }
0054
0055 static void __auxio_set_bit(u8 bit, int on, int ebus)
0056 {
0057 u8 bits_on = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
0058 u8 bits_off = 0;
0059
0060 if (!on) {
0061 u8 tmp = bits_off;
0062 bits_off = bits_on;
0063 bits_on = tmp;
0064 }
0065 __auxio_rmw(bits_on, bits_off, ebus);
0066 }
0067
0068 void auxio_set_led(int on)
0069 {
0070 int ebus = auxio_devtype == AUXIO_TYPE_EBUS;
0071 u8 bit;
0072
0073 bit = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
0074 __auxio_set_bit(bit, on, ebus);
0075 }
0076 EXPORT_SYMBOL(auxio_set_led);
0077
0078 static void __auxio_sbus_set_lte(int on)
0079 {
0080 __auxio_set_bit(AUXIO_AUX1_LTE, on, 0);
0081 }
0082
0083 void auxio_set_lte(int on)
0084 {
0085 switch(auxio_devtype) {
0086 case AUXIO_TYPE_SBUS:
0087 __auxio_sbus_set_lte(on);
0088 break;
0089 case AUXIO_TYPE_EBUS:
0090 default:
0091 break;
0092 }
0093 }
0094 EXPORT_SYMBOL(auxio_set_lte);
0095
0096 static const struct of_device_id auxio_match[] = {
0097 {
0098 .name = "auxio",
0099 },
0100 {},
0101 };
0102
0103 MODULE_DEVICE_TABLE(of, auxio_match);
0104
0105 static int auxio_probe(struct platform_device *dev)
0106 {
0107 struct device_node *dp = dev->dev.of_node;
0108 unsigned long size;
0109
0110 if (of_node_name_eq(dp->parent, "ebus")) {
0111 auxio_devtype = AUXIO_TYPE_EBUS;
0112 size = sizeof(u32);
0113 } else if (of_node_name_eq(dp->parent, "sbus")) {
0114 auxio_devtype = AUXIO_TYPE_SBUS;
0115 size = 1;
0116 } else {
0117 printk("auxio: Unknown parent bus type [%pOFn]\n",
0118 dp->parent);
0119 return -ENODEV;
0120 }
0121 auxio_register = of_ioremap(&dev->resource[0], 0, size, "auxio");
0122 if (!auxio_register)
0123 return -ENODEV;
0124
0125 printk(KERN_INFO "AUXIO: Found device at %pOF\n", dp);
0126
0127 if (auxio_devtype == AUXIO_TYPE_EBUS)
0128 auxio_set_led(AUXIO_LED_ON);
0129
0130 return 0;
0131 }
0132
0133 static struct platform_driver auxio_driver = {
0134 .probe = auxio_probe,
0135 .driver = {
0136 .name = "auxio",
0137 .of_match_table = auxio_match,
0138 },
0139 };
0140
0141 static int __init auxio_init(void)
0142 {
0143 return platform_driver_register(&auxio_driver);
0144 }
0145
0146
0147
0148
0149
0150 fs_initcall(auxio_init);