setup.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. .parts = nand_partitions,
  89. .num_parts = ARRAY_SIZE(nand_partitions),
  90. };
  91. #endif
  92. /* Initialized by bootloader-specific startup code. */
  93. struct tag *bootloader_tags __initdata;
  94. struct eth_addr {
  95. u8 addr[6];
  96. };
  97. static struct eth_addr __initdata hw_addr[2];
  98. static struct eth_platform_data __initdata eth_data[2];
  99. static struct spi_board_info spi0_board_info[] __initdata = {
  100. {
  101. .modalias = "mtd_dataflash",
  102. .max_speed_hz = 8000000,
  103. .chip_select = 0,
  104. },
  105. };
  106. static struct mci_platform_data __initdata mci0_data = {
  107. .slot[0] = {
  108. .bus_width = 4,
  109. #if defined(CONFIG_BOARD_ATNGW100_MKII)
  110. .detect_pin = GPIO_PIN_PC(25),
  111. .wp_pin = GPIO_PIN_PE(22),
  112. #else
  113. .detect_pin = GPIO_PIN_PC(25),
  114. .wp_pin = GPIO_PIN_PE(0),
  115. #endif
  116. },
  117. };
  118. static struct usba_platform_data atngw100_usba_data __initdata = {
  119. #if defined(CONFIG_BOARD_ATNGW100_MKII)
  120. .vbus_pin = GPIO_PIN_PE(26),
  121. #else
  122. .vbus_pin = -ENODEV,
  123. #endif
  124. };
  125. /*
  126. * The next two functions should go away as the boot loader is
  127. * supposed to initialize the macb address registers with a valid
  128. * ethernet address. But we need to keep it around for a while until
  129. * we can be reasonably sure the boot loader does this.
  130. *
  131. * The phy_id is ignored as the driver will probe for it.
  132. */
  133. static int __init parse_tag_ethernet(struct tag *tag)
  134. {
  135. int i;
  136. i = tag->u.ethernet.mac_index;
  137. if (i < ARRAY_SIZE(hw_addr))
  138. memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  139. sizeof(hw_addr[i].addr));
  140. return 0;
  141. }
  142. __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  143. static void __init set_hw_addr(struct platform_device *pdev)
  144. {
  145. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  146. const u8 *addr;
  147. void __iomem *regs;
  148. struct clk *pclk;
  149. if (!res)
  150. return;
  151. if (pdev->id >= ARRAY_SIZE(hw_addr))
  152. return;
  153. addr = hw_addr[pdev->id].addr;
  154. if (!is_valid_ether_addr(addr))
  155. return;
  156. /*
  157. * Since this is board-specific code, we'll cheat and use the
  158. * physical address directly as we happen to know that it's
  159. * the same as the virtual address.
  160. */
  161. regs = (void __iomem __force *)res->start;
  162. pclk = clk_get(&pdev->dev, "pclk");
  163. if (IS_ERR(pclk))
  164. return;
  165. clk_enable(pclk);
  166. __raw_writel((addr[3] << 24) | (addr[2] << 16)
  167. | (addr[1] << 8) | addr[0], regs + 0x98);
  168. __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
  169. clk_disable(pclk);
  170. clk_put(pclk);
  171. }
  172. void __init setup_board(void)
  173. {
  174. at32_map_usart(1, 0, 0); /* USART 1: /dev/ttyS0, DB9 */
  175. at32_setup_serial_console(0);
  176. }
  177. static const struct gpio_led ngw_leds[] = {
  178. { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
  179. .default_trigger = "heartbeat",
  180. },
  181. { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
  182. { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
  183. };
  184. static const struct gpio_led_platform_data ngw_led_data = {
  185. .num_leds = ARRAY_SIZE(ngw_leds),
  186. .leds = (void *) ngw_leds,
  187. };
  188. static struct platform_device ngw_gpio_leds = {
  189. .name = "leds-gpio",
  190. .id = -1,
  191. .dev = {
  192. .platform_data = (void *) &ngw_led_data,
  193. }
  194. };
  195. static struct i2c_gpio_platform_data i2c_gpio_data = {
  196. .sda_pin = GPIO_PIN_PA(6),
  197. .scl_pin = GPIO_PIN_PA(7),
  198. .sda_is_open_drain = 1,
  199. .scl_is_open_drain = 1,
  200. .udelay = 2, /* close to 100 kHz */
  201. };
  202. static struct platform_device i2c_gpio_device = {
  203. .name = "i2c-gpio",
  204. .id = 0,
  205. .dev = {
  206. .platform_data = &i2c_gpio_data,
  207. },
  208. };
  209. static struct i2c_board_info __initdata i2c_info[] = {
  210. /* NOTE: original ATtiny24 firmware is at address 0x0b */
  211. };
  212. static int __init atngw100_init(void)
  213. {
  214. unsigned i;
  215. /*
  216. * ATNGW100 mkII uses 32-bit SDRAM interface. Reserve the
  217. * SDRAM-specific pins so that nobody messes with them.
  218. */
  219. #ifdef CONFIG_BOARD_ATNGW100_MKII
  220. at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL);
  221. smc_set_timing(&nand_config, &nand_timing);
  222. smc_set_configuration(3, &nand_config);
  223. at32_add_device_nand(0, &atngw100mkii_nand_data);
  224. #endif
  225. at32_add_device_usart(0);
  226. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  227. #ifndef CONFIG_BOARD_ATNGW100_MKII_LCD
  228. set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
  229. #endif
  230. at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
  231. at32_add_device_mci(0, &mci0_data);
  232. at32_add_device_usba(0, &atngw100_usba_data);
  233. for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
  234. at32_select_gpio(ngw_leds[i].gpio,
  235. AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  236. }
  237. platform_device_register(&ngw_gpio_leds);
  238. /* all these i2c/smbus pins should have external pullups for
  239. * open-drain sharing among all I2C devices. SDA and SCL do;
  240. * PB28/EXTINT3 (ATNGW100) and PE21 (ATNGW100 mkII) doesn't; it should
  241. * be SMBALERT# (for PMBus), but it's not available off-board.
  242. */
  243. #ifdef CONFIG_BOARD_ATNGW100_MKII
  244. at32_select_periph(GPIO_PIOE_BASE, 1 << 21, 0, AT32_GPIOF_PULLUP);
  245. #else
  246. at32_select_periph(GPIO_PIOB_BASE, 1 << 28, 0, AT32_GPIOF_PULLUP);
  247. #endif
  248. at32_select_gpio(i2c_gpio_data.sda_pin,
  249. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  250. at32_select_gpio(i2c_gpio_data.scl_pin,
  251. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  252. platform_device_register(&i2c_gpio_device);
  253. i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
  254. return 0;
  255. }
  256. postcore_initcall(atngw100_init);
  257. static int __init atngw100_arch_init(void)
  258. {
  259. /* PB30 (ATNGW100) and PE30 (ATNGW100 mkII) is the otherwise unused
  260. * jumper on the mainboard, with an external pullup; the jumper grounds
  261. * it. Use it however you like, including letting U-Boot or Linux tweak
  262. * boot sequences.
  263. */
  264. #ifdef CONFIG_BOARD_ATNGW100_MKII
  265. at32_select_gpio(GPIO_PIN_PE(30), 0);
  266. gpio_request(GPIO_PIN_PE(30), "j15");
  267. gpio_direction_input(GPIO_PIN_PE(30));
  268. gpio_export(GPIO_PIN_PE(30), false);
  269. #else
  270. at32_select_gpio(GPIO_PIN_PB(30), 0);
  271. gpio_request(GPIO_PIN_PB(30), "j15");
  272. gpio_direction_input(GPIO_PIN_PB(30));
  273. gpio_export(GPIO_PIN_PB(30), false);
  274. #endif
  275. /* set_irq_type() after the arch_initcall for EIC has run, and
  276. * before the I2C subsystem could try using this IRQ.
  277. */
  278. return irq_set_irq_type(AT32_EXTINT(3), IRQ_TYPE_EDGE_FALLING);
  279. }
  280. arch_initcall(atngw100_arch_init);