energy: add LCD support for sprdfb_panel driver 73/157573/1
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Tue, 24 Oct 2017 18:24:29 +0000 (21:24 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 25 Oct 2017 06:52:22 +0000 (09:52 +0300)
support configs:
- CONFIG_FB_SCX35
- CONFIG_FB_SCX30G
- CONFIG_FB_SCX15
- CONFIG_FB_SCX35L

Change-Id: Ieba9dec593379104190859aa72e2df92fa4e4db4
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
modules/energy/Kbuild
modules/energy/lcd/sprdfb_panel.c [new file with mode: 0644]

index 80d23c9c053239b97478a30d5ec87d4f44574371..501be014ea27c294d5b2b2c4ea7b8d0c80e79496 100644 (file)
@@ -46,6 +46,13 @@ ifeq ($(CONFIG_MARU_BACKLIGHT), y)
 endif
 
 
+# SPRDFB_PANEL
+ifneq ($(filter y,$(CONFIG_FB_SCX35) $(CONFIG_FB_SCX30G) $(CONFIG_FB_SCX15) $(CONFIG_FB_SCX35L)),)
+    swap_energy-y += lcd/sprdfb_panel.o
+    LCD_FUNC_LIST += sprdfb_panel
+endif
+
+
 
 
 
diff --git a/modules/energy/lcd/sprdfb_panel.c b/modules/energy/lcd/sprdfb_panel.c
new file mode 100644 (file)
index 0000000..051fb8d
--- /dev/null
@@ -0,0 +1,186 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2017
+ *
+ *    2017      Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ */
+
+
+#include <kprobe/swap_kprobes.h>
+#include <linux/backlight.h>
+#include "lcd_base.h"
+
+
+static const char path_bl[] = "/sys/class/backlight/panel/brightness";
+static const char path_bl_max[] = "/sys/class/backlight/panel/max_brightness";
+static const char path_power[] = "/sys/class/lcd/panel/lcd_power";
+
+static const char * const all_path[] = {
+       path_bl,
+       path_bl_max,
+       path_power
+};
+
+
+static int sprdfb_check(struct lcd_ops *ops)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(all_path); ++i) {
+               int ret = read_val(all_path[i]);
+
+               if (IS_ERR_VALUE(ret))
+                       return 0;
+       }
+
+       return 1;
+}
+
+static unsigned long sprdfb_get_parameter(struct lcd_ops *ops,
+                                         enum lcd_parameter_type type)
+{
+       switch (type) {
+       case LPD_MIN_BRIGHTNESS:
+               return 0;
+       case LPD_MAX_BRIGHTNESS:
+               return read_val(path_bl_max);
+       case LPD_BRIGHTNESS:
+               return read_val(path_bl);
+       case LPD_POWER:
+               return read_val(path_power);
+       }
+
+       return -EINVAL;
+}
+
+
+static int entry_handler_set_power(struct kretprobe_instance *ri,
+                                  struct pt_regs *regs);
+static int ret_handler_set_power(struct kretprobe_instance *ri,
+                                struct pt_regs *regs);
+
+static struct kretprobe set_power_krp = {
+       .kp.symbol_name = "sprdfb_set_power",
+       .entry_handler = entry_handler_set_power,
+       .handler = ret_handler_set_power,
+       .data_size = sizeof(int)
+};
+
+
+static int entry_handler_set_backlight(struct kretprobe_instance *ri,
+                                      struct pt_regs *regs);
+static int ret_handler_set_backlight(struct kretprobe_instance *ri,
+                                    struct pt_regs *regs);
+
+static struct kretprobe set_backlight_krp = {
+       .kp.symbol_name = "panel_update_brightness",
+       .entry_handler = entry_handler_set_backlight,
+       .handler = ret_handler_set_backlight,
+       .data_size = sizeof(int)
+};
+
+int sprdfb_set(struct lcd_ops *ops)
+{
+       int ret;
+
+       ret = swap_register_kretprobe(&set_power_krp);
+       if (ret)
+               return ret;
+
+       ret = swap_register_kretprobe(&set_backlight_krp);
+       if (ret)
+               swap_unregister_kretprobe(&set_power_krp);
+
+       return ret;
+}
+
+int sprdfb_unset(struct lcd_ops *ops)
+{
+       swap_unregister_kretprobe(&set_backlight_krp);
+       swap_unregister_kretprobe(&set_power_krp);
+
+       return 0;
+}
+
+static struct lcd_ops sprdfb_ops = {
+       .name = "sprdfb_panel",
+       .check = sprdfb_check,
+       .set = sprdfb_set,
+       .unset = sprdfb_unset,
+       .get = sprdfb_get_parameter
+};
+
+struct lcd_ops *LCD_MAKE_FNAME(sprdfb_panel)(void)
+{
+       return &sprdfb_ops;
+}
+
+
+/* ============================================================================
+ * ===                               POWER                                  ===
+ * ============================================================================
+ */
+static int entry_handler_set_power(struct kretprobe_instance *ri,
+                                  struct pt_regs *regs)
+{
+       int *power = (int *)ri->data;
+
+       *power = (int)swap_get_karg(regs, 1);
+
+       return 0;
+}
+
+static int ret_handler_set_power(struct kretprobe_instance *ri,
+                                struct pt_regs *regs)
+{
+       int *power = (int *)ri->data;
+       int ret = regs_return_value(regs);
+
+       if (!ret && sprdfb_ops.notifier)
+               sprdfb_ops.notifier(&sprdfb_ops, LAT_POWER, INT2VOIDP(*power));
+
+       return 0;
+}
+
+
+/* ============================================================================
+ * ===                              BACKLIGHT                               ===
+ * ============================================================================
+ */
+static int entry_handler_set_backlight(struct kretprobe_instance *ri,
+                                      struct pt_regs *regs)
+{
+       int *br = (int *)ri->data;
+       struct backlight_device *bd;
+
+       bd = (struct backlight_device *)swap_get_karg(regs, 0);
+       *br = bd->props.brightness;
+
+       return 0;
+}
+
+static int ret_handler_set_backlight(struct kretprobe_instance *ri,
+                                    struct pt_regs *regs)
+{
+       int *br = (int *)ri->data;
+       int ret = regs_return_value(regs);
+
+       if (!ret && sprdfb_ops.notifier)
+               sprdfb_ops.notifier(&sprdfb_ops, LAT_BRIGHTNESS,
+                                   INT2VOIDP(*br));
+
+       return 0;
+}