board-ap325rxa.c 9.4 KB

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