setup.c 8.9 KB

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