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

Archive Download the corresponding diff file



interactive