[IMPROVE] new struct lcd_base
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 11 Nov 2013 12:58:17 +0000 (16:58 +0400)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Tue, 12 Nov 2013 08:40:22 +0000 (08:40 +0000)
not support S6E8AA0 and MARU

Change-Id: I2366a868c6d854d4b21cdb1833baed4d3f5ece5b
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
energy/Kbuild
energy/energy.c
energy/lcd/lcd_base.c
energy/lcd/lcd_base.h

index 4ead3e7..6728787 100644 (file)
@@ -45,19 +45,19 @@ UNREG_RET := void
 ###############################################################################
 # S6E8AA0:
 ifeq ($(CONFIG_LCD_S6E8AA0), y)
-       swap_energy-y += lcd/s6e8aa0.o
+       #swap_energy-y += lcd/s6e8aa0.o
 
-       REG_FUNC_LIST += s6e8aa0_register
-       UNREG_FUNC_LIST += s6e8aa0_unregister
+       #REG_FUNC_LIST += s6e8aa0_register
+       #UNREG_FUNC_LIST += s6e8aa0_unregister
 endif
 
 
 # MARU:
 ifeq ($(CONFIG_MARU_BACKLIGHT), y)
-       swap_energy-y += lcd/maru.o
+       #swap_energy-y += lcd/maru.o
 
-       REG_FUNC_LIST += maru_register
-       UNREG_FUNC_LIST += maru_unregister
+       #REG_FUNC_LIST += maru_register
+       #UNREG_FUNC_LIST += maru_unregister
 endif
 
 
index da510b3..ffb37ad 100644 (file)
@@ -36,6 +36,7 @@
 #include <us_manager/sspt/sspt_feature.h>
 #include <linux/atomic.h>
 #include "energy.h"
+#include "lcd/lcd_base.h"
 
 
 static u64 get_ntime(void)
@@ -585,12 +586,19 @@ int energy_init(void)
        sys_write_krp.kp.addr = (kprobe_opcode_t *)addr;
 
        ret = init_feature();
