wii.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * arch/powerpc/platforms/embedded6xx/wii.c
  4. *
  5. * Nintendo Wii board-specific support
  6. * Copyright (C) 2008-2009 The GameCube Linux Team
  7. * Copyright (C) 2008,2009 Albert Herranz
  8. */
  9. #define DRV_MODULE_NAME "wii"
  10. #define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/irq.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/of_address.h>
  16. #include <linux/of_platform.h>
  17. #include <asm/io.h>
  18. #include <asm/machdep.h>
  19. #include <asm/time.h>
  20. #include <asm/udbg.h>
  21. #include "flipper-pic.h"
  22. #include "hlwd-pic.h"
  23. #include "usbgecko_udbg.h"
  24. /* control block */
  25. #define HW_CTRL_COMPATIBLE "nintendo,hollywood-control"
  26. #define HW_CTRL_RESETS 0x94
  27. #define HW_CTRL_RESETS_SYS (1<<0)
  28. /* gpio */
  29. #define HW_GPIO_COMPATIBLE "nintendo,hollywood-gpio"
  30. #define HW_GPIO_BASE(idx) (idx * 0x20)
  31. #define HW_GPIO_OUT(idx) (HW_GPIO_BASE(idx) + 0)
  32. #define HW_GPIO_DIR(idx) (HW_GPIO_BASE(idx) + 4)
  33. #define HW_GPIO_OWNER (HW_GPIO_BASE(1) + 0x1c)
  34. #define HW_GPIO_SHUTDOWN (1<<1)
  35. #define HW_GPIO_SLOT_LED (1<<5)
  36. #define HW_GPIO_SENSOR_BAR (1<<8)
  37. static void __iomem *hw_ctrl;
  38. static void __iomem *hw_gpio;
  39. static void __noreturn wii_spin(void)
  40. {
  41. local_irq_disable();
  42. for (;;)
  43. cpu_relax();
  44. }
  45. static void __iomem *__init wii_ioremap_hw_regs(char *name, char *compatible)
  46. {
  47. void __iomem *hw_regs = NULL;
  48. struct device_node *np;
  49. struct resource res;
  50. int error = -ENODEV;
  51. np = of_find_compatible_node(NULL, NULL, compatible);
  52. if (!np) {
  53. pr_err("no compatible node found for %s\n", compatible);
  54. goto out;
  55. }
  56. error = of_address_to_resource(np, 0, &res);
  57. if (error) {
  58. pr_err("no valid reg found for %pOFn\n", np);
  59. goto out_put;
  60. }
  61. hw_regs = ioremap(res.start, resource_size(&res));
  62. if (hw_regs) {
  63. pr_info("%s at 0x%pa mapped to 0x%p\n", name,
  64. &res.start, hw_regs);
  65. }
  66. out_put:
  67. of_node_put(np);
  68. out:
  69. return hw_regs;
  70. }
  71. static void __init wii_setup_arch(void)
  72. {
  73. hw_ctrl = wii_ioremap_hw_regs("hw_ctrl", HW_CTRL_COMPATIBLE);
  74. hw_gpio = wii_ioremap_hw_regs("hw_gpio", HW_GPIO_COMPATIBLE);
  75. if (hw_gpio) {
  76. /* turn off the front blue led and IR light */
  77. clrbits32(hw_gpio + HW_GPIO_OUT(0),
  78. HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR);
  79. }
  80. }
  81. static void __noreturn wii_restart(char *cmd)
  82. {
  83. local_irq_disable();
  84. if (hw_ctrl) {
  85. /* clear the system reset pin to cause a reset */
  86. clrbits32(hw_ctrl + HW_CTRL_RESETS, HW_CTRL_RESETS_SYS);
  87. }
  88. wii_spin();
  89. }
  90. static void wii_power_off(void)
  91. {
  92. local_irq_disable();
  93. if (hw_gpio) {
  94. /*
  95. * set the owner of the shutdown pin to ARM, because it is
  96. * accessed through the registers for the ARM, below
  97. */
  98. clrbits32(hw_gpio + HW_GPIO_OWNER, HW_GPIO_SHUTDOWN);
  99. /* make sure that the poweroff GPIO is configured as output */
  100. setbits32(hw_gpio + HW_GPIO_DIR(1), HW_GPIO_SHUTDOWN);
  101. /* drive the poweroff GPIO high */
  102. setbits32(hw_gpio + HW_GPIO_OUT(1), HW_GPIO_SHUTDOWN);
  103. }
  104. wii_spin();
  105. }
  106. static void __noreturn wii_halt(void)
  107. {
  108. if (ppc_md.restart)
  109. ppc_md.restart(NULL);
  110. wii_spin();
  111. }
  112. static void __init wii_pic_probe(void)
  113. {
  114. flipper_pic_probe();
  115. hlwd_pic_probe();
  116. }
  117. static int __init wii_probe(void)
  118. {
  119. if (!of_machine_is_compatible("nintendo,wii"))
  120. return 0;
  121. pm_power_off = wii_power_off;
  122. ug_udbg_init();
  123. return 1;
  124. }
  125. static void wii_shutdown(void)
  126. {
  127. hlwd_quiesce();
  128. flipper_quiesce();
  129. }
  130. static const struct of_device_id wii_of_bus[] = {
  131. { .compatible = "nintendo,hollywood", },
  132. { },
  133. };
  134. static int __init wii_device_probe(void)
  135. {
  136. if (!machine_is(wii))
  137. return 0;
  138. of_platform_populate(NULL, wii_of_bus, NULL, NULL);
  139. return 0;
  140. }
  141. device_initcall(wii_device_probe);
  142. define_machine(wii) {
  143. .name = "wii",
  144. .probe = wii_probe,
  145. .setup_arch = wii_setup_arch,
  146. .restart = wii_restart,
  147. .halt = wii_halt,
  148. .init_IRQ = wii_pic_probe,
  149. .get_irq = flipper_pic_get_irq,
  150. .calibrate_decr = generic_calibrate_decr,
  151. .progress = udbg_progress,
  152. .machine_shutdown = wii_shutdown,
  153. };