auxio_32.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. #include <linux/stddef.h>
  7. #include <linux/init.h>
  8. #include <linux/spinlock.h>
  9. #include <linux/of.h>
  10. #include <linux/of_device.h>
  11. #include <linux/export.h>
  12. #include <asm/oplib.h>
  13. #include <asm/io.h>
  14. #include <asm/auxio.h>
  15. #include <asm/string.h> /* memset(), Linux has no bzero() */
  16. #include <asm/cpu_type.h>
  17. #include "kernel.h"
  18. /* Probe and map in the Auxiliary I/O register */
  19. /* auxio_register is not static because it is referenced
  20. * in entry.S::floppy_tdone
  21. */
  22. void __iomem *auxio_register = NULL;
  23. static DEFINE_SPINLOCK(auxio_lock);
  24. void __init auxio_probe(void)
  25. {
  26. phandle node, auxio_nd;
  27. struct linux_prom_registers auxregs[1];
  28. struct resource r;
  29. switch (sparc_cpu_model) {
  30. case sparc_leon:
  31. case sun4d:
  32. return;
  33. default:
  34. break;
  35. }
  36. node = prom_getchild(prom_root_node);
  37. auxio_nd = prom_searchsiblings(node, "auxiliary-io");
  38. if(!auxio_nd) {
  39. node = prom_searchsiblings(node, "obio");
  40. node = prom_getchild(node);
  41. auxio_nd = prom_searchsiblings(node, "auxio");
  42. if(!auxio_nd) {
  43. #ifdef CONFIG_PCI
  44. /* There may be auxio on Ebus */
  45. return;
  46. #else
  47. if(prom_searchsiblings(node, "leds")) {
  48. /* VME chassis sun4m machine, no auxio exists. */
  49. return;
  50. }
  51. prom_printf("Cannot find auxio node, cannot continue...\n");
  52. prom_halt();
  53. #endif
  54. }
  55. }
  56. if(prom_getproperty(auxio_nd, "reg", (char *) auxregs, sizeof(auxregs)) <= 0)
  57. return;
  58. prom_apply_obio_ranges(auxregs, 0x1);
  59. /* Map the register both read and write */
  60. r.flags = auxregs[0].which_io & 0xF;
  61. r.start = auxregs[0].phys_addr;
  62. r.end = auxregs[0].phys_addr + auxregs[0].reg_size - 1;
  63. auxio_register = of_ioremap(&r, 0, auxregs[0].reg_size, "auxio");
  64. /* Fix the address on sun4m. */
  65. if ((((unsigned long) auxregs[0].phys_addr) & 3) == 3)
  66. auxio_register += (3 - ((unsigned long)auxio_register & 3));
  67. set_auxio(AUXIO_LED, 0);
  68. }
  69. unsigned char get_auxio(void)
  70. {
  71. if(auxio_register)
  72. return sbus_readb(auxio_register);
  73. return 0;
  74. }
  75. EXPORT_SYMBOL(get_auxio);
  76. void set_auxio(unsigned char bits_on, unsigned char bits_off)
  77. {
  78. unsigned char regval;
  79. unsigned long flags;
  80. spin_lock_irqsave(&auxio_lock, flags);
  81. switch (sparc_cpu_model) {
  82. case sun4m:
  83. if(!auxio_register)
  84. break; /* VME chassis sun4m, no auxio. */
  85. regval = sbus_readb(auxio_register);
  86. sbus_writeb(((regval | bits_on) & ~bits_off) | AUXIO_ORMEIN4M,
  87. auxio_register);
  88. break;
  89. case sun4d:
  90. break;
  91. default:
  92. panic("Can't set AUXIO register on this machine.");
  93. }
  94. spin_unlock_irqrestore(&auxio_lock, flags);
  95. }
  96. EXPORT_SYMBOL(set_auxio);
  97. /* sun4m power control register (AUXIO2) */
  98. volatile u8 __iomem *auxio_power_register = NULL;
  99. void __init auxio_power_probe(void)
  100. {
  101. struct linux_prom_registers regs;
  102. phandle node;
  103. struct resource r;
  104. /* Attempt to find the sun4m power control node. */
  105. node = prom_getchild(prom_root_node);
  106. node = prom_searchsiblings(node, "obio");
  107. node = prom_getchild(node);
  108. node = prom_searchsiblings(node, "power");
  109. if (node == 0 || (s32)node == -1)
  110. return;
  111. /* Map the power control register. */
  112. if (prom_getproperty(node, "reg", (char *)&regs, sizeof(regs)) <= 0)
  113. return;
  114. prom_apply_obio_ranges(&regs, 1);
  115. memset(&r, 0, sizeof(r));
  116. r.flags = regs.which_io & 0xF;
  117. r.start = regs.phys_addr;
  118. r.end = regs.phys_addr + regs.reg_size - 1;
  119. auxio_power_register =
  120. (u8 __iomem *)of_ioremap(&r, 0, regs.reg_size, "auxpower");
  121. /* Display a quick message on the console. */
  122. if (auxio_power_register)
  123. printk(KERN_INFO "Power off control detected.\n");
  124. }