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