board-dm365-evm.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. /*
  2. * TI DaVinci DM365 EVM board support
  3. *
  4. * Copyright (C) 2009 Texas Instruments Incorporated
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation version 2.
  9. *
  10. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  11. * kind, whether express or implied; without even the implied warranty
  12. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/err.h>
  18. #include <linux/i2c.h>
  19. #include <linux/io.h>
  20. #include <linux/clk.h>
  21. #include <linux/platform_data/at24.h>
  22. #include <linux/leds.h>
  23. #include <linux/mtd/mtd.h>
  24. #include <linux/mtd/partitions.h>
  25. #include <linux/slab.h>
  26. #include <linux/mtd/rawnand.h>
  27. #include <linux/input.h>
  28. #include <linux/spi/spi.h>
  29. #include <linux/spi/eeprom.h>
  30. #include <linux/v4l2-dv-timings.h>
  31. #include <linux/platform_data/ti-aemif.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/mach/arch.h>
  34. #include <mach/mux.h>
  35. #include <mach/common.h>
  36. #include <linux/platform_data/i2c-davinci.h>
  37. #include <mach/serial.h>
  38. #include <linux/platform_data/mmc-davinci.h>
  39. #include <linux/platform_data/mtd-davinci.h>
  40. #include <linux/platform_data/keyscan-davinci.h>
  41. #include <media/i2c/ths7303.h>
  42. #include <media/i2c/tvp514x.h>
  43. #include "davinci.h"
  44. static inline int have_imager(void)
  45. {
  46. /* REVISIT when it's supported, trigger via Kconfig */
  47. return 0;
  48. }
  49. static inline int have_tvp7002(void)
  50. {
  51. /* REVISIT when it's supported, trigger via Kconfig */
  52. return 0;
  53. }
  54. #define DM365_EVM_PHY_ID "davinci_mdio-0:01"
  55. /*
  56. * A MAX-II CPLD is used for various board control functions.
  57. */
  58. #define CPLD_OFFSET(a13a8,a2a1) (((a13a8) << 10) + ((a2a1) << 3))
  59. #define CPLD_VERSION CPLD_OFFSET(0,0) /* r/o */
  60. #define CPLD_TEST CPLD_OFFSET(0,1)
  61. #define CPLD_LEDS CPLD_OFFSET(0,2)
  62. #define CPLD_MUX CPLD_OFFSET(0,3)
  63. #define CPLD_SWITCH CPLD_OFFSET(1,0) /* r/o */
  64. #define CPLD_POWER CPLD_OFFSET(1,1)
  65. #define CPLD_VIDEO CPLD_OFFSET(1,2)
  66. #define CPLD_CARDSTAT CPLD_OFFSET(1,3) /* r/o */
  67. #define CPLD_DILC_OUT CPLD_OFFSET(2,0)
  68. #define CPLD_DILC_IN CPLD_OFFSET(2,1) /* r/o */
  69. #define CPLD_IMG_DIR0 CPLD_OFFSET(2,2)
  70. #define CPLD_IMG_MUX0 CPLD_OFFSET(2,3)
  71. #define CPLD_IMG_MUX1 CPLD_OFFSET(3,0)
  72. #define CPLD_IMG_DIR1 CPLD_OFFSET(3,1)
  73. #define CPLD_IMG_MUX2 CPLD_OFFSET(3,2)
  74. #define CPLD_IMG_MUX3 CPLD_OFFSET(3,3)
  75. #define CPLD_IMG_DIR2 CPLD_OFFSET(4,0)
  76. #define CPLD_IMG_MUX4 CPLD_OFFSET(4,1)
  77. #define CPLD_IMG_MUX5 CPLD_OFFSET(4,2)
  78. #define CPLD_RESETS CPLD_OFFSET(4,3)
  79. #define CPLD_CCD_DIR1 CPLD_OFFSET(0x3e,0)
  80. #define CPLD_CCD_IO1 CPLD_OFFSET(0x3e,1)
  81. #define CPLD_CCD_DIR2 CPLD_OFFSET(0x3e,2)
  82. #define CPLD_CCD_IO2 CPLD_OFFSET(0x3e,3)
  83. #define CPLD_CCD_DIR3 CPLD_OFFSET(0x3f,0)
  84. #define CPLD_CCD_IO3 CPLD_OFFSET(0x3f,1)
  85. static void __iomem *cpld;
  86. /* NOTE: this is geared for the standard config, with a socketed
  87. * 2 GByte Micron NAND (MT29F16G08FAA) using 128KB sectors. If you
  88. * swap chips with a different block size, partitioning will
  89. * need to be changed. This NAND chip MT29F16G08FAA is the default
  90. * NAND shipped with the Spectrum Digital DM365 EVM
  91. */
  92. #define NAND_BLOCK_SIZE SZ_128K
  93. static struct mtd_partition davinci_nand_partitions[] = {
  94. {
  95. /* UBL (a few copies) plus U-Boot */
  96. .name = "bootloader",
  97. .offset = 0,
  98. .size = 30 * NAND_BLOCK_SIZE,
  99. .mask_flags = MTD_WRITEABLE, /* force read-only */
  100. }, {
  101. /* U-Boot environment */
  102. .name = "params",
  103. .offset = MTDPART_OFS_APPEND,
  104. .size = 2 * NAND_BLOCK_SIZE,
  105. .mask_flags = 0,
  106. }, {
  107. .name = "kernel",
  108. .offset = MTDPART_OFS_APPEND,
  109. .size = SZ_4M,
  110. .mask_flags = 0,
  111. }, {
  112. .name = "filesystem1",
  113. .offset = MTDPART_OFS_APPEND,
  114. .size = SZ_512M,
  115. .mask_flags = 0,
  116. }, {
  117. .name = "filesystem2",
  118. .offset = MTDPART_OFS_APPEND,
  119. .size = MTDPART_SIZ_FULL,
  120. .mask_flags = 0,
  121. }
  122. /* two blocks with bad block table (and mirror) at the end */
  123. };
  124. static struct davinci_nand_pdata davinci_nand_data = {
  125. .core_chipsel = 0,
  126. .mask_chipsel = BIT(14),
  127. .parts = davinci_nand_partitions,
  128. .nr_parts = ARRAY_SIZE(davinci_nand_partitions),
  129. .ecc_mode = NAND_ECC_HW,
  130. .bbt_options = NAND_BBT_USE_FLASH,
  131. .ecc_bits = 4,
  132. };
  133. static struct resource davinci_nand_resources[] = {
  134. {
  135. .start = DM365_ASYNC_EMIF_DATA_CE0_BASE,
  136. .end = DM365_ASYNC_EMIF_DATA_CE0_BASE + SZ_32M - 1,
  137. .flags = IORESOURCE_MEM,
  138. }, {
  139. .start = DM365_ASYNC_EMIF_CONTROL_BASE,
  140. .end = DM365_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
  141. .flags = IORESOURCE_MEM,
  142. },
  143. };
  144. static struct platform_device davinci_aemif_devices[] = {
  145. {
  146. .name = "davinci_nand",
  147. .id = 0,
  148. .num_resources = ARRAY_SIZE(davinci_nand_resources),
  149. .resource = davinci_nand_resources,
  150. .dev = {
  151. .platform_data = &davinci_nand_data,
  152. },
  153. }
  154. };
  155. static struct resource davinci_aemif_resources[] = {
  156. {
  157. .start = DM365_ASYNC_EMIF_CONTROL_BASE,
  158. .end = DM365_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
  159. .flags = IORESOURCE_MEM,
  160. },
  161. };
  162. static struct aemif_abus_data da850_evm_aemif_abus_data[] = {
  163. {
  164. .cs = 1,
  165. },
  166. };
  167. static struct aemif_platform_data davinci_aemif_pdata = {
  168. .abus_data = da850_evm_aemif_abus_data,
  169. .num_abus_data = ARRAY_SIZE(da850_evm_aemif_abus_data),
  170. .sub_devices = davinci_aemif_devices,
  171. .num_sub_devices = ARRAY_SIZE(davinci_aemif_devices),
  172. };
  173. static struct platform_device davinci_aemif_device = {
  174. .name = "ti-aemif",
  175. .id = -1,
  176. .dev = {
  177. .platform_data = &davinci_aemif_pdata,
  178. },
  179. .resource = davinci_aemif_resources,
  180. .num_resources = ARRAY_SIZE(davinci_aemif_resources),
  181. };
  182. static struct at24_platform_data eeprom_info = {
  183. .byte_len = (256*1024) / 8,
  184. .page_size = 64,
  185. .flags = AT24_FLAG_ADDR16,
  186. .setup = davinci_get_mac_addr,
  187. .context = (void *)0x7f00,
  188. };
  189. static struct i2c_board_info i2c_info[] = {
  190. {
  191. I2C_BOARD_INFO("24c256", 0x50),
  192. .platform_data = &eeprom_info,
  193. },
  194. {
  195. I2C_BOARD_INFO("tlv320aic3x", 0x18),
  196. },
  197. };
  198. static struct davinci_i2c_platform_data i2c_pdata = {
  199. .bus_freq = 400 /* kHz */,
  200. .bus_delay = 0 /* usec */,
  201. };
  202. static int dm365evm_keyscan_enable(struct device *dev)
  203. {
  204. return davinci_cfg_reg(DM365_KEYSCAN);
  205. }
  206. static unsigned short dm365evm_keymap[] = {
  207. KEY_KP2,
  208. KEY_LEFT,
  209. KEY_EXIT,
  210. KEY_DOWN,
  211. KEY_ENTER,
  212. KEY_UP,
  213. KEY_KP1,
  214. KEY_RIGHT,
  215. KEY_MENU,
  216. KEY_RECORD,
  217. KEY_REWIND,
  218. KEY_KPMINUS,
  219. KEY_STOP,
  220. KEY_FASTFORWARD,
  221. KEY_KPPLUS,
  222. KEY_PLAYPAUSE,
  223. 0
  224. };
  225. static struct davinci_ks_platform_data dm365evm_ks_data = {
  226. .device_enable = dm365evm_keyscan_enable,
  227. .keymap = dm365evm_keymap,
  228. .keymapsize = ARRAY_SIZE(dm365evm_keymap),
  229. .rep = 1,
  230. /* Scan period = strobe + interval */
  231. .strobe = 0x5,
  232. .interval = 0x2,
  233. .matrix_type = DAVINCI_KEYSCAN_MATRIX_4X4,
  234. };
  235. static int cpld_mmc_get_cd(int module)
  236. {
  237. if (!cpld)
  238. return -ENXIO;
  239. /* low == card present */
  240. return !(__raw_readb(cpld + CPLD_CARDSTAT) & BIT(module ? 4 : 0));
  241. }
  242. static int cpld_mmc_get_ro(int module)
  243. {
  244. if (!cpld)
  245. return -ENXIO;
  246. /* high == card's write protect switch active */
  247. return !!(__raw_readb(cpld + CPLD_CARDSTAT) & BIT(module ? 5 : 1));
  248. }
  249. static struct davinci_mmc_config dm365evm_mmc_config = {
  250. .get_cd = cpld_mmc_get_cd,
  251. .get_ro = cpld_mmc_get_ro,
  252. .wires = 4,
  253. .max_freq = 50000000,
  254. .caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
  255. };
  256. static void dm365evm_emac_configure(void)
  257. {
  258. /*
  259. * EMAC pins are multiplexed with GPIO and UART
  260. * Further details are available at the DM365 ARM
  261. * Subsystem Users Guide(sprufg5.pdf) pages 125 - 127
  262. */
  263. davinci_cfg_reg(DM365_EMAC_TX_EN);
  264. davinci_cfg_reg(DM365_EMAC_TX_CLK);
  265. davinci_cfg_reg(DM365_EMAC_COL);
  266. davinci_cfg_reg(DM365_EMAC_TXD3);
  267. davinci_cfg_reg(DM365_EMAC_TXD2);
  268. davinci_cfg_reg(DM365_EMAC_TXD1);
  269. davinci_cfg_reg(DM365_EMAC_TXD0);
  270. davinci_cfg_reg(DM365_EMAC_RXD3);
  271. davinci_cfg_reg(DM365_EMAC_RXD2);
  272. davinci_cfg_reg(DM365_EMAC_RXD1);
  273. davinci_cfg_reg(DM365_EMAC_RXD0);
  274. davinci_cfg_reg(DM365_EMAC_RX_CLK);
  275. davinci_cfg_reg(DM365_EMAC_RX_DV);
  276. davinci_cfg_reg(DM365_EMAC_RX_ER);
  277. davinci_cfg_reg(DM365_EMAC_CRS);
  278. davinci_cfg_reg(DM365_EMAC_MDIO);
  279. davinci_cfg_reg(DM365_EMAC_MDCLK);
  280. /*
  281. * EMAC interrupts are multiplexed with GPIO interrupts
  282. * Details are available at the DM365 ARM
  283. * Subsystem Users Guide(sprufg5.pdf) pages 133 - 134
  284. */
  285. davinci_cfg_reg(DM365_INT_EMAC_RXTHRESH);
  286. davinci_cfg_reg(DM365_INT_EMAC_RXPULSE);
  287. davinci_cfg_reg(DM365_INT_EMAC_TXPULSE);
  288. davinci_cfg_reg(DM365_INT_EMAC_MISCPULSE);
  289. }
  290. static void dm365evm_mmc_configure(void)
  291. {
  292. /*
  293. * MMC/SD pins are multiplexed with GPIO and EMIF
  294. * Further details are available at the DM365 ARM
  295. * Subsystem Users Guide(sprufg5.pdf) pages 118, 128 - 131
  296. */
  297. davinci_cfg_reg(DM365_SD1_CLK);
  298. davinci_cfg_reg(DM365_SD1_CMD);
  299. davinci_cfg_reg(DM365_SD1_DATA3);
  300. davinci_cfg_reg(DM365_SD1_DATA2);
  301. davinci_cfg_reg(DM365_SD1_DATA1);
  302. davinci_cfg_reg(DM365_SD1_DATA0);
  303. }
  304. static struct tvp514x_platform_data tvp5146_pdata = {
  305. .clk_polarity = 0,
  306. .hs_polarity = 1,
  307. .vs_polarity = 1
  308. };
  309. #define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
  310. /* Inputs available at the TVP5146 */
  311. static struct v4l2_input tvp5146_inputs[] = {
  312. {
  313. .index = 0,
  314. .name = "Composite",
  315. .type = V4L2_INPUT_TYPE_CAMERA,
  316. .std = TVP514X_STD_ALL,
  317. },
  318. {
  319. .index = 1,
  320. .name = "S-Video",
  321. .type = V4L2_INPUT_TYPE_CAMERA,
  322. .std = TVP514X_STD_ALL,
  323. },
  324. };
  325. /*
  326. * this is the route info for connecting each input to decoder
  327. * ouput that goes to vpfe. There is a one to one correspondence
  328. * with tvp5146_inputs
  329. */
  330. static struct vpfe_route tvp5146_routes[] = {
  331. {
  332. .input = INPUT_CVBS_VI2B,
  333. .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
  334. },
  335. {
  336. .input = INPUT_SVIDEO_VI2C_VI1C,
  337. .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
  338. },
  339. };
  340. static struct vpfe_subdev_info vpfe_sub_devs[] = {
  341. {
  342. .name = "tvp5146",
  343. .grp_id = 0,
  344. .num_inputs = ARRAY_SIZE(tvp5146_inputs),
  345. .inputs = tvp5146_inputs,
  346. .routes = tvp5146_routes,
  347. .can_route = 1,
  348. .ccdc_if_params = {
  349. .if_type = VPFE_BT656,
  350. .hdpol = VPFE_PINPOL_POSITIVE,
  351. .vdpol = VPFE_PINPOL_POSITIVE,
  352. },
  353. .board_info = {
  354. I2C_BOARD_INFO("tvp5146", 0x5d),
  355. .platform_data = &tvp5146_pdata,
  356. },
  357. },
  358. };
  359. static struct vpfe_config vpfe_cfg = {
  360. .num_subdevs = ARRAY_SIZE(vpfe_sub_devs),
  361. .sub_devs = vpfe_sub_devs,
  362. .i2c_adapter_id = 1,
  363. .card_name = "DM365 EVM",
  364. .ccdc = "ISIF",
  365. };
  366. /* venc standards timings */
  367. static struct vpbe_enc_mode_info dm365evm_enc_std_timing[] = {
  368. {
  369. .name = "ntsc",
  370. .timings_type = VPBE_ENC_STD,
  371. .std_id = V4L2_STD_NTSC,
  372. .interlaced = 1,
  373. .xres = 720,
  374. .yres = 480,
  375. .aspect = {11, 10},
  376. .fps = {30000, 1001},
  377. .left_margin = 0x79,
  378. .upper_margin = 0x10,
  379. },
  380. {
  381. .name = "pal",
  382. .timings_type = VPBE_ENC_STD,
  383. .std_id = V4L2_STD_PAL,
  384. .interlaced = 1,
  385. .xres = 720,
  386. .yres = 576,
  387. .aspect = {54, 59},
  388. .fps = {25, 1},
  389. .left_margin = 0x7E,
  390. .upper_margin = 0x16,
  391. },
  392. };
  393. /* venc dv timings */
  394. static struct vpbe_enc_mode_info dm365evm_enc_preset_timing[] = {
  395. {
  396. .name = "480p59_94",
  397. .timings_type = VPBE_ENC_DV_TIMINGS,
  398. .dv_timings = V4L2_DV_BT_CEA_720X480P59_94,
  399. .interlaced = 0,
  400. .xres = 720,
  401. .yres = 480,
  402. .aspect = {1, 1},
  403. .fps = {5994, 100},
  404. .left_margin = 0x8F,
  405. .upper_margin = 0x2D,
  406. },
  407. {
  408. .name = "576p50",
  409. .timings_type = VPBE_ENC_DV_TIMINGS,
  410. .dv_timings = V4L2_DV_BT_CEA_720X576P50,
  411. .interlaced = 0,
  412. .xres = 720,
  413. .yres = 576,
  414. .aspect = {1, 1},
  415. .fps = {50, 1},
  416. .left_margin = 0x8C,
  417. .upper_margin = 0x36,
  418. },
  419. {
  420. .name = "720p60",
  421. .timings_type = VPBE_ENC_DV_TIMINGS,
  422. .dv_timings = V4L2_DV_BT_CEA_1280X720P60,
  423. .interlaced = 0,
  424. .xres = 1280,
  425. .yres = 720,
  426. .aspect = {1, 1},
  427. .fps = {60, 1},
  428. .left_margin = 0x117,
  429. .right_margin = 70,
  430. .upper_margin = 38,
  431. .lower_margin = 3,
  432. .hsync_len = 80,
  433. .vsync_len = 5,
  434. },
  435. {
  436. .name = "1080i60",
  437. .timings_type = VPBE_ENC_DV_TIMINGS,
  438. .dv_timings = V4L2_DV_BT_CEA_1920X1080I60,
  439. .interlaced = 1,
  440. .xres = 1920,
  441. .yres = 1080,
  442. .aspect = {1, 1},
  443. .fps = {30, 1},
  444. .left_margin = 0xc9,
  445. .right_margin = 80,
  446. .upper_margin = 30,
  447. .lower_margin = 3,
  448. .hsync_len = 88,
  449. .vsync_len = 5,
  450. },
  451. };
  452. #define VENC_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
  453. /*
  454. * The outputs available from VPBE + ecnoders. Keep the
  455. * the order same as that of encoders. First those from venc followed by that
  456. * from encoders. Index in the output refers to index on a particular
  457. * encoder.Driver uses this index to pass it to encoder when it supports more
  458. * than one output. Application uses index of the array to set an output.
  459. */
  460. static struct vpbe_output dm365evm_vpbe_outputs[] = {
  461. {
  462. .output = {
  463. .index = 0,
  464. .name = "Composite",
  465. .type = V4L2_OUTPUT_TYPE_ANALOG,
  466. .std = VENC_STD_ALL,
  467. .capabilities = V4L2_OUT_CAP_STD,
  468. },
  469. .subdev_name = DM365_VPBE_VENC_SUBDEV_NAME,
  470. .default_mode = "ntsc",
  471. .num_modes = ARRAY_SIZE(dm365evm_enc_std_timing),
  472. .modes = dm365evm_enc_std_timing,
  473. .if_params = MEDIA_BUS_FMT_FIXED,
  474. },
  475. {
  476. .output = {
  477. .index = 1,
  478. .name = "Component",
  479. .type = V4L2_OUTPUT_TYPE_ANALOG,
  480. .capabilities = V4L2_OUT_CAP_DV_TIMINGS,
  481. },
  482. .subdev_name = DM365_VPBE_VENC_SUBDEV_NAME,
  483. .default_mode = "480p59_94",
  484. .num_modes = ARRAY_SIZE(dm365evm_enc_preset_timing),
  485. .modes = dm365evm_enc_preset_timing,
  486. .if_params = MEDIA_BUS_FMT_FIXED,
  487. },
  488. };
  489. /*
  490. * Amplifiers on the board
  491. */
  492. static struct ths7303_platform_data ths7303_pdata = {
  493. .ch_1 = 3,
  494. .ch_2 = 3,
  495. .ch_3 = 3,
  496. };
  497. static struct amp_config_info vpbe_amp = {
  498. .module_name = "ths7303",
  499. .is_i2c = 1,
  500. .board_info = {
  501. I2C_BOARD_INFO("ths7303", 0x2c),
  502. .platform_data = &ths7303_pdata,
  503. }
  504. };
  505. static struct vpbe_config dm365evm_display_cfg = {
  506. .module_name = "dm365-vpbe-display",
  507. .i2c_adapter_id = 1,
  508. .amp = &vpbe_amp,
  509. .osd = {
  510. .module_name = DM365_VPBE_OSD_SUBDEV_NAME,
  511. },
  512. .venc = {
  513. .module_name = DM365_VPBE_VENC_SUBDEV_NAME,
  514. },
  515. .num_outputs = ARRAY_SIZE(dm365evm_vpbe_outputs),
  516. .outputs = dm365evm_vpbe_outputs,
  517. };
  518. static void __init evm_init_i2c(void)
  519. {
  520. davinci_init_i2c(&i2c_pdata);
  521. i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
  522. }
  523. static inline int have_leds(void)
  524. {
  525. #ifdef CONFIG_LEDS_CLASS
  526. return 1;
  527. #else
  528. return 0;
  529. #endif
  530. }
  531. struct cpld_led {
  532. struct led_classdev cdev;
  533. u8 mask;
  534. };
  535. static const struct {
  536. const char *name;
  537. const char *trigger;
  538. } cpld_leds[] = {
  539. { "dm365evm::ds2", },
  540. { "dm365evm::ds3", },
  541. { "dm365evm::ds4", },
  542. { "dm365evm::ds5", },
  543. { "dm365evm::ds6", "nand-disk", },
  544. { "dm365evm::ds7", "mmc1", },
  545. { "dm365evm::ds8", "mmc0", },
  546. { "dm365evm::ds9", "heartbeat", },
  547. };
  548. static void cpld_led_set(struct led_classdev *cdev, enum led_brightness b)
  549. {
  550. struct cpld_led *led = container_of(cdev, struct cpld_led, cdev);
  551. u8 reg = __raw_readb(cpld + CPLD_LEDS);
  552. if (b != LED_OFF)
  553. reg &= ~led->mask;
  554. else
  555. reg |= led->mask;
  556. __raw_writeb(reg, cpld + CPLD_LEDS);
  557. }
  558. static enum led_brightness cpld_led_get(struct led_classdev *cdev)
  559. {
  560. struct cpld_led *led = container_of(cdev, struct cpld_led, cdev);
  561. u8 reg = __raw_readb(cpld + CPLD_LEDS);
  562. return (reg & led->mask) ? LED_OFF : LED_FULL;
  563. }
  564. static int __init cpld_leds_init(void)
  565. {
  566. int i;
  567. if (!have_leds() || !cpld)
  568. return 0;
  569. /* setup LEDs */
  570. __raw_writeb(0xff, cpld + CPLD_LEDS);
  571. for (i = 0; i < ARRAY_SIZE(cpld_leds); i++) {
  572. struct cpld_led *led;
  573. led = kzalloc(sizeof(*led), GFP_KERNEL);
  574. if (!led)
  575. break;
  576. led->cdev.name = cpld_leds[i].name;
  577. led->cdev.brightness_set = cpld_led_set;
  578. led->cdev.brightness_get = cpld_led_get;
  579. led->cdev.default_trigger = cpld_leds[i].trigger;
  580. led->mask = BIT(i);
  581. if (led_classdev_register(NULL, &led->cdev) < 0) {
  582. kfree(led);
  583. break;
  584. }
  585. }
  586. return 0;
  587. }
  588. /* run after subsys_initcall() for LEDs */
  589. fs_initcall(cpld_leds_init);
  590. static void __init evm_init_cpld(void)
  591. {
  592. u8 mux, resets;
  593. const char *label;
  594. struct clk *aemif_clk;
  595. int rc;
  596. /* Make sure we can configure the CPLD through CS1. Then
  597. * leave it on for later access to MMC and LED registers.
  598. */
  599. aemif_clk = clk_get(NULL, "aemif");
  600. if (IS_ERR(aemif_clk))
  601. return;
  602. clk_prepare_enable(aemif_clk);
  603. if (request_mem_region(DM365_ASYNC_EMIF_DATA_CE1_BASE, SECTION_SIZE,
  604. "cpld") == NULL)
  605. goto fail;
  606. cpld = ioremap(DM365_ASYNC_EMIF_DATA_CE1_BASE, SECTION_SIZE);
  607. if (!cpld) {
  608. release_mem_region(DM365_ASYNC_EMIF_DATA_CE1_BASE,
  609. SECTION_SIZE);
  610. fail:
  611. pr_err("ERROR: can't map CPLD\n");
  612. clk_disable_unprepare(aemif_clk);
  613. return;
  614. }
  615. /* External muxing for some signals */
  616. mux = 0;
  617. /* Read SW5 to set up NAND + keypad _or_ OneNAND (sync read).
  618. * NOTE: SW4 bus width setting must match!
  619. */
  620. if ((__raw_readb(cpld + CPLD_SWITCH) & BIT(5)) == 0) {
  621. /* external keypad mux */
  622. mux |= BIT(7);
  623. rc = platform_device_register(&davinci_aemif_device);
  624. if (rc)
  625. pr_warn("%s(): error registering the aemif device: %d\n",
  626. __func__, rc);
  627. } else {
  628. /* no OneNAND support yet */
  629. }
  630. /* Leave external chips in reset when unused. */
  631. resets = BIT(3) | BIT(2) | BIT(1) | BIT(0);
  632. /* Static video input config with SN74CBT16214 1-of-3 mux:
  633. * - port b1 == tvp7002 (mux lowbits == 1 or 6)
  634. * - port b2 == imager (mux lowbits == 2 or 7)
  635. * - port b3 == tvp5146 (mux lowbits == 5)
  636. *
  637. * Runtime switching could work too, with limitations.
  638. */
  639. if (have_imager()) {
  640. label = "HD imager";
  641. mux |= 2;
  642. /* externally mux MMC1/ENET/AIC33 to imager */
  643. mux |= BIT(6) | BIT(5) | BIT(3);
  644. } else {
  645. struct davinci_soc_info *soc_info = &davinci_soc_info;
  646. /* we can use MMC1 ... */
  647. dm365evm_mmc_configure();
  648. davinci_setup_mmc(1, &dm365evm_mmc_config);
  649. /* ... and ENET ... */
  650. dm365evm_emac_configure();
  651. soc_info->emac_pdata->phy_id = DM365_EVM_PHY_ID;
  652. resets &= ~BIT(3);
  653. /* ... and AIC33 */
  654. resets &= ~BIT(1);
  655. if (have_tvp7002()) {
  656. mux |= 1;
  657. resets &= ~BIT(2);
  658. label = "tvp7002 HD";
  659. } else {
  660. /* default to tvp5146 */
  661. mux |= 5;
  662. resets &= ~BIT(0);
  663. label = "tvp5146 SD";
  664. }
  665. }
  666. __raw_writeb(mux, cpld + CPLD_MUX);
  667. __raw_writeb(resets, cpld + CPLD_RESETS);
  668. pr_info("EVM: %s video input\n", label);
  669. /* REVISIT export switches: NTSC/PAL (SW5.6), EXTRA1 (SW5.2), etc */
  670. }
  671. static void __init dm365_evm_map_io(void)
  672. {
  673. dm365_init();
  674. }
  675. static struct spi_eeprom at25640 = {
  676. .byte_len = SZ_64K / 8,
  677. .name = "at25640",
  678. .page_size = 32,
  679. .flags = EE_ADDR2,
  680. };
  681. static const struct spi_board_info dm365_evm_spi_info[] __initconst = {
  682. {
  683. .modalias = "at25",
  684. .platform_data = &at25640,
  685. .max_speed_hz = 10 * 1000 * 1000,
  686. .bus_num = 0,
  687. .chip_select = 0,
  688. .mode = SPI_MODE_0,
  689. },
  690. };
  691. static __init void dm365_evm_init(void)
  692. {
  693. int ret;
  694. dm365_register_clocks();
  695. ret = dm365_gpio_register();
  696. if (ret)
  697. pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
  698. evm_init_i2c();
  699. davinci_serial_init(dm365_serial_device);
  700. dm365evm_emac_configure();
  701. dm365evm_mmc_configure();
  702. davinci_setup_mmc(0, &dm365evm_mmc_config);
  703. dm365_init_video(&vpfe_cfg, &dm365evm_display_cfg);
  704. /* maybe setup mmc1/etc ... _after_ mmc0 */
  705. evm_init_cpld();
  706. #ifdef CONFIG_SND_DM365_AIC3X_CODEC
  707. dm365_init_asp();
  708. #elif defined(CONFIG_SND_DM365_VOICE_CODEC)
  709. dm365_init_vc();
  710. #endif
  711. dm365_init_rtc();
  712. dm365_init_ks(&dm365evm_ks_data);
  713. dm365_init_spi0(BIT(0), dm365_evm_spi_info,
  714. ARRAY_SIZE(dm365_evm_spi_info));
  715. }
  716. MACHINE_START(DAVINCI_DM365_EVM, "DaVinci DM365 EVM")
  717. .atag_offset = 0x100,
  718. .map_io = dm365_evm_map_io,
  719. .init_irq = davinci_irq_init,
  720. .init_time = dm365_init_time,
  721. .init_machine = dm365_evm_init,
  722. .init_late = davinci_init_late,
  723. .dma_zone_size = SZ_128M,
  724. MACHINE_END