.code = EV_MENU,
.gpio = RK29_PIN6_PA3, // PA0--> PA3: home -> menu
.active_low = PRESS_LEV_LOW,
+ .wakeup = 0,
},
{
.desc = "vol+",
.code = KEY_VOLUMEUP,
.gpio = RK29_PIN6_PA2,
.active_low = PRESS_LEV_LOW,
+ .wakeup = 0,
},
{
.desc = "vol-",
.code = KEY_VOLUMEDOWN,
.gpio = RK29_PIN6_PA1,
.active_low = PRESS_LEV_LOW,
+ .wakeup = 0,
},
{
.desc = "home",
.code = KEY_HOME,
.gpio = RK29_PIN6_PA5, //PA3 --> PA5
.active_low = PRESS_LEV_LOW,
- },
- {
- .desc = "search",
- .code = KEY_SEARCH,
- .gpio = RK29_PIN6_PA4,
- .active_low = PRESS_LEV_LOW,
+ .wakeup = 0,
},
{
.desc = "esc",
.code = KEY_BACK,
.gpio = RK29_PIN6_PA0, //PA5-->PA0: menu-> esc
.active_low = PRESS_LEV_LOW,
- },
- {
- .desc = "sensor",
- .code = KEY_CAMERA,
- .gpio = RK29_PIN6_PA6,
- .active_low = PRESS_LEV_LOW,
+ .wakeup = 0,
},
{
.desc = "play",
.code = KEY_POWER,
.gpio = RK29_PIN6_PA7,
.active_low = PRESS_LEV_LOW,
- //.code_long_press = EV_ENCALL,
.wakeup = 1,
},
-#if 0
- {
- .desc = "vol+",
- .code = KEY_VOLUMEDOWN,
- .adc_value = 95,
- .gpio = INVALID_GPIO,
- .active_low = PRESS_LEV_LOW,
- },
- {
- .desc = "vol-",
- .code = KEY_VOLUMEUP,
- .adc_value = 249,
- .gpio = INVALID_GPIO,
- .active_low = PRESS_LEV_LOW,
- },
- {
- .desc = "menu",
- .code = EV_MENU,
- .adc_value = 406,
- .gpio = INVALID_GPIO,
- .active_low = PRESS_LEV_LOW,
- },
- {
- .desc = "home",
- .code = KEY_HOME,
- .code_long_press = KEY_F4,
- .adc_value = 561,
- .gpio = INVALID_GPIO,
- .active_low = PRESS_LEV_LOW,
- },
- {
- .desc = "esc",
- .code = KEY_ESC,
- .adc_value = 726,
- .gpio = INVALID_GPIO,
- .active_low = PRESS_LEV_LOW,
- },
- {
- .desc = "adkey6",
- .code = KEY_BACK,
- .code_long_press = EV_ENCALL,
- .adc_value = 899,
- .gpio = INVALID_GPIO,
- .active_low = PRESS_LEV_LOW,
- },
-#endif
};
struct rk29_keys_platform_data rk29_keys_pdata = {
.buttons = key_button,
* backlight devices
* author: nzy@rock-chips.com
*****************************************************************************************/
-#ifdef CONFIG_BACKLIGHT_RK29_BL
+#ifdef CONFIG_BACKLIGHT_RK29_NEWTON_BL
/*
GPIO1B5_PWM0_NAME, GPIO1L_PWM0
GPIO5D2_PWM1_UART1SIRIN_NAME, GPIO5H_PWM1
.pwm_resume = rk29_backlight_pwm_resume,
.min_brightness = BACKLIGHT_MINVALUE,
};
+struct platform_device rk29_device_backlight = {
+ .name = "rk29_backlight",
+ .id = -1,
+ .dev = {
+ .platform_data = &rk29_bl_info,
+ }
+};
#endif
/*****************************************************************************************
* pwm voltage regulator devices
};
#endif
-#ifdef CONFIG_KEYS_RK29
+#ifdef CONFIG_KEYS_RK29_NEWTON
extern struct rk29_keys_platform_data rk29_keys_pdata;
static struct platform_device rk29_device_keys = {
.name = "rk29-keypad",
&rk29_device_iis_8ch,
#endif
-#ifdef CONFIG_KEYS_RK29
+#ifdef CONFIG_KEYS_RK29_NEWTON
&rk29_device_keys,
#endif
#ifdef CONFIG_SDMMC0_RK29
&rk29_device_fb,
&rk29_device_dma_cpy,
#endif
-#ifdef CONFIG_BACKLIGHT_RK29_BL
+#ifdef CONFIG_BACKLIGHT_RK29_NEWTON_BL
&rk29_device_backlight,
#endif
#ifdef CONFIG_RK29_VMAC
help
rk29 keyboard drivers(gpio and adc)
+config KEYS_RK29_NEWTON
+ tristate "rk29 newton keyboard"
+ depends on ARCH_RK29
+ default y
+ help
+ rk29 newton keyboard drivers(gpio and adc)
+
config SYNAPTICS_SO340010
tristate "Synaptics So340010 TouchPad KEY"
depends on I2C
# Each configuration option enables a list of files.
-obj-$(CONFIG_KEYS_RK29) += rk29_keys.o
+obj-$(CONFIG_KEYS_RK29) += rk29_keys.o
+obj-$(CONFIG_KEYS_RK29_NEWTON) += rk29_newton_keys.o
obj-$(CONFIG_KEYBOARD_AAED2000) += aaed2000_kbd.o
obj-$(CONFIG_KEYBOARD_ADP5588) += adp5588-keys.o
obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o
obj-$(CONFIG_KEYBOARD_CORGI) += corgikbd.o
obj-$(CONFIG_KEYBOARD_EP93XX) += ep93xx_keypad.o
obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o
-obj-$(CONFIG_KEYBOARD_WM831X_GPIO) += wm831x_gpio_keys.o
+obj-$(CONFIG_KEYBOARD_WM831X_GPIO) += wm831x_gpio_keys.o
obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o
obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o
obj-$(CONFIG_KEYBOARD_HP6XX) += jornada680_kbd.o
--- /dev/null
+/*
+ * Driver for keys on GPIO lines capable of generating interrupts.
+ *
+ * Copyright 2005 Phil Blundell
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+
+#include <linux/init.h>
+#include <linux/fs.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/sched.h>
+#include <linux/pm.h>
+#include <linux/sysctl.h>
+#include <linux/proc_fs.h>
+#include <linux/delay.h>
+#include <linux/platform_device.h>
+#include <linux/input.h>
+#include <linux/adc.h>
+#include <linux/earlysuspend.h>
+#include <asm/gpio.h>
+#include <mach/key.h>
+#include <mach/board.h>
+
+
+#define EMPTY_ADVALUE 950
+#define DRIFT_ADVALUE 70
+#define INVALID_ADVALUE 10
+
+
+#if 0
+#define key_dbg(bdata, format, arg...) \
+ dev_printk(KERN_INFO , &bdata->input->dev , format , ## arg)
+#else
+#define key_dbg(bdata, format, arg...)
+#endif
+
+struct rk29_button_data {
+ int state;
+ int long_press_count;
+ struct rk29_keys_button *button;
+ struct input_dev *input;
+ struct timer_list timer;
+};
+
+struct rk29_keys_drvdata {
+ int nbuttons;
+ int result;
+ struct input_dev *input;
+ struct adc_client *client;
+ struct timer_list timer;
+ struct rk29_button_data data[0];
+};
+
+static struct input_dev *input_dev;
+static struct early_suspend newton_key_power;
+static int suspend = 0;
+void rk29_send_power_key(int state)
+{
+ if (!input_dev)
+ return;
+ if(state)
+ {
+ input_report_key(input_dev, KEY_POWER, 1);
+ input_sync(input_dev);
+ }
+ else
+ {
+ input_report_key(input_dev, KEY_POWER, 0);
+ input_sync(input_dev);
+ }
+}
+
+void rk28_send_wakeup_key(void)
+{
+ if (!input_dev)
+ return;
+
+ input_report_key(input_dev, KEY_WAKEUP, 1);
+ input_sync(input_dev);
+ input_report_key(input_dev, KEY_WAKEUP, 0);
+ input_sync(input_dev);
+}
+
+static void keys_long_press_timer(unsigned long _data)
+{
+ int state;
+ struct rk29_button_data *bdata = (struct rk29_button_data *)_data;
+ struct rk29_keys_button *button = bdata->button;
+ struct input_dev *input = bdata->input;
+ unsigned int type = EV_KEY;
+ if(button->gpio != INVALID_GPIO )
+ state = !!((gpio_get_value(button->gpio) ? 1 : 0) ^ button->active_low);
+ else
+ state = !!button->adc_state;
+ if(state) {
+ if(bdata->long_press_count != 0) {
+ if(bdata->long_press_count % (LONG_PRESS_COUNT+ONE_SEC_COUNT) == 0){
+ key_dbg(bdata, "%skey[%s]: report ev[%d] state[0]\n",
+ (button->gpio == INVALID_GPIO)?"ad":"io", button->desc, button->code_long_press);
+ input_event(input, type, button->code_long_press, 0);
+ input_sync(input);
+ }
+ else if(bdata->long_press_count%LONG_PRESS_COUNT == 0) {
+ key_dbg(bdata, "%skey[%s]: report ev[%d] state[1]\n",
+ (button->gpio == INVALID_GPIO)?"ad":"io", button->desc, button->code_long_press);
+ input_event(input, type, button->code_long_press, 1);
+ input_sync(input);
+ }
+ }
+ bdata->long_press_count++;
+ mod_timer(&bdata->timer,
+ jiffies + msecs_to_jiffies(DEFAULT_DEBOUNCE_INTERVAL));
+ }
+ else {
+ if(bdata->long_press_count <= LONG_PRESS_COUNT) {
+ bdata->long_press_count = 0;
+ key_dbg(bdata, "%skey[%s]: report ev[%d] state[1], report ev[%d] state[0]\n",
+ (button->gpio == INVALID_GPIO)?"ad":"io", button->desc, button->code, button->code);
+ input_event(input, type, button->code, 1);
+ input_sync(input);
+ input_event(input, type, button->code, 0);
+ input_sync(input);
+ }
+ else if(bdata->state != state) {
+ key_dbg(bdata, "%skey[%s]: report ev[%d] state[0]\n",
+ (button->gpio == INVALID_GPIO)?"ad":"io", button->desc, button->code_long_press);
+ input_event(input, type, button->code_long_press, 0);
+ input_sync(input);
+ }
+ }
+ bdata->state = state;
+}
+static void keys_timer(unsigned long _data)
+{
+ int state;
+ struct rk29_button_data *bdata = (struct rk29_button_data *)_data;
+ struct rk29_keys_button *button = bdata->button;
+ struct input_dev *input = bdata->input;
+ unsigned int type = EV_KEY;
+
+ if((suspend)&&(!button->wakeup))
+ return;
+ if(button->gpio != INVALID_GPIO)
+ state = !!((gpio_get_value(button->gpio) ? 1 : 0) ^ button->active_low);
+ else
+ state = !!button->adc_state;
+ if(bdata->state != state) {
+ bdata->state = state;
+ key_dbg(bdata, "%skey[%s]: report ev[%d] state[%d]\n",
+ (button->gpio == INVALID_GPIO)?"ad":"io", button->desc, button->code, bdata->state);
+ input_event(input, type, button->code, bdata->state);
+ input_sync(input);
+ }
+ if(state)
+ mod_timer(&bdata->timer,
+ jiffies + msecs_to_jiffies(DEFAULT_DEBOUNCE_INTERVAL));
+}
+
+static irqreturn_t keys_isr(int irq, void *dev_id)
+{
+ struct rk29_button_data *bdata = dev_id;
+ struct rk29_keys_button *button = bdata->button;
+ BUG_ON(irq != gpio_to_irq(button->gpio));
+ bdata->long_press_count = 0;
+ mod_timer(&bdata->timer,
+ jiffies + msecs_to_jiffies(DEFAULT_DEBOUNCE_INTERVAL));
+ return IRQ_HANDLED;
+}
+
+static int keys_suspend(struct device *dev)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+ struct rk29_keys_platform_data *pdata = pdev->dev.platform_data;
+ int i;
+
+ if (device_may_wakeup(&pdev->dev)) {
+ for (i = 0; i < pdata->nbuttons; i++) {
+ struct rk29_keys_button *button = &pdata->buttons[i];
+ int irq = gpio_to_irq(button->gpio);
+ enable_irq_wake(irq);
+ }
+ }
+ suspend = 1;
+ return 0;
+}
+
+static int keys_resume(struct device *dev)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+ struct rk29_keys_platform_data *pdata = pdev->dev.platform_data;
+ int i;
+
+ if (device_may_wakeup(&pdev->dev)) {
+ for (i = 0; i < pdata->nbuttons; i++) {
+ struct rk29_keys_button *button = &pdata->buttons[i];
+ if (button->wakeup) {
+ int irq = gpio_to_irq(button->gpio);
+ disable_irq_wake(irq);
+ }
+ }
+ }
+ suspend = 0;
+ return 0;
+}
+
+static void newton_key_early_suspend(struct early_suspend *h)
+{
+ dev_info(&input_dev->dev, "newton_key_early_suspend!\n");
+ keys_suspend(&input_dev->dev);
+}
+
+static void newton_key_last_resume(struct early_suspend *h)
+{
+ dev_info(&input_dev->dev, "newton_key_last_resume!\n");
+ keys_resume(&input_dev->dev);
+}
+
+static int __devinit keys_probe(struct platform_device *pdev)
+{
+ struct rk29_keys_platform_data *pdata = pdev->dev.platform_data;
+ struct rk29_keys_drvdata *ddata;
+ struct input_dev *input;
+ int i, error = 0;
+ int wakeup = 0;
+
+ if(!pdata)
+ return -EINVAL;
+
+ ddata = kzalloc(sizeof(struct rk29_keys_drvdata) +
+ pdata->nbuttons * sizeof(struct rk29_button_data),
+ GFP_KERNEL);
+ input = input_allocate_device();
+ if (!ddata || !input) {
+ error = -ENOMEM;
+ goto fail0;
+ }
+
+ platform_set_drvdata(pdev, ddata);
+
+ input->name = pdev->name;
+ input->phys = "gpio-keys/input0";
+ input->dev.parent = &pdev->dev;
+
+ input->id.bustype = BUS_HOST;
+ input->id.vendor = 0x0001;
+ input->id.product = 0x0001;
+ input->id.version = 0x0100;
+
+ /* Enable auto repeat feature of Linux input subsystem */
+ if (pdata->rep)
+ __set_bit(EV_REP, input->evbit);
+ ddata->nbuttons = pdata->nbuttons;
+ ddata->input = input;
+
+ for (i = 0; i < pdata->nbuttons; i++) {
+ struct rk29_keys_button *button = &pdata->buttons[i];
+ struct rk29_button_data *bdata = &ddata->data[i];
+ int irq;
+ unsigned int type = EV_KEY;
+
+ bdata->input = input;
+ bdata->button = button;
+ if(button->code_long_press)
+ setup_timer(&bdata->timer,
+ keys_long_press_timer, (unsigned long)bdata);
+ else if(button->code)
+ setup_timer(&bdata->timer,
+ keys_timer, (unsigned long)bdata);
+ if(button->gpio != INVALID_GPIO) {
+ error = gpio_request(button->gpio, button->desc ?: "keys");
+ if (error < 0) {
+ pr_err("gpio-keys: failed to request GPIO %d,"
+ " error %d\n", button->gpio, error);
+ goto fail2;
+ }
+
+ error = gpio_direction_input(button->gpio);
+ if (error < 0) {
+ pr_err("gpio-keys: failed to configure input"
+ " direction for GPIO %d, error %d\n",
+ button->gpio, error);
+ gpio_free(button->gpio);
+ goto fail2;
+ }
+ irq = gpio_to_irq(button->gpio);
+ if (irq < 0) {
+ error = irq;
+ pr_err("gpio-keys: Unable to get irq number"
+ " for GPIO %d, error %d\n",
+ button->gpio, error);
+ gpio_free(button->gpio);
+ goto fail2;
+ }
+
+ error = request_irq(irq, keys_isr,
+ (button->active_low)?IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING,
+ button->desc ? button->desc : "keys",
+ bdata);
+ if (error) {
+ pr_err("gpio-keys: Unable to claim irq %d; error %d\n",
+ irq, error);
+ gpio_free(button->gpio);
+ goto fail2;
+ }
+ }
+ if (button->wakeup)
+ wakeup = 1;
+
+ input_set_capability(input, type, button->code);
+ }
+
+ input_set_capability(input, EV_KEY, KEY_WAKEUP);
+
+ error = input_register_device(input);
+ if (error) {
+ pr_err("gpio-keys: Unable to register input device, "
+ "error: %d\n", error);
+ goto fail2;
+ }
+
+ device_init_wakeup(&pdev->dev, wakeup);
+
+ input_dev = input;
+
+ newton_key_power.suspend = newton_key_early_suspend;
+ newton_key_power.resume = newton_key_last_resume;
+ newton_key_power.level = 0x2;
+ register_early_suspend(&newton_key_power);
+ return error;
+
+ fail2:
+ while (--i >= 0) {
+ free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
+ del_timer_sync(&ddata->data[i].timer);
+ gpio_free(pdata->buttons[i].gpio);
+ }
+ platform_set_drvdata(pdev, NULL);
+ fail0:
+ input_free_device(input);
+ kfree(ddata);
+
+ return error;
+}
+
+static int __devexit keys_remove(struct platform_device *pdev)
+{
+ struct rk29_keys_platform_data *pdata = pdev->dev.platform_data;
+ struct rk29_keys_drvdata *ddata = platform_get_drvdata(pdev);
+ struct input_dev *input = ddata->input;
+ int i;
+
+ input_dev = NULL;
+ device_init_wakeup(&pdev->dev, 0);
+
+ for (i = 0; i < pdata->nbuttons; i++) {
+ int irq = gpio_to_irq(pdata->buttons[i].gpio);
+ free_irq(irq, &ddata->data[i]);
+ del_timer_sync(&ddata->data[i].timer);
+ gpio_free(pdata->buttons[i].gpio);
+ }
+ if(pdata->chn >= 0 && ddata->client);
+ adc_unregister(ddata->client);
+ input_unregister_device(input);
+
+ return 0;
+}
+
+
+
+static struct platform_driver keys_device_driver = {
+ .probe = keys_probe,
+ .remove = __devexit_p(keys_remove),
+ .driver = {
+ .name = "rk29-keypad",
+ .owner = THIS_MODULE,
+ }
+};
+
+static int __init keys_init(void)
+{
+ return platform_driver_register(&keys_device_driver);
+}
+
+static void __exit keys_exit(void)
+{
+ platform_driver_unregister(&keys_device_driver);
+}
+
+module_init(keys_init);
+module_exit(keys_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Phil Blundell <pb@handhelds.org>");
+MODULE_DESCRIPTION("Keyboard driver for CPU GPIOs");
+MODULE_ALIAS("platform:gpio-keys");
#include <media/soc_camera.h> /* ddl@rock-chips.com : camera support */
#include <mach/vpu_mem.h>
#include <mach/sram.h>
-#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
-static struct early_suspend ft5406_early_suspend;
-#endif
+static struct early_suspend ft5406_power;
return 0;
}
+static void ft5406_suspend_early(struct early_suspend *h)
+{
+ dev_info(&this_client->dev, "ft5406_suspend_early!\n");
+ ft5406_suspend(this_client,PMSG_SUSPEND);
+}
+
+static void ft5406_resume_early(struct early_suspend *h)
+{
+ dev_info(&this_client->dev, "ft5406_resume_early!\n");
+ ft5406_resume(this_client);
+}
static int __devexit ft5406_remove(struct i2c_client *client)
{
struct ft5x0x_ts_data *ft5x0x_ts = i2c_get_clientdata(client);
cancel_work_sync(&ft5x0x_ts->pen_event_work);
destroy_workqueue(ft5x0x_ts->ts_workqueue);
i2c_set_clientdata(client, NULL);
-#ifdef CONFIG_HAS_EARLYSUSPEND
- unregister_early_suspend(&ft5406_early_suspend);
-#endif
+ unregister_early_suspend(&ft5406_power);
this_client = NULL;
return 0;
}
}
i2c_set_clientdata(client, ft5x0x_ts);
-#if 0//def CONFIG_HAS_EARLYSUSPEND
- ft5406_early_suspend.suspend =ft5406_ts_suspend;
- ft5406_early_suspend.resume =ft5406_ts_resume;
- ft5406_early_suspend.level = 0x2;
- register_early_suspend(&ft5406_early_suspend);
-#endif
+ ft5406_power.suspend =ft5406_suspend_early;
+ ft5406_power.resume =ft5406_resume_early;
+ ft5406_power.level = 0x2;
+ register_early_suspend(&ft5406_power);
buf_w[0] = 6;
err = ft5406_set_regs(client,0x88,buf_w,1);
},
.id_table = ft5406_idtable,
.probe = ft5406_probe,
- .suspend = ft5406_suspend,
- .resume = ft5406_resume,
.remove = __devexit_p(ft5406_remove),
};
unsigned int oldcrc32 = 0xFFFFFFFF;
unsigned int ulPolynomial = 0x04c11db7;
struct i2c_client * i2c_connect_client = NULL;
+static struct early_suspend gt819_power;
static u8 gt819_fw[]=
{
#include "gt819_fw.i"
return 0;
}
+static void gt819_early_suspend(struct early_suspend *h)
+{
+ dev_info(&i2c_connect_client->dev, "gt819_early_suspend!\n");
+ gt819_suspend(i2c_connect_client,PMSG_SUSPEND);
+}
+
+static void gt819_early_resume(struct early_suspend *h)
+{
+ dev_info(&i2c_connect_client->dev, "gt819_resume_early!\n");
+ gt819_resume(i2c_connect_client);
+}
/*******************************************************
Description:
remove_proc_entry("goodix-update", NULL);
#endif
//goodix_debug_sysfs_deinit();
- gpio_direction_input(ts->irq_gpio);
- gpio_free(ts->irq_gpio);
- free_irq(client->irq, ts);
+ gpio_direction_input(ts->irq_gpio);
+ gpio_free(ts->irq_gpio);
+ free_irq(client->irq, ts);
if(ts->goodix_wq)
destroy_workqueue(ts->goodix_wq);
dev_notice(&client->dev,"The driver is removing...\n");
i2c_set_clientdata(client, NULL);
input_unregister_device(ts->input_dev);
+ unregister_early_suspend(>819_power);
+ i2c_connect_client = 0;
kfree(ts);
return 0;
}
}
i2c_set_clientdata(client, ts);
+ gt819_power.suspend = gt819_early_suspend;
+ gt819_power.resume = gt819_early_resume;
+ gt819_power.level = 0x2;
+ register_early_suspend(>819_power);
return 0;
i2c_set_clientdata(client, NULL);
input_unregister_device(ts->input_dev);
static struct i2c_driver gt819_driver = {
.probe = gt819_probe,
.remove = gt819_remove,
- .suspend = gt819_suspend,
- .resume = gt819_resume,
.id_table = gt819_id,
.driver = {
.name = GOODIX_I2C_NAME,
help
rk29 backlight support.
+config BACKLIGHT_RK29_NEWTON_BL
+ bool "rk29 newton backlight driver"
+ depends on BACKLIGHT_CLASS_DEVICE && ARCH_RK29
+ default y
+ help
+ rk29 newton backlight support.
+
config FIH_TOUCHKEY_LED
bool "fih touch key led driver"
depends on BACKLIGHT_CLASS_DEVICE && ARCH_RK29
obj-$(CONFIG_BACKLIGHT_ADP5520) += adp5520_bl.o
obj-$(CONFIG_BACKLIGHT_RK2818_BL) += rk2818_backlight.o
obj-$(CONFIG_BACKLIGHT_RK29_BL) += rk29_backlight.o
+obj-$(CONFIG_BACKLIGHT_RK29_NEWTON_BL) += rk29_newton_backlight.o
obj-$(CONFIG_BACKLIGHT_AW9364) += aw9364_bl.o
obj-$(CONFIG_FIH_TOUCHKEY_LED) += fih_touchkey_led.o
obj-$(CONFIG_BUTTON_LIGHT) += rk29_buttonlight.o
--- /dev/null
+/* drivers/video/backlight/rk29_backlight.c
+ *
+ * Copyright (C) 2009-2011 Rockchip Corporation.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/err.h>
+#include <linux/delay.h>
+#include <linux/platform_device.h>
+#include <linux/backlight.h>
+#include <linux/fb.h>
+#include <linux/clk.h>
+
+#include <linux/earlysuspend.h>
+#include <asm/io.h>
+#include <mach/rk29_iomap.h>
+#include <mach/board.h>
+
+#include "rk2818_backlight.h"
+
+/*
+ * Debug
+ */
+#if 0
+#define DBG(x...) printk(KERN_INFO x)
+#else
+#define DBG(x...)
+#endif
+
+
+#define write_pwm_reg(id, addr, val) __raw_writel(val, addr+(RK29_PWM_BASE+id*0x10))
+#define read_pwm_reg(id, addr) __raw_readl(addr+(RK29_PWM_BASE+id*0x10))
+
+static struct clk *pwm_clk;
+static struct backlight_device *rk29_bl;
+static int suspend_flag = 0;
+
+static int rk29_bl_update_status(struct backlight_device *bl)
+{
+ u32 divh,div_total;
+ struct rk29_bl_info *rk29_bl_info = bl_get_data(bl);
+ u32 id = rk29_bl_info->pwm_id;
+ u32 ref = rk29_bl_info->bl_ref;
+
+ if (suspend_flag)
+ return 0;
+
+ if (bl->props.brightness < rk29_bl_info->min_brightness) /*avoid can't view screen when close backlight*/
+ bl->props.brightness = rk29_bl_info->min_brightness;
+
+ div_total = read_pwm_reg(id, PWM_REG_LRC);
+ if (ref) {
+ divh = div_total*(bl->props.brightness)/BL_STEP;
+ } else {
+ divh = div_total*(BL_STEP-bl->props.brightness)/BL_STEP;
+ }
+ write_pwm_reg(id, PWM_REG_HRC, divh);
+
+ DBG(">>>%s-->%d brightness = %d, div_total = %d, divh = %d\n",__FUNCTION__,__LINE__,bl->props.brightness, div_total, divh);
+ return 0;
+}
+
+static int rk29_bl_get_brightness(struct backlight_device *bl)
+{
+ u32 divh,div_total;
+ struct rk29_bl_info *rk29_bl_info = bl_get_data(bl);
+ u32 id = rk29_bl_info->pwm_id;
+ u32 ref = rk29_bl_info->bl_ref;
+
+ div_total = read_pwm_reg(id, PWM_REG_LRC);
+ divh = read_pwm_reg(id, PWM_REG_HRC);
+
+ if (!div_total)
+ return 0;
+
+ if (ref) {
+ return BL_STEP*divh/div_total;
+ } else {
+ return BL_STEP-(BL_STEP*divh/div_total);
+ }
+}
+
+static struct backlight_ops rk29_bl_ops = {
+ .update_status = rk29_bl_update_status,
+ .get_brightness = rk29_bl_get_brightness,
+};
+
+static void rk29_backlight_work_func(struct work_struct *work)
+{
+ suspend_flag = 0;
+ rk29_bl_update_status(rk29_bl);
+}
+static DECLARE_DELAYED_WORK(rk29_backlight_work, rk29_backlight_work_func);
+
+#ifdef CONFIG_HAS_EARLYSUSPEND
+static void rk29_bl_suspend(struct early_suspend *h)
+{
+ struct rk29_bl_info *rk29_bl_info = bl_get_data(rk29_bl);
+ int brightness = rk29_bl->props.brightness;
+
+ cancel_delayed_work_sync(&rk29_backlight_work);
+
+ if (rk29_bl->props.brightness) {
+ rk29_bl->props.brightness = 0;
+ rk29_bl_update_status(rk29_bl);
+ rk29_bl->props.brightness = brightness;
+ }
+
+ if (!suspend_flag) {
+ clk_disable(pwm_clk);
+ if (rk29_bl_info->pwm_suspend)
+ rk29_bl_info->pwm_suspend();
+ }
+
+ suspend_flag = 1;
+}
+
+static void rk29_bl_resume(struct early_suspend *h)
+{
+ struct rk29_bl_info *rk29_bl_info = bl_get_data(rk29_bl);
+ DBG("%s : %s\n", __FILE__, __FUNCTION__);
+
+ if (rk29_bl_info->pwm_resume)
+ rk29_bl_info->pwm_resume();
+
+ clk_enable(pwm_clk);
+
+ schedule_delayed_work(&rk29_backlight_work, msecs_to_jiffies(rk29_bl_info->delay_ms));
+}
+
+static struct early_suspend bl_early_suspend = {
+ .suspend = rk29_bl_suspend,
+ .resume = rk29_bl_resume,
+ .level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 1,
+};
+#endif
+
+static int rk29_backlight_probe(struct platform_device *pdev)
+{
+ int ret = 0;
+ struct rk29_bl_info *rk29_bl_info = pdev->dev.platform_data;
+ u32 id = rk29_bl_info->pwm_id;
+ u32 divh, div_total;
+ unsigned long pwm_clk_rate;
+
+ if (rk29_bl) {
+ DBG(KERN_CRIT "%s: backlight device register has existed \n",
+ __func__);
+ return -EEXIST;
+ }
+
+ if (!rk29_bl_info->delay_ms)
+ rk29_bl_info->delay_ms = 100;
+
+ if (rk29_bl_info->min_brightness < 0 || rk29_bl_info->min_brightness > BL_STEP)
+ rk29_bl_info->min_brightness = 52;
+
+ if (rk29_bl_info && rk29_bl_info->io_init) {
+ rk29_bl_info->io_init();
+ }
+
+ rk29_bl = backlight_device_register("rk28_bl", &pdev->dev, rk29_bl_info, &rk29_bl_ops);
+ if (!rk29_bl) {
+ DBG(KERN_CRIT "%s: backlight device register error\n",
+ __func__);
+ return -ENODEV;
+ }
+
+ pwm_clk = clk_get(NULL, "pwm");
+ if (IS_ERR(pwm_clk)) {
+ printk(KERN_ERR "failed to get pwm clock source\n");
+ return -ENODEV;
+ }
+ pwm_clk_rate = clk_get_rate(pwm_clk);
+ div_total = pwm_clk_rate / PWM_APB_PRE_DIV;
+
+ div_total >>= (1 + (PWM_DIV >> 9));
+ div_total = (div_total) ? div_total : 1;
+
+ if(rk29_bl_info->bl_ref) {
+ divh = 0;
+ } else {
+ divh = div_total;
+ }
+
+ clk_enable(pwm_clk);
+ write_pwm_reg(id, PWM_REG_CTRL, PWM_DIV|PWM_RESET);
+ write_pwm_reg(id, PWM_REG_LRC, div_total);
+ write_pwm_reg(id, PWM_REG_HRC, divh);
+ write_pwm_reg(id, PWM_REG_CNTR, 0x0);
+ write_pwm_reg(id, PWM_REG_CTRL, PWM_DIV|PWM_ENABLE|PWM_TIME_EN);
+
+ rk29_bl->props.power = FB_BLANK_UNBLANK;
+ rk29_bl->props.fb_blank = FB_BLANK_UNBLANK;
+ rk29_bl->props.max_brightness = BL_STEP;
+ rk29_bl->props.brightness = BL_STEP / 2;
+
+ if (rk29_bl_info && rk29_bl_info->pwm_resume) {
+ rk29_bl_info->pwm_resume();
+ }
+
+ schedule_delayed_work(&rk29_backlight_work, msecs_to_jiffies(rk29_bl_info->delay_ms));
+
+ register_early_suspend(&bl_early_suspend);
+
+ printk("RK29 Backlight Driver Initialized.\n");
+ return ret;
+}
+
+static int rk29_backlight_remove(struct platform_device *pdev)
+{
+ struct rk29_bl_info *rk29_bl_info = pdev->dev.platform_data;
+
+ if (rk29_bl) {
+ backlight_device_unregister(rk29_bl);
+ unregister_early_suspend(&bl_early_suspend);
+ clk_disable(pwm_clk);
+ clk_put(pwm_clk);
+ if (rk29_bl_info && rk29_bl_info->io_deinit) {
+ rk29_bl_info->io_deinit();
+ }
+ return 0;
+ } else {
+ DBG(KERN_CRIT "%s: no backlight device has registered\n",
+ __func__);
+ return -ENODEV;
+ }
+}
+
+static void rk29_backlight_shutdown(struct platform_device *pdev)
+{
+ struct rk29_bl_info *rk29_bl_info = pdev->dev.platform_data;
+
+ rk29_bl->props.brightness >>= 1;
+ rk29_bl_update_status(rk29_bl);
+ mdelay(100);
+
+ rk29_bl->props.brightness >>= 1;
+ rk29_bl_update_status(rk29_bl);
+ mdelay(100);
+
+ rk29_bl->props.brightness = 0;
+ rk29_bl_update_status(rk29_bl);
+
+ if (rk29_bl_info && rk29_bl_info->io_deinit)
+ rk29_bl_info->io_deinit();
+}
+
+static struct platform_driver rk29_backlight_driver = {
+ .probe = rk29_backlight_probe,
+ .remove = rk29_backlight_remove,
+ .driver = {
+ .name = "rk29_backlight",
+ .owner = THIS_MODULE,
+ },
+ .shutdown = rk29_backlight_shutdown,
+};
+
+static int __init rk29_backlight_init(void)
+{
+ platform_driver_register(&rk29_backlight_driver);
+ return 0;
+}
+fs_initcall_sync(rk29_backlight_init);