auxio.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 struct of_device_id auxio_match[] = {
  96. {
  97. .name = "auxio",
  98. },
  99. {},
  100. };
  101. MODULE_DEVICE_TABLE(of, auxio_match);
  102. static int __devinit auxio_probe(struct of_device *dev, const struct of_device_id *match)
  103. {
  104. struct device_node *dp = dev->node;
  105. unsigned long size;
  106. if (!strcmp(dp->parent->name, "ebus")) {
  107. auxio_devtype = AUXIO_TYPE_EBUS;
  108. size = sizeof(u32);
  109. } else if (!strcmp(dp->parent->name, "sbus")) {
  110. auxio_devtype = AUXIO_TYPE_SBUS;
  111. size = 1;
  112. } else {
  113. printk("auxio: Unknown parent bus type [%s]\n",
  114. dp->parent->name);
  115. return -ENODEV;
  116. }
  117. auxio_register = of_ioremap(&dev->resource[0], 0, size, "auxio");
  118. if (!auxio_register)
  119. return -ENODEV;
  120. printk(KERN_INFO "AUXIO: Found device at %s\n",
  121. dp->full_name);
  122. if (auxio_devtype == AUXIO_TYPE_EBUS)
  123. auxio_set_led(AUXIO_LED_ON);
  124. return 0;
  125. }
  126. static struct of_platform_driver auxio_driver = {
  127. .name = "auxio",
  128. .match_table = auxio_match,
  129. .probe = auxio_probe,
  130. };
  131. static int __init auxio_init(void)
  132. {
  133. return of_register_driver(&auxio_driver, &of_bus_type);
  134. }
  135. /* Must be after subsys_initcall() so that busses are probed. Must
  136. * be before device_initcall() because things like the floppy driver
  137. * need to use the AUXIO register.
  138. */
  139. fs_initcall(auxio_init);