setup.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /*
  2. * arch/sh/boards/renesas/r7780rp/setup.c
  3. *
  4. * Renesas Solutions Highlander Support.
  5. *
  6. * Copyright (C) 2002 Atom Create Engineering Co., Ltd.
  7. * Copyright (C) 2005 - 2008 Paul Mundt
  8. *
  9. * This contains support for the R7780RP-1, R7780MP, and R7785RP
  10. * Highlander modules.
  11. *
  12. * This file is subject to the terms and conditions of the GNU General Public
  13. * License. See the file "COPYING" in the main directory of this archive
  14. * for more details.
  15. */
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/ata_platform.h>
  20. #include <linux/types.h>
  21. #include <linux/mtd/physmap.h>
  22. #include <linux/i2c.h>
  23. #include <linux/irq.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/usb/r8a66597.h>
  26. #include <linux/usb/m66592.h>
  27. #include <linux/clkdev.h>
  28. #include <net/ax88796.h>
  29. #include <asm/machvec.h>
  30. #include <mach/highlander.h>
  31. #include <asm/clock.h>
  32. #include <asm/heartbeat.h>
  33. #include <asm/io.h>
  34. #include <asm/io_trapped.h>
  35. static struct r8a66597_platdata r8a66597_data = {
  36. .xtal = R8A66597_PLATDATA_XTAL_12MHZ,
  37. .vif = 1,
  38. };
  39. static struct resource r8a66597_usb_host_resources[] = {
  40. [0] = {
  41. .start = 0xA4200000,
  42. .end = 0xA42000FF,
  43. .flags = IORESOURCE_MEM,
  44. },
  45. [1] = {
  46. .start = IRQ_EXT1, /* irq number */
  47. .end = IRQ_EXT1,
  48. .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
  49. },
  50. };
  51. static struct platform_device r8a66597_usb_host_device = {
  52. .name = "r8a66597_hcd",
  53. .id = -1,
  54. .dev = {
  55. .dma_mask = NULL, /* don't use dma */
  56. .coherent_dma_mask = 0xffffffff,
  57. .platform_data = &r8a66597_data,
  58. },
  59. .num_resources = ARRAY_SIZE(r8a66597_usb_host_resources),
  60. .resource = r8a66597_usb_host_resources,
  61. };
  62. static struct m66592_platdata usbf_platdata = {
  63. .xtal = M66592_PLATDATA_XTAL_24MHZ,
  64. .vif = 1,
  65. };
  66. static struct resource m66592_usb_peripheral_resources[] = {
  67. [0] = {
  68. .name = "m66592_udc",
  69. .start = 0xb0000000,
  70. .end = 0xb00000FF,
  71. .flags = IORESOURCE_MEM,
  72. },
  73. [1] = {
  74. .name = "m66592_udc",
  75. .start = IRQ_EXT4, /* irq number */
  76. .end = IRQ_EXT4,
  77. .flags = IORESOURCE_IRQ,
  78. },
  79. };
  80. static struct platform_device m66592_usb_peripheral_device = {
  81. .name = "m66592_udc",
  82. .id = -1,
  83. .dev = {
  84. .dma_mask = NULL, /* don't use dma */
  85. .coherent_dma_mask = 0xffffffff,
  86. .platform_data = &usbf_platdata,
  87. },
  88. .num_resources = ARRAY_SIZE(m66592_usb_peripheral_resources),
  89. .resource = m66592_usb_peripheral_resources,
  90. };
  91. static struct resource cf_ide_resources[] = {
  92. [0] = {
  93. .start = PA_AREA5_IO + 0x1000,
  94. .end = PA_AREA5_IO + 0x1000 + 0x08 - 1,
  95. .flags = IORESOURCE_MEM,
  96. },
  97. [1] = {
  98. .start = PA_AREA5_IO + 0x80c,
  99. .end = PA_AREA5_IO + 0x80c + 0x16 - 1,
  100. .flags = IORESOURCE_MEM,
  101. },
  102. [2] = {
  103. .start = IRQ_CF,
  104. .flags = IORESOURCE_IRQ,
  105. },
  106. };
  107. static struct pata_platform_info pata_info = {
  108. .ioport_shift = 1,
  109. };
  110. static struct platform_device cf_ide_device = {
  111. .name = "pata_platform",
  112. .id = -1,
  113. .num_resources = ARRAY_SIZE(cf_ide_resources),
  114. .resource = cf_ide_resources,
  115. .dev = {
  116. .platform_data = &pata_info,
  117. },
  118. };
  119. static struct resource heartbeat_resources[] = {
  120. [0] = {
  121. .start = PA_OBLED,
  122. .end = PA_OBLED,
  123. .flags = IORESOURCE_MEM,
  124. },
  125. };
  126. #ifndef CONFIG_SH_R7785RP
  127. static unsigned char heartbeat_bit_pos[] = { 2, 1, 0, 3, 6, 5, 4, 7 };
  128. static struct heartbeat_data heartbeat_data = {
  129. .bit_pos = heartbeat_bit_pos,
  130. .nr_bits = ARRAY_SIZE(heartbeat_bit_pos),
  131. };
  132. #endif
  133. static struct platform_device heartbeat_device = {
  134. .name = "heartbeat",
  135. .id = -1,
  136. /* R7785RP has a slightly more sensible FPGA.. */
  137. #ifndef CONFIG_SH_R7785RP
  138. .dev = {
  139. .platform_data = &heartbeat_data,
  140. },
  141. #endif
  142. .num_resources = ARRAY_SIZE(heartbeat_resources),
  143. .resource = heartbeat_resources,
  144. };
  145. static struct ax_plat_data ax88796_platdata = {
  146. .flags = AXFLG_HAS_93CX6,
  147. .wordlength = 2,
  148. .dcr_val = 0x1,
  149. .rcr_val = 0x40,
  150. };
  151. static struct resource ax88796_resources[] = {
  152. {
  153. #ifdef CONFIG_SH_R7780RP
  154. .start = 0xa5800400,
  155. .end = 0xa5800400 + (0x20 * 0x2) - 1,
  156. #else
  157. .start = 0xa4100400,
  158. .end = 0xa4100400 + (0x20 * 0x2) - 1,
  159. #endif
  160. .flags = IORESOURCE_MEM,
  161. },
  162. {
  163. .start = IRQ_AX88796,
  164. .end = IRQ_AX88796,
  165. .flags = IORESOURCE_IRQ,
  166. },
  167. };
  168. static struct platform_device ax88796_device = {
  169. .name = "ax88796",
  170. .id = 0,
  171. .dev = {
  172. .platform_data = &ax88796_platdata,
  173. },
  174. .num_resources = ARRAY_SIZE(ax88796_resources),
  175. .resource = ax88796_resources,
  176. };
  177. static struct mtd_partition nor_flash_partitions[] = {
  178. {
  179. .name = "loader",
  180. .offset = 0x00000000,
  181. .size = 512 * 1024,
  182. },
  183. {
  184. .name = "bootenv",
  185. .offset = MTDPART_OFS_APPEND,
  186. .size = 512 * 1024,
  187. },
  188. {
  189. .name = "kernel",
  190. .offset = MTDPART_OFS_APPEND,
  191. .size = 4 * 1024 * 1024,
  192. },
  193. {
  194. .name = "data",
  195. .offset = MTDPART_OFS_APPEND,
  196. .size = MTDPART_SIZ_FULL,
  197. },
  198. };
  199. static struct physmap_flash_data nor_flash_data = {
  200. .width = 4,
  201. .parts = nor_flash_partitions,
  202. .nr_parts = ARRAY_SIZE(nor_flash_partitions),
  203. };
  204. /* This config is flash board for mass production. */
  205. static struct resource nor_flash_resources[] = {
  206. [0] = {
  207. .start = PA_NORFLASH_ADDR,
  208. .end = PA_NORFLASH_ADDR + PA_NORFLASH_SIZE - 1,
  209. .flags = IORESOURCE_MEM,
  210. }
  211. };
  212. static struct platform_device nor_flash_device = {
  213. .name = "physmap-flash",
  214. .dev = {
  215. .platform_data = &nor_flash_data,
  216. },
  217. .num_resources = ARRAY_SIZE(nor_flash_resources),
  218. .resource = nor_flash_resources,
  219. };
  220. static struct resource smbus_resources[] = {
  221. [0] = {
  222. .start = PA_SMCR,
  223. .end = PA_SMCR + 0x100 - 1,
  224. .flags = IORESOURCE_MEM,
  225. },
  226. [1] = {
  227. .start = IRQ_SMBUS,
  228. .end = IRQ_SMBUS,
  229. .flags = IORESOURCE_IRQ,
  230. },
  231. };
  232. static struct platform_device smbus_device = {
  233. .name = "i2c-highlander",
  234. .id = 0,
  235. .num_resources = ARRAY_SIZE(smbus_resources),
  236. .resource = smbus_resources,
  237. };
  238. static struct i2c_board_info __initdata highlander_i2c_devices[] = {
  239. {
  240. I2C_BOARD_INFO("r2025sd", 0x32),
  241. },
  242. };
  243. static struct platform_device *r7780rp_devices[] __initdata = {
  244. &r8a66597_usb_host_device,
  245. &m66592_usb_peripheral_device,
  246. &heartbeat_device,
  247. &smbus_device,
  248. &nor_flash_device,
  249. #ifndef CONFIG_SH_R7780RP
  250. &ax88796_device,
  251. #endif
  252. };
  253. /*
  254. * The CF is connected using a 16-bit bus where 8-bit operations are
  255. * unsupported. The linux ata driver is however using 8-bit operations, so
  256. * insert a trapped io filter to convert 8-bit operations into 16-bit.
  257. */
  258. static struct trapped_io cf_trapped_io = {
  259. .resource = cf_ide_resources,
  260. .num_resources = 2,
  261. .minimum_bus_width = 16,
  262. };
  263. static int __init r7780rp_devices_setup(void)
  264. {
  265. int ret = 0;
  266. #ifndef CONFIG_SH_R7780RP
  267. if (register_trapped_io(&cf_trapped_io) == 0)
  268. ret |= platform_device_register(&cf_ide_device);
  269. #endif
  270. ret |= platform_add_devices(r7780rp_devices,
  271. ARRAY_SIZE(r7780rp_devices));
  272. ret |= i2c_register_board_info(0, highlander_i2c_devices,
  273. ARRAY_SIZE(highlander_i2c_devices));
  274. return ret;
  275. }
  276. device_initcall(r7780rp_devices_setup);
  277. /*
  278. * Platform specific clocks
  279. */
  280. static int ivdr_clk_enable(struct clk *clk)
  281. {
  282. __raw_writew(__raw_readw(PA_IVDRCTL) | (1 << IVDR_CK_ON), PA_IVDRCTL);
  283. return 0;
  284. }
  285. static void ivdr_clk_disable(struct clk *clk)
  286. {
  287. __raw_writew(__raw_readw(PA_IVDRCTL) & ~(1 << IVDR_CK_ON), PA_IVDRCTL);
  288. }
  289. static struct sh_clk_ops ivdr_clk_ops = {
  290. .enable = ivdr_clk_enable,
  291. .disable = ivdr_clk_disable,
  292. };
  293. static struct clk ivdr_clk = {
  294. .ops = &ivdr_clk_ops,
  295. };
  296. static struct clk *r7780rp_clocks[] = {
  297. &ivdr_clk,
  298. };
  299. static struct clk_lookup lookups[] = {
  300. /* main clocks */
  301. CLKDEV_CON_ID("ivdr_clk", &ivdr_clk),
  302. };
  303. static void r7780rp_power_off(void)
  304. {
  305. if (mach_is_r7780mp() || mach_is_r7785rp())
  306. __raw_writew(0x0001, PA_POFF);
  307. }
  308. /*
  309. * Initialize the board
  310. */
  311. static void __init highlander_setup(char **cmdline_p)
  312. {
  313. u16 ver = __raw_readw(PA_VERREG);
  314. int i;
  315. printk(KERN_INFO "Renesas Solutions Highlander %s support.\n",
  316. mach_is_r7780rp() ? "R7780RP-1" :
  317. mach_is_r7780mp() ? "R7780MP" :
  318. "R7785RP");
  319. printk(KERN_INFO "Board version: %d (revision %d), "
  320. "FPGA version: %d (revision %d)\n",
  321. (ver >> 12) & 0xf, (ver >> 8) & 0xf,
  322. (ver >> 4) & 0xf, ver & 0xf);
  323. highlander_plat_pinmux_setup();
  324. /*
  325. * Enable the important clocks right away..
  326. */
  327. for (i = 0; i < ARRAY_SIZE(r7780rp_clocks); i++) {
  328. struct clk *clk = r7780rp_clocks[i];
  329. clk_register(clk);
  330. clk_enable(clk);
  331. }
  332. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  333. __raw_writew(0x0000, PA_OBLED); /* Clear LED. */
  334. if (mach_is_r7780rp())
  335. __raw_writew(0x0001, PA_SDPOW); /* SD Power ON */
  336. __raw_writew(__raw_readw(PA_IVDRCTL) | 0x01, PA_IVDRCTL); /* Si13112 */
  337. pm_power_off = r7780rp_power_off;
  338. }
  339. static unsigned char irl2irq[HL_NR_IRL];
  340. static int highlander_irq_demux(int irq)
  341. {
  342. if (irq >= HL_NR_IRL || irq < 0 || !irl2irq[irq])
  343. return irq;
  344. return irl2irq[irq];
  345. }
  346. static void __init highlander_init_irq(void)
  347. {
  348. unsigned char *ucp = highlander_plat_irq_setup();
  349. if (ucp) {
  350. plat_irq_setup_pins(IRQ_MODE_IRL3210);
  351. memcpy(irl2irq, ucp, HL_NR_IRL);
  352. }
  353. }
  354. /*
  355. * The Machine Vector
  356. */
  357. static struct sh_machine_vector mv_highlander __initmv = {
  358. .mv_name = "Highlander",
  359. .mv_setup = highlander_setup,
  360. .mv_init_irq = highlander_init_irq,
  361. .mv_irq_demux = highlander_irq_demux,
  362. };