diff options
Diffstat (limited to 'firmware/target/arm/olympus')
-rw-r--r-- | firmware/target/arm/olympus/mrobe-100/adc-mr100.c | 141 | ||||
-rw-r--r-- | firmware/target/arm/olympus/mrobe-100/adc-target.h | 39 | ||||
-rw-r--r-- | firmware/target/arm/olympus/mrobe-100/backlight-mr100.c | 57 | ||||
-rw-r--r-- | firmware/target/arm/olympus/mrobe-100/backlight-target.h | 41 | ||||
-rw-r--r-- | firmware/target/arm/olympus/mrobe-100/button-mr100.c | 60 | ||||
-rw-r--r-- | firmware/target/arm/olympus/mrobe-100/button-target.h | 64 | ||||
-rw-r--r-- | firmware/target/arm/olympus/mrobe-100/lcd-mr100.c | 192 | ||||
-rw-r--r-- | firmware/target/arm/olympus/mrobe-100/power-mr100.c | 62 | ||||
-rw-r--r-- | firmware/target/arm/olympus/mrobe-100/powermgmt-mr100.c | 59 |
9 files changed, 715 insertions, 0 deletions
diff --git a/firmware/target/arm/olympus/mrobe-100/adc-mr100.c b/firmware/target/arm/olympus/mrobe-100/adc-mr100.c new file mode 100644 index 0000000000..f63e8b8013 --- /dev/null +++ b/firmware/target/arm/olympus/mrobe-100/adc-mr100.c @@ -0,0 +1,141 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Barry Wardell + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include "cpu.h" +#include "system.h" +#include "kernel.h" +#include "thread.h" +#include "adc.h" + +static unsigned short adcdata[NUM_ADC_CHANNELS]; + +/* Scan ADC so that adcdata[channel] gets updated. */ +unsigned short adc_scan(int channel) +{ + unsigned int adc_data_1; + unsigned int adc_data_2; + + /* Start conversion */ + ADC_ADDR |= 0x80000000; + + /* Wait for conversion to complete */ + while((ADC_STATUS & (0x40<<8*channel))==0); + + /* Stop conversion */ + ADC_ADDR &=~ 0x80000000; + + /* ADC_DATA_1 and ADC_DATA_2 are both four bytes, one byte per channel. + For each channel, ADC_DATA_1 stores the 8-bit msb, ADC_DATA_2 stores the + 2-bit lsb (in bits 0 and 1). Each channel is 10 bits total. */ + adc_data_1 = ((ADC_DATA_1 >> (8*channel)) & 0xff); + adc_data_2 = ((ADC_DATA_2 >> (8*channel+6)) & 0x3); + + adcdata[channel] = (adc_data_1<<2 | adc_data_2); + + /* ADC values read low if PLL is enabled */ + if(PLL_CONTROL & 0x80000000){ + adcdata[channel] += 0x14; + if(adcdata[channel] > 0x400) + adcdata[channel] = 0x400; + } + + return adcdata[channel]; +} + +/* Read 10-bit channel data */ +unsigned short adc_read(int channel) +{ + return adcdata[channel]; +} + +static int adc_counter; + +static void adc_tick(void) +{ + if(++adc_counter == HZ) + { + adc_counter = 0; + adc_scan(ADC_BATTERY); + adc_scan(ADC_UNKNOWN_1); + adc_scan(ADC_REMOTE); + adc_scan(ADC_SCROLLPAD); + } +} + +/* Figured out from how the OF does things */ +void adc_init(void) +{ + ADC_INIT |= 1; + ADC_INIT |= 0x40000000; + udelay(100); + + /* Reset ADC */ + DEV_RS2 |= 0x20; + udelay(100); + + DEV_RS2 &=~ 0x20; + udelay(100); + + /* Enable ADC */ + DEV_EN2 |= 0x20; + udelay(100); + + ADC_CLOCK_SRC |= 0x3; + udelay(100); + + ADC_ADDR |= 0x40; + ADC_ADDR |= 0x20000000; + udelay(100); + + ADC_INIT; + ADC_INIT = 0; + udelay(100); + + ADC_STATUS = 0; + + /* Enable channel 0 (battery) */ + DEV_INIT1 &=~0x3; + ADC_ADDR |= 0x1000000; + ADC_STATUS |= 0x20; + + /* Enable channel 1 (unknown, temperature?) */ + DEV_INIT1 &=~30; + ADC_ADDR |= 0x2000000; + ADC_STATUS |= 0x2000; + + /* Enable channel 2 (remote) */ + DEV_INIT1 &=~0x300; + DEV_INIT1 |= 0x100; + ADC_ADDR |= 0x4000000; + ADC_STATUS |= 0x200000; + + /* Enable channel 3 (scroll pad) */ + DEV_INIT1 &=~0x3000; + DEV_INIT1 |= 0x1000; + ADC_ADDR |= 0x8000000; + ADC_STATUS |= 0x20000000; + + /* Force a scan of all channels to get initial values */ + adc_scan(ADC_BATTERY); + adc_scan(ADC_UNKNOWN_1); + adc_scan(ADC_REMOTE); + adc_scan(ADC_SCROLLPAD); + + tick_add_task(adc_tick); +} diff --git a/firmware/target/arm/olympus/mrobe-100/adc-target.h b/firmware/target/arm/olympus/mrobe-100/adc-target.h new file mode 100644 index 0000000000..f761e761ef --- /dev/null +++ b/firmware/target/arm/olympus/mrobe-100/adc-target.h @@ -0,0 +1,39 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Barry Wardell + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef _ADC_TARGET_H_ +#define _ADC_TARGET_H_ + +#define ADC_ADDR (*(volatile unsigned long*)(0x7000ad00)) +#define ADC_STATUS (*(volatile unsigned long*)(0x7000ad04)) +#define ADC_DATA_1 (*(volatile unsigned long*)(0x7000ad20)) +#define ADC_DATA_2 (*(volatile unsigned long*)(0x7000ad24)) +#define ADC_INIT (*(volatile unsigned long*)(0x7000ad2c)) + +#define NUM_ADC_CHANNELS 4 + +#define ADC_BATTERY 0 +#define ADC_UNKNOWN_1 1 +#define ADC_REMOTE 2 +#define ADC_SCROLLPAD 3 +#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ + +/* Force a scan now */ +unsigned short adc_scan(int channel); + +#endif diff --git a/firmware/target/arm/olympus/mrobe-100/backlight-mr100.c b/firmware/target/arm/olympus/mrobe-100/backlight-mr100.c new file mode 100644 index 0000000000..10a7f666e5 --- /dev/null +++ b/firmware/target/arm/olympus/mrobe-100/backlight-mr100.c @@ -0,0 +1,57 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Mark Arigo + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "backlight-target.h" +#include "system.h" +#include "lcd.h" +#include "backlight.h" +#include "i2c-pp.h" + +void _backlight_on(void) +{ +} + +void _backlight_off(void) +{ +} + +void _buttonlight_on(void) +{ + /* turn on all touchpad leds */ + GPIOA_OUTPUT_VAL |= BUTTONLIGHT_ALL; + +#if 0 + /* Writing to 0x7000a010 controls the brightness of the leds. + This routine fades the leds from dim to bright, like when + you first turn the unit on. */ + unsigned long val = 0x80ff08ff; + int i = 0; + for (i = 0; i < 16; i++) + outl(val, 0x7000a010); + udelay(100000); + val -= 0x110000; + } +#endif +} + +void _buttonlight_off(void) +{ + /* turn off all touchpad leds */ + GPIOA_OUTPUT_VAL &= ~BUTTONLIGHT_ALL; +} diff --git a/firmware/target/arm/olympus/mrobe-100/backlight-target.h b/firmware/target/arm/olympus/mrobe-100/backlight-target.h new file mode 100644 index 0000000000..e6c8387222 --- /dev/null +++ b/firmware/target/arm/olympus/mrobe-100/backlight-target.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Mark Arigo + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef BACKLIGHT_TARGET_H +#define BACKLIGHT_TARGET_H + +#define _backlight_init() true +void _backlight_on(void); +void _backlight_off(void); + +/* Button lights are controlled by GPIOA_OUTPUT_VAL */ +#define BUTTONLIGHT_PLAY 0x01 +#define BUTTONLIGHT_MENU 0x02 +#define BUTTONLIGHT_DISPLAY 0x04 +#define BUTTONLIGHT_LEFT 0x08 +#define BUTTONLIGHT_RIGHT 0x10 +#define BUTTONLIGHT_SCROLL 0x20 +#define BUTTONLIGHT_ALL (BUTTONLIGHT_PLAY | BUTTONLIGHT_MENU | \ + BUTTONLIGHT_DISPLAY | BUTTONLIGHT_LEFT | \ + BUTTONLIGHT_RIGHT | BUTTONLIGHT_SCROLL) + +void _buttonlight_on(void); +void _buttonlight_off(void); + +#endif diff --git a/firmware/target/arm/olympus/mrobe-100/button-mr100.c b/firmware/target/arm/olympus/mrobe-100/button-mr100.c new file mode 100644 index 0000000000..141a6d5b0c --- /dev/null +++ b/firmware/target/arm/olympus/mrobe-100/button-mr100.c @@ -0,0 +1,60 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Mark Arigo + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include <stdlib.h> +#include "config.h" +#include "cpu.h" +#include "system.h" +#include "button.h" +#include "kernel.h" +#include "backlight.h" +#include "backlight-target.h" +#include "system.h" + +void button_int(void) +{ +} + +void button_init_device(void) +{ + /* taken from the mr-100 bootloader (offset 0x1e72) */ + //~ DEV_EN |= 0x20000; /* enable the touchpad ?? */ + + /* enable touchpad leds */ + GPIOA_ENABLE |= 0xff; + GPIOA_OUTPUT_EN |= BUTTONLIGHT_ALL; +} + +/* + * Get button pressed from hardware + */ +int button_read_device(void) +{ + return BUTTON_NONE; +} + +bool button_hold(void) +{ + return (GPIOD_INPUT_VAL & BUTTON_HOLD) ? false : true; +} + +bool headphones_inserted(void) +{ + return (GPIOD_INPUT_VAL & 0x80) ? true : false; +} diff --git a/firmware/target/arm/olympus/mrobe-100/button-target.h b/firmware/target/arm/olympus/mrobe-100/button-target.h new file mode 100644 index 0000000000..99f17bb09b --- /dev/null +++ b/firmware/target/arm/olympus/mrobe-100/button-target.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$
+ *
+ * Copyright (C) 2008 by Mark Arigo
+ * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef _BUTTON_TARGET_H_ +#define _BUTTON_TARGET_H_ + +#include <stdbool.h> +#include "config.h" + +#define HAS_BUTTON_HOLD + +bool button_hold(void); +void button_init_device(void); +int button_read_device(void); + +/* Power button is on GPIOA */ +#define BUTTON_POWER 0x80 +#define POWEROFF_BUTTON BUTTON_POWER +#define POWEROFF_COUNT 10 + +/* Hold button is on GPIOD */ +#define BUTTON_HOLD 0x10 +
+/* FIXME: Until the buttons are figured out, we use the button definitions + for the H10 keypad & remote. THESE ARE NOT CORRECT! */ +
+/* Main unit's buttons */
+#define BUTTON_LEFT 0x00000002
+#define BUTTON_RIGHT 0x00000004
+#define BUTTON_REW 0x00000008
+#define BUTTON_PLAY 0x00000010
+#define BUTTON_FF 0x00000020
+#define BUTTON_SCROLL_UP 0x00000040
+#define BUTTON_SCROLL_DOWN 0x00000080
+#define BUTTON_MAIN (BUTTON_POWER|BUTTON_O|BUTTON_BACK|BUTTON_REW\
+ |BUTTON_PLAY|BUTTON_FF)
+
+/* Remote control's buttons */ +#define BUTTON_RC_REW 0x00080000 +#define BUTTON_RC_PLAY 0x00100000 +#define BUTTON_RC_FF 0x00200000 +#define BUTTON_RC_VOL_UP 0x00400000 +#define BUTTON_RC_VOL_DOWN 0x00800000 +#define BUTTON_REMOTE (BUTTON_RC_PLAY|BUTTON_RC_VOL_UP|BUTTON_RC_VOL_DOWN\ + |BUTTON_RC_REW|BUTTON_RC_FF) +#define RC_POWEROFF_BUTTON BUTTON_RC_PLAY + +#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/arm/olympus/mrobe-100/lcd-mr100.c b/firmware/target/arm/olympus/mrobe-100/lcd-mr100.c new file mode 100644 index 0000000000..501a0942e5 --- /dev/null +++ b/firmware/target/arm/olympus/mrobe-100/lcd-mr100.c @@ -0,0 +1,192 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Mark Arigo + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include "cpu.h" +#include "lcd.h" +#include "kernel.h" +#include "system.h" +
+/* send LCD data */
+static void lcd_send_data(unsigned data)
+{
+ while (LCD1_CONTROL & LCD1_BUSY_MASK); /* wait for LCD */ + LCD1_DATA = data;
+}
+
+/* send LCD command */
+static void lcd_send_command(unsigned cmd)
+{
+ while (LCD1_CONTROL & LCD1_BUSY_MASK); /* wait for LCD */
+ LCD1_CMD = cmd;
+}
+
+/* LCD init */
+void lcd_init_device(void)
+{
+ int i;
+
+ DEV_INIT1 &= ~0xfc000000; + + i = DEV_INIT1; + DEV_INIT1 = i; + + DEV_INIT2 &= ~0x400;
+ udelay(10000); +
+ LCD1_CONTROL &= ~0x4; + udelay(15); + + LCD1_CONTROL |= 0x4; + udelay(10); + + LCD1_CONTROL = 0x690;
+ LCD1_CONTROL = 0x694; +
+ /* OF just reads these */
+ i = LCD1_CONTROL;
+ i = inl(0x70003004);
+ i = LCD1_CMD;
+ i = inl(0x7000300c);
+ +#if 0 + /* this is skipped in the OF */ + LCD1_CONTROL &= ~0x200; + LCD1_CONTROL &= ~0x800; + LCD1_CONTROL &= ~0x400; +#endif +
+ LCD1_CONTROL |= 0x1;
+ udelay(15000);
+
+ lcd_send_command(0xe2);
+ lcd_send_command(0x2f);
+ lcd_send_command(0x26);
+ lcd_send_command(0xcc);
+ lcd_send_command(0xe8);
+ lcd_send_command(0x81);
+ lcd_send_command(0);
+ lcd_send_command(0x40);
+ lcd_send_command(0xa6);
+ lcd_send_command(0x88);
+ lcd_send_command(0xb0);
+ lcd_send_command(0x10);
+ lcd_send_command(0);
+}
+ +/*** hardware configuration ***/ +int lcd_default_contrast(void)
+{
+ return DEFAULT_CONTRAST_SETTING;
+}
+ +void lcd_set_contrast(int val) +{ + lcd_send_command(0x81); + lcd_send_command(val); +} + +void lcd_set_invert_display(bool yesno) +{ + /* TODO: Implement lcd_set_invert_display() */ + (void)yesno; +} + +/* turn the display upside down (call lcd_update() afterwards) */ +void lcd_set_flip(bool yesno) +{ + /* TODO: Implement lcd_set_flip() */ + (void)yesno; +} + +/*** update functions ***/ + +/* Performance function that works with an external buffer + note that by and bheight are in 4-pixel units! */ +void lcd_blit(const fb_data* data, int x, int by, int width, + int bheight, int stride) +{ + /* TODO: Implement lcd_blit() */ + (void)data; + (void)x; + (void)by; + (void)width; + (void)bheight; + (void)stride; +} + +/* Performance function to blit a YUV bitmap directly to the LCD */ +void lcd_yuv_blit(unsigned char * const src[3], + int src_x, int src_y, int stride, + int x, int y, int width, int height) +{ + (void)src; + (void)src_x; + (void)src_y; + (void)stride; + (void)x; + (void)y; + (void)width; + (void)height; +} + +/* Update the display. + This must be called after all other LCD functions that change the display. */ +void lcd_update(void) +{ + lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); +} +
+/* Update a fraction of the display. */
+void lcd_update_rect(int x0, int y0, int width, int height)
+{ + unsigned char *addr; + unsigned int cmd0, cmd1, cmd2; + int r, c, x1, y1, start_row, last_row; + + x1 = (x0 + width) - 1; + y1 = (y0 + height) - 1; + if ((x1 <= 0) || (y1 <= 0)) + return; + + if(x1 >= LCD_WIDTH) + x1 = LCD_WIDTH - 1; + + if(y1 >= LCD_HEIGHT) + y1 = LCD_HEIGHT - 1; + + start_row = y0/8; + last_row = y1/8; + + cmd1 = (x0 & 0xff) >> 4; + cmd1 = (cmd1 + 5) | 0x10; + cmd2 = x0 & 0xf; + + for (r = start_row; r <= last_row; r++) { + cmd0 = (r & 0xff) | 0xb0; + lcd_send_command(cmd0); + lcd_send_command(cmd1); + lcd_send_command(cmd2); + + addr = (unsigned char*)&lcd_framebuffer[r][x0]; + for (c = x0; c <= x1; c++) + lcd_send_data(*(addr++)); + } + + lcd_send_command(0xaf); +}
diff --git a/firmware/target/arm/olympus/mrobe-100/power-mr100.c b/firmware/target/arm/olympus/mrobe-100/power-mr100.c new file mode 100644 index 0000000000..1fb2ecb958 --- /dev/null +++ b/firmware/target/arm/olympus/mrobe-100/power-mr100.c @@ -0,0 +1,62 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Barry Wardell + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "cpu.h" +#include <stdbool.h> +#include "adc.h" +#include "kernel.h" +#include "system.h" +#include "power.h" +#include "logf.h" +#include "usb.h" + +#if CONFIG_CHARGING == CHARGING_CONTROL +bool charger_enabled; +#endif + +void power_init(void) +{ +} + +bool charger_inserted(void) +{ + return false; +} + +void ide_power_enable(bool on) +{ + (void)on; + /* We do nothing on the iPod */ +} + + +bool ide_powered(void) +{ + /* pretend we are always powered - we don't turn it off on the ipod */ + return true; +} + +void power_off(void) +{ + /* Give things a second to settle before cutting power */ + sleep(HZ); + + //GPIOF_OUTPUT_VAL &=~ 0x20; +} diff --git a/firmware/target/arm/olympus/mrobe-100/powermgmt-mr100.c b/firmware/target/arm/olympus/mrobe-100/powermgmt-mr100.c new file mode 100644 index 0000000000..1b6a52f517 --- /dev/null +++ b/firmware/target/arm/olympus/mrobe-100/powermgmt-mr100.c @@ -0,0 +1,59 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese + * Revisions copyright (C) 2005 by Gerald Van Baren + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "adc.h" +#include "powermgmt.h" + +/* FIXME: All voltages copied from H10/Tatung Elio. This will need changing + proper power management. */ + +const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = +{ + 3760 +}; + +const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = +{ + 3650 +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ +const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = +{ + { 3760, 3800, 3850, 3870, 3900, 3950, 4020, 4070, 4110, 4180, 4240 } +}; + +#if CONFIG_CHARGING +/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ +const unsigned short percent_to_volt_charge[11] = +{ + 3990, 4030, 4060, 4080, 4100, 4120, 4150, 4180, 4220, 4260, 4310 +}; +#endif /* CONFIG_CHARGING */ + +#define BATTERY_SCALE_FACTOR 4650 +/* full-scale ADC readout (2^10) in millivolt */ + +/* Returns battery voltage from ADC [millivolts] */ +unsigned int battery_adc_voltage(void) +{ + return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10; +} |