board-dm644x-evm.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /*
  2. * TI DaVinci EVM board support
  3. *
  4. * Author: Kevin Hilman, MontaVista Software, Inc. <source@mvista.com>
  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/module.h>
  13. #include <linux/init.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/gpio.h>
  17. #include <linux/leds.h>
  18. #include <linux/i2c.h>
  19. #include <linux/i2c/pcf857x.h>
  20. #include <linux/i2c/at24.h>
  21. #include <linux/mtd/mtd.h>
  22. #include <linux/mtd/partitions.h>
  23. #include <linux/mtd/physmap.h>
  24. #include <linux/io.h>
  25. #include <asm/setup.h>
  26. #include <asm/mach-types.h>
  27. #include <asm/mach/arch.h>
  28. #include <asm/mach/map.h>
  29. #include <asm/mach/flash.h>
  30. #include <mach/hardware.h>
  31. #include <mach/common.h>
  32. #include <mach/i2c.h>
  33. #define DAVINCI_CFC_ATA_BASE 0x01C66000
  34. #define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE 0x02000000
  35. /* other misc. init functions */
  36. void __init davinci_psc_init(void);
  37. void __init davinci_irq_init(void);
  38. void __init davinci_map_common_io(void);
  39. void __init davinci_init_common_hw(void);
  40. #if defined(CONFIG_MTD_PHYSMAP) || \
  41. defined(CONFIG_MTD_PHYSMAP_MODULE)
  42. static struct mtd_partition davinci_evm_norflash_partitions[] = {
  43. /* bootloader (U-Boot, etc) in first 4 sectors */
  44. {
  45. .name = "bootloader",
  46. .offset = 0,
  47. .size = 4 * SZ_64K,
  48. .mask_flags = MTD_WRITEABLE, /* force read-only */
  49. },
  50. /* bootloader params in the next 1 sectors */
  51. {
  52. .name = "params",
  53. .offset = MTDPART_OFS_APPEND,
  54. .size = SZ_64K,
  55. .mask_flags = 0,
  56. },
  57. /* kernel */
  58. {
  59. .name = "kernel",
  60. .offset = MTDPART_OFS_APPEND,
  61. .size = SZ_2M,
  62. .mask_flags = 0
  63. },
  64. /* file system */
  65. {
  66. .name = "filesystem",
  67. .offset = MTDPART_OFS_APPEND,
  68. .size = MTDPART_SIZ_FULL,
  69. .mask_flags = 0
  70. }
  71. };
  72. static struct physmap_flash_data davinci_evm_norflash_data = {
  73. .width = 2,
  74. .parts = davinci_evm_norflash_partitions,
  75. .nr_parts = ARRAY_SIZE(davinci_evm_norflash_partitions),
  76. };
  77. /* NOTE: CFI probe will correctly detect flash part as 32M, but EMIF
  78. * limits addresses to 16M, so using addresses past 16M will wrap */
  79. static struct resource davinci_evm_norflash_resource = {
  80. .start = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE,
  81. .end = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
  82. .flags = IORESOURCE_MEM,
  83. };
  84. static struct platform_device davinci_evm_norflash_device = {
  85. .name = "physmap-flash",
  86. .id = 0,
  87. .dev = {
  88. .platform_data = &davinci_evm_norflash_data,
  89. },
  90. .num_resources = 1,
  91. .resource = &davinci_evm_norflash_resource,
  92. };
  93. #endif
  94. #if defined(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \
  95. defined(CONFIG_BLK_DEV_PALMCHIP_BK3710_MODULE)
  96. static struct resource ide_resources[] = {
  97. {
  98. .start = DAVINCI_CFC_ATA_BASE,
  99. .end = DAVINCI_CFC_ATA_BASE + 0x7ff,
  100. .flags = IORESOURCE_MEM,
  101. },
  102. {
  103. .start = IRQ_IDE,
  104. .end = IRQ_IDE,
  105. .flags = IORESOURCE_IRQ,
  106. },
  107. };
  108. static u64 ide_dma_mask = DMA_BIT_MASK(32);
  109. static struct platform_device ide_dev = {
  110. .name = "palm_bk3710",
  111. .id = -1,
  112. .resource = ide_resources,
  113. .num_resources = ARRAY_SIZE(ide_resources),
  114. .dev = {
  115. .dma_mask = &ide_dma_mask,
  116. .coherent_dma_mask = DMA_BIT_MASK(32),
  117. },
  118. };
  119. #endif
  120. /*----------------------------------------------------------------------*/
  121. /*
  122. * I2C GPIO expanders
  123. */
  124. #define PCF_Uxx_BASE(x) (DAVINCI_N_GPIO + ((x) * 8))
  125. /* U2 -- LEDs */
  126. static struct gpio_led evm_leds[] = {
  127. { .name = "DS8", .active_low = 1,
  128. .default_trigger = "heartbeat", },
  129. { .name = "DS7", .active_low = 1, },
  130. { .name = "DS6", .active_low = 1, },
  131. { .name = "DS5", .active_low = 1, },
  132. { .name = "DS4", .active_low = 1, },
  133. { .name = "DS3", .active_low = 1, },
  134. { .name = "DS2", .active_low = 1,
  135. .default_trigger = "mmc0", },
  136. { .name = "DS1", .active_low = 1,
  137. .default_trigger = "ide-disk", },
  138. };
  139. static const struct gpio_led_platform_data evm_led_data = {
  140. .num_leds = ARRAY_SIZE(evm_leds),
  141. .leds = evm_leds,
  142. };
  143. static struct platform_device *evm_led_dev;
  144. static int
  145. evm_led_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
  146. {
  147. struct gpio_led *leds = evm_leds;
  148. int status;
  149. while (ngpio--) {
  150. leds->gpio = gpio++;
  151. leds++;
  152. }
  153. /* what an extremely annoying way to be forced to handle
  154. * device unregistration ...
  155. */
  156. evm_led_dev = platform_device_alloc("leds-gpio", 0);
  157. platform_device_add_data(evm_led_dev,
  158. &evm_led_data, sizeof evm_led_data);
  159. evm_led_dev->dev.parent = &client->dev;
  160. status = platform_device_add(evm_led_dev);
  161. if (status < 0) {
  162. platform_device_put(evm_led_dev);
  163. evm_led_dev = NULL;
  164. }
  165. return status;
  166. }
  167. static int
  168. evm_led_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
  169. {
  170. if (evm_led_dev) {
  171. platform_device_unregister(evm_led_dev);
  172. evm_led_dev = NULL;
  173. }
  174. return 0;
  175. }
  176. static struct pcf857x_platform_data pcf_data_u2 = {
  177. .gpio_base = PCF_Uxx_BASE(0),
  178. .setup = evm_led_setup,
  179. .teardown = evm_led_teardown,
  180. };
  181. /* U18 - A/V clock generator and user switch */
  182. static int sw_gpio;
  183. static ssize_t
  184. sw_show(struct device *d, struct device_attribute *a, char *buf)
  185. {
  186. char *s = gpio_get_value_cansleep(sw_gpio) ? "on\n" : "off\n";
  187. strcpy(buf, s);
  188. return strlen(s);
  189. }
  190. static DEVICE_ATTR(user_sw, S_IRUGO, sw_show, NULL);
  191. static int
  192. evm_u18_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
  193. {
  194. int status;
  195. /* export dip switch option */
  196. sw_gpio = gpio + 7;
  197. status = gpio_request(sw_gpio, "user_sw");
  198. if (status == 0)
  199. status = gpio_direction_input(sw_gpio);
  200. if (status == 0)
  201. status = device_create_file(&client->dev, &dev_attr_user_sw);
  202. else
  203. gpio_free(sw_gpio);
  204. if (status != 0)
  205. sw_gpio = -EINVAL;
  206. /* audio PLL: 48 kHz (vs 44.1 or 32), single rate (vs double) */
  207. gpio_request(gpio + 3, "pll_fs2");
  208. gpio_direction_output(gpio + 3, 0);
  209. gpio_request(gpio + 2, "pll_fs1");
  210. gpio_direction_output(gpio + 2, 0);
  211. gpio_request(gpio + 1, "pll_sr");
  212. gpio_direction_output(gpio + 1, 0);
  213. return 0;
  214. }
  215. static int
  216. evm_u18_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
  217. {
  218. gpio_free(gpio + 1);
  219. gpio_free(gpio + 2);
  220. gpio_free(gpio + 3);
  221. if (sw_gpio > 0) {
  222. device_remove_file(&client->dev, &dev_attr_user_sw);
  223. gpio_free(sw_gpio);
  224. }
  225. return 0;
  226. }
  227. static struct pcf857x_platform_data pcf_data_u18 = {
  228. .gpio_base = PCF_Uxx_BASE(1),
  229. .n_latch = (1 << 3) | (1 << 2) | (1 << 1),
  230. .setup = evm_u18_setup,
  231. .teardown = evm_u18_teardown,
  232. };
  233. /* U35 - various I/O signals used to manage USB, CF, ATA, etc */
  234. static int
  235. evm_u35_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
  236. {
  237. /* p0 = nDRV_VBUS (initial: don't supply it) */
  238. gpio_request(gpio + 0, "nDRV_VBUS");
  239. gpio_direction_output(gpio + 0, 1);
  240. /* p1 = VDDIMX_EN */
  241. gpio_request(gpio + 1, "VDDIMX_EN");
  242. gpio_direction_output(gpio + 1, 1);
  243. /* p2 = VLYNQ_EN */
  244. gpio_request(gpio + 2, "VLYNQ_EN");
  245. gpio_direction_output(gpio + 2, 1);
  246. /* p3 = n3V3_CF_RESET (initial: stay in reset) */
  247. gpio_request(gpio + 3, "nCF_RESET");
  248. gpio_direction_output(gpio + 3, 0);
  249. /* (p4 unused) */
  250. /* p5 = 1V8_WLAN_RESET (initial: stay in reset) */
  251. gpio_request(gpio + 5, "WLAN_RESET");
  252. gpio_direction_output(gpio + 5, 1);
  253. /* p6 = nATA_SEL (initial: select) */
  254. gpio_request(gpio + 6, "nATA_SEL");
  255. gpio_direction_output(gpio + 6, 0);
  256. /* p7 = nCF_SEL (initial: deselect) */
  257. gpio_request(gpio + 7, "nCF_SEL");
  258. gpio_direction_output(gpio + 7, 1);
  259. /* irlml6401 sustains over 3A, switches 5V in under 8 msec */
  260. setup_usb(500, 8);
  261. return 0;
  262. }
  263. static int
  264. evm_u35_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
  265. {
  266. gpio_free(gpio + 7);
  267. gpio_free(gpio + 6);
  268. gpio_free(gpio + 5);
  269. gpio_free(gpio + 3);
  270. gpio_free(gpio + 2);
  271. gpio_free(gpio + 1);
  272. gpio_free(gpio + 0);
  273. return 0;
  274. }
  275. static struct pcf857x_platform_data pcf_data_u35 = {
  276. .gpio_base = PCF_Uxx_BASE(2),
  277. .setup = evm_u35_setup,
  278. .teardown = evm_u35_teardown,
  279. };
  280. /*----------------------------------------------------------------------*/
  281. /* Most of this EEPROM is unused, but U-Boot uses some data:
  282. * - 0x7f00, 6 bytes Ethernet Address
  283. * - 0x0039, 1 byte NTSC vs PAL (bit 0x80 == PAL)
  284. * - ... newer boards may have more
  285. */
  286. static struct at24_platform_data eeprom_info = {
  287. .byte_len = (256*1024) / 8,
  288. .page_size = 64,
  289. .flags = AT24_FLAG_ADDR16,
  290. };
  291. static struct i2c_board_info __initdata i2c_info[] = {
  292. {
  293. I2C_BOARD_INFO("pcf8574", 0x38),
  294. .platform_data = &pcf_data_u2,
  295. },
  296. {
  297. I2C_BOARD_INFO("pcf8574", 0x39),
  298. .platform_data = &pcf_data_u18,
  299. },
  300. {
  301. I2C_BOARD_INFO("pcf8574", 0x3a),
  302. .platform_data = &pcf_data_u35,
  303. },
  304. {
  305. I2C_BOARD_INFO("24c256", 0x50),
  306. .platform_data = &eeprom_info,
  307. },
  308. /* ALSO:
  309. * - tvl320aic33 audio codec (0x1b)
  310. * - msp430 microcontroller (0x23)
  311. * - tvp5146 video decoder (0x5d)
  312. */
  313. };
  314. /* The msp430 uses a slow bitbanged I2C implementation (ergo 20 KHz),
  315. * which requires 100 usec of idle bus after i2c writes sent to it.
  316. */
  317. static struct davinci_i2c_platform_data i2c_pdata = {
  318. .bus_freq = 20 /* kHz */,
  319. .bus_delay = 100 /* usec */,
  320. };
  321. static void __init evm_init_i2c(void)
  322. {
  323. davinci_init_i2c(&i2c_pdata);
  324. i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
  325. }
  326. static struct platform_device *davinci_evm_devices[] __initdata = {
  327. #if defined(CONFIG_MTD_PHYSMAP) || \
  328. defined(CONFIG_MTD_PHYSMAP_MODULE)
  329. &davinci_evm_norflash_device,
  330. #endif
  331. #if defined(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \
  332. defined(CONFIG_BLK_DEV_PALMCHIP_BK3710_MODULE)
  333. &ide_dev,
  334. #endif
  335. };
  336. static void __init
  337. davinci_evm_map_io(void)
  338. {
  339. davinci_map_common_io();
  340. }
  341. static __init void davinci_evm_init(void)
  342. {
  343. #if defined(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \
  344. defined(CONFIG_BLK_DEV_PALMCHIP_BK3710_MODULE)
  345. #if defined(CONFIG_MTD_PHYSMAP) || \
  346. defined(CONFIG_MTD_PHYSMAP_MODULE)
  347. printk(KERN_WARNING "WARNING: both IDE and NOR flash are enabled, "
  348. "but share pins.\n\t Disable IDE for NOR support.\n");
  349. #endif
  350. #endif
  351. platform_add_devices(davinci_evm_devices,
  352. ARRAY_SIZE(davinci_evm_devices));
  353. evm_init_i2c();
  354. }
  355. static __init void davinci_evm_irq_init(void)
  356. {
  357. davinci_irq_init();
  358. }
  359. MACHINE_START(DAVINCI_EVM, "DaVinci EVM")
  360. /* Maintainer: MontaVista Software <source@mvista.com> */
  361. .phys_io = IO_PHYS,
  362. .io_pg_offst = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
  363. .boot_params = (DAVINCI_DDR_BASE + 0x100),
  364. .map_io = davinci_evm_map_io,
  365. .init_irq = davinci_evm_irq_init,
  366. .timer = &davinci_timer,
  367. .init_machine = davinci_evm_init,
  368. MACHINE_END