Of course there's no mdelay on c200(v1), so just use udelay
[kugel-rb.git] / firmware / target / arm / ipod / backlight-4g_color.c
bloba0e14c99e3d054eb704c848fa0ebf13b0442a379
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 /* Index 0 is a dummy, 1..31 are used */
38 static unsigned char log_brightness[32] = {
39 0, 1, 2, 4, 6, 9, 12, 16, 20, 25, 30, 36,
40 42, 49, 56, 64, 72, 81, 90, 100, 110, 121, 132, 144,
41 156, 169, 182, 196, 210, 225, 240, 255
44 static unsigned brightness = 100; /* 1 to 255 */
45 static bool enabled = false;
47 /* Handling B03 in _backlight_on() and _backlight_off() makes backlight go off
48 * without delay. Not doing that does a short (fixed) fade out. Opt for the
49 * latter. */
51 void _backlight_on(void)
53 /* brightness full */
54 outl(0x80000000 | (brightness << 16), 0x7000a010);
55 /* GPIO_SET_BITWISE(GPIOB_OUTPUT_VAL, 0x08); */
56 enabled = true;
59 void _backlight_off(void)
61 outl(0x80000000, 0x7000a010);
62 /* GPIO_CLEAR_BITWISE(GPIOB_OUTPUT_VAL, 0x08); */
63 enabled = false;
66 void _backlight_set_brightness(int val)
68 brightness = log_brightness[val];
69 if (enabled)
70 outl(0x80000000 | (brightness << 16), 0x7000a010);
73 bool _backlight_init(void)
75 GPIO_SET_BITWISE(GPIOB_ENABLE, 0x0c); /* B02 and B03 enable */
76 GPIO_SET_BITWISE(GPIOB_OUTPUT_VAL, 0x08); /* B03 = 1 */
77 GPO32_ENABLE &= ~0x2000000; /* D01 disable, so pwm takes over */
78 DEV_EN |= DEV_PWM; /* PWM enable */
80 _backlight_on();
81 return true;