setup.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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-pwm-bl.h>
  21. #include <linux/spi/spi.h>
  22. #include <linux/spi/ads7846.h>
  23. #include <video/atmel_lcdc.h>
  24. #include <asm/setup.h>
  25. #include <asm/arch/at32ap700x.h>
  26. #include <asm/arch/init.h>
  27. #include <asm/arch/board.h>
  28. #include <asm/arch/portmux.h>
  29. /* Oscillator frequencies. These are board-specific */
  30. unsigned long at32_board_osc_rates[3] = {
  31. [0] = 32768, /* 32.768 kHz on RTC osc */
  32. [1] = 20000000, /* 20 MHz on osc0 */
  33. [2] = 12000000, /* 12 MHz on osc1 */
  34. };
  35. /* Initialized by bootloader-specific startup code. */
  36. struct tag *bootloader_tags __initdata;
  37. struct eth_addr {
  38. u8 addr[6];
  39. };
  40. static struct eth_addr __initdata hw_addr[1];
  41. static struct eth_platform_data __initdata eth_data[1] = {
  42. {
  43. .phy_mask = ~(1U << 1),
  44. },
  45. };
  46. static int ads7843_get_pendown_state(void)
  47. {
  48. return !gpio_get_value(GPIO_PIN_PB(3));
  49. }
  50. static struct ads7846_platform_data ads7843_data = {
  51. .model = 7843,
  52. .get_pendown_state = ads7843_get_pendown_state,
  53. .pressure_max = 255,
  54. /*
  55. * Values below are for debounce filtering, these can be experimented
  56. * with further.
  57. */
  58. .debounce_max = 20,
  59. .debounce_rep = 4,
  60. .debounce_tol = 5,
  61. };
  62. static struct spi_board_info __initdata spi1_board_info[] = {
  63. {
  64. /* ADS7843 touch controller */
  65. .modalias = "ads7846",
  66. .max_speed_hz = 2000000,
  67. .chip_select = 0,
  68. .bus_num = 1,
  69. .platform_data = &ads7843_data,
  70. },
  71. };
  72. static struct fb_videomode __initdata lb104v03_modes[] = {
  73. {
  74. .name = "640x480 @ 50",
  75. .refresh = 50,
  76. .xres = 640, .yres = 480,
  77. .pixclock = KHZ2PICOS(25100),
  78. .left_margin = 90, .right_margin = 70,
  79. .upper_margin = 30, .lower_margin = 15,
  80. .hsync_len = 12, .vsync_len = 2,
  81. .sync = 0,
  82. .vmode = FB_VMODE_NONINTERLACED,
  83. },
  84. };
  85. static struct fb_monspecs __initdata favr32_default_monspecs = {
  86. .manufacturer = "LG",
  87. .monitor = "LB104V03",
  88. .modedb = lb104v03_modes,
  89. .modedb_len = ARRAY_SIZE(lb104v03_modes),
  90. .hfmin = 27273,
  91. .hfmax = 31111,
  92. .vfmin = 45,
  93. .vfmax = 60,
  94. .dclkmax = 28000000,
  95. };
  96. struct atmel_lcdfb_info __initdata favr32_lcdc_data = {
  97. .default_bpp = 16,
  98. .default_dmacon = ATMEL_LCDC_DMAEN | ATMEL_LCDC_DMA2DEN,
  99. .default_lcdcon2 = (ATMEL_LCDC_DISTYPE_TFT
  100. | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE
  101. | ATMEL_LCDC_MEMOR_BIG),
  102. .default_monspecs = &favr32_default_monspecs,
  103. .guard_time = 2,
  104. };
  105. static struct gpio_led favr32_leds[] = {
  106. {
  107. .name = "green",
  108. .gpio = GPIO_PIN_PE(19),
  109. .default_trigger = "heartbeat",
  110. .active_low = 1,
  111. },
  112. {
  113. .name = "red",
  114. .gpio = GPIO_PIN_PE(20),
  115. .active_low = 1,
  116. },
  117. };
  118. static struct gpio_led_platform_data favr32_led_data = {
  119. .num_leds = ARRAY_SIZE(favr32_leds),
  120. .leds = favr32_leds,
  121. };
  122. static struct platform_device favr32_led_dev = {
  123. .name = "leds-gpio",
  124. .id = 0,
  125. .dev = {
  126. .platform_data = &favr32_led_data,
  127. },
  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 (!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 favr32_setup_leds(void)
  177. {
  178. unsigned i;
  179. for (i = 0; i < ARRAY_SIZE(favr32_leds); i++)
  180. at32_select_gpio(favr32_leds[i].gpio, AT32_GPIOF_OUTPUT);
  181. platform_device_register(&favr32_led_dev);
  182. }
  183. static struct atmel_pwm_bl_platform_data atmel_pwm_bl_pdata = {
  184. .pwm_channel = 2,
  185. .pwm_frequency = 200000,
  186. .pwm_compare_max = 345,
  187. .pwm_duty_max = 345,
  188. .pwm_duty_min = 90,
  189. .pwm_active_low = 1,
  190. .gpio_on = GPIO_PIN_PA(28),
  191. .on_active_low = 0,
  192. };
  193. static struct platform_device atmel_pwm_bl_dev = {
  194. .name = "atmel-pwm-bl",
  195. .id = 0,
  196. .dev = {
  197. .platform_data = &atmel_pwm_bl_pdata,
  198. },
  199. };
  200. static void __init favr32_setup_atmel_pwm_bl(void)
  201. {
  202. platform_device_register(&atmel_pwm_bl_dev);
  203. at32_select_gpio(atmel_pwm_bl_pdata.gpio_on, 0);
  204. }
  205. void __init setup_board(void)
  206. {
  207. at32_map_usart(3, 0); /* USART 3 => /dev/ttyS0 */
  208. at32_setup_serial_console(0);
  209. }
  210. static int __init set_abdac_rate(struct platform_device *pdev)
  211. {
  212. int retval;
  213. struct clk *osc1;
  214. struct clk *pll1;
  215. struct clk *abdac;
  216. if (pdev == NULL)
  217. return -ENXIO;
  218. osc1 = clk_get(NULL, "osc1");
  219. if (IS_ERR(osc1)) {
  220. retval = PTR_ERR(osc1);
  221. goto out;
  222. }
  223. pll1 = clk_get(NULL, "pll1");
  224. if (IS_ERR(pll1)) {
  225. retval = PTR_ERR(pll1);
  226. goto out_osc1;
  227. }
  228. abdac = clk_get(&pdev->dev, "sample_clk");
  229. if (IS_ERR(abdac)) {
  230. retval = PTR_ERR(abdac);
  231. goto out_pll1;
  232. }
  233. retval = clk_set_parent(pll1, osc1);
  234. if (retval != 0)
  235. goto out_abdac;
  236. /*
  237. * Rate is 32000 to 50000 and ABDAC oversamples 256x. Multiply, in
  238. * power of 2, to a value above 80 MHz. Power of 2 so it is possible
  239. * for the generic clock to divide it down again and 80 MHz is the
  240. * lowest frequency for the PLL.
  241. */
  242. retval = clk_round_rate(pll1,
  243. CONFIG_BOARD_FAVR32_ABDAC_RATE * 256 * 16);
  244. if (retval < 0)
  245. goto out_abdac;
  246. retval = clk_set_rate(pll1, retval);
  247. if (retval != 0)
  248. goto out_abdac;
  249. retval = clk_set_parent(abdac, pll1);
  250. if (retval != 0)
  251. goto out_abdac;
  252. out_abdac:
  253. clk_put(abdac);
  254. out_pll1:
  255. clk_put(pll1);
  256. out_osc1:
  257. clk_put(osc1);
  258. out:
  259. return retval;
  260. }
  261. static int __init favr32_init(void)
  262. {
  263. /*
  264. * Favr-32 uses 32-bit SDRAM interface. Reserve the SDRAM-specific
  265. * pins so that nobody messes with them.
  266. */
  267. at32_reserve_pin(GPIO_PIN_PE(0)); /* DATA[16] */
  268. at32_reserve_pin(GPIO_PIN_PE(1)); /* DATA[17] */
  269. at32_reserve_pin(GPIO_PIN_PE(2)); /* DATA[18] */
  270. at32_reserve_pin(GPIO_PIN_PE(3)); /* DATA[19] */
  271. at32_reserve_pin(GPIO_PIN_PE(4)); /* DATA[20] */
  272. at32_reserve_pin(GPIO_PIN_PE(5)); /* DATA[21] */
  273. at32_reserve_pin(GPIO_PIN_PE(6)); /* DATA[22] */
  274. at32_reserve_pin(GPIO_PIN_PE(7)); /* DATA[23] */
  275. at32_reserve_pin(GPIO_PIN_PE(8)); /* DATA[24] */
  276. at32_reserve_pin(GPIO_PIN_PE(9)); /* DATA[25] */
  277. at32_reserve_pin(GPIO_PIN_PE(10)); /* DATA[26] */
  278. at32_reserve_pin(GPIO_PIN_PE(11)); /* DATA[27] */
  279. at32_reserve_pin(GPIO_PIN_PE(12)); /* DATA[28] */
  280. at32_reserve_pin(GPIO_PIN_PE(13)); /* DATA[29] */
  281. at32_reserve_pin(GPIO_PIN_PE(14)); /* DATA[30] */
  282. at32_reserve_pin(GPIO_PIN_PE(15)); /* DATA[31] */
  283. at32_reserve_pin(GPIO_PIN_PE(26)); /* SDCS */
  284. at32_select_gpio(GPIO_PIN_PB(3), 0); /* IRQ from ADS7843 */
  285. at32_add_system_devices();
  286. at32_add_device_usart(0);
  287. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  288. spi1_board_info[0].irq = gpio_to_irq(GPIO_PIN_PB(3));
  289. set_abdac_rate(at32_add_device_abdac(0));
  290. at32_add_device_pwm(1 << atmel_pwm_bl_pdata.pwm_channel);
  291. at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
  292. at32_add_device_mci(0, NULL);
  293. at32_add_device_usba(0, NULL);
  294. at32_add_device_lcdc(0, &favr32_lcdc_data, fbmem_start, fbmem_size, 0);
  295. favr32_setup_leds();
  296. favr32_setup_atmel_pwm_bl();
  297. return 0;
  298. }
  299. postcore_initcall(favr32_init);