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/power/jz4740-battery.h>
26 #include <linux/mmc/jz4740_mmc.h>
28 #include <video/broadsheetfb.h>
29 #include <linux/delay.h>
30 #include <linux/interrupt.h>
32 #include <linux/input.h>
33 #include <linux/gpio_keys.h>
35 #include <linux/i2c.h>
36 #include <linux/i2c-gpio.h>
39 static struct nand_ecclayout n526_ecclayout
= {
42 6, 7, 8, 9, 10, 11, 12, 13,
43 14, 15, 16, 17, 18, 19, 20, 21,
44 22, 23, 24, 25, 26, 27, 28, 29,
45 30, 31, 32, 33, 34, 35, 36, 37,
54 static struct mtd_partition n526_partitions
[] = {
55 { .name
= "NAND BOOT partition",
56 .offset
= 0 * 0x100000,
59 { .name
= "NAND KERNEL partition",
60 .offset
= 4 * 0x100000,
63 { .name
= "NAND ROOTFS partition",
64 .offset
= 16 * 0x100000,
65 .size
= 498 * 0x100000,
69 static struct jz_nand_platform_data n526_nand_pdata
= {
70 .ecc_layout
= &n526_ecclayout
,
71 .partitions
= n526_partitions
,
72 .num_partitions
= ARRAY_SIZE(n526_partitions
),
78 /*static struct jz_batt_info n526_battery_pdata = {
79 .dc_dect_gpio = GPIO_DC_DETE_N,
80 .usb_dect_gpio = GPIO_USB_DETE,
81 .charg_stat_gpio = GPIO_CHARG_STAT_N,
83 .min_voltag = 3600000,
84 .max_voltag = 4200000,
85 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
89 static struct jz4740_mmc_platform_data n526_mmc_pdata
= {
90 .gpio_card_detect
= JZ_GPIO_PORTD(7),
91 .card_detect_active_low
= 1,
93 .gpio_power
= JZ_GPIO_PORTD(17),
94 .power_active_low
= 1,
97 static struct gpio_led n526_leds
[] = {
99 .name
= "n526:blue:power",
100 .gpio
= JZ_GPIO_PORTD(28),
101 .default_state
= LEDS_GPIO_DEFSTATE_ON
,
105 static struct gpio_led_platform_data n526_leds_pdata
= {
107 .num_leds
= ARRAY_SIZE(n526_leds
),
110 static struct platform_device n526_leds_device
= {
114 .platform_data
= &n526_leds_pdata
,
118 static void __init
board_gpio_setup(void)
120 /* We only need to enable/disable pullup here for pins used in generic
121 * drivers. Everything else is done by the drivers themselfs. */
122 jz_gpio_disable_pullup(JZ_GPIO_PORTD(17));
123 jz_gpio_enable_pullup(JZ_GPIO_PORTD(7));
124 jz_gpio_disable_pullup(JZ_GPIO_PORTC(19));
125 jz_gpio_disable_pullup(JZ_GPIO_PORTC(20));
126 jz_gpio_disable_pullup(JZ_GPIO_PORTC(21));
127 jz_gpio_disable_pullup(JZ_GPIO_PORTC(23));
131 static const int n526_eink_ctrl_gpios
[] = {
138 static void n526_eink_set_ctl(struct broadsheetfb_par
* par
, unsigned char ctrl
, u8
141 gpio_set_value(n526_eink_ctrl_gpios
[ctrl
], value
);
145 static int n526_eink_wait(struct broadsheetfb_par
*par
)
148 wait_event(par
->waitq
, gpio_get_value(JZ_GPIO_PORTB(17)));
153 static u16
n526_eink_get_hdb(struct broadsheetfb_par
*par
)
156 jz_gpio_port_direction_input(JZ_GPIO_PORTC(0), 0xffff);
157 gpio_set_value(JZ_GPIO_PORTC(21), 0);
160 value
= jz_gpio_port_get_value(JZ_GPIO_PORTC(0), 0xffff);
162 gpio_set_value(JZ_GPIO_PORTC(21), 1);
163 jz_gpio_port_direction_output(JZ_GPIO_PORTC(0), 0xffff);
167 static void n526_eink_set_hdb(struct broadsheetfb_par
*par
, u16 value
)
169 jz_gpio_port_set_value(JZ_GPIO_PORTC(0), value
, 0xffff);
172 static int n526_eink_init(struct broadsheetfb_par
*par
)
176 gpio_request(JZ_GPIO_PORTD(1), "display reset?");
177 gpio_direction_output(JZ_GPIO_PORTD(1), 1);
179 gpio_set_value(JZ_GPIO_PORTD(1), 0);
181 gpio_request(JZ_GPIO_PORTB(18), "foobar");
182 gpio_direction_output(JZ_GPIO_PORTB(18), 0);
184 gpio_request(JZ_GPIO_PORTB(29), "foobar");
185 gpio_direction_output(JZ_GPIO_PORTB(29), 1);
188 for(i
= 1; i
< ARRAY_SIZE(n526_eink_ctrl_gpios
); ++i
) {
189 gpio_request(n526_eink_ctrl_gpios
[i
], "foobar");
190 gpio_direction_output(n526_eink_ctrl_gpios
[i
], 0);
193 gpio_request(JZ_GPIO_PORTC(22), "foobar");
194 gpio_direction_input(JZ_GPIO_PORTC(22));
195 gpio_request(JZ_GPIO_PORTC(21), "foobar");
196 gpio_direction_output(JZ_GPIO_PORTC(21), 1);
198 for(i
= 0; i
< 16; ++i
) {
199 gpio_request(JZ_GPIO_PORTC(i
), "display data");
201 jz_gpio_port_direction_output(JZ_GPIO_PORTC(0), 0xffff);
203 gpio_direction_output(JZ_GPIO_PORTB(18), 1);
208 static irqreturn_t
n526_eink_busy_irq(int irq
, void *devid
)
210 struct broadsheetfb_par
*par
= devid
;
211 wake_up(&par
->waitq
);
216 static int n526_eink_setup_irq(struct fb_info
*info
)
219 struct broadsheetfb_par
*par
= info
->par
;
221 gpio_request(JZ_GPIO_PORTB(17), "foobar");
222 gpio_direction_input(JZ_GPIO_PORTB(17));
224 ret
= request_irq(gpio_to_irq(JZ_GPIO_PORTB(17)), n526_eink_busy_irq
,
225 IRQF_DISABLED
| IRQF_TRIGGER_RISING
,
226 "eInk busyline", par
);
228 printk("n526 display: Failed to request busyline irq: %d\n", ret
);
232 static void n526_eink_cleanup(struct broadsheetfb_par
*par
)
236 static struct broadsheet_board broadsheet_pdata
= {
237 .owner
= THIS_MODULE
,
238 .init
= n526_eink_init
,
239 .wait_for_rdy
= n526_eink_wait
,
240 .set_ctl
= n526_eink_set_ctl
,
241 .set_hdb
= n526_eink_set_hdb
,
242 .get_hdb
= n526_eink_get_hdb
,
243 .cleanup
= n526_eink_cleanup
,
244 .setup_irq
= n526_eink_setup_irq
,
247 static struct platform_device n526_broadsheet_device
= {
248 .name
= "broadsheetfb",
251 .platform_data
= &broadsheet_pdata
,
255 static struct gpio_keys_button qi_lb60_gpio_keys_buttons
[] = {
264 static struct gpio_keys_platform_data qi_lb60_gpio_keys_data
= {
265 .nbuttons
= ARRAY_SIZE(qi_lb60_gpio_keys_buttons
),
266 .buttons
= qi_lb60_gpio_keys_buttons
,
269 static struct platform_device qi_lb60_gpio_keys
= {
273 .platform_data
= &qi_lb60_gpio_keys_data
,
277 static struct i2c_gpio_platform_data n526_i2c_pdata
= {
278 .sda_pin
= JZ_GPIO_PORTD(23),
279 .scl_pin
= JZ_GPIO_PORTD(24),
284 static struct platform_device n526_i2c_device
= {
288 .platform_data
= &n526_i2c_pdata
,
292 static struct i2c_board_info n526_i2c_board_info
= {
298 static struct platform_device
*jz_platform_devices
[] __initdata
= {
299 &jz4740_usb_ohci_device
,
300 &jz4740_usb_gdt_device
,
304 &jz4740_codec_device
,
307 &n526_broadsheet_device
,
313 static int __init
n526_init_platform_devices(void)
316 jz4740_nand_device
.dev
.platform_data
= &n526_nand_pdata
;
317 /* jz4740_battery_device.dev.platform_data = &n526_battery_pdata;*/
318 jz4740_mmc_device
.dev
.platform_data
= &n526_mmc_pdata
;
320 n526_i2c_board_info
.irq
= gpio_to_irq(JZ_GPIO_PORTD(14)),
321 i2c_register_board_info(0, &n526_i2c_board_info
, 1);
323 return platform_add_devices(jz_platform_devices
,
324 ARRAY_SIZE(jz_platform_devices
));
329 extern int jz_gpiolib_init(void);
330 extern int jz_init_clocks(unsigned long extal
);
332 static int __init
n526_board_setup(void)
334 if (jz_gpiolib_init())
335 panic("Failed to initalize jz gpio\n");
336 jz_init_clocks(12000000);
340 if (n526_init_platform_devices())
341 panic("Failed to initalize platform devices\n");
346 arch_initcall(n526_board_setup
);