Submit FS#9890 by Boris Gjenero. Enabling option for iPod Video to shut down LCD...
[kugel-rb.git] / firmware / target / arm / ipod / backlight-nano_video.c
blob2f56f942253017651a9b57b7bad06b8eeb4581cd
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
22 #include <stdlib.h>
23 #include "cpu.h"
24 #include "kernel.h"
25 #include "thread.h"
26 #include "i2c.h"
27 #include "debug.h"
28 #include "rtc.h"
29 #include "usb.h"
30 #include "power.h"
31 #include "system.h"
32 #include "button.h"
33 #include "timer.h"
34 #include "backlight.h"
35 #include "backlight-target.h"
37 static int brightness = 1; /* 1 to 32 */
38 static int current_dim = 16; /* default after enabling the backlight dimmer */
39 static bool enabled = false;
41 void _backlight_set_brightness(int val)
43 int oldlevel;
45 if (current_dim < val)
49 oldlevel = disable_irq_save();
50 GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x80);
51 udelay(10);
52 GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x80);
53 restore_irq(oldlevel);
54 udelay(10);
56 while (++current_dim < val);
58 else if (current_dim > val)
62 oldlevel = disable_irq_save();
63 GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x80);
64 udelay(200);
65 GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x80);
66 restore_irq(oldlevel);
67 udelay(10);
69 while (--current_dim > val);
71 brightness = val;
74 void _backlight_hw_enable(bool on)
76 #ifdef HAVE_LCD_SLEEP
77 if (on)
78 /* If the fade-out is interrupted, enabled will be true, but
79 lcd_awake() needs to be called anyways because the LCD
80 may be sleeping.
82 lcd_awake();
83 #endif
85 if (on == enabled)
86 return;
88 if (on)
90 GPIO_SET_BITWISE(GPIOB_OUTPUT_VAL, 0x08);
91 GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x80);
92 sleep(HZ/100);
93 current_dim = 16;
94 _backlight_set_brightness(brightness);
96 else
98 GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x80);
99 GPIO_CLEAR_BITWISE(GPIOB_OUTPUT_VAL, 0x08);
100 sleep(HZ/20);
102 enabled = on;
105 /* Switch the backlight on. Works only if the backlight circuit is enabled.
106 * Called in ISR context for fading, so it must be fast. */
107 void _backlight_led_on(void)
109 GPIO_SET_BITWISE(GPIOL_OUTPUT_VAL, 0x80);
112 /* Switch the backlight off. Keeps the backlight circuit enabled.
113 * Called in ISR context for fading, so it must be fast. */
114 void _backlight_led_off(void)
116 GPIO_CLEAR_BITWISE(GPIOL_OUTPUT_VAL, 0x80);
119 bool _backlight_init(void)
121 GPIO_SET_BITWISE(GPIOB_ENABLE, 0x08);
122 GPIO_SET_BITWISE(GPIOB_OUTPUT_EN, 0x08);
123 GPIO_SET_BITWISE(GPIOD_ENABLE, 0x80);
124 GPIO_SET_BITWISE(GPIOD_OUTPUT_EN, 0x80);
125 _backlight_hw_enable(true);
126 GPIO_SET_BITWISE(GPIOL_ENABLE, 0x80);
127 GPIO_SET_BITWISE(GPIOL_OUTPUT_EN, 0x80);
128 GPIO_SET_BITWISE(GPIOL_OUTPUT_VAL, 0x80);
130 return true;