Nokia N900 >> Native Debian >> Kernel 5.3.0

實做自動調節屏亮度以及鍵盤背光功能(Kernel)


利用Battery Polling機制取得Light Sensor數值,接著設定LCD Brightness和Keyboard Backlight

diff -Naur old/bq27xxx_battery.c new/bq27xxx_battery.c
--- old/bq27xxx_battery.c  2019-11-22 09:59:59.310120115 +0800
+++ new/bq27xxx_battery.c  2019-11-22 10:01:38.185984078 +0800
@@ -1623,11 +1623,40 @@
 }
 EXPORT_SYMBOL_GPL(bq27xxx_battery_update);
 
+extern int gpio_keys_lock;
+int set_mylcd(int);
+int set_mykb(int);
+int get_mylight(void);
 static void bq27xxx_battery_poll(struct work_struct *work)
 {
+  int lux=0;
   struct bq27xxx_device_info *di =
-      container_of(work, struct bq27xxx_device_info,
-             work.work);
+      container_of(work, struct bq27xxx_device_info, work.work);
+
+  if (gpio_keys_lock == 0) {
+    lux = get_mylight();
+    if (lux < 5) {
+      set_mykb(30);
+      set_mylcd(20);
+    }
+    else if (lux < 10) {
+      set_mykb(0);
+      set_mylcd(30);
+    }
+    else if (lux < 50) {
+      set_mykb(0);
+      set_mylcd(50);
+    }
+    else if (lux < 100) {
+      set_mykb(0);
+      set_mylcd(100);
+    }
+    else {
+      set_mykb(0);
+      set_mylcd(150);
+    }
+  }
 
   bq27xxx_battery_update(di);
 
diff -Naur old/gpio_keys.c new/gpio_keys.c
--- old/gpio_keys.c  2019-11-22 09:59:42.766142814 +0800
+++ new/gpio_keys.c  2019-11-22 10:01:26.394000333 +0800
@@ -1,13 +1,13 @@
-// SPDX-License-Identifier: GPL-2.0-only
 /*
+ * SPDX-License-Identifier: GPL-2.0-only
  * Driver for keys on GPIO lines capable of generating interrupts.
  *
  * Copyright 2005 Phil Blundell
  * Copyright 2010, 2011 David Jander <david@protonic.nl>
+ * Copyright 2019 Steward Fu <steward.fu@gmail.com>
  */
 
 #include <linux/module.h>
-
 #include <linux/init.h>
 #include <linux/fs.h>
 #include <linux/interrupt.h>
@@ -29,6 +29,12 @@
 #include <linux/spinlock.h>
 #include <dt-bindings/input/gpio-keys.h>
 
+#define LOCK_KEY 10
+int gpio_keys_lock=0;
+EXPORT_SYMBOL(gpio_keys_lock);
+int set_mykb(int);
+int set_mylcd(int);
+
 struct gpio_button_data {
   const struct gpio_keys_button *button;
   struct input_dev *input;
@@ -361,7 +367,8 @@
   const struct gpio_keys_button *button = bdata->button;
   struct input_dev *input = bdata->input;
   unsigned int type = button->type ?: EV_KEY;
-  int state;
+  int state, code, value;
+  static int lcd=0, kb=0;
 
   state = gpiod_get_value_cansleep(bdata->gpiod);
   if (state < 0) {
@@ -371,12 +378,30 @@
   }
 
   if (type == EV_ABS) {
-    if (state)
-      input_event(input, type, button->code, button->value);
-  } else {
-    input_event(input, type, *bdata->code, state);
-  }
-  input_sync(input);
+    if (state) {
+      code = button->code;
+      value = button->value;
+    }
+  } 
+  else {
+    code = *bdata->code;
+    value = state;
+  }
+
+  if (code == LOCK_KEY) {
+    gpio_keys_lock = (value  > 0) ? 0 : 1;
+    if (gpio_keys_lock) {
+      kb = set_mykb(0);
+      lcd = set_mylcd(0);
+    }
+    else {
+      set_mykb(kb);
+      set_mylcd(lcd);
+    }
+  }
+
+  input_event(input, type, code, value);
+  input_sync(input);
 }
 
 static void gpio_keys_gpio_work_func(struct work_struct *work)
