wii.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * arch/powerpc/platforms/embedded6xx/wii.c
  3. *
  4. * Nintendo Wii board-specific support
  5. * Copyright (C) 2008-2009 The GameCube Linux Team
  6. * Copyright (C) 2008,2009 Albert Herranz
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. */
  14. #define DRV_MODULE_NAME "wii"
  15. #define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/irq.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/of_platform.h>
  21. #include <linux/memblock.h>
  22. #include <mm/mmu_decl.h>
  23. #include <asm/io.h>
  24. #include <asm/machdep.h>
  25. #include <asm/prom.h>
  26. #include <asm/time.h>
  27. #include <asm/udbg.h>
  28. #include "flipper-pic.h"
  29. #include "hlwd-pic.h"
  30. #include "usbgecko_udbg.h"
  31. /* control block */
  32. #define HW_CTRL_COMPATIBLE "nintendo,hollywood-control"
  33. #define HW_CTRL_RESETS 0x94
  34. #define HW_CTRL_RESETS_SYS (1<<0)
  35. /* gpio */
  36. #define HW_GPIO_COMPATIBLE "nintendo,hollywood-gpio"
  37. #define HW_GPIO_BASE(idx) (idx * 0x20)
  38. #define HW_GPIO_OUT(idx) (HW_GPIO_BASE(idx) + 0)
  39. #define HW_GPIO_DIR(idx) (HW_GPIO_BASE(idx) + 4)
  40. #define HW_GPIO_OWNER (HW_GPIO_BASE(1) + 0x1c)
  41. #define HW_GPIO_SHUTDOWN (1<<1)
  42. #define HW_GPIO_SLOT_LED (1<<5)
  43. #define HW_GPIO_SENSOR_BAR (1<<8)
  44. static void __iomem *hw_ctrl;
  45. static void __iomem *hw_gpio;
  46. unsigned long wii_hole_start;
  47. unsigned long wii_hole_size;
  48. static int __init page_aligned(unsigned long x)
  49. {
  50. return !(x & (PAGE_SIZE-1));
  51. }
  52. void __init wii_memory_fixups(void)
  53. {
  54. struct memblock_region *p = memblock.memory.regions;
  55. BUG_ON(memblock.memory.cnt != 2);
  56. BUG_ON(!page_aligned(p[0].base) || !page_aligned(p[1].base));
  57. /* determine hole */
  58. wii_hole_start = ALIGN(p[0].base + p[0].size, PAGE_SIZE);
  59. wii_hole_size = p[1].base - wii_hole_start;
  60. }
  61. unsigned long __init wii_mmu_mapin_mem2(unsigned long top)
  62. {
  63. unsigned long delta, size, bl;
  64. unsigned long max_size = (256<<20);
  65. /* MEM2 64MB@0x10000000 */
  66. delta = wii_hole_start + wii_hole_size;
  67. size = top - delta;
  68. if (__map_without_bats)
  69. return delta;
  70. for (bl = 128<<10; bl < max_size; bl <<= 1) {
  71. if (bl * 2 > size)
  72. break;
  73. }
  74. setbat(4, PAGE_OFFSET+delta, delta, bl, PAGE_KERNEL_X);
  75. return delta + bl;
  76. }
  77. static void __noreturn wii_spin(void)
  78. {
  79. local_irq_disable();
  80. for (;;)
  81. cpu_relax();
  82. }
  83. static void __iomem *wii_ioremap_hw_regs(char *name, char *compatible)
  84. {
  85. void __iomem *hw_regs = NULL;
  86. struct device_node *np;
  87. struct resource res;
  88. int error = -ENODEV;
  89. np = of_find_compatible_node(NULL, NULL, compatible);
  90. if (!np) {
  91. pr_err("no compatible node found for %s\n", compatible);
  92. goto out;
  93. }
  94. error = of_address_to_resource(np, 0, &res);
  95. if (error) {
  96. pr_err("no valid reg found for %s\n", np->name);
  97. goto out_put;
  98. }
  99. hw_regs = ioremap(res.start, resource_size(&res));
  100. if (hw_regs) {
  101. pr_info("%s at 0x%08x mapped to 0x%p\n", name,
  102. res.start, hw_regs);
  103. }
  104. out_put:
  105. of_node_put(np);
  106. out:
  107. return hw_regs;
  108. }
  109. static void __init wii_setup_arch(void)
  110. {
  111. hw_ctrl = wii_ioremap_hw_regs("hw_ctrl", HW_CTRL_COMPATIBLE);
  112. hw_gpio = wii_ioremap_hw_regs("hw_gpio", HW_GPIO_COMPATIBLE);
  113. if (hw_gpio) {
  114. /* turn off the front blue led and IR light */
  115. clrbits32(hw_gpio + HW_GPIO_OUT(0),
  116. HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR);
  117. }
  118. }
  119. static void __noreturn wii_restart(char *cmd)
  120. {
  121. local_irq_disable();
  122. if (hw_ctrl) {
  123. /* clear the system reset pin to cause a reset */
  124. clrbits32(hw_ctrl + HW_CTRL_RESETS, HW_CTRL_RESETS_SYS);
  125. }
  126. wii_spin();
  127. }
  128. static void wii_power_off(void)
  129. {
  130. local_irq_disable();
  131. if (hw_gpio) {
  132. /*
  133. * set the owner of the shutdown pin to ARM, because it is
  134. * accessed through the registers for the ARM, below
  135. */
  136. clrbits32(hw_gpio + HW_GPIO_OWNER, HW_GPIO_SHUTDOWN);
  137. /* make sure that the poweroff GPIO is configured as output */
  138. setbits32(hw_gpio + HW_GPIO_DIR(1), HW_GPIO_SHUTDOWN);
  139. /* drive the poweroff GPIO high */
  140. setbits32(hw_gpio + HW_GPIO_OUT(1), HW_GPIO_SHUTDOWN);
  141. }
  142. wii_spin();
  143. }
  144. static void __noreturn wii_halt(void)
  145. {
  146. if (ppc_md.restart)
  147. ppc_md.restart(NULL);
  148. wii_spin();
  149. }
  150. static void __init wii_pic_probe(void)
  151. {
  152. flipper_pic_probe();
  153. hlwd_pic_probe();
  154. }
  155. static int __init wii_probe(void)
  156. {
  157. if (!of_machine_is_compatible("nintendo,wii"))
  158. return 0;
  159. pm_power_off = wii_power_off;
  160. ug_udbg_init();
  161. return 1;
  162. }
  163. static void wii_shutdown(void)
  164. {
  165. hlwd_quiesce();
  166. flipper_quiesce();
  167. }
  168. define_machine(wii) {
  169. .name = "wii",
  170. .probe = wii_probe,
  171. .setup_arch = wii_setup_arch,
  172. .restart = wii_restart,
  173. .halt = wii_halt,
  174. .init_IRQ = wii_pic_probe,
  175. .get_irq = flipper_pic_get_irq,
  176. .calibrate_decr = generic_calibrate_decr,
  177. .progress = udbg_progress,
  178. .machine_shutdown = wii_shutdown,
  179. };
  180. static const struct of_device_id wii_of_bus[] = {
  181. { .compatible = "nintendo,hollywood", },
  182. { },
  183. };
  184. static int __init wii_device_probe(void)
  185. {
  186. if (!machine_is(wii))
  187. return 0;
  188. of_platform_populate(NULL, wii_of_bus, NULL, NULL);
  189. return 0;
  190. }
  191. device_initcall(wii_device_probe);