setup.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /*
  2. * Favr-32 board-specific setup code.
  3. *
  4. * Copyright (C) 2008 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/bootmem.h>
  13. #include <linux/fb.h>
  14. #include <linux/init.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/types.h>
  17. #include <linux/linkage.h>
  18. #include <linux/gpio.h>
  19. #include <linux/leds.h>
  20. #include <linux/atmel-mci.h>
  21. #include <linux/atmel-pwm-bl.h>
  22. #include <linux/spi/spi.h>
  23. #include <linux/spi/ads7846.h>
  24. #include <video/atmel_lcdc.h>
  25. #include <asm/setup.h>
  26. #include <mach/at32ap700x.h>
  27. #include <mach/init.h>
  28. #include <mach/board.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. /* Initialized by bootloader-specific startup code. */
  37. struct tag *bootloader_tags __initdata;
  38. struct eth_addr {
  39. u8 addr[6];
  40. };
  41. static struct eth_addr __initdata hw_addr[1];
  42. static struct eth_platform_data __initdata eth_data[1] = {
  43. {
  44. .phy_mask = ~(1U << 1),
  45. },
  46. };
  47. static int ads7843_get_pendown_state(void)
  48. {
  49. return !gpio_get_value(GPIO_PIN_PB(3));
  50. }
  51. static struct ads7846_platform_data ads7843_data = {
  52. .model = 7843,
  53. .get_pendown_state = ads7843_get_pendown_state,
  54. .pressure_max = 255,
  55. /*
  56. * Values below are for debounce filtering, these can be experimented
  57. * with further.
  58. */
  59. .debounce_max = 20,
  60. .debounce_rep = 4,
  61. .debounce_tol = 5,
  62. };
  63. static struct spi_board_info __initdata spi1_board_info[] = {
  64. {
  65. /* ADS7843 touch controller */
  66. .modalias = "ads7846",
  67. .max_speed_hz = 2000000,
  68. .chip_select = 0,
  69. .bus_num = 1,
  70. .platform_data = &ads7843_data,
  71. },
  72. };
  73. static struct mci_platform_data __initdata mci0_data = {
  74. .slot[0] = {
  75. .bus_width = 4,
  76. .detect_pin = -ENODEV,
  77. .wp_pin = -ENODEV,
  78. },
  79. };
  80. static struct fb_videomode __initdata lb104v03_modes[] = {
  81. {
  82. .name = "640x480 @ 50",
  83. .refresh = 50,
  84. .xres = 640, .yres = 480,
  85. .pixclock = KHZ2PICOS(25100),
  86. .left_margin = 90, .right_margin = 70,
  87. .upper_margin = 30, .lower_margin = 15,
  88. .hsync_len = 12, .vsync_len = 2,
  89. .sync = 0,
  90. .vmode = FB_VMODE_NONINTERLACED,
  91. },
  92. };
  93. static struct fb_monspecs __initdata favr32_default_monspecs = {
  94. .manufacturer = "LG",
  95. .monitor = "LB104V03",
  96. .modedb = lb104v03_modes,
  97. .modedb_len = ARRAY_SIZE(lb104v03_modes),
  98. .hfmin = 27273,
  99. .hfmax = 31111,
  100. .vfmin = 45,
  101. .vfmax = 60,
  102. .dclkmax = 28000000,
  103. };
  104. struct atmel_lcdfb_info __initdata favr32_lcdc_data = {
  105. .default_bpp = 16,
  106. .default_dmacon = ATMEL_LCDC_DMAEN | ATMEL_LCDC_DMA2DEN,
  107. .default_lcdcon2 = (ATMEL_LCDC_DISTYPE_TFT
  108. | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE
  109. | ATMEL_LCDC_MEMOR_BIG),
  110. .default_monspecs = &favr32_default_monspecs,
  111. .guard_time = 2,
  112. };
  113. static struct gpio_led favr32_leds[] = {
  114. {
  115. .name = "green",
  116. .gpio = GPIO_PIN_PE(19),
  117. .default_trigger = "heartbeat",
  118. .active_low = 1,
  119. },
  120. {
  121. .name = "red",
  122. .gpio = GPIO_PIN_PE(20),
  123. .active_low = 1,
  124. },
  125. };
  126. static struct gpio_led_platform_data favr32_led_data = {
  127. .num_leds = ARRAY_SIZE(favr32_leds),
  128. .leds = favr32_leds,
  129. };
  130. static struct platform_device favr32_led_dev = {
  131. .name = "leds-gpio",
  132. .id = 0,
  133. .dev = {
  134. .platform_data = &favr32_led_data,
  135. },
  136. };
  137. /*
  138. * The next two functions should go away as the boot loader is
  139. * supposed to initialize the macb address registers with a valid
  140. * ethernet address. But we need to keep it around for a while until
  141. * we can be reasonably sure the boot loader does this.
  142. *
  143. * The phy_id is ignored as the driver will probe for it.
  144. */
  145. static int __init parse_tag_ethernet(struct tag *tag)
  146. {
  147. int i;
  148. i = tag->u.ethernet.mac_index;
  149. if (i < ARRAY_SIZE(hw_addr))
  150. memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  151. sizeof(hw_addr[i].addr));
  152. return 0;
  153. }
  154. __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  155. static void __init set_hw_addr(struct platform_device *pdev)
  156. {
  157. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  158. const u8 *addr;
  159. void __iomem *regs;
  160. struct clk *pclk;
  161. if (!res)
  162. return;
  163. if (pdev->id >= ARRAY_SIZE(hw_addr))
  164. return;
  165. addr = hw_addr[pdev->id].addr;
  166. if (!is_valid_ether_addr(addr))
  167. return;
  168. /*
  169. * Since this is board-specific code, we'll cheat and use the
  170. * physical address directly as we happen to know that it's
  171. * the same as the virtual address.
  172. */
  173. regs = (void __iomem __force *)res->start;
  174. pclk = clk_get(&pdev->dev, "pclk");
  175. if (!pclk)
  176. return;
  177. clk_enable(pclk);
  178. __raw_writel((addr[3] << 24) | (addr[2] << 16)
  179. | (addr[1] << 8) | addr[0], regs + 0x98);
  180. __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
  181. clk_disable(pclk);
  182. clk_put(pclk);
  183. }
  184. void __init favr32_setup_leds(void)
  185. {
  186. unsigned i;
  187. for (i = 0; i < ARRAY_SIZE(favr32_leds); i++)
  188. at32_select_gpio(favr32_leds[i].gpio, AT32_GPIOF_OUTPUT);
  189. platform_device_register(&favr32_led_dev);
  190. }
  191. static struct atmel_pwm_bl_platform_data atmel_pwm_bl_pdata = {
  192. .pwm_channel = 2,
  193. .pwm_frequency = 200000,
  194. .pwm_compare_max = 345,
  195. .pwm_duty_max = 345,
  196. .pwm_duty_min = 90,
  197. .pwm_active_low = 1,
  198. .gpio_on = GPIO_PIN_PA(28),
  199. .on_active_low = 0,
  200. };
  201. static struct platform_device atmel_pwm_bl_dev = {
  202. .name = "atmel-pwm-bl",
  203. .id = 0,
  204. .dev = {
  205. .platform_data = &atmel_pwm_bl_pdata,
  206. },
  207. };
  208. static void __init favr32_setup_atmel_pwm_bl(void)
  209. {
  210. platform_device_register(&atmel_pwm_bl_dev);
  211. at32_select_gpio(atmel_pwm_bl_pdata.gpio_on, 0);
  212. }
  213. void __init setup_board(void)
  214. {
  215. at32_map_usart(3, 0); /* USART 3 => /dev/ttyS0 */
  216. at32_setup_serial_console(0);
  217. }
  218. static int __init set_abdac_rate(struct platform_device *pdev)
  219. {
  220. int retval;
  221. struct clk *osc1;
  222. struct clk *pll1;
  223. struct clk *abdac;
  224. if (pdev == NULL)
  225. return -ENXIO;
  226. osc1 = clk_get(NULL, "osc1");
  227. if (IS_ERR(osc1)) {
  228. retval = PTR_ERR(osc1);
  229. goto out;
  230. }
  231. pll1 = clk_get(NULL, "pll1");
  232. if (IS_ERR(pll1)) {
  233. retval = PTR_ERR(pll1);
  234. goto out_osc1;
  235. }
  236. abdac = clk_get(&pdev->dev, "sample_clk");
  237. if (IS_ERR(abdac)) {
  238. retval = PTR_ERR(abdac);
  239. goto out_pll1;
  240. }
  241. retval = clk_set_parent(pll1, osc1);
  242. if (retval != 0)
  243. goto out_abdac;
  244. /*
  245. * Rate is 32000 to 50000 and ABDAC oversamples 256x. Multiply, in
  246. * power of 2, to a value above 80 MHz. Power of 2 so it is possible
  247. * for the generic clock to divide it down again and 80 MHz is the
  248. * lowest frequency for the PLL.
  249. */
  250. retval = clk_round_rate(pll1,
  251. CONFIG_BOARD_FAVR32_ABDAC_RATE * 256 * 16);
  252. if (retval < 0)
  253. goto out_abdac;
  254. retval = clk_set_rate(pll1, retval);
  255. if (retval != 0)
  256. goto out_abdac;
  257. retval = clk_set_parent(abdac, pll1);
  258. if (retval != 0)
  259. goto out_abdac;
  260. out_abdac:
  261. clk_put(abdac);
  262. out_pll1:
  263. clk_put(pll1);
  264. out_osc1:
  265. clk_put(osc1);
  266. out:
  267. return retval;
  268. }
  269. static int __init favr32_init(void)
  270. {
  271. /*
  272. * Favr-32 uses 32-bit SDRAM interface. Reserve the SDRAM-specific
  273. * pins so that nobody messes with them.
  274. */
  275. at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL);
  276. at32_select_gpio(GPIO_PIN_PB(3), 0); /* IRQ from ADS7843 */
  277. at32_add_device_usart(0);
  278. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  279. spi1_board_info[0].irq = gpio_to_irq(GPIO_PIN_PB(3));
  280. set_abdac_rate(at32_add_device_abdac(0));
  281. at32_add_device_pwm(1 << atmel_pwm_bl_pdata.pwm_channel);
  282. at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
  283. at32_add_device_mci(0, &mci0_data);
  284. at32_add_device_usba(0, NULL);
  285. at32_add_device_lcdc(0, &favr32_lcdc_data, fbmem_start, fbmem_size, 0);
  286. favr32_setup_leds();
  287. favr32_setup_atmel_pwm_bl();
  288. return 0;
  289. }
  290. postcore_initcall(favr32_init);