of: MSI: Simplify irqdomain lookup
[linux/fpc-iii.git] / arch / avr32 / boards / merisc / setup.c
blob83d896cc2aed7f4ae1f04f2563aa09329c03affa
1 /*
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.
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 <linux/pwm.h>
26 #include <linux/leds_pwm.h>
28 #include <asm/io.h>
29 #include <asm/setup.h>
30 #include <asm/gpio.h>
32 #include <mach/at32ap700x.h>
33 #include <mach/board.h>
34 #include <mach/init.h>
35 #include <mach/portmux.h>
37 #include "merisc.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 */
52 struct eth_addr {
53 u8 addr[6];
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 = {
70 .model = 7846,
71 .vref_delay_usecs = 100,
72 .vref_mv = 0,
73 .keep_vref_on = 0,
74 .settle_delay_usecs = 150,
75 .penirq_recheck_delay_usecs = 1,
76 .x_plate_ohms = 800,
77 .debounce_rep = 4,
78 .debounce_max = 10,
79 .debounce_tol = 50,
80 .get_pendown_state = ads7846_get_pendown_state_PB26,
81 .filter_init = NULL,
82 .filter = NULL,
83 .filter_cleanup = NULL,
86 static struct spi_board_info __initdata spi0_board_info[] = {
88 .modalias = "ads7846",
89 .max_speed_hz = 3250000,
90 .chip_select = 0,
91 .bus_num = 0,
92 .platform_data = &ads7846_data,
93 .mode = SPI_MODE_0,
97 static struct mci_platform_data __initdata mci0_data = {
98 .slot[0] = {
99 .bus_width = 4,
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)
108 int i;
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));
116 return 0;
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);
123 const u8 *addr;
124 void __iomem *regs;
125 struct clk *pclk;
127 if (!res)
128 return;
130 if (pdev->id >= ARRAY_SIZE(hw_addr))
131 return;
133 addr = hw_addr[pdev->id].addr;
134 if (!is_valid_ether_addr(addr))
135 return;
137 regs = (void __iomem __force *)res->start;
138 pclk = clk_get(&pdev->dev, "pclk");
139 if (IS_ERR(pclk))
140 return;
142 clk_enable(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);
146 clk_disable(pclk);
147 clk_put(pclk);
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,
155 .udelay = 2,
158 static struct platform_device i2c_gpio_device = {
159 .name = "i2c-gpio",
160 .id = 0,
161 .dev = {
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[] = {
180 .name = "backlight",
181 .max_brightness = 255,
185 static struct led_pwm_platform_data pwm_data = {
186 .num_leds = ARRAY_SIZE(pwm_leds),
187 .leds = pwm_leds,
190 static struct platform_device leds_pwm = {
191 .name = "leds_pwm",
192 .id = -1,
193 .dev = {
194 .platform_data = &pwm_data,
197 #endif
199 const char *merisc_model(void)
201 switch (merisc_board_id) {
202 case 0:
203 case 1:
204 return "500-01";
205 case 2:
206 return "BT";
207 default:
208 return "Unknown";
212 const char *merisc_revision(void)
214 switch (merisc_board_id) {
215 case 0:
216 return "B";
217 case 1:
218 return "D";
219 case 2:
220 return "A";
221 default:
222 return "Unknown";
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(),
253 merisc_revision());
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, &eth_data[0]));
268 /* ADS7846 PENIRQ */
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);
274 } else {
275 ads7846_data.get_pendown_state = ads7846_get_pendown_state_PB28;
276 at32_select_periph(GPIO_PIOB_BASE, 1 << 28, GPIO_PERIPH_A,
277 AT32_GPIOF_PULLUP);
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);
292 #else
293 at32_add_device_pwm((1 << 2));
294 #endif
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));
304 return 0;
306 postcore_initcall(merisc_init);