setup.c 7.8 KB

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