auxio.c 3.6 KB

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