1 From 5739f1348052000ed12a7745f7bafd352fff832a 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 07/23] Add n526 board support
7 arch/mips/jz4740/Kconfig | 4 +
8 arch/mips/jz4740/Makefile | 1 +
9 arch/mips/jz4740/board-n526.c | 318 +++++++++++++++++++++++++++++++++++++++++
10 3 files changed, 323 insertions(+), 0 deletions(-)
11 create mode 100644 arch/mips/jz4740/board-n526.c
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"
20 + bool "Hanvon n526 eBook reader"
26 --- a/arch/mips/jz4740/Makefile
27 +++ b/arch/mips/jz4740/Makefile
28 @@ -13,6 +13,7 @@ obj-$(CONFIG_DEBUG_FS) += clock-debugfs.
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
37 +++ b/arch/mips/jz4740/board-n526.c
40 + * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
41 + * N526 eBook reader support
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.
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.
54 +#include <linux/kernel.h>
55 +#include <linux/init.h>
56 +#include <linux/gpio.h>
58 +#include <linux/mutex.h>
59 +#include <linux/wait.h>
60 +#include <video/broadsheetfb.h>
61 +#include <linux/delay.h>
62 +#include <linux/interrupt.h>
64 +#include <linux/input.h>
65 +#include <linux/gpio_keys.h>
67 +#include <linux/leds.h>
69 +#include <linux/i2c.h>
73 +#include <asm/mach-jz4740/jz4740_mmc.h>
74 +#include <asm/mach-jz4740/jz4740_nand.h>
75 +#include <asm/mach-jz4740/jz4740_fb.h>
77 +#include <asm/mach-jz4740/platform.h>
80 +static struct nand_ecclayout n526_ecclayout = {
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,
100 +static struct mtd_partition n526_partitions[] = {
101 + { .name = "NAND BOOT partition",
102 + .offset = 0 * 0x100000,
103 + .size = 4 * 0x100000,
105 + { .name = "NAND KERNEL partition",
106 + .offset = 4 * 0x100000,
107 + .size = 4 * 0x100000,
109 + { .name = "NAND ROOTFS partition",
110 + .offset = 16 * 0x100000,
111 + .size = 498 * 0x100000,
115 +static struct jz_nand_platform_data n526_nand_pdata = {
116 + .ecc_layout = &n526_ecclayout,
117 + .partitions = n526_partitions,
118 + .num_partitions = ARRAY_SIZE(n526_partitions),
119 + .busy_gpio = JZ_GPIO_PORTC(30),
122 +static struct jz4740_mmc_platform_data n526_mmc_pdata = {
123 + .gpio_card_detect = JZ_GPIO_PORTD(7),
124 + .card_detect_active_low = 1,
125 + .gpio_read_only = -1,
126 + .gpio_power = JZ_GPIO_PORTD(17),
127 + .power_active_low = 1,
130 +static struct gpio_led n526_leds[] = {
132 + .name = "n526:blue:power",
133 + .gpio = JZ_GPIO_PORTD(28),
134 + .default_state = LEDS_GPIO_DEFSTATE_ON,
138 +static struct gpio_led_platform_data n526_leds_pdata = {
140 + .num_leds = ARRAY_SIZE(n526_leds),
143 +static struct platform_device n526_leds_device = {
144 + .name = "leds-gpio",
147 + .platform_data = &n526_leds_pdata,
151 +static void __init board_gpio_setup(void)
153 + /* We only need to enable/disable pullup here for pins used in generic
154 + * drivers. Everything else is done by the drivers themselfs. */
155 + jz_gpio_disable_pullup(JZ_GPIO_PORTD(17));
156 + jz_gpio_enable_pullup(JZ_GPIO_PORTD(7));
157 + jz_gpio_disable_pullup(JZ_GPIO_PORTC(19));
158 + jz_gpio_disable_pullup(JZ_GPIO_PORTC(20));
159 + jz_gpio_disable_pullup(JZ_GPIO_PORTC(21));
160 + jz_gpio_disable_pullup(JZ_GPIO_PORTC(23));
164 +static const int n526_eink_ctrl_gpios[] = {
171 +static void n526_eink_set_ctl(struct broadsheetfb_par * par, unsigned char ctrl, u8
174 + gpio_set_value(n526_eink_ctrl_gpios[ctrl], value);
178 +static int n526_eink_wait(struct broadsheetfb_par *par)
180 + wait_event(par->waitq, gpio_get_value(JZ_GPIO_PORTB(17)));
185 +static u16 n526_eink_get_hdb(struct broadsheetfb_par *par)
188 + jz_gpio_port_direction_input(JZ_GPIO_PORTC(0), 0xffff);
189 + gpio_set_value(JZ_GPIO_PORTC(21), 0);
192 + value = jz_gpio_port_get_value(JZ_GPIO_PORTC(0), 0xffff);
194 + gpio_set_value(JZ_GPIO_PORTC(21), 1);
195 + jz_gpio_port_direction_output(JZ_GPIO_PORTC(0), 0xffff);
199 +static void n526_eink_set_hdb(struct broadsheetfb_par *par, u16 value)
201 + jz_gpio_port_set_value(JZ_GPIO_PORTC(0), value, 0xffff);
204 +static int n526_eink_init(struct broadsheetfb_par *par)
208 + gpio_request(JZ_GPIO_PORTD(1), "display reset");
209 + gpio_direction_output(JZ_GPIO_PORTD(1), 1);
211 + gpio_set_value(JZ_GPIO_PORTD(1), 0);
213 + gpio_request(JZ_GPIO_PORTB(18), "eink enable");
214 + gpio_direction_output(JZ_GPIO_PORTB(18), 0);
216 + gpio_request(JZ_GPIO_PORTB(29), "foobar");
217 + gpio_direction_output(JZ_GPIO_PORTB(29), 1);
219 + for(i = 1; i < ARRAY_SIZE(n526_eink_ctrl_gpios); ++i) {
220 + gpio_request(n526_eink_ctrl_gpios[i], "eink display ctrl");
221 + gpio_direction_output(n526_eink_ctrl_gpios[i], 0);
224 + gpio_request(JZ_GPIO_PORTC(22), "foobar");
225 + gpio_direction_input(JZ_GPIO_PORTC(22));
226 + gpio_request(JZ_GPIO_PORTC(21), "eink nRD");
227 + gpio_direction_output(JZ_GPIO_PORTC(21), 1);
229 + for(i = 0; i < 16; ++i) {
230 + gpio_request(JZ_GPIO_PORTC(i), "eink display data");
232 + jz_gpio_port_direction_output(JZ_GPIO_PORTC(0), 0xffff);
234 + gpio_set_value(JZ_GPIO_PORTB(18), 1);
239 +static irqreturn_t n526_eink_busy_irq(int irq, void *devid)
241 + struct broadsheetfb_par *par = devid;
242 + wake_up(&par->waitq);
244 + return IRQ_HANDLED;
247 +static int n526_eink_setup_irq(struct fb_info *info)
250 + struct broadsheetfb_par *par = info->par;
252 + gpio_request(JZ_GPIO_PORTB(17), "eink busy");
253 + gpio_direction_input(JZ_GPIO_PORTB(17));
255 + ret = request_irq(gpio_to_irq(JZ_GPIO_PORTB(17)), n526_eink_busy_irq,
256 + IRQF_DISABLED | IRQF_TRIGGER_RISING,
257 + "eink busyline", par);
259 + printk("n526 display: Failed to request busyline irq: %d\n", ret);
263 +static void n526_eink_cleanup(struct broadsheetfb_par *par)
267 +static struct broadsheet_board broadsheet_pdata = {
268 + .owner = THIS_MODULE,
269 + .init = n526_eink_init,
270 + .wait_for_rdy = n526_eink_wait,
271 + .set_ctl = n526_eink_set_ctl,
272 + .set_hdb = n526_eink_set_hdb,
273 + .get_hdb = n526_eink_get_hdb,
274 + .cleanup = n526_eink_cleanup,
275 + .setup_irq = n526_eink_setup_irq,
278 +static struct platform_device n526_broadsheet_device = {
279 + .name = "broadsheetfb",
282 + .platform_data = &broadsheet_pdata,
287 +static struct gpio_keys_button n526_gpio_keys_buttons[] = {
296 +static struct gpio_keys_platform_data n526_gpio_keys_data = {
297 + .nbuttons = ARRAY_SIZE(n526_gpio_keys_buttons),
298 + .buttons = n526_gpio_keys_buttons,
301 +static struct platform_device n526_gpio_keys_device = {
302 + .name = "gpio-keys",
305 + .platform_data = &n526_gpio_keys_data,
309 +static struct i2c_board_info n526_i2c_board_info = {
310 + .type = "n526-lpc",
314 +static struct platform_device *n526_platform_devices[] __initdata = {
315 + &jz4740_usb_ohci_device,
316 + &jz4740_udc_device,
317 + &jz4740_mmc_device,
318 + &jz4740_nand_device,
319 + &jz4740_i2s_device,
320 + &jz4740_codec_device,
321 + &jz4740_pcm_device,
322 + &jz4740_rtc_device,
323 + &jz4740_i2c_device,
325 + &n526_broadsheet_device,
326 + &n526_gpio_keys_device,
329 +static int __init n526_init_platform_devices(void)
331 + jz4740_nand_device.dev.platform_data = &n526_nand_pdata;
332 + jz4740_mmc_device.dev.platform_data = &n526_mmc_pdata;
334 + jz4740_serial_device_register();
336 + n526_i2c_board_info.irq = gpio_to_irq(JZ_GPIO_PORTD(14)),
337 + i2c_register_board_info(0, &n526_i2c_board_info, 1);
339 + return platform_add_devices(n526_platform_devices,
340 + ARRAY_SIZE(n526_platform_devices));
344 +struct jz4740_clock_board_data jz4740_clock_bdata = {
345 + .ext_rate = 12000000,
349 +static int __init n526_board_setup(void)
351 + board_gpio_setup();
353 + if (n526_init_platform_devices())
354 + panic("Failed to initalize platform devices\n");
358 +arch_initcall(n526_board_setup);