board-dm365-evm.c 18 KB

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