auxio.c 3.4 KB

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