Date:2011-03-16 03:38:46 (9 years 2 months ago)
Author:Maarten ter Huurne
Commit:0c210f293f724bdcc9e89d881b0530c3a72bb4fc
Message:MIPS: A320: Add Dingoo A320 board support

This is a squashed version of the development done in the jz-3.5 branch.
Files: arch/mips/jz4740/Kconfig (1 diff)
arch/mips/jz4740/Makefile (1 diff)
arch/mips/jz4740/board-a320.c (1 diff)

Change Details

arch/mips/jz4740/Kconfig
66config JZ4740_QI_LB60
77    bool "Qi Hardware Ben NanoNote"
88
9config JZ4740_A320
10    bool "Dingoo A320 game and media player"
11
912endchoice
arch/mips/jz4740/Makefile
1212# board specific support
1313
1414obj-$(CONFIG_JZ4740_QI_LB60) += board-qi_lb60.o
15obj-$(CONFIG_JZ4740_A320) += board-a320.o
1516
1617# PM support
1718
arch/mips/jz4740/board-a320.c
1/*
2 * linux/arch/mips/jz4740/board-a320.c
3 *
4 * JZ4740 A320 board setup routines.
5 *
6 * Copyright (c) 2006-2007 Ingenic Semiconductor Inc.
7 * Copyright (c) 2009 Ignacio Garcia Perez <iggarpe@gmail.com>
8 * Copyright (c) 2010-2011 Maarten ter Huurne <maarten@treewalker.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/init.h>
16#include <linux/sched.h>
17#include <linux/ioport.h>
18#include <linux/mm.h>
19#include <linux/console.h>
20#include <linux/delay.h>
21#include <linux/kernel.h>
22#include <linux/gpio.h>
23#include <linux/i2c.h>
24#include <linux/i2c-gpio.h>
25#include <linux/power_supply.h>
26#include <linux/power/gpio-charger.h>
27#include <linux/power/jz4740-battery.h>
28
29#include <linux/pwm.h>
30#include <linux/pwm_backlight.h>
31#include <linux/input.h>
32#include <linux/gpio_keys.h>
33
34#include <media/radio-rda5807.h>
35
36#include <asm/cpu.h>
37#include <asm/bootinfo.h>
38#include <asm/mipsregs.h>
39#include <asm/reboot.h>
40
41#include <asm/mach-jz4740/gpio.h>
42#include <asm/mach-jz4740/jz4740_fb.h>
43#include <asm/mach-jz4740/jz4740_mmc.h>
44#include <asm/mach-jz4740/jz4740_nand.h>
45#include <asm/mach-jz4740/platform.h>
46
47#include "clock.h"
48
49/*
50 * This is called by the panic reboot delay loop if panic=<n> parameter
51 * is passed to the kernel. The A320 does not have any LEDs, so the best
52 * we can do is to blink the LCD backlight.
53 *
54 * TODO(MtH): This should use the backlight driver instead of directly
55 * manipulating the GPIO pin.
56 */
57static long a320_panic_blink_callback(int time)
58{
59    gpio_direction_output(JZ_GPIO_PORTD(31), (time / 500) & 1);
60    return 0;
61}
62
63#ifdef CONFIG_I2C_GPIO
64/* I2C over GPIO pins */
65static struct i2c_gpio_platform_data a320_i2c_pdata = {
66    .sda_pin = JZ_GPIO_PORTD(23),
67    .scl_pin = JZ_GPIO_PORTD(24),
68    .udelay = 2,
69    .timeout = 3 * HZ,
70};
71
72static struct platform_device a320_i2c_device = {
73    .name = "i2c-gpio",
74    .id = 0,
75    .dev = {
76        .platform_data = &a320_i2c_pdata,
77    },
78};
79#endif
80
81/* NAND */
82#define A320_NAND_PAGE_SIZE (4096ull)
83#define A320_NAND_ERASE_BLOCK_SIZE (128 * A320_NAND_PAGE_SIZE)
84
85static struct mtd_partition a320_nand_partitions[] = {
86    { .name = "SPL",
87      .offset = 0 * A320_NAND_ERASE_BLOCK_SIZE,
88      .size = 64 * A320_NAND_PAGE_SIZE,
89    },
90    { .name = "uC/OS-II loader",
91      .offset = 64 * A320_NAND_PAGE_SIZE,
92      .size = 192 * A320_NAND_PAGE_SIZE,
93    },
94    /* erase block 3 is empty (maybe alternative location for bbt?) */
95    /* erase block 4 contains the bad block table */
96    { .name = "uC/OS-II Z:",
97      .offset = 5 * A320_NAND_ERASE_BLOCK_SIZE,
98      .size = 127 * A320_NAND_ERASE_BLOCK_SIZE,
99    },
100    { .name = "uC/OS-II A:",
101      .offset = 132 * A320_NAND_ERASE_BLOCK_SIZE,
102      .size = (8192 - 132) * A320_NAND_ERASE_BLOCK_SIZE,
103    },
104};
105
106static uint8_t a320_nand_bbt_pattern[] = {'b', 'b', 't', '8' };
107
108static struct nand_bbt_descr a320_nand_bbt_main_descr = {
109    .options = NAND_BBT_ABSPAGE | NAND_BBT_8BIT,
110    /* TODO(MtH): Maybe useful flags for the future:
111    NAND_BBT_CREATE | NAND_BBT_WRITE | NAND_BBT_VERSION | NAND_BBT_PERCHIP
112    */
113    .pages = { 4 * A320_NAND_ERASE_BLOCK_SIZE / A320_NAND_PAGE_SIZE },
114    .maxblocks = 1,
115    .pattern = a320_nand_bbt_pattern,
116    .len = ARRAY_SIZE(a320_nand_bbt_pattern),
117    .offs = 128 - ARRAY_SIZE(a320_nand_bbt_pattern),
118};
119
120static struct nand_ecclayout a320_nand_ecc_layout = {
121    .eccbytes = 72,
122    .eccpos = {
123         4, 5, 6, 7, 8, 9, 10, 11, 12, /* sector 0 */
124        16, 17, 18, 19, 20, 21, 22, 23, 24, /* sector 1 */
125        28, 29, 30, 31, 32, 33, 34, 35, 36, /* sector 2 */
126        40, 41, 42, 43, 44, 45, 46, 47, 48, /* sector 3 */
127        52, 53, 54, 55, 56, 57, 58, 59, 60, /* sector 4 */
128        64, 65, 66, 67, 68, 69, 70, 71, 72, /* sector 5 */
129        76, 77, 78, 79, 80, 81, 82, 83, 84, /* sector 6 */
130        88, 89, 90, 91, 92, 93, 94, 95, 96, /* sector 7 */
131    },
132    .oobfree = {
133        { .offset = 100, .length = 22 },
134    }
135};
136
137static void a320_nand_ident(struct platform_device *pdev,
138                struct nand_chip *chip,
139                struct mtd_partition **partitions,
140                int *num_partitions)
141{
142    chip->bbt_options |= NAND_BBT_USE_FLASH;
143    chip->bbt_td = &a320_nand_bbt_main_descr;
144    /* MtH: I did not find a mirror bbt yet, but it might exist. */
145    chip->bbt_md = NULL;
146}
147
148static struct jz_nand_platform_data a320_nand_pdata = {
149    .num_partitions = ARRAY_SIZE(a320_nand_partitions),
150    .partitions = a320_nand_partitions,
151    .ecc_layout = &a320_nand_ecc_layout,
152    .banks = { 1, 2, 3, 4 },
153    .ident_callback = a320_nand_ident,
154};
155
156static struct gpiod_lookup_table a320_nand_gpio_table = {
157    .dev_id = "jz4740-nand.0",
158    .table = {
159        GPIO_LOOKUP("Bank C", 30, "busy", 0),
160        { },
161    },
162};
163
164/* Display */
165static struct fb_videomode a320_video_modes[] = {
166    {
167        .name = "320x240",
168        .xres = 320,
169        .yres = 240,
170        // TODO(MtH): Set refresh or pixclock.
171        .vmode = FB_VMODE_NONINTERLACED,
172    },
173};
174
175static struct jz4740_fb_platform_data a320_fb_pdata = {
176    .width = 60,
177    .height = 45,
178    .num_modes = ARRAY_SIZE(a320_video_modes),
179    .modes = a320_video_modes,
180    .bpp = 16,
181    .lcd_type = JZ_LCD_TYPE_SMART_PARALLEL_16_BIT,
182    .pixclk_falling_edge = 0,
183    .chip_select_active_low = 1,
184    .register_select_active_low = 1,
185};
186
187static int a320_backlight_notify(struct device *dev, int brightness)
188{
189    if (!gpio_get_value(JZ_GPIO_PORTB(18))) {
190        /* RESET_N pin of the ILI chip is pulled down,
191           so force backlight off. */
192        return 0;
193    }
194
195    return brightness;
196}
197
198static struct platform_pwm_backlight_data a320_backlight_pdata = {
199    .max_brightness = 255,
200    .dft_brightness = 145,
201    .pwm_period_ns = 1000000,
202    .notify = a320_backlight_notify,
203};
204
205static struct platform_device a320_backlight_device = {
206    .name = "pwm-backlight",
207    .id = -1,
208    .dev = {
209        .platform_data = &a320_backlight_pdata,
210    },
211};
212
213struct pwm_lookup a320_pwm_table[] = {
214    PWM_LOOKUP("jz4740-pwm", 7, "pwm-backlight", 0),
215};
216
217static struct jz4740_mmc_platform_data a320_mmc_pdata = {
218    .gpio_card_detect = JZ_GPIO_PORTB(29),
219    .gpio_read_only = -1,
220    .gpio_power = -1,
221    // TODO(MtH): I don't know which GPIO pin the SD power is connected to.
222    // Booboo left power alone, but I don't know why.
223    //.gpio_power = GPIO_SD_VCC_EN_N,
224    //.power_active_low = 1,
225};
226
227/* Battery */
228static struct jz_battery_platform_data a320_battery_pdata = {
229    // TODO(MtH): Sometimes while charging, the GPIO pin quickly flips between
230    // 0 and 1. This causes a very high CPU load because the kernel
231    // will invoke a hotplug event handler process on every status
232    // change. Until it is clear how to avoid or handle that, it
233    // is better not to use the charge status.
234    //.gpio_charge = JZ_GPIO_PORTB(30),
235    .gpio_charge = -1,
236    .gpio_charge_active_low = 1,
237    .info = {
238        .name = "battery",
239        .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
240        .voltage_max_design = 4150000,
241        .voltage_min_design = 3450000,
242    },
243};
244
245static char *a320_batteries[] = {
246    "battery",
247};
248
249static struct gpio_charger_platform_data a320_charger_pdata = {
250    .name = "usb",
251    .type = POWER_SUPPLY_TYPE_USB,
252    .gpio = JZ_GPIO_PORTD(28),
253    .gpio_active_low = 0,
254    .supplied_to = a320_batteries,
255    .num_supplicants = ARRAY_SIZE(a320_batteries),
256};
257
258static struct platform_device a320_charger_device = {
259    .name = "gpio-charger",
260    .dev = {
261        .platform_data = &a320_charger_pdata,
262    },
263};
264
265/* Note that the microswitch buttons need debounce while the rubber buttons
266 * do not need it.
267 */
268static struct gpio_keys_button a320_buttons[] = {
269    /* D-pad up */ {
270        .gpio = JZ_GPIO_PORTD(6),
271        .active_low = 1,
272        .code = KEY_UP,
273    },
274    /* D-pad down */ {
275        .gpio = JZ_GPIO_PORTD(27),
276        .active_low = 1,
277        .code = KEY_DOWN,
278    },
279    /* D-pad left */ {
280        .gpio = JZ_GPIO_PORTD(5),
281        .active_low = 1,
282        .code = KEY_LEFT,
283    },
284    /* D-pad right */ {
285        .gpio = JZ_GPIO_PORTD(18),
286        .active_low = 1,
287        .code = KEY_RIGHT,
288    },
289    /* A button */ {
290        .gpio = JZ_GPIO_PORTD(0),
291        .active_low = 1,
292        .code = KEY_LEFTCTRL,
293    },
294    /* B button */ {
295        .gpio = JZ_GPIO_PORTD(1),
296        .active_low = 1,
297        .code = KEY_LEFTALT,
298    },
299    /* X button */ {
300        .gpio = JZ_GPIO_PORTD(19),
301        .active_low = 1,
302        .code = KEY_SPACE,
303    },
304    /* Y button */ {
305        .gpio = JZ_GPIO_PORTD(2),
306        .active_low = 1,
307        .code = KEY_LEFTSHIFT,
308    },
309    /* Left shoulder button */ {
310        .gpio = JZ_GPIO_PORTD(14),
311        .active_low = 1,
312        .code = KEY_TAB,
313        .debounce_interval = 5,
314    },
315    /* Right shoulder button */ {
316        .gpio = JZ_GPIO_PORTD(15),
317        .active_low = 1,
318        .code = KEY_BACKSPACE,
319        .debounce_interval = 5,
320    },
321    /* START button */ {
322        .gpio = JZ_GPIO_PORTC(17),
323        .active_low = 1,
324        .code = KEY_ENTER,
325        .debounce_interval = 5,
326    },
327    /* SELECT button */ {
328        .gpio = JZ_GPIO_PORTD(17),
329        .active_low = 1,
330        .code = KEY_ESC,
331        .debounce_interval = 5,
332    },
333    /* POWER slider */ {
334        .gpio = JZ_GPIO_PORTD(29),
335        .active_low = 1,
336        .code = KEY_POWER,
337        .wakeup = 1,
338    },
339    /* POWER hold */ {
340        .gpio = JZ_GPIO_PORTD(22),
341        .active_low = 1,
342        .code = KEY_PAUSE,
343    },
344};
345
346static struct gpio_keys_platform_data a320_gpio_keys_pdata = {
347    .buttons = a320_buttons,
348    .nbuttons = ARRAY_SIZE(a320_buttons),
349    .rep = 1,
350};
351
352static struct platform_device a320_gpio_keys_device = {
353    .name = "gpio-keys",
354    .id = -1,
355    .dev = {
356        .platform_data = &a320_gpio_keys_pdata,
357    },
358};
359
360/* Audio */
361static struct platform_device a320_audio_device = {
362    .name = "a320-audio",
363    .id = -1,
364};
365
366static struct platform_device *jz_platform_devices[] __initdata = {
367#ifdef CONFIG_I2C_JZ47XX
368    &jz4740_i2c_device,
369#endif
370#ifdef CONFIG_I2C_GPIO
371    &a320_i2c_device,
372#endif
373    /* USB host is not usable since the PCB does not route the pins to
374     * a place where new wires can be soldered. */
375    /*&jz4740_usb_ohci_device,*/
376    &jz4740_udc_device,
377    &jz4740_mmc_device,
378    &jz4740_nand_device,
379    &jz4740_framebuffer_device,
380    &jz4740_pcm_device,
381    &jz4740_i2s_device,
382    &jz4740_codec_device,
383    &jz4740_rtc_device,
384    &jz4740_adc_device,
385    &jz4740_wdt_device,
386    &a320_charger_device,
387    &jz4740_pwm_device,
388    &a320_backlight_device,
389    &a320_gpio_keys_device,
390    &a320_audio_device,
391};
392
393static void __init board_gpio_setup(void)
394{
395    /* We only need to enable/disable pullup here for pins used in generic
396     * drivers. Everything else is done by the drivers themselves. */
397
398    /* Disable pullup of the USB detection pin: on the A320 pullup or not
399     * seems to make no difference, but on A330 the signal will be unstable
400     * when the pullup is enabled. */
401    jz_gpio_disable_pullup(JZ_GPIO_PORTD(28));
402}
403
404static int __init a320_init_platform_devices(void)
405{
406    jz4740_framebuffer_device.dev.platform_data = &a320_fb_pdata;
407    jz4740_nand_device.dev.platform_data = &a320_nand_pdata;
408    jz4740_adc_device.dev.platform_data = &a320_battery_pdata;
409    jz4740_mmc_device.dev.platform_data = &a320_mmc_pdata;
410
411    gpiod_add_lookup_table(&a320_nand_gpio_table);
412
413    jz4740_serial_device_register();
414
415    pwm_add_table(a320_pwm_table, ARRAY_SIZE(a320_pwm_table));
416
417    return platform_add_devices(jz_platform_devices,
418                    ARRAY_SIZE(jz_platform_devices));
419}
420
421struct jz4740_clock_board_data jz4740_clock_bdata = {
422    .ext_rate = 12000000,
423    .rtc_rate = 32768,
424};
425
426static struct rda5807_platform_data a320_rda5807_pdata = {
427    .input_flags = RDA5807_INPUT_LNA_WC_25 | RDA5807_LNA_PORT_P,
428    .output_flags = RDA5807_OUTPUT_AUDIO_ANALOG,
429};
430
431static struct i2c_board_info a320_i2c_info[] __initdata = {
432    {
433        .type = "radio-rda5807",
434        .addr = RDA5807_I2C_ADDR,
435        .platform_data = &a320_rda5807_pdata,
436    }
437};
438
439static int __init a320_board_setup(void)
440{
441    printk(KERN_INFO "JZ4740 A320 board setup\n");
442
443    panic_blink = a320_panic_blink_callback;
444
445    board_gpio_setup();
446
447    if (a320_init_platform_devices())
448        panic("Failed to initalize platform devices\n");
449
450    i2c_register_board_info(0, a320_i2c_info, ARRAY_SIZE(a320_i2c_info));
451
452    return 0;
453}
454
455arch_initcall(a320_board_setup);

Archive Download the corresponding diff file



interactive