board-mackerel.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. /*
  2. * mackerel board support
  3. *
  4. * Copyright (C) 2010 Renesas Solutions Corp.
  5. * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * based on ap4evb
  8. * Copyright (C) 2010 Magnus Damm
  9. * Copyright (C) 2008 Yoshihiro Shimoda
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; version 2 of the License.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/init.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/irq.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/gpio.h>
  30. #include <linux/input.h>
  31. #include <linux/io.h>
  32. #include <linux/i2c.h>
  33. #include <linux/leds.h>
  34. #include <linux/mtd/mtd.h>
  35. #include <linux/mtd/partitions.h>
  36. #include <linux/mtd/physmap.h>
  37. #include <linux/smsc911x.h>
  38. #include <linux/sh_intc.h>
  39. #include <linux/usb/r8a66597.h>
  40. #include <video/sh_mobile_lcdc.h>
  41. #include <sound/sh_fsi.h>
  42. #include <mach/common.h>
  43. #include <mach/sh7372.h>
  44. #include <asm/mach/arch.h>
  45. #include <asm/mach/time.h>
  46. #include <asm/mach/map.h>
  47. #include <asm/mach-types.h>
  48. /*
  49. * Address Interface BusWidth note
  50. * ------------------------------------------------------------------
  51. * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
  52. * 0x0800_0000 user area -
  53. * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
  54. * 0x1400_0000 Ether (LAN9220) 16bit
  55. * 0x1600_0000 user area - cannot use with NAND
  56. * 0x1800_0000 user area -
  57. * 0x1A00_0000 -
  58. * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
  59. */
  60. /*
  61. * CPU mode
  62. *
  63. * SW4 | Boot Area| Master | Remarks
  64. * 1 | 2 | 3 | 4 | 5 | 6 | 8 | | Processor|
  65. * ----+-----+-----+-----+-----+-----+-----+----------+----------+--------------
  66. * ON | ON | OFF | ON | ON | OFF | OFF | External | System | External ROM
  67. * ON | ON | ON | ON | ON | OFF | OFF | External | System | ROM Debug
  68. * ON | ON | X | ON | OFF | OFF | OFF | Built-in | System | ROM Debug
  69. * X | OFF | X | X | X | X | OFF | Built-in | System | MaskROM
  70. * OFF | X | X | X | X | X | OFF | Built-in | System | MaskROM
  71. * X | X | X | OFF | X | X | OFF | Built-in | System | MaskROM
  72. * OFF | ON | OFF | X | X | OFF | ON | External | System | Standalone
  73. * ON | OFF | OFF | X | X | OFF | ON | External | Realtime | Standalone
  74. */
  75. /*
  76. * NOR Flash ROM
  77. *
  78. * SW1 | SW2 | SW7 | NOR Flash ROM
  79. * bit1 | bit1 bit2 | bit1 | Memory allocation
  80. * ------+------------+------+------------------
  81. * OFF | ON OFF | ON | Area 0
  82. * OFF | ON OFF | OFF | Area 4
  83. */
  84. /*
  85. * SMSC 9220
  86. *
  87. * SW1 SMSC 9220
  88. * -----------------------
  89. * ON access disable
  90. * OFF access enable
  91. */
  92. /*
  93. * NAND Flash ROM
  94. *
  95. * SW1 | SW2 | SW7 | NAND Flash ROM
  96. * bit1 | bit1 bit2 | bit2 | Memory allocation
  97. * ------+------------+------+------------------
  98. * OFF | ON OFF | ON | FCE 0
  99. * OFF | ON OFF | OFF | FCE 1
  100. */
  101. /*
  102. * External interrupt pin settings
  103. *
  104. * IRQX | pin setting | device | level
  105. * ------+--------------------+--------------------+-------
  106. * IRQ0 | ICR1A.IRQ0SA=0010 | SDHI2 card detect | Low
  107. * IRQ6 | ICR1A.IRQ6SA=0011 | Ether(LAN9220) | High
  108. * IRQ7 | ICR1A.IRQ7SA=0010 | LCD Tuch Panel | Low
  109. * IRQ8 | ICR2A.IRQ8SA=0010 | MMC/SD card detect | Low
  110. * IRQ9 | ICR2A.IRQ9SA=0010 | KEY(TCA6408) | Low
  111. * IRQ21 | ICR4A.IRQ21SA=0011 | Sensor(ADXL345) | High
  112. * IRQ22 | ICR4A.IRQ22SA=0011 | Sensor(AK8975) | High
  113. */
  114. /*
  115. * USB
  116. *
  117. * USB0 : CN22 : Function
  118. * USB1 : CN31 : Function/Host *1
  119. *
  120. * J30 (for CN31) *1
  121. * ----------+---------------+-------------
  122. * 1-2 short | VBUS 5V | Host
  123. * open | external VBUS | Function
  124. *
  125. * *1
  126. * CN31 is used as Host in Linux.
  127. */
  128. /*
  129. * FIXME !!
  130. *
  131. * gpio_no_direction
  132. * are quick_hack.
  133. *
  134. * current gpio frame work doesn't have
  135. * the method to control only pull up/down/free.
  136. * this function should be replaced by correct gpio function
  137. */
  138. static void __init gpio_no_direction(u32 addr)
  139. {
  140. __raw_writeb(0x00, addr);
  141. }
  142. /* MTD */
  143. static struct mtd_partition nor_flash_partitions[] = {
  144. {
  145. .name = "loader",
  146. .offset = 0x00000000,
  147. .size = 512 * 1024,
  148. .mask_flags = MTD_WRITEABLE,
  149. },
  150. {
  151. .name = "bootenv",
  152. .offset = MTDPART_OFS_APPEND,
  153. .size = 512 * 1024,
  154. .mask_flags = MTD_WRITEABLE,
  155. },
  156. {
  157. .name = "kernel_ro",
  158. .offset = MTDPART_OFS_APPEND,
  159. .size = 8 * 1024 * 1024,
  160. .mask_flags = MTD_WRITEABLE,
  161. },
  162. {
  163. .name = "kernel",
  164. .offset = MTDPART_OFS_APPEND,
  165. .size = 8 * 1024 * 1024,
  166. },
  167. {
  168. .name = "data",
  169. .offset = MTDPART_OFS_APPEND,
  170. .size = MTDPART_SIZ_FULL,
  171. },
  172. };
  173. static struct physmap_flash_data nor_flash_data = {
  174. .width = 2,
  175. .parts = nor_flash_partitions,
  176. .nr_parts = ARRAY_SIZE(nor_flash_partitions),
  177. };
  178. static struct resource nor_flash_resources[] = {
  179. [0] = {
  180. .start = 0x00000000,
  181. .end = 0x08000000 - 1,
  182. .flags = IORESOURCE_MEM,
  183. }
  184. };
  185. static struct platform_device nor_flash_device = {
  186. .name = "physmap-flash",
  187. .dev = {
  188. .platform_data = &nor_flash_data,
  189. },
  190. .num_resources = ARRAY_SIZE(nor_flash_resources),
  191. .resource = nor_flash_resources,
  192. };
  193. /* SMSC */
  194. static struct resource smc911x_resources[] = {
  195. {
  196. .start = 0x14000000,
  197. .end = 0x16000000 - 1,
  198. .flags = IORESOURCE_MEM,
  199. }, {
  200. .start = evt2irq(0x02c0) /* IRQ6A */,
  201. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  202. },
  203. };
  204. static struct smsc911x_platform_config smsc911x_info = {
  205. .flags = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
  206. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  207. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  208. };
  209. static struct platform_device smc911x_device = {
  210. .name = "smsc911x",
  211. .id = -1,
  212. .num_resources = ARRAY_SIZE(smc911x_resources),
  213. .resource = smc911x_resources,
  214. .dev = {
  215. .platform_data = &smsc911x_info,
  216. },
  217. };
  218. /* LCDC */
  219. static struct fb_videomode mackerel_lcdc_modes[] = {
  220. {
  221. .name = "WVGA Panel",
  222. .xres = 800,
  223. .yres = 480,
  224. .left_margin = 220,
  225. .right_margin = 110,
  226. .hsync_len = 70,
  227. .upper_margin = 20,
  228. .lower_margin = 5,
  229. .vsync_len = 5,
  230. .sync = 0,
  231. },
  232. };
  233. static struct sh_mobile_lcdc_info lcdc_info = {
  234. .clock_source = LCDC_CLK_BUS,
  235. .ch[0] = {
  236. .chan = LCDC_CHAN_MAINLCD,
  237. .bpp = 16,
  238. .lcd_cfg = mackerel_lcdc_modes,
  239. .num_cfg = ARRAY_SIZE(mackerel_lcdc_modes),
  240. .interface_type = RGB24,
  241. .clock_divider = 2,
  242. .flags = 0,
  243. .lcd_size_cfg.width = 152,
  244. .lcd_size_cfg.height = 91,
  245. }
  246. };
  247. static struct resource lcdc_resources[] = {
  248. [0] = {
  249. .name = "LCDC",
  250. .start = 0xfe940000,
  251. .end = 0xfe943fff,
  252. .flags = IORESOURCE_MEM,
  253. },
  254. [1] = {
  255. .start = intcs_evt2irq(0x580),
  256. .flags = IORESOURCE_IRQ,
  257. },
  258. };
  259. static struct platform_device lcdc_device = {
  260. .name = "sh_mobile_lcdc_fb",
  261. .num_resources = ARRAY_SIZE(lcdc_resources),
  262. .resource = lcdc_resources,
  263. .dev = {
  264. .platform_data = &lcdc_info,
  265. .coherent_dma_mask = ~0,
  266. },
  267. };
  268. /* USB1 (Host) */
  269. static void usb1_host_port_power(int port, int power)
  270. {
  271. if (!power) /* only power-on is supported for now */
  272. return;
  273. /* set VBOUT/PWEN and EXTLP1 in DVSTCTR */
  274. __raw_writew(__raw_readw(0xE68B0008) | 0x600, 0xE68B0008);
  275. }
  276. static struct r8a66597_platdata usb1_host_data = {
  277. .on_chip = 1,
  278. .port_power = usb1_host_port_power,
  279. };
  280. static struct resource usb1_host_resources[] = {
  281. [0] = {
  282. .name = "USBHS",
  283. .start = 0xE68B0000,
  284. .end = 0xE68B00E6 - 1,
  285. .flags = IORESOURCE_MEM,
  286. },
  287. [1] = {
  288. .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
  289. .flags = IORESOURCE_IRQ,
  290. },
  291. };
  292. static struct platform_device usb1_host_device = {
  293. .name = "r8a66597_hcd",
  294. .id = 1,
  295. .dev = {
  296. .dma_mask = NULL, /* not use dma */
  297. .coherent_dma_mask = 0xffffffff,
  298. .platform_data = &usb1_host_data,
  299. },
  300. .num_resources = ARRAY_SIZE(usb1_host_resources),
  301. .resource = usb1_host_resources,
  302. };
  303. /* LED */
  304. static struct gpio_led mackerel_leds[] = {
  305. {
  306. .name = "led0",
  307. .gpio = GPIO_PORT0,
  308. .default_state = LEDS_GPIO_DEFSTATE_ON,
  309. },
  310. {
  311. .name = "led1",
  312. .gpio = GPIO_PORT1,
  313. .default_state = LEDS_GPIO_DEFSTATE_ON,
  314. },
  315. {
  316. .name = "led2",
  317. .gpio = GPIO_PORT2,
  318. .default_state = LEDS_GPIO_DEFSTATE_ON,
  319. },
  320. {
  321. .name = "led3",
  322. .gpio = GPIO_PORT159,
  323. .default_state = LEDS_GPIO_DEFSTATE_ON,
  324. }
  325. };
  326. static struct gpio_led_platform_data mackerel_leds_pdata = {
  327. .leds = mackerel_leds,
  328. .num_leds = ARRAY_SIZE(mackerel_leds),
  329. };
  330. static struct platform_device leds_device = {
  331. .name = "leds-gpio",
  332. .id = 0,
  333. .dev = {
  334. .platform_data = &mackerel_leds_pdata,
  335. },
  336. };
  337. /* FSI */
  338. #define IRQ_FSI evt2irq(0x1840)
  339. static struct sh_fsi_platform_info fsi_info = {
  340. .porta_flags = SH_FSI_BRS_INV |
  341. SH_FSI_OUT_SLAVE_MODE |
  342. SH_FSI_IN_SLAVE_MODE |
  343. SH_FSI_OFMT(PCM) |
  344. SH_FSI_IFMT(PCM),
  345. };
  346. static struct resource fsi_resources[] = {
  347. [0] = {
  348. .name = "FSI",
  349. .start = 0xFE3C0000,
  350. .end = 0xFE3C0400 - 1,
  351. .flags = IORESOURCE_MEM,
  352. },
  353. [1] = {
  354. .start = IRQ_FSI,
  355. .flags = IORESOURCE_IRQ,
  356. },
  357. };
  358. static struct platform_device fsi_device = {
  359. .name = "sh_fsi2",
  360. .id = -1,
  361. .num_resources = ARRAY_SIZE(fsi_resources),
  362. .resource = fsi_resources,
  363. .dev = {
  364. .platform_data = &fsi_info,
  365. },
  366. };
  367. static struct platform_device fsi_ak4643_device = {
  368. .name = "sh_fsi2_a_ak4643",
  369. };
  370. static struct platform_device *mackerel_devices[] __initdata = {
  371. &nor_flash_device,
  372. &smc911x_device,
  373. &lcdc_device,
  374. &usb1_host_device,
  375. &leds_device,
  376. &fsi_device,
  377. &fsi_ak4643_device,
  378. };
  379. /* I2C */
  380. static struct i2c_board_info i2c0_devices[] = {
  381. {
  382. I2C_BOARD_INFO("ak4643", 0x13),
  383. },
  384. };
  385. static struct map_desc mackerel_io_desc[] __initdata = {
  386. /* create a 1:1 entity map for 0xe6xxxxxx
  387. * used by CPGA, INTC and PFC.
  388. */
  389. {
  390. .virtual = 0xe6000000,
  391. .pfn = __phys_to_pfn(0xe6000000),
  392. .length = 256 << 20,
  393. .type = MT_DEVICE_NONSHARED
  394. },
  395. };
  396. static void __init mackerel_map_io(void)
  397. {
  398. iotable_init(mackerel_io_desc, ARRAY_SIZE(mackerel_io_desc));
  399. /* setup early devices and console here as well */
  400. sh7372_add_early_devices();
  401. shmobile_setup_console();
  402. }
  403. #define GPIO_PORT9CR 0xE6051009
  404. #define GPIO_PORT10CR 0xE605100A
  405. static void __init mackerel_init(void)
  406. {
  407. sh7372_pinmux_init();
  408. /* enable SCIFA0 */
  409. gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
  410. gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
  411. /* enable SMSC911X */
  412. gpio_request(GPIO_FN_CS5A, NULL);
  413. gpio_request(GPIO_FN_IRQ6_39, NULL);
  414. /* LCDC */
  415. gpio_request(GPIO_FN_LCDD23, NULL);
  416. gpio_request(GPIO_FN_LCDD22, NULL);
  417. gpio_request(GPIO_FN_LCDD21, NULL);
  418. gpio_request(GPIO_FN_LCDD20, NULL);
  419. gpio_request(GPIO_FN_LCDD19, NULL);
  420. gpio_request(GPIO_FN_LCDD18, NULL);
  421. gpio_request(GPIO_FN_LCDD17, NULL);
  422. gpio_request(GPIO_FN_LCDD16, NULL);
  423. gpio_request(GPIO_FN_LCDD15, NULL);
  424. gpio_request(GPIO_FN_LCDD14, NULL);
  425. gpio_request(GPIO_FN_LCDD13, NULL);
  426. gpio_request(GPIO_FN_LCDD12, NULL);
  427. gpio_request(GPIO_FN_LCDD11, NULL);
  428. gpio_request(GPIO_FN_LCDD10, NULL);
  429. gpio_request(GPIO_FN_LCDD9, NULL);
  430. gpio_request(GPIO_FN_LCDD8, NULL);
  431. gpio_request(GPIO_FN_LCDD7, NULL);
  432. gpio_request(GPIO_FN_LCDD6, NULL);
  433. gpio_request(GPIO_FN_LCDD5, NULL);
  434. gpio_request(GPIO_FN_LCDD4, NULL);
  435. gpio_request(GPIO_FN_LCDD3, NULL);
  436. gpio_request(GPIO_FN_LCDD2, NULL);
  437. gpio_request(GPIO_FN_LCDD1, NULL);
  438. gpio_request(GPIO_FN_LCDD0, NULL);
  439. gpio_request(GPIO_FN_LCDDISP, NULL);
  440. gpio_request(GPIO_FN_LCDDCK, NULL);
  441. gpio_request(GPIO_PORT31, NULL); /* backlight */
  442. gpio_direction_output(GPIO_PORT31, 1);
  443. gpio_request(GPIO_PORT151, NULL); /* LCDDON */
  444. gpio_direction_output(GPIO_PORT151, 1);
  445. /* USB enable */
  446. gpio_request(GPIO_FN_VBUS0_1, NULL);
  447. gpio_request(GPIO_FN_IDIN_1_18, NULL);
  448. gpio_request(GPIO_FN_PWEN_1_115, NULL);
  449. gpio_request(GPIO_FN_OVCN_1_114, NULL);
  450. gpio_request(GPIO_FN_EXTLP_1, NULL);
  451. gpio_request(GPIO_FN_OVCN2_1, NULL);
  452. /* setup USB phy */
  453. __raw_writew(0x8a0a, 0xE6058130); /* USBCR2 */
  454. /* enable FSI2 port A (ak4643) */
  455. gpio_request(GPIO_FN_FSIAIBT, NULL);
  456. gpio_request(GPIO_FN_FSIAILR, NULL);
  457. gpio_request(GPIO_FN_FSIAISLD, NULL);
  458. gpio_request(GPIO_FN_FSIAOSLD, NULL);
  459. gpio_request(GPIO_PORT161, NULL);
  460. gpio_direction_output(GPIO_PORT161, 0); /* slave */
  461. gpio_request(GPIO_PORT9, NULL);
  462. gpio_request(GPIO_PORT10, NULL);
  463. gpio_no_direction(GPIO_PORT9CR); /* FSIAOBT needs no direction */
  464. gpio_no_direction(GPIO_PORT10CR); /* FSIAOLR needs no direction */
  465. intc_set_priority(IRQ_FSI, 3); /* irq priority FSI(3) > SMSC911X(2) */
  466. i2c_register_board_info(0, i2c0_devices,
  467. ARRAY_SIZE(i2c0_devices));
  468. sh7372_add_standard_devices();
  469. platform_add_devices(mackerel_devices, ARRAY_SIZE(mackerel_devices));
  470. }
  471. static void __init mackerel_timer_init(void)
  472. {
  473. sh7372_clock_init();
  474. shmobile_timer.init();
  475. }
  476. static struct sys_timer mackerel_timer = {
  477. .init = mackerel_timer_init,
  478. };
  479. MACHINE_START(MACKEREL, "mackerel")
  480. .map_io = mackerel_map_io,
  481. .init_irq = sh7372_init_irq,
  482. .init_machine = mackerel_init,
  483. .timer = &mackerel_timer,
  484. MACHINE_END