setup.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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 macb_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. .detect_is_active_high = true,
  88. },
  89. };
  90. static int __init parse_tag_ethernet(struct tag *tag)
  91. {
  92. int i;
  93. i = tag->u.ethernet.mac_index;
  94. if (i < ARRAY_SIZE(hw_addr)) {
  95. memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
  96. sizeof(hw_addr[i].addr));
  97. }
  98. return 0;
  99. }
  100. __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
  101. static void __init set_hw_addr(struct platform_device *pdev)
  102. {
  103. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  104. const u8 *addr;
  105. void __iomem *regs;
  106. struct clk *pclk;
  107. if (!res)
  108. return;
  109. if (pdev->id >= ARRAY_SIZE(hw_addr))
  110. return;
  111. addr = hw_addr[pdev->id].addr;
  112. if (!is_valid_ether_addr(addr))
  113. return;
  114. regs = (void __iomem __force *)res->start;
  115. pclk = clk_get(&pdev->dev, "pclk");
  116. if (IS_ERR(pclk))
  117. return;
  118. clk_enable(pclk);
  119. __raw_writel((addr[3] << 24) | (addr[2] << 16)
  120. | (addr[1] << 8) | addr[0], regs + 0x98);
  121. __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
  122. clk_disable(pclk);
  123. clk_put(pclk);
  124. }
  125. static struct i2c_gpio_platform_data i2c_gpio_data = {
  126. .sda_pin = GPIO_PIN_PA(6),
  127. .scl_pin = GPIO_PIN_PA(7),
  128. .sda_is_open_drain = 1,
  129. .scl_is_open_drain = 1,
  130. .udelay = 2,
  131. };
  132. static struct platform_device i2c_gpio_device = {
  133. .name = "i2c-gpio",
  134. .id = 0,
  135. .dev = {
  136. .platform_data = &i2c_gpio_data,
  137. },
  138. };
  139. static struct i2c_board_info __initdata i2c_info[] = {
  140. {
  141. I2C_BOARD_INFO("pcf8563", 0x51)
  142. },
  143. };
  144. #ifdef CONFIG_LEDS_ATMEL_PWM
  145. static struct gpio_led stk_pwm_led[] = {
  146. {
  147. .name = "backlight",
  148. .gpio = 0, /* PWM channel 0 (LCD backlight) */
  149. },
  150. };
  151. static struct gpio_led_platform_data stk_pwm_led_data = {
  152. .num_leds = ARRAY_SIZE(stk_pwm_led),
  153. .leds = stk_pwm_led,
  154. };
  155. static struct platform_device stk_pwm_led_dev = {
  156. .name = "leds-atmel-pwm",
  157. .id = -1,
  158. .dev = {
  159. .platform_data = &stk_pwm_led_data,
  160. },
  161. };
  162. #endif
  163. const char *merisc_model(void)
  164. {
  165. switch (merisc_board_id) {
  166. case 0:
  167. case 1:
  168. return "500-01";
  169. case 2:
  170. return "BT";
  171. default:
  172. return "Unknown";
  173. }
  174. }
  175. const char *merisc_revision(void)
  176. {
  177. switch (merisc_board_id) {
  178. case 0:
  179. return "B";
  180. case 1:
  181. return "D";
  182. case 2:
  183. return "A";
  184. default:
  185. return "Unknown";
  186. }
  187. }
  188. static void detect_merisc_board_id(void)
  189. {
  190. /* Board ID pins MUST be set as input or the board may be damaged */
  191. at32_select_gpio(GPIO_PIN_PA(24), AT32_GPIOF_PULLUP);
  192. at32_select_gpio(GPIO_PIN_PA(25), AT32_GPIOF_PULLUP);
  193. at32_select_gpio(GPIO_PIN_PA(26), AT32_GPIOF_PULLUP);
  194. at32_select_gpio(GPIO_PIN_PA(27), AT32_GPIOF_PULLUP);
  195. merisc_board_id = !gpio_get_value(GPIO_PIN_PA(24)) +
  196. !gpio_get_value(GPIO_PIN_PA(25)) * 2 +
  197. !gpio_get_value(GPIO_PIN_PA(26)) * 4 +
  198. !gpio_get_value(GPIO_PIN_PA(27)) * 8;
  199. }
  200. void __init setup_board(void)
  201. {
  202. at32_map_usart(0, 0, 0);
  203. at32_map_usart(1, 1, 0);
  204. at32_map_usart(3, 3, 0);
  205. at32_setup_serial_console(1);
  206. }
  207. static int __init merisc_init(void)
  208. {
  209. detect_merisc_board_id();
  210. printk(KERN_NOTICE "BOARD: Merisc %s revision %s\n", merisc_model(),
  211. merisc_revision());
  212. /* Reserve pins for SDRAM */
  213. at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL | (1 << 26));
  214. if (merisc_board_id >= 1)
  215. at32_map_usart(2, 2, 0);
  216. at32_add_device_usart(0);
  217. at32_add_device_usart(1);
  218. if (merisc_board_id >= 1)
  219. at32_add_device_usart(2);
  220. at32_add_device_usart(3);
  221. set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
  222. /* ADS7846 PENIRQ */
  223. if (merisc_board_id == 0) {
  224. ads7846_data.get_pendown_state = ads7846_get_pendown_state_PB26;
  225. at32_select_periph(GPIO_PIOB_BASE, 1 << 26,
  226. GPIO_PERIPH_A, AT32_GPIOF_PULLUP);
  227. spi0_board_info[0].irq = AT32_EXTINT(1);
  228. } else {
  229. ads7846_data.get_pendown_state = ads7846_get_pendown_state_PB28;
  230. at32_select_periph(GPIO_PIOB_BASE, 1 << 28, GPIO_PERIPH_A,
  231. AT32_GPIOF_PULLUP);
  232. spi0_board_info[0].irq = AT32_EXTINT(3);
  233. }
  234. /* ADS7846 busy pin */
  235. at32_select_gpio(GPIO_PIN_PA(4), AT32_GPIOF_PULLUP);
  236. at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
  237. at32_add_device_mci(0, &mci0_data);
  238. #ifdef CONFIG_LEDS_ATMEL_PWM
  239. at32_add_device_pwm((1 << 0) | (1 << 2));
  240. platform_device_register(&stk_pwm_led_dev);
  241. #else
  242. at32_add_device_pwm((1 << 2));
  243. #endif
  244. at32_select_gpio(i2c_gpio_data.sda_pin,
  245. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  246. at32_select_gpio(i2c_gpio_data.scl_pin,
  247. AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
  248. platform_device_register(&i2c_gpio_device);
  249. i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
  250. return 0;
  251. }
  252. postcore_initcall(merisc_init);