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 | |
| 6 | #include <linux/stddef.h> |
| 7 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/spinlock.h> |
David S. Miller | 454eeb2 | 2008-08-27 04:05:35 -0700 | [diff] [blame] | 9 | #include <linux/of.h> |
| 10 | #include <linux/of_device.h> |
Paul Gortmaker | 7b64db6 | 2011-07-18 15:57:46 -0400 | [diff] [blame] | 11 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/oplib.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <asm/auxio.h> |
| 15 | #include <asm/string.h> /* memset(), Linux has no bzero() */ |
David Howells | d550bbd | 2012-03-28 18:30:03 +0100 | [diff] [blame] | 16 | #include <asm/cpu_type.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | /* Probe and map in the Auxiliary I/O register */ |
| 19 | |
| 20 | /* auxio_register is not static because it is referenced |
| 21 | * in entry.S::floppy_tdone |
| 22 | */ |
| 23 | void __iomem *auxio_register = NULL; |
| 24 | static DEFINE_SPINLOCK(auxio_lock); |
| 25 | |
| 26 | void __init auxio_probe(void) |
| 27 | { |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 28 | phandle node, auxio_nd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | struct linux_prom_registers auxregs[1]; |
| 30 | struct resource r; |
| 31 | |
| 32 | switch (sparc_cpu_model) { |
Kristoffer Glembo | c000c71272d | 2009-11-13 05:21:22 +0000 | [diff] [blame] | 33 | case sparc_leon: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | case sun4d: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | return; |
| 36 | default: |
| 37 | break; |
| 38 | } |
| 39 | node = prom_getchild(prom_root_node); |
| 40 | auxio_nd = prom_searchsiblings(node, "auxiliary-io"); |
| 41 | if(!auxio_nd) { |
| 42 | node = prom_searchsiblings(node, "obio"); |
| 43 | node = prom_getchild(node); |
| 44 | auxio_nd = prom_searchsiblings(node, "auxio"); |
| 45 | if(!auxio_nd) { |
| 46 | #ifdef CONFIG_PCI |
| 47 | /* There may be auxio on Ebus */ |
| 48 | return; |
| 49 | #else |
| 50 | if(prom_searchsiblings(node, "leds")) { |
| 51 | /* VME chassis sun4m machine, no auxio exists. */ |
| 52 | return; |
| 53 | } |
| 54 | prom_printf("Cannot find auxio node, cannot continue...\n"); |
| 55 | prom_halt(); |
| 56 | #endif |
| 57 | } |
| 58 | } |
| 59 | if(prom_getproperty(auxio_nd, "reg", (char *) auxregs, sizeof(auxregs)) <= 0) |
| 60 | return; |
| 61 | prom_apply_obio_ranges(auxregs, 0x1); |
| 62 | /* Map the register both read and write */ |
| 63 | r.flags = auxregs[0].which_io & 0xF; |
| 64 | r.start = auxregs[0].phys_addr; |
| 65 | r.end = auxregs[0].phys_addr + auxregs[0].reg_size - 1; |
David S. Miller | 454eeb2 | 2008-08-27 04:05:35 -0700 | [diff] [blame] | 66 | auxio_register = of_ioremap(&r, 0, auxregs[0].reg_size, "auxio"); |
David S. Miller | 6e54e95 | 2012-05-12 00:23:23 -0700 | [diff] [blame] | 67 | /* Fix the address on sun4m. */ |
| 68 | if ((((unsigned long) auxregs[0].phys_addr) & 3) == 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | auxio_register += (3 - ((unsigned long)auxio_register & 3)); |
| 70 | |
| 71 | set_auxio(AUXIO_LED, 0); |
| 72 | } |
| 73 | |
| 74 | unsigned char get_auxio(void) |
| 75 | { |
| 76 | if(auxio_register) |
| 77 | return sbus_readb(auxio_register); |
| 78 | return 0; |
| 79 | } |
Sam Ravnborg | 6943f3d | 2009-01-08 16:58:05 -0800 | [diff] [blame] | 80 | EXPORT_SYMBOL(get_auxio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | void set_auxio(unsigned char bits_on, unsigned char bits_off) |
| 83 | { |
| 84 | unsigned char regval; |
| 85 | unsigned long flags; |
| 86 | spin_lock_irqsave(&auxio_lock, flags); |
David S. Miller | 6e54e95 | 2012-05-12 00:23:23 -0700 | [diff] [blame] | 87 | switch (sparc_cpu_model) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | case sun4m: |
| 89 | if(!auxio_register) |
Simon Arlott | d1a78c3 | 2007-05-11 13:51:23 -0700 | [diff] [blame] | 90 | break; /* VME chassis sun4m, no auxio. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | regval = sbus_readb(auxio_register); |
| 92 | sbus_writeb(((regval | bits_on) & ~bits_off) | AUXIO_ORMEIN4M, |
| 93 | auxio_register); |
| 94 | break; |
| 95 | case sun4d: |
| 96 | break; |
| 97 | default: |
| 98 | panic("Can't set AUXIO register on this machine."); |
Joe Perches | 6cb79b3 | 2011-06-03 14:45:23 +0000 | [diff] [blame] | 99 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | spin_unlock_irqrestore(&auxio_lock, flags); |
| 101 | } |
Sam Ravnborg | 6943f3d | 2009-01-08 16:58:05 -0800 | [diff] [blame] | 102 | EXPORT_SYMBOL(set_auxio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | /* sun4m power control register (AUXIO2) */ |
| 105 | |
| 106 | volatile unsigned char * auxio_power_register = NULL; |
| 107 | |
| 108 | void __init auxio_power_probe(void) |
| 109 | { |
| 110 | struct linux_prom_registers regs; |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 111 | phandle node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | struct resource r; |
| 113 | |
| 114 | /* Attempt to find the sun4m power control node. */ |
| 115 | node = prom_getchild(prom_root_node); |
| 116 | node = prom_searchsiblings(node, "obio"); |
| 117 | node = prom_getchild(node); |
| 118 | node = prom_searchsiblings(node, "power"); |
Andres Salomon | 4a3a255 | 2010-11-11 22:42:06 -0800 | [diff] [blame] | 119 | if (node == 0 || (s32)node == -1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | return; |
| 121 | |
| 122 | /* Map the power control register. */ |
| 123 | if (prom_getproperty(node, "reg", (char *)®s, sizeof(regs)) <= 0) |
| 124 | return; |
| 125 | prom_apply_obio_ranges(®s, 1); |
| 126 | memset(&r, 0, sizeof(r)); |
| 127 | r.flags = regs.which_io & 0xF; |
| 128 | r.start = regs.phys_addr; |
| 129 | r.end = regs.phys_addr + regs.reg_size - 1; |
David S. Miller | 454eeb2 | 2008-08-27 04:05:35 -0700 | [diff] [blame] | 130 | auxio_power_register = (unsigned char *) of_ioremap(&r, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | regs.reg_size, "auxpower"); |
| 132 | |
| 133 | /* Display a quick message on the console. */ |
| 134 | if (auxio_power_register) |
| 135 | printk(KERN_INFO "Power off control detected.\n"); |
| 136 | } |