2 * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
3 * N526 eBook reader support
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.
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.
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/gpio.h>
20 #include <asm/mach-jz4740/platform.h>
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>
27 #include <video/broadsheetfb.h>
28 #include <linux/delay.h>
29 #include <linux/interrupt.h>
31 #include <linux/input.h>
32 #include <linux/gpio_keys.h>
34 #include <linux/i2c.h>
35 #include <linux/i2c-gpio.h>
40 static struct nand_ecclayout n526_ecclayout
= {
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,
55 static struct mtd_partition n526_partitions
[] = {
56 { .name
= "NAND BOOT partition",
57 .offset
= 0 * 0x100000,
60 { .name
= "NAND KERNEL partition",
61 .offset
= 4 * 0x100000,
64 { .name
= "NAND ROOTFS partition",
65 .offset
= 16 * 0x100000,
66 .size
= 498 * 0x100000,
70 static struct jz_nand_platform_data n526_nand_pdata
= {
71 .ecc_layout
= &n526_ecclayout
,
72 .partitions
= n526_partitions
,
73 .num_partitions
= ARRAY_SIZE(n526_partitions
),
77 static struct jz4740_mmc_platform_data n526_mmc_pdata
= {
78 .gpio_card_detect
= JZ_GPIO_PORTD(7),
79 .card_detect_active_low
= 1,
81 .gpio_power
= JZ_GPIO_PORTD(17),
82 .power_active_low
= 1,
85 static struct gpio_led n526_leds
[] = {
87 .name
= "n526:blue:power",
88 .gpio
= JZ_GPIO_PORTD(28),
89 .default_state
= LEDS_GPIO_DEFSTATE_ON
,
93 static struct gpio_led_platform_data n526_leds_pdata
= {
95 .num_leds
= ARRAY_SIZE(n526_leds
),
98 static struct platform_device n526_leds_device
= {
102 .platform_data
= &n526_leds_pdata
,
106 static void __init
board_gpio_setup(void)
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));
119 static const int n526_eink_ctrl_gpios
[] = {
126 static void n526_eink_set_ctl(struct broadsheetfb_par
* par
, unsigned char ctrl
, u8
129 gpio_set_value(n526_eink_ctrl_gpios
[ctrl
], value
);
133 static int n526_eink_wait(struct broadsheetfb_par
*par
)
135 wait_event(par
->waitq
, gpio_get_value(JZ_GPIO_PORTB(17)));
140 static u16
n526_eink_get_hdb(struct broadsheetfb_par
*par
)
143 jz_gpio_port_direction_input(JZ_GPIO_PORTC(0), 0xffff);
144 gpio_set_value(JZ_GPIO_PORTC(21), 0);
147 value
= jz_gpio_port_get_value(JZ_GPIO_PORTC(0), 0xffff);
149 gpio_set_value(JZ_GPIO_PORTC(21), 1);
150 jz_gpio_port_direction_output(JZ_GPIO_PORTC(0), 0xffff);
154 static void n526_eink_set_hdb(struct broadsheetfb_par
*par
, u16 value
)
156 jz_gpio_port_set_value(JZ_GPIO_PORTC(0), value
, 0xffff);
159 static int n526_eink_init(struct broadsheetfb_par
*par
)
163 gpio_request(JZ_GPIO_PORTD(1), "display reset");
164 gpio_direction_output(JZ_GPIO_PORTD(1), 1);
166 gpio_set_value(JZ_GPIO_PORTD(1), 0);
168 gpio_request(JZ_GPIO_PORTB(18), "eink enable");
169 gpio_direction_output(JZ_GPIO_PORTB(18), 0);
171 gpio_request(JZ_GPIO_PORTB(29), "foobar");
172 gpio_direction_output(JZ_GPIO_PORTB(29), 1);
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);
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);
184 for(i
= 0; i
< 16; ++i
) {
185 gpio_request(JZ_GPIO_PORTC(i
), "eink display data");
187 jz_gpio_port_direction_output(JZ_GPIO_PORTC(0), 0xffff);
189 gpio_set_value(JZ_GPIO_PORTB(18), 1);
194 static irqreturn_t
n526_eink_busy_irq(int irq
, void *devid
)
196 struct broadsheetfb_par
*par
= devid
;
197 wake_up(&par
->waitq
);
202 static int n526_eink_setup_irq(struct fb_info
*info
)
205 struct broadsheetfb_par
*par
= info
->par
;
207 gpio_request(JZ_GPIO_PORTB(17), "eink busy");
208 gpio_direction_input(JZ_GPIO_PORTB(17));
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
);
214 printk("n526 display: Failed to request busyline irq: %d\n", ret
);
218 static void n526_eink_cleanup(struct broadsheetfb_par
*par
)
222 static 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
,
233 static struct platform_device n526_broadsheet_device
= {
234 .name
= "broadsheetfb",
237 .platform_data
= &broadsheet_pdata
,
241 static struct gpio_keys_button qi_lb60_gpio_keys_buttons
[] = {
250 static 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
,
255 static struct platform_device qi_lb60_gpio_keys
= {
259 .platform_data
= &qi_lb60_gpio_keys_data
,
263 static struct i2c_gpio_platform_data n526_i2c_pdata
= {
264 .sda_pin
= JZ_GPIO_PORTD(23),
265 .scl_pin
= JZ_GPIO_PORTD(24),
270 static struct platform_device n526_i2c_device
= {
274 .platform_data
= &n526_i2c_pdata
,
278 static struct i2c_board_info n526_i2c_board_info
= {
283 static struct platform_device
*jz_platform_devices
[] __initdata
= {
284 &jz4740_usb_ohci_device
,
285 &jz4740_usb_gdt_device
,
289 &jz4740_codec_device
,
292 &n526_broadsheet_device
,
298 static int __init
n526_init_platform_devices(void)
301 jz4740_nand_device
.dev
.platform_data
= &n526_nand_pdata
;
302 jz4740_mmc_device
.dev
.platform_data
= &n526_mmc_pdata
;
304 n526_i2c_board_info
.irq
= gpio_to_irq(JZ_GPIO_PORTD(14)),
305 i2c_register_board_info(0, &n526_i2c_board_info
, 1);
307 return platform_add_devices(jz_platform_devices
,
308 ARRAY_SIZE(jz_platform_devices
));
312 struct jz4740_clock_board_data jz4740_clock_bdata
= {
313 .ext_rate
= 12000000,
317 extern int jz_gpiolib_init(void);
319 static int __init
n526_board_setup(void)
321 if (jz_gpiolib_init())
322 panic("Failed to initalize jz gpio\n");
327 if (n526_init_platform_devices())
328 panic("Failed to initalize platform devices\n");
333 arch_initcall(n526_board_setup
);