setup.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Board-specific setup code for the MIMC200
  3. *
  4. * Copyright (C) 2008 Mercury IMC Ltd
  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. extern struct atmel_lcdfb_pdata mimc200_lcdc_data;
  11. #include <linux/clk.h>
  12. #include <linux/etherdevice.h>
  13. #include <linux/i2c-gpio.h>
  14. #include <linux/init.h>
  15. #include <linux/linkage.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/types.h>
  18. #include <linux/leds.h>
  19. #include <linux/spi/spi.h>
  20. #include <linux/spi/eeprom.h>
  21. #include <video/atmel_lcdc.h>
  22. #include <linux/fb.h>
  23. #include <linux/atmel-mci.h>
  24. #include <linux/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] = 10000000, /* 10 MHz on osc0 */
  34. [2] = 12000000, /* 12 MHz on osc1 */
  35. };
  36. /* Initialized by bootloader-specific startup code. */
  37. struct tag *bootloader_tags __initdata;
  38. static struct fb_videomode __initdata pt0434827_modes[] = {
  39. {
  40. .name = "480x272 @ 72",
  41. .refresh = 72,
  42. .xres = 480, .yres = 272,
  43. .pixclock = KHZ2PICOS(10000),
  44. .left_margin = 1, .right_margin = 1,
  45. .upper_margin = 12, .lower_margin = 1,
  46. .hsync_len = 42, .vsync_len = 1,
  47. .sync = 0,
  48. .vmode = FB_VMODE_NONINTERLACED,
  49. },
  50. };
  51. static struct fb_monspecs __initdata mimc200_default_monspecs = {
  52. .manufacturer = "PT",
  53. .monitor = "PT0434827-A401",
  54. .modedb = pt0434827_modes,
  55. .modedb_len = ARRAY_SIZE(pt0434827_modes),
  56. .hfmin = 14820,
  57. .hfmax = 22230,
  58. .vfmin = 60,
  59. .vfmax = 85,
  60. .dclkmax = 25200000,
  61. };
  62. struct atmel_lcdfb_pdata __initdata mimc200_lcdc_data = {
  63. .default_bpp = 16,
  64. .default_dmacon = ATMEL_LCDC_DMAEN | ATMEL_LCDC_DMA2DEN,
  65. .default_lcdcon2 = (ATMEL_LCDC_DISTYPE_TFT
  66. | ATMEL_LCDC_INVCLK
  67. | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE
  68. | ATMEL_LCDC_MEMOR_BIG),
  69. .default_monspecs = &mimc200_default_monspecs,
  70. .guard_time = 2,
  71. };
  72. struct eth_addr {
  73. u8 addr[6];
  74. };
  75. static struct eth_addr __initdata hw_addr[2];
  76. static struct macb_platform_data __initdata eth_data[2];
  77. static struct spi_eeprom eeprom_25lc010 = {
  78. .name = "25lc010",
  79. .byte_len = 128,
  80. .page_size = 16,
  81. .flags = EE_ADDR1,
  82. };
  83. static struct spi_board_info spi0_board_info[] __initdata = {
  84. {
  85. .modalias = "rtc-ds1390",
  86. .max_speed_hz = 4000000,
  87. .chip_select = 2,
  88. },
  89. {
  90. .modalias = "at25",
  91. .max_speed_hz = 1000000,
  92. .chip_select = 1,
  93. .mode = SPI_MODE_3,
  94. .platform_data = &eeprom_25lc010,
  95. },
  96. };
  97. static struct mci_platform_data __initdata mci0_data = {
  98. .slot[0] = {
  99. .bus_width = 4,
  100. .detect_pin = GPIO_PIN_PA(26),
  101. .wp_pin = GPIO_PIN_PA(27),
  102. },
  103. };
  104. /*
  105. * The next two functions should go away as the boot loader is
  106. * supposed to initialize the macb address registers with a valid
  107. * ethernet address. But we need to keep it around for a while until
  108. * we can be reasonably sure the boot loader does this.
  109. *
  110. * The phy_id is ignored as the driver will probe for it.
  111. */
  112. static int __init parse_tag_ethernet(struct tag *tag)
  113. {
  114. int i;
  115. i = tag->u.ethernet.mac_index;
  116. if (i < ARRAY_SIZE(hw_addr))
  117. memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  118. sizeof(hw_addr[i].addr));
  119. return 0;
  120. }
  121. __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  122. static void __init set_hw_addr(struct platform_device *pdev)
  123. {
  124. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  125. const u8 *addr;
  126. void __iomem *regs;
  127. struct clk *pclk;
  128. if (!res)
  129. return;
  130. if (pdev->id >= ARRAY_SIZE(hw_addr))
  131. return;
  132. addr = hw_addr[pdev->id].addr;
  133. if (!is_valid_ether_addr(addr))
  134. return;
  135. /*
  136. * Since this is board-specific code, we'll cheat and use the
  137. * physical address directly as we happen to know that it's
  138. * the same as the virtual address.
  139. */
  140. regs = (void __iomem __force *)res->start;
  141. pclk = clk_get(&pdev->dev, "pclk");
  142. if (IS_ERR(pclk))
  143. return;
  144. clk_enable(pclk);
  145. __raw_writel((addr[3] << 24) | (addr[2] << 16)
  146. | (addr[1] << 8) | addr[0], regs + 0x98);
  147. __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
  148. clk_disable(pclk);
  149. clk_put(pclk);
  150. }
  151. void __init setup_board(void)
  152. {
  153. at32_map_usart(0, 0, 0); /* USART 0: /dev/ttyS0 (TTL --> Altera) */
  154. at32_map_usart(1, 1, 0); /* USART 1: /dev/ttyS1 (RS232) */
  155. at32_map_usart(2, 2, 0); /* USART 2: /dev/ttyS2 (RS485) */
  156. at32_map_usart(3, 3, 0); /* USART 3: /dev/ttyS3 (RS422 Multidrop) */
  157. }
  158. static struct i2c_gpio_platform_data i2c_gpio_data = {
  159. .sda_pin = GPIO_PIN_PA(6),
  160. .scl_pin = GPIO_PIN_PA(7),
  161. .sda_is_open_drain = 1,
  162. .scl_is_open_drain = 1,
  163. .udelay = 2, /* close to 100 kHz */
  164. };
  165. static struct platform_device i2c_gpio_device = {
  166. .name = "i2c-gpio",
  167. .id = 0,
  168. .dev = {
  169. .platform_data = &i2c_gpio_data,
  170. },
  171. };
  172. static struct i2c_board_info __initdata i2c_info[] = {
  173. };
  174. static int __init mimc200_init(void)
  175. {
  176. /*
  177. * MIMC200 uses 16-bit SDRAM interface, so we don't need to
  178. * reserve any pins for it.
  179. */
  180. at32_add_device_usart(0);
  181. at32_add_device_usart(1);
  182. at32_add_device_usart(2);
  183. at32_add_device_usart(3);
  184. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  185. set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
  186. at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
  187. at32_add_device_mci(0, &mci0_data);
  188. at32_add_device_usba(0, NULL);
  189. at32_select_periph(GPIO_PIOB_BASE, 1 << 28, 0, AT32_GPIOF_PULLUP);
  190. at32_select_gpio(i2c_gpio_data.sda_pin,
  191. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  192. at32_select_gpio(i2c_gpio_data.scl_pin,
  193. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  194. platform_device_register(&i2c_gpio_device);
  195. i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
  196. at32_add_device_lcdc(0, &mimc200_lcdc_data,
  197. fbmem_start, fbmem_size,
  198. ATMEL_LCDC_CONTROL | ATMEL_LCDC_ALT_CONTROL | ATMEL_LCDC_ALT_24B_DATA);
  199. return 0;
  200. }
  201. postcore_initcall(mimc200_init);