diff options
| author | Amit Jain <ajain@motorola.com> | 2014-10-05 20:21:19 -0500 |
|---|---|---|
| committer | Amit Jain <ajain@motorola.com> | 2014-10-06 19:10:24 +0000 |
| commit | 1d37d79a3000fa182aacf007ca05826ffb4a46fc (patch) | |
| tree | 932d2a4c3b58c3738624073f89d23e4add86de59 /drivers/misc/m4sensorhub_als.c | |
| parent | 89ee8f2ea7aa0a1e9af8184da2e3e3282976f196 (diff) | |
| download | olio-linux-3.10-1d37d79a3000fa182aacf007ca05826ffb4a46fc.tar.xz olio-linux-3.10-1d37d79a3000fa182aacf007ca05826ffb4a46fc.zip | |
IKXCLOCK-4101: use ALS to control backlight
when watch is on charger
Diffstat (limited to 'drivers/misc/m4sensorhub_als.c')
| -rw-r--r-- | drivers/misc/m4sensorhub_als.c | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/drivers/misc/m4sensorhub_als.c b/drivers/misc/m4sensorhub_als.c index 55fa5f733e1..717c4fe2911 100644 --- a/drivers/misc/m4sensorhub_als.c +++ b/drivers/misc/m4sensorhub_als.c @@ -29,6 +29,11 @@ #include <linux/input.h> #include <linux/slab.h> #include <linux/delay.h> +#ifdef CONFIG_ALS_WHILE_CHARGING +#include <linux/notifier.h> +#include <linux/als_notify.h> +#include <linux/wakeup_source_notify.h> +#endif #define m4als_err(format, args...) KDEBUG(M4SH_ERROR, format, ## args) @@ -48,8 +53,31 @@ struct m4als_driver_data { int16_t latest_samplerate; int16_t fastest_rate; uint16_t status; +#ifdef CONFIG_ALS_WHILE_CHARGING + struct notifier_block charger_nb; + bool chargerstatus; +#endif }; +#ifdef CONFIG_ALS_WHILE_CHARGING +static int charger_notify(struct notifier_block *self, + unsigned long action, void *dev) +{ + struct m4als_driver_data *dd = + container_of(self, struct m4als_driver_data, charger_nb); + switch (action) { + case DISPLAY_WAKE_EVENT_DOCKON: + case DISPLAY_WAKE_EVENT_DOCKOFF: + dd->chargerstatus = (action == DISPLAY_WAKE_EVENT_DOCKON); + pr_info("%s: dd->chargerstatus is %d\n", + __func__, dd->chargerstatus); + break; + } + + return NOTIFY_OK; +} +#endif + static void m4als_work_func(struct work_struct *work) { int err = 0; @@ -82,8 +110,18 @@ static void m4als_work_func(struct work_struct *work) dd->luminosity = luminosity; - input_event(dd->indev, EV_MSC, MSC_RAW, dd->luminosity); - input_sync(dd->indev); +#ifdef CONFIG_ALS_WHILE_CHARGING + if (dd->chargerstatus == true) { + als_notify_subscriber(luminosity); + } else { + input_event(dd->indev, EV_MSC, MSC_RAW, dd->luminosity); + input_sync(dd->indev); + } +#else + input_event(dd->indev, EV_MSC, MSC_RAW, dd->luminosity); + input_sync(dd->indev); +#endif + if (dd->samplerate > 0) queue_delayed_work(system_freezable_wq, &(dd->m4als_work), msecs_to_jiffies(dd->samplerate)); @@ -102,6 +140,13 @@ static int m4als_set_samplerate(struct m4als_driver_data *dd, int16_t rate) int err = 0; int size = 0; +#ifdef CONFIG_ALS_WHILE_CHARGING + if (rate == -1 && dd->chargerstatus == true) { + m4als_err("%s: ignoring disable\n", __func__); + return err; + } +#endif + if ((rate >= 0) && (rate <= dd->fastest_rate)) rate = dd->fastest_rate; @@ -388,6 +433,12 @@ static int m4als_probe(struct platform_device *pdev) goto m4als_probe_fail; } +#ifdef CONFIG_ALS_WHILE_CHARGING + dd->chargerstatus = false; + dd->charger_nb.notifier_call = charger_notify; + wakeup_source_register_notify(&dd->charger_nb); +#endif + return 0; m4als_probe_fail: @@ -406,6 +457,9 @@ static int __exit m4als_remove(struct platform_device *pdev) cancel_delayed_work(&(dd->m4als_work)); m4als_remove_sysfs(dd); m4sensorhub_unregister_initcall(m4als_driver_init); +#ifdef CONFIG_ALS_WHILE_CHARGING + wakeup_source_unregister_notify(&dd->charger_nb); +#endif if (dd->indev != NULL) input_unregister_device(dd->indev); mutex_destroy(&(dd->mutex)); |