setup.c 8.3 KB

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