+       if (ret)
+               return ret;
+
+       ret = lcd_init();
+       if (ret)
+               uninit_feature();
 
        return ret;
 }
 
 void energy_uninit(void)
 {
+       lcd_exit();
        uninit_feature();
 
        if (energy_enable)
index 6b9e269..d685788 100644 (file)
 
 
 #include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/fs.h>
 #include "lcd_base.h"
 
 
-#ifdef CONFIG_ENEGRGY_LCD
-int lcd_mach_init(struct lcd_ops_set *ops_set, struct lcd_ops_get *ops_get);
-void lcd_mach_exit(void);
-#else /* CONFIG_ENEGRGY_LCD */
-static int lcd_mach_init(struct lcd_ops_set *ops_set, struct lcd_ops_get *ops_get)
-{
-       return -EPERM;
-}
-static void lcd_mach_exit(void)
-{
-}
-#endif /* CONFIG_ENEGRGY_LCD */
-
-
 int read_val(const char *path)
 {
        int ret;
@@ -70,35 +57,154 @@ int read_val(const char *path)
        return (int)val;
 }
 
-void set_backlight(int val)
+enum {
+       brightness_cnt = 10
+};
+
+void set_brightness(struct lcd_ops *ops, int val)
 {
        /* TODO: implement */
+       printk("####### set_backlight: name=%s val=%d\n", ops->name, val);
 }
 
-void set_power(int val)
+struct lcd_priv_data {
+       int min_brightness;
+       int max_brightness;
+
+       int brightness[brightness_cnt];
+
+       /* W = slope * brightness + intercept */
+       u64 slope_denominator;
+       u64 slope_numenator;
+       u64 intercept_denominator;
+       u64 intercept_numenator;
+};
+
+static int func_notifier_lcd(struct lcd_ops *ops, enum lcd_action_type action,
+                            void *data)
 {
-       /* TODO: implement */
+       switch (action) {
+       case LAT_BRIGHTNESS:
+               set_brightness(ops, (int)data);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
 }
 
-static struct lcd_ops_set ops_set = {
-       .set_backlight = set_backlight,
-       .set_power = set_power
-};
+static void *create_lcd_priv(struct lcd_ops *ops)
+{
+       int i;
+       struct lcd_priv_data *lpd = kmalloc(sizeof(*lpd), GFP_KERNEL);
 
-static struct lcd_ops_get ops_get = { NULL, NULL };
+       lpd->min_brightness = ops->get(ops, LPD_MIN_BRIGHTNESS);
+       lpd->max_brightness = ops->get(ops, LPD_MAX_BRIGHTNESS);
 
-int lcd_init(void)
+       for (i = 0; i < brightness_cnt; ++i)
+               lpd->brightness[i] = 0;
+
+       lpd->slope_denominator = 1;
+       lpd->slope_numenator = 1;
+       lpd->intercept_denominator = 1;
+       lpd->intercept_numenator = 1;
+
+       return (void *)lpd;
+}
+
+static void destroy_lcd_priv(void *data)
+{
+       kfree(data);
+}
+
+static LIST_HEAD(lcd_list);
+static DEFINE_MUTEX(lcd_lock);
+
+static void add_lcd(struct lcd_ops *ops)
+{
+       ops->priv = create_lcd_priv(ops);
+       ops->notifler = func_notifier_lcd;
+
+       INIT_LIST_HEAD(&ops->list);
+       list_add(&ops->list, &lcd_list);
+}
+
+static void del_lcd(struct lcd_ops *ops)
+{
+       list_del(&ops->list);
+
+       destroy_lcd_priv(ops->priv);
+}
+
+static struct lcd_ops *find_lcd(const char *name)
+{
+       struct lcd_ops *ops;
+
+       list_for_each_entry(ops, &lcd_list, list)
+               if (strcmp(ops->name, name) == 0)
+                       return ops;
+
+       return NULL;
+}
+
+static int lcd_is_register(struct lcd_ops *ops)
+{
+       struct lcd_ops *o;
+
+       list_for_each_entry(o, &lcd_list, list)
+               if (o == ops)
+                       return 1;
+
+       return 0;
+}
+
+int register_lcd(struct lcd_ops *ops)
 {
        int ret;
 
-       ret = lcd_mach_init(&ops_set, &ops_get);
-       if (ret)
-               return ret;
+       if (ops->check() == 0) {
+               printk("error checking %s\n", ops->name);
+               return -EINVAL;
+       }
 
+       mutex_lock(&lcd_lock);
+       if (find_lcd(ops->name)) {
+               ret = -EINVAL;
+               goto unlock;
+       }
+
+       add_lcd(ops);
+
+unlock:
+       mutex_unlock(&lcd_lock);
        return ret;
 }
 
+void unregister_lcd(struct lcd_ops *ops)
+{
+       mutex_lock(&lcd_lock);
+       if (lcd_is_register(ops) == 0)
+               goto unlock;
+
+       del_lcd(ops);
+
+unlock:
+       mutex_unlock(&lcd_lock);
+}
+
+
+DEFINITION_REG_FUNC;
+DEFINITION_UNREG_FUNC;
+
 void lcd_exit(void)
 {
-       lcd_mach_exit();
+       UNREGISTER_ALL_FUNC();
+}
+
+int lcd_init(void)
+{
+       REGISTER_ALL_FUNC();
+
+       return 0;
 }
index 435590b..570729b 100644 (file)
  *
  */
 
+
 #include <linux/errno.h>
 
 
-struct lcd_ops_get {
-       int (*get_backlight)(void);
-       int (*get_power)(void);
+enum lcd_action_type {
+       LAT_BRIGHTNESS
 };
 
-struct lcd_ops_set {
-       void (*set_backlight)(int val);
-       void (*set_power)(int val);
+enum lcd_paramerer_type {
+       LPD_MIN_BRIGHTNESS,
+       LPD_MAX_BRIGHTNESS,
+       LPD_BRIGHTNESS
 };
 
+struct lcd_ops;
+
+typedef int (*check_lcd)(void);
+typedef int (*notifier_lcd)(struct lcd_ops *ops, enum lcd_action_type action,
+                           void *data);
+typedef unsigned long (*get_parameter_lcd)(struct lcd_ops *ops,
+                                          enum lcd_paramerer_type type);
+
+
+struct lcd_ops {
+       struct list_head list;
+
+       char *name;
+       check_lcd check;
+       notifier_lcd notifler;
+       get_parameter_lcd get;
+
+       void *priv;
+};
+
+int register_lcd(struct lcd_ops *ops);
+void unregister_lcd(struct lcd_ops *ops);
 
 int read_val(const char *path);
+
 int lcd_init(void);
 void lcd_exit(void);