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