setup.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * Board-specific setup code for the Miromico Hammerhead board
  3. *
  4. * Copyright (C) 2008 Miromico AG
  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/atmel-mci.h>
  11. #include <linux/clk.h>
  12. #include <linux/fb.h>
  13. #include <linux/etherdevice.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/spi/spi.h>
  21. #include <video/atmel_lcdc.h>
  22. #include <linux/io.h>
  23. #include <asm/setup.h>
  24. #include <mach/at32ap700x.h>
  25. #include <mach/board.h>
  26. #include <mach/init.h>
  27. #include <mach/portmux.h>
  28. #include <sound/atmel-ac97c.h>
  29. #include "../../mach-at32ap/clock.h"
  30. #include "flash.h"
  31. /* Oscillator frequencies. These are board-specific */
  32. unsigned long at32_board_osc_rates[3] = {
  33. [0] = 32768, /* 32.768 kHz on RTC osc */
  34. [1] = 25000000, /* 25MHz on osc0 */
  35. [2] = 12000000, /* 12 MHz on osc1 */
  36. };
  37. /* Initialized by bootloader-specific startup code. */
  38. struct tag *bootloader_tags __initdata;
  39. #ifdef CONFIG_BOARD_HAMMERHEAD_LCD
  40. static struct fb_videomode __initdata hda350tlv_modes[] = {
  41. {
  42. .name = "320x240 @ 75",
  43. .refresh = 75,
  44. .xres = 320,
  45. .yres = 240,
  46. .pixclock = KHZ2PICOS(6891),
  47. .left_margin = 48,
  48. .right_margin = 18,
  49. .upper_margin = 18,
  50. .lower_margin = 4,
  51. .hsync_len = 20,
  52. .vsync_len = 2,
  53. .sync = 0,
  54. .vmode = FB_VMODE_NONINTERLACED,
  55. },
  56. };
  57. static struct fb_monspecs __initdata hammerhead_hda350t_monspecs = {
  58. .manufacturer = "HAN",
  59. .monitor = "HDA350T-LV",
  60. .modedb = hda350tlv_modes,
  61. .modedb_len = ARRAY_SIZE(hda350tlv_modes),
  62. .hfmin = 14900,
  63. .hfmax = 22350,
  64. .vfmin = 60,
  65. .vfmax = 90,
  66. .dclkmax = 10000000,
  67. };
  68. struct atmel_lcdfb_pdata __initdata hammerhead_lcdc_data = {
  69. .default_bpp = 24,
  70. .default_dmacon = ATMEL_LCDC_DMAEN | ATMEL_LCDC_DMA2DEN,
  71. .default_lcdcon2 = (ATMEL_LCDC_DISTYPE_TFT
  72. | ATMEL_LCDC_INVCLK
  73. | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE
  74. | ATMEL_LCDC_MEMOR_BIG),
  75. .default_monspecs = &hammerhead_hda350t_monspecs,
  76. .guard_time = 2,
  77. };
  78. #endif
  79. static struct mci_platform_data __initdata mci0_data = {
  80. .slot[0] = {
  81. .bus_width = 4,
  82. .detect_pin = -ENODEV,
  83. .wp_pin = -ENODEV,
  84. },
  85. };
  86. struct eth_addr {
  87. u8 addr[6];
  88. };
  89. static struct eth_addr __initdata hw_addr[1];
  90. static struct macb_platform_data __initdata eth_data[1];
  91. /*
  92. * The next two functions should go away as the boot loader is
  93. * supposed to initialize the macb address registers with a valid
  94. * ethernet address. But we need to keep it around for a while until
  95. * we can be reasonably sure the boot loader does this.
  96. *
  97. * The phy_id is ignored as the driver will probe for it.
  98. */
  99. static int __init parse_tag_ethernet(struct tag *tag)
  100. {
  101. int i = tag->u.ethernet.mac_index;
  102. if (i < ARRAY_SIZE(hw_addr))
  103. memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  104. sizeof(hw_addr[i].addr));
  105. return 0;
  106. }
  107. __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  108. static void __init set_hw_addr(struct platform_device *pdev)
  109. {
  110. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  111. const u8 *addr;
  112. void __iomem *regs;
  113. struct clk *pclk;
  114. if (!res)
  115. return;
  116. if (pdev->id >= ARRAY_SIZE(hw_addr))
  117. return;
  118. addr = hw_addr[pdev->id].addr;
  119. if (!is_valid_ether_addr(addr))
  120. return;
  121. /*
  122. * Since this is board-specific code, we'll cheat and use the
  123. * physical address directly as we happen to know that it's
  124. * the same as the virtual address.
  125. */
  126. regs = (void __iomem __force *)res->start;
  127. pclk = clk_get(&pdev->dev, "pclk");
  128. if (IS_ERR(pclk))
  129. return;
  130. clk_enable(pclk);
  131. __raw_writel((addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8) |
  132. addr[0], regs + 0x98);
  133. __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
  134. clk_disable(pclk);
  135. clk_put(pclk);
  136. }
  137. void __init setup_board(void)
  138. {
  139. at32_map_usart(1, 0, 0); /* USART 1: /dev/ttyS0, DB9 */
  140. at32_setup_serial_console(0);
  141. }
  142. static struct i2c_gpio_platform_data i2c_gpio_data = {
  143. .sda_pin = GPIO_PIN_PA(6),
  144. .scl_pin = GPIO_PIN_PA(7),
  145. .sda_is_open_drain = 1,
  146. .scl_is_open_drain = 1,
  147. .udelay = 2, /* close to 100 kHz */
  148. };
  149. static struct platform_device i2c_gpio_device = {
  150. .name = "i2c-gpio",
  151. .id = 0,
  152. .dev = { .platform_data = &i2c_gpio_data, },
  153. };
  154. static struct i2c_board_info __initdata i2c_info[] = {};
  155. #ifdef CONFIG_BOARD_HAMMERHEAD_SND
  156. static struct ac97c_platform_data ac97c_data = {
  157. .reset_pin = GPIO_PIN_PA(16),
  158. };
  159. #endif
  160. static int __init hammerhead_init(void)
  161. {
  162. /*
  163. * Hammerhead uses 32-bit SDRAM interface. Reserve the
  164. * SDRAM-specific pins so that nobody messes with them.
  165. */
  166. at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL);
  167. at32_add_device_usart(0);
  168. /* Reserve PB29 (GCLK3). This pin is used as clock source
  169. * for ETH PHY (25MHz). GCLK3 setup is done by U-Boot.
  170. */
  171. at32_reserve_pin(GPIO_PIOB_BASE, (1<<29));
  172. /*
  173. * Hammerhead uses only one ethernet port, so we don't set
  174. * address of second port
  175. */
  176. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  177. #ifdef CONFIG_BOARD_HAMMERHEAD_FPGA
  178. at32_add_device_hh_fpga();
  179. #endif
  180. at32_add_device_mci(0, &mci0_data);
  181. #ifdef CONFIG_BOARD_HAMMERHEAD_USB
  182. at32_add_device_usba(0, NULL);
  183. #endif
  184. #ifdef CONFIG_BOARD_HAMMERHEAD_LCD
  185. at32_add_device_lcdc(0, &hammerhead_lcdc_data, fbmem_start,
  186. fbmem_size, ATMEL_LCDC_PRI_24BIT);
  187. #endif
  188. at32_select_gpio(i2c_gpio_data.sda_pin,
  189. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT |
  190. AT32_GPIOF_HIGH);
  191. at32_select_gpio(i2c_gpio_data.scl_pin,
  192. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT |
  193. AT32_GPIOF_HIGH);
  194. platform_device_register(&i2c_gpio_device);
  195. i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
  196. #ifdef CONFIG_BOARD_HAMMERHEAD_SND
  197. at32_add_device_ac97c(0, &ac97c_data, AC97C_BOTH);
  198. #endif
  199. /* Select the Touchscreen interrupt pin mode */
  200. at32_select_periph(GPIO_PIOB_BASE, 0x08000000, GPIO_PERIPH_A, 0);
  201. return 0;
  202. }
  203. postcore_initcall(hammerhead_init);