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