auxio.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. static void __devinit auxio_report_dev(struct device_node *dp)
  95. {
  96. printk(KERN_INFO "AUXIO: Found device at %s\n",
  97. dp->full_name);
  98. }
  99. static struct of_device_id auxio_match[] = {
  100. {
  101. .name = "auxio",
  102. },
  103. {},
  104. };
  105. MODULE_DEVICE_TABLE(of, auxio_match);
  106. #ifdef CONFIG_SBUS
  107. static int __devinit auxio_sbus_probe(struct of_device *dev, const struct of_device_id *match)
  108. {
  109. struct sbus_dev *sdev = to_sbus_device(&dev->dev);
  110. auxio_devtype = AUXIO_TYPE_SBUS;
  111. auxio_register = sbus_ioremap(&sdev->resource[0], 0,
  112. sdev->reg_addrs[0].reg_size,
  113. "auxiliaryIO");
  114. if (!auxio_register)
  115. return -ENODEV;
  116. auxio_report_dev(dev->node);
  117. return 0;
  118. }
  119. static struct of_platform_driver auxio_sbus_driver = {
  120. .name = "auxio",
  121. .match_table = auxio_match,
  122. .probe = auxio_sbus_probe,
  123. };
  124. #endif
  125. #ifdef CONFIG_PCI
  126. static int __devinit auxio_ebus_probe(struct of_device *dev, const struct of_device_id *match)
  127. {
  128. struct linux_ebus_device *edev = to_ebus_device(&dev->dev);
  129. auxio_devtype = AUXIO_TYPE_EBUS;
  130. auxio_register = ioremap(edev->resource[0].start, sizeof(u32));
  131. if (!auxio_register)
  132. return -ENODEV;
  133. auxio_report_dev(dev->node);
  134. auxio_set_led(AUXIO_LED_ON);
  135. return 0;
  136. }
  137. static struct of_platform_driver auxio_ebus_driver = {
  138. .name = "auxio",
  139. .match_table = auxio_match,
  140. .probe = auxio_ebus_probe,
  141. };
  142. #endif
  143. static int __init auxio_probe(void)
  144. {
  145. #ifdef CONFIG_SBUS
  146. of_register_driver(&auxio_sbus_driver, &sbus_bus_type);
  147. #endif
  148. #ifdef CONFIG_PCI
  149. of_register_driver(&auxio_ebus_driver, &ebus_bus_type);
  150. #endif
  151. return 0;
  152. }
  153. /* Must be after subsys_initcall() so that busses are probed. Must
  154. * be before device_initcall() because things like the floppy driver
  155. * need to use the AUXIO register.
  156. */
  157. fs_initcall(auxio_probe);