board-dm646x-evm.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. * TI DaVinci DM646X EVM board
  3. *
  4. * Derived from: arch/arm/mach-davinci/board-evm.c
  5. * Copyright (C) 2006 Texas Instruments.
  6. *
  7. * (C) 2007-2008, MontaVista Software, Inc.
  8. *
  9. * This file is licensed under the terms of the GNU General Public License
  10. * version 2. This program is licensed "as is" without any warranty of any
  11. * kind, whether express or implied.
  12. *
  13. */
  14. /**************************************************************************
  15. * Included Files
  16. **************************************************************************/
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/init.h>
  20. #include <linux/fs.h>
  21. #include <linux/major.h>
  22. #include <linux/root_dev.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/serial.h>
  25. #include <linux/serial_8250.h>
  26. #include <linux/leds.h>
  27. #include <linux/gpio.h>
  28. #include <linux/io.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/i2c.h>
  31. #include <linux/i2c/at24.h>
  32. #include <linux/i2c/pcf857x.h>
  33. #include <linux/etherdevice.h>
  34. #include <asm/setup.h>
  35. #include <asm/mach-types.h>
  36. #include <asm/mach/arch.h>
  37. #include <asm/mach/map.h>
  38. #include <asm/mach/flash.h>
  39. #include <mach/dm646x.h>
  40. #include <mach/common.h>
  41. #include <mach/psc.h>
  42. #include <mach/serial.h>
  43. #include <mach/i2c.h>
  44. #include <mach/mmc.h>
  45. #include <mach/emac.h>
  46. #define DM646X_EVM_PHY_MASK (0x2)
  47. #define DM646X_EVM_MDIO_FREQUENCY (2200000) /* PHY bus frequency */
  48. static struct emac_platform_data dm646x_evm_emac_pdata = {
  49. .phy_mask = DM646X_EVM_PHY_MASK,
  50. .mdio_max_freq = DM646X_EVM_MDIO_FREQUENCY,
  51. };
  52. static struct davinci_uart_config uart_config __initdata = {
  53. .enabled_uarts = (1 << 0),
  54. };
  55. /* LEDS */
  56. static struct gpio_led evm_leds[] = {
  57. { .name = "DS1", .active_low = 1, },
  58. { .name = "DS2", .active_low = 1, },
  59. { .name = "DS3", .active_low = 1, },
  60. { .name = "DS4", .active_low = 1, },
  61. };
  62. static __initconst struct gpio_led_platform_data evm_led_data = {
  63. .num_leds = ARRAY_SIZE(evm_leds),
  64. .leds = evm_leds,
  65. };
  66. static struct platform_device *evm_led_dev;
  67. static int evm_led_setup(struct i2c_client *client, int gpio,
  68. unsigned int ngpio, void *c)
  69. {
  70. struct gpio_led *leds = evm_leds;
  71. int status;
  72. while (ngpio--) {
  73. leds->gpio = gpio++;
  74. leds++;
  75. };
  76. evm_led_dev = platform_device_alloc("leds-gpio", 0);
  77. platform_device_add_data(evm_led_dev, &evm_led_data,
  78. sizeof(evm_led_data));
  79. evm_led_dev->dev.parent = &client->dev;
  80. status = platform_device_add(evm_led_dev);
  81. if (status < 0) {
  82. platform_device_put(evm_led_dev);
  83. evm_led_dev = NULL;
  84. }
  85. return status;
  86. }
  87. static int evm_led_teardown(struct i2c_client *client, int gpio,
  88. unsigned ngpio, void *c)
  89. {
  90. if (evm_led_dev) {
  91. platform_device_unregister(evm_led_dev);
  92. evm_led_dev = NULL;
  93. }
  94. return 0;
  95. }
  96. static int evm_sw_gpio[4] = { -EINVAL, -EINVAL, -EINVAL, -EINVAL };
  97. static int evm_sw_setup(struct i2c_client *client, int gpio,
  98. unsigned ngpio, void *c)
  99. {
  100. int status;
  101. int i;
  102. char label[10];
  103. for (i = 0; i < 4; ++i) {
  104. snprintf(label, 10, "user_sw%d", i);
  105. status = gpio_request(gpio, label);
  106. if (status)
  107. goto out_free;
  108. evm_sw_gpio[i] = gpio++;
  109. status = gpio_direction_input(evm_sw_gpio[i]);
  110. if (status) {
  111. gpio_free(evm_sw_gpio[i]);
  112. evm_sw_gpio[i] = -EINVAL;
  113. goto out_free;
  114. }
  115. status = gpio_export(evm_sw_gpio[i], 0);
  116. if (status) {
  117. gpio_free(evm_sw_gpio[i]);
  118. evm_sw_gpio[i] = -EINVAL;
  119. goto out_free;
  120. }
  121. }
  122. return status;
  123. out_free:
  124. for (i = 0; i < 4; ++i) {
  125. if (evm_sw_gpio[i] != -EINVAL) {
  126. gpio_free(evm_sw_gpio[i]);
  127. evm_sw_gpio[i] = -EINVAL;
  128. }
  129. }
  130. return status;
  131. }
  132. static int evm_sw_teardown(struct i2c_client *client, int gpio,
  133. unsigned ngpio, void *c)
  134. {
  135. int i;
  136. for (i = 0; i < 4; ++i) {
  137. if (evm_sw_gpio[i] != -EINVAL) {
  138. gpio_unexport(evm_sw_gpio[i]);
  139. gpio_free(evm_sw_gpio[i]);
  140. evm_sw_gpio[i] = -EINVAL;
  141. }
  142. }
  143. return 0;
  144. }
  145. static int evm_pcf_setup(struct i2c_client *client, int gpio,
  146. unsigned int ngpio, void *c)
  147. {
  148. int status;
  149. if (ngpio < 8)
  150. return -EINVAL;
  151. status = evm_sw_setup(client, gpio, 4, c);
  152. if (status)
  153. return status;
  154. return evm_led_setup(client, gpio+4, 4, c);
  155. }
  156. static int evm_pcf_teardown(struct i2c_client *client, int gpio,
  157. unsigned int ngpio, void *c)
  158. {
  159. BUG_ON(ngpio < 8);
  160. evm_sw_teardown(client, gpio, 4, c);
  161. evm_led_teardown(client, gpio+4, 4, c);
  162. return 0;
  163. }
  164. static struct pcf857x_platform_data pcf_data = {
  165. .gpio_base = DAVINCI_N_GPIO+1,
  166. .setup = evm_pcf_setup,
  167. .teardown = evm_pcf_teardown,
  168. };
  169. /* Most of this EEPROM is unused, but U-Boot uses some data:
  170. * - 0x7f00, 6 bytes Ethernet Address
  171. * - ... newer boards may have more
  172. */
  173. static struct memory_accessor *at24_mem_acc;
  174. static void at24_setup(struct memory_accessor *mem_acc, void *context)
  175. {
  176. char mac_addr[ETH_ALEN];
  177. at24_mem_acc = mem_acc;
  178. /* Read MAC addr from EEPROM */
  179. if (at24_mem_acc->read(at24_mem_acc, mac_addr, 0x7f00, ETH_ALEN) ==
  180. ETH_ALEN) {
  181. pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr);
  182. memcpy(dm646x_evm_emac_pdata.mac_addr, mac_addr, ETH_ALEN);
  183. }
  184. }
  185. static struct at24_platform_data eeprom_info = {
  186. .byte_len = (256*1024) / 8,
  187. .page_size = 64,
  188. .flags = AT24_FLAG_ADDR16,
  189. .setup = at24_setup,
  190. };
  191. int dm646xevm_eeprom_read(void *buf, off_t off, size_t count)
  192. {
  193. if (at24_mem_acc)
  194. return at24_mem_acc->read(at24_mem_acc, buf, off, count);
  195. return -ENODEV;
  196. }
  197. EXPORT_SYMBOL(dm646xevm_eeprom_read);
  198. int dm646xevm_eeprom_write(void *buf, off_t off, size_t count)
  199. {
  200. if (at24_mem_acc)
  201. return at24_mem_acc->write(at24_mem_acc, buf, off, count);
  202. return -ENODEV;
  203. }
  204. EXPORT_SYMBOL(dm646xevm_eeprom_write);
  205. static struct i2c_board_info __initdata i2c_info[] = {
  206. {
  207. I2C_BOARD_INFO("24c256", 0x50),
  208. .platform_data = &eeprom_info,
  209. },
  210. {
  211. I2C_BOARD_INFO("pcf8574a", 0x38),
  212. .platform_data = &pcf_data,
  213. },
  214. };
  215. static struct davinci_i2c_platform_data i2c_pdata = {
  216. .bus_freq = 100 /* kHz */,
  217. .bus_delay = 0 /* usec */,
  218. };
  219. static void __init evm_init_i2c(void)
  220. {
  221. davinci_init_i2c(&i2c_pdata);
  222. i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
  223. }
  224. static void __init davinci_map_io(void)
  225. {
  226. davinci_map_common_io();
  227. dm646x_init();
  228. }
  229. static __init void evm_init(void)
  230. {
  231. evm_init_i2c();
  232. davinci_serial_init(&uart_config);
  233. dm646x_init_emac(&dm646x_evm_emac_pdata);
  234. }
  235. static __init void davinci_dm646x_evm_irq_init(void)
  236. {
  237. davinci_irq_init();
  238. }
  239. MACHINE_START(DAVINCI_DM6467_EVM, "DaVinci DM646x EVM")
  240. .phys_io = IO_PHYS,
  241. .io_pg_offst = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
  242. .boot_params = (0x80000100),
  243. .map_io = davinci_map_io,
  244. .init_irq = davinci_dm646x_evm_irq_init,
  245. .timer = &davinci_timer,
  246. .init_machine = evm_init,
  247. MACHINE_END