1 From c260fa2e5fe9699824190555e075d6c1157d5f36 Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Sat, 24 Apr 2010 17:25:01 +0200
4 Subject: [PATCH] Add n516 board support
7 arch/mips/include/asm/mach-jz4740/board-n516.h | 39 +++
8 arch/mips/jz4740/Kconfig | 4 +
9 arch/mips/jz4740/Makefile | 1 +
10 arch/mips/jz4740/board-n516-display.c | 394 ++++++++++++++++++++++++
11 arch/mips/jz4740/board-n516.c | 203 ++++++++++++
12 5 files changed, 641 insertions(+), 0 deletions(-)
13 create mode 100644 arch/mips/include/asm/mach-jz4740/board-n516.h
14 create mode 100644 arch/mips/jz4740/board-n516-display.c
15 create mode 100644 arch/mips/jz4740/board-n516.c
18 +++ b/arch/mips/include/asm/mach-jz4740/board-n516.h
21 + * linux/include/asm-mips/mach-jz4740/board-n516.h
23 + * JZ4730-based N516 board definition.
25 + * Copyright (C) 2009, Yauhen Kharuzhy <jekhor@gmail.com>
27 + * This program is free software; you can redistribute it and/or modify
28 + * it under the terms of the GNU General Public License as published by
29 + * the Free Software Foundation; either version 2 of the License, or
30 + * (at your option) any later version.
33 +#ifndef __ASM_JZ4740_N516_H__
34 +#define __ASM_JZ4740_N516_H__
36 +#include <asm/mach-jz4740/gpio.h>
41 +#define GPIO_SD_VCC_EN_N JZ_GPIO_PORTD(17)
42 +#define GPIO_SD_CD_N JZ_GPIO_PORTD(7)
43 +#define GPIO_SD_WP JZ_GPIO_PORTD(15)
44 +#define GPIO_USB_DETECT JZ_GPIO_PORTD(19)
45 +#define GPIO_CHARG_STAT_N JZ_GPIO_PORTD(16)
46 +#define GPIO_LED_ENABLE JZ_GPIO_PORTD(28)
47 +#define GPIO_LPC_INT JZ_GPIO_PORTD(14)
48 +#define GPIO_HPHONE_DETECT JZ_GPIO_PORTD(20)
49 +#define GPIO_SPEAKER_ENABLE JZ_GPIO_PORTD(21)
52 +#define GPIO_DISPLAY_RST_L JZ_GPIO_PORTB(18)
53 +#define GPIO_DISPLAY_RDY JZ_GPIO_PORTB(17)
54 +#define GPIO_DISPLAY_STBY JZ_GPIO_PORTC(22)
55 +#define GPIO_DISPLAY_ERR JZ_GPIO_PORTC(23)
56 +#define GPIO_DISPLAY_OFF_N JZ_GPIO_PORTD(1)
58 +#endif /* __ASM_JZ4740_N516_H__ */
59 --- a/arch/mips/jz4740/Kconfig
60 +++ b/arch/mips/jz4740/Kconfig
61 @@ -6,6 +6,10 @@ choice
63 bool "Qi Hardware Ben NanoNote"
66 + bool "Hanvon n516 eBook reader"
72 --- a/arch/mips/jz4740/Makefile
73 +++ b/arch/mips/jz4740/Makefile
74 @@ -12,6 +12,7 @@ obj-$(CONFIG_DEBUG_FS) += clock-debugfs.
75 # board specific support
77 obj-$(CONFIG_JZ4740_QI_LB60) += board-qi_lb60.o
78 +obj-$(CONFIG_JZ4740_N516) += board-n516.o board-n516-display.o
83 +++ b/arch/mips/jz4740/board-n516-display.c
86 + * board-n516-display.c -- Platform device for N516 display
88 + * Copyright (C) 2009, Yauhen Kharuzhy <jekhor@gmail.com>
90 + * This file is subject to the terms and conditions of the GNU General Public
91 + * License. See the file COPYING in the main directory of this archive for
95 +#include <linux/module.h>
96 +#include <linux/kernel.h>
97 +#include <linux/errno.h>
98 +#include <linux/string.h>
99 +#include <linux/delay.h>
100 +#include <linux/interrupt.h>
101 +#include <linux/fb.h>
102 +#include <linux/init.h>
103 +#include <linux/platform_device.h>
104 +#include <linux/irq.h>
105 +#include <linux/gpio.h>
107 +#include <asm/mach-jz4740/jz4740_fb.h>
109 +#include <asm/mach-jz4740/platform.h>
110 +#include <asm/mach-jz4740/board-n516.h>
112 +#include <video/metronomefb.h>
113 +#include <linux/console.h>
115 +static struct fb_videomode n516_fb_modes[] = {
117 + .name = "Metronome 800x600",
123 + .right_margin = 31,
127 + .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
131 +static struct jz4740_fb_platform_data n516_fb_pdata = {
132 + .num_modes = ARRAY_SIZE(n516_fb_modes),
133 + .modes = n516_fb_modes,
135 + .lcd_type = JZ_LCD_TYPE_GENERIC_16_BIT,
138 +struct n516_board_info {
141 + struct fb_info *host_fbinfo; /* the host LCD controller's fbi */
146 +static struct platform_device *n516_device;
147 +static struct n516_board_info n516_board_info;
149 +static int metronome_gpios[] = {
151 + GPIO_DISPLAY_RST_L,
154 +/* GPIO_DISPLAY_OFF_N,*/
157 +static const char *metronome_gpio_names[] = {
162 +/* "Metronone OFF",*/
165 +static int n516_enable_hostfb(bool enable)
168 + int blank = enable ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
170 + acquire_console_sem();
171 + ret = fb_blank(n516_board_info.host_fbinfo, blank);
172 + release_console_sem();
177 +static int n516_init_metronome_gpios(struct metronomefb_par *par)
182 + for (i = 0; i < ARRAY_SIZE(metronome_gpios); ++i) {
183 + ret = gpio_request(metronome_gpios[i], metronome_gpio_names[i]);
188 + gpio_direction_output(GPIO_DISPLAY_OFF_N, 0);
189 + gpio_direction_output(GPIO_DISPLAY_RST_L, 0);
190 + gpio_direction_output(GPIO_DISPLAY_STBY, 0);
191 + gpio_direction_input(GPIO_DISPLAY_RDY);
192 + gpio_direction_input(GPIO_DISPLAY_ERR);
196 + for (--i; i >= 0; --i)
197 + gpio_free(metronome_gpios[i]);
202 +static int n516_share_video_mem(struct fb_info *info)
206 + dev_dbg(&n516_device->dev, "ENTER %s\n", __func__);
207 + dev_dbg(&n516_device->dev, "%s, info->var.xres = %u, info->var.yres = %u\n", __func__, info->var.xres, info->var.yres);
208 + /* rough check if this is our desired fb and not something else */
209 + if ((info->var.xres != n516_fb_pdata.modes[0].xres)
210 + || (info->var.yres != n516_fb_pdata.modes[0].yres))
213 + /* we've now been notified that we have our new fb */
214 + n516_board_info.metromem = info->screen_base;
215 + n516_board_info.host_fbinfo = info;
217 + n516_enable_hostfb(false);
218 + /* try to refcount host drv since we are the consumer after this */
219 + if (!try_module_get(info->fbops->owner))
222 + /* this _add binds metronomefb to n516. metronomefb refcounts n516 */
223 + ret = platform_device_add(n516_device);
226 + platform_device_put(n516_device);
230 + /* request our platform independent driver */
231 + request_module("metronomefb");
236 +static int n516_unshare_video_mem(struct fb_info *info)
238 + dev_dbg(&n516_device->dev, "ENTER %s\n", __func__);
240 + if (info != n516_board_info.host_fbinfo)
243 + module_put(n516_board_info.host_fbinfo->fbops->owner);
247 +static int n516_fb_notifier_callback(struct notifier_block *self,
248 + unsigned long event, void *data)
250 + struct fb_event *evdata = data;
251 + struct fb_info *info = evdata->info;
253 + dev_dbg(&n516_device->dev, "ENTER %s\n", __func__);
255 + if (event == FB_EVENT_FB_REGISTERED)
256 + return n516_share_video_mem(info);
257 + else if (event == FB_EVENT_FB_UNREGISTERED)
258 + return n516_unshare_video_mem(info);
263 +static struct notifier_block n516_fb_notif = {
264 + .notifier_call = n516_fb_notifier_callback,
267 +/* this gets called as part of our init. these steps must be done now so
268 + * that we can use set_pxa_fb_info */
269 +static void __init n516_presetup_fb(void)
274 + /* the frame buffer is divided as follows:
275 + command | CRC | padding
276 + 16kb waveform data | CRC | padding
280 + n516_board_info.fw = 800;
281 + n516_board_info.fh = 624;
283 + /* waveform must be 16k + 2 for checksum */
284 + n516_board_info.wfm_size = roundup(16*1024 + 2, n516_board_info.fw);
286 + padding_size = PAGE_SIZE + (4 * n516_board_info.fw);
288 + /* total is 1 cmd , 1 wfm, padding and image */
289 + totalsize = n516_board_info.fw + n516_board_info.wfm_size;
290 + totalsize += padding_size + (n516_board_info.fw*n516_board_info.fh);
292 + /* save this off because we're manipulating fw after this and
293 + * we'll need it when we're ready to setup the framebuffer */
295 + /* the reason we do this adjustment is because we want to acquire
296 + * more framebuffer memory without imposing custom awareness on the
297 + * underlying driver */
298 + n516_fb_pdata.modes[0].yres = DIV_ROUND_UP(totalsize, n516_board_info.fw);
300 + jz4740_framebuffer_device.dev.platform_data = &n516_fb_pdata;
301 + platform_device_register(&jz4740_framebuffer_device);
304 +/* this gets called by metronomefb as part of its init, in our case, we
305 + * have already completed initial framebuffer init in presetup_fb so we
306 + * can just setup the fb access pointers */
307 +static int n516_setup_fb(struct metronomefb_par *par)
309 + /* metromem was set up by the notifier in share_video_mem so now
310 + * we can use its value to calculate the other entries */
311 + par->metromem_cmd = (struct metromem_cmd *) n516_board_info.metromem;
312 + par->metromem_wfm = n516_board_info.metromem + n516_board_info.fw;
313 + par->metromem_img = par->metromem_wfm + n516_board_info.wfm_size;
314 + par->metromem_img_csum = (u16 *) (par->metromem_img + (n516_board_info.fw * n516_board_info.fh));
315 + par->metromem_dma = n516_board_info.host_fbinfo->fix.smem_start;
320 +static int n516_get_panel_type(void)
325 +static irqreturn_t n516_handle_irq(int irq, void *dev_id)
327 + struct metronomefb_par *par = dev_id;
329 + dev_dbg(&par->pdev->dev, "Metronome IRQ! RDY=%d\n", gpio_get_value(GPIO_DISPLAY_RDY));
330 + wake_up_all(&par->waitq);
332 + return IRQ_HANDLED;
335 +static void n516_power_ctl(struct metronomefb_par *par, int cmd)
338 + case METRONOME_POWER_OFF:
339 + gpio_set_value(GPIO_DISPLAY_OFF_N, 1);
340 + n516_enable_hostfb(false);
342 + case METRONOME_POWER_ON:
343 + gpio_set_value(GPIO_DISPLAY_OFF_N, 0);
344 + n516_enable_hostfb(true);
349 +static int n516_get_rdy(struct metronomefb_par *par)
351 + return gpio_get_value(GPIO_DISPLAY_RDY);
354 +static int n516_get_err(struct metronomefb_par *par)
356 + return gpio_get_value(GPIO_DISPLAY_ERR);
359 +static int n516_setup_irq(struct fb_info *info)
363 + dev_dbg(&n516_device->dev, "ENTER %s\n", __func__);
365 + ret = request_irq(gpio_to_irq(GPIO_DISPLAY_RDY), n516_handle_irq,
366 + IRQF_TRIGGER_RISING,
367 + "n516", info->par);
369 + dev_err(&n516_device->dev, "request_irq failed: %d\n", ret);
374 +static void n516_set_rst(struct metronomefb_par *par, int state)
376 + dev_dbg(&n516_device->dev, "ENTER %s, RDY=%d\n", __func__, gpio_get_value(GPIO_DISPLAY_RDY));
378 + gpio_set_value(GPIO_DISPLAY_RST_L, 1);
380 + gpio_set_value(GPIO_DISPLAY_RST_L, 0);
383 +static void n516_set_stdby(struct metronomefb_par *par, int state)
385 + dev_dbg(&n516_device->dev, "ENTER %s, RDY=%d\n", __func__, gpio_get_value(GPIO_DISPLAY_RDY));
387 + gpio_set_value(GPIO_DISPLAY_STBY, 1);
389 + gpio_set_value(GPIO_DISPLAY_STBY, 0);
392 +static int n516_wait_event(struct metronomefb_par *par)
394 + unsigned long timeout = jiffies + HZ / 20;
396 + dev_dbg(&n516_device->dev, "ENTER1 %s, RDY=%d\n",
397 + __func__, gpio_get_value(GPIO_DISPLAY_RDY));
398 + while (n516_get_rdy(par) && time_before(jiffies, timeout))
401 + dev_dbg(&n516_device->dev, "ENTER2 %s, RDY=%d\n",
402 + __func__, gpio_get_value(GPIO_DISPLAY_RDY));
403 + return wait_event_timeout(par->waitq,
404 + n516_get_rdy(par), HZ * 2) ? 0 : -EIO;
407 +static int n516_wait_event_intr(struct metronomefb_par *par)
409 + unsigned long timeout = jiffies + HZ/20;
411 + dev_dbg(&n516_device->dev, "ENTER1 %s, RDY=%d\n",
412 + __func__, gpio_get_value(GPIO_DISPLAY_RDY));
413 + while (n516_get_rdy(par) && time_before(jiffies, timeout))
416 + dev_dbg(&n516_device->dev, "ENTER2 %s, RDY=%d\n",
417 + __func__, gpio_get_value(GPIO_DISPLAY_RDY));
418 + return wait_event_interruptible_timeout(par->waitq,
419 + n516_get_rdy(par), HZ * 2) ? 0 : -EIO;
422 +static void n516_cleanup(struct metronomefb_par *par)
426 + free_irq(gpio_to_irq(GPIO_DISPLAY_RDY), par);
427 + for (i = 0; i < ARRAY_SIZE(metronome_gpios); ++i)
428 + gpio_free(metronome_gpios[i]);
431 +static struct metronome_board n516_board __initdata = {
432 + .owner = THIS_MODULE,
433 + .power_ctl = n516_power_ctl,
434 + .setup_irq = n516_setup_irq,
435 + .setup_io = n516_init_metronome_gpios,
436 + .setup_fb = n516_setup_fb,
437 + .set_rst = n516_set_rst,
438 + .get_err = n516_get_err,
439 + .get_rdy = n516_get_rdy,
440 + .set_stdby = n516_set_stdby,
441 + .met_wait_event = n516_wait_event,
442 + .met_wait_event_intr = n516_wait_event_intr,
443 + .get_panel_type = n516_get_panel_type,
444 + .cleanup = n516_cleanup,
447 +static int __init n516_init(void)
451 + /* Keep the metronome off, until its driver is loaded */
452 + ret = gpio_request(GPIO_DISPLAY_OFF_N, "Display off");
456 + gpio_direction_output(GPIO_DISPLAY_OFF_N, 1);
458 + /* before anything else, we request notification for any fb
459 + * creation events */
460 + fb_register_client(&n516_fb_notif);
462 + n516_device = platform_device_alloc("metronomefb", -1);
466 + /* the n516_board that will be seen by metronomefb is a copy */
467 + platform_device_add_data(n516_device, &n516_board,
468 + sizeof(n516_board));
470 + n516_presetup_fb();
474 +module_init(n516_init);
476 +MODULE_DESCRIPTION("board driver for n516 display");
477 +MODULE_AUTHOR("Yauhen Kharuzhy");
478 +MODULE_LICENSE("GPL");
480 +++ b/arch/mips/jz4740/board-n516.c
483 + * linux/arch/mips/jz4740/board-516.c
485 + * JZ4740 n516 board setup routines.
487 + * Copyright (c) 2009, Yauhen Kharuzhy <jekhor@gmail.com>
489 + * This program is free software; you can redistribute it and/or modify
490 + * it under the terms of the GNU General Public License as published by
491 + * the Free Software Foundation; either version 2 of the License, or
492 + * (at your option) any later version.
495 +#include <linux/init.h>
496 +#include <linux/sched.h>
497 +#include <linux/ioport.h>
498 +#include <linux/mm.h>
499 +#include <linux/console.h>
500 +#include <linux/delay.h>
501 +#include <linux/i2c.h>
502 +#include <linux/platform_device.h>
503 +#include <linux/mtd/mtd.h>
504 +#include <linux/leds.h>
506 +#include <linux/power_supply.h>
507 +#include <linux/power/gpio-charger.h>
509 +#include <linux/i2c.h>
510 +#include <linux/i2c-gpio.h>
512 +#include <asm/mach-jz4740/jz4740_mmc.h>
513 +#include <asm/mach-jz4740/jz4740_nand.h>
515 +#include <asm/mach-jz4740/board-n516.h>
516 +#include <asm/mach-jz4740/platform.h>
520 +static long n516_panic_blink(long time)
522 + gpio_set_value(GPIO_LED_ENABLE, 1);
524 + gpio_set_value(GPIO_LED_ENABLE, 0);
530 +static void __init board_gpio_setup(void)
532 +/* jz_gpio_enable_pullup(JZ_GPIO_PORTD(23));
533 + jz_gpio_enable_pullup(JZ_GPIO_PORTD(24));*/
536 +static struct i2c_gpio_platform_data n516_i2c_pdata = {
537 + .sda_pin = JZ_GPIO_PORTD(23),
538 + .scl_pin = JZ_GPIO_PORTD(24),
543 +static struct platform_device n516_i2c_device = {
544 + .name = "i2c-gpio",
547 + .platform_data = &n516_i2c_pdata,
551 +static const struct i2c_board_info n516_i2c_board_info[] = {
562 +static struct jz4740_mmc_platform_data n516_mmc_pdata = {
563 + .gpio_card_detect = GPIO_SD_CD_N,
564 + .card_detect_active_low = 1,
565 + .gpio_read_only = -1,
566 + .gpio_power = GPIO_SD_VCC_EN_N,
567 + .power_active_low = 1,
570 +static struct gpio_led n516_leds[] = {
572 + .name = "n516:blue:power",
573 + .gpio = GPIO_LED_ENABLE,
574 + .default_state = LEDS_GPIO_DEFSTATE_ON,
575 + .default_trigger = "nand-disk",
579 +static struct gpio_led_platform_data n516_leds_pdata = {
581 + .num_leds = ARRAY_SIZE(n516_leds),
584 +static struct platform_device n516_leds_device = {
585 + .name = "leds-gpio",
588 + .platform_data = &n516_leds_pdata,
592 +static struct mtd_partition n516_partitions[] = {
593 + { .name = "NAND BOOT partition",
594 + .offset = 0 * 0x100000,
595 + .size = 4 * 0x100000,
597 + { .name = "NAND KERNEL partition",
598 + .offset = 4 * 0x100000,
599 + .size = 4 * 0x100000,
601 + { .name = "NAND ROOTFS partition",
602 + .offset = 8 * 0x100000,
603 + .size = 504 * 0x100000,
607 +static struct nand_ecclayout n516_ecclayout = {
610 + 6, 7, 8, 9, 10, 11, 12, 13, 14,
611 + 15, 16, 17, 18, 19, 20, 21, 22, 23,
612 + 24, 25, 26, 27, 28, 29, 30, 31, 32,
613 + 33, 34, 35, 36, 37, 38, 39, 40, 41,
627 +static struct jz_nand_platform_data n516_nand_pdata = {
628 + .ecc_layout = &n516_ecclayout,
629 + .partitions = n516_partitions,
630 + .num_partitions = ARRAY_SIZE(n516_partitions),
634 +static char *n516_batteries[] = {
638 +static struct gpio_charger_platform_data n516_charger_pdata = {
640 + .type = POWER_SUPPLY_TYPE_USB,
641 + .gpio = GPIO_USB_DETECT,
642 + .gpio_active_low = 1,
643 + .batteries = n516_batteries,
644 + .num_batteries = ARRAY_SIZE(n516_batteries),
647 +static struct platform_device n516_charger_device = {
648 + .name = "gpio-charger",
650 + .platform_data = &n516_charger_pdata,
654 +static struct platform_device *n516_devices[] __initdata = {
655 + &jz4740_nand_device,
657 + &jz4740_mmc_device,
658 + &jz4740_i2s_device,
659 + &jz4740_codec_device,
660 + &jz4740_rtc_device,
661 + &jz4740_udc_device,
663 + &n516_charger_device,
666 +struct jz4740_clock_board_data jz4740_clock_bdata = {
667 + .ext_rate = 12000000,
671 +extern int jz_gpiolib_init(void);
673 +static int n516_setup_platform(void)
675 + board_gpio_setup();
677 + panic_blink = n516_panic_blink;
678 + i2c_register_board_info(0, n516_i2c_board_info, ARRAY_SIZE(n516_i2c_board_info));
679 + jz4740_mmc_device.dev.platform_data = &n516_mmc_pdata;
680 + jz4740_nand_device.dev.platform_data = &n516_nand_pdata;
682 + return platform_add_devices(n516_devices, ARRAY_SIZE(n516_devices));
684 +arch_initcall(n516_setup_platform);