board-mackerel.c 14 KB

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