1
2
3
4
5
6
7
8
9
10
11
12#include <linux/gpio.h>
13#include <linux/init.h>
14#include <linux/irq.h>
15#include <linux/linkage.h>
16#include <linux/platform_device.h>
17#include <linux/types.h>
18#include <linux/fb.h>
19#include <linux/leds.h>
20#include <linux/pwm.h>
21#include <linux/leds_pwm.h>
22#include <linux/input.h>
23#include <linux/gpio_keys.h>
24#include <linux/spi/spi.h>
25#include <linux/spi/ads7846.h>
26
27#include <video/atmel_lcdc.h>
28#include <sound/atmel-ac97c.h>
29
30#include <asm/delay.h>
31#include <asm/io.h>
32#include <asm/setup.h>
33
34#include <mach/at32ap700x.h>
35#include <mach/board.h>
36#include <mach/init.h>
37#include <mach/portmux.h>
38
39
40#define PIN_LCD_BL GPIO_PIN_PA(28)
41#define PWM_CH_BL 0
42#define PIN_LCD_DISP GPIO_PIN_PA(31)
43#define PIN_AC97_RST_N GPIO_PIN_PA(30)
44#define PB_EXTINT_BASE 25
45#define TS_IRQ 0
46#define PIN_TS_EXTINT GPIO_PIN_PB(PB_EXTINT_BASE+TS_IRQ)
47#define PIN_PB_LEFT GPIO_PIN_PB(11)
48#define PIN_PB_RIGHT GPIO_PIN_PB(12)
49#define PIN_PWR_SW_N GPIO_PIN_PB(14)
50#define PIN_PWR_ON GPIO_PIN_PB(13)
51#define PIN_ZB_RST_N GPIO_PIN_PA(21)
52#define PIN_BT_RST GPIO_PIN_PA(22)
53#define PIN_LED_SYS GPIO_PIN_PA(16)
54#define PIN_LED_A GPIO_PIN_PA(19)
55#define PIN_LED_B GPIO_PIN_PE(19)
56
57#ifdef CONFIG_BOARD_MRMT_LCD_LQ043T3DX0X
58
59static struct fb_videomode __initdata lcd_fb_modes[] = {
60 {
61 .name = "480x272 @ 59.94Hz",
62 .refresh = 59.94,
63 .xres = 480, .yres = 272,
64 .pixclock = KHZ2PICOS(9000),
65
66 .left_margin = 2, .right_margin = 2,
67 .upper_margin = 3, .lower_margin = 9,
68 .hsync_len = 41, .vsync_len = 1,
69
70 .sync = 0,
71 .vmode = FB_VMODE_NONINTERLACED,
72 },
73};
74
75static struct fb_monspecs __initdata lcd_fb_default_monspecs = {
76 .manufacturer = "SHA",
77 .monitor = "LQ043T3DX02",
78 .modedb = lcd_fb_modes,
79 .modedb_len = ARRAY_SIZE(lcd_fb_modes),
80 .hfmin = 14915,
81 .hfmax = 17638,
82 .vfmin = 53,
83 .vfmax = 61,
84 .dclkmax = 9260000,
85};
86
87static struct atmel_lcdfb_pdata __initdata rmt_lcdc_data = {
88 .default_bpp = 24,
89 .default_dmacon = ATMEL_LCDC_DMAEN | ATMEL_LCDC_DMA2DEN,
90 .default_lcdcon2 = (ATMEL_LCDC_DISTYPE_TFT
91 | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE
92 | ATMEL_LCDC_INVCLK_NORMAL
93 | ATMEL_LCDC_MEMOR_BIG),
94 .lcd_wiring_mode = ATMEL_LCDC_WIRING_RGB,
95 .default_monspecs = &lcd_fb_default_monspecs,
96 .guard_time = 2,
97};
98#endif
99
100#ifdef CONFIG_BOARD_MRMT_LCD_KWH043GM08
101
102static struct fb_videomode __initdata lcd_fb_modes[] = {
103 {
104 .name = "480x272 @ 59.94Hz",
105 .refresh = 59.94,
106 .xres = 480, .yres = 272,
107 .pixclock = KHZ2PICOS(9000),
108
109 .left_margin = 2, .right_margin = 2,
110 .upper_margin = 3, .lower_margin = 9,
111 .hsync_len = 41, .vsync_len = 1,
112
113 .sync = 0,
114 .vmode = FB_VMODE_NONINTERLACED,
115 },
116};
117
118static struct fb_monspecs __initdata lcd_fb_default_monspecs = {
119 .manufacturer = "FOR",
120 .monitor = "KWH043GM08",
121 .modedb = lcd_fb_modes,
122 .modedb_len = ARRAY_SIZE(lcd_fb_modes),
123 .hfmin = 14915,
124 .hfmax = 17638,
125 .vfmin = 53,
126 .vfmax = 61,
127 .dclkmax = 9260000,
128};
129
130static struct atmel_lcdfb_pdata __initdata rmt_lcdc_data = {
131 .default_bpp = 24,
132 .default_dmacon = ATMEL_LCDC_DMAEN | ATMEL_LCDC_DMA2DEN,
133 .default_lcdcon2 = (ATMEL_LCDC_DISTYPE_TFT
134 | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE
135 | ATMEL_LCDC_INVCLK_INVERTED
136 | ATMEL_LCDC_MEMOR_BIG),
137 .lcd_wiring_mode = ATMEL_LCDC_WIRING_RGB,
138 .default_monspecs = &lcd_fb_default_monspecs,
139 .guard_time = 2,
140};
141#endif
142
143#ifdef CONFIG_BOARD_MRMT_AC97
144static struct ac97c_platform_data __initdata ac97c0_data = {
145 .reset_pin = PIN_AC97_RST_N,
146};
147#endif
148
149#ifdef CONFIG_BOARD_MRMT_UCB1400_TS
150
151static struct platform_device rmt_ts_device = {
152 .name = "ucb1400_ts",
153 .id = -1,
154};
155#endif
156
157#ifdef CONFIG_BOARD_MRMT_BL_PWM
158
159static struct pwm_lookup pwm_lookup[] = {
160 PWM_LOOKUP("at91sam9rl-pwm", PWM_CH_BL, "leds_pwm", "ds1",
161 5000, PWM_POLARITY_INVERSED),
162};
163
164static struct led_pwm pwm_leds[] = {
165 {
166 .name = "backlight",
167 .max_brightness = 255,
168 },
169};
170
171static struct led_pwm_platform_data pwm_data = {
172 .num_leds = ARRAY_SIZE(pwm_leds),
173 .leds = pwm_leds,
174};
175
176static struct platform_device leds_pwm = {
177 .name = "leds_pwm",
178 .id = -1,
179 .dev = {
180 .platform_data = &pwm_data,
181 },
182};
183#endif
184
185#ifdef CONFIG_BOARD_MRMT_ADS7846_TS
186static int ads7846_pendown_state(void)
187{
188 return !gpio_get_value( PIN_TS_EXTINT );
189}
190
191static struct ads7846_platform_data ads_info = {
192 .model = 7846,
193 .keep_vref_on = 0,
194 .vref_delay_usecs = 0,
195 .vref_mv = 3300,
196 .settle_delay_usecs = 800,
197 .penirq_recheck_delay_usecs = 800,
198 .x_plate_ohms = 750,
199 .y_plate_ohms = 300,
200 .pressure_max = 4096,
201 .debounce_max = 1,
202 .debounce_rep = 0,
203 .debounce_tol = (~0),
204 .get_pendown_state = ads7846_pendown_state,
205 .filter = NULL,
206 .filter_init = NULL,
207};
208
209static struct spi_board_info spi01_board_info[] __initdata = {
210 {
211 .modalias = "ads7846",
212 .max_speed_hz = 31250*26,
213 .bus_num = 0,
214 .chip_select = 1,
215 .platform_data = &ads_info,
216 .irq = AT32_EXTINT(TS_IRQ),
217 },
218};
219#endif
220
221
222static const struct gpio_keys_button rmt_gpio_keys_buttons[] = {
223 [0] = {
224 .type = EV_KEY,
225 .code = KEY_POWER,
226 .gpio = PIN_PWR_SW_N,
227 .active_low = 1,
228 .desc = "power button",
229 },
230 [1] = {
231 .type = EV_KEY,
232 .code = KEY_LEFT,
233 .gpio = PIN_PB_LEFT,
234 .active_low = 1,
235 .desc = "left button",
236 },
237 [2] = {
238 .type = EV_KEY,
239 .code = KEY_RIGHT,
240 .gpio = PIN_PB_RIGHT,
241 .active_low = 1,
242 .desc = "right button",
243 },
244};
245
246static const struct gpio_keys_platform_data rmt_gpio_keys_data = {
247 .nbuttons = ARRAY_SIZE(rmt_gpio_keys_buttons),
248 .buttons = (void *) rmt_gpio_keys_buttons,
249};
250
251static struct platform_device rmt_gpio_keys = {
252 .name = "gpio-keys",
253 .id = -1,
254 .dev = {
255 .platform_data = (void *) &rmt_gpio_keys_data,
256 }
257};
258
259#ifdef CONFIG_BOARD_MRMT_RTC_I2C
260static struct i2c_board_info __initdata mrmt1_i2c_rtc = {
261 I2C_BOARD_INFO("s35390a", 0x30),
262 .irq = 0,
263};
264#endif
265
266static void mrmt_power_off(void)
267{
268
269 gpio_set_value( PIN_PWR_ON, 0 );
270}
271
272static int __init mrmt1_init(void)
273{
274 gpio_set_value( PIN_PWR_ON, 1 );
275
276 pm_power_off = mrmt_power_off;
277
278
279 at32_map_usart(2, 1, 0);
280 at32_map_usart(3, 2, ATMEL_USART_RTS | ATMEL_USART_CTS);
281
282 at32_add_device_usart(1);
283 at32_add_device_usart(2);
284
285
286 at32_select_gpio( PIN_PWR_SW_N, AT32_GPIOF_DEGLITCH);
287 at32_select_gpio( PIN_PB_LEFT, AT32_GPIOF_DEGLITCH);
288 at32_select_gpio( PIN_PB_RIGHT, AT32_GPIOF_DEGLITCH);
289 platform_device_register(&rmt_gpio_keys);
290
291#ifdef CONFIG_BOARD_MRMT_RTC_I2C
292 i2c_register_board_info(0, &mrmt1_i2c_rtc, 1);
293#endif
294
295#ifndef CONFIG_BOARD_MRMT_LCD_DISABLE
296
297
298 at32_add_device_lcdc(0, &rmt_lcdc_data,
299 fbmem_start, fbmem_size,
300 (ATMEL_LCDC_ALT_24BIT | ATMEL_LCDC_PE_DVAL ) );
301#endif
302
303#ifdef CONFIG_BOARD_MRMT_AC97
304 at32_add_device_ac97c(0, &ac97c0_data, AC97C_BOTH);
305#endif
306
307#ifdef CONFIG_BOARD_MRMT_ADS7846_TS
308
309 at32_select_periph( GPIO_PIOB_BASE, 1 << (PB_EXTINT_BASE+TS_IRQ),
310 GPIO_PERIPH_A, AT32_GPIOF_DEGLITCH);
311 irq_set_irq_type(AT32_EXTINT(TS_IRQ), IRQ_TYPE_EDGE_FALLING);
312 at32_spi_setup_slaves(0,spi01_board_info,ARRAY_SIZE(spi01_board_info));
313 spi_register_board_info(spi01_board_info,ARRAY_SIZE(spi01_board_info));
314#endif
315
316#ifdef CONFIG_BOARD_MRMT_UCB1400_TS
317
318 at32_select_periph( GPIO_PIOB_BASE, 1 << (PB_EXTINT_BASE+TS_IRQ),
319 GPIO_PERIPH_A, AT32_GPIOF_DEGLITCH);
320 platform_device_register(&rmt_ts_device);
321#endif
322
323 at32_select_gpio( PIN_LCD_DISP, AT32_GPIOF_OUTPUT );
324 gpio_request( PIN_LCD_DISP, "LCD_DISP" );
325 gpio_direction_output( PIN_LCD_DISP, 0 );
326#ifdef CONFIG_BOARD_MRMT_LCD_DISABLE
327
328 at32_select_gpio( PIN_LCD_BL, AT32_GPIOF_OUTPUT );
329 gpio_request( PIN_LCD_BL, "LCD_BL" );
330 gpio_direction_output( PIN_LCD_BL, 0 );
331#else
332 gpio_set_value( PIN_LCD_DISP, 1 );
333#ifdef CONFIG_BOARD_MRMT_BL_PWM
334
335 at32_add_device_pwm(1 << PWM_CH_BL);
336 pwm_add_table(pwm_lookup, ARRAY_SIZE(pwm_lookup));
337 platform_device_register(&leds_pwm);
338#else
339
340 udelay( 1 );
341 at32_select_gpio( PIN_LCD_BL, AT32_GPIOF_OUTPUT );
342 gpio_request( PIN_LCD_BL, "LCD_BL" );
343 gpio_direction_output( PIN_LCD_BL, 1 );
344#endif
345#endif
346
347
348 at32_select_gpio( PIN_BT_RST, AT32_GPIOF_OUTPUT );
349 gpio_request( PIN_BT_RST, "BT_RST" );
350 gpio_direction_output( PIN_BT_RST, 1 );
351
352
353 at32_select_gpio( PIN_ZB_RST_N, AT32_GPIOF_OUTPUT );
354 gpio_request( PIN_ZB_RST_N, "ZB_RST_N" );
355 gpio_direction_output( PIN_ZB_RST_N, 0 );
356
357
358#ifdef CONFIG_BOARD_MRMT_WIRELESS_ZB
359 udelay( 1000 );
360
361 gpio_set_value( PIN_ZB_RST_N, 1 );
362#endif
363#ifdef CONFIG_BOARD_MRMT_WIRELESS_BT
364 udelay( 1000 );
365
366 gpio_set_value( PIN_BT_RST, 0 );
367#endif
368
369 return 0;
370}
371arch_initcall(mrmt1_init);
372
373static int __init mrmt1_early_init(void)
374{
375
376 at32_select_gpio( PIN_PWR_ON, AT32_GPIOF_OUTPUT );
377 gpio_request( PIN_PWR_ON, "PIN_PWR_ON" );
378 gpio_direction_output( PIN_PWR_ON, 1 );
379
380 return 0;
381}
382core_initcall(mrmt1_early_init);
383