board-dm646x-evm.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. #include <mach/common.h>
  47. #define DM646X_EVM_PHY_MASK (0x2)
  48. #define DM646X_EVM_MDIO_FREQUENCY (2200000) /* PHY bus frequency */
  49. static struct davinci_uart_config uart_config __initdata = {
  50. .enabled_uarts = (1 << 0),
  51. };
  52. /* LEDS */
  53. static struct gpio_led evm_leds[] = {
  54. { .name = "DS1", .active_low = 1, },
  55. { .name = "DS2", .active_low = 1, },
  56. { .name = "DS3", .active_low = 1, },
  57. { .name = "DS4", .active_low = 1, },
  58. };
  59. static __initconst struct gpio_led_platform_data evm_led_data = {
  60. .num_leds = ARRAY_SIZE(evm_leds),
  61. .leds = evm_leds,
  62. };
  63. static struct platform_device *evm_led_dev;
  64. static int evm_led_setup(struct i2c_client *client, int gpio,
  65. unsigned int ngpio, void *c)
  66. {
  67. struct gpio_led *leds = evm_leds;
  68. int status;
  69. while (ngpio--) {
  70. leds->gpio = gpio++;
  71. leds++;
  72. };
  73. evm_led_dev = platform_device_alloc("leds-gpio", 0);
  74. platform_device_add_data(evm_led_dev, &evm_led_data,
  75. sizeof(evm_led_data));
  76. evm_led_dev->dev.parent = &client->dev;
  77. status = platform_device_add(evm_led_dev);
  78. if (status < 0) {
  79. platform_device_put(evm_led_dev);
  80. evm_led_dev = NULL;
  81. }
  82. return status;
  83. }
  84. static int evm_led_teardown(struct i2c_client *client, int gpio,
  85. unsigned ngpio, void *c)
  86. {
  87. if (evm_led_dev) {
  88. platform_device_unregister(evm_led_dev);
  89. evm_led_dev = NULL;
  90. }
  91. return 0;
  92. }
  93. static int evm_sw_gpio[4] = { -EINVAL, -EINVAL, -EINVAL, -EINVAL };
  94. static int evm_sw_setup(struct i2c_client *client, int gpio,
  95. unsigned ngpio, void *c)
  96. {
  97. int status;
  98. int i;
  99. char label[10];
  100. for (i = 0; i < 4; ++i) {
  101. snprintf(label, 10, "user_sw%d", i);
  102. status = gpio_request(gpio, label);
  103. if (status)
  104. goto out_free;
  105. evm_sw_gpio[i] = gpio++;
  106. status = gpio_direction_input(evm_sw_gpio[i]);
  107. if (status) {
  108. gpio_free(evm_sw_gpio[i]);
  109. evm_sw_gpio[i] = -EINVAL;
  110. goto out_free;
  111. }
  112. status = gpio_export(evm_sw_gpio[i], 0);
  113. if (status) {
  114. gpio_free(evm_sw_gpio[i]);
  115. evm_sw_gpio[i] = -EINVAL;
  116. goto out_free;
  117. }
  118. }
  119. return status;
  120. out_free:
  121. for (i = 0; i < 4; ++i) {
  122. if (evm_sw_gpio[i] != -EINVAL) {
  123. gpio_free(evm_sw_gpio[i]);
  124. evm_sw_gpio[i] = -EINVAL;
  125. }
  126. }
  127. return status;
  128. }
  129. static int evm_sw_teardown(struct i2c_client *client, int gpio,
  130. unsigned ngpio, void *c)
  131. {
  132. int i;
  133. for (i = 0; i < 4; ++i) {
  134. if (evm_sw_gpio[i] != -EINVAL) {
  135. gpio_unexport(evm_sw_gpio[i]);
  136. gpio_free(evm_sw_gpio[i]);
  137. evm_sw_gpio[i] = -EINVAL;
  138. }
  139. }
  140. return 0;
  141. }
  142. static int evm_pcf_setup(struct i2c_client *client, int gpio,
  143. unsigned int ngpio, void *c)
  144. {
  145. int status;
  146. if (ngpio < 8)
  147. return -EINVAL;
  148. status = evm_sw_setup(client, gpio, 4, c);
  149. if (status)
  150. return status;
  151. return evm_led_setup(client, gpio+4, 4, c);
  152. }
  153. static int evm_pcf_teardown(struct i2c_client *client, int gpio,
  154. unsigned int ngpio, void *c)
  155. {
  156. BUG_ON(ngpio < 8);
  157. evm_sw_teardown(client, gpio, 4, c);
  158. evm_led_teardown(client, gpio+4, 4, c);
  159. return 0;
  160. }
  161. static struct pcf857x_platform_data pcf_data = {
  162. .gpio_base = DAVINCI_N_GPIO+1,
  163. .setup = evm_pcf_setup,
  164. .teardown = evm_pcf_teardown,
  165. };
  166. /* Most of this EEPROM is unused, but U-Boot uses some data:
  167. * - 0x7f00, 6 bytes Ethernet Address
  168. * - ... newer boards may have more
  169. */
  170. static struct at24_platform_data eeprom_info = {
  171. .byte_len = (256*1024) / 8,
  172. .page_size = 64,
  173. .flags = AT24_FLAG_ADDR16,
  174. .setup = davinci_get_mac_addr,
  175. .context = (void *)0x7f00,
  176. };
  177. static struct i2c_board_info __initdata i2c_info[] = {
  178. {
  179. I2C_BOARD_INFO("24c256", 0x50),
  180. .platform_data = &eeprom_info,
  181. },
  182. {
  183. I2C_BOARD_INFO("pcf8574a", 0x38),
  184. .platform_data = &pcf_data,
  185. },
  186. };
  187. static struct davinci_i2c_platform_data i2c_pdata = {
  188. .bus_freq = 100 /* kHz */,
  189. .bus_delay = 0 /* usec */,
  190. };
  191. static void __init evm_init_i2c(void)
  192. {
  193. davinci_init_i2c(&i2c_pdata);
  194. i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
  195. }
  196. static void __init davinci_map_io(void)
  197. {
  198. dm646x_init();
  199. }
  200. static __init void evm_init(void)
  201. {
  202. struct davinci_soc_info *soc_info = &davinci_soc_info;
  203. evm_init_i2c();
  204. davinci_serial_init(&uart_config);
  205. soc_info->emac_pdata->phy_mask = DM646X_EVM_PHY_MASK;
  206. soc_info->emac_pdata->mdio_max_freq = DM646X_EVM_MDIO_FREQUENCY;
  207. }
  208. static __init void davinci_dm646x_evm_irq_init(void)
  209. {
  210. davinci_irq_init();
  211. }
  212. MACHINE_START(DAVINCI_DM6467_EVM, "DaVinci DM646x EVM")
  213. .phys_io = IO_PHYS,
  214. .io_pg_offst = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
  215. .boot_params = (0x80000100),
  216. .map_io = davinci_map_io,
  217. .init_irq = davinci_dm646x_evm_irq_init,
  218. .timer = &davinci_timer,
  219. .init_machine = evm_init,
  220. MACHINE_END