setup.c 7.9 KB

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