setup.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * Board-specific setup code for the ATNGW100 Network Gateway
  3. *
  4. * Copyright (C) 2005-2006 Atmel Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/clk.h>
  11. #include <linux/etherdevice.h>
  12. #include <linux/gpio.h>
  13. #include <linux/irq.h>
  14. #include <linux/i2c.h>
  15. #include <linux/i2c-gpio.h>
  16. #include <linux/init.h>
  17. #include <linux/linkage.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/types.h>
  20. #include <linux/leds.h>
  21. #include <linux/spi/spi.h>
  22. #include <linux/atmel-mci.h>
  23. #include <linux/usb/atmel_usba_udc.h>
  24. #include <asm/io.h>
  25. #include <asm/setup.h>
  26. #include <mach/at32ap700x.h>
  27. #include <mach/board.h>
  28. #include <mach/init.h>
  29. #include <mach/portmux.h>
  30. /* Oscillator frequencies. These are board-specific */
  31. unsigned long at32_board_osc_rates[3] = {
  32. [0] = 32768, /* 32.768 kHz on RTC osc */
  33. [1] = 20000000, /* 20 MHz on osc0 */
  34. [2] = 12000000, /* 12 MHz on osc1 */
  35. };
  36. /*
  37. * The ATNGW100 mkII is very similar to the ATNGW100. Both have the AT32AP7000
  38. * chip on board; the difference is that the ATNGW100 mkII has 128 MB 32-bit
  39. * SDRAM (the ATNGW100 has 32 MB 16-bit SDRAM) and 256 MB 16-bit NAND flash
  40. * (the ATNGW100 has none.)
  41. *
  42. * The RAM difference is handled by the boot loader, so the only difference we
  43. * end up handling here is the NAND flash, EBI pin reservation and if LCDC or
  44. * MACB1 should be enabled.
  45. */
  46. #ifdef CONFIG_BOARD_ATNGW100_MKII
  47. #include <linux/mtd/partitions.h>
  48. #include <mach/smc.h>
  49. static struct smc_timing nand_timing __initdata = {
  50. .ncs_read_setup = 0,
  51. .nrd_setup = 10,
  52. .ncs_write_setup = 0,
  53. .nwe_setup = 10,
  54. .ncs_read_pulse = 30,
  55. .nrd_pulse = 15,
  56. .ncs_write_pulse = 30,
  57. .nwe_pulse = 15,
  58. .read_cycle = 30,
  59. .write_cycle = 30,
  60. .ncs_read_recover = 0,
  61. .nrd_recover = 15,
  62. .ncs_write_recover = 0,
  63. /* WE# high -> RE# low min 60 ns */
  64. .nwe_recover = 50,
  65. };
  66. static struct smc_config nand_config __initdata = {
  67. .bus_width = 2,
  68. .nrd_controlled = 1,
  69. .nwe_controlled = 1,
  70. .nwait_mode = 0,
  71. .byte_write = 0,
  72. .tdf_cycles = 2,
  73. .tdf_mode = 0,
  74. };
  75. static struct mtd_partition nand_partitions[] = {
  76. {
  77. .name = "main",
  78. .offset = 0x00000000,
  79. .size = MTDPART_SIZ_FULL,
  80. },
  81. };
  82. static struct atmel_nand_data atngw100mkii_nand_data __initdata = {
  83. .cle = 21,
  84. .ale = 22,
  85. .rdy_pin = GPIO_PIN_PB(28),
  86. .enable_pin = GPIO_PIN_PE(23),
  87. .bus_width_16 = true,
  88. .ecc_mode = NAND_ECC_SOFT,
  89. .parts = nand_partitions,
  90. .num_parts = ARRAY_SIZE(nand_partitions),
  91. };
  92. #endif
  93. /* Initialized by bootloader-specific startup code. */
  94. struct tag *bootloader_tags __initdata;
  95. struct eth_addr {
  96. u8 addr[6];
  97. };
  98. static struct eth_addr __initdata hw_addr[2];
  99. static struct macb_platform_data __initdata eth_data[2];
  100. static struct spi_board_info spi0_board_info[] __initdata = {
  101. {
  102. .modalias = "mtd_dataflash",
  103. .max_speed_hz = 8000000,
  104. .chip_select = 0,
  105. },
  106. };
  107. static struct mci_platform_data __initdata mci0_data = {
  108. .slot[0] = {
  109. .bus_width = 4,
  110. #if defined(CONFIG_BOARD_ATNGW100_MKII)
  111. .detect_pin = GPIO_PIN_PC(25),
  112. .wp_pin = GPIO_PIN_PE(22),
  113. #else
  114. .detect_pin = GPIO_PIN_PC(25),
  115. .wp_pin = GPIO_PIN_PE(0),
  116. #endif
  117. },
  118. };
  119. static struct usba_platform_data atngw100_usba_data __initdata = {
  120. #if defined(CONFIG_BOARD_ATNGW100_MKII)
  121. .vbus_pin = GPIO_PIN_PE(26),
  122. #else
  123. .vbus_pin = -ENODEV,
  124. #endif
  125. };
  126. /*
  127. * The next two functions should go away as the boot loader is
  128. * supposed to initialize the macb address registers with a valid
  129. * ethernet address. But we need to keep it around for a while until
  130. * we can be reasonably sure the boot loader does this.
  131. *
  132. * The phy_id is ignored as the driver will probe for it.
  133. */
  134. static int __init parse_tag_ethernet(struct tag *tag)
  135. {
  136. int i;
  137. i = tag->u.ethernet.mac_index;
  138. if (i < ARRAY_SIZE(hw_addr))
  139. memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  140. sizeof(hw_addr[i].addr));
  141. return 0;
  142. }
  143. __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  144. static void __init set_hw_addr(struct platform_device *pdev)
  145. {
  146. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  147. const u8 *addr;
  148. void __iomem *regs;
  149. struct clk *pclk;
  150. if (!res)
  151. return;
  152. if (pdev->id >= ARRAY_SIZE(hw_addr))
  153. return;
  154. addr = hw_addr[pdev->id].addr;
  155. if (!is_valid_ether_addr(addr))
  156. return;
  157. /*
  158. * Since this is board-specific code, we'll cheat and use the
  159. * physical address directly as we happen to know that it's
  160. * the same as the virtual address.
  161. */
  162. regs = (void __iomem __force *)res->start;
  163. pclk = clk_get(&pdev->dev, "pclk");
  164. if (IS_ERR(pclk))
  165. return;
  166. clk_enable(pclk);
  167. __raw_writel((addr[3] << 24) | (addr[2] << 16)
  168. | (addr[1] << 8) | addr[0], regs + 0x98);
  169. __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
  170. clk_disable(pclk);
  171. clk_put(pclk);
  172. }
  173. void __init setup_board(void)
  174. {
  175. at32_map_usart(1, 0, 0); /* USART 1: /dev/ttyS0, DB9 */
  176. at32_setup_serial_console(0);
  177. }
  178. static const struct gpio_led ngw_leds[] = {
  179. { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
  180. .default_trigger = "heartbeat",
  181. },
  182. { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
  183. { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
  184. };
  185. static const struct gpio_led_platform_data ngw_led_data = {
  186. .num_leds = ARRAY_SIZE(ngw_leds),
  187. .leds = (void *) ngw_leds,
  188. };
  189. static struct platform_device ngw_gpio_leds = {
  190. .name = "leds-gpio",
  191. .id = -1,
  192. .dev = {
  193. .platform_data = (void *) &ngw_led_data,
  194. }
  195. };
  196. static struct i2c_gpio_platform_data i2c_gpio_data = {
  197. .sda_pin = GPIO_PIN_PA(6),
  198. .scl_pin = GPIO_PIN_PA(7),
  199. .sda_is_open_drain = 1,
  200. .scl_is_open_drain = 1,
  201. .udelay = 2, /* close to 100 kHz */
  202. };
  203. static struct platform_device i2c_gpio_device = {
  204. .name = "i2c-gpio",
  205. .id = 0,
  206. .dev = {
  207. .platform_data = &i2c_gpio_data,
  208. },
  209. };
  210. static struct i2c_board_info __initdata i2c_info[] = {
  211. /* NOTE: original ATtiny24 firmware is at address 0x0b */
  212. };
  213. static int __init atngw100_init(void)
  214. {
  215. unsigned i;
  216. /*
  217. * ATNGW100 mkII uses 32-bit SDRAM interface. Reserve the
  218. * SDRAM-specific pins so that nobody messes with them.
  219. */
  220. #ifdef CONFIG_BOARD_ATNGW100_MKII
  221. at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL);
  222. smc_set_timing(&nand_config, &nand_timing);
  223. smc_set_configuration(3, &nand_config);
  224. at32_add_device_nand(0, &atngw100mkii_nand_data);
  225. #endif
  226. at32_add_device_usart(0);
  227. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  228. #ifndef CONFIG_BOARD_ATNGW100_MKII_LCD
  229. set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
  230. #endif
  231. at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
  232. at32_add_device_mci(0, &mci0_data);
  233. at32_add_device_usba(0, &atngw100_usba_data);
  234. for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
  235. at32_select_gpio(ngw_leds[i].gpio,
  236. AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  237. }
  238. platform_device_register(&ngw_gpio_leds);
  239. /* all these i2c/smbus pins should have external pullups for
  240. * open-drain sharing among all I2C devices. SDA and SCL do;
  241. * PB28/EXTINT3 (ATNGW100) and PE21 (ATNGW100 mkII) doesn't; it should
  242. * be SMBALERT# (for PMBus), but it's not available off-board.
  243. */
  244. #ifdef CONFIG_BOARD_ATNGW100_MKII
  245. at32_select_periph(GPIO_PIOE_BASE, 1 << 21, 0, AT32_GPIOF_PULLUP);
  246. #else
  247. at32_select_periph(GPIO_PIOB_BASE, 1 << 28, 0, AT32_GPIOF_PULLUP);
  248. #endif
  249. at32_select_gpio(i2c_gpio_data.sda_pin,
  250. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  251. at32_select_gpio(i2c_gpio_data.scl_pin,
  252. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  253. platform_device_register(&i2c_gpio_device);
  254. i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
  255. return 0;
  256. }
  257. postcore_initcall(atngw100_init);
  258. static int __init atngw100_arch_init(void)
  259. {
  260. /* PB30 (ATNGW100) and PE30 (ATNGW100 mkII) is the otherwise unused
  261. * jumper on the mainboard, with an external pullup; the jumper grounds
  262. * it. Use it however you like, including letting U-Boot or Linux tweak
  263. * boot sequences.
  264. */
  265. #ifdef CONFIG_BOARD_ATNGW100_MKII
  266. at32_select_gpio(GPIO_PIN_PE(30), 0);
  267. gpio_request(GPIO_PIN_PE(30), "j15");
  268. gpio_direction_input(GPIO_PIN_PE(30));
  269. gpio_export(GPIO_PIN_PE(30), false);
  270. #else
  271. at32_select_gpio(GPIO_PIN_PB(30), 0);
  272. gpio_request(GPIO_PIN_PB(30), "j15");
  273. gpio_direction_input(GPIO_PIN_PB(30));
  274. gpio_export(GPIO_PIN_PB(30), false);
  275. #endif
  276. /* set_irq_type() after the arch_initcall for EIC has run, and
  277. * before the I2C subsystem could try using this IRQ.
  278. */
  279. return irq_set_irq_type(AT32_EXTINT(3), IRQ_TYPE_EDGE_FALLING);
  280. }
  281. arch_initcall(atngw100_arch_init);