auxio_64.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* auxio.c: Probing for the Sparc AUXIO register at boot time.
  3. *
  4. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  5. *
  6. * Refactoring for unified NCR/PCIO support 2002 Eric Brower (ebrower@usa.net)
  7. */
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/ioport.h>
  12. #include <linux/of_device.h>
  13. #include <asm/prom.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_rmw(u8 bits_on, u8 bits_off, int ebus)
  26. {
  27. if (auxio_register) {
  28. unsigned long flags;
  29. u8 regval, newval;
  30. spin_lock_irqsave(&auxio_lock, flags);
  31. regval = (ebus ?
  32. (u8) readl(auxio_register) :
  33. sbus_readb(auxio_register));
  34. newval = regval | bits_on;
  35. newval &= ~bits_off;
  36. if (!ebus)
  37. newval &= ~AUXIO_AUX1_MASK;
  38. if (ebus)
  39. writel((u32) newval, auxio_register);
  40. else
  41. sbus_writeb(newval, auxio_register);
  42. spin_unlock_irqrestore(&auxio_lock, flags);
  43. }
  44. }
  45. static void __auxio_set_bit(u8 bit, int on, int ebus)
  46. {
  47. u8 bits_on = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
  48. u8 bits_off = 0;
  49. if (!on) {
  50. u8 tmp = bits_off;
  51. bits_off = bits_on;
  52. bits_on = tmp;
  53. }
  54. __auxio_rmw(bits_on, bits_off, ebus);
  55. }
  56. void auxio_set_led(int on)
  57. {
  58. int ebus = auxio_devtype == AUXIO_TYPE_EBUS;
  59. u8 bit;
  60. bit = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
  61. __auxio_set_bit(bit, on, ebus);
  62. }
  63. EXPORT_SYMBOL(auxio_set_led);
  64. static void __auxio_sbus_set_lte(int on)
  65. {
  66. __auxio_set_bit(AUXIO_AUX1_LTE, on, 0);
  67. }
  68. void auxio_set_lte(int on)
  69. {
  70. switch(auxio_devtype) {
  71. case AUXIO_TYPE_SBUS:
  72. __auxio_sbus_set_lte(on);
  73. break;
  74. case AUXIO_TYPE_EBUS:
  75. /* FALL-THROUGH */
  76. default:
  77. break;
  78. }
  79. }
  80. EXPORT_SYMBOL(auxio_set_lte);
  81. static const struct of_device_id auxio_match[] = {
  82. {
  83. .name = "auxio",
  84. },
  85. {},
  86. };
  87. MODULE_DEVICE_TABLE(of, auxio_match);
  88. static int auxio_probe(struct platform_device *dev)
  89. {
  90. struct device_node *dp = dev->dev.of_node;
  91. unsigned long size;
  92. if (!strcmp(dp->parent->name, "ebus")) {
  93. auxio_devtype = AUXIO_TYPE_EBUS;
  94. size = sizeof(u32);
  95. } else if (!strcmp(dp->parent->name, "sbus")) {
  96. auxio_devtype = AUXIO_TYPE_SBUS;
  97. size = 1;
  98. } else {
  99. printk("auxio: Unknown parent bus type [%s]\n",
  100. dp->parent->name);
  101. return -ENODEV;
  102. }
  103. auxio_register = of_ioremap(&dev->resource[0], 0, size, "auxio");
  104. if (!auxio_register)
  105. return -ENODEV;
  106. printk(KERN_INFO "AUXIO: Found device at %s\n",
  107. dp->full_name);
  108. if (auxio_devtype == AUXIO_TYPE_EBUS)
  109. auxio_set_led(AUXIO_LED_ON);
  110. return 0;
  111. }
  112. static struct platform_driver auxio_driver = {
  113. .probe = auxio_probe,
  114. .driver = {
  115. .name = "auxio",
  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);