htcleo: new button backlight manager driver
- Now button backlight is managed by this driver, also it is configurable by sysfs (number of secs. after backlight will be turned off after last key-press, enable/disable this auto_off feature) -When disabled auto_off, backlight will go off along with screen backlight. - Sysfs for num. of seconds : /sys/devices/platform/btn_backlight_manager/off_seconds (min: 5 sec, max: 60 sec) - Sysfs for turn on/off auto-off feature: /sys/devices/platform/btn_backlight_manager/auto_off (0 to disable auto-off, 1 to enable)
This commit is contained in:
parent
c3c716173f
commit
86ad764392
@ -232,6 +232,7 @@ CONFIG_MSM_DEBUG_UART_NONE=y
|
||||
CONFIG_MACH_HTCLEO=y
|
||||
# CONFIG_USING_BRAVOS_DSP is not set
|
||||
# CONFIG_HTCLEO_BLINK_AT_BOOT is not set
|
||||
CONFIG_HTCLEO_BTN_BACKLIGHT_MANAGER=y
|
||||
# CONFIG_MACH_PASSIONC is not set
|
||||
# CONFIG_MACH_BRAVOC is not set
|
||||
# CONFIG_MACH_INCREDIBLE is not set
|
||||
|
@ -296,6 +296,13 @@ config HTCLEO_BLINK_AT_BOOT
|
||||
help
|
||||
Blink flash led during hardware init
|
||||
|
||||
config HTCLEO_BTN_BACKLIGHT_MANAGER
|
||||
depends on MACH_HTCLEO
|
||||
default y
|
||||
bool "Use button backlight manager"
|
||||
help
|
||||
Use kernel button backlight manager to turn on/off backlight
|
||||
|
||||
config MACH_PASSIONC
|
||||
depends on ARCH_QSD8X50
|
||||
default n
|
||||
|
@ -127,6 +127,7 @@ obj-$(CONFIG_MACH_HTCLEO) += board-htcleo-proximity.o board-htcleo-ls.o
|
||||
obj-$(CONFIG_MACH_HTCLEO) += clock-wince.o
|
||||
obj-$(CONFIG_HTCLEO_BACKLIGHT) += board-htcleo-bl.o
|
||||
obj-$(CONFIG_HTCLEO_BACKLIGHT_LED) += board-htcleo-bl-led.o
|
||||
obj-$(CONFIG_HTCLEO_BTN_BACKLIGHT_MANAGER) += board-htcleo-btn_backlight-manager.o
|
||||
|
||||
# MSM7x30 boards
|
||||
obj-$(CONFIG_ARCH_MSM7X30) += panel-samsungwvga-tl2796a.o panel-samsungwvga-s6e63m0.o panel-sonywvga-s6d16a0x21-7x30.o
|
||||
|
@ -2,6 +2,7 @@
|
||||
*
|
||||
* Copyright (c) 2010 Cotulla
|
||||
* Edited to Common Structure by Markinus
|
||||
* Added support for Button backlight manager by Danijel Posilović (dan1j3l)
|
||||
*
|
||||
* This software is licensed under the terms of the GNU General Public
|
||||
* License version 2, as published by the Free Software Foundation, and
|
||||
@ -37,17 +38,15 @@
|
||||
#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;
|
||||
#ifdef CONFIG_HTCLEO_BTN_BACKLIGHT_MANAGER
|
||||
static int BUTTON_BACKLIGHT_GPIO = 48;
|
||||
#endif
|
||||
|
||||
static int htcleo_brightness_autobacklight(uint8_t value)
|
||||
{
|
||||
@ -92,47 +91,16 @@ static ssize_t htcleo_auto_bl_set(struct device *dev,
|
||||
|
||||
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));
|
||||
}
|
||||
#ifdef CONFIG_HTCLEO_BTN_BACKLIGHT_MANAGER
|
||||
// Disable button backlight along with screen
|
||||
if (!enable)
|
||||
gpio_set_value(BUTTON_BACKLIGHT_GPIO, 0);
|
||||
#endif
|
||||
|
||||
data[0] = enable ? 1 : 0;
|
||||
ret = microp_i2c_write(MICROP_I2C_WCMD_BL_EN, data, 1);
|
||||
@ -204,9 +172,6 @@ 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);
|
||||
@ -220,7 +185,6 @@ 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;
|
||||
}
|
||||
|
||||
|
188
arch/arm/mach-msm/board-htcleo-btn_backlight-manager.c
Normal file
188
arch/arm/mach-msm/board-htcleo-btn_backlight-manager.c
Normal file
@ -0,0 +1,188 @@
|
||||
/* board-htcleo_btn_backlight-manager.c
|
||||
*
|
||||
* Driver for managing buttons backlight
|
||||
*
|
||||
* Copyright (C) 2010 Danijel Posilović (dan1j3l) <danijel.posilovic@gmail.com>
|
||||
*
|
||||
* 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/keyboard.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
static int BUTTON_BACKLIGHT_GPIO = 48;
|
||||
static int OFF_SEC = 10;
|
||||
static int auto_off_enabled = 1;
|
||||
|
||||
static struct delayed_off
|
||||
{
|
||||
struct delayed_work work;
|
||||
} btn_off_work;
|
||||
|
||||
static DEFINE_MUTEX(htcleo_btn_manager_lock);
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// off_sec sysfs
|
||||
static ssize_t htcleo_manager_offsec_get(struct device *dev,struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int ret;
|
||||
ret = sprintf(buf, "%d", OFF_SEC);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t htcleo_manager_offsec_set(struct device *dev,struct device_attribute *attr,const char *buf, size_t count)
|
||||
{
|
||||
int set_state;
|
||||
|
||||
mutex_lock(&htcleo_btn_manager_lock);
|
||||
|
||||
sscanf(buf, "%d", &set_state);
|
||||
|
||||
if (set_state < 5)
|
||||
set_state = 5;
|
||||
|
||||
if (set_state > 60)
|
||||
set_state=60;
|
||||
|
||||
OFF_SEC = set_state;
|
||||
|
||||
mutex_unlock(&htcleo_btn_manager_lock);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(off_seconds, 0666, htcleo_manager_offsec_get, htcleo_manager_offsec_set);
|
||||
|
||||
|
||||
// auto_off sysfs
|
||||
static ssize_t htcleo_manager_auto_off_get(struct device *dev,struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int ret;
|
||||
ret = sprintf(buf, "%d", auto_off_enabled);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t htcleo_manager_auto_off_set(struct device *dev,struct device_attribute *attr,const char *buf, size_t count)
|
||||
{
|
||||
int set_state;
|
||||
|
||||
mutex_lock(&htcleo_btn_manager_lock);
|
||||
|
||||
sscanf(buf, "%d", &set_state);
|
||||
|
||||
if (set_state < 0)
|
||||
set_state = 0;
|
||||
|
||||
if (set_state > 1)
|
||||
set_state=1;
|
||||
|
||||
auto_off_enabled = set_state;
|
||||
|
||||
mutex_unlock(&htcleo_btn_manager_lock);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(auto_off, 0666, htcleo_manager_auto_off_get, htcleo_manager_auto_off_set);
|
||||
|
||||
|
||||
static void btn_delayed_off_function(struct work_struct *work){
|
||||
gpio_set_value(BUTTON_BACKLIGHT_GPIO, 0);
|
||||
}
|
||||
|
||||
int buttons_notify(struct notifier_block *nblock, unsigned long code, void *_param) {
|
||||
struct keyboard_notifier_param *param = _param;
|
||||
int keycode;
|
||||
|
||||
if (code == KBD_KEYCODE) {
|
||||
|
||||
mutex_lock(&htcleo_btn_manager_lock);
|
||||
|
||||
keycode = param->value;
|
||||
|
||||
//printk(KERN_DEBUG "BTN-BCKM: KEYLOGGER %i %s\n", param->value, (param->down ? "down" : "up"));
|
||||
|
||||
// Turn backlight on only if pressed = Dial, home, winkey, back, end button
|
||||
if (keycode==231 || keycode==102 || keycode==139 || keycode==158 || keycode==107){
|
||||
|
||||
gpio_set_value(BUTTON_BACKLIGHT_GPIO, 1);
|
||||
|
||||
// If auto off enabled then buttons will turn off after declared amount of time, else screen backlight will turn them off
|
||||
if (auto_off_enabled){
|
||||
cancel_delayed_work_sync(&btn_off_work.work);
|
||||
schedule_delayed_work(&btn_off_work.work, msecs_to_jiffies(OFF_SEC*1000));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mutex_unlock(&htcleo_btn_manager_lock);
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct notifier_block nb = {
|
||||
.notifier_call = buttons_notify
|
||||
};
|
||||
|
||||
|
||||
static int htcleo_btn_backlight_manager_probe(struct platform_device *pdev)
|
||||
{
|
||||
int rc;
|
||||
|
||||
printk("BTN-BCKM: Registering btn manager...\n");
|
||||
register_keyboard_notifier(&nb);
|
||||
rc = device_create_file(&pdev->dev, &dev_attr_off_seconds);
|
||||
rc = device_create_file(&pdev->dev, &dev_attr_auto_off);
|
||||
INIT_DELAYED_WORK(&btn_off_work.work, btn_delayed_off_function);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int htcleo_btn_backlight_manager_remove(struct platform_device *pdev)
|
||||
{
|
||||
printk("BTN-BCKM: Deactivating btn manager...\n");
|
||||
unregister_keyboard_notifier(&nb);
|
||||
device_remove_file(&pdev->dev, &dev_attr_off_seconds);
|
||||
device_remove_file(&pdev->dev,&dev_attr_auto_off);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static struct platform_driver htcleo_btn_backlight_manager = {
|
||||
.probe = htcleo_btn_backlight_manager_probe,
|
||||
.remove= htcleo_btn_backlight_manager_remove,
|
||||
.driver = {
|
||||
.name = "btn_backlight_manager",
|
||||
.owner = THIS_MODULE
|
||||
},
|
||||
};
|
||||
|
||||
static int __init backlight_manager_init(void)
|
||||
{
|
||||
return platform_driver_register(&htcleo_btn_backlight_manager);
|
||||
}
|
||||
|
||||
static void __exit backlight_manager_exit(void)
|
||||
{
|
||||
platform_driver_unregister(&htcleo_btn_backlight_manager);
|
||||
}
|
||||
|
||||
module_init(backlight_manager_init);
|
||||
module_exit(backlight_manager_exit);
|
||||
|
||||
MODULE_AUTHOR("Danijel Posilović (dan1j3l) <danijel.posilovic@gmail.com>");
|
||||
MODULE_DESCRIPTION("Button Backlight Manager");
|
||||
MODULE_LICENSE("GPL");
|
@ -63,7 +63,7 @@
|
||||
#include "dex_comm.h"
|
||||
|
||||
|
||||
#define ATAG_MAGLDR_BOOT 0x4C47414D
|
||||
#define ATAG_MAGLDR_BOOT 0x4C47414D
|
||||
struct tag_magldr_entry
|
||||
{
|
||||
_Bool fNoNandBoot;
|
||||
@ -80,7 +80,7 @@ static unsigned int nand_boot = 0;
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
int htcleo_is_nand_boot(void)
|
||||
{
|
||||
return nand_boot;
|
||||
return nand_boot;
|
||||
}
|
||||
|
||||
static int __init parse_tag_nand_boot(const struct tag *tag)
|
||||
@ -240,10 +240,10 @@ static struct platform_device microp_devices[] = {
|
||||
{
|
||||
.name = "leds-microp",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.dev = {
|
||||
.platform_data = µp_leds_data,
|
||||
},
|
||||
|
||||
|
||||
},
|
||||
{
|
||||
.name = "htcleo-lsensor",
|
||||
@ -282,7 +282,7 @@ static struct i2c_board_info base_i2c_devices[] =
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// USB
|
||||
// USB
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
static uint32_t usb_phy_3v3_table[] =
|
||||
@ -706,7 +706,7 @@ static struct platform_device msm_kgsl_device =
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Memory
|
||||
// Memory
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
static struct android_pmem_platform_data mdp_pmem_pdata = {
|
||||
@ -824,6 +824,17 @@ struct platform_device msm_device_rtc = {
|
||||
.name = "msm_rtc",
|
||||
.id = -1,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_HTCLEO_BTN_BACKLIGHT_MANAGER
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Button backlight manager
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
struct platform_device btn_backlight_manager = {
|
||||
.name = "btn_backlight_manager",
|
||||
.id = -1,
|
||||
};
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Platform Devices
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
@ -854,6 +865,9 @@ static struct platform_device *devices[] __initdata =
|
||||
&qsd_device_spi,
|
||||
&htc_headset_mgr,
|
||||
&htc_headset_gpio,
|
||||
#ifdef CONFIG_HTCLEO_BTN_BACKLIGHT_MANAGER
|
||||
&btn_backlight_manager,
|
||||
#endif
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Vibrator
|
||||
@ -962,7 +976,7 @@ static void __init htcleo_init(void)
|
||||
do_sdc1_reset();
|
||||
|
||||
msm_acpu_clock_init(&htcleo_clock_data);
|
||||
|
||||
|
||||
perflock_init(&htcleo_perflock_data);
|
||||
|
||||
init_dex_comm();
|
||||
@ -975,7 +989,7 @@ static void __init htcleo_init(void)
|
||||
|
||||
bt_export_bd_address();
|
||||
htcleo_audio_init();
|
||||
|
||||
|
||||
msm_device_i2c_init();
|
||||
|
||||
/* set the gpu power rail to manual mode so clk en/dis will not
|
||||
@ -985,7 +999,7 @@ static void __init htcleo_init(void)
|
||||
htcleo_kgsl_power(false);
|
||||
mdelay(100);
|
||||
htcleo_kgsl_power(true);
|
||||
|
||||
|
||||
platform_add_devices(devices, ARRAY_SIZE(devices));
|
||||
|
||||
htcleo_init_panel();
|
||||
@ -996,11 +1010,11 @@ static void __init htcleo_init(void)
|
||||
#ifdef CONFIG_USB_ANDROID
|
||||
htcleo_add_usb_devices();
|
||||
#endif
|
||||
|
||||
|
||||
htcleo_init_mmc(0);
|
||||
platform_device_register(&htcleo_timed_gpios);
|
||||
|
||||
|
||||
|
||||
/* Blink the camera LED shortly to show that we're alive! */
|
||||
#ifdef CONFIG_HTCLEO_BLINK_AT_BOOT
|
||||
bank6_in = (unsigned int*)(MSM_GPIO1_BASE + 0x0864);
|
||||
@ -1078,7 +1092,7 @@ static void __init htcleo_map_io(void)
|
||||
msm_map_common_io();
|
||||
htcleo_allocate_memory_regions();
|
||||
msm_clock_init();
|
||||
|
||||
|
||||
#if defined(CONFIG_VERY_EARLY_CONSOLE)
|
||||
// Init our consoles _really_ early
|
||||
#if defined(CONFIG_HTC_FB_CONSOLE)
|
||||
|
Loading…
x
Reference in New Issue
Block a user