auxio.c 3.4 KB

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