auxio_64.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 ([email protected])
  5. *
  6. * Refactoring for unified NCR/PCIO support 2002 Eric Brower ([email protected])
  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. 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 auxio_probe(struct platform_device *dev)
  88. {
  89. struct device_node *dp = dev->dev.of_node;
  90. unsigned long size;
  91. if (of_node_name_eq(dp->parent, "ebus")) {
  92. auxio_devtype = AUXIO_TYPE_EBUS;
  93. size = sizeof(u32);
  94. } else if (of_node_name_eq(dp->parent, "sbus")) {
  95. auxio_devtype = AUXIO_TYPE_SBUS;
  96. size = 1;
  97. } else {
  98. printk("auxio: Unknown parent bus type [%pOFn]\n",
  99. dp->parent);
  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 %pOF\n", dp);
  106. if (auxio_devtype == AUXIO_TYPE_EBUS)
  107. auxio_set_led(AUXIO_LED_ON);
  108. return 0;
  109. }
  110. static struct platform_driver auxio_driver = {
  111. .probe = auxio_probe,
  112. .driver = {
  113. .name = "auxio",
  114. .of_match_table = auxio_match,
  115. },
  116. };
  117. static int __init auxio_init(void)
  118. {
  119. return platform_driver_register(&auxio_driver);
  120. }
  121. /* Must be after subsys_initcall() so that busses are probed. Must
  122. * be before device_initcall() because things like the floppy driver
  123. * need to use the AUXIO register.
  124. */
  125. fs_initcall(auxio_init);