board-ap325rxa.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. /*
  2. * Renesas - AP-325RXA
  3. * (Compatible with Algo System ., LTD. - AP-320A)
  4. *
  5. * Copyright (C) 2008 Renesas Solutions Corp.
  6. * Author : Yusuke Goda <goda.yuske@renesas.com>
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/device.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/mtd/physmap.h>
  17. #include <linux/mtd/sh_flctl.h>
  18. #include <linux/delay.h>
  19. #include <linux/i2c.h>
  20. #include <linux/smc911x.h>
  21. #include <linux/gpio.h>
  22. #include <media/soc_camera_platform.h>
  23. #include <media/sh_mobile_ceu.h>
  24. #include <video/sh_mobile_lcdc.h>
  25. #include <asm/io.h>
  26. #include <asm/clock.h>
  27. #include <cpu/sh7723.h>
  28. static struct smc911x_platdata smc911x_info = {
  29. .flags = SMC911X_USE_32BIT,
  30. .irq_flags = IRQF_TRIGGER_LOW,
  31. };
  32. static struct resource smc9118_resources[] = {
  33. [0] = {
  34. .start = 0xb6080000,
  35. .end = 0xb60fffff,
  36. .flags = IORESOURCE_MEM,
  37. },
  38. [1] = {
  39. .start = 35,
  40. .end = 35,
  41. .flags = IORESOURCE_IRQ,
  42. }
  43. };
  44. static struct platform_device smc9118_device = {
  45. .name = "smc911x",
  46. .id = -1,
  47. .num_resources = ARRAY_SIZE(smc9118_resources),
  48. .resource = smc9118_resources,
  49. .dev = {
  50. .platform_data = &smc911x_info,
  51. },
  52. };
  53. /*
  54. * AP320 and AP325RXA has CPLD data in NOR Flash(0xA80000-0xABFFFF).
  55. * If this area erased, this board can not boot.
  56. */
  57. static struct mtd_partition ap325rxa_nor_flash_partitions[] = {
  58. {
  59. .name = "uboot",
  60. .offset = 0,
  61. .size = (1 * 1024 * 1024),
  62. .mask_flags = MTD_WRITEABLE, /* Read-only */
  63. }, {
  64. .name = "kernel",
  65. .offset = MTDPART_OFS_APPEND,
  66. .size = (2 * 1024 * 1024),
  67. }, {
  68. .name = "free-area0",
  69. .offset = MTDPART_OFS_APPEND,
  70. .size = ((7 * 1024 * 1024) + (512 * 1024)),
  71. }, {
  72. .name = "CPLD-Data",
  73. .offset = MTDPART_OFS_APPEND,
  74. .mask_flags = MTD_WRITEABLE, /* Read-only */
  75. .size = (1024 * 128 * 2),
  76. }, {
  77. .name = "free-area1",
  78. .offset = MTDPART_OFS_APPEND,
  79. .size = MTDPART_SIZ_FULL,
  80. },
  81. };
  82. static struct physmap_flash_data ap325rxa_nor_flash_data = {
  83. .width = 2,
  84. .parts = ap325rxa_nor_flash_partitions,
  85. .nr_parts = ARRAY_SIZE(ap325rxa_nor_flash_partitions),
  86. };
  87. static struct resource ap325rxa_nor_flash_resources[] = {
  88. [0] = {
  89. .name = "NOR Flash",
  90. .start = 0x00000000,
  91. .end = 0x00ffffff,
  92. .flags = IORESOURCE_MEM,
  93. }
  94. };
  95. static struct platform_device ap325rxa_nor_flash_device = {
  96. .name = "physmap-flash",
  97. .resource = ap325rxa_nor_flash_resources,
  98. .num_resources = ARRAY_SIZE(ap325rxa_nor_flash_resources),
  99. .dev = {
  100. .platform_data = &ap325rxa_nor_flash_data,
  101. },
  102. };
  103. static struct mtd_partition nand_partition_info[] = {
  104. {
  105. .name = "nand_data",
  106. .offset = 0,
  107. .size = MTDPART_SIZ_FULL,
  108. },
  109. };
  110. static struct resource nand_flash_resources[] = {
  111. [0] = {
  112. .start = 0xa4530000,
  113. .end = 0xa45300ff,
  114. .flags = IORESOURCE_MEM,
  115. }
  116. };
  117. static struct sh_flctl_platform_data nand_flash_data = {
  118. .parts = nand_partition_info,
  119. .nr_parts = ARRAY_SIZE(nand_partition_info),
  120. .flcmncr_val = FCKSEL_E | TYPESEL_SET | NANWF_E,
  121. .has_hwecc = 1,
  122. };
  123. static struct platform_device nand_flash_device = {
  124. .name = "sh_flctl",
  125. .resource = nand_flash_resources,
  126. .num_resources = ARRAY_SIZE(nand_flash_resources),
  127. .dev = {
  128. .platform_data = &nand_flash_data,
  129. },
  130. };
  131. #define FPGA_LCDREG 0xB4100180
  132. #define FPGA_BKLREG 0xB4100212
  133. #define FPGA_LCDREG_VAL 0x0018
  134. #define PORT_MSELCRB 0xA4050182
  135. #define PORT_HIZCRC 0xA405015C
  136. #define PORT_DRVCRA 0xA405018A
  137. #define PORT_DRVCRB 0xA405018C
  138. static void ap320_wvga_power_on(void *board_data)
  139. {
  140. msleep(100);
  141. /* ASD AP-320/325 LCD ON */
  142. ctrl_outw(FPGA_LCDREG_VAL, FPGA_LCDREG);
  143. /* backlight */
  144. gpio_set_value(GPIO_PTS3, 0);
  145. ctrl_outw(0x100, FPGA_BKLREG);
  146. }
  147. static struct sh_mobile_lcdc_info lcdc_info = {
  148. .clock_source = LCDC_CLK_EXTERNAL,
  149. .ch[0] = {
  150. .chan = LCDC_CHAN_MAINLCD,
  151. .bpp = 16,
  152. .interface_type = RGB18,
  153. .clock_divider = 1,
  154. .lcd_cfg = {
  155. .name = "LB070WV1",
  156. .xres = 800,
  157. .yres = 480,
  158. .left_margin = 40,
  159. .right_margin = 160,
  160. .hsync_len = 8,
  161. .upper_margin = 63,
  162. .lower_margin = 80,
  163. .vsync_len = 1,
  164. .sync = 0, /* hsync and vsync are active low */
  165. },
  166. .lcd_size_cfg = { /* 7.0 inch */
  167. .width = 152,
  168. .height = 91,
  169. },
  170. .board_cfg = {
  171. .display_on = ap320_wvga_power_on,
  172. },
  173. }
  174. };
  175. static struct resource lcdc_resources[] = {
  176. [0] = {
  177. .name = "LCDC",
  178. .start = 0xfe940000, /* P4-only space */
  179. .end = 0xfe941fff,
  180. .flags = IORESOURCE_MEM,
  181. },
  182. };
  183. static struct platform_device lcdc_device = {
  184. .name = "sh_mobile_lcdc_fb",
  185. .num_resources = ARRAY_SIZE(lcdc_resources),
  186. .resource = lcdc_resources,
  187. .dev = {
  188. .platform_data = &lcdc_info,
  189. },
  190. };
  191. #ifdef CONFIG_I2C
  192. static unsigned char camera_ncm03j_magic[] =
  193. {
  194. 0x87, 0x00, 0x88, 0x08, 0x89, 0x01, 0x8A, 0xE8,
  195. 0x1D, 0x00, 0x1E, 0x8A, 0x21, 0x00, 0x33, 0x36,
  196. 0x36, 0x60, 0x37, 0x08, 0x3B, 0x31, 0x44, 0x0F,
  197. 0x46, 0xF0, 0x4B, 0x28, 0x4C, 0x21, 0x4D, 0x55,
  198. 0x4E, 0x1B, 0x4F, 0xC7, 0x50, 0xFC, 0x51, 0x12,
  199. 0x58, 0x02, 0x66, 0xC0, 0x67, 0x46, 0x6B, 0xA0,
  200. 0x6C, 0x34, 0x7E, 0x25, 0x7F, 0x25, 0x8D, 0x0F,
  201. 0x92, 0x40, 0x93, 0x04, 0x94, 0x26, 0x95, 0x0A,
  202. 0x99, 0x03, 0x9A, 0xF0, 0x9B, 0x14, 0x9D, 0x7A,
  203. 0xC5, 0x02, 0xD6, 0x07, 0x59, 0x00, 0x5A, 0x1A,
  204. 0x5B, 0x2A, 0x5C, 0x37, 0x5D, 0x42, 0x5E, 0x56,
  205. 0xC8, 0x00, 0xC9, 0x1A, 0xCA, 0x2A, 0xCB, 0x37,
  206. 0xCC, 0x42, 0xCD, 0x56, 0xCE, 0x00, 0xCF, 0x1A,
  207. 0xD0, 0x2A, 0xD1, 0x37, 0xD2, 0x42, 0xD3, 0x56,
  208. 0x5F, 0x68, 0x60, 0x87, 0x61, 0xA3, 0x62, 0xBC,
  209. 0x63, 0xD4, 0x64, 0xEA, 0xD6, 0x0F,
  210. };
  211. static int camera_set_capture(struct soc_camera_platform_info *info,
  212. int enable)
  213. {
  214. struct i2c_adapter *a = i2c_get_adapter(0);
  215. struct i2c_msg msg;
  216. int ret = 0;
  217. int i;
  218. if (!enable)
  219. return 0; /* no disable for now */
  220. for (i = 0; i < ARRAY_SIZE(camera_ncm03j_magic); i += 2) {
  221. u_int8_t buf[8];
  222. msg.addr = 0x6e;
  223. msg.buf = buf;
  224. msg.len = 2;
  225. msg.flags = 0;
  226. buf[0] = camera_ncm03j_magic[i];
  227. buf[1] = camera_ncm03j_magic[i + 1];
  228. ret = (ret < 0) ? ret : i2c_transfer(a, &msg, 1);
  229. }
  230. return ret;
  231. }
  232. static struct soc_camera_platform_info camera_info = {
  233. .iface = 0,
  234. .format_name = "UYVY",
  235. .format_depth = 16,
  236. .format = {
  237. .pixelformat = V4L2_PIX_FMT_UYVY,
  238. .colorspace = V4L2_COLORSPACE_SMPTE170M,
  239. .width = 640,
  240. .height = 480,
  241. },
  242. .bus_param = SOCAM_PCLK_SAMPLE_RISING | SOCAM_HSYNC_ACTIVE_HIGH |
  243. SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_DATAWIDTH_8,
  244. .set_capture = camera_set_capture,
  245. };
  246. static struct platform_device camera_device = {
  247. .name = "soc_camera_platform",
  248. .dev = {
  249. .platform_data = &camera_info,
  250. },
  251. };
  252. #endif /* CONFIG_I2C */
  253. static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
  254. .flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_HSYNC_ACTIVE_HIGH |
  255. SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_DATAWIDTH_8,
  256. };
  257. static struct resource ceu_resources[] = {
  258. [0] = {
  259. .name = "CEU",
  260. .start = 0xfe910000,
  261. .end = 0xfe91009f,
  262. .flags = IORESOURCE_MEM,
  263. },
  264. [1] = {
  265. .start = 52,
  266. .flags = IORESOURCE_IRQ,
  267. },
  268. [2] = {
  269. /* place holder for contiguous memory */
  270. },
  271. };
  272. static struct platform_device ceu_device = {
  273. .name = "sh_mobile_ceu",
  274. .num_resources = ARRAY_SIZE(ceu_resources),
  275. .resource = ceu_resources,
  276. .dev = {
  277. .platform_data = &sh_mobile_ceu_info,
  278. },
  279. };
  280. static struct platform_device *ap325rxa_devices[] __initdata = {
  281. &smc9118_device,
  282. &ap325rxa_nor_flash_device,
  283. &lcdc_device,
  284. &ceu_device,
  285. #ifdef CONFIG_I2C
  286. &camera_device,
  287. #endif
  288. &nand_flash_device,
  289. };
  290. static struct i2c_board_info __initdata ap325rxa_i2c_devices[] = {
  291. {
  292. I2C_BOARD_INFO("pcf8563", 0x51),
  293. },
  294. };
  295. static int __init ap325rxa_devices_setup(void)
  296. {
  297. /* LD3 and LD4 LEDs */
  298. gpio_request(GPIO_PTX5, NULL); /* RUN */
  299. gpio_direction_output(GPIO_PTX5, 1);
  300. gpio_export(GPIO_PTX5, 0);
  301. gpio_request(GPIO_PTX4, NULL); /* INDICATOR */
  302. gpio_direction_output(GPIO_PTX4, 0);
  303. gpio_export(GPIO_PTX4, 0);
  304. /* SW1 input */
  305. gpio_request(GPIO_PTF7, NULL); /* MODE */
  306. gpio_direction_input(GPIO_PTF7);
  307. gpio_export(GPIO_PTF7, 0);
  308. /* LCDC */
  309. clk_always_enable("mstp200");
  310. gpio_request(GPIO_FN_LCDD15, NULL);
  311. gpio_request(GPIO_FN_LCDD14, NULL);
  312. gpio_request(GPIO_FN_LCDD13, NULL);
  313. gpio_request(GPIO_FN_LCDD12, NULL);
  314. gpio_request(GPIO_FN_LCDD11, NULL);
  315. gpio_request(GPIO_FN_LCDD10, NULL);
  316. gpio_request(GPIO_FN_LCDD9, NULL);
  317. gpio_request(GPIO_FN_LCDD8, NULL);
  318. gpio_request(GPIO_FN_LCDD7, NULL);
  319. gpio_request(GPIO_FN_LCDD6, NULL);
  320. gpio_request(GPIO_FN_LCDD5, NULL);
  321. gpio_request(GPIO_FN_LCDD4, NULL);
  322. gpio_request(GPIO_FN_LCDD3, NULL);
  323. gpio_request(GPIO_FN_LCDD2, NULL);
  324. gpio_request(GPIO_FN_LCDD1, NULL);
  325. gpio_request(GPIO_FN_LCDD0, NULL);
  326. gpio_request(GPIO_FN_LCDLCLK_PTR, NULL);
  327. gpio_request(GPIO_FN_LCDDCK, NULL);
  328. gpio_request(GPIO_FN_LCDVEPWC, NULL);
  329. gpio_request(GPIO_FN_LCDVCPWC, NULL);
  330. gpio_request(GPIO_FN_LCDVSYN, NULL);
  331. gpio_request(GPIO_FN_LCDHSYN, NULL);
  332. gpio_request(GPIO_FN_LCDDISP, NULL);
  333. gpio_request(GPIO_FN_LCDDON, NULL);
  334. /* LCD backlight */
  335. gpio_request(GPIO_PTS3, NULL);
  336. gpio_direction_output(GPIO_PTS3, 1);
  337. /* CEU */
  338. clk_always_enable("mstp203");
  339. gpio_request(GPIO_FN_VIO_CLK2, NULL);
  340. gpio_request(GPIO_FN_VIO_VD2, NULL);
  341. gpio_request(GPIO_FN_VIO_HD2, NULL);
  342. gpio_request(GPIO_FN_VIO_FLD, NULL);
  343. gpio_request(GPIO_FN_VIO_CKO, NULL);
  344. gpio_request(GPIO_FN_VIO_D15, NULL);
  345. gpio_request(GPIO_FN_VIO_D14, NULL);
  346. gpio_request(GPIO_FN_VIO_D13, NULL);
  347. gpio_request(GPIO_FN_VIO_D12, NULL);
  348. gpio_request(GPIO_FN_VIO_D11, NULL);
  349. gpio_request(GPIO_FN_VIO_D10, NULL);
  350. gpio_request(GPIO_FN_VIO_D9, NULL);
  351. gpio_request(GPIO_FN_VIO_D8, NULL);
  352. gpio_request(GPIO_PTZ7, NULL);
  353. gpio_direction_output(GPIO_PTZ7, 0); /* OE_CAM */
  354. gpio_request(GPIO_PTZ6, NULL);
  355. gpio_direction_output(GPIO_PTZ6, 0); /* STBY_CAM */
  356. gpio_request(GPIO_PTZ5, NULL);
  357. gpio_direction_output(GPIO_PTZ5, 1); /* RST_CAM */
  358. gpio_request(GPIO_PTZ4, NULL);
  359. gpio_direction_output(GPIO_PTZ4, 0); /* SADDR */
  360. ctrl_outw(ctrl_inw(PORT_MSELCRB) & ~0x0001, PORT_MSELCRB);
  361. /* FLCTL */
  362. gpio_request(GPIO_FN_FCE, NULL);
  363. gpio_request(GPIO_FN_NAF7, NULL);
  364. gpio_request(GPIO_FN_NAF6, NULL);
  365. gpio_request(GPIO_FN_NAF5, NULL);
  366. gpio_request(GPIO_FN_NAF4, NULL);
  367. gpio_request(GPIO_FN_NAF3, NULL);
  368. gpio_request(GPIO_FN_NAF2, NULL);
  369. gpio_request(GPIO_FN_NAF1, NULL);
  370. gpio_request(GPIO_FN_NAF0, NULL);
  371. gpio_request(GPIO_FN_FCDE, NULL);
  372. gpio_request(GPIO_FN_FOE, NULL);
  373. gpio_request(GPIO_FN_FSC, NULL);
  374. gpio_request(GPIO_FN_FWE, NULL);
  375. gpio_request(GPIO_FN_FRB, NULL);
  376. ctrl_outw(0, PORT_HIZCRC);
  377. ctrl_outw(0xFFFF, PORT_DRVCRA);
  378. ctrl_outw(0xFFFF, PORT_DRVCRB);
  379. platform_resource_setup_memory(&ceu_device, "ceu", 4 << 20);
  380. i2c_register_board_info(0, ap325rxa_i2c_devices,
  381. ARRAY_SIZE(ap325rxa_i2c_devices));
  382. return platform_add_devices(ap325rxa_devices,
  383. ARRAY_SIZE(ap325rxa_devices));
  384. }
  385. device_initcall(ap325rxa_devices_setup);
  386. static struct sh_machine_vector mv_ap325rxa __initmv = {
  387. .mv_name = "AP-325RXA",
  388. };