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>
31 #include <mach/at32ap700x.h>
32 #include <mach/board.h>
33 #include <mach/init.h>
34 #include <mach/portmux.h>
38 /* Holds the autodetected board model and revision */
39 static int merisc_board_id;
41 /* Initialized by bootloader-specific startup code. */
42 struct tag *bootloader_tags __initdata;
44 /* Oscillator frequencies. These are board specific */
45 unsigned long at32_board_osc_rates[3] = {
46 [0] = 32768, /* 32.768 kHz on RTC osc */
47 [1] = 20000000, /* 20 MHz on osc0 */
48 [2] = 12000000, /* 12 MHz on osc1 */
55 static struct eth_addr __initdata hw_addr[2];
56 static struct macb_platform_data __initdata eth_data[2];
58 static int ads7846_get_pendown_state_PB26(void)
60 return !gpio_get_value(GPIO_PIN_PB(26));
63 static int ads7846_get_pendown_state_PB28(void)
65 return !gpio_get_value(GPIO_PIN_PB(28));
68 static struct ads7846_platform_data __initdata ads7846_data = {
70 .vref_delay_usecs = 100,
73 .settle_delay_usecs = 150,
74 .penirq_recheck_delay_usecs = 1,
79 .get_pendown_state = ads7846_get_pendown_state_PB26,
82 .filter_cleanup = NULL,
85 static struct spi_board_info __initdata spi0_board_info[] = {
87 .modalias = "ads7846",
88 .max_speed_hz = 3250000,
91 .platform_data = &ads7846_data,
96 static struct mci_platform_data __initdata mci0_data = {
99 .detect_pin = GPIO_PIN_PE(19),
100 .wp_pin = GPIO_PIN_PE(20),
101 .detect_is_active_high = true,
105 static int __init parse_tag_ethernet(struct tag *tag)
109 i = tag->u.ethernet.mac_index;
110 if (i < ARRAY_SIZE(hw_addr)) {
111 memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
112 sizeof(hw_addr[i].addr));
117 __tagtable(ATAG_ETHERNET, parse_tag_ethernet);
119 static void __init set_hw_addr(struct platform_device *pdev)
121 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
129 if (pdev->id >= ARRAY_SIZE(hw_addr))
132 addr = hw_addr[pdev->id].addr;
133 if (!is_valid_ether_addr(addr))
136 regs = (void __iomem __force *)res->start;
137 pclk = clk_get(&pdev->dev, "pclk");
142 __raw_writel((addr[3] << 24) | (addr[2] << 16)
143 | (addr[1] << 8) | addr[0], regs + 0x98);
144 __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
149 static struct i2c_gpio_platform_data i2c_gpio_data = {
150 .sda_pin = GPIO_PIN_PA(6),
151 .scl_pin = GPIO_PIN_PA(7),
152 .sda_is_open_drain = 1,
153 .scl_is_open_drain = 1,
157 static struct platform_device i2c_gpio_device = {
161 .platform_data = &i2c_gpio_data,
165 static struct i2c_board_info __initdata i2c_info[] = {
167 I2C_BOARD_INFO("pcf8563", 0x51)
171 #if IS_ENABLED(CONFIG_LEDS_PWM)
172 static struct pwm_lookup pwm_lookup[] = {
173 PWM_LOOKUP("at91sam9rl-pwm", 0, "leds_pwm", "backlight",
174 5000, PWM_POLARITY_NORMAL),
177 static struct led_pwm pwm_leds[] = {
180 .max_brightness = 255,
184 static struct led_pwm_platform_data pwm_data = {
185 .num_leds = ARRAY_SIZE(pwm_leds),
189 static struct platform_device leds_pwm = {
193 .platform_data = &pwm_data,
198 const char *merisc_model(void)
200 switch (merisc_board_id) {
211 const char *merisc_revision(void)
213 switch (merisc_board_id) {
225 static void detect_merisc_board_id(void)
227 /* Board ID pins MUST be set as input or the board may be damaged */
228 at32_select_gpio(GPIO_PIN_PA(24), AT32_GPIOF_PULLUP);
229 at32_select_gpio(GPIO_PIN_PA(25), AT32_GPIOF_PULLUP);
230 at32_select_gpio(GPIO_PIN_PA(26), AT32_GPIOF_PULLUP);
231 at32_select_gpio(GPIO_PIN_PA(27), AT32_GPIOF_PULLUP);
233 merisc_board_id = !gpio_get_value(GPIO_PIN_PA(24)) +
234 !gpio_get_value(GPIO_PIN_PA(25)) * 2 +
235 !gpio_get_value(GPIO_PIN_PA(26)) * 4 +
236 !gpio_get_value(GPIO_PIN_PA(27)) * 8;
239 void __init setup_board(void)
241 at32_map_usart(0, 0, 0);
242 at32_map_usart(1, 1, 0);
243 at32_map_usart(3, 3, 0);
244 at32_setup_serial_console(1);
247 static int __init merisc_init(void)
249 detect_merisc_board_id();
251 printk(KERN_NOTICE "BOARD: Merisc %s revision %s\n", merisc_model(),
254 /* Reserve pins for SDRAM */
255 at32_reserve_pin(GPIO_PIOE_BASE, ATMEL_EBI_PE_DATA_ALL | (1 << 26));
257 if (merisc_board_id >= 1)
258 at32_map_usart(2, 2, 0);
260 at32_add_device_usart(0);
261 at32_add_device_usart(1);
262 if (merisc_board_id >= 1)
263 at32_add_device_usart(2);
264 at32_add_device_usart(3);
265 set_hw_addr(at32_add_device_eth(0, ð_data[0]));
268 if (merisc_board_id == 0) {
269 ads7846_data.get_pendown_state = ads7846_get_pendown_state_PB26;
270 at32_select_periph(GPIO_PIOB_BASE, 1 << 26,
271 GPIO_PERIPH_A, AT32_GPIOF_PULLUP);
272 spi0_board_info[0].irq = AT32_EXTINT(1);
274 ads7846_data.get_pendown_state = ads7846_get_pendown_state_PB28;
275 at32_select_periph(GPIO_PIOB_BASE, 1 << 28, GPIO_PERIPH_A,
277 spi0_board_info[0].irq = AT32_EXTINT(3);
280 /* ADS7846 busy pin */
281 at32_select_gpio(GPIO_PIN_PA(4), AT32_GPIOF_PULLUP);
283 at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
285 at32_add_device_mci(0, &mci0_data);
287 #if IS_ENABLED(CONFIG_LEDS_PWM)
288 pwm_add_table(pwm_lookup, ARRAY_SIZE(pwm_lookup));
289 at32_add_device_pwm((1 << 0) | (1 << 2));
290 platform_device_register(&leds_pwm);
292 at32_add_device_pwm((1 << 2));
295 at32_select_gpio(i2c_gpio_data.sda_pin,
296 AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
297 at32_select_gpio(i2c_gpio_data.scl_pin,
298 AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
299 platform_device_register(&i2c_gpio_device);
301 i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
305 postcore_initcall(merisc_init);