auxio.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/ioport.h>
  12. #include <asm/oplib.h>
  13. #include <asm/io.h>
  14. #include <asm/sbus.h>
  15. #include <asm/ebus.h>
  16. #include <asm/auxio.h>
  17. void __iomem *auxio_register = NULL;
  18. EXPORT_SYMBOL(auxio_register);
  19. enum auxio_type {
  20. AUXIO_TYPE_NODEV,
  21. AUXIO_TYPE_SBUS,
  22. AUXIO_TYPE_EBUS
  23. };
  24. static enum auxio_type auxio_devtype = AUXIO_TYPE_NODEV;
  25. static DEFINE_SPINLOCK(auxio_lock);
  26. static void __auxio_sbus_set(u8 bits_on, u8 bits_off)
  27. {
  28. if (auxio_register) {
  29. unsigned char regval;
  30. unsigned long flags;
  31. unsigned char newval;
  32. spin_lock_irqsave(&auxio_lock, flags);
  33. regval = sbus_readb(auxio_register);
  34. newval = regval | bits_on;
  35. newval &= ~bits_off;
  36. newval &= ~AUXIO_AUX1_MASK;
  37. sbus_writeb(newval, auxio_register);
  38. spin_unlock_irqrestore(&auxio_lock, flags);
  39. }
  40. }
  41. static void __auxio_ebus_set(u8 bits_on, u8 bits_off)
  42. {
  43. if (auxio_register) {
  44. unsigned char regval;
  45. unsigned long flags;
  46. unsigned char newval;
  47. spin_lock_irqsave(&auxio_lock, flags);
  48. regval = (u8)readl(auxio_register);
  49. newval = regval | bits_on;
  50. newval &= ~bits_off;
  51. writel((u32)newval, auxio_register);
  52. spin_unlock_irqrestore(&auxio_lock, flags);
  53. }
  54. }
  55. static inline void __auxio_ebus_set_led(int on)
  56. {
  57. (on) ? __auxio_ebus_set(AUXIO_PCIO_LED, 0) :
  58. __auxio_ebus_set(0, AUXIO_PCIO_LED) ;
  59. }
  60. static inline void __auxio_sbus_set_led(int on)
  61. {
  62. (on) ? __auxio_sbus_set(AUXIO_AUX1_LED, 0) :
  63. __auxio_sbus_set(0, AUXIO_AUX1_LED) ;
  64. }
  65. void auxio_set_led(int on)
  66. {
  67. switch(auxio_devtype) {
  68. case AUXIO_TYPE_SBUS:
  69. __auxio_sbus_set_led(on);
  70. break;
  71. case AUXIO_TYPE_EBUS:
  72. __auxio_ebus_set_led(on);
  73. break;
  74. default:
  75. break;
  76. }
  77. }
  78. static inline void __auxio_sbus_set_lte(int on)
  79. {
  80. (on) ? __auxio_sbus_set(AUXIO_AUX1_LTE, 0) :
  81. __auxio_sbus_set(0, AUXIO_AUX1_LTE) ;
  82. }
  83. void auxio_set_lte(int on)
  84. {
  85. switch(auxio_devtype) {
  86. case AUXIO_TYPE_SBUS:
  87. __auxio_sbus_set_lte(on);
  88. break;
  89. case AUXIO_TYPE_EBUS:
  90. /* FALL-THROUGH */
  91. default:
  92. break;
  93. }
  94. }
  95. static void __devinit auxio_report_dev(struct device_node *dp)
  96. {
  97. printk(KERN_INFO "AUXIO: Found device at %s\n",
  98. dp->full_name);
  99. }
  100. static struct of_device_id auxio_match[] = {
  101. {
  102. .name = "auxio",
  103. },
  104. {},
  105. };
  106. MODULE_DEVICE_TABLE(of, auxio_match);
  107. #ifdef CONFIG_SBUS
  108. static int __devinit auxio_sbus_probe(struct of_device *dev, const struct of_device_id *match)
  109. {
  110. struct sbus_dev *sdev = to_sbus_device(&dev->dev);
  111. auxio_devtype = AUXIO_TYPE_SBUS;
  112. auxio_register = sbus_ioremap(&sdev->resource[0], 0,
  113. sdev->reg_addrs[0].reg_size,
  114. "auxiliaryIO");
  115. if (!auxio_register)
  116. return -ENODEV;
  117. auxio_report_dev(dev->node);
  118. return 0;
  119. }
  120. static struct of_platform_driver auxio_sbus_driver = {
  121. .name = "auxio",
  122. .match_table = auxio_match,
  123. .probe = auxio_sbus_probe,
  124. };
  125. #endif
  126. #ifdef CONFIG_PCI
  127. static int __devinit auxio_ebus_probe(struct of_device *dev, const struct of_device_id *match)
  128. {
  129. struct linux_ebus_device *edev = to_ebus_device(&dev->dev);
  130. auxio_devtype = AUXIO_TYPE_EBUS;
  131. auxio_register = ioremap(edev->resource[0].start, sizeof(u32));
  132. if (!auxio_register)
  133. return -ENODEV;
  134. auxio_report_dev(dev->node);
  135. auxio_set_led(AUXIO_LED_ON);
  136. return 0;
  137. }
  138. static struct of_platform_driver auxio_ebus_driver = {
  139. .name = "auxio",
  140. .match_table = auxio_match,
  141. .probe = auxio_ebus_probe,
  142. };
  143. #endif
  144. static int __init auxio_probe(void)
  145. {
  146. #ifdef CONFIG_SBUS
  147. of_register_driver(&auxio_sbus_driver, &sbus_bus_type);
  148. #endif
  149. #ifdef CONFIG_PCI
  150. of_register_driver(&auxio_ebus_driver, &ebus_bus_type);
  151. #endif
  152. return 0;
  153. }
  154. /* Must be after subsys_initcall() so that busses are probed. Must
  155. * be before device_initcall() because things like the floppy driver
  156. * need to use the AUXIO register.
  157. */
  158. fs_initcall(auxio_probe);