Fix non-integer display_zoom for charcell.
[maemo-rb.git] / firmware / target / hosted / ypr0 / backlight-ypr0.c
blob551b386f1929e4d9c3b41c48c207896f3540271c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2011 by Lorenzo Miori
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.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
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"
30 static bool backlight_on_status = true; /* Is on or off? */
32 /*TODO: see if LCD sleep could be implemented in a better way -> ie using a rockbox feature */
33 /* Turn off LCD power supply */
34 static void _backlight_lcd_sleep(void)
36 int fp = open("/sys/class/graphics/fb0/blank", O_RDWR);
37 write(fp, "1", 1);
38 close(fp);
40 /* Turn on LCD screen */
41 static void _backlight_lcd_power(void)
43 int fp = open("/sys/class/graphics/fb0/blank", O_RDWR);
44 write(fp, "0", 1);
45 close(fp);
48 bool _backlight_init(void)
50 /* We have nothing to do */
51 return true;
54 void _backlight_on(void)
56 if (!backlight_on_status)
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);
64 backlight_on_status = true;
68 void _backlight_off(void)
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();
77 backlight_on_status = false;
80 void _backlight_set_brightness(int brightness)
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);