display: Change get_var_display_config return type to const
[platform/core/system/deviced.git] / plugins / wearable / display / device-interface.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <stdbool.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <string.h>
27 #include <unistd.h>
28 #include <limits.h>
29 #include <math.h>
30 #include <assert.h>
31 #include <errno.h>
32 #include <dlfcn.h>
33 #include <hal/device/hal-display.h>
34
35 #include "ambient-mode.h"
36 #include "core/log.h"
37 #include "shared/devices.h"
38 #include "shared/common.h"
39 #include "shared/device-notifier.h"
40 #include "util.h"
41 #include "device-interface.h"
42 #include "vconf.h"
43 #include "core.h"
44 #include "display/display-dpms.h"
45 #include "display/display.h"
46 #include "display/display-lock.h"
47 #include "battery-monitor.h"
48 #include "battery/power-supply.h"
49 #include "power/power-suspend.h"
50 #include "shared/plugin.h"
51
52 #define TOUCH_ON        1
53 #define TOUCH_OFF       0
54
55 #define LCD_PHASED_MIN_BRIGHTNESS       1
56 #define LCD_PHASED_MAX_BRIGHTNESS       100
57 #define LCD_PHASED_CHANGE_STEP          5
58 #define LCD_PHASED_DELAY                10000   /* microsecond */
59 #define DUMP_MODE_WAITING_TIME          600000  /* milisecond */
60
61 #define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so"
62
63 #define GESTURE_STR                     "gesture"
64 #define POWERKEY_STR                    "powerkey"
65 #define EVENT_STR                       "event"
66 #define TOUCH_STR                       "touch"
67 #define BEZEL_STR                       "bezel"
68 #define TIMEOUT_STR                     "timeout"
69 #define PROXIMITY_STR                   "proximity"
70 #define PALM_STR                        "palm"
71 #define UNKNOWN_STR                     "unknown"
72
73 #define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state"
74
75
76 static struct _backlight_ops backlight_ops;
77 static struct battery_plugin *battery_plgn;
78 static bool custom_status;
79 static int custom_brightness;
80 static int force_brightness;
81 static int default_brightness;
82 static int dpms_running_state = DPMS_SETTING_DONE;
83 static bool display_dev_available = false;
84 static guint release_timer;
85 static int aod_max_level = -1;
86 static int aod_normal_level = -1;
87 static int aod_min_level = -1;
88 static int aod_charging_level = -1;
89 static const struct display_config *display_conf;
90 static struct battery_status *battery = NULL;
91 static struct battery_status* (*fp_get_var_battery_status)(void);
92
93 inline struct _backlight_ops *get_var_backlight_ops(void)
94 {
95         return &backlight_ops;
96 }
97
98 bool display_dev_ready(void)
99 {
100         return display_dev_available;
101 }
102
103 void dpms_set_running_state(int val)
104 {
105         dpms_running_state = val;
106 }
107
108 static int bl_onoff(int on, enum device_flags flags)
109 {
110         dpms_set_state(on);
111
112 #ifdef ENABLE_PM_LOG
113         if (on == DPMS_ON)
114                 pm_history_save(PM_LOG_LCD_ON_COMPLETE, get_pm_cur_state());
115         else if (on == DPMS_OFF || on == DPMS_FORCE_OFF)
116                 pm_history_save(PM_LOG_LCD_OFF_COMPLETE, get_pm_cur_state());
117         else
118                 pm_history_save(PM_LOG_LCD_CONTROL_FAIL, on);
119 #endif
120
121         return 0;
122 }
123
124 static int bl_brt(int brightness, int delay)
125 {
126         int ret = -1;
127
128         if (delay > 0)
129                 usleep(delay);
130
131         /* Update device brightness */
132         ret = backlight_ops.set_brightness(brightness);
133
134         _I("Set brightness(%d): %d", brightness, ret);
135
136         return ret;
137 }
138
139 static int get_lcd_power_node(void)
140 {
141         int ret;
142         enum display_state val;
143
144         ret = hal_device_display_get_state(&val);
145         if (ret < 0)
146                 return ret;
147
148         if (val == DISPLAY_ON && ambient_get_state())
149                 return DPMS_OFF;
150
151         if (dpms_running_state != DPMS_SETTING_DONE)
152                 return dpms_running_state;
153
154         switch (val) {
155                 case DISPLAY_ON:
156                         return DPMS_ON;
157                 case DISPLAY_STANDBY:
158                         return DPMS_STANDBY;
159                 case DISPLAY_SUSPEND:
160                         return DPMS_SUSPEND;
161                 case DISPLAY_OFF:
162                         return DPMS_OFF;
163                 case DISPLAY_DETACH:
164                         return DPMS_DETACH;
165                 default:
166                         return -EINVAL;
167         }
168 }
169
170 bool display_dimstay_check(void)
171 {
172         if (get_pm_status_flag() & DIM_FLAG)
173                 return true;
174
175         return false;
176 }
177
178 static void change_brightness(int start, int end, int step)
179 {
180         int diff, val;
181         int ret = -1;
182         int prev;
183
184         if (display_dimstay_check())
185                 return;
186
187         ret = backlight_ops.get_brightness(&prev);
188         if (ret < 0) {
189                 _E("Failed to get brightness: %d", ret);
190                 return;
191         }
192
193         if (prev == end)
194                 return;
195
196         if (get_pm_status_flag() & DIM_MASK)
197                 end = 0;
198
199         _I("start %d end %d step %d", start, end, step);
200
201         if (display_dev_available) {
202                 ret = hal_device_display_set_multi_brightness(end, step, LCD_PHASED_DELAY);
203                 if (ret != -ENODEV) {
204                         if (ret < 0)
205                                 _E("Failed to set_multi_brightness (%d)", ret);
206
207                         backlight_ops.set_brightness(end);
208
209                         return;
210                 }
211         }
212
213         diff = end - start;
214
215         if (abs(diff) < step)
216                 val = (diff > 0 ? 1 : -1);
217         else
218                 val = (int)ceil((double)diff / step);
219
220         while (start != end) {
221                 if (val == 0) break;
222
223                 start += val;
224                 if ((val > 0 && start > end) ||
225                     (val < 0 && start < end))
226                         start = end;
227
228                 bl_brt(start, LCD_PHASED_DELAY);
229         }
230 }
231
232 static int backlight_on(enum device_flags flags)
233 {
234         int ret = -1;
235         static int cnt;
236
237         _I("[DPMS XLIB Backlight] LCD on %#x cnt:%d", flags, cnt);
238
239         cnt++;
240         ret = bl_onoff(DPMS_ON, flags);
241 #ifdef ENABLE_PM_LOG
242         pm_history_save(PM_LOG_LCD_ON, get_pm_cur_state());
243 #endif
244
245         return ret;
246 }
247
248 static int backlight_off(enum device_flags flags)
249 {
250         int ret = -1;
251         static int cnt, ambient_cnt;
252
253         if (flags & AMBIENT_MODE) {
254                 _I("[DPMS XLIB Backlight] LCD suspend %#x cnt:%d", flags, ambient_cnt);
255                 ambient_cnt++;
256
257                 return 0;
258         }
259
260         _I("[DPMS XLIB Backlight] LCD off %#x cnt:%d", flags, cnt);
261         cnt++;
262
263         if (flags & LCD_PHASED_TRANSIT_MODE)
264                 backlight_ops.transit_brt(default_brightness,
265                     LCD_PHASED_MIN_BRIGHTNESS, LCD_PHASED_CHANGE_STEP);
266
267         if (flags & FORCE_OFF_MODE)
268                 ret = bl_onoff(DPMS_FORCE_OFF, flags);
269         else
270                 ret = bl_onoff(DPMS_OFF, flags);
271
272 #ifdef ENABLE_PM_LOG
273         pm_history_save(PM_LOG_LCD_OFF, get_pm_cur_state());
274 #endif
275
276         return ret;
277 }
278
279 static int backlight_dim(void)
280 {
281         int ret;
282
283         ret = backlight_ops.set_brightness(PM_DIM_BRIGHTNESS);
284 #ifdef ENABLE_PM_LOG
285         if (!ret)
286                 pm_history_save(PM_LOG_LCD_DIM, get_pm_cur_state());
287         else
288                 pm_history_save(PM_LOG_LCD_DIM_FAIL, get_pm_cur_state());
289 #endif
290         return ret;
291 }
292
293 static int set_custom_status(bool on)
294 {
295         custom_status = on;
296         return 0;
297 }
298
299 static bool get_custom_status(void)
300 {
301         return custom_status;
302 }
303
304 static int save_custom_brightness(void)
305 {
306         int ret, brightness;
307
308         ret = backlight_ops.get_brightness(&brightness);
309
310         custom_brightness = brightness;
311
312         return ret;
313 }
314
315 static int custom_backlight_update(void)
316 {
317         int ret = 0;
318
319         if (custom_brightness < PM_MIN_BRIGHTNESS ||
320             custom_brightness > PM_MAX_BRIGHTNESS)
321                 return -EINVAL;
322
323         if (display_dimstay_check())
324                 ret = backlight_dim();
325         else {
326                 _I("custom brightness restored! %d", custom_brightness);
327                 ret = backlight_ops.set_brightness(custom_brightness);
328         }
329
330         return ret;
331 }
332
333 static int set_force_brightness(int level)
334 {
335         if (level < 0 ||  level > PM_MAX_BRIGHTNESS)
336                 return -EINVAL;
337
338         force_brightness = level;
339
340         return 0;
341 }
342
343 static int backlight_update(void)
344 {
345         int ret = 0;
346         int brt;
347
348         if (get_custom_status()) {
349                 _I("custom brightness mode! brt no updated");
350                 return 0;
351         }
352         if (display_dimstay_check())
353                 ret = backlight_dim();
354         else {
355                 brt = backlight_ops.get_default_brt();
356                 ret = backlight_ops.set_brightness(brt);
357         }
358         return ret;
359 }
360
361 static int backlight_standby(int force)
362 {
363         int ret = -1;
364
365         if ((dpms_get_cached_state() == DPMS_ON) || force) {
366                 _I("LCD standby");
367                 ret = bl_onoff(DPMS_STANDBY, 0);
368         }
369
370         return ret;
371 }
372
373 static int set_default_brt(int level)
374 {
375         if (level < PM_MIN_BRIGHTNESS || level > PM_MAX_BRIGHTNESS)
376                 level = display_conf->pm_default_brightness;
377
378         default_brightness = level;
379
380         return 0;
381 }
382
383 static int get_default_brt(void)
384 {
385         return default_brightness;
386 }
387
388 static int get_max_brightness(void)
389 {
390         static int max = -1;
391         int ret;
392
393         if (max > 0)
394                 return max;
395
396         if (!display_dev_available) {
397                 _E("There is no HAL for display.");
398                 return -ENOENT;
399         }
400
401         ret = hal_device_display_get_max_brightness(&max);
402         if (ret < 0) {
403                 if (ret == -ENODEV) {
404                         _E("Get max brightness is not supported.");
405                         max = DEFAULT_DISPLAY_MAX_BRIGHTNESS;
406                         return max;
407                 } else {
408                         _E("Failed to get max brightness: %d", ret);
409                         return ret;
410                 }
411         }
412
413         return max;
414 }
415
416 static int set_brightness(int val)
417 {
418         int max;
419
420         if (!display_dev_available) {
421                 _E("There is no display device.");
422                 return -ENOENT;
423         }
424
425         max = get_max_brightness();
426         if (max < 0) {
427                 _E("Failed to get max brightness.");
428                 return max;
429         }
430
431         if (force_brightness > 0 && val != PM_DIM_BRIGHTNESS) {
432                 _I("brightness(%d), force brightness(%d)",
433                     val, force_brightness);
434                 val = force_brightness;
435         }
436
437         if (get_pm_status_flag() & DIM_MASK)
438                 val = 0;
439
440         /* Maximum Brightness to users is 100.
441          * Thus real brightness need to be calculated */
442         val = val * max / 100;
443
444         update_bds_brightness_record(val);
445         _I("set brightness %d (default:%d)", val, default_brightness);
446         device_notify(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, (void *)&val);
447
448         return hal_device_display_set_brightness(val);
449 }
450
451 static int get_brt_normalized(int brt_raw)
452 {
453         int quotient, remainder;
454         int max;
455
456         max = get_max_brightness();
457         if (max < 0) {
458                 _E("Failed to get max brightness.");
459                 return max;
460         }
461
462         /* Maximum Brightness to users is 100.
463          * Thus the brightness value need to be calculated using real brightness.
464          *    ex) Let's suppose that the maximum brightness of driver is 255.
465          *      case 1) When the user sets the brightness to 41,
466          *              real brightness is
467          *                 41 * 255 / 100 = 104.55 = 104 (rounded off)
468          *      case 2) When the user gets the brightness,
469          *              the driver returns the brightness 104.
470          *              Thus the brightness to users is
471          *                 104 * 100 / 255 = 40.7843.... = 41 (rounded up)
472          */
473         quotient = brt_raw * 100 / max;
474         remainder = brt_raw * 100 % max;
475         if (remainder > 0)
476                 quotient++;
477
478         return quotient;
479 }
480
481 static int get_brightness(int *val)
482 {
483         int brt, ret;
484
485         if (!display_dev_available) {
486                 _E("There is no display device.");
487                 return -ENOENT;
488         }
489
490         ret = hal_device_display_get_brightness(&brt);
491         if (ret < 0) {
492                 if (ret == -ENODEV)
493                         _E("Get brightness is not supported.");
494                 else
495                         _E("Failed to get brightness: %d", ret);
496
497                 return ret;
498         }
499
500         *val = get_brt_normalized(brt);
501         return 0;
502 }
503
504 static int get_brightness_by_light_sensor(float lmax, float lmin, float light, int *brt)
505 {
506         int brt_raw;
507         int ret;
508
509         if (!display_dev_available)
510                 return -ENOTSUP;
511
512         ret = hal_device_display_get_auto_brightness(lmax, lmin, light, &brt_raw);
513         if (ret < 0) {
514                 if (ret == -ENODEV)
515                         _E("Get auto brightness is not supported.");
516                 else
517                         _E("Failed to get brightness by light sensor: %d", ret);
518
519                 return ret;
520         }
521
522         *brt = get_brt_normalized(brt_raw);
523         return 0;
524 }
525
526 static int get_image_effect(enum display_image_effect *effect)
527 {
528         int ret;
529         enum display_image_effect val;
530
531         if (!display_dev_available) {
532                 _E("There is no display device.");
533                 return -ENOENT;
534         }
535
536         ret = hal_device_display_get_image_effect(&val);
537         if (ret < 0) {
538                 if (ret == -ENODEV)
539                         _E("Get image effect is not supported.");
540                 else
541                         _E("Failed to get image effect: %d", ret);
542
543                 return ret;
544         }
545
546         *effect = val;
547
548         return 0;
549 }
550
551 static int set_image_effect(enum display_image_effect effect)
552 {
553         int ret;
554
555         if (!display_dev_available) {
556                 _E("There is no display device.");
557                 return -ENOENT;
558         }
559
560         ret = hal_device_display_set_image_effect(effect);
561         if (ret < 0) {
562                 if (ret == -ENODEV)
563                         _E("Set image effect is not supported.");
564                 else
565                         _E("Failed to set image effect: %d", ret);
566
567                 return ret;
568         }
569
570         return 0;
571 }
572
573 static int get_panel_mode(enum display_panel_mode *mode)
574 {
575         int ret;
576         enum display_panel_mode val;
577
578         if (!display_dev_available) {
579                 _E("There is no display device.");
580                 return -ENOENT;
581         }
582
583         ret = hal_device_display_get_panel_mode(&val);
584         if (ret < 0) {
585                 if (ret == -ENODEV)
586                         _E("Get panel mode is not supported.");
587                 else
588                         _E("Failed to get panel mode(%d)", ret);
589
590                 return ret;
591         }
592
593         *mode = val;
594
595         return 0;
596 }
597
598 static int set_panel_mode(enum display_panel_mode mode)
599 {
600         int ret;
601
602         if (!display_dev_available) {
603                 _E("There is no display device.");
604                 return -ENOENT;
605         }
606
607         ret = hal_device_display_set_panel_mode(mode);
608         if (ret < 0) {
609                 if (ret == -ENODEV)
610                         _E("Set panel mode is not supported.");
611                 else
612                         _E("Failed to set panel mode(%d)", ret);
613
614                 return ret;
615         }
616
617         return 0;
618 }
619
620 static int get_frame_rate(int *rate)
621 {
622         if (!rate)
623                 return -EINVAL;
624
625         if (!display_dev_available)
626                 return -ENOTSUP;
627
628         return hal_device_display_get_frame_rate(rate);
629 }
630
631 static int set_frame_rate(int rate)
632 {
633         int ret = 0;
634         static int fmin = -1, fmax = -1;
635
636         if (!display_dev_available)
637                 return -ENOTSUP;
638
639         if (fmin < 0) {
640                 ret = hal_device_display_get_min_frame_rate(&fmin);
641                 if (ret < 0) {
642                         _E("Failed to get min frate rate: %d", ret);
643                         return ret;
644                 }
645         }
646         if ((ret != -ENODEV) && (rate < fmin)) {
647                 _E("Invalid rate(%d). (Valid rate: %d <= rate)", rate, fmin);
648                 return -EINVAL;
649         }
650
651         if (fmax < 0) {
652                 ret = hal_device_display_get_max_frame_rate(&fmax);
653                 if (ret < 0) {
654                         _E("Failed to get max frate rate: %d", ret);
655                         return ret;
656                 }
657         }
658         if ((ret != -ENODEV) && (rate > fmax)) {
659                 _E("Invalid rate(%d). (Valid rate: rate <= %d)", rate, fmax);
660                 return -EINVAL;
661         }
662
663         return hal_device_display_set_frame_rate(rate);
664 }
665
666 /* It was operated only AOD enter & leave */
667 static int backlight_transit_state(int state)
668 {
669         int brt, val;
670         int start, end;
671         static int aod_brightness_level;
672
673         backlight_ops.get_brightness(&brt);
674
675         if (state == DPMS_OFF) {
676                 start = brt;
677
678                 /*
679                  * The value of backlight_ops.get_brightness is system brightness.
680                  * But when device is LBM, the value is not same with real brightness.
681                  * So it should be read exactly value for transit smooth effect
682                  */
683                 get_brightness(&val);
684
685                 /* AOD brightness
686                  *
687                  * Compare current brightness with threshold based on charger's charging state.
688                  * Charger charging state has 2 threshold: CHARGING, MIN
689                  * The other states has 3 threshold: MAX, NORMAL, MIN
690                  *
691                  * Select the highest threshold among the thresholds less then the current brightness.
692                  * If current brightness is less then MIN threshold, do not transit brightness.
693                  *
694                  * e.g.
695                  * threshold for    | threshold for
696                  * charger CHARGING | the other charger states
697                  *                  |
698                  *                  |
699                  *                  |-----MAX(50)
700                  *                  |
701                  *                  |-----NORMAL(40)
702                  *                  |
703                  *                  |
704                  * CHARGING(20)-----|
705                  *                  |
706                  *      MIN(10)-----|-----MIN(10)
707                  *  if DISCHARGING and current brightness is 30, then AOD brightness will be 10.
708                  *  if DISCHARGING and current brightness is 45, then AOD brightness will be 40.
709                  *  if CHARGING and current brightness is 80, then AOD brightness will be 20.
710                  *  if current brightness is 5, do not transit brightness.
711                  */
712                 if (aod_min_level > 0 && val < aod_min_level) {
713                         _W("Current brightness is already lower than minimum threshold.");
714                         return 0;
715                 }
716
717                 if (battery && battery->charge_now == CHARGER_CHARGING) {
718                         if (aod_charging_level > 0 && val >= aod_charging_level)
719                                 aod_brightness_level = aod_charging_level;
720                         else if (aod_min_level > 0 && val >= aod_min_level)
721                                 aod_brightness_level = aod_min_level;
722                         else
723                                 aod_brightness_level = display_conf->aod_enter_level;
724                 } else {
725                         if (aod_max_level > 0 && val >= aod_max_level)
726                                 aod_brightness_level = aod_max_level;
727                         else if (aod_normal_level > 0 && val >= aod_normal_level)
728                                 aod_brightness_level = aod_normal_level;
729                         else if (aod_min_level > 0 && val >= aod_min_level)
730                                 aod_brightness_level = aod_min_level;
731                         else
732                                 aod_brightness_level = display_conf->aod_enter_level;
733                 }
734
735                 if (val > aod_brightness_level) {
736                         _D("backlight transit start %d end %d DPMS OFF", start, aod_brightness_level);
737                         backlight_ops.transit_brt(start, aod_brightness_level, display_conf->brightness_change_step);
738                 }
739         } else {
740                 /* prevent transit effect when another effect is already executed */
741                 if (brt != aod_brightness_level) {
742                         _W("effect is already executed brt(%d) aod_level(%d)",
743                                         brt, aod_brightness_level);
744                         return 0;
745                 }
746
747                 start = aod_brightness_level;
748                 end = default_brightness;
749                 _D("backlight transit start %d end %d DPMS ON", start, end);
750                 backlight_ops.transit_brt(start, end, display_conf->brightness_change_step);
751         }
752
753         return 0;
754 }
755
756 static gboolean blink_cb(gpointer data)
757 {
758         static bool flag;
759
760         set_brightness(flag ? PM_MAX_BRIGHTNESS : PM_MIN_BRIGHTNESS);
761
762         flag = !flag;
763
764         return G_SOURCE_CONTINUE;
765 }
766
767 static void blink(int timeout)
768 {
769         static guint timer;
770
771         if (timer) {
772                 g_source_remove(timer);
773                 timer = 0;
774         }
775
776         if (timeout < 0) {
777                 _E("timeout value is invalid %d", timeout);
778                 return;
779         }
780
781         if (timeout == 0) {
782                 backlight_update();
783                 return;
784         }
785
786         timer = g_timeout_add(timeout, blink_cb, NULL);
787 }
788
789 static gboolean release_blink_cb(gpointer data)
790 {
791         blink(0);
792
793         release_timer = 0;
794         return G_SOURCE_REMOVE;
795 }
796
797 static void release_blink(void)
798 {
799         if (release_timer) {
800                 g_source_remove(release_timer);
801                 release_timer = 0;
802         }
803
804         release_timer = g_timeout_add(DUMP_MODE_WAITING_TIME, release_blink_cb, NULL);
805 }
806
807 static void restore_brightness_func(void)
808 {
809         backlight_ops.set_brightness = set_brightness;
810         backlight_ops.get_brightness = get_brightness;
811         backlight_ops.transit_brt = change_brightness;
812 }
813
814 static struct _backlight_ops backlight_ops = {
815         .off = backlight_off,
816         .dim = backlight_dim,
817         .on = backlight_on,
818         .update = backlight_update,
819         .standby = backlight_standby,
820         .set_default_brt = set_default_brt,
821         .get_default_brt = get_default_brt,
822         .get_lcd_power = dpms_get_cached_state,
823         .get_lcd_power_node = get_lcd_power_node,
824         .set_custom_status = set_custom_status,
825         .get_custom_status = get_custom_status,
826         .save_custom_brightness = save_custom_brightness,
827         .custom_update = custom_backlight_update,
828         .set_force_brightness = set_force_brightness,
829         .set_brightness = set_brightness,
830         .get_brightness = get_brightness,
831         .restore_brightness_func = restore_brightness_func,
832         .get_brightness_by_light_sensor = get_brightness_by_light_sensor,
833         .get_image_effect = get_image_effect,
834         .set_image_effect = set_image_effect,
835         .get_panel_mode = get_panel_mode,
836         .set_panel_mode = set_panel_mode,
837         .get_frame_rate = get_frame_rate,
838         .set_frame_rate = set_frame_rate,
839         .transit_state = backlight_transit_state,
840         .transit_brt = change_brightness,
841         .blink = blink,
842         .release_blink = release_blink,
843         /* auto-test only function */
844         .get_brightness_raw = get_brightness, /* always fetch brightness from node even LBM mode */
845 };
846
847 int display_service_load(void)
848 {
849         int r;
850
851         if (display_dev_available)
852                 return 0;
853
854         r = hal_device_display_get_backend();
855         if (r < 0) {
856                 _E("There is no HAL for display.");
857                 display_dev_available = false;
858                 display_set_hal_backend_available(display_dev_available);
859                 return 0;
860         }
861
862         display_dev_available = true;
863         display_set_hal_backend_available(display_dev_available);
864         _D("Display device structure load success.");
865         return 0;
866 }
867
868 int display_service_free(void)
869 {
870         display_dev_available = false;
871         return hal_device_display_put_backend();
872 }
873
874 int is_lcdon_blocked(void)
875 {
876         int state = backlight_ops.get_lcd_power();
877
878         if ((state == DPMS_DETACH) || (state == -EINVAL))
879                 return LCDON_BLOCK_WHEN_DISPLAY_DETACHED;
880
881         return LCDON_BLOCK_NONE;
882 }
883
884 int init_sysfs(unsigned int flags)
885 {
886         register_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed);
887
888         if (battery_plgn->handle) {
889                 fp_get_var_battery_status = dlsym(battery_plgn->handle, "get_var_battery_status");
890                 if (fp_get_var_battery_status) {
891                         battery = fp_get_var_battery_status();
892                         if (!battery)
893                                 _E("Failed to get battery status.");
894                 } else
895                         _E("Failed to obtain address of get_var_battery_status, %s.", dlerror());
896         } else
897                  _I("There is no battery module.");
898
899         return 0;
900 }
901
902 int exit_sysfs(void)
903 {
904         const struct device_ops *ops = NULL;
905
906         backlight_update();
907
908         exit_dpms();
909
910         ops = find_device("touchscreen");
911         if (!check_default(ops))
912                 ops->start(NORMAL_MODE);
913
914         unregister_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed);
915
916         return 0;
917 }
918
919 static void __CONSTRUCTOR__ initialize(void)
920 {
921         display_conf = get_var_display_config();
922         if (!display_conf)
923                 _E("Failed to get display configuration variable.");
924
925         battery_plgn = get_var_battery_plugin();
926         if (!battery_plgn)
927                 _E("Failed to get battery plugin variable.");
928 }