auxio.c 3.5 KB

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