board-ap325rxa.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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/smsc911x.h>
  21. #include <linux/gpio.h>
  22. #include <linux/spi/spi.h>
  23. #include <linux/spi/spi_gpio.h>
  24. #include <media/ov772x.h>
  25. #include <media/soc_camera.h>
  26. #include <media/soc_camera_platform.h>
  27. #include <media/sh_mobile_ceu.h>
  28. #include <video/sh_mobile_lcdc.h>
  29. #include <asm/io.h>
  30. #include <asm/clock.h>
  31. #include <cpu/sh7723.h>
  32. static struct smsc911x_platform_config smsc911x_config = {
  33. .phy_interface = PHY_INTERFACE_MODE_MII,
  34. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  35. .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
  36. .flags = SMSC911X_USE_32BIT,
  37. };
  38. static struct resource smsc9118_resources[] = {
  39. [0] = {
  40. .start = 0xb6080000,
  41. .end = 0xb60fffff,
  42. .flags = IORESOURCE_MEM,
  43. },
  44. [1] = {
  45. .start = 35,
  46. .end = 35,
  47. .flags = IORESOURCE_IRQ,
  48. }
  49. };
  50. static struct platform_device smsc9118_device = {
  51. .name = "smsc911x",
  52. .id = -1,
  53. .num_resources = ARRAY_SIZE(smsc9118_resources),
  54. .resource = smsc9118_resources,
  55. .dev = {
  56. .platform_data = &smsc911x_config,
  57. },
  58. };
  59. /*
  60. * AP320 and AP325RXA has CPLD data in NOR Flash(0xA80000-0xABFFFF).
  61. * If this area erased, this board can not boot.
  62. */
  63. static struct mtd_partition ap325rxa_nor_flash_partitions[] = {
  64. {
  65. .name = "uboot",
  66. .offset = 0,
  67. .size = (1 * 1024 * 1024),
  68. .mask_flags = MTD_WRITEABLE, /* Read-only */
  69. }, {
  70. .name = "kernel",
  71. .offset = MTDPART_OFS_APPEND,
  72. .size = (2 * 1024 * 1024),
  73. }, {
  74. .name = "free-area0",
  75. .offset = MTDPART_OFS_APPEND,
  76. .size = ((7 * 1024 * 1024) + (512 * 1024)),
  77. }, {
  78. .name = "CPLD-Data",
  79. .offset = MTDPART_OFS_APPEND,
  80. .mask_flags = MTD_WRITEABLE, /* Read-only */
  81. .size = (1024 * 128 * 2),
  82. }, {
  83. .name = "free-area1",
  84. .offset = MTDPART_OFS_APPEND,
  85. .size = MTDPART_SIZ_FULL,
  86. },
  87. };
  88. static struct physmap_flash_data ap325rxa_nor_flash_data = {
  89. .width = 2,
  90. .parts = ap325rxa_nor_flash_partitions,
  91. .nr_parts = ARRAY_SIZE(ap325rxa_nor_flash_partitions),
  92. };
  93. static struct resource ap325rxa_nor_flash_resources[] = {
  94. [0] = {
  95. .name = "NOR Flash",
  96. .start = 0x00000000,
  97. .end = 0x00ffffff,
  98. .flags = IORESOURCE_MEM,
  99. }
  100. };
  101. static struct platform_device ap325rxa_nor_flash_device = {
  102. .name = "physmap-flash",
  103. .resource = ap325rxa_nor_flash_resources,
  104. .num_resources = ARRAY_SIZE(ap325rxa_nor_flash_resources),
  105. .dev = {
  106. .platform_data = &ap325rxa_nor_flash_data,
  107. },
  108. };
  109. static struct mtd_partition nand_partition_info[] = {
  110. {
  111. .name = "nand_data",
  112. .offset = 0,
  113. .size = MTDPART_SIZ_FULL,
  114. },
  115. };
  116. static struct resource nand_flash_resources[] = {
  117. [0] = {
  118. .start = 0xa4530000,
  119. .end = 0xa45300ff,
  120. .flags = IORESOURCE_MEM,
  121. }
  122. };
  123. static struct sh_flctl_platform_data nand_flash_data = {
  124. .parts = nand_partition_info,
  125. .nr_parts = ARRAY_SIZE(nand_partition_info),
  126. .flcmncr_val = FCKSEL_E | TYPESEL_SET | NANWF_E,
  127. .has_hwecc = 1,
  128. };
  129. static struct platform_device nand_flash_device = {
  130. .name = "sh_flctl",
  131. .resource = nand_flash_resources,
  132. .num_resources = ARRAY_SIZE(nand_flash_resources),
  133. .dev = {
  134. .platform_data = &nand_flash_data,
  135. },
  136. };
  137. #define FPGA_LCDREG 0xB4100180
  138. #define FPGA_BKLREG 0xB4100212
  139. #define FPGA_LCDREG_VAL 0x0018
  140. #define PORT_MSELCRB 0xA4050182
  141. #define PORT_HIZCRC 0xA405015C
  142. #define PORT_DRVCRA 0xA405018A
  143. #define PORT_DRVCRB 0xA405018C
  144. static void ap320_wvga_power_on(void *board_data)
  145. {
  146. msleep(100);
  147. /* ASD AP-320/325 LCD ON */
  148. ctrl_outw(FPGA_LCDREG_VAL, FPGA_LCDREG);
  149. /* backlight */
  150. gpio_set_value(GPIO_PTS3, 0);
  151. ctrl_outw(0x100, FPGA_BKLREG);
  152. }
  153. static void ap320_wvga_power_off(void *board_data)
  154. {
  155. /* backlight */
  156. ctrl_outw(0, FPGA_BKLREG);
  157. gpio_set_value(GPIO_PTS3, 1);
  158. /* ASD AP-320/325 LCD OFF */
  159. ctrl_outw(0, FPGA_LCDREG);
  160. }
  161. static struct sh_mobile_lcdc_info lcdc_info = {
  162. .clock_source = LCDC_CLK_EXTERNAL,
  163. .ch[0] = {
  164. .chan = LCDC_CHAN_MAINLCD,
  165. .bpp = 16,
  166. .interface_type = RGB18,
  167. .clock_divider = 1,
  168. .lcd_cfg = {
  169. .name = "LB070WV1",
  170. .xres = 800,
  171. .yres = 480,
  172. .left_margin = 40,
  173. .right_margin = 160,
  174. .hsync_len = 8,
  175. .upper_margin = 63,
  176. .lower_margin = 80,
  177. .vsync_len = 1,
  178. .sync = 0, /* hsync and vsync are active low */
  179. },
  180. .lcd_size_cfg = { /* 7.0 inch */
  181. .width = 152,
  182. .height = 91,
  183. },
  184. .board_cfg = {
  185. .display_on = ap320_wvga_power_on,
  186. .display_off = ap320_wvga_power_off,
  187. },
  188. }
  189. };
  190. static struct resource lcdc_resources[] = {
  191. [0] = {
  192. .name = "LCDC",
  193. .start = 0xfe940000, /* P4-only space */
  194. .end = 0xfe941fff,
  195. .flags = IORESOURCE_MEM,
  196. },
  197. [1] = {
  198. .start = 28,
  199. .flags = IORESOURCE_IRQ,
  200. },
  201. };
  202. static struct platform_device lcdc_device = {
  203. .name = "sh_mobile_lcdc_fb",
  204. .num_resources = ARRAY_SIZE(lcdc_resources),
  205. .resource = lcdc_resources,
  206. .dev = {
  207. .platform_data = &lcdc_info,
  208. },
  209. };
  210. static void camera_power(int val)
  211. {
  212. gpio_set_value(GPIO_PTZ5, val); /* RST_CAM/RSTB */
  213. mdelay(10);
  214. }
  215. #ifdef CONFIG_I2C
  216. /* support for the old ncm03j camera */
  217. static unsigned char camera_ncm03j_magic[] =
  218. {
  219. 0x87, 0x00, 0x88, 0x08, 0x89, 0x01, 0x8A, 0xE8,
  220. 0x1D, 0x00, 0x1E, 0x8A, 0x21, 0x00, 0x33, 0x36,
  221. 0x36, 0x60, 0x37, 0x08, 0x3B, 0x31, 0x44, 0x0F,
  222. 0x46, 0xF0, 0x4B, 0x28, 0x4C, 0x21, 0x4D, 0x55,
  223. 0x4E, 0x1B, 0x4F, 0xC7, 0x50, 0xFC, 0x51, 0x12,
  224. 0x58, 0x02, 0x66, 0xC0, 0x67, 0x46, 0x6B, 0xA0,
  225. 0x6C, 0x34, 0x7E, 0x25, 0x7F, 0x25, 0x8D, 0x0F,
  226. 0x92, 0x40, 0x93, 0x04, 0x94, 0x26, 0x95, 0x0A,
  227. 0x99, 0x03, 0x9A, 0xF0, 0x9B, 0x14, 0x9D, 0x7A,
  228. 0xC5, 0x02, 0xD6, 0x07, 0x59, 0x00, 0x5A, 0x1A,
  229. 0x5B, 0x2A, 0x5C, 0x37, 0x5D, 0x42, 0x5E, 0x56,
  230. 0xC8, 0x00, 0xC9, 0x1A, 0xCA, 0x2A, 0xCB, 0x37,
  231. 0xCC, 0x42, 0xCD, 0x56, 0xCE, 0x00, 0xCF, 0x1A,
  232. 0xD0, 0x2A, 0xD1, 0x37, 0xD2, 0x42, 0xD3, 0x56,
  233. 0x5F, 0x68, 0x60, 0x87, 0x61, 0xA3, 0x62, 0xBC,
  234. 0x63, 0xD4, 0x64, 0xEA, 0xD6, 0x0F,
  235. };
  236. static int camera_probe(void)
  237. {
  238. struct i2c_adapter *a = i2c_get_adapter(0);
  239. struct i2c_msg msg;
  240. int ret;
  241. camera_power(1);
  242. msg.addr = 0x6e;
  243. msg.buf = camera_ncm03j_magic;
  244. msg.len = 2;
  245. msg.flags = 0;
  246. ret = i2c_transfer(a, &msg, 1);
  247. camera_power(0);
  248. return ret;
  249. }
  250. static int camera_set_capture(struct soc_camera_platform_info *info,
  251. int enable)
  252. {
  253. struct i2c_adapter *a = i2c_get_adapter(0);
  254. struct i2c_msg msg;
  255. int ret = 0;
  256. int i;
  257. camera_power(0);
  258. if (!enable)
  259. return 0; /* no disable for now */
  260. camera_power(1);
  261. for (i = 0; i < ARRAY_SIZE(camera_ncm03j_magic); i += 2) {
  262. u_int8_t buf[8];
  263. msg.addr = 0x6e;
  264. msg.buf = buf;
  265. msg.len = 2;
  266. msg.flags = 0;
  267. buf[0] = camera_ncm03j_magic[i];
  268. buf[1] = camera_ncm03j_magic[i + 1];
  269. ret = (ret < 0) ? ret : i2c_transfer(a, &msg, 1);
  270. }
  271. return ret;
  272. }
  273. static struct soc_camera_platform_info camera_info = {
  274. .iface = 0,
  275. .format_name = "UYVY",
  276. .format_depth = 16,
  277. .format = {
  278. .pixelformat = V4L2_PIX_FMT_UYVY,
  279. .colorspace = V4L2_COLORSPACE_SMPTE170M,
  280. .width = 640,
  281. .height = 480,
  282. },
  283. .bus_param = SOCAM_PCLK_SAMPLE_RISING | SOCAM_HSYNC_ACTIVE_HIGH |
  284. SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_DATAWIDTH_8,
  285. .set_capture = camera_set_capture,
  286. };
  287. static struct platform_device camera_device = {
  288. .name = "soc_camera_platform",
  289. .dev = {
  290. .platform_data = &camera_info,
  291. },
  292. };
  293. static int __init camera_setup(void)
  294. {
  295. if (camera_probe() > 0)
  296. platform_device_register(&camera_device);
  297. return 0;
  298. }
  299. late_initcall(camera_setup);
  300. #endif /* CONFIG_I2C */
  301. static int ov7725_power(struct device *dev, int mode)
  302. {
  303. camera_power(0);
  304. if (mode)
  305. camera_power(1);
  306. return 0;
  307. }
  308. static struct ov772x_camera_info ov7725_info = {
  309. .buswidth = SOCAM_DATAWIDTH_8,
  310. .flags = OV772X_FLAG_VFLIP | OV772X_FLAG_HFLIP,
  311. .edgectrl = OV772X_AUTO_EDGECTRL(0xf, 0),
  312. .link = {
  313. .power = ov7725_power,
  314. },
  315. };
  316. static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
  317. .flags = SH_CEU_FLAG_USE_8BIT_BUS,
  318. };
  319. static struct resource ceu_resources[] = {
  320. [0] = {
  321. .name = "CEU",
  322. .start = 0xfe910000,
  323. .end = 0xfe91009f,
  324. .flags = IORESOURCE_MEM,
  325. },
  326. [1] = {
  327. .start = 52,
  328. .flags = IORESOURCE_IRQ,
  329. },
  330. [2] = {
  331. /* place holder for contiguous memory */
  332. },
  333. };
  334. static struct platform_device ceu_device = {
  335. .name = "sh_mobile_ceu",
  336. .id = 0, /* "ceu0" clock */
  337. .num_resources = ARRAY_SIZE(ceu_resources),
  338. .resource = ceu_resources,
  339. .dev = {
  340. .platform_data = &sh_mobile_ceu_info,
  341. },
  342. };
  343. struct spi_gpio_platform_data sdcard_cn3_platform_data = {
  344. .sck = GPIO_PTD0,
  345. .mosi = GPIO_PTD1,
  346. .miso = GPIO_PTD2,
  347. .num_chipselect = 1,
  348. };
  349. static struct platform_device sdcard_cn3_device = {
  350. .name = "spi_gpio",
  351. .dev = {
  352. .platform_data = &sdcard_cn3_platform_data,
  353. },
  354. };
  355. static struct platform_device *ap325rxa_devices[] __initdata = {
  356. &smsc9118_device,
  357. &ap325rxa_nor_flash_device,
  358. &lcdc_device,
  359. &ceu_device,
  360. &nand_flash_device,
  361. &sdcard_cn3_device,
  362. };
  363. static struct i2c_board_info __initdata ap325rxa_i2c_devices[] = {
  364. {
  365. I2C_BOARD_INFO("pcf8563", 0x51),
  366. },
  367. {
  368. I2C_BOARD_INFO("ov772x", 0x21),
  369. .platform_data = &ov7725_info,
  370. },
  371. };
  372. static struct spi_board_info ap325rxa_spi_devices[] = {
  373. {
  374. .modalias = "mmc_spi",
  375. .max_speed_hz = 5000000,
  376. .chip_select = 0,
  377. .controller_data = (void *) GPIO_PTD5,
  378. },
  379. };
  380. static int __init ap325rxa_devices_setup(void)
  381. {
  382. /* LD3 and LD4 LEDs */
  383. gpio_request(GPIO_PTX5, NULL); /* RUN */
  384. gpio_direction_output(GPIO_PTX5, 1);
  385. gpio_export(GPIO_PTX5, 0);
  386. gpio_request(GPIO_PTX4, NULL); /* INDICATOR */
  387. gpio_direction_output(GPIO_PTX4, 0);
  388. gpio_export(GPIO_PTX4, 0);
  389. /* SW1 input */
  390. gpio_request(GPIO_PTF7, NULL); /* MODE */
  391. gpio_direction_input(GPIO_PTF7);
  392. gpio_export(GPIO_PTF7, 0);
  393. /* LCDC */
  394. gpio_request(GPIO_FN_LCDD15, NULL);
  395. gpio_request(GPIO_FN_LCDD14, NULL);
  396. gpio_request(GPIO_FN_LCDD13, NULL);
  397. gpio_request(GPIO_FN_LCDD12, NULL);
  398. gpio_request(GPIO_FN_LCDD11, NULL);
  399. gpio_request(GPIO_FN_LCDD10, NULL);
  400. gpio_request(GPIO_FN_LCDD9, NULL);
  401. gpio_request(GPIO_FN_LCDD8, NULL);
  402. gpio_request(GPIO_FN_LCDD7, NULL);
  403. gpio_request(GPIO_FN_LCDD6, NULL);
  404. gpio_request(GPIO_FN_LCDD5, NULL);
  405. gpio_request(GPIO_FN_LCDD4, NULL);
  406. gpio_request(GPIO_FN_LCDD3, NULL);
  407. gpio_request(GPIO_FN_LCDD2, NULL);
  408. gpio_request(GPIO_FN_LCDD1, NULL);
  409. gpio_request(GPIO_FN_LCDD0, NULL);
  410. gpio_request(GPIO_FN_LCDLCLK_PTR, NULL);
  411. gpio_request(GPIO_FN_LCDDCK, NULL);
  412. gpio_request(GPIO_FN_LCDVEPWC, NULL);
  413. gpio_request(GPIO_FN_LCDVCPWC, NULL);
  414. gpio_request(GPIO_FN_LCDVSYN, NULL);
  415. gpio_request(GPIO_FN_LCDHSYN, NULL);
  416. gpio_request(GPIO_FN_LCDDISP, NULL);
  417. gpio_request(GPIO_FN_LCDDON, NULL);
  418. /* LCD backlight */
  419. gpio_request(GPIO_PTS3, NULL);
  420. gpio_direction_output(GPIO_PTS3, 1);
  421. /* CEU */
  422. gpio_request(GPIO_FN_VIO_CLK2, NULL);
  423. gpio_request(GPIO_FN_VIO_VD2, NULL);
  424. gpio_request(GPIO_FN_VIO_HD2, NULL);
  425. gpio_request(GPIO_FN_VIO_FLD, NULL);
  426. gpio_request(GPIO_FN_VIO_CKO, NULL);
  427. gpio_request(GPIO_FN_VIO_D15, NULL);
  428. gpio_request(GPIO_FN_VIO_D14, NULL);
  429. gpio_request(GPIO_FN_VIO_D13, NULL);
  430. gpio_request(GPIO_FN_VIO_D12, NULL);
  431. gpio_request(GPIO_FN_VIO_D11, NULL);
  432. gpio_request(GPIO_FN_VIO_D10, NULL);
  433. gpio_request(GPIO_FN_VIO_D9, NULL);
  434. gpio_request(GPIO_FN_VIO_D8, NULL);
  435. gpio_request(GPIO_PTZ7, NULL);
  436. gpio_direction_output(GPIO_PTZ7, 0); /* OE_CAM */
  437. gpio_request(GPIO_PTZ6, NULL);
  438. gpio_direction_output(GPIO_PTZ6, 0); /* STBY_CAM */
  439. gpio_request(GPIO_PTZ5, NULL);
  440. gpio_direction_output(GPIO_PTZ5, 0); /* RST_CAM */
  441. gpio_request(GPIO_PTZ4, NULL);
  442. gpio_direction_output(GPIO_PTZ4, 0); /* SADDR */
  443. ctrl_outw(ctrl_inw(PORT_MSELCRB) & ~0x0001, PORT_MSELCRB);
  444. /* FLCTL */
  445. gpio_request(GPIO_FN_FCE, NULL);
  446. gpio_request(GPIO_FN_NAF7, NULL);
  447. gpio_request(GPIO_FN_NAF6, NULL);
  448. gpio_request(GPIO_FN_NAF5, NULL);
  449. gpio_request(GPIO_FN_NAF4, NULL);
  450. gpio_request(GPIO_FN_NAF3, NULL);
  451. gpio_request(GPIO_FN_NAF2, NULL);
  452. gpio_request(GPIO_FN_NAF1, NULL);
  453. gpio_request(GPIO_FN_NAF0, NULL);
  454. gpio_request(GPIO_FN_FCDE, NULL);
  455. gpio_request(GPIO_FN_FOE, NULL);
  456. gpio_request(GPIO_FN_FSC, NULL);
  457. gpio_request(GPIO_FN_FWE, NULL);
  458. gpio_request(GPIO_FN_FRB, NULL);
  459. ctrl_outw(0, PORT_HIZCRC);
  460. ctrl_outw(0xFFFF, PORT_DRVCRA);
  461. ctrl_outw(0xFFFF, PORT_DRVCRB);
  462. platform_resource_setup_memory(&ceu_device, "ceu", 4 << 20);
  463. i2c_register_board_info(0, ap325rxa_i2c_devices,
  464. ARRAY_SIZE(ap325rxa_i2c_devices));
  465. spi_register_board_info(ap325rxa_spi_devices,
  466. ARRAY_SIZE(ap325rxa_spi_devices));
  467. return platform_add_devices(ap325rxa_devices,
  468. ARRAY_SIZE(ap325rxa_devices));
  469. }
  470. device_initcall(ap325rxa_devices_setup);
  471. static struct sh_machine_vector mv_ap325rxa __initmv = {
  472. .mv_name = "AP-325RXA",
  473. };