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>
25 #include <linux/pwm.h>
26 #include <linux/leds_pwm.h>
29 #include <asm/setup.h>
32 #include <mach/at32ap700x.h>
33 #include <mach/board.h>
34 #include <mach/init.h>
35 #include <mach/portmux.h>
39 /* Holds the autodetected board model and revision */
40 static int merisc_board_id
;
42 /* Initialized by bootloader-specific startup code. */
43 struct tag
*bootloader_tags __initdata
;
45 /* Oscillator frequencies. These are board specific */
46 unsigned long at32_board_osc_rates
[3] = {
47 [0] = 32768, /* 32.768 kHz on RTC osc */
48 [1] = 20000000, /* 20 MHz on osc0 */
49 [2] = 12000000, /* 12 MHz on osc1 */
56 static struct eth_addr __initdata hw_addr
[2];
57 static struct macb_platform_data __initdata eth_data
[2];
59 static int ads7846_get_pendown_state_PB26(void)
61 return !gpio_get_value(GPIO_PIN_PB(26));
64 static int ads7846_get_pendown_state_PB28(void)
66 return !gpio_get_value(GPIO_PIN_PB(28));
69 static struct ads7846_platform_data __initdata ads7846_data
= {
71 .vref_delay_usecs
= 100,
74 .settle_delay_usecs
= 150,
75 .penirq_recheck_delay_usecs
= 1,
80 .get_pendown_state
= ads7846_get_pendown_state_PB26
,
83 .filter_cleanup
= NULL
,
86 static struct spi_board_info __initdata spi0_board_info
[] = {
88 .modalias
= "ads7846",
89 .max_speed_hz
= 3250000,
92 .platform_data
= &ads7846_data
,
97 static struct mci_platform_data __initdata mci0_data
= {
100 .detect_pin
= GPIO_PIN_PE(19),
101 .wp_pin
= GPIO_PIN_PE(20),
102 .detect_is_active_high
= true,
106 static int __init
parse_tag_ethernet(struct tag
*tag
)
110 i
= tag
->u
.ethernet
.mac_index
;
111 if (i
< ARRAY_SIZE(hw_addr
)) {
112 memcpy(hw_addr
[i
].addr
, tag
->u
.ethernet
.hw_address
,
113 sizeof(hw_addr
[i
].addr
));
118 __tagtable(ATAG_ETHERNET
, parse_tag_ethernet
);
120 static void __init
set_hw_addr(struct platform_device
*pdev
)
122 struct resource
*res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
130 if (pdev
->id
>= ARRAY_SIZE(hw_addr
))
133 addr
= hw_addr
[pdev
->id
].addr
;
134 if (!is_valid_ether_addr(addr
))
137 regs
= (void __iomem __force
*)res
->start
;
138 pclk
= clk_get(&pdev
->dev
, "pclk");
143 __raw_writel((addr
[3] << 24) | (addr
[2] << 16)
144 | (addr
[1] << 8) | addr
[0], regs
+ 0x98);
145 __raw_writel((addr
[5] << 8) | addr
[4], regs
+ 0x9c);
150 static struct i2c_gpio_platform_data i2c_gpio_data
= {
151 .sda_pin
= GPIO_PIN_PA(6),
152 .scl_pin
= GPIO_PIN_PA(7),
153 .sda_is_open_drain
= 1,
154 .scl_is_open_drain
= 1,
158 static struct platform_device i2c_gpio_device
= {
162 .platform_data
= &i2c_gpio_data
,
166 static struct i2c_board_info __initdata i2c_info
[] = {
168 I2C_BOARD_INFO("pcf8563", 0x51)
172 #if IS_ENABLED(CONFIG_LEDS_PWM)
173 static struct pwm_lookup pwm_lookup
[] = {
174 PWM_LOOKUP("at91sam9rl-pwm", 0, "leds_pwm", "backlight",
175 5000, PWM_POLARITY_NORMAL
),
178 static struct led_pwm pwm_leds
[] = {
181 .max_brightness
= 255,
185 static struct led_pwm_platform_data pwm_data
= {
186 .num_leds
= ARRAY_SIZE(pwm_leds
),
190 static struct platform_device leds_pwm
= {
194 .platform_data
= &pwm_data
,
199 const char *merisc_model(void)
201 switch (merisc_board_id
) {
212 const char *merisc_revision(void)
214 switch (merisc_board_id
) {
226 static void detect_merisc_board_id(void)
228 /* Board ID pins MUST be set as input or the board may be damaged */
229 at32_select_gpio(GPIO_PIN_PA(24), AT32_GPIOF_PULLUP
);
230 at32_select_gpio(GPIO_PIN_PA(25), AT32_GPIOF_PULLUP
);
231 at32_select_gpio(GPIO_PIN_PA(26), AT32_GPIOF_PULLUP
);
232 at32_select_gpio(GPIO_PIN_PA(27), AT32_GPIOF_PULLUP
);
234 merisc_board_id
= !gpio_get_value(GPIO_PIN_PA(24)) +
235 !gpio_get_value(GPIO_PIN_PA(25)) * 2 +
236 !gpio_get_value(GPIO_PIN_PA(26)) * 4 +
237 !gpio_get_value(GPIO_PIN_PA(27)) * 8;
240 void __init
setup_board(void)
242 at32_map_usart(0, 0, 0);
243 at32_map_usart(1, 1, 0);
244 at32_map_usart(3, 3, 0);
245 at32_setup_serial_console(1);
248 static int __init
merisc_init(void)
250 detect_merisc_board_id();
252 printk(KERN_NOTICE
"BOARD: Merisc %s revision %s\n", merisc_model(),
255 /* Reserve pins for SDRAM */
256 at32_reserve_pin(GPIO_PIOE_BASE
, ATMEL_EBI_PE_DATA_ALL
| (1 << 26));
258 if (merisc_board_id
>= 1)
259 at32_map_usart(2, 2, 0);
261 at32_add_device_usart(0);
262 at32_add_device_usart(1);
263 if (merisc_board_id
>= 1)
264 at32_add_device_usart(2);
265 at32_add_device_usart(3);
266 set_hw_addr(at32_add_device_eth(0, ð_data
[0]));
269 if (merisc_board_id
== 0) {
270 ads7846_data
.get_pendown_state
= ads7846_get_pendown_state_PB26
;
271 at32_select_periph(GPIO_PIOB_BASE
, 1 << 26,
272 GPIO_PERIPH_A
, AT32_GPIOF_PULLUP
);
273 spi0_board_info
[0].irq
= AT32_EXTINT(1);
275 ads7846_data
.get_pendown_state
= ads7846_get_pendown_state_PB28
;
276 at32_select_periph(GPIO_PIOB_BASE
, 1 << 28, GPIO_PERIPH_A
,
278 spi0_board_info
[0].irq
= AT32_EXTINT(3);
281 /* ADS7846 busy pin */
282 at32_select_gpio(GPIO_PIN_PA(4), AT32_GPIOF_PULLUP
);
284 at32_add_device_spi(0, spi0_board_info
, ARRAY_SIZE(spi0_board_info
));
286 at32_add_device_mci(0, &mci0_data
);
288 #if IS_ENABLED(CONFIG_LEDS_PWM)
289 pwm_add_table(pwm_lookup
, ARRAY_SIZE(pwm_lookup
));
290 at32_add_device_pwm((1 << 0) | (1 << 2));
291 platform_device_register(&leds_pwm
);
293 at32_add_device_pwm((1 << 2));
296 at32_select_gpio(i2c_gpio_data
.sda_pin
,
297 AT32_GPIOF_MULTIDRV
| AT32_GPIOF_OUTPUT
| AT32_GPIOF_HIGH
);
298 at32_select_gpio(i2c_gpio_data
.scl_pin
,
299 AT32_GPIOF_MULTIDRV
| AT32_GPIOF_OUTPUT
| AT32_GPIOF_HIGH
);
300 platform_device_register(&i2c_gpio_device
);
302 i2c_register_board_info(0, i2c_info
, ARRAY_SIZE(i2c_info
));
306 postcore_initcall(merisc_init
);