auxio.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. * Refactoring for unified NCR/PCIO support 2002 Eric Brower (ebrower@usa.net)
  6. */
  7. #include <linux/config.h>
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/ioport.h>
  11. #include <asm/oplib.h>
  12. #include <asm/io.h>
  13. #include <asm/sbus.h>
  14. #include <asm/ebus.h>
  15. #include <asm/auxio.h>
  16. /* This cannot be static, as it is referenced in irq.c */
  17. void __iomem *auxio_register = NULL;
  18. enum auxio_type {
  19. AUXIO_TYPE_NODEV,
  20. AUXIO_TYPE_SBUS,
  21. AUXIO_TYPE_EBUS
  22. };
  23. static enum auxio_type auxio_devtype = AUXIO_TYPE_NODEV;
  24. static DEFINE_SPINLOCK(auxio_lock);
  25. static void __auxio_sbus_set(u8 bits_on, u8 bits_off)
  26. {
  27. if (auxio_register) {
  28. unsigned char regval;
  29. unsigned long flags;
  30. unsigned char newval;
  31. spin_lock_irqsave(&auxio_lock, flags);
  32. regval = sbus_readb(auxio_register);
  33. newval = regval | bits_on;
  34. newval &= ~bits_off;
  35. newval &= ~AUXIO_AUX1_MASK;
  36. sbus_writeb(newval, auxio_register);
  37. spin_unlock_irqrestore(&auxio_lock, flags);
  38. }
  39. }
  40. static void __auxio_ebus_set(u8 bits_on, u8 bits_off)
  41. {
  42. if (auxio_register) {
  43. unsigned char regval;
  44. unsigned long flags;
  45. unsigned char newval;
  46. spin_lock_irqsave(&auxio_lock, flags);
  47. regval = (u8)readl(auxio_register);
  48. newval = regval | bits_on;
  49. newval &= ~bits_off;
  50. writel((u32)newval, auxio_register);
  51. spin_unlock_irqrestore(&auxio_lock, flags);
  52. }
  53. }
  54. static inline void __auxio_ebus_set_led(int on)
  55. {
  56. (on) ? __auxio_ebus_set(AUXIO_PCIO_LED, 0) :
  57. __auxio_ebus_set(0, AUXIO_PCIO_LED) ;
  58. }
  59. static inline void __auxio_sbus_set_led(int on)
  60. {
  61. (on) ? __auxio_sbus_set(AUXIO_AUX1_LED, 0) :
  62. __auxio_sbus_set(0, AUXIO_AUX1_LED) ;
  63. }
  64. void auxio_set_led(int on)
  65. {
  66. switch(auxio_devtype) {
  67. case AUXIO_TYPE_SBUS:
  68. __auxio_sbus_set_led(on);
  69. break;
  70. case AUXIO_TYPE_EBUS:
  71. __auxio_ebus_set_led(on);
  72. break;
  73. default:
  74. break;
  75. }
  76. }
  77. static inline void __auxio_sbus_set_lte(int on)
  78. {
  79. (on) ? __auxio_sbus_set(AUXIO_AUX1_LTE, 0) :
  80. __auxio_sbus_set(0, AUXIO_AUX1_LTE) ;
  81. }
  82. void auxio_set_lte(int on)
  83. {
  84. switch(auxio_devtype) {
  85. case AUXIO_TYPE_SBUS:
  86. __auxio_sbus_set_lte(on);
  87. break;
  88. case AUXIO_TYPE_EBUS:
  89. /* FALL-THROUGH */
  90. default:
  91. break;
  92. }
  93. }
  94. void __init auxio_probe(void)
  95. {
  96. struct sbus_bus *sbus;
  97. struct sbus_dev *sdev = NULL;
  98. for_each_sbus(sbus) {
  99. for_each_sbusdev(sdev, sbus) {
  100. if(!strcmp(sdev->prom_name, "auxio"))
  101. goto found_sdev;
  102. }
  103. }
  104. found_sdev:
  105. if (sdev) {
  106. auxio_devtype = AUXIO_TYPE_SBUS;
  107. auxio_register = sbus_ioremap(&sdev->resource[0], 0,
  108. sdev->reg_addrs[0].reg_size,
  109. "auxiliaryIO");
  110. }
  111. #ifdef CONFIG_PCI
  112. else {
  113. struct linux_ebus *ebus;
  114. struct linux_ebus_device *edev = NULL;
  115. for_each_ebus(ebus) {
  116. for_each_ebusdev(edev, ebus) {
  117. if (!strcmp(edev->prom_name, "auxio"))
  118. goto ebus_done;
  119. }
  120. }
  121. ebus_done:
  122. if (edev) {
  123. auxio_devtype = AUXIO_TYPE_EBUS;
  124. auxio_register =
  125. ioremap(edev->resource[0].start, sizeof(u32));
  126. }
  127. }
  128. auxio_set_led(AUXIO_LED_ON);
  129. #endif
  130. }