auxio_32.c 3.7 KB

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