setup.c 8.5 KB

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