board-dm355-evm.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * TI DaVinci EVM board support
  4. *
  5. * Author: Kevin Hilman, Deep Root Systems, LLC
  6. *
  7. * 2007 (c) MontaVista Software, Inc.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/err.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/mtd/mtd.h>
  14. #include <linux/mtd/partitions.h>
  15. #include <linux/mtd/rawnand.h>
  16. #include <linux/i2c.h>
  17. #include <linux/gpio.h>
  18. #include <linux/gpio/machine.h>
  19. #include <linux/clk.h>
  20. #include <linux/dm9000.h>
  21. #include <linux/videodev2.h>
  22. #include <media/i2c/tvp514x.h>
  23. #include <linux/spi/spi.h>
  24. #include <linux/spi/eeprom.h>
  25. #include <linux/platform_data/gpio-davinci.h>
  26. #include <linux/platform_data/i2c-davinci.h>
  27. #include <linux/platform_data/mtd-davinci.h>
  28. #include <linux/platform_data/mmc-davinci.h>
  29. #include <linux/platform_data/usb-davinci.h>
  30. #include <asm/mach-types.h>
  31. #include <asm/mach/arch.h>
  32. #include "serial.h"
  33. #include "common.h"
  34. #include "davinci.h"
  35. /* NOTE: this is geared for the standard config, with a socketed
  36. * 2 GByte Micron NAND (MT29F16G08FAA) using 128KB sectors. If you
  37. * swap chips, maybe with a different block size, partitioning may
  38. * need to be changed.
  39. */
  40. #define NAND_BLOCK_SIZE SZ_128K
  41. static struct mtd_partition davinci_nand_partitions[] = {
  42. {
  43. /* UBL (a few copies) plus U-Boot */
  44. .name = "bootloader",
  45. .offset = 0,
  46. .size = 15 * NAND_BLOCK_SIZE,
  47. .mask_flags = MTD_WRITEABLE, /* force read-only */
  48. }, {
  49. /* U-Boot environment */
  50. .name = "params",
  51. .offset = MTDPART_OFS_APPEND,
  52. .size = 1 * NAND_BLOCK_SIZE,
  53. .mask_flags = 0,
  54. }, {
  55. .name = "kernel",
  56. .offset = MTDPART_OFS_APPEND,
  57. .size = SZ_4M,
  58. .mask_flags = 0,
  59. }, {
  60. .name = "filesystem1",
  61. .offset = MTDPART_OFS_APPEND,
  62. .size = SZ_512M,
  63. .mask_flags = 0,
  64. }, {
  65. .name = "filesystem2",
  66. .offset = MTDPART_OFS_APPEND,
  67. .size = MTDPART_SIZ_FULL,
  68. .mask_flags = 0,
  69. }
  70. /* two blocks with bad block table (and mirror) at the end */
  71. };
  72. static struct davinci_nand_pdata davinci_nand_data = {
  73. .core_chipsel = 0,
  74. .mask_chipsel = BIT(14),
  75. .parts = davinci_nand_partitions,
  76. .nr_parts = ARRAY_SIZE(davinci_nand_partitions),
  77. .engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST,
  78. .bbt_options = NAND_BBT_USE_FLASH,
  79. .ecc_bits = 4,
  80. };
  81. static struct resource davinci_nand_resources[] = {
  82. {
  83. .start = DM355_ASYNC_EMIF_DATA_CE0_BASE,
  84. .end = DM355_ASYNC_EMIF_DATA_CE0_BASE + SZ_32M - 1,
  85. .flags = IORESOURCE_MEM,
  86. }, {
  87. .start = DM355_ASYNC_EMIF_CONTROL_BASE,
  88. .end = DM355_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
  89. .flags = IORESOURCE_MEM,
  90. },
  91. };
  92. static struct platform_device davinci_nand_device = {
  93. .name = "davinci_nand",
  94. .id = 0,
  95. .num_resources = ARRAY_SIZE(davinci_nand_resources),
  96. .resource = davinci_nand_resources,
  97. .dev = {
  98. .platform_data = &davinci_nand_data,
  99. },
  100. };
  101. #define DM355_I2C_SDA_PIN GPIO_TO_PIN(0, 15)
  102. #define DM355_I2C_SCL_PIN GPIO_TO_PIN(0, 14)
  103. static struct gpiod_lookup_table i2c_recovery_gpiod_table = {
  104. .dev_id = "i2c_davinci.1",
  105. .table = {
  106. GPIO_LOOKUP("davinci_gpio", DM355_I2C_SDA_PIN, "sda",
  107. GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
  108. GPIO_LOOKUP("davinci_gpio", DM355_I2C_SCL_PIN, "scl",
  109. GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
  110. { }
  111. },
  112. };
  113. static struct davinci_i2c_platform_data i2c_pdata = {
  114. .bus_freq = 400 /* kHz */,
  115. .bus_delay = 0 /* usec */,
  116. .gpio_recovery = true,
  117. };
  118. static int dm355evm_mmc_gpios = -EINVAL;
  119. static void dm355evm_mmcsd_gpios(unsigned gpio)
  120. {
  121. gpio_request(gpio + 0, "mmc0_ro");
  122. gpio_request(gpio + 1, "mmc0_cd");
  123. gpio_request(gpio + 2, "mmc1_ro");
  124. gpio_request(gpio + 3, "mmc1_cd");
  125. /* we "know" these are input-only so we don't
  126. * need to call gpio_direction_input()
  127. */
  128. dm355evm_mmc_gpios = gpio;
  129. }
  130. static struct i2c_board_info dm355evm_i2c_info[] = {
  131. { I2C_BOARD_INFO("dm355evm_msp", 0x25),
  132. .platform_data = dm355evm_mmcsd_gpios,
  133. },
  134. /* { plus irq }, */
  135. { I2C_BOARD_INFO("tlv320aic33", 0x1b), },
  136. };
  137. static void __init evm_init_i2c(void)
  138. {
  139. gpiod_add_lookup_table(&i2c_recovery_gpiod_table);
  140. davinci_init_i2c(&i2c_pdata);
  141. gpio_request(5, "dm355evm_msp");
  142. gpio_direction_input(5);
  143. dm355evm_i2c_info[0].irq = gpio_to_irq(5);
  144. i2c_register_board_info(1, dm355evm_i2c_info,
  145. ARRAY_SIZE(dm355evm_i2c_info));
  146. }
  147. static struct resource dm355evm_dm9000_rsrc[] = {
  148. {
  149. /* addr */
  150. .start = 0x04014000,
  151. .end = 0x04014001,
  152. .flags = IORESOURCE_MEM,
  153. }, {
  154. /* data */
  155. .start = 0x04014002,
  156. .end = 0x04014003,
  157. .flags = IORESOURCE_MEM,
  158. }, {
  159. .flags = IORESOURCE_IRQ
  160. | IORESOURCE_IRQ_HIGHEDGE /* rising (active high) */,
  161. },
  162. };
  163. static struct dm9000_plat_data dm335evm_dm9000_platdata;
  164. static struct platform_device dm355evm_dm9000 = {
  165. .name = "dm9000",
  166. .id = -1,
  167. .resource = dm355evm_dm9000_rsrc,
  168. .num_resources = ARRAY_SIZE(dm355evm_dm9000_rsrc),
  169. .dev = {
  170. .platform_data = &dm335evm_dm9000_platdata,
  171. },
  172. };
  173. static struct tvp514x_platform_data tvp5146_pdata = {
  174. .clk_polarity = 0,
  175. .hs_polarity = 1,
  176. .vs_polarity = 1
  177. };
  178. #define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
  179. /* Inputs available at the TVP5146 */
  180. static struct v4l2_input tvp5146_inputs[] = {
  181. {
  182. .index = 0,
  183. .name = "Composite",
  184. .type = V4L2_INPUT_TYPE_CAMERA,
  185. .std = TVP514X_STD_ALL,
  186. },
  187. {
  188. .index = 1,
  189. .name = "S-Video",
  190. .type = V4L2_INPUT_TYPE_CAMERA,
  191. .std = TVP514X_STD_ALL,
  192. },
  193. };
  194. /*
  195. * this is the route info for connecting each input to decoder
  196. * ouput that goes to vpfe. There is a one to one correspondence
  197. * with tvp5146_inputs
  198. */
  199. static struct vpfe_route tvp5146_routes[] = {
  200. {
  201. .input = INPUT_CVBS_VI2B,
  202. .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
  203. },
  204. {
  205. .input = INPUT_SVIDEO_VI2C_VI1C,
  206. .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
  207. },
  208. };
  209. static struct vpfe_subdev_info vpfe_sub_devs[] = {
  210. {
  211. .name = "tvp5146",
  212. .grp_id = 0,
  213. .num_inputs = ARRAY_SIZE(tvp5146_inputs),
  214. .inputs = tvp5146_inputs,
  215. .routes = tvp5146_routes,
  216. .can_route = 1,
  217. .ccdc_if_params = {
  218. .if_type = VPFE_BT656,
  219. .hdpol = VPFE_PINPOL_POSITIVE,
  220. .vdpol = VPFE_PINPOL_POSITIVE,
  221. },
  222. .board_info = {
  223. I2C_BOARD_INFO("tvp5146", 0x5d),
  224. .platform_data = &tvp5146_pdata,
  225. },
  226. }
  227. };
  228. static struct vpfe_config vpfe_cfg = {
  229. .num_subdevs = ARRAY_SIZE(vpfe_sub_devs),
  230. .i2c_adapter_id = 1,
  231. .sub_devs = vpfe_sub_devs,
  232. .card_name = "DM355 EVM",
  233. .ccdc = "DM355 CCDC",
  234. };
  235. /* venc standards timings */
  236. static struct vpbe_enc_mode_info dm355evm_enc_preset_timing[] = {
  237. {
  238. .name = "ntsc",
  239. .timings_type = VPBE_ENC_STD,
  240. .std_id = V4L2_STD_NTSC,
  241. .interlaced = 1,
  242. .xres = 720,
  243. .yres = 480,
  244. .aspect = {11, 10},
  245. .fps = {30000, 1001},
  246. .left_margin = 0x79,
  247. .upper_margin = 0x10,
  248. },
  249. {
  250. .name = "pal",
  251. .timings_type = VPBE_ENC_STD,
  252. .std_id = V4L2_STD_PAL,
  253. .interlaced = 1,
  254. .xres = 720,
  255. .yres = 576,
  256. .aspect = {54, 59},
  257. .fps = {25, 1},
  258. .left_margin = 0x7E,
  259. .upper_margin = 0x16
  260. },
  261. };
  262. #define VENC_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
  263. /*
  264. * The outputs available from VPBE + ecnoders. Keep the
  265. * the order same as that of encoders. First those from venc followed by that
  266. * from encoders. Index in the output refers to index on a particular encoder.
  267. * Driver uses this index to pass it to encoder when it supports more than
  268. * one output. Application uses index of the array to set an output.
  269. */
  270. static struct vpbe_output dm355evm_vpbe_outputs[] = {
  271. {
  272. .output = {
  273. .index = 0,
  274. .name = "Composite",
  275. .type = V4L2_OUTPUT_TYPE_ANALOG,
  276. .std = VENC_STD_ALL,
  277. .capabilities = V4L2_OUT_CAP_STD,
  278. },
  279. .subdev_name = DM355_VPBE_VENC_SUBDEV_NAME,
  280. .default_mode = "ntsc",
  281. .num_modes = ARRAY_SIZE(dm355evm_enc_preset_timing),
  282. .modes = dm355evm_enc_preset_timing,
  283. .if_params = MEDIA_BUS_FMT_FIXED,
  284. },
  285. };
  286. static struct vpbe_config dm355evm_display_cfg = {
  287. .module_name = "dm355-vpbe-display",
  288. .i2c_adapter_id = 1,
  289. .osd = {
  290. .module_name = DM355_VPBE_OSD_SUBDEV_NAME,
  291. },
  292. .venc = {
  293. .module_name = DM355_VPBE_VENC_SUBDEV_NAME,
  294. },
  295. .num_outputs = ARRAY_SIZE(dm355evm_vpbe_outputs),
  296. .outputs = dm355evm_vpbe_outputs,
  297. };
  298. static struct platform_device *davinci_evm_devices[] __initdata = {
  299. &dm355evm_dm9000,
  300. &davinci_nand_device,
  301. };
  302. static void __init dm355_evm_map_io(void)
  303. {
  304. dm355_init();
  305. }
  306. static int dm355evm_mmc_get_cd(int module)
  307. {
  308. if (!gpio_is_valid(dm355evm_mmc_gpios))
  309. return -ENXIO;
  310. /* low == card present */
  311. return !gpio_get_value_cansleep(dm355evm_mmc_gpios + 2 * module + 1);
  312. }
  313. static int dm355evm_mmc_get_ro(int module)
  314. {
  315. if (!gpio_is_valid(dm355evm_mmc_gpios))
  316. return -ENXIO;
  317. /* high == card's write protect switch active */
  318. return gpio_get_value_cansleep(dm355evm_mmc_gpios + 2 * module + 0);
  319. }
  320. static struct davinci_mmc_config dm355evm_mmc_config = {
  321. .get_cd = dm355evm_mmc_get_cd,
  322. .get_ro = dm355evm_mmc_get_ro,
  323. .wires = 4,
  324. .max_freq = 50000000,
  325. .caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
  326. };
  327. /* Don't connect anything to J10 unless you're only using USB host
  328. * mode *and* have to do so with some kind of gender-bender. If
  329. * you have proper Mini-B or Mini-A cables (or Mini-A adapters)
  330. * the ID pin won't need any help.
  331. */
  332. #define USB_ID_VALUE 1 /* ID pulled low */
  333. static struct spi_eeprom at25640a = {
  334. .byte_len = SZ_64K / 8,
  335. .name = "at25640a",
  336. .page_size = 32,
  337. .flags = EE_ADDR2,
  338. };
  339. static const struct spi_board_info dm355_evm_spi_info[] __initconst = {
  340. {
  341. .modalias = "at25",
  342. .platform_data = &at25640a,
  343. .max_speed_hz = 10 * 1000 * 1000, /* at 3v3 */
  344. .bus_num = 0,
  345. .chip_select = 0,
  346. .mode = SPI_MODE_0,
  347. },
  348. };
  349. static __init void dm355_evm_init(void)
  350. {
  351. struct clk *aemif;
  352. int ret;
  353. dm355_register_clocks();
  354. ret = dm355_gpio_register();
  355. if (ret)
  356. pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
  357. gpio_request(1, "dm9000");
  358. gpio_direction_input(1);
  359. dm355evm_dm9000_rsrc[2].start = gpio_to_irq(1);
  360. aemif = clk_get(&dm355evm_dm9000.dev, "aemif");
  361. if (!WARN(IS_ERR(aemif), "unable to get AEMIF clock\n"))
  362. clk_prepare_enable(aemif);
  363. platform_add_devices(davinci_evm_devices,
  364. ARRAY_SIZE(davinci_evm_devices));
  365. evm_init_i2c();
  366. davinci_serial_init(dm355_serial_device);
  367. /* NOTE: NAND flash timings set by the UBL are slower than
  368. * needed by MT29F16G08FAA chips ... EMIF.A1CR is 0x40400204
  369. * but could be 0x0400008c for about 25% faster page reads.
  370. */
  371. gpio_request(2, "usb_id_toggle");
  372. gpio_direction_output(2, USB_ID_VALUE);
  373. /* irlml6401 switches over 1A in under 8 msec */
  374. davinci_setup_usb(1000, 8);
  375. davinci_setup_mmc(0, &dm355evm_mmc_config);
  376. davinci_setup_mmc(1, &dm355evm_mmc_config);
  377. dm355_init_video(&vpfe_cfg, &dm355evm_display_cfg);
  378. dm355_init_spi0(BIT(0), dm355_evm_spi_info,
  379. ARRAY_SIZE(dm355_evm_spi_info));
  380. /* DM335 EVM uses ASP1; line-out is a stereo mini-jack */
  381. dm355_init_asp1(ASP1_TX_EVT_EN | ASP1_RX_EVT_EN);
  382. }
  383. MACHINE_START(DAVINCI_DM355_EVM, "DaVinci DM355 EVM")
  384. .atag_offset = 0x100,
  385. .map_io = dm355_evm_map_io,
  386. .init_irq = dm355_init_irq,
  387. .init_time = dm355_init_time,
  388. .init_machine = dm355_evm_init,
  389. .init_late = davinci_init_late,
  390. .dma_zone_size = SZ_128M,
  391. MACHINE_END