auxio_32.c 3.6 KB

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