board-dm365-evm.c 20 KB

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