auxio_64.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. static void __auxio_sbus_set_lte(int on)
  63. {
  64. __auxio_set_bit(AUXIO_AUX1_LTE, on, 0);
  65. }
  66. void auxio_set_lte(int on)
  67. {
  68. switch(auxio_devtype) {
  69. case AUXIO_TYPE_SBUS:
  70. __auxio_sbus_set_lte(on);
  71. break;
  72. case AUXIO_TYPE_EBUS:
  73. /* FALL-THROUGH */
  74. default:
  75. break;
  76. }
  77. }
  78. static struct of_device_id __initdata auxio_match[] = {
  79. {
  80. .name = "auxio",
  81. },
  82. {},
  83. };
  84. MODULE_DEVICE_TABLE(of, auxio_match);
  85. static int __devinit auxio_probe(struct of_device *dev, const struct of_device_id *match)
  86. {
  87. struct device_node *dp = dev->node;
  88. unsigned long size;
  89. if (!strcmp(dp->parent->name, "ebus")) {
  90. auxio_devtype = AUXIO_TYPE_EBUS;
  91. size = sizeof(u32);
  92. } else if (!strcmp(dp->parent->name, "sbus")) {
  93. auxio_devtype = AUXIO_TYPE_SBUS;
  94. size = 1;
  95. } else {
  96. printk("auxio: Unknown parent bus type [%s]\n",
  97. dp->parent->name);
  98. return -ENODEV;
  99. }
  100. auxio_register = of_ioremap(&dev->resource[0], 0, size, "auxio");
  101. if (!auxio_register)
  102. return -ENODEV;
  103. printk(KERN_INFO "AUXIO: Found device at %s\n",
  104. dp->full_name);
  105. if (auxio_devtype == AUXIO_TYPE_EBUS)
  106. auxio_set_led(AUXIO_LED_ON);
  107. return 0;
  108. }
  109. static struct of_platform_driver auxio_driver = {
  110. .match_table = auxio_match,
  111. .probe = auxio_probe,
  112. .driver = {
  113. .name = "auxio",
  114. },
  115. };
  116. static int __init auxio_init(void)
  117. {
  118. return of_register_driver(&auxio_driver, &of_platform_bus_type);
  119. }
  120. /* Must be after subsys_initcall() so that busses are probed. Must
  121. * be before device_initcall() because things like the floppy driver
  122. * need to use the AUXIO register.
  123. */
  124. fs_initcall(auxio_init);