board-usb-a926x.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /*
  2. * linux/arch/arm/mach-at91/board-usb-a926x.c
  3. *
  4. * Copyright (C) 2005 SAN People
  5. * Copyright (C) 2007 Atmel Corporation.
  6. * Copyright (C) 2007 Calao-systems
  7. * Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <linux/types.h>
  24. #include <linux/init.h>
  25. #include <linux/mm.h>
  26. #include <linux/module.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/spi/spi.h>
  29. #include <linux/gpio_keys.h>
  30. #include <linux/gpio.h>
  31. #include <linux/input.h>
  32. #include <linux/spi/mmc_spi.h>
  33. #include <asm/setup.h>
  34. #include <asm/mach-types.h>
  35. #include <asm/irq.h>
  36. #include <asm/mach/arch.h>
  37. #include <asm/mach/map.h>
  38. #include <asm/mach/irq.h>
  39. #include <mach/hardware.h>
  40. #include <mach/board.h>
  41. #include <mach/at91_aic.h>
  42. #include <mach/at91sam9_smc.h>
  43. #include <mach/at91_shdwc.h>
  44. #include "sam9_smc.h"
  45. #include "generic.h"
  46. static void __init ek_init_early(void)
  47. {
  48. /* Initialize processor: 12.00 MHz crystal */
  49. at91_initialize(12000000);
  50. }
  51. /*
  52. * USB Host port
  53. */
  54. static struct at91_usbh_data __initdata ek_usbh_data = {
  55. .ports = 2,
  56. .vbus_pin = {-EINVAL, -EINVAL},
  57. .overcurrent_pin= {-EINVAL, -EINVAL},
  58. };
  59. /*
  60. * USB Device port
  61. */
  62. static struct at91_udc_data __initdata ek_udc_data = {
  63. .vbus_pin = AT91_PIN_PB11,
  64. .pullup_pin = -EINVAL, /* pull-up driven by UDC */
  65. };
  66. static void __init ek_add_device_udc(void)
  67. {
  68. if (machine_is_usb_a9260() || machine_is_usb_a9g20())
  69. ek_udc_data.vbus_pin = AT91_PIN_PC5;
  70. at91_add_device_udc(&ek_udc_data);
  71. }
  72. #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
  73. #define MMC_SPI_CARD_DETECT_INT AT91_PIN_PC4
  74. static int at91_mmc_spi_init(struct device *dev,
  75. irqreturn_t (*detect_int)(int, void *), void *data)
  76. {
  77. /* Configure Interrupt pin as input, no pull-up */
  78. at91_set_gpio_input(MMC_SPI_CARD_DETECT_INT, 0);
  79. return request_irq(gpio_to_irq(MMC_SPI_CARD_DETECT_INT), detect_int,
  80. IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  81. "mmc-spi-detect", data);
  82. }
  83. static void at91_mmc_spi_exit(struct device *dev, void *data)
  84. {
  85. free_irq(gpio_to_irq(MMC_SPI_CARD_DETECT_INT), data);
  86. }
  87. static struct mmc_spi_platform_data at91_mmc_spi_pdata = {
  88. .init = at91_mmc_spi_init,
  89. .exit = at91_mmc_spi_exit,
  90. .detect_delay = 100, /* msecs */
  91. };
  92. #endif
  93. /*
  94. * SPI devices.
  95. */
  96. static struct spi_board_info usb_a9263_spi_devices[] = {
  97. #if !defined(CONFIG_MMC_AT91)
  98. { /* DataFlash chip */
  99. .modalias = "mtd_dataflash",
  100. .chip_select = 0,
  101. .max_speed_hz = 15 * 1000 * 1000,
  102. .bus_num = 0,
  103. }
  104. #endif
  105. };
  106. static struct spi_board_info usb_a9g20_spi_devices[] = {
  107. #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
  108. {
  109. .modalias = "mmc_spi",
  110. .max_speed_hz = 20000000, /* max spi clock (SCK) speed in HZ */
  111. .bus_num = 1,
  112. .chip_select = 0,
  113. .platform_data = &at91_mmc_spi_pdata,
  114. .mode = SPI_MODE_3,
  115. },
  116. #endif
  117. };
  118. static void __init ek_add_device_spi(void)
  119. {
  120. if (machine_is_usb_a9263())
  121. at91_add_device_spi(usb_a9263_spi_devices, ARRAY_SIZE(usb_a9263_spi_devices));
  122. else if (machine_is_usb_a9g20())
  123. at91_add_device_spi(usb_a9g20_spi_devices, ARRAY_SIZE(usb_a9g20_spi_devices));
  124. }
  125. /*
  126. * MACB Ethernet device
  127. */
  128. static struct macb_platform_data __initdata ek_macb_data = {
  129. .phy_irq_pin = AT91_PIN_PE31,
  130. .is_rmii = 1,
  131. };
  132. static void __init ek_add_device_eth(void)
  133. {
  134. if (machine_is_usb_a9260() || machine_is_usb_a9g20())
  135. ek_macb_data.phy_irq_pin = AT91_PIN_PA31;
  136. at91_add_device_eth(&ek_macb_data);
  137. }
  138. /*
  139. * NAND flash
  140. */
  141. static struct mtd_partition __initdata ek_nand_partition[] = {
  142. {
  143. .name = "barebox",
  144. .offset = 0,
  145. .size = 3 * SZ_128K,
  146. }, {
  147. .name = "bareboxenv",
  148. .offset = MTDPART_OFS_NXTBLK,
  149. .size = SZ_128K,
  150. }, {
  151. .name = "bareboxenv2",
  152. .offset = MTDPART_OFS_NXTBLK,
  153. .size = SZ_128K,
  154. }, {
  155. .name = "oftree",
  156. .offset = MTDPART_OFS_NXTBLK,
  157. .size = SZ_128K,
  158. }, {
  159. .name = "kernel",
  160. .offset = MTDPART_OFS_NXTBLK,
  161. .size = 4 * SZ_1M,
  162. }, {
  163. .name = "rootfs",
  164. .offset = MTDPART_OFS_NXTBLK,
  165. .size = 120 * SZ_1M,
  166. }, {
  167. .name = "data",
  168. .offset = MTDPART_OFS_NXTBLK,
  169. .size = MTDPART_SIZ_FULL,
  170. }
  171. };
  172. static struct atmel_nand_data __initdata ek_nand_data = {
  173. .ale = 21,
  174. .cle = 22,
  175. .det_pin = -EINVAL,
  176. .rdy_pin = AT91_PIN_PA22,
  177. .enable_pin = AT91_PIN_PD15,
  178. .ecc_mode = NAND_ECC_SOFT,
  179. .on_flash_bbt = 1,
  180. .parts = ek_nand_partition,
  181. .num_parts = ARRAY_SIZE(ek_nand_partition),
  182. };
  183. static struct sam9_smc_config __initdata usb_a9260_nand_smc_config = {
  184. .ncs_read_setup = 0,
  185. .nrd_setup = 1,
  186. .ncs_write_setup = 0,
  187. .nwe_setup = 1,
  188. .ncs_read_pulse = 3,
  189. .nrd_pulse = 3,
  190. .ncs_write_pulse = 3,
  191. .nwe_pulse = 3,
  192. .read_cycle = 5,
  193. .write_cycle = 5,
  194. .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
  195. .tdf_cycles = 2,
  196. };
  197. static struct sam9_smc_config __initdata usb_a9g20_nand_smc_config = {
  198. .ncs_read_setup = 0,
  199. .nrd_setup = 2,
  200. .ncs_write_setup = 0,
  201. .nwe_setup = 2,
  202. .ncs_read_pulse = 4,
  203. .nrd_pulse = 4,
  204. .ncs_write_pulse = 4,
  205. .nwe_pulse = 4,
  206. .read_cycle = 7,
  207. .write_cycle = 7,
  208. .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
  209. .tdf_cycles = 3,
  210. };
  211. static void __init ek_add_device_nand(void)
  212. {
  213. if (machine_is_usb_a9260() || machine_is_usb_a9g20()) {
  214. ek_nand_data.rdy_pin = AT91_PIN_PC13;
  215. ek_nand_data.enable_pin = AT91_PIN_PC14;
  216. }
  217. /* configure chip-select 3 (NAND) */
  218. if (machine_is_usb_a9g20())
  219. sam9_smc_configure(0, 3, &usb_a9g20_nand_smc_config);
  220. else
  221. sam9_smc_configure(0, 3, &usb_a9260_nand_smc_config);
  222. at91_add_device_nand(&ek_nand_data);
  223. }
  224. /*
  225. * GPIO Buttons
  226. */
  227. #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
  228. static struct gpio_keys_button ek_buttons[] = {
  229. { /* USER PUSH BUTTON */
  230. .code = KEY_ENTER,
  231. .gpio = AT91_PIN_PB10,
  232. .active_low = 1,
  233. .desc = "user_pb",
  234. .wakeup = 1,
  235. }
  236. };
  237. static struct gpio_keys_platform_data ek_button_data = {
  238. .buttons = ek_buttons,
  239. .nbuttons = ARRAY_SIZE(ek_buttons),
  240. };
  241. static struct platform_device ek_button_device = {
  242. .name = "gpio-keys",
  243. .id = -1,
  244. .num_resources = 0,
  245. .dev = {
  246. .platform_data = &ek_button_data,
  247. }
  248. };
  249. static void __init ek_add_device_buttons(void)
  250. {
  251. at91_set_GPIO_periph(AT91_PIN_PB10, 1); /* user push button, pull up enabled */
  252. at91_set_deglitch(AT91_PIN_PB10, 1);
  253. platform_device_register(&ek_button_device);
  254. }
  255. #else
  256. static void __init ek_add_device_buttons(void) {}
  257. #endif
  258. /*
  259. * LEDs
  260. */
  261. static struct gpio_led ek_leds[] = {
  262. { /* user_led (green) */
  263. .name = "user_led",
  264. .gpio = AT91_PIN_PB21,
  265. .active_low = 1,
  266. .default_trigger = "heartbeat",
  267. }
  268. };
  269. static struct i2c_board_info __initdata ek_i2c_devices[] = {
  270. {
  271. I2C_BOARD_INFO("rv3029c2", 0x56),
  272. },
  273. };
  274. static void __init ek_add_device_leds(void)
  275. {
  276. if (machine_is_usb_a9260() || machine_is_usb_a9g20())
  277. ek_leds[0].active_low = 0;
  278. at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
  279. }
  280. static void __init ek_board_init(void)
  281. {
  282. /* Serial */
  283. /* DBGU on ttyS0. (Rx & Tx only) */
  284. at91_register_uart(0, 0, 0);
  285. at91_add_device_serial();
  286. /* USB Host */
  287. at91_add_device_usbh(&ek_usbh_data);
  288. /* USB Device */
  289. ek_add_device_udc();
  290. /* SPI */
  291. ek_add_device_spi();
  292. /* Ethernet */
  293. ek_add_device_eth();
  294. /* NAND */
  295. ek_add_device_nand();
  296. /* Push Buttons */
  297. ek_add_device_buttons();
  298. /* LEDs */
  299. ek_add_device_leds();
  300. if (machine_is_usb_a9g20()) {
  301. /* I2C */
  302. at91_add_device_i2c(ek_i2c_devices, ARRAY_SIZE(ek_i2c_devices));
  303. } else {
  304. /* I2C */
  305. at91_add_device_i2c(NULL, 0);
  306. /* shutdown controller, wakeup button (5 msec low) */
  307. at91_shdwc_write(AT91_SHDW_MR, AT91_SHDW_CPTWK0_(10)
  308. | AT91_SHDW_WKMODE0_LOW
  309. | AT91_SHDW_RTTWKEN);
  310. }
  311. }
  312. MACHINE_START(USB_A9263, "CALAO USB_A9263")
  313. /* Maintainer: calao-systems */
  314. .timer = &at91sam926x_timer,
  315. .map_io = at91_map_io,
  316. .handle_irq = at91_aic_handle_irq,
  317. .init_early = ek_init_early,
  318. .init_irq = at91_init_irq_default,
  319. .init_machine = ek_board_init,
  320. MACHINE_END
  321. MACHINE_START(USB_A9260, "CALAO USB_A9260")
  322. /* Maintainer: calao-systems */
  323. .timer = &at91sam926x_timer,
  324. .map_io = at91_map_io,
  325. .handle_irq = at91_aic_handle_irq,
  326. .init_early = ek_init_early,
  327. .init_irq = at91_init_irq_default,
  328. .init_machine = ek_board_init,
  329. MACHINE_END
  330. MACHINE_START(USB_A9G20, "CALAO USB_A92G0")
  331. /* Maintainer: Jean-Christophe PLAGNIOL-VILLARD */
  332. .timer = &at91sam926x_timer,
  333. .map_io = at91_map_io,
  334. .handle_irq = at91_aic_handle_irq,
  335. .init_early = ek_init_early,
  336. .init_irq = at91_init_irq_default,
  337. .init_machine = ek_board_init,
  338. MACHINE_END