Root/target/linux/xburst/files-2.6.32/arch/mips/jz4740/board-n526.c

1/*
2 * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
3 * N526 eBook reader support
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * You should have received a copy of the GNU General Public License along
11 * with this program; if not, write to the Free Software Foundation, Inc.,
12 * 675 Mass Ave, Cambridge, MA 02139, USA.
13 *
14 */
15
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/gpio.h>
19
20#include <asm/mach-jz4740/platform.h>
21
22#include <linux/mtd/jz4740_nand.h>
23#include <linux/jz4740_fb.h>
24#include <linux/power_supply.h>
25#include <linux/mmc/jz4740_mmc.h>
26
27#include <video/broadsheetfb.h>
28#include <linux/delay.h>
29#include <linux/interrupt.h>
30
31#include <linux/input.h>
32#include <linux/gpio_keys.h>
33
34#include <linux/i2c.h>
35#include <linux/i2c-gpio.h>
36
37#include "clock.h"
38
39/* NAND */
40static struct nand_ecclayout n526_ecclayout = {
41    .eccbytes = 36,
42    .eccpos = {
43        6, 7, 8, 9, 10, 11, 12, 13,
44        14, 15, 16, 17, 18, 19, 20, 21,
45        22, 23, 24, 25, 26, 27, 28, 29,
46        30, 31, 32, 33, 34, 35, 36, 37,
47        38, 39, 40, 41},
48    .oobfree = {
49        {.offset = 2,
50         .length = 4},
51        {.offset = 42,
52         .length = 22}}
53};
54
55static struct mtd_partition n526_partitions[] = {
56    { .name = "NAND BOOT partition",
57      .offset = 0 * 0x100000,
58      .size = 4 * 0x100000,
59     },
60    { .name = "NAND KERNEL partition",
61      .offset = 4 * 0x100000,
62      .size = 4 * 0x100000,
63     },
64    { .name = "NAND ROOTFS partition",
65      .offset = 16 * 0x100000,
66      .size = 498 * 0x100000,
67     },
68};
69
70static struct jz_nand_platform_data n526_nand_pdata = {
71    .ecc_layout = &n526_ecclayout,
72    .partitions = n526_partitions,
73    .num_partitions = ARRAY_SIZE(n526_partitions),
74    .busy_gpio = 94,
75};
76
77static struct jz4740_mmc_platform_data n526_mmc_pdata = {
78    .gpio_card_detect = JZ_GPIO_PORTD(7),
79    .card_detect_active_low = 1,
80    .gpio_read_only = -1,
81    .gpio_power = JZ_GPIO_PORTD(17),
82    .power_active_low = 1,
83};
84
85static struct gpio_led n526_leds[] = {
86    {
87        .name = "n526:blue:power",
88        .gpio = JZ_GPIO_PORTD(28),
89        .default_state = LEDS_GPIO_DEFSTATE_ON,
90    }
91};
92
93static struct gpio_led_platform_data n526_leds_pdata = {
94    .leds = n526_leds,
95    .num_leds = ARRAY_SIZE(n526_leds),
96};
97
98static struct platform_device n526_leds_device = {
99    .name = "leds-gpio",
100    .id = -1,
101    .dev = {
102        .platform_data = &n526_leds_pdata,
103    },
104};
105
106static void __init board_gpio_setup(void)
107{
108    /* We only need to enable/disable pullup here for pins used in generic
109     * drivers. Everything else is done by the drivers themselfs. */
110    jz_gpio_disable_pullup(JZ_GPIO_PORTD(17));
111    jz_gpio_enable_pullup(JZ_GPIO_PORTD(7));
112    jz_gpio_disable_pullup(JZ_GPIO_PORTC(19));
113    jz_gpio_disable_pullup(JZ_GPIO_PORTC(20));
114    jz_gpio_disable_pullup(JZ_GPIO_PORTC(21));
115    jz_gpio_disable_pullup(JZ_GPIO_PORTC(23));
116}
117
118
119static const int n526_eink_ctrl_gpios[] = {
120    0,
121    JZ_GPIO_PORTC(23),
122    JZ_GPIO_PORTC(19),
123    JZ_GPIO_PORTC(20),
124};
125
126static void n526_eink_set_ctl(struct broadsheetfb_par * par, unsigned char ctrl, u8
127value)
128{
129    gpio_set_value(n526_eink_ctrl_gpios[ctrl], value);
130}
131
132
133static int n526_eink_wait(struct broadsheetfb_par *par)
134{
135    wait_event(par->waitq, gpio_get_value(JZ_GPIO_PORTB(17)));
136
137    return 0;
138}
139
140static u16 n526_eink_get_hdb(struct broadsheetfb_par *par)
141{
142    u16 value = 0;
143    jz_gpio_port_direction_input(JZ_GPIO_PORTC(0), 0xffff);
144    gpio_set_value(JZ_GPIO_PORTC(21), 0);
145    mdelay(100);
146
147    value = jz_gpio_port_get_value(JZ_GPIO_PORTC(0), 0xffff);
148
149    gpio_set_value(JZ_GPIO_PORTC(21), 1);
150    jz_gpio_port_direction_output(JZ_GPIO_PORTC(0), 0xffff);
151    return value;
152}
153
154static void n526_eink_set_hdb(struct broadsheetfb_par *par, u16 value)
155{
156    jz_gpio_port_set_value(JZ_GPIO_PORTC(0), value, 0xffff);
157}
158
159static int n526_eink_init(struct broadsheetfb_par *par)
160{
161    int i;
162
163    gpio_request(JZ_GPIO_PORTD(1), "display reset");
164    gpio_direction_output(JZ_GPIO_PORTD(1), 1);
165    mdelay(10);
166    gpio_set_value(JZ_GPIO_PORTD(1), 0);
167
168    gpio_request(JZ_GPIO_PORTB(18), "eink enable");
169    gpio_direction_output(JZ_GPIO_PORTB(18), 0);
170
171    gpio_request(JZ_GPIO_PORTB(29), "foobar");
172    gpio_direction_output(JZ_GPIO_PORTB(29), 1);
173
174    for(i = 1; i < ARRAY_SIZE(n526_eink_ctrl_gpios); ++i) {
175        gpio_request(n526_eink_ctrl_gpios[i], "eink display ctrl");
176        gpio_direction_output(n526_eink_ctrl_gpios[i], 0);
177    }
178
179    gpio_request(JZ_GPIO_PORTC(22), "foobar");
180    gpio_direction_input(JZ_GPIO_PORTC(22));
181    gpio_request(JZ_GPIO_PORTC(21), "eink nRD");
182    gpio_direction_output(JZ_GPIO_PORTC(21), 1);
183
184    for(i = 0; i < 16; ++i) {
185        gpio_request(JZ_GPIO_PORTC(i), "eink display data");
186    }
187    jz_gpio_port_direction_output(JZ_GPIO_PORTC(0), 0xffff);
188
189    gpio_set_value(JZ_GPIO_PORTB(18), 1);
190
191    return 0;
192}
193
194static irqreturn_t n526_eink_busy_irq(int irq, void *devid)
195{
196    struct broadsheetfb_par *par = devid;
197    wake_up(&par->waitq);
198
199    return IRQ_HANDLED;
200}
201
202static int n526_eink_setup_irq(struct fb_info *info)
203{
204    int ret;
205    struct broadsheetfb_par *par = info->par;
206
207    gpio_request(JZ_GPIO_PORTB(17), "eink busy");
208    gpio_direction_input(JZ_GPIO_PORTB(17));
209
210    ret = request_irq(gpio_to_irq(JZ_GPIO_PORTB(17)), n526_eink_busy_irq,
211                IRQF_DISABLED | IRQF_TRIGGER_RISING,
212                "eink busyline", par);
213    if (ret)
214        printk("n526 display: Failed to request busyline irq: %d\n", ret);
215    return 0;
216}
217
218static void n526_eink_cleanup(struct broadsheetfb_par *par)
219{
220}
221
222static struct broadsheet_board broadsheet_pdata = {
223    .owner = THIS_MODULE,
224    .init = n526_eink_init,
225    .wait_for_rdy = n526_eink_wait,
226    .set_ctl = n526_eink_set_ctl,
227    .set_hdb = n526_eink_set_hdb,
228    .get_hdb = n526_eink_get_hdb,
229    .cleanup = n526_eink_cleanup,
230    .setup_irq = n526_eink_setup_irq,
231};
232
233static struct platform_device n526_broadsheet_device = {
234    .name = "broadsheetfb",
235    .id = -1,
236    .dev = {
237        .platform_data = &broadsheet_pdata,
238    },
239};
240
241static struct gpio_keys_button qi_lb60_gpio_keys_buttons[] = {
242    [0] = {
243        .code = KEY_ENTER,
244        .gpio = 0,
245        .active_low = 1,
246        .desc = "Power",
247    },
248};
249
250static struct gpio_keys_platform_data qi_lb60_gpio_keys_data = {
251    .nbuttons = ARRAY_SIZE(qi_lb60_gpio_keys_buttons),
252    .buttons = qi_lb60_gpio_keys_buttons,
253};
254
255static struct platform_device qi_lb60_gpio_keys = {
256    .name = "gpio-keys",
257    .id = -1,
258    .dev = {
259        .platform_data = &qi_lb60_gpio_keys_data,
260    }
261};
262
263static struct i2c_gpio_platform_data n526_i2c_pdata = {
264    .sda_pin = JZ_GPIO_PORTD(23),
265    .scl_pin = JZ_GPIO_PORTD(24),
266    .udelay = 2,
267    .timeout = 3 * HZ,
268};
269
270static struct platform_device n526_i2c_device = {
271    .name = "i2c-gpio",
272    .id = -1,
273    .dev = {
274        .platform_data = &n526_i2c_pdata,
275    },
276};
277
278static struct i2c_board_info n526_i2c_board_info = {
279    .type = "n526-lpc",
280    .addr = 0x54,
281};
282
283static struct platform_device *jz_platform_devices[] __initdata = {
284    &jz4740_usb_ohci_device,
285    &jz4740_usb_gdt_device,
286    &jz4740_mmc_device,
287    &jz4740_nand_device,
288    &jz4740_i2s_device,
289    &jz4740_codec_device,
290    &jz4740_rtc_device,
291    &n526_leds_device,
292    &n526_broadsheet_device,
293    &qi_lb60_gpio_keys,
294    &n526_i2c_device,
295};
296
297
298static int __init n526_init_platform_devices(void)
299{
300
301    jz4740_nand_device.dev.platform_data = &n526_nand_pdata;
302    jz4740_mmc_device.dev.platform_data = &n526_mmc_pdata;
303
304    n526_i2c_board_info.irq = gpio_to_irq(JZ_GPIO_PORTD(14)),
305    i2c_register_board_info(0, &n526_i2c_board_info, 1);
306
307    return platform_add_devices(jz_platform_devices,
308                    ARRAY_SIZE(jz_platform_devices));
309
310}
311
312struct jz4740_clock_board_data jz4740_clock_bdata = {
313    .ext_rate = 12000000,
314    .rtc_rate = 32768,
315};
316
317extern int jz_gpiolib_init(void);
318
319static int __init n526_board_setup(void)
320{
321    if (jz_gpiolib_init())
322        panic("Failed to initalize jz gpio\n");
323
324    jz4740_clock_init();
325    board_gpio_setup();
326
327    if (n526_init_platform_devices())
328        panic("Failed to initalize platform devices\n");
329
330    return 0;
331}
332
333arch_initcall(n526_board_setup);
334

Archive Download this file



interactive