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