auxio_64.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 <linux/of_device.h>
  12. #include <asm/prom.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_rmw(u8 bits_on, u8 bits_off, int ebus)
  25. {
  26. if (auxio_register) {
  27. unsigned long flags;
  28. u8 regval, newval;
  29. spin_lock_irqsave(&auxio_lock, flags);
  30. regval = (ebus ?
  31. (u8) readl(auxio_register) :
  32. sbus_readb(auxio_register));
  33. newval = regval | bits_on;
  34. newval &= ~bits_off;
  35. if (!ebus)
  36. newval &= ~AUXIO_AUX1_MASK;
  37. if (ebus)
  38. writel((u32) newval, auxio_register);
  39. else
  40. sbus_writeb(newval, auxio_register);
  41. spin_unlock_irqrestore(&auxio_lock, flags);
  42. }
  43. }
  44. static void __auxio_set_bit(u8 bit, int on, int ebus)
  45. {
  46. u8 bits_on = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
  47. u8 bits_off = 0;
  48. if (!on) {
  49. u8 tmp = bits_off;
  50. bits_off = bits_on;
  51. bits_on = tmp;
  52. }
  53. __auxio_rmw(bits_on, bits_off, ebus);
  54. }
  55. void auxio_set_led(int on)
  56. {
  57. int ebus = auxio_devtype == AUXIO_TYPE_EBUS;
  58. u8 bit;
  59. bit = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
  60. __auxio_set_bit(bit, on, ebus);
  61. }
  62. EXPORT_SYMBOL(auxio_set_led);
  63. static void __auxio_sbus_set_lte(int on)
  64. {
  65. __auxio_set_bit(AUXIO_AUX1_LTE, on, 0);
  66. }
  67. void auxio_set_lte(int on)
  68. {
  69. switch(auxio_devtype) {
  70. case AUXIO_TYPE_SBUS:
  71. __auxio_sbus_set_lte(on);
  72. break;
  73. case AUXIO_TYPE_EBUS:
  74. /* FALL-THROUGH */
  75. default:
  76. break;
  77. }
  78. }
  79. EXPORT_SYMBOL(auxio_set_lte);
  80. static const struct of_device_id auxio_match[] = {
  81. {
  82. .name = "auxio",
  83. },
  84. {},
  85. };
  86. MODULE_DEVICE_TABLE(of, auxio_match);
  87. static int __devinit auxio_probe(struct platform_device *dev)
  88. {
  89. struct device_node *dp = dev->dev.of_node;
  90. unsigned long size;
  91. if (!strcmp(dp->parent->name, "ebus")) {
  92. auxio_devtype = AUXIO_TYPE_EBUS;
  93. size = sizeof(u32);
  94. } else if (!strcmp(dp->parent->name, "sbus")) {
  95. auxio_devtype = AUXIO_TYPE_SBUS;
  96. size = 1;
  97. } else {
  98. printk("auxio: Unknown parent bus type [%s]\n",
  99. dp->parent->name);
  100. return -ENODEV;
  101. }
  102. auxio_register = of_ioremap(&dev->resource[0], 0, size, "auxio");
  103. if (!auxio_register)
  104. return -ENODEV;
  105. printk(KERN_INFO "AUXIO: Found device at %s\n",
  106. dp->full_name);
  107. if (auxio_devtype == AUXIO_TYPE_EBUS)
  108. auxio_set_led(AUXIO_LED_ON);
  109. return 0;
  110. }
  111. static struct platform_driver auxio_driver = {
  112. .probe = auxio_probe,
  113. .driver = {
  114. .name = "auxio",
  115. .owner = THIS_MODULE,
  116. .of_match_table = auxio_match,
  117. },
  118. };
  119. static int __init auxio_init(void)
  120. {
  121. return platform_driver_register(&auxio_driver);
  122. }
  123. /* Must be after subsys_initcall() so that busses are probed. Must
  124. * be before device_initcall() because things like the floppy driver
  125. * need to use the AUXIO register.
  126. */
  127. fs_initcall(auxio_init);