wii.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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_SHUTDOWN (1<<1)
  41. #define HW_GPIO_SLOT_LED (1<<5)
  42. #define HW_GPIO_SENSOR_BAR (1<<8)
  43. static void __iomem *hw_ctrl;
  44. static void __iomem *hw_gpio;
  45. unsigned long wii_hole_start;
  46. unsigned long wii_hole_size;
  47. static int __init page_aligned(unsigned long x)
  48. {
  49. return !(x & (PAGE_SIZE-1));
  50. }
  51. void __init wii_memory_fixups(void)
  52. {
  53. struct memblock_region *p = memblock.memory.regions;
  54. /*
  55. * This is part of a workaround to allow the use of two
  56. * discontinuous RAM ranges on the Wii, even if this is
  57. * currently unsupported on 32-bit PowerPC Linux.
  58. *
  59. * We coalesce the two memory ranges of the Wii into a
  60. * single range, then create a reservation for the "hole"
  61. * between both ranges.
  62. */
  63. BUG_ON(memblock.memory.cnt != 2);
  64. BUG_ON(!page_aligned(p[0].base) || !page_aligned(p[1].base));
  65. p[0].size = _ALIGN_DOWN(p[0].size, PAGE_SIZE);
  66. p[1].size = _ALIGN_DOWN(p[1].size, PAGE_SIZE);
  67. wii_hole_start = p[0].base + p[0].size;
  68. wii_hole_size = p[1].base - wii_hole_start;
  69. pr_info("MEM1: <%08llx %08llx>\n", p[0].base, p[0].size);
  70. pr_info("HOLE: <%08lx %08lx>\n", wii_hole_start, wii_hole_size);
  71. pr_info("MEM2: <%08llx %08llx>\n", p[1].base, p[1].size);
  72. p[0].size += wii_hole_size + p[1].size;
  73. memblock.memory.cnt = 1;
  74. memblock_analyze();
  75. /* reserve the hole */
  76. memblock_reserve(wii_hole_start, wii_hole_size);
  77. /* allow ioremapping the address space in the hole */
  78. __allow_ioremap_reserved = 1;
  79. }
  80. unsigned long __init wii_mmu_mapin_mem2(unsigned long top)
  81. {
  82. unsigned long delta, size, bl;
  83. unsigned long max_size = (256<<20);
  84. /* MEM2 64MB@0x10000000 */
  85. delta = wii_hole_start + wii_hole_size;
  86. size = top - delta;
  87. for (bl = 128<<10; bl < max_size; bl <<= 1) {
  88. if (bl * 2 > size)
  89. break;
  90. }
  91. setbat(4, PAGE_OFFSET+delta, delta, bl, PAGE_KERNEL_X);
  92. return delta + bl;
  93. }
  94. static void wii_spin(void)
  95. {
  96. local_irq_disable();
  97. for (;;)
  98. cpu_relax();
  99. }
  100. static void __iomem *wii_ioremap_hw_regs(char *name, char *compatible)
  101. {
  102. void __iomem *hw_regs = NULL;
  103. struct device_node *np;
  104. struct resource res;
  105. int error = -ENODEV;
  106. np = of_find_compatible_node(NULL, NULL, compatible);
  107. if (!np) {
  108. pr_err("no compatible node found for %s\n", compatible);
  109. goto out;
  110. }
  111. error = of_address_to_resource(np, 0, &res);
  112. if (error) {
  113. pr_err("no valid reg found for %s\n", np->name);
  114. goto out_put;
  115. }
  116. hw_regs = ioremap(res.start, resource_size(&res));
  117. if (hw_regs) {
  118. pr_info("%s at 0x%08x mapped to 0x%p\n", name,
  119. res.start, hw_regs);
  120. }
  121. out_put:
  122. of_node_put(np);
  123. out:
  124. return hw_regs;
  125. }
  126. static void __init wii_setup_arch(void)
  127. {
  128. hw_ctrl = wii_ioremap_hw_regs("hw_ctrl", HW_CTRL_COMPATIBLE);
  129. hw_gpio = wii_ioremap_hw_regs("hw_gpio", HW_GPIO_COMPATIBLE);
  130. if (hw_gpio) {
  131. /* turn off the front blue led and IR light */
  132. clrbits32(hw_gpio + HW_GPIO_OUT(0),
  133. HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR);
  134. }
  135. }
  136. static void wii_restart(char *cmd)
  137. {
  138. local_irq_disable();
  139. if (hw_ctrl) {
  140. /* clear the system reset pin to cause a reset */
  141. clrbits32(hw_ctrl + HW_CTRL_RESETS, HW_CTRL_RESETS_SYS);
  142. }
  143. wii_spin();
  144. }
  145. static void wii_power_off(void)
  146. {
  147. local_irq_disable();
  148. if (hw_gpio) {
  149. /* make sure that the poweroff GPIO is configured as output */
  150. setbits32(hw_gpio + HW_GPIO_DIR(1), HW_GPIO_SHUTDOWN);
  151. /* drive the poweroff GPIO high */
  152. setbits32(hw_gpio + HW_GPIO_OUT(1), HW_GPIO_SHUTDOWN);
  153. }
  154. wii_spin();
  155. }
  156. static void wii_halt(void)
  157. {
  158. if (ppc_md.restart)
  159. ppc_md.restart(NULL);
  160. wii_spin();
  161. }
  162. static void __init wii_init_early(void)
  163. {
  164. ug_udbg_init();
  165. }
  166. static void __init wii_pic_probe(void)
  167. {
  168. flipper_pic_probe();
  169. hlwd_pic_probe();
  170. }
  171. static int __init wii_probe(void)
  172. {
  173. unsigned long dt_root;
  174. dt_root = of_get_flat_dt_root();
  175. if (!of_flat_dt_is_compatible(dt_root, "nintendo,wii"))
  176. return 0;
  177. return 1;
  178. }
  179. static void wii_shutdown(void)
  180. {
  181. hlwd_quiesce();
  182. flipper_quiesce();
  183. }
  184. define_machine(wii) {
  185. .name = "wii",
  186. .probe = wii_probe,
  187. .init_early = wii_init_early,
  188. .setup_arch = wii_setup_arch,
  189. .restart = wii_restart,
  190. .power_off = wii_power_off,
  191. .halt = wii_halt,
  192. .init_IRQ = wii_pic_probe,
  193. .get_irq = flipper_pic_get_irq,
  194. .calibrate_decr = generic_calibrate_decr,
  195. .progress = udbg_progress,
  196. .machine_shutdown = wii_shutdown,
  197. };
  198. static struct of_device_id wii_of_bus[] = {
  199. { .compatible = "nintendo,hollywood", },
  200. { },
  201. };
  202. static int __init wii_device_probe(void)
  203. {
  204. if (!machine_is(wii))
  205. return 0;
  206. of_platform_bus_probe(NULL, wii_of_bus, NULL);
  207. return 0;
  208. }
  209. device_initcall(wii_device_probe);