@@ -386,16 +411,22 @@
 
   gpio_keys_gpio_report_event(bdata);
 
-  if (bdata->button->wakeup)
-    pm_relax(bdata->input->dev.parent);
+  if (bdata->button->wakeup) {
+    pm_relax(bdata->input->dev.parent);
+  }
 }
 
 static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id)
 {
   struct gpio_button_data *bdata = dev_id;
+  const struct gpio_keys_button *button = bdata->button;
 
   BUG_ON(irq != bdata->irq);
 
+  if ((gpio_keys_lock) && (button->code != LOCK_KEY)) {
+    return IRQ_HANDLED;
+  }
+
   if (bdata->button->wakeup) {
     const struct gpio_keys_button *button = bdata->button;
 
@@ -647,15 +678,16 @@
 
 static void gpio_keys_report_state(struct gpio_keys_drvdata *ddata)
 {
+  int i;
   struct input_dev *input = ddata->input;
-  int i;
 
   for (i = 0; i < ddata->pdata->nbuttons; i++) {
     struct gpio_button_data *bdata = &ddata->data[i];
-    if (bdata->gpiod)
-      gpio_keys_gpio_report_event(bdata);
+    if (bdata->gpiod) {
+      gpio_keys_gpio_report_event(bdata);
+    }
   }
-  input_sync(input);
+  input_sync(input);
 }
 
 static int gpio_keys_open(struct input_dev *input)
diff -Naur old/leds-lp5523.c new/leds-lp5523.c
--- old/leds-lp5523.c  2019-11-22 10:00:10.822104310 +0800
+++ new/leds-lp5523.c  2019-11-22 10:01:48.269970171 +0800
@@ -790,6 +790,26 @@
   mutex_unlock(&chip->lock);
   return ret;
 }
+  
+static struct lp55xx_led *myled=NULL;
+int set_mykb(int level)
+{
+  int ret;
+  static int brightness=0;
+  struct lp55xx_chip *chip = myled->chip;
+
+  ret = brightness;
+  mutex_lock(&chip->lock);
+  lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + 0, level);
+  lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + 1, level);
+  lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + 2, level);
+  lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + 3, level);
+  lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + 7, level);
+  lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + 8, level);
+  mutex_unlock(&chip->lock);
+  return ret;
+}
+EXPORT_SYMBOL(set_mykb);
 
 static int lp5523_led_brightness(struct lp55xx_led *led)
 {
@@ -916,6 +936,7 @@
     goto err_register_sysfs;
   }
 
+  myled = led;
   return 0;
 
 err_register_sysfs:
diff -Naur old/panel-sony-acx565akm.c new/panel-sony-acx565akm.c
--- old/panel-sony-acx565akm.c  2019-11-22 10:00:47.502053889 +0800
+++ new/panel-sony-acx565akm.c  2019-11-22 10:01:59.473954711 +0800
@@ -52,6 +52,9 @@
 #define MIPID_VER_LS041Y3    4
 #define MIPID_VER_L4F00311    8
 #define MIPID_VER_ACX565AKM    9
+  
+static struct panel_drv_data *mylcd;
+int set_mylcd(int level);
 
 struct panel_drv_data {
   struct omap_dss_device  dssdev;
@@ -333,6 +336,13 @@
   return bv;
 }
 
+int set_mylcd(int level)
+{
+  int ret = acx565akm_get_actual_brightness(mylcd);
+  acx565akm_set_brightness(mylcd, level);
+  return ret;
+}
+EXPORT_SYMBOL(set_mylcd);
 
 static int acx565akm_bl_update_status(struct backlight_device *dev)
 {
@@ -849,6 +859,7 @@
     goto err_reg;
   }
 
+  mylcd = ddata;
   return 0;
 
 err_reg:


返回上一頁