Root/arch/mips/jz47xx/jz4740/board-n526.c

Source at commit fad288aff22be8618aeb6baa5c980f721226a5e1 created 9 years 4 months ago.
By Peter Zotov, MIPS: JZ47xx: Fix a few naming issues.
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 <video/broadsheetfb.h>
21#include <linux/delay.h>
22#include <linux/interrupt.h>
23
24#include <linux/input.h>
25#include <linux/gpio_keys.h>
26
27#include <linux/leds.h>
28
29#include <linux/i2c.h>
30
31#include "../clock.h"
32
33#include <asm/mach-jz4740/jz4740_mmc.h>
34#include <asm/mach-jz4740/jz4740_nand.h>
35#include <asm/mach-jz4740/jz4740_fb.h>
36
37#include <asm/mach-jz4740/platform.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        {
50            .offset = 2,
51            .length = 4,
52        },
53        {
54            .offset = 42,
55            .length = 22,
56        },
57    }
58};
59
60static struct mtd_partition n526_partitions[] = {
61    { .name = "NAND BOOT partition",
62      .offset = 0 * 0x100000,
63      .size = 4 * 0x100000,
64     },
65    { .name = "NAND KERNEL partition",
66      .offset = 4 * 0x100000,
67      .size = 4 * 0x100000,
68     },
69    { .name = "NAND ROOTFS partition",
70      .offset = 16 * 0x100000,
71      .size = 498 * 0x100000,
72     },
73};
74
75static struct jz_nand_platform_data n526_nand_pdata = {
76    .ecc_layout = &n526_ecclayout,
77    .partitions = n526_partitions,
78    .num_partitions = ARRAY_SIZE(n526_partitions),
79    .busy_gpio = JZ_GPIO_PORTC(30),
80};
81
82static struct jz4740_mmc_platform_data n526_mmc_pdata = {
83    .gpio_card_detect = JZ_GPIO_PORTD(7),
84    .card_detect_active_low = 1,
85    .gpio_read_only = -1,
86    .gpio_power = JZ_GPIO_PORTD(17),
87    .power_active_low = 1,
88};
89
90static struct gpio_led n526_leds[] = {
91    {
92        .name = "n526:blue:power",
93        .gpio = JZ_GPIO_PORTD(28),
94        .default_state = LEDS_GPIO_DEFSTATE_ON,
95    }
96};
97
98static struct gpio_led_platform_data n526_leds_pdata = {
99    .leds = n526_leds,
100    .num_leds = ARRAY_SIZE(n526_leds),
101};
102
103static struct platform_device n526_leds_device = {
104    .name = "leds-gpio",
105    .id = -1,
106    .dev = {
107        .platform_data = &n526_leds_pdata,
108    },
109};
110
111static void __init board_gpio_setup(void)
112{
113    /* We only need to enable/disable pullup here for pins used in generic
114     * drivers. Everything else is done by the drivers themselfs. */
115    jz_gpio_disable_pullup(JZ_GPIO_PORTD(17));
116    jz_gpio_enable_pullup(JZ_GPIO_PORTD(7));
117    jz_gpio_disable_pullup(JZ_GPIO_PORTC(19));
118    jz_gpio_disable_pullup(JZ_GPIO_PORTC(20));
119    jz_gpio_disable_pullup(JZ_GPIO_PORTC(21));
120    jz_gpio_disable_pullup(JZ_GPIO_PORTC(23));
121}
122
123
124static const int n526_eink_ctrl_gpios[] = {
125    0,
126    JZ_GPIO_PORTC(23),
127    JZ_GPIO_PORTC(19),
128    JZ_GPIO_PORTC(20),
129};
130
131static void n526_eink_set_ctl(struct broadsheetfb_par * par, unsigned char ctrl, u8
132value)
133{
134    gpio_set_value(n526_eink_ctrl_gpios[ctrl], value);
135}
136
137
138static int n526_eink_wait(struct broadsheetfb_par *par)
139{
140    wait_event(par->waitq, gpio_get_value(JZ_GPIO_PORTB(17)));
141
142    return 0;
143}
144
145static u16 n526_eink_get_hdb(struct broadsheetfb_par *par)
146{
147    u16 value = 0;
148    jz_gpio_port_direction_input(JZ_GPIO_PORTC(0), 0xffff);
149    gpio_set_value(JZ_GPIO_PORTC(21), 0);
150    mdelay(100);
151
152    value = jz_gpio_port_get_value(JZ_GPIO_PORTC(0), 0xffff);
153
154    gpio_set_value(JZ_GPIO_PORTC(21), 1);
155    jz_gpio_port_direction_output(JZ_GPIO_PORTC(0), 0xffff);
156    return value;
157}
158
159static void n526_eink_set_hdb(struct broadsheetfb_par *par, u16 value)
160{
161    jz_gpio_port_set_value(JZ_GPIO_PORTC(0), value, 0xffff);
162}
163
164static int n526_eink_init(struct broadsheetfb_par *par)
165{
166    int i;
167
168    gpio_request(JZ_GPIO_PORTD(1), "display reset");
169    gpio_direction_output(JZ_GPIO_PORTD(1), 1);
170    mdelay(10);
171    gpio_set_value(JZ_GPIO_PORTD(1), 0);
172
173    gpio_request(JZ_GPIO_PORTB(18), "eink enable");
174    gpio_direction_output(JZ_GPIO_PORTB(18), 0);
175
176    gpio_request(JZ_GPIO_PORTB(29), "foobar");
177    gpio_direction_output(JZ_GPIO_PORTB(29), 1);
178
179    for(i = 1; i < ARRAY_SIZE(n526_eink_ctrl_gpios); ++i) {
180        gpio_request(n526_eink_ctrl_gpios[i], "eink display ctrl");
181        gpio_direction_output(n526_eink_ctrl_gpios[i], 0);
182    }
183
184    gpio_request(JZ_GPIO_PORTC(22), "foobar");
185    gpio_direction_input(JZ_GPIO_PORTC(22));
186    gpio_request(JZ_GPIO_PORTC(21), "eink nRD");
187    gpio_direction_output(JZ_GPIO_PORTC(21), 1);
188
189    for(i = 0; i < 16; ++i) {
190        gpio_request(JZ_GPIO_PORTC(i), "eink display data");
191    }
192    jz_gpio_port_direction_output(JZ_GPIO_PORTC(0), 0xffff);
193
194    gpio_set_value(JZ_GPIO_PORTB(18), 1);
195
196    return 0;
197}
198
199static irqreturn_t n526_eink_busy_irq(int irq, void *devid)
200{
201    struct broadsheetfb_par *par = devid;
202    wake_up(&par->waitq);
203
204    return IRQ_HANDLED;
205}
206
207static int n526_eink_setup_irq(struct fb_info *info)
208{
209    int ret;
210    struct broadsheetfb_par *par = info->par;
211
212    gpio_request(JZ_GPIO_PORTB(17), "eink busy");
213    gpio_direction_input(JZ_GPIO_PORTB(17));
214
215    ret = request_irq(gpio_to_irq(JZ_GPIO_PORTB(17)), n526_eink_busy_irq,
216                IRQF_DISABLED | IRQF_TRIGGER_RISING,
217                "eink busyline", par);
218    if (ret)
219        printk("n526 display: Failed to request busyline irq: %d\n", ret);
220    return 0;
221}
222
223static void n526_eink_cleanup(struct broadsheetfb_par *par)
224{
225}
226
227static struct broadsheet_board broadsheet_pdata = {
228    .owner = THIS_MODULE,
229    .init = n526_eink_init,
230    .wait_for_rdy = n526_eink_wait,
231    .set_ctl = n526_eink_set_ctl,
232    .set_hdb = n526_eink_set_hdb,
233    .get_hdb = n526_eink_get_hdb,
234    .cleanup = n526_eink_cleanup,
235    .setup_irq = n526_eink_setup_irq,
236};
237
238static struct platform_device n526_broadsheet_device = {
239    .name = "broadsheetfb",
240    .id = -1,
241    .dev = {
242        .platform_data = &broadsheet_pdata,
243    },
244};
245
246/* Buttons */
247static struct gpio_keys_button n526_gpio_keys_buttons[] = {
248    [0] = {
249        .code = KEY_ENTER,
250        .gpio = 0,
251        .active_low = 1,
252        .desc = "Power",
253    },
254};
255
256static struct gpio_keys_platform_data n526_gpio_keys_data = {
257    .nbuttons = ARRAY_SIZE(n526_gpio_keys_buttons),
258    .buttons = n526_gpio_keys_buttons,
259};
260
261static struct platform_device n526_gpio_keys_device = {
262    .name = "gpio-keys",
263    .id = -1,
264    .dev = {
265        .platform_data = &n526_gpio_keys_data,
266    }
267};
268
269static struct i2c_board_info n526_i2c_board_info = {
270    .type = "n526-lpc",
271    .addr = 0x54,
272};
273
274static struct platform_device *n526_platform_devices[] __initdata = {
275    &jz4740_usb_ohci_device,
276    &jz4740_udc_device,
277    &jz4740_mmc_device,
278    &jz4740_nand_device,
279    &jz4740_i2s_device,
280    &jz4740_codec_device,
281    &jz4740_pcm_device,
282    &jz4740_rtc_device,
283    &jz4740_i2c_device,
284    &n526_leds_device,
285    &n526_broadsheet_device,
286    &n526_gpio_keys_device,
287};
288
289static int __init n526_init_platform_devices(void)
290{
291    jz4740_nand_device.dev.platform_data = &n526_nand_pdata;
292    jz4740_mmc_device.dev.platform_data = &n526_mmc_pdata;
293
294    jz4740_serial_device_register();
295
296    n526_i2c_board_info.irq = gpio_to_irq(JZ_GPIO_PORTD(14)),
297    i2c_register_board_info(0, &n526_i2c_board_info, 1);
298
299    return platform_add_devices(n526_platform_devices,
300                    ARRAY_SIZE(n526_platform_devices));
301
302}
303
304struct jz4740_clock_board_data jz4740_clock_bdata = {
305    .ext_rate = 12000000,
306    .rtc_rate = 32768,
307};
308
309static int __init n526_board_setup(void)
310{
311    board_gpio_setup();
312
313    if (n526_init_platform_devices())
314        panic("Failed to initalize platform devices\n");
315
316    return 0;
317}
318arch_initcall(n526_board_setup);
319

Archive Download this file



interactive