board-dm355-evm.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /*
  2. * TI DaVinci EVM board support
  3. *
  4. * Author: Kevin Hilman, Deep Root Systems, LLC
  5. *
  6. * 2007 (c) MontaVista Software, Inc. This file is licensed under
  7. * the terms of the GNU General Public License version 2. This program
  8. * is licensed "as is" without any warranty of any kind, whether express
  9. * or implied.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/err.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/mtd/mtd.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <linux/mtd/nand.h>
  18. #include <linux/i2c.h>
  19. #include <linux/gpio.h>
  20. #include <linux/clk.h>
  21. #include <linux/videodev2.h>
  22. #include <media/tvp514x.h>
  23. #include <linux/spi/spi.h>
  24. #include <linux/spi/eeprom.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/mach/arch.h>
  27. #include <mach/i2c.h>
  28. #include <mach/serial.h>
  29. #include <mach/nand.h>
  30. #include <mach/mmc.h>
  31. #include <mach/usb.h>
  32. #include "davinci.h"
  33. /* NOTE: this is geared for the standard config, with a socketed
  34. * 2 GByte Micron NAND (MT29F16G08FAA) using 128KB sectors. If you
  35. * swap chips, maybe with a different block size, partitioning may
  36. * need to be changed.
  37. */
  38. #define NAND_BLOCK_SIZE SZ_128K
  39. static struct mtd_partition davinci_nand_partitions[] = {
  40. {
  41. /* UBL (a few copies) plus U-Boot */
  42. .name = "bootloader",
  43. .offset = 0,
  44. .size = 15 * NAND_BLOCK_SIZE,
  45. .mask_flags = MTD_WRITEABLE, /* force read-only */
  46. }, {
  47. /* U-Boot environment */
  48. .name = "params",
  49. .offset = MTDPART_OFS_APPEND,
  50. .size = 1 * NAND_BLOCK_SIZE,
  51. .mask_flags = 0,
  52. }, {
  53. .name = "kernel",
  54. .offset = MTDPART_OFS_APPEND,
  55. .size = SZ_4M,
  56. .mask_flags = 0,
  57. }, {
  58. .name = "filesystem1",
  59. .offset = MTDPART_OFS_APPEND,
  60. .size = SZ_512M,
  61. .mask_flags = 0,
  62. }, {
  63. .name = "filesystem2",
  64. .offset = MTDPART_OFS_APPEND,
  65. .size = MTDPART_SIZ_FULL,
  66. .mask_flags = 0,
  67. }
  68. /* two blocks with bad block table (and mirror) at the end */
  69. };
  70. static struct davinci_nand_pdata davinci_nand_data = {
  71. .mask_chipsel = BIT(14),
  72. .parts = davinci_nand_partitions,
  73. .nr_parts = ARRAY_SIZE(davinci_nand_partitions),
  74. .ecc_mode = NAND_ECC_HW,
  75. .bbt_options = NAND_BBT_USE_FLASH,
  76. .ecc_bits = 4,
  77. };
  78. static struct resource davinci_nand_resources[] = {
  79. {
  80. .start = DM355_ASYNC_EMIF_DATA_CE0_BASE,
  81. .end = DM355_ASYNC_EMIF_DATA_CE0_BASE + SZ_32M - 1,
  82. .flags = IORESOURCE_MEM,
  83. }, {
  84. .start = DM355_ASYNC_EMIF_CONTROL_BASE,
  85. .end = DM355_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
  86. .flags = IORESOURCE_MEM,
  87. },
  88. };
  89. static struct platform_device davinci_nand_device = {
  90. .name = "davinci_nand",
  91. .id = 0,
  92. .num_resources = ARRAY_SIZE(davinci_nand_resources),
  93. .resource = davinci_nand_resources,
  94. .dev = {
  95. .platform_data = &davinci_nand_data,
  96. },
  97. };
  98. static struct davinci_i2c_platform_data i2c_pdata = {
  99. .bus_freq = 400 /* kHz */,
  100. .bus_delay = 0 /* usec */,
  101. .sda_pin = 15,
  102. .scl_pin = 14,
  103. };
  104. static struct snd_platform_data dm355_evm_snd_data;
  105. static int dm355evm_mmc_gpios = -EINVAL;
  106. static void dm355evm_mmcsd_gpios(unsigned gpio)
  107. {
  108. gpio_request(gpio + 0, "mmc0_ro");
  109. gpio_request(gpio + 1, "mmc0_cd");
  110. gpio_request(gpio + 2, "mmc1_ro");
  111. gpio_request(gpio + 3, "mmc1_cd");
  112. /* we "know" these are input-only so we don't
  113. * need to call gpio_direction_input()
  114. */
  115. dm355evm_mmc_gpios = gpio;
  116. }
  117. static struct i2c_board_info dm355evm_i2c_info[] = {
  118. { I2C_BOARD_INFO("dm355evm_msp", 0x25),
  119. .platform_data = dm355evm_mmcsd_gpios,
  120. },
  121. /* { plus irq }, */
  122. { I2C_BOARD_INFO("tlv320aic33", 0x1b), },
  123. };
  124. static void __init evm_init_i2c(void)
  125. {
  126. davinci_init_i2c(&i2c_pdata);
  127. gpio_request(5, "dm355evm_msp");
  128. gpio_direction_input(5);
  129. dm355evm_i2c_info[0].irq = gpio_to_irq(5);
  130. i2c_register_board_info(1, dm355evm_i2c_info,
  131. ARRAY_SIZE(dm355evm_i2c_info));
  132. }
  133. static struct resource dm355evm_dm9000_rsrc[] = {
  134. {
  135. /* addr */
  136. .start = 0x04014000,
  137. .end = 0x04014001,
  138. .flags = IORESOURCE_MEM,
  139. }, {
  140. /* data */
  141. .start = 0x04014002,
  142. .end = 0x04014003,
  143. .flags = IORESOURCE_MEM,
  144. }, {
  145. .flags = IORESOURCE_IRQ
  146. | IORESOURCE_IRQ_HIGHEDGE /* rising (active high) */,
  147. },
  148. };
  149. static struct platform_device dm355evm_dm9000 = {
  150. .name = "dm9000",
  151. .id = -1,
  152. .resource = dm355evm_dm9000_rsrc,
  153. .num_resources = ARRAY_SIZE(dm355evm_dm9000_rsrc),
  154. };
  155. static struct tvp514x_platform_data tvp5146_pdata = {
  156. .clk_polarity = 0,
  157. .hs_polarity = 1,
  158. .vs_polarity = 1
  159. };
  160. #define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
  161. /* Inputs available at the TVP5146 */
  162. static struct v4l2_input tvp5146_inputs[] = {
  163. {
  164. .index = 0,
  165. .name = "Composite",
  166. .type = V4L2_INPUT_TYPE_CAMERA,
  167. .std = TVP514X_STD_ALL,
  168. },
  169. {
  170. .index = 1,
  171. .name = "S-Video",
  172. .type = V4L2_INPUT_TYPE_CAMERA,
  173. .std = TVP514X_STD_ALL,
  174. },
  175. };
  176. /*
  177. * this is the route info for connecting each input to decoder
  178. * ouput that goes to vpfe. There is a one to one correspondence
  179. * with tvp5146_inputs
  180. */
  181. static struct vpfe_route tvp5146_routes[] = {
  182. {
  183. .input = INPUT_CVBS_VI2B,
  184. .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
  185. },
  186. {
  187. .input = INPUT_SVIDEO_VI2C_VI1C,
  188. .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
  189. },
  190. };
  191. static struct vpfe_subdev_info vpfe_sub_devs[] = {
  192. {
  193. .name = "tvp5146",
  194. .grp_id = 0,
  195. .num_inputs = ARRAY_SIZE(tvp5146_inputs),
  196. .inputs = tvp5146_inputs,
  197. .routes = tvp5146_routes,
  198. .can_route = 1,
  199. .ccdc_if_params = {
  200. .if_type = VPFE_BT656,
  201. .hdpol = VPFE_PINPOL_POSITIVE,
  202. .vdpol = VPFE_PINPOL_POSITIVE,
  203. },
  204. .board_info = {
  205. I2C_BOARD_INFO("tvp5146", 0x5d),
  206. .platform_data = &tvp5146_pdata,
  207. },
  208. }
  209. };
  210. static struct vpfe_config vpfe_cfg = {
  211. .num_subdevs = ARRAY_SIZE(vpfe_sub_devs),
  212. .i2c_adapter_id = 1,
  213. .sub_devs = vpfe_sub_devs,
  214. .card_name = "DM355 EVM",
  215. .ccdc = "DM355 CCDC",
  216. };
  217. static struct platform_device *davinci_evm_devices[] __initdata = {
  218. &dm355evm_dm9000,
  219. &davinci_nand_device,
  220. };
  221. static struct davinci_uart_config uart_config __initdata = {
  222. .enabled_uarts = (1 << 0),
  223. };
  224. static void __init dm355_evm_map_io(void)
  225. {
  226. /* setup input configuration for VPFE input devices */
  227. dm355_set_vpfe_config(&vpfe_cfg);
  228. dm355_init();
  229. }
  230. static int dm355evm_mmc_get_cd(int module)
  231. {
  232. if (!gpio_is_valid(dm355evm_mmc_gpios))
  233. return -ENXIO;
  234. /* low == card present */
  235. return !gpio_get_value_cansleep(dm355evm_mmc_gpios + 2 * module + 1);
  236. }
  237. static int dm355evm_mmc_get_ro(int module)
  238. {
  239. if (!gpio_is_valid(dm355evm_mmc_gpios))
  240. return -ENXIO;
  241. /* high == card's write protect switch active */
  242. return gpio_get_value_cansleep(dm355evm_mmc_gpios + 2 * module + 0);
  243. }
  244. static struct davinci_mmc_config dm355evm_mmc_config = {
  245. .get_cd = dm355evm_mmc_get_cd,
  246. .get_ro = dm355evm_mmc_get_ro,
  247. .wires = 4,
  248. .max_freq = 50000000,
  249. .caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
  250. .version = MMC_CTLR_VERSION_1,
  251. };
  252. /* Don't connect anything to J10 unless you're only using USB host
  253. * mode *and* have to do so with some kind of gender-bender. If
  254. * you have proper Mini-B or Mini-A cables (or Mini-A adapters)
  255. * the ID pin won't need any help.
  256. */
  257. #ifdef CONFIG_USB_MUSB_PERIPHERAL
  258. #define USB_ID_VALUE 0 /* ID pulled high; *should* float */
  259. #else
  260. #define USB_ID_VALUE 1 /* ID pulled low */
  261. #endif
  262. static struct spi_eeprom at25640a = {
  263. .byte_len = SZ_64K / 8,
  264. .name = "at25640a",
  265. .page_size = 32,
  266. .flags = EE_ADDR2,
  267. };
  268. static struct spi_board_info dm355_evm_spi_info[] __initconst = {
  269. {
  270. .modalias = "at25",
  271. .platform_data = &at25640a,
  272. .max_speed_hz = 10 * 1000 * 1000, /* at 3v3 */
  273. .bus_num = 0,
  274. .chip_select = 0,
  275. .mode = SPI_MODE_0,
  276. },
  277. };
  278. static __init void dm355_evm_init(void)
  279. {
  280. struct clk *aemif;
  281. gpio_request(1, "dm9000");
  282. gpio_direction_input(1);
  283. dm355evm_dm9000_rsrc[2].start = gpio_to_irq(1);
  284. aemif = clk_get(&dm355evm_dm9000.dev, "aemif");
  285. if (IS_ERR(aemif))
  286. WARN("%s: unable to get AEMIF clock\n", __func__);
  287. else
  288. clk_enable(aemif);
  289. platform_add_devices(davinci_evm_devices,
  290. ARRAY_SIZE(davinci_evm_devices));
  291. evm_init_i2c();
  292. davinci_serial_init(&uart_config);
  293. /* NOTE: NAND flash timings set by the UBL are slower than
  294. * needed by MT29F16G08FAA chips ... EMIF.A1CR is 0x40400204
  295. * but could be 0x0400008c for about 25% faster page reads.
  296. */
  297. gpio_request(2, "usb_id_toggle");
  298. gpio_direction_output(2, USB_ID_VALUE);
  299. /* irlml6401 switches over 1A in under 8 msec */
  300. davinci_setup_usb(1000, 8);
  301. davinci_setup_mmc(0, &dm355evm_mmc_config);
  302. davinci_setup_mmc(1, &dm355evm_mmc_config);
  303. dm355_init_spi0(BIT(0), dm355_evm_spi_info,
  304. ARRAY_SIZE(dm355_evm_spi_info));
  305. /* DM335 EVM uses ASP1; line-out is a stereo mini-jack */
  306. dm355_init_asp1(ASP1_TX_EVT_EN | ASP1_RX_EVT_EN, &dm355_evm_snd_data);
  307. }
  308. MACHINE_START(DAVINCI_DM355_EVM, "DaVinci DM355 EVM")
  309. .atag_offset = 0x100,
  310. .map_io = dm355_evm_map_io,
  311. .init_irq = davinci_irq_init,
  312. .timer = &davinci_timer,
  313. .init_machine = dm355_evm_init,
  314. .dma_zone_size = SZ_128M,
  315. .restart = davinci_restart,
  316. MACHINE_END