- Some cleanups

- Added button backlight control via panel backlight (button backlight will go on/off with screen backlight)
- To enable/disable this just echo 0 or 1 to /sys/devices/platform/htcleo-backlight/btn_control
( echo 0 >  /sys/devices/platform/htcleo-backlight/btn_control )
- By default button control is enabled
This commit is contained in:
Danijel Posilović 2010-11-22 21:46:37 +01:00 committed by tytung
parent 2bbd73cdec
commit c3c716173f
3 changed files with 54 additions and 5 deletions

View File

@ -29,7 +29,6 @@
#include <mach/msm_iomap.h>
#include <mach/atmega_microp.h>
//#define DEBUG_LCM
#ifdef DEBUG_LCM
#define LCMDBG(fmt, arg...) printk(fmt, ## arg)
@ -38,10 +37,17 @@
#endif
#define HTCLEO_DEFAULT_BACKLIGHT_BRIGHTNESS 255
int BUTTON_BACKLIGHT_GPIO = 48;
static struct led_trigger *htcleo_lcd_backlight;
static int auto_bl_state=0;
static DEFINE_MUTEX(htcleo_backlight_lock);
static int btn_backlight_control = 1;
static struct delayed_off
{
struct delayed_work work;
} delayed_off_work;
static int htcleo_brightness_autobacklight(uint8_t value)
{
@ -84,14 +90,50 @@ static ssize_t htcleo_auto_bl_set(struct device *dev,
return count;
}
static DEVICE_ATTR(auto_bl, 0666, htcleo_auto_bl_get, htcleo_auto_bl_set);
//////////////////////////////////////////////////////
// Button backlight control
//////////////////////////////////////////////////////
static void btn_delayed_off_function(struct work_struct *work){
gpio_set_value(BUTTON_BACKLIGHT_GPIO, 0);
}
static ssize_t htcleo_btn_control_get(struct device *dev,struct device_attribute *attr, char *buf)
{
int ret;
ret = sprintf(buf, "%d", btn_backlight_control);
return ret;
}
static ssize_t htcleo_btn_control_set(struct device *dev,struct device_attribute *attr,const char *buf, size_t count)
{
int set_state;
mutex_lock(&htcleo_backlight_lock);
sscanf(buf, "%d", &set_state);
if(set_state!=0 && set_state!=1) return -EINVAL;
btn_backlight_control = set_state;
gpio_set_value(BUTTON_BACKLIGHT_GPIO, set_state);
mutex_unlock(&htcleo_backlight_lock);
return count;
}
static DEVICE_ATTR(btn_control, 0666, htcleo_btn_control_get, htcleo_btn_control_set);
static int htcleo_brightness_onoff_bkl(int enable)
{
int ret;
uint8_t data[1];
// If btn backlight control enabled then set it
if (btn_backlight_control){
// Enable backlight
gpio_set_value(BUTTON_BACKLIGHT_GPIO, enable);
// Schedule timed off dan1j3l TODO !!!
//cancel_delayed_work_sync(&delayed_off_work.work);
//schedule_delayed_work(&delayed_off_work.work, msecs_to_jiffies(10000));
}
data[0] = enable ? 1 : 0;
ret = microp_i2c_write(MICROP_I2C_WCMD_BL_EN, data, 1);
if (ret != 0)
@ -148,7 +190,7 @@ static enum led_brightness htcleo_brightness_get(struct led_classdev *led_cdev)
return led_cdev->brightness;
}
static struct led_classdev htcleo_backlight_led =
static struct led_classdev htcleo_backlight_led =
{
.name = "lcd-backlight",
.brightness = HTCLEO_DEFAULT_BACKLIGHT_BRIGHTNESS,
@ -162,7 +204,10 @@ static int htcleo_backlight_probe(struct platform_device *pdev)
rc = device_create_file(&pdev->dev, &dev_attr_auto_bl);
printk(KERN_INFO "%s: HTCLeo Backlight connect with microP: "
"Probe\n", __func__);
// Kernel button backlight control
rc = device_create_file(&pdev->dev, &dev_attr_btn_control);
INIT_DELAYED_WORK(&delayed_off_work.work, btn_delayed_off_function);
led_trigger_register_simple("lcd-backlight-gate", &htcleo_lcd_backlight);
rc = led_classdev_register(&pdev->dev, &htcleo_backlight_led);
if (rc)
@ -175,6 +220,7 @@ static int htcleo_backlight_probe(struct platform_device *pdev)
static int htcleo_backlight_remove(struct platform_device *pdev)
{
device_remove_file(&pdev->dev, &dev_attr_auto_bl);
device_remove_file(&pdev->dev, &dev_attr_btn_control);
return 0;
}

View File

@ -31,6 +31,7 @@ obj-$(CONFIG_LEDS_WM831X_STATUS) += leds-wm831x-status.o
obj-$(CONFIG_LEDS_WM8350) += leds-wm8350.o
obj-$(CONFIG_LEDS_PWM) += leds-pwm.o
obj-$(CONFIG_MACH_HTCLEO) += leds-microp.o
obj-$(CONFIG_MICROP_COMMON) += leds-microp.o
obj-$(CONFIG_LEDS_PM8058) += leds-pm8058.o
# LED SPI Drivers

View File

@ -14,6 +14,7 @@
*
*/
#if defined(CONFIG_MICROP_COMMON) || defined(CONFIG_MACH_HTCLEO)
#include <linux/module.h>
#include <linux/init.h>
#include <linux/leds.h>
@ -25,6 +26,7 @@
int gl_state = 0; // Green led last state
int al_state = 0; // Amber led last state
static int microp_write_led_mode(struct led_classdev *led_cdev,uint8_t mode, uint16_t off_timer){
struct microp_led_data *ldata;
@ -836,4 +838,4 @@ module_exit(microp_led_exit);
MODULE_DESCRIPTION("Atmega MicroP led driver");
MODULE_LICENSE("GPL");
#endif