setup.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * Board-specific setup code for the Merisc
  3. *
  4. * Copyright (C) 2008 Martinsson Elektronik AB
  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/i2c.h>
  13. #include <linux/i2c-gpio.h>
  14. #include <linux/gpio.h>
  15. #include <linux/init.h>
  16. #include <linux/linkage.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/types.h>
  19. #include <linux/leds.h>
  20. #include <linux/spi/spi.h>
  21. #include <linux/spi/ads7846.h>
  22. #include <linux/irq.h>
  23. #include <linux/fb.h>
  24. #include <linux/atmel-mci.h>
  25. #include <asm/io.h>
  26. #include <asm/setup.h>
  27. #include <asm/gpio.h>
  28. #include <mach/at32ap700x.h>
  29. #include <mach/board.h>
  30. #include <mach/init.h>
  31. #include <mach/portmux.h>
  32. #include "merisc.h"
  33. /* Holds the autodetected board model and revision */
  34. static int merisc_board_id;
  35. /* Initialized by bootloader-specific startup code. */
  36. struct tag *bootloader_tags __initdata;
  37. /* Oscillator frequencies. These are board specific */
  38. unsigned long at32_board_osc_rates[3] = {
  39. [0] = 32768, /* 32.768 kHz on RTC osc */
  40. [1] = 20000000, /* 20 MHz on osc0 */
  41. [2] = 12000000, /* 12 MHz on osc1 */
  42. };
  43. struct eth_addr {
  44. u8 addr[6];
  45. };
  46. static struct eth_addr __initdata hw_addr[2];
  47. static struct eth_platform_data __initdata eth_data[2];
  48. static int ads7846_get_pendown_state_PB26(void)
  49. {
  50. return !gpio_get_value(GPIO_PIN_PB(26));
  51. }
  52. static int ads7846_get_pendown_state_PB28(void)
  53. {
  54. return !gpio_get_value(GPIO_PIN_PB(28));
  55. }
  56. static struct ads7846_platform_data __initdata ads7846_data = {
  57. .model = 7846,
  58. .vref_delay_usecs = 100,
  59. .vref_mv = 0,
  60. .keep_vref_on = 0,
  61. .settle_delay_usecs = 150,
  62. .penirq_recheck_delay_usecs = 1,
  63. .x_plate_ohms = 800,
  64. .debounce_rep = 4,
  65. .debounce_max = 10,
  66. .debounce_tol = 50,
  67. .get_pendown_state = ads7846_get_pendown_state_PB26,
  68. .filter_init = NULL,
  69. .filter = NULL,
  70. .filter_cleanup = NULL,
  71. };
  72. static struct spi_board_info __initdata spi0_board_info[] = {
  73. {
  74. .modalias = "ads7846",
  75. .max_speed_hz = 3250000,
  76. .chip_select = 0,
  77. .bus_num = 0,
  78. .platform_data = &ads7846_data,
  79. .mode = SPI_MODE_0,
  80. },
  81. };
  82. static struct mci_platform_data __initdata mci0_data = {
  83. .slot[0] = {
  84. .bus_width = 4,
  85. .detect_pin = GPIO_PIN_PE(19),
  86. .wp_pin = GPIO_PIN_PE(20),
  87. },
  88. };
  89. static int __init parse_tag_ethernet(struct tag *tag)
  90. {
  91. int i;
  92. i = tag->u.ethernet.mac_index;
  93. if (i < ARRAY_SIZE(hw_addr)) {
  94. memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  95. sizeof(hw_addr[i].addr));
  96. }
  97. return 0;
  98. }
  99. __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  100. static void __init set_hw_addr(struct platform_device *pdev)
  101. {
  102. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  103. const u8 *addr;
  104. void __iomem *regs;
  105. struct clk *pclk;
  106. if (!res)
  107. return;
  108. if (pdev->id >= ARRAY_SIZE(hw_addr))
  109. return;
  110. addr = hw_addr[pdev->id].addr;
  111. if (!is_valid_ether_addr(addr))
  112. return;
  113. regs = (void __iomem __force *)res->start;
  114. pclk = clk_get(&pdev->dev, "pclk");
  115. if (!pclk)
  116. return;
  117. clk_enable(pclk);
  118. __raw_writel((addr[3] << 24) | (addr[2] << 16)
  119. | (addr[1] << 8) | addr[0], regs + 0x98);
  120. __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
  121. clk_disable(pclk);
  122. clk_put(pclk);
  123. }
  124. static struct i2c_gpio_platform_data i2c_gpio_data = {
  125. .sda_pin = GPIO_PIN_PA(6),
  126. .scl_pin = GPIO_PIN_PA(7),
  127. .sda_is_open_drain = 1,
  128. .scl_is_open_drain = 1,
  129. .udelay = 2,
  130. };
  131. static struct platform_device i2c_gpio_device = {
  132. .name = "i2c-gpio",
  133. .id = 0,
  134. .dev = {
  135. .platform_data = &i2c_gpio_data,
  136. },
  137. };
  138. static struct i2c_board_info __initdata i2c_info[] = {
  139. {
  140. I2C_BOARD_INFO("pcf8563", 0x51)
  141. },
  142. };
  143. #ifdef CONFIG_LEDS_ATMEL_PWM
  144. static struct gpio_led stk_pwm_led[] = {
  145. {
  146. .name = "backlight",
  147. .gpio = 0, /* PWM channel 0 (LCD backlight) */
  148. },
  149. };
  150. static struct gpio_led_platform_data stk_pwm_led_data = {
  151. .num_leds = ARRAY_SIZE(stk_pwm_led),
  152. .leds = stk_pwm_led,
  153. };
  154. static struct platform_device stk_pwm_led_dev = {
  155. .name = "leds-atmel-pwm",
  156. .id = -1,
  157. .dev = {
  158. .platform_data = &stk_pwm_led_data,
  159. },
  160. };
  161. #endif
  162. const char *merisc_model(void)
  163. {
  164. switch (merisc_board_id) {
  165. case 0:
  166. case 1:
  167. return "500-01";
  168. case 2:
  169. return "BT";
  170. default:
  171. return "Unknown";
  172. }
  173. }
  174. const char *merisc_revision(void)
  175. {
  176. switch (merisc_board_id) {
  177. case 0:
  178. return "B";
  179. case 1:
  180. return "D";
  181. case 2:
  182. return "A";
  183. default:
  184. return "Unknown";
  185. }
  186. }
  187. static void detect_merisc_board_id(void)
  188. {
  189. /* Board ID pins MUST be set as input or the board may be damaged */
  190. at32_select_gpio(GPIO_PIN_PA(24), AT32_GPIOF_PULLUP);
  191. at32_select_gpio(GPIO_PIN_PA(25), AT32_GPIOF_PULLUP);
  192. at32_select_gpio(GPIO_PIN_PA(26), AT32_GPIOF_PULLUP);
  193. at32_select_gpio(GPIO_PIN_PA(27), AT32_GPIOF_PULLUP);
  194. merisc_board_id = !gpio_get_value(GPIO_PIN_PA(24)) +
  195. !gpio_get_value(GPIO_PIN_PA(25)) * 2 +
  196. !gpio_get_value(GPIO_PIN_PA(26)) * 4 +
  197. !gpio_get_value(GPIO_PIN_PA(27)) * 8;
  198. }
  199. void __init setup_board(void)
  200. {
  201. at32_map_usart(0, 0, 0);
  202. at32_map_usart(1, 1, 0);
  203. at32_map_usart(3, 3, 0);
  204. at32_setup_serial_console(1);
  205. }
  206. static int __init merisc_init(void)
  207. {
  208. detect_merisc_board_id();
  209. printk(KERN_NOTICE "BOARD: Merisc %s revision %s\n", merisc_model(),
  210. merisc_revision());
  211. /* Reserve pins for SDRAM */
  212. at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL | (1 << 26));
  213. if (merisc_board_id >= 1)
  214. at32_map_usart(2, 2, 0);
  215. at32_add_device_usart(0);
  216. at32_add_device_usart(1);
  217. if (merisc_board_id >= 1)
  218. at32_add_device_usart(2);
  219. at32_add_device_usart(3);
  220. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  221. /* ADS7846 PENIRQ */
  222. if (merisc_board_id == 0) {
  223. ads7846_data.get_pendown_state = ads7846_get_pendown_state_PB26;
  224. at32_select_periph(GPIO_PIOB_BASE, 1 << 26,
  225. GPIO_PERIPH_A, AT32_GPIOF_PULLUP);
  226. spi0_board_info[0].irq = AT32_EXTINT(1);
  227. } else {
  228. ads7846_data.get_pendown_state = ads7846_get_pendown_state_PB28;
  229. at32_select_periph(GPIO_PIOB_BASE, 1 << 28, GPIO_PERIPH_A,
  230. AT32_GPIOF_PULLUP);
  231. spi0_board_info[0].irq = AT32_EXTINT(3);
  232. }
  233. /* ADS7846 busy pin */
  234. at32_select_gpio(GPIO_PIN_PA(4), AT32_GPIOF_PULLUP);
  235. at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
  236. at32_add_device_mci(0, &mci0_data);
  237. #ifdef CONFIG_LEDS_ATMEL_PWM
  238. at32_add_device_pwm((1 << 0) | (1 << 2));
  239. platform_device_register(&stk_pwm_led_dev);
  240. #else
  241. at32_add_device_pwm((1 << 2));
  242. #endif
  243. at32_select_gpio(i2c_gpio_data.sda_pin,
  244. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  245. at32_select_gpio(i2c_gpio_data.scl_pin,
  246. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  247. platform_device_register(&i2c_gpio_device);
  248. i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
  249. return 0;
  250. }
  251. postcore_initcall(merisc_init);