summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/samsungypr/ypr0/backlight-ypr0.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/samsungypr/ypr0/backlight-ypr0.c')
-rw-r--r--firmware/target/hosted/samsungypr/ypr0/backlight-ypr0.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/firmware/target/hosted/samsungypr/ypr0/backlight-ypr0.c b/firmware/target/hosted/samsungypr/ypr0/backlight-ypr0.c
new file mode 100644
index 0000000000..551b386f19
--- /dev/null
+++ b/firmware/target/hosted/samsungypr/ypr0/backlight-ypr0.c
@@ -0,0 +1,88 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2011 by Lorenzo Miori
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20#include "config.h"
21#include "system.h"
22#include "backlight.h"
23#include "backlight-target.h"
24#include "lcd.h"
25#include "as3514.h"
26#include "ascodec.h"
27#include <fcntl.h>
28#include "unistd.h"
29
30static bool backlight_on_status = true; /* Is on or off? */
31
32/*TODO: see if LCD sleep could be implemented in a better way -> ie using a rockbox feature */
33/* Turn off LCD power supply */
34static void _backlight_lcd_sleep(void)
35{
36 int fp = open("/sys/class/graphics/fb0/blank", O_RDWR);
37 write(fp, "1", 1);
38 close(fp);
39}
40/* Turn on LCD screen */
41static void _backlight_lcd_power(void)
42{
43 int fp = open("/sys/class/graphics/fb0/blank", O_RDWR);
44 write(fp, "0", 1);
45 close(fp);
46}
47
48bool _backlight_init(void)
49{
50 /* We have nothing to do */
51 return true;
52}
53
54void _backlight_on(void)
55{
56 if (!backlight_on_status)
57 {
58 /* Turn on lcd power before backlight */
59 _backlight_lcd_power();
60 /* Original app sets this to 0xb1 when backlight is on... */
61 ascodec_write_pmu(AS3543_BACKLIGHT, 0x1, 0xb1);
62 }
63
64 backlight_on_status = true;
65
66}
67
68void _backlight_off(void)
69{
70 if (backlight_on_status) {
71 /* Disabling the DCDC15 completely, keeps brightness register value */
72 ascodec_write_pmu(AS3543_BACKLIGHT, 0x1, 0x00);
73 /* Turn off lcd power then */
74 _backlight_lcd_sleep();
75 }
76
77 backlight_on_status = false;
78}
79
80void _backlight_set_brightness(int brightness)
81{
82 /* Just another check... */
83 if (brightness > MAX_BRIGHTNESS_SETTING)
84 brightness = MAX_BRIGHTNESS_SETTING;
85 if (brightness < MIN_BRIGHTNESS_SETTING)
86 brightness = MIN_BRIGHTNESS_SETTING;
87 ascodec_write_pmu(AS3543_BACKLIGHT, 0x3, brightness << 3 & 0xf8);
88}