[xburst] Cleanup clock module a bit and replace last users of __cpm_*
[openwrt/svn-archive/archive.git] / target / linux / xburst / files-2.6.32 / arch / mips / jz4740 / board-qi_lb60.c
1 /*
2 * linux/arch/mips/jz4740/board-qi_lb60.c
3 *
4 * QI_LB60 setup routines.
5 *
6 * Copyright (c) 2009 Qi Hardware inc.,
7 * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 or later
11 * as published by the Free Software Foundation.
12 */
13
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/gpio.h>
17
18 #include <asm/mach-jz4740/board-qi_lb60.h>
19 #include <asm/mach-jz4740/platform.h>
20
21 #include <linux/input.h>
22 #include <linux/gpio_keys.h>
23 #include <linux/mtd/jz4740_nand.h>
24 #include <linux/jz4740_fb.h>
25 #include <linux/input/matrix_keypad.h>
26 #include <linux/mtd/jz4740_nand.h>
27 #include <linux/spi/spi.h>
28 #include <linux/spi/spi_gpio.h>
29 #include <linux/power_supply.h>
30 #include <linux/power/jz4740-battery.h>
31 #include <linux/mmc/jz4740_mmc.h>
32
33
34 /* NAND */
35 static struct nand_ecclayout qi_lb60_ecclayout_1gb = {
36 .eccbytes = 36,
37 .eccpos = {
38 6, 7, 8, 9, 10, 11, 12, 13,
39 14, 15, 16, 17, 18, 19, 20, 21,
40 22, 23, 24, 25, 26, 27, 28, 29,
41 30, 31, 32, 33, 34, 35, 36, 37,
42 38, 39, 40, 41},
43 .oobfree = {
44 {.offset = 2,
45 .length = 4},
46 {.offset = 42,
47 .length = 22}}
48 };
49
50 static struct mtd_partition qi_lb60_partitions_1gb[] = {
51 { .name = "NAND BOOT partition",
52 .offset = 0 * 0x100000,
53 .size = 4 * 0x100000,
54 },
55 { .name = "NAND KERNEL partition",
56 .offset = 4 * 0x100000,
57 .size = 4 * 0x100000,
58 },
59 { .name = "NAND ROOTFS partition",
60 .offset = 8 * 0x100000,
61 .size = (504 + 512) * 0x100000,
62 },
63 };
64
65 static struct nand_ecclayout qi_lb60_ecclayout_2gb = {
66 .eccbytes = 72,
67 .eccpos = {
68 12, 13, 14, 15, 16, 17, 18, 19,
69 20, 21, 22, 23, 24, 25, 26, 27,
70 28, 29, 30, 31, 32, 33, 34, 35,
71 36, 37, 38, 39, 40, 41, 42, 43,
72 44, 45, 46, 47, 48, 49, 50, 51,
73 52, 53, 54, 55, 56, 57, 58, 59,
74 60, 61, 62, 63, 64, 65, 66, 67,
75 68, 69, 70, 71, 72, 73, 74, 75,
76 76, 77, 78, 79, 80, 81, 82, 83},
77 .oobfree = {
78 {.offset = 2,
79 .length = 10},
80 {.offset = 84,
81 .length = 44}}
82 };
83
84 static struct mtd_partition qi_lb60_partitions_2gb[] = {
85 { .name = "NAND BOOT partition",
86 .offset = 0 * 0x100000,
87 .size = 4 * 0x100000,
88 },
89 { .name = "NAND KERNEL partition",
90 .offset = 4 * 0x100000,
91 .size = 4 * 0x100000,
92 },
93 { .name = "NAND ROOTFS partition",
94 .offset = 8 * 0x100000,
95 .size = (504 + 512 + 1024) * 0x100000,
96 },
97 };
98
99 static void qi_lb60_nand_ident(struct platform_device *pdev,
100 struct nand_chip *chip,
101 struct mtd_partition **partitions,
102 int *num_partitions)
103 {
104 if (chip->page_shift == 12) {
105 chip->ecc.layout = &qi_lb60_ecclayout_2gb;
106 *partitions = qi_lb60_partitions_2gb;
107 *num_partitions = ARRAY_SIZE(qi_lb60_partitions_2gb);
108 } else {
109 chip->ecc.layout = &qi_lb60_ecclayout_1gb;
110 *partitions = qi_lb60_partitions_1gb;
111 *num_partitions = ARRAY_SIZE(qi_lb60_partitions_1gb);
112 }
113 }
114
115 static struct jz_nand_platform_data qi_lb60_nand_pdata = {
116 .ident_callback = qi_lb60_nand_ident,
117 .busy_gpio = 94,
118 };
119
120
121 /* Keyboard*/
122
123 /* #define KEEP_UART_ALIVE
124 * don't define this. the keyboard and keyboard both work
125 */
126
127 #define KEY_QI_QI KEY_F13
128 #define KEY_QI_UPRED KEY_RIGHTALT
129 #define KEY_QI_VOLUP KEY_VOLUMEUP
130 #define KEY_QI_VOLDOWN KEY_VOLUMEDOWN
131 #define KEY_QI_FN KEY_LEFTCTRL
132
133 static const uint32_t qi_lb60_keymap[] = {
134 KEY(0, 0, KEY_F1), /* S2 */
135 KEY(0, 1, KEY_F2), /* S3 */
136 KEY(0, 2, KEY_F3), /* S4 */
137 KEY(0, 3, KEY_F4), /* S5 */
138 KEY(0, 4, KEY_F5), /* S6 */
139 KEY(0, 5, KEY_F6), /* S7 */
140 KEY(0, 6, KEY_F7), /* S8 */
141
142 KEY(1, 0, KEY_Q), /* S10 */
143 KEY(1, 1, KEY_W), /* S11 */
144 KEY(1, 2, KEY_E), /* S12 */
145 KEY(1, 3, KEY_R), /* S13 */
146 KEY(1, 4, KEY_T), /* S14 */
147 KEY(1, 5, KEY_Y), /* S15 */
148 KEY(1, 6, KEY_U), /* S16 */
149 KEY(1, 7, KEY_I), /* S17 */
150 KEY(2, 0, KEY_A), /* S18 */
151 KEY(2, 1, KEY_S), /* S19 */
152 KEY(2, 2, KEY_D), /* S20 */
153 KEY(2, 3, KEY_F), /* S21 */
154 KEY(2, 4, KEY_G), /* S22 */
155 KEY(2, 5, KEY_H), /* S23 */
156 KEY(2, 6, KEY_J), /* S24 */
157 KEY(2, 7, KEY_K), /* S25 */
158 KEY(3, 0, KEY_ESC), /* S26 */
159 KEY(3, 1, KEY_Z), /* S27 */
160 KEY(3, 2, KEY_X), /* S28 */
161 KEY(3, 3, KEY_C), /* S29 */
162 KEY(3, 4, KEY_V), /* S30 */
163 KEY(3, 5, KEY_B), /* S31 */
164 KEY(3, 6, KEY_N), /* S32 */
165 KEY(3, 7, KEY_M), /* S33 */
166 KEY(4, 0, KEY_TAB), /* S34 */
167 KEY(4, 1, KEY_CAPSLOCK), /* S35 */
168 KEY(4, 2, KEY_BACKSLASH), /* S36 */
169 KEY(4, 3, KEY_APOSTROPHE), /* S37 */
170 KEY(4, 4, KEY_COMMA), /* S38 */
171 KEY(4, 5, KEY_DOT), /* S39 */
172 KEY(4, 6, KEY_SLASH), /* S40 */
173 KEY(4, 7, KEY_UP), /* S41 */
174 KEY(5, 0, KEY_O), /* S42 */
175 KEY(5, 1, KEY_L), /* S43 */
176 KEY(5, 2, KEY_EQUAL), /* S44 */
177 KEY(5, 3, KEY_QI_UPRED), /* S45 */
178 KEY(5, 4, KEY_SPACE), /* S46 */
179 KEY(5, 5, KEY_QI_QI), /* S47 */
180 KEY(5, 6, KEY_RIGHTCTRL), /* S48 */
181 KEY(5, 7, KEY_LEFT), /* S49 */
182 KEY(6, 0, KEY_F8), /* S50 */
183 KEY(6, 1, KEY_P), /* S51 */
184 KEY(6, 2, KEY_BACKSPACE),/* S52 */
185 KEY(6, 3, KEY_ENTER), /* S53 */
186 KEY(6, 4, KEY_QI_VOLUP), /* S54 */
187 KEY(6, 5, KEY_QI_VOLDOWN), /* S55 */
188 KEY(6, 6, KEY_DOWN), /* S56 */
189 KEY(6, 7, KEY_RIGHT), /* S57 */
190
191 #ifndef KEEP_UART_ALIVE
192 KEY(7, 0, KEY_LEFTSHIFT), /* S58 */
193 KEY(7, 1, KEY_LEFTALT), /* S59 */
194 KEY(7, 2, KEY_QI_FN), /* S60 */
195 #endif
196 };
197
198 static const struct matrix_keymap_data qi_lb60_keymap_data = {
199 .keymap = qi_lb60_keymap,
200 .keymap_size = ARRAY_SIZE(qi_lb60_keymap),
201 };
202
203 static const unsigned int qi_lb60_keypad_cols[] = {
204 74, 75, 76, 77, 78, 79, 80, 81,
205 };
206
207 static const unsigned int qi_lb60_keypad_rows[] = {
208 114, 115, 116, 117, 118, 119, 120,
209 #ifndef KEEP_UART_ALIVE
210 122,
211 #endif
212 };
213
214 static struct matrix_keypad_platform_data qi_lb60_pdata = {
215 .keymap_data = &qi_lb60_keymap_data,
216 .col_gpios = qi_lb60_keypad_cols,
217 .row_gpios = qi_lb60_keypad_rows,
218 .num_col_gpios = ARRAY_SIZE(qi_lb60_keypad_cols),
219 .num_row_gpios = ARRAY_SIZE(qi_lb60_keypad_rows),
220 .col_scan_delay_us = 10,
221 .debounce_ms = 10,
222 .wakeup = 1,
223 .active_low = 1,
224 };
225
226 static struct platform_device qi_lb60_keypad = {
227 .name = "matrix-keypad",
228 .id = -1,
229 .dev = {
230 .platform_data = &qi_lb60_pdata,
231 },
232 };
233
234 /* Display */
235 static struct fb_videomode qi_lb60_video_modes[] = {
236 {
237 .name = "320x240",
238 .xres = 320,
239 .yres = 240,
240 .pixclock = 700000,
241 .left_margin = 140,
242 .right_margin = 273,
243 .upper_margin = 20,
244 .lower_margin = 2,
245 .hsync_len = 1,
246 .vsync_len = 1,
247 .sync = 0,
248 .vmode = FB_VMODE_NONINTERLACED,
249 },
250 };
251
252 static struct jz4740_fb_platform_data qi_lb60_fb_pdata = {
253 .width = 60,
254 .height = 45,
255 .num_modes = ARRAY_SIZE(qi_lb60_video_modes),
256 .modes = qi_lb60_video_modes,
257 .bpp = 24,
258 .lcd_type = JZ_LCD_TYPE_8BIT_SERIAL,
259 };
260
261
262 struct spi_gpio_platform_data spigpio_platform_data = {
263 .sck = JZ_GPIO_PORTC(23),
264 .mosi = JZ_GPIO_PORTC(22),
265 .miso = JZ_GPIO_PORTC(22),
266 .num_chipselect = 1,
267 };
268
269 static struct platform_device spigpio_device = {
270 .name = "spi_gpio",
271 .id = 1,
272 .dev = {
273 .platform_data = &spigpio_platform_data,
274 },
275 };
276
277 static struct spi_board_info qi_lb60_spi_board_info[] = {
278 {
279 .modalias = "gpm940b0",
280 .controller_data = (void*)JZ_GPIO_PORTC(21),
281 .chip_select = 0,
282 .bus_num = 1,
283 .max_speed_hz = 30 * 1000,
284 },
285 };
286
287 /* Battery */
288 static struct jz_batt_info qi_lb60_battery_pdata = {
289 .dc_dect_gpio = GPIO_DC_DETE_N,
290 .usb_dect_gpio = GPIO_USB_DETE,
291 .charg_stat_gpio = GPIO_CHARG_STAT_N,
292
293 .min_voltag = 3600000,
294 .max_voltag = 4200000,
295 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
296 };
297
298 /* GPIO Key: power */
299 static struct gpio_keys_button qi_lb60_gpio_keys_buttons[] = {
300 [0] = {
301 .code = KEY_POWER,
302 .gpio = GPIO_WAKEUP_N,
303 .active_low = 1,
304 .desc = "Power",
305 .wakeup = 1,
306 },
307 };
308
309 static struct gpio_keys_platform_data qi_lb60_gpio_keys_data = {
310 .nbuttons = ARRAY_SIZE(qi_lb60_gpio_keys_buttons),
311 .buttons = qi_lb60_gpio_keys_buttons,
312 };
313
314 static struct platform_device qi_lb60_gpio_keys = {
315 .name = "gpio-keys",
316 .id = -1,
317 .dev = {
318 .platform_data = &qi_lb60_gpio_keys_data,
319 }
320 };
321
322 static struct jz4740_mmc_platform_data qi_lb60_mmc_pdata = {
323 .gpio_card_detect = JZ_GPIO_PORTD(0),
324 .gpio_read_only = -1,
325 .gpio_power = JZ_GPIO_PORTD(2),
326 .power_active_low = 1,
327 };
328
329 static struct platform_device *jz_platform_devices[] __initdata = {
330 &jz4740_usb_ohci_device,
331 &jz4740_usb_gdt_device,
332 &jz4740_mmc_device,
333 &jz4740_nand_device,
334 &qi_lb60_keypad,
335 &spigpio_device,
336 &jz4740_framebuffer_device,
337 &jz4740_i2s_device,
338 &jz4740_codec_device,
339 &jz4740_rtc_device,
340 &jz4740_adc_device,
341 &jz4740_battery_device,
342 &qi_lb60_gpio_keys,
343 };
344
345 static void __init board_gpio_setup(void)
346 {
347 /* We only need to enable/disable pullup here for pins used in generic
348 * drivers. Everything else is done by the drivers themselfs. */
349 jz_gpio_disable_pullup(GPIO_SD_VCC_EN_N);
350 jz_gpio_disable_pullup(GPIO_SD_CD_N);
351 }
352
353 static int __init qi_lb60_init_platform_devices(void)
354 {
355 jz4740_framebuffer_device.dev.platform_data = &qi_lb60_fb_pdata;
356 jz4740_nand_device.dev.platform_data = &qi_lb60_nand_pdata;
357 jz4740_battery_device.dev.platform_data = &qi_lb60_battery_pdata;
358 jz4740_mmc_device.dev.platform_data = &qi_lb60_mmc_pdata;
359
360 spi_register_board_info(qi_lb60_spi_board_info,
361 ARRAY_SIZE(qi_lb60_spi_board_info));
362
363 return platform_add_devices(jz_platform_devices,
364 ARRAY_SIZE(jz_platform_devices));
365
366 }
367 extern int jz_gpiolib_init(void);
368 extern int jz_init_clocks(unsigned long extal);
369
370 static __init int board_avt2(char *str)
371 {
372 qi_lb60_mmc_pdata.card_detect_active_low = 1;
373
374 return 1;
375 }
376
377 __setup("avt2", board_avt2);
378
379 static int __init qi_lb60_board_setup(void)
380 {
381 printk("Qi Hardware JZ4740 QI_LB60 setup\n");
382 if (jz_gpiolib_init())
383 panic("Failed to initalize jz gpio\n");
384 jz_init_clocks(12000000);
385
386 board_gpio_setup();
387
388 if (qi_lb60_init_platform_devices())
389 panic("Failed to initalize platform devices\n");
390
391 return 0;
392 }
393
394 arch_initcall(qi_lb60_board_setup);