2 * Board-specific setup code for the Merisc
4 * Copyright (C) 2008 Martinsson Elektronik AB
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.
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>
24 #include <linux/atmel-mci.h>
27 #include <asm/setup.h>
30 #include <mach/at32ap700x.h>
31 #include <mach/board.h>
32 #include <mach/init.h>
33 #include <mach/portmux.h>
37 /* Holds the autodetected board model and revision */
38 static int merisc_board_id;
40 /* Initialized by bootloader-specific startup code. */
41 struct tag *bootloader_tags __initdata;
43 /* Oscillator frequencies. These are board specific */
44 unsigned long at32_board_osc_rates[3] = {
45 [0] = 32768, /* 32.768 kHz on RTC osc */
46 [1] = 20000000, /* 20 MHz on osc0 */
47 [2] = 12000000, /* 12 MHz on osc1 */
54 static struct eth_addr __initdata hw_addr[2];
55 static struct eth_platform_data __initdata eth_data[2];
57 static int ads7846_get_pendown_state_PB26(void)
59 return !gpio_get_value(GPIO_PIN_PB(26));
62 static int ads7846_get_pendown_state_PB28(void)
64 return !gpio_get_value(GPIO_PIN_PB(28));
67 static struct ads7846_platform_data __initdata ads7846_data = {
69 .vref_delay_usecs = 100,
72 .settle_delay_usecs = 150,
73 .penirq_recheck_delay_usecs = 1,
78 .get_pendown_state = ads7846_get_pendown_state_PB26,
81 .filter_cleanup = NULL,
84 static struct spi_board_info __initdata spi0_board_info[] = {
86 .modalias = "ads7846",
87 .max_speed_hz = 3250000,
90 .platform_data = &ads7846_data,
95 static struct mci_platform_data __initdata mci0_data = {
98 .detect_pin = GPIO_PIN_PE(19),
99 .wp_pin = GPIO_PIN_PE(20),
103 static int __init parse_tag_ethernet(struct tag *tag)
107 i = tag->u.ethernet.mac_index;
108 if (i < ARRAY_SIZE(hw_addr)) {
109 memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
110 sizeof(hw_addr[i].addr));
115 __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
117 static void __init set_hw_addr(struct platform_device *pdev)
119 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
127 if (pdev->id >= ARRAY_SIZE(hw_addr))
130 addr = hw_addr[pdev->id].addr;
131 if (!is_valid_ether_addr(addr))
134 regs = (void __iomem __force *)res->start;
135 pclk = clk_get(&pdev->dev, "pclk");
140 __raw_writel((addr[3] << 24) | (addr[2] << 16)
141 | (addr[1] << 8) | addr[0], regs + 0x98);
142 __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
147 static struct i2c_gpio_platform_data i2c_gpio_data = {
148 .sda_pin = GPIO_PIN_PA(6),
149 .scl_pin = GPIO_PIN_PA(7),
150 .sda_is_open_drain = 1,
151 .scl_is_open_drain = 1,
155 static struct platform_device i2c_gpio_device = {
159 .platform_data = &i2c_gpio_data,
163 static struct i2c_board_info __initdata i2c_info[] = {
165 I2C_BOARD_INFO("pcf8563", 0x51)
169 #ifdef CONFIG_LEDS_ATMEL_PWM
170 static struct gpio_led stk_pwm_led[] = {
173 .gpio = 0, /* PWM channel 0 (LCD backlight) */
177 static struct gpio_led_platform_data stk_pwm_led_data = {
178 .num_leds = ARRAY_SIZE(stk_pwm_led),
182 static struct platform_device stk_pwm_led_dev = {
183 .name = "leds-atmel-pwm",
186 .platform_data = &stk_pwm_led_data,
191 const char *merisc_model(void)
193 switch (merisc_board_id) {
204 const char *merisc_revision(void)
206 switch (merisc_board_id) {
218 static void detect_merisc_board_id(void)
220 /* Board ID pins MUST be set as input or the board may be damaged */
221 at32_select_gpio(GPIO_PIN_PA(24), AT32_GPIOF_PULLUP);
222 at32_select_gpio(GPIO_PIN_PA(25), AT32_GPIOF_PULLUP);
223 at32_select_gpio(GPIO_PIN_PA(26), AT32_GPIOF_PULLUP);
224 at32_select_gpio(GPIO_PIN_PA(27), AT32_GPIOF_PULLUP);
226 merisc_board_id = !gpio_get_value(GPIO_PIN_PA(24)) +
227 !gpio_get_value(GPIO_PIN_PA(25)) * 2 +
228 !gpio_get_value(GPIO_PIN_PA(26)) * 4 +
229 !gpio_get_value(GPIO_PIN_PA(27)) * 8;
232 void __init setup_board(void)
234 at32_map_usart(0, 0, 0);
235 at32_map_usart(1, 1, 0);
236 at32_map_usart(3, 3, 0);
237 at32_setup_serial_console(1);
240 static int __init merisc_init(void)
242 detect_merisc_board_id();
244 printk(KERN_NOTICE "BOARD: Merisc %s revision %s\n", merisc_model(),
247 /* Reserve pins for SDRAM */
248 at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL | (1 << 26));
250 if (merisc_board_id >= 1)
251 at32_map_usart(2, 2, 0);
253 at32_add_device_usart(0);
254 at32_add_device_usart(1);
255 if (merisc_board_id >= 1)
256 at32_add_device_usart(2);
257 at32_add_device_usart(3);
258 set_hw_addr(at32_add_device_eth(0, ð_data[0]));
261 if (merisc_board_id == 0) {
262 ads7846_data.get_pendown_state = ads7846_get_pendown_state_PB26;
263 at32_select_periph(GPIO_PIOB_BASE, 1 << 26,
264 GPIO_PERIPH_A, AT32_GPIOF_PULLUP);
265 spi0_board_info[0].irq = AT32_EXTINT(1);
267 ads7846_data.get_pendown_state = ads7846_get_pendown_state_PB28;
268 at32_select_periph(GPIO_PIOB_BASE, 1 << 28, GPIO_PERIPH_A,
270 spi0_board_info[0].irq = AT32_EXTINT(3);
273 /* ADS7846 busy pin */
274 at32_select_gpio(GPIO_PIN_PA(4), AT32_GPIOF_PULLUP);
276 at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
278 at32_add_device_mci(0, &mci0_data);
280 #ifdef CONFIG_LEDS_ATMEL_PWM
281 at32_add_device_pwm((1 << 0) | (1 << 2));
282 platform_device_register(&stk_pwm_led_dev);
284 at32_add_device_pwm((1 << 2));
287 at32_select_gpio(i2c_gpio_data.sda_pin,
288 AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
289 at32_select_gpio(i2c_gpio_data.scl_pin,
290 AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
291 platform_device_register(&i2c_gpio_device);
293 i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
297 postcore_initcall(merisc_init);