summaryrefslogtreecommitdiff
path: root/firmware/target/arm/philips/sa9200
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/philips/sa9200')
-rw-r--r--firmware/target/arm/philips/sa9200/adc-target.h43
-rw-r--r--firmware/target/arm/philips/sa9200/backlight-sa9200.c75
-rw-r--r--firmware/target/arm/philips/sa9200/backlight-target.h30
-rwxr-xr-xfirmware/target/arm/philips/sa9200/button-sa9200.c72
-rwxr-xr-xfirmware/target/arm/philips/sa9200/button-target.h53
-rwxr-xr-xfirmware/target/arm/philips/sa9200/lcd-sa9200.c205
-rw-r--r--firmware/target/arm/philips/sa9200/power-sa9200.c136
-rw-r--r--firmware/target/arm/philips/sa9200/powermgmt-sa9200.c58
8 files changed, 672 insertions, 0 deletions
diff --git a/firmware/target/arm/philips/sa9200/adc-target.h b/firmware/target/arm/philips/sa9200/adc-target.h
new file mode 100644
index 0000000000..56efdf7574
--- /dev/null
+++ b/firmware/target/arm/philips/sa9200/adc-target.h
@@ -0,0 +1,43 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Barry Wardell
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifndef _ADC_TARGET_H_
20#define _ADC_TARGET_H_
21
22/* ADC channels */
23#define NUM_ADC_CHANNELS 13
24
25#define ADC_BVDD 0 /* Battery voltage of 4V LiIo accumulator */
26#define ADC_RTCSUP 1 /* RTC backup battery voltage */
27#define ADC_UVDD 2 /* USB host voltage */
28#define ADC_CHG_IN 3 /* Charger input voltage */
29#define ADC_CVDD 4 /* Charger pump output voltage */
30#define ADC_BATTEMP 5 /* Battery charging temperature */
31#define ADC_MICSUP1 6 /* Voltage on MicSup1 for remote control
32 or external voltage measurement */
33#define ADC_MICSUP2 7 /* Voltage on MicSup1 for remote control
34 or external voltage measurement */
35#define ADC_VBE1 8 /* Measuring junction temperature @ 2uA */
36#define ADC_VBE2 9 /* Measuring junction temperature @ 1uA */
37#define ADC_I_MICSUP1 10 /* Current of MicSup1 for remote control detection */
38#define ADC_I_MICSUP2 11 /* Current of MicSup2 for remote control detection */
39#define ADC_VBAT 12 /* Single cell battery voltage */
40
41#define ADC_UNREG_POWER ADC_BVDD /* For compatibility */
42
43#endif
diff --git a/firmware/target/arm/philips/sa9200/backlight-sa9200.c b/firmware/target/arm/philips/sa9200/backlight-sa9200.c
new file mode 100644
index 0000000000..aaec8cf007
--- /dev/null
+++ b/firmware/target/arm/philips/sa9200/backlight-sa9200.c
@@ -0,0 +1,75 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Barry Wardell
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include "backlight-target.h"
21#include "system.h"
22#include "lcd.h"
23#include "backlight.h"
24#include "i2c-pp.h"
25#include "as3514.h"
26
27static unsigned short backlight_brightness = DEFAULT_BRIGHTNESS_SETTING;
28
29void _backlight_set_brightness(int brightness)
30{
31 backlight_brightness = brightness;
32
33 if (brightness > 0)
34 _backlight_on();
35 else
36 _backlight_off();
37}
38
39void _backlight_on(void)
40{
41#ifdef HAVE_LCD_SLEEP
42 backlight_lcd_sleep_countdown(false); /* stop counter */
43#endif
44#ifdef HAVE_LCD_ENABLE
45 lcd_enable(true); /* power on lcd + visible display */
46#endif
47 pp_i2c_send(AS3514_I2C_ADDR, AS3514_DCDC15, backlight_brightness);
48}
49
50void _backlight_off(void)
51{
52 pp_i2c_send(AS3514_I2C_ADDR, AS3514_DCDC15, 0x0);
53#ifdef HAVE_LCD_ENABLE
54 lcd_enable(false); /* power off visible display */
55#endif
56#ifdef HAVE_LCD_SLEEP
57 backlight_lcd_sleep_countdown(true); /* start countdown */
58#endif
59}
60
61void _buttonlight_on(void)
62{
63 GPIO_SET_BITWISE(GPIOG_OUTPUT_VAL, 0x80);
64#ifdef SANSA_C200
65 GPIO_SET_BITWISE(GPIOB_OUTPUT_VAL, 0x10); /* The "menu" backlight */
66#endif
67}
68
69void _buttonlight_off(void)
70{
71 GPIO_CLEAR_BITWISE(GPIOG_OUTPUT_VAL, 0x80);
72#ifdef SANSA_C200
73 GPIO_CLEAR_BITWISE(GPIOB_OUTPUT_VAL, 0x10); /* The "menu" backlight */
74#endif
75}
diff --git a/firmware/target/arm/philips/sa9200/backlight-target.h b/firmware/target/arm/philips/sa9200/backlight-target.h
new file mode 100644
index 0000000000..01573b8403
--- /dev/null
+++ b/firmware/target/arm/philips/sa9200/backlight-target.h
@@ -0,0 +1,30 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Barry Wardell
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifndef BACKLIGHT_TARGET_H
20#define BACKLIGHT_TARGET_H
21
22#define _backlight_init() true
23void _backlight_on(void);
24void _backlight_off(void);
25void _backlight_set_brightness(int brightness);
26int __backlight_is_on(void);
27
28void _buttonlight_on(void);
29void _buttonlight_off(void);
30#endif
diff --git a/firmware/target/arm/philips/sa9200/button-sa9200.c b/firmware/target/arm/philips/sa9200/button-sa9200.c
new file mode 100755
index 0000000000..dc9f3466c2
--- /dev/null
+++ b/firmware/target/arm/philips/sa9200/button-sa9200.c
@@ -0,0 +1,72 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Mark Arigo
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "system.h"
21#include "button.h"
22#include "backlight.h"
23
24void button_init_device(void)
25{
26 /* TODO...for now, hardware initialisation is done by the c200 bootloader */
27}
28
29bool button_hold(void)
30{
31 return !(GPIOL_INPUT_VAL & 0x40);
32}
33
34/*
35 * Get button pressed from hardware
36 */
37int button_read_device(void)
38{
39 int btn = BUTTON_NONE;
40 static bool hold_button = false;
41 bool hold_button_old;
42
43 /* Hold */
44 hold_button_old = hold_button;
45 hold_button = button_hold();
46
47#ifndef BOOTLOADER
48 if (hold_button != hold_button_old)
49 backlight_hold_changed(hold_button);
50#endif
51
52 /* device buttons */
53 if (!hold_button)
54 {
55#if 0
56 if (!(GPIOB_INPUT_VAL & 0x20)) btn |= BUTTON_POWER;
57 if (!(GPIOF_INPUT_VAL & 0x10)) btn |= BUTTON_VOL_UP;
58 if (!(GPIOF_INPUT_VAL & 0x04)) btn |= BUTTON_VOL_DOWN;
59#endif
60 /* A hack until the touchpad works */
61 if (!(GPIOB_INPUT_VAL & 0x20)) btn |= BUTTON_SELECT;
62 if (!(GPIOF_INPUT_VAL & 0x10)) btn |= BUTTON_UP;
63 if (!(GPIOF_INPUT_VAL & 0x04)) btn |= BUTTON_DOWN;
64 }
65
66 return btn;
67}
68
69bool headphones_inserted(void)
70{
71 return (GPIOB_INPUT_VAL & 0x10) ? false : true;
72}
diff --git a/firmware/target/arm/philips/sa9200/button-target.h b/firmware/target/arm/philips/sa9200/button-target.h
new file mode 100755
index 0000000000..1cd6e52097
--- /dev/null
+++ b/firmware/target/arm/philips/sa9200/button-target.h
@@ -0,0 +1,53 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id:$
9 *
10 * Copyright (C) 2007 by Mark Arigo
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef _BUTTON_TARGET_H_
21#define _BUTTON_TARGET_H_
22
23#include <stdbool.h>
24#include "config.h"
25
26#define HAS_BUTTON_HOLD
27
28bool button_hold(void);
29void button_init_device(void);
30int button_read_device(void);
31
32/* Main unit's buttons */
33#define BUTTON_POWER 0x00000001
34#define BUTTON_SELECT 0x00000002
35#define BUTTON_MENU 0x00000004
36#define BUTTON_LEFT 0x00000008
37#define BUTTON_RIGHT 0x00000010
38#define BUTTON_REW 0x00000020
39#define BUTTON_FFWD 0x00000040
40#define BUTTON_UP 0x00000080
41#define BUTTON_DOWN 0x00000100
42#define BUTTON_VOL_UP 0x00000200
43#define BUTTON_VOL_DOWN 0x00000400
44
45#define BUTTON_MAIN 0x00000fff
46
47/* No Remote control */
48#define BUTTON_REMOTE 0
49
50#define POWEROFF_BUTTON BUTTON_POWER
51#define POWEROFF_COUNT 10
52
53#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/arm/philips/sa9200/lcd-sa9200.c b/firmware/target/arm/philips/sa9200/lcd-sa9200.c
new file mode 100755
index 0000000000..b06dcd952b
--- /dev/null
+++ b/firmware/target/arm/philips/sa9200/lcd-sa9200.c
@@ -0,0 +1,205 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Mark Arigo
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include "cpu.h"
21#include "lcd.h"
22#include "kernel.h"
23#include "system.h"
24
25/* Display status */
26static unsigned lcd_yuv_options SHAREDBSS_ATTR = 0;
27
28/* wait for LCD */
29static inline void lcd_wait_write(void)
30{
31 while (LCD1_CONTROL & LCD1_BUSY_MASK);
32}
33
34/* send LCD data */
35static void lcd_send_data(unsigned data)
36{
37 lcd_wait_write();
38 LCD1_DATA = data >> 8;
39 lcd_wait_write();
40 LCD1_DATA = data & 0xff;
41}
42
43/* send LCD command */
44static void lcd_send_command(unsigned cmd)
45{
46 lcd_wait_write();
47 LCD1_CMD = cmd >> 8;
48 lcd_wait_write();
49 LCD1_CMD = cmd & 0xff;
50}
51
52static void lcd_write_reg(unsigned reg, unsigned data)
53{
54 lcd_send_command(reg);
55 lcd_send_data(data);
56}
57
58void lcd_init_device(void)
59{
60#if 0
61 /* This is the init done by the OF bootloader.
62 Re-initializing the lcd causes it to flash
63 a white screen, so for now disable this. */
64 DEV_INIT1 &= ~0x3000;
65 DEV_INIT1 = DEV_INIT1;
66 DEV_INIT2 &= ~0x400;
67
68 LCD1_CONTROL = 0x4680;
69 udelay(1500);
70 LCD1_CONTROL = 0x4684;
71
72 outl(1, 0x70003018);
73
74 LCD1_CONTROL &= ~0x200;
75 LCD1_CONTROL &= ~0x800;
76 LCD1_CONTROL &= ~0x400;
77 udelay(30000);
78
79 LCD1_CONTROL |= 0x1;
80
81 lcd_write_reg(0x0000, 0x0001);
82 udelay(50000);
83
84 lcd_write_reg(0x0011, 0x171f);
85 lcd_write_reg(0x0012, 0x0001);
86 lcd_write_reg(0x0013, 0x08cd);
87 lcd_write_reg(0x0014, 0x0416);
88 lcd_write_reg(0x0010, 0x1208);
89 udelay(50000);
90
91 lcd_write_reg(0x0013, 0x081C);
92 udelay(200000);
93
94 lcd_write_reg(0x0001, 0x0a0c);
95 lcd_write_reg(0x0002, 0x0200);
96 lcd_write_reg(0x0003, 0x1030);
97 lcd_write_reg(0x0007, 0x0005);
98 lcd_write_reg(0x0008, 0x030a);
99 lcd_write_reg(0x000b, 0x0000);
100 lcd_write_reg(0x000c, 0x0000);
101 lcd_write_reg(0x0030, 0x0000);
102 lcd_write_reg(0x0031, 0x0204);
103 lcd_write_reg(0x0032, 0x0001);
104 lcd_write_reg(0x0033, 0x0600);
105 lcd_write_reg(0x0034, 0x0607);
106 lcd_write_reg(0x0035, 0x0305);
107 lcd_write_reg(0x0036, 0x0707);
108 lcd_write_reg(0x0037, 0x0006);
109 lcd_write_reg(0x0038, 0x0400);
110 lcd_write_reg(0x0040, 0x0000);
111 lcd_write_reg(0x0042, 0x9f00);
112 lcd_write_reg(0x0043, 0x0000);
113 lcd_write_reg(0x0044, 0x7f00);
114 lcd_write_reg(0x0045, 0x9f00);
115 lcd_write_reg(0x00a8, 0x0125);
116 lcd_write_reg(0x00a9, 0x0014);
117 lcd_write_reg(0x00a7, 0x0022);
118
119 lcd_write_reg(0x0007, 0x0021);
120 udelay(40000);
121 lcd_write_reg(0x0007, 0x0023);
122 udelay(40000);
123 lcd_write_reg(0x0007, 0x1037);
124
125 lcd_write_reg(0x0021, 0x0000);
126#endif
127}
128
129/*** hardware configuration ***/
130#if 0
131int lcd_default_contrast(void)
132{
133 return DEFAULT_CONTRAST_SETTING;
134}
135#endif
136
137void lcd_set_contrast(int val)
138{
139 (void)val;
140}
141
142void lcd_set_invert_display(bool yesno)
143{
144 (void)yesno;
145}
146
147/* turn the display upside down (call lcd_update() afterwards) */
148void lcd_set_flip(bool yesno)
149{
150 (void)yesno;
151}
152
153void lcd_yuv_set_options(unsigned options)
154{
155 lcd_yuv_options = options;
156}
157
158/* Performance function to blit a YUV bitmap directly to the LCD */
159void lcd_blit_yuv(unsigned char * const src[3],
160 int src_x, int src_y, int stride,
161 int x, int y, int width, int height)
162{
163 (void)src;
164 (void)src_x;
165 (void)src_y;
166 (void)stride;
167 (void)x;
168 (void)y;
169 (void)width;
170 (void)height;
171}
172
173/* Update the display.
174 This must be called after all other LCD functions that change the display. */
175void lcd_update(void)
176{
177 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
178}
179
180/* Update a fraction of the display. */
181void lcd_update_rect(int x, int y, int width, int height)
182{
183 const fb_data *addr;
184
185 if (x + width >= LCD_WIDTH)
186 width = LCD_WIDTH - x;
187 if (y + height >= LCD_HEIGHT)
188 height = LCD_HEIGHT - y;
189
190 if ((width <= 0) || (height <= 0))
191 return; /* Nothing left to do. */
192
193 addr = &lcd_framebuffer[y][x];
194
195 do {
196 lcd_write_reg(0x0021, ((y++ & 0xff) << 8) | (x & 0xff));
197 lcd_send_command(0x0022);
198
199 int w = width;
200 do {
201 lcd_send_data(*addr++);
202 } while (--w > 0);
203 addr += LCD_WIDTH - width;
204 } while (--height > 0);
205}
diff --git a/firmware/target/arm/philips/sa9200/power-sa9200.c b/firmware/target/arm/philips/sa9200/power-sa9200.c
new file mode 100644
index 0000000000..8c8214a7ce
--- /dev/null
+++ b/firmware/target/arm/philips/sa9200/power-sa9200.c
@@ -0,0 +1,136 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Daniel Ankers
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <stdbool.h>
21#include "system.h"
22#include "cpu.h"
23#include "i2c-pp.h"
24#include "tuner.h"
25#include "as3514.h"
26#include "power.h"
27
28void power_init(void)
29{
30}
31
32void power_off(void)
33{
34 char byte;
35
36 /* Send shutdown command to PMU */
37 byte = i2c_readbyte(AS3514_I2C_ADDR, AS3514_SYSTEM);
38 byte &= ~0x1;
39 pp_i2c_send(AS3514_I2C_ADDR, AS3514_SYSTEM, byte);
40
41 /* Stop interrupts on both cores */
42 disable_interrupt(IRQ_FIQ_STATUS);
43 COP_INT_CLR = -1;
44 CPU_INT_CLR = -1;
45
46 /* Halt everything and wait for device to power off */
47 while (1)
48 {
49 COP_CTL = 0x40000000;
50 CPU_CTL = 0x40000000;
51 }
52}
53
54bool charger_inserted(void)
55{
56#ifdef SANSA_E200
57 if(GPIOB_INPUT_VAL & 0x10)
58#else /* SANSA_C200 */
59 if(GPIOH_INPUT_VAL & 0x2)
60#endif
61 return true;
62 return false;
63}
64
65void ide_power_enable(bool on)
66{
67 (void)on;
68}
69
70#if CONFIG_TUNER
71
72/** Tuner **/
73static bool powered = false;
74
75bool tuner_power(bool status)
76{
77 bool old_status;
78 lv24020lp_lock();
79
80 old_status = powered;
81
82 if (status != old_status)
83 {
84 if (status)
85 {
86 /* init mystery amplification device */
87#if defined(SANSA_E200)
88 GPO32_ENABLE |= 0x1;
89#else /* SANSA_C200 */
90 DEV_INIT2 &= ~0x800;
91#endif
92 udelay(5);
93
94 /* When power up, host should initialize the 3-wire bus
95 in host read mode: */
96
97 /* 1. Set direction of the DATA-line to input-mode. */
98 GPIOH_OUTPUT_EN &= ~(1 << 5);
99 GPIOH_ENABLE |= (1 << 5);
100
101 /* 2. Drive NR_W low */
102 GPIOH_OUTPUT_VAL &= ~(1 << 3);
103 GPIOH_OUTPUT_EN |= (1 << 3);
104 GPIOH_ENABLE |= (1 << 3);
105
106 /* 3. Drive CLOCK high */
107 GPIOH_OUTPUT_VAL |= (1 << 4);
108 GPIOH_OUTPUT_EN |= (1 << 4);
109 GPIOH_ENABLE |= (1 << 4);
110
111 lv24020lp_power(true);
112 }
113 else
114 {
115 lv24020lp_power(false);
116
117 /* set all as inputs */
118 GPIOH_OUTPUT_EN &= ~((1 << 5) | (1 << 3) | (1 << 4));
119 GPIOH_ENABLE &= ~((1 << 3) | (1 << 4));
120
121 /* turn off mystery amplification device */
122#if defined (SANSA_E200)
123 GPO32_ENABLE &= ~0x1;
124#else
125 DEV_INIT2 |= 0x800;
126#endif
127 }
128
129 powered = status;
130 }
131
132 lv24020lp_unlock();
133 return old_status;
134}
135
136#endif /* CONFIG_TUNER */
diff --git a/firmware/target/arm/philips/sa9200/powermgmt-sa9200.c b/firmware/target/arm/philips/sa9200/powermgmt-sa9200.c
new file mode 100644
index 0000000000..9bb70263be
--- /dev/null
+++ b/firmware/target/arm/philips/sa9200/powermgmt-sa9200.c
@@ -0,0 +1,58 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese
11 * Revisions copyright (C) 2005 by Gerald Van Baren
12 *
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20
21#include "config.h"
22#include "adc.h"
23#include "powermgmt.h"
24
25const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
26{
27 3400
28};
29
30const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
31{
32 3300
33};
34
35/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
36const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
37{
38 /* Sansa Li Ion 750mAH, took from battery benchs */
39 { 3300, 3680, 3740, 3760, 3780, 3810, 3870, 3930, 3970, 4070, 4160 },
40};
41
42/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
43const unsigned short percent_to_volt_charge[11] =
44{
45 /* Sansa Li Ion 750mAH FIXME */
46 3300, 3680, 3740, 3760, 3780, 3810, 3870, 3930, 3970, 4070, 4160
47};
48
49/* ADC should read 0x3ff=5.12V */
50#define BATTERY_SCALE_FACTOR 5125
51/* full-scale ADC readout (2^10) in millivolt */
52
53/* Returns battery voltage from ADC [millivolts] */
54unsigned int battery_adc_voltage(void)
55{
56 return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
57}
58