Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
David S. Miller | dda9beb | 2006-06-25 02:08:47 -0700 | [diff] [blame] | 8 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/kernel.h> |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/ioport.h> |
Stephen Rothwell | 764f257 | 2008-08-07 15:33:36 -0700 | [diff] [blame] | 12 | #include <linux/of_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
David S. Miller | f2ad06a | 2006-06-29 15:22:22 -0700 | [diff] [blame] | 14 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/auxio.h> |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | void __iomem *auxio_register = NULL; |
David S. Miller | dda9beb | 2006-06-25 02:08:47 -0700 | [diff] [blame] | 19 | EXPORT_SYMBOL(auxio_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | enum auxio_type { |
| 22 | AUXIO_TYPE_NODEV, |
| 23 | AUXIO_TYPE_SBUS, |
| 24 | AUXIO_TYPE_EBUS |
| 25 | }; |
| 26 | |
| 27 | static enum auxio_type auxio_devtype = AUXIO_TYPE_NODEV; |
| 28 | static DEFINE_SPINLOCK(auxio_lock); |
| 29 | |
David S. Miller | 86821d1 | 2008-10-29 23:18:41 -0700 | [diff] [blame^] | 30 | static void __auxio_rmw(u8 bits_on, u8 bits_off, int ebus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | { |
| 32 | if (auxio_register) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | unsigned long flags; |
David S. Miller | 86821d1 | 2008-10-29 23:18:41 -0700 | [diff] [blame^] | 34 | u8 regval, newval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | spin_lock_irqsave(&auxio_lock, flags); |
| 37 | |
David S. Miller | 86821d1 | 2008-10-29 23:18:41 -0700 | [diff] [blame^] | 38 | regval = (ebus ? |
| 39 | (u8) readl(auxio_register) : |
| 40 | sbus_readb(auxio_register)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | newval = regval | bits_on; |
| 42 | newval &= ~bits_off; |
David S. Miller | 86821d1 | 2008-10-29 23:18:41 -0700 | [diff] [blame^] | 43 | if (!ebus) |
| 44 | newval &= ~AUXIO_AUX1_MASK; |
| 45 | if (ebus) |
| 46 | writel((u32) newval, auxio_register); |
| 47 | else |
| 48 | sbus_writeb(newval, auxio_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | spin_unlock_irqrestore(&auxio_lock, flags); |
| 51 | } |
| 52 | } |
| 53 | |
David S. Miller | 86821d1 | 2008-10-29 23:18:41 -0700 | [diff] [blame^] | 54 | static void __auxio_set_bit(u8 bit, int on, int ebus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
David S. Miller | 86821d1 | 2008-10-29 23:18:41 -0700 | [diff] [blame^] | 56 | u8 bits_on = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED); |
| 57 | u8 bits_off = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
David S. Miller | 86821d1 | 2008-10-29 23:18:41 -0700 | [diff] [blame^] | 59 | if (!on) { |
| 60 | u8 tmp = bits_off; |
| 61 | bits_off = bits_on; |
| 62 | bits_on = tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
David S. Miller | 86821d1 | 2008-10-29 23:18:41 -0700 | [diff] [blame^] | 64 | __auxio_rmw(bits_on, bits_off, ebus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void auxio_set_led(int on) |
| 68 | { |
David S. Miller | 86821d1 | 2008-10-29 23:18:41 -0700 | [diff] [blame^] | 69 | int ebus = auxio_devtype == AUXIO_TYPE_EBUS; |
| 70 | u8 bit; |
| 71 | |
| 72 | bit = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED); |
| 73 | __auxio_set_bit(bit, on, ebus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
David S. Miller | 86821d1 | 2008-10-29 23:18:41 -0700 | [diff] [blame^] | 76 | static void __auxio_sbus_set_lte(int on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
David S. Miller | 86821d1 | 2008-10-29 23:18:41 -0700 | [diff] [blame^] | 78 | __auxio_set_bit(AUXIO_AUX1_LTE, on, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void auxio_set_lte(int on) |
| 82 | { |
| 83 | switch(auxio_devtype) { |
| 84 | case AUXIO_TYPE_SBUS: |
| 85 | __auxio_sbus_set_lte(on); |
| 86 | break; |
| 87 | case AUXIO_TYPE_EBUS: |
| 88 | /* FALL-THROUGH */ |
| 89 | default: |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | |
David S. Miller | fd09831 | 2008-08-31 01:23:17 -0700 | [diff] [blame] | 94 | static struct of_device_id __initdata auxio_match[] = { |
David S. Miller | b5ba074 | 2006-06-23 22:46:49 -0700 | [diff] [blame] | 95 | { |
| 96 | .name = "auxio", |
| 97 | }, |
| 98 | {}, |
| 99 | }; |
| 100 | |
| 101 | MODULE_DEVICE_TABLE(of, auxio_match); |
| 102 | |
David S. Miller | 36a59bd | 2006-06-29 14:36:35 -0700 | [diff] [blame] | 103 | static int __devinit auxio_probe(struct of_device *dev, const struct of_device_id *match) |
David S. Miller | b5ba074 | 2006-06-23 22:46:49 -0700 | [diff] [blame] | 104 | { |
David S. Miller | 36a59bd | 2006-06-29 14:36:35 -0700 | [diff] [blame] | 105 | struct device_node *dp = dev->node; |
| 106 | unsigned long size; |
David S. Miller | b5ba074 | 2006-06-23 22:46:49 -0700 | [diff] [blame] | 107 | |
David S. Miller | 36a59bd | 2006-06-29 14:36:35 -0700 | [diff] [blame] | 108 | if (!strcmp(dp->parent->name, "ebus")) { |
| 109 | auxio_devtype = AUXIO_TYPE_EBUS; |
| 110 | size = sizeof(u32); |
| 111 | } else if (!strcmp(dp->parent->name, "sbus")) { |
| 112 | auxio_devtype = AUXIO_TYPE_SBUS; |
| 113 | size = 1; |
| 114 | } else { |
| 115 | printk("auxio: Unknown parent bus type [%s]\n", |
| 116 | dp->parent->name); |
| 117 | return -ENODEV; |
| 118 | } |
| 119 | auxio_register = of_ioremap(&dev->resource[0], 0, size, "auxio"); |
David S. Miller | b5ba074 | 2006-06-23 22:46:49 -0700 | [diff] [blame] | 120 | if (!auxio_register) |
| 121 | return -ENODEV; |
| 122 | |
David S. Miller | 36a59bd | 2006-06-29 14:36:35 -0700 | [diff] [blame] | 123 | printk(KERN_INFO "AUXIO: Found device at %s\n", |
| 124 | dp->full_name); |
David S. Miller | b5ba074 | 2006-06-23 22:46:49 -0700 | [diff] [blame] | 125 | |
David S. Miller | 36a59bd | 2006-06-29 14:36:35 -0700 | [diff] [blame] | 126 | if (auxio_devtype == AUXIO_TYPE_EBUS) |
| 127 | auxio_set_led(AUXIO_LED_ON); |
David S. Miller | b5ba074 | 2006-06-23 22:46:49 -0700 | [diff] [blame] | 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
David S. Miller | 36a59bd | 2006-06-29 14:36:35 -0700 | [diff] [blame] | 132 | static struct of_platform_driver auxio_driver = { |
David S. Miller | b5ba074 | 2006-06-23 22:46:49 -0700 | [diff] [blame] | 133 | .match_table = auxio_match, |
David S. Miller | 36a59bd | 2006-06-29 14:36:35 -0700 | [diff] [blame] | 134 | .probe = auxio_probe, |
Stephen Rothwell | a2cd155 | 2007-10-10 23:27:34 -0700 | [diff] [blame] | 135 | .driver = { |
| 136 | .name = "auxio", |
| 137 | }, |
David S. Miller | b5ba074 | 2006-06-23 22:46:49 -0700 | [diff] [blame] | 138 | }; |
David S. Miller | b5ba074 | 2006-06-23 22:46:49 -0700 | [diff] [blame] | 139 | |
David S. Miller | 36a59bd | 2006-06-29 14:36:35 -0700 | [diff] [blame] | 140 | static int __init auxio_init(void) |
David S. Miller | b5ba074 | 2006-06-23 22:46:49 -0700 | [diff] [blame] | 141 | { |
Stephen Rothwell | 37b7754 | 2007-04-30 17:43:56 +1000 | [diff] [blame] | 142 | return of_register_driver(&auxio_driver, &of_platform_bus_type); |
David S. Miller | b5ba074 | 2006-06-23 22:46:49 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /* Must be after subsys_initcall() so that busses are probed. Must |
| 146 | * be before device_initcall() because things like the floppy driver |
| 147 | * need to use the AUXIO register. |
| 148 | */ |
David S. Miller | 36a59bd | 2006-06-29 14:36:35 -0700 | [diff] [blame] | 149 | fs_initcall(auxio_init); |