From 16ada4cb81c70c1a151c69aa08da13e55aba0081 Mon Sep 17 00:00:00 2001 From: Rob Purchase Date: Sat, 10 Oct 2009 17:35:02 +0000 Subject: Initial support for runtime detection of the PMU used in newer D2+ models (PCF50635). The backlight and battery monitoring should work, but the RTC and touchscreen are not yet implemented. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23078 a1c6a512-1295-4272-9138-f99709370657 --- firmware/SOURCES | 1 + firmware/drivers/pcf50606.c | 12 +- firmware/drivers/pcf50635.c | 132 +++++++ firmware/export/pcf50635.h | 34 ++ firmware/export/pcf5063x.h | 384 +++++++++++++++++++++ .../target/arm/tcc780x/cowond2/backlight-cowond2.c | 42 ++- .../target/arm/tcc780x/cowond2/power-cowond2.c | 60 ++-- firmware/target/arm/tcc780x/cowond2/power-target.h | 32 ++ .../target/arm/tcc780x/cowond2/powermgmt-cowond2.c | 9 +- 9 files changed, 679 insertions(+), 27 deletions(-) create mode 100644 firmware/drivers/pcf50635.c create mode 100644 firmware/export/pcf50635.h create mode 100644 firmware/export/pcf5063x.h create mode 100644 firmware/target/arm/tcc780x/cowond2/power-target.h diff --git a/firmware/SOURCES b/firmware/SOURCES index 9c41194a5b..0371cea684 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -1253,6 +1253,7 @@ target/arm/tcc77x/iaudio7/audio-iaudio7.c #ifndef SIMULATOR drivers/nand_id.c drivers/pcf50606.c +drivers/pcf50635.c target/arm/lcd-as-memframe.S target/arm/tcc780x/adc-tcc780x.c target/arm/tcc780x/system-tcc780x.c diff --git a/firmware/drivers/pcf50606.c b/firmware/drivers/pcf50606.c index 8592c005fe..4ef747fe80 100644 --- a/firmware/drivers/pcf50606.c +++ b/firmware/drivers/pcf50606.c @@ -53,7 +53,17 @@ int pcf50606_read_multiple(int address, unsigned char* buf, int count) void pcf50606_init(void) { - // TODO +#ifdef COWON_D2 + /* Set outputs as per OF - further investigation required. */ + pcf50606_write(PCF5060X_DCDEC1, 0xe4); + pcf50606_write(PCF5060X_IOREGC, 0xf5); + pcf50606_write(PCF5060X_D1REGC1, 0xf5); + pcf50606_write(PCF5060X_D2REGC1, 0xe9); + pcf50606_write(PCF5060X_D3REGC1, 0xf8); /* WM8985 3.3v */ + pcf50606_write(PCF5060X_DCUDC1, 0xe7); + pcf50606_write(PCF5060X_LPREGC1, 0x0); + pcf50606_write(PCF5060X_LPREGC2, 0x2); +#endif } void pcf50606_reset_timeout(void) diff --git a/firmware/drivers/pcf50635.c b/firmware/drivers/pcf50635.c new file mode 100644 index 0000000000..c436498670 --- /dev/null +++ b/firmware/drivers/pcf50635.c @@ -0,0 +1,132 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2009 by Rob Purchase + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "pcf50635.h" +#include "i2c.h" +#include "system.h" + +#define PCF50635_ADDR 0xe6 + +int pcf50635_write(int address, unsigned char val) +{ + unsigned char data[] = { address, val }; + return i2c_write(PCF50635_ADDR, data, 2); +} + +int pcf50635_write_multiple(int address, const unsigned char* buf, int count) +{ + int i; + + for (i = 0; i < count; i++) + pcf50635_write(address + i, buf[i]); + + return 0; +} + +int pcf50635_read(int address) +{ + unsigned char val = -1; + i2c_readmem(PCF50635_ADDR, address, &val, 1); + return val; +} + +int pcf50635_read_multiple(int address, unsigned char* buf, int count) +{ + return i2c_readmem(PCF50635_ADDR, address, buf, count); +} + +void pcf50635_init(void) +{ +#ifdef COWON_D2 + /* Configure outputs as per OF */ + pcf50635_write(PCF5063X_REG_DOWN1OUT, 0x13); /* DOWN1 = 1.2V */ + pcf50635_write(PCF5063X_REG_DOWN1CTL, 0x1e); /* DOWN1 DVM step = max */ + pcf50635_write(PCF5063X_REG_DOWN1ENA, 0x1); /* DOWN1 enable */ + pcf50635_write(PCF5063X_REG_DOWN2OUT, 0x2f); /* DOWN2 = 1.8V */ + pcf50635_write(PCF5063X_REG_DOWN2CTL, 0x1e); /* DOWN2 DVM step = max */ + pcf50635_write(PCF5063X_REG_DOWN2ENA, 0x1); /* DOWN2 enable */ + pcf50635_write(PCF5063X_REG_AUTOOUT, 0x5f); /* AUTO = 3.0V */ + pcf50635_write(PCF5063X_REG_AUTOENA, 0x1); /* AUTO enable */ + pcf50635_write(PCF5063X_REG_LDO1OUT, 0x18); /* LDO1 = 3.3V */ + pcf50635_write(PCF5063X_REG_LDO1ENA, 0x1); /* LDO1 enable */ + pcf50635_write(PCF5063X_REG_LDO2OUT, 0x15); /* LDO2 = 3.0V */ + pcf50635_write(PCF5063X_REG_LDO2ENA, 0x1); /* LDO2 enable */ + pcf50635_write(PCF5063X_REG_LDO3ENA, 0x0); /* LDO3 disable */ + pcf50635_write(PCF5063X_REG_LDO4OUT, 0x15); /* LDO4 = 3.0V */ + pcf50635_write(PCF5063X_REG_LDO4ENA, 0x1); /* LDO4 enable */ + pcf50635_write(PCF5063X_REG_LDO5OUT, 0x9); /* LDO5 = 1.8V */ + pcf50635_write(PCF5063X_REG_LDO5ENA, 0x1); /* LDO4 enable */ + pcf50635_write(PCF5063X_REG_LDO6OUT, 0xc); /* LDO6 = 2.1V */ + pcf50635_write(PCF5063X_REG_LDO6ENA, 0x1); /* LDO4 enable */ + pcf50635_write(PCF5063X_REG_HCLDOENA, 0x0); /* HCLDO disable */ + + /* Configure automatic battery charging as per OF */ + pcf50635_write(PCF5063X_REG_MBCC1, + pcf50635_read(PCF5063X_REG_MBCC1) | 7); /* auto charge termination & resume */ + pcf50635_write(PCF5063X_REG_MBCC2, 0xa8); /* Vmax = 4.2V, Vbatcond = 2.7V, long debounce */ + pcf50635_write(PCF5063X_REG_MBCC3, 0x2a); /* precharge level = 16% */ + pcf50635_write(PCF5063X_REG_MBCC4, 0x94); /* fastcharge level = 58% */ + pcf50635_write(PCF5063X_REG_MBCC5, 0xff); /* fastcharge level (usb) = 100% */ + pcf50635_write(PCF5063X_REG_MBCC6, 0x4); /* cutoff level = 12.5% */ + pcf50635_write(PCF5063X_REG_MBCC7, 0xc1); /* bat-sysimax = 2.2A, USB = 500mA */ + pcf50635_write(PCF5063X_REG_BVMCTL, 0xe); /* batok level = 3.4V */ + + /* IRQ masks */ + pcf50635_write(PCF5063X_REG_INT1M, 0x8a); /* enable alarm, usbins, adpins */ + pcf50635_write(PCF5063X_REG_INT2M, 0xff); /* mask all */ + pcf50635_write(PCF5063X_REG_INT3M, 0x7f); /* enable onkey1s */ + pcf50635_write(PCF5063X_REG_INT4M, 0xfd); /* enable lowbat */ + pcf50635_write(PCF5063X_REG_INT5M, 0xff); /* mask all */ + + pcf50635_write(PCF5063X_REG_OOCMODE, 0x0); + pcf50635_write(PCF5063X_REG_OOCCTL, 0x2); /* actphrst = phase 3 */ + pcf50635_write(PCF5063X_REG_OOCWAKE, /* adapter, usb, (rtc) wake */ + (pcf50635_read(PCF5063X_REG_OOCWAKE) & 0x10) | 0xc1); + + /* We don't care about the GPIOs, disable them */ + pcf50635_write(PCF5063X_REG_GPIOCTL, 0x0); + pcf50635_write(PCF5063X_REG_GPIO1CFG, 0x0); + pcf50635_write(PCF5063X_REG_GPIO2CFG, 0x0); + pcf50635_write(PCF5063X_REG_GPIO3CFG, 0x0); +#endif +} + +void pcf50635_read_adc(int adc, short* res1, short* res2) +{ + int adcs1 = 0, adcs2 = 0, adcs3 = 0; + + int level = disable_irq_save(); + + pcf50635_write(PCF5063X_REG_ADCC1, PCF5063X_ADCC1_ADCSTART | adc); + + do { + adcs3 = pcf50635_read(PCF5063X_REG_ADCS3); + } while (!(adcs3 & PCF5063X_ADCS3_ADCRDY)); + + if (res1 != NULL) adcs1 = pcf50635_read(PCF5063X_REG_ADCS1); + if (res2 != NULL) adcs2 = pcf50635_read(PCF5063X_REG_ADCS2); + + pcf50635_write(PCF5063X_REG_ADCC1, 0); + + restore_interrupt(level); + + if (res1 != NULL) *res1 = (adcs1 << 2) | (adcs3 & 3); + if (res2 != NULL) *res2 = (adcs2 << 2) | ((adcs3 & 0xC) >> 2); +} diff --git a/firmware/export/pcf50635.h b/firmware/export/pcf50635.h new file mode 100644 index 0000000000..716ed52899 --- /dev/null +++ b/firmware/export/pcf50635.h @@ -0,0 +1,34 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2009 by Rob Purchase + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef PCF50635_H +#define PCF50635_H + +#include "pcf5063x.h" + +void pcf50635_init(void); +int pcf50635_write_multiple(int address, const unsigned char* buf, int count); +int pcf50635_write(int address, unsigned char val); +int pcf50635_read_multiple(int address, unsigned char* buf, int count); +int pcf50635_read(int address); + +void pcf50635_read_adc(int adc, short* res1, short* res2); + +#endif /* PCF50635_H */ diff --git a/firmware/export/pcf5063x.h b/firmware/export/pcf5063x.h new file mode 100644 index 0000000000..164417f483 --- /dev/null +++ b/firmware/export/pcf5063x.h @@ -0,0 +1,384 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Philips PCF50633 Power Managemnt Unit (PMU) driver + * (C) 2006-2007 by Openmoko, Inc. + * Author: Harald Welte + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef PCF5063X_H +#define PCF5063X_H + +enum pcf5063X_regs { + PCF5063X_REG_VERSION = 0x00, + PCF5063X_REG_VARIANT = 0x01, + PCF5063X_REG_INT1 = 0x02, /* Interrupt Status */ + PCF5063X_REG_INT2 = 0x03, /* Interrupt Status */ + PCF5063X_REG_INT3 = 0x04, /* Interrupt Status */ + PCF5063X_REG_INT4 = 0x05, /* Interrupt Status */ + PCF5063X_REG_INT5 = 0x06, /* Interrupt Status */ + PCF5063X_REG_INT1M = 0x07, /* Interrupt Mask */ + PCF5063X_REG_INT2M = 0x08, /* Interrupt Mask */ + PCF5063X_REG_INT3M = 0x09, /* Interrupt Mask */ + PCF5063X_REG_INT4M = 0x0a, /* Interrupt Mask */ + PCF5063X_REG_INT5M = 0x0b, /* Interrupt Mask */ + PCF5063X_REG_OOCSHDWN = 0x0c, + PCF5063X_REG_OOCWAKE = 0x0d, + PCF5063X_REG_OOCTIM1 = 0x0e, + PCF5063X_REG_OOCTIM2 = 0x0f, + PCF5063X_REG_OOCMODE = 0x10, + PCF5063X_REG_OOCCTL = 0x11, + PCF5063X_REG_OOCSTAT = 0x12, + PCF5063X_REG_GPIOCTL = 0x13, + PCF5063X_REG_GPIO1CFG = 0x14, + PCF5063X_REG_GPIO2CFG = 0x15, + PCF5063X_REG_GPIO3CFG = 0x16, + PCF5063X_REG_GPOCFG = 0x17, + PCF5063X_REG_BVMCTL = 0x18, + PCF5063X_REG_SVMCTL = 0x19, + PCF5063X_REG_AUTOOUT = 0x1a, + PCF5063X_REG_AUTOENA = 0x1b, + PCF5063X_REG_AUTOCTL = 0x1c, + PCF5063X_REG_AUTOMXC = 0x1d, + PCF5063X_REG_DOWN1OUT = 0x1e, + PCF5063X_REG_DOWN1ENA = 0x1f, + PCF5063X_REG_DOWN1CTL = 0x20, + PCF5063X_REG_DOWN1MXC = 0x21, + PCF5063X_REG_DOWN2OUT = 0x22, + PCF5063X_REG_DOWN2ENA = 0x23, + PCF5063X_REG_DOWN2CTL = 0x24, + PCF5063X_REG_DOWN2MXC = 0x25, + PCF5063X_REG_MEMLDOOUT = 0x26, + PCF5063X_REG_MEMLDOENA = 0x27, + PCF5063X_REG_LEDOUT = 0x28, + PCF5063X_REG_LEDENA = 0x29, + PCF5063X_REG_LEDCTL = 0x2a, + PCF5063X_REG_LEDDIM = 0x2b, + /* reserved */ + PCF5063X_REG_LDO1OUT = 0x2d, + PCF5063X_REG_LDO1ENA = 0x2e, + PCF5063X_REG_LDO2OUT = 0x2f, + PCF5063X_REG_LDO2ENA = 0x30, + PCF5063X_REG_LDO3OUT = 0x31, + PCF5063X_REG_LDO3ENA = 0x32, + PCF5063X_REG_LDO4OUT = 0x33, + PCF5063X_REG_LDO4ENA = 0x34, + PCF5063X_REG_LDO5OUT = 0x35, + PCF5063X_REG_LDO5ENA = 0x36, + PCF5063X_REG_LDO6OUT = 0x37, + PCF5063X_REG_LDO6ENA = 0x38, + PCF5063X_REG_HCLDOOUT = 0x39, + PCF5063X_REG_HCLDOENA = 0x3a, + PCF5063X_REG_STBYCTL1 = 0x3b, + PCF5063X_REG_STBYCTL2 = 0x3c, + PCF5063X_REG_DEBPF1 = 0x3d, + PCF5063X_REG_DEBPF2 = 0x3e, + PCF5063X_REG_DEBPF3 = 0x3f, + PCF5063X_REG_HCLDOOVL = 0x40, + PCF5063X_REG_DCDCSTAT = 0x41, + PCF5063X_REG_LDOSTAT = 0x42, + PCF5063X_REG_MBCC1 = 0x43, + PCF5063X_REG_MBCC2 = 0x44, + PCF5063X_REG_MBCC3 = 0x45, + PCF5063X_REG_MBCC4 = 0x46, + PCF5063X_REG_MBCC5 = 0x47, + PCF5063X_REG_MBCC6 = 0x48, + PCF5063X_REG_MBCC7 = 0x49, + PCF5063X_REG_MBCC8 = 0x4a, + PCF5063X_REG_MBCS1 = 0x4b, + PCF5063X_REG_MBCS2 = 0x4c, + PCF5063X_REG_MBCS3 = 0x4d, + PCF5063X_REG_BBCCTL = 0x4e, + PCF5063X_REG_ALMGAIN = 0x4f, + PCF5063X_REG_ALMDATA = 0x50, + /* reserved */ + PCF5063X_REG_ADCC3 = 0x52, + PCF5063X_REG_ADCC2 = 0x53, + PCF5063X_REG_ADCC1 = 0x54, + PCF5063X_REG_ADCS1 = 0x55, + PCF5063X_REG_ADCS2 = 0x56, + PCF5063X_REG_ADCS3 = 0x57, + /* reserved */ + PCF5063X_REG_RTCSC = 0x59, /* Second */ + PCF5063X_REG_RTCMN = 0x5a, /* Minute */ + PCF5063X_REG_RTCHR = 0x5b, /* Hour */ + PCF5063X_REG_RTCWD = 0x5c, /* Weekday */ + PCF5063X_REG_RTCDT = 0x5d, /* Day */ + PCF5063X_REG_RTCMT = 0x5e, /* Month */ + PCF5063X_REG_RTCYR = 0x5f, /* Year */ + PCF5063X_REG_RTCSCA = 0x60, /* Alarm Second */ + PCF5063X_REG_RTCMNA = 0x61, /* Alarm Minute */ + PCF5063X_REG_RTCHRA = 0x62, /* Alarm Hour */ + PCF5063X_REG_RTCWDA = 0x63, /* Alarm Weekday */ + PCF5063X_REG_RTCDTA = 0x64, /* Alarm Day */ + PCF5063X_REG_RTCMTA = 0x65, /* Alarm Month */ + PCF5063X_REG_RTCYRA = 0x66, /* Alarm Year */ + + PCF5063X_REG_MEMBYTE0 = 0x67, + PCF5063X_REG_MEMBYTE1 = 0x68, + PCF5063X_REG_MEMBYTE2 = 0x69, + PCF5063X_REG_MEMBYTE3 = 0x6a, + PCF5063X_REG_MEMBYTE4 = 0x6b, + PCF5063X_REG_MEMBYTE5 = 0x6c, + PCF5063X_REG_MEMBYTE6 = 0x6d, + PCF5063X_REG_MEMBYTE7 = 0x6e, + /* reserved */ + PCF5063X_REG_DCDCPFM = 0x84, + __NUM_PCF5063X_REGS +}; + + +enum pcf5063X_reg_oocshdwn { + PCF5063X_OOCSHDWN_GOSTDBY = 0x01, + PCF5063X_OOCSHDWN_TOTRST = 0x04, + PCF5063X_OOCSHDWN_COLDBOOT = 0x08, +}; + +enum pcf5063X_reg_oocwake { + PCF5063X_OOCWAKE_ONKEY = 0x01, + PCF5063X_OOCWAKE_EXTON1 = 0x02, + PCF5063X_OOCWAKE_EXTON2 = 0x04, + PCF5063X_OOCWAKE_EXTON3 = 0x08, + PCF5063X_OOCWAKE_RTC = 0x10, + /* reserved */ + PCF5063X_OOCWAKE_USB = 0x40, + PCF5063X_OOCWAKE_ADP = 0x80, +}; + +enum pcf5063X_reg_mbcc1 { + PCF5063X_MBCC1_CHGENA = 0x01, /* Charger enable */ + PCF5063X_MBCC1_AUTOSTOP = 0x02, + PCF5063X_MBCC1_AUTORES = 0x04, /* automatic resume */ + PCF5063X_MBCC1_RESUME = 0x08, /* explicit resume cmd */ + PCF5063X_MBCC1_RESTART = 0x10, /* restart charging */ + PCF5063X_MBCC1_PREWDTIME_60M = 0x20, /* max. precharging time */ + PCF5063X_MBCC1_WDTIME_1H = 0x00, + PCF5063X_MBCC1_WDTIME_2H = 0x40, + PCF5063X_MBCC1_WDTIME_4H = 0x80, + PCF5063X_MBCC1_WDTIME_6H = 0xc0, +}; +#define PCF5063X_MBCC1_WDTIME_MASK 0xc0 + +enum pcf5063X_reg_mbcc2 { + PCF5063X_MBCC2_VBATCOND_2V7 = 0x00, + PCF5063X_MBCC2_VBATCOND_2V85 = 0x01, + PCF5063X_MBCC2_VBATCOND_3V0 = 0x02, + PCF5063X_MBCC2_VBATCOND_3V15 = 0x03, + PCF5063X_MBCC2_VMAX_4V = 0x00, + PCF5063X_MBCC2_VMAX_4V20 = 0x28, + PCF5063X_MBCC2_VRESDEBTIME_64S = 0x80, /* debounce time (32/64sec) */ +}; +#define PCF5063X_MBCC2_VBATCOND_MASK 0x03 +#define PCF5063X_MBCC2_VMAX_MASK 0x3c + +enum pcf5063X_reg_adcc1 { + PCF5063X_ADCC1_ADCSTART = 0x01, + PCF5063X_ADCC1_RES_10BIT = 0x02, + PCF5063X_ADCC1_AVERAGE_NO = 0x00, + PCF5063X_ADCC1_AVERAGE_4 = 0x04, + PCF5063X_ADCC1_AVERAGE_8 = 0x08, + PCF5063X_ADCC1_AVERAGE_16 = 0x0c, + + PCF5063X_ADCC1_MUX_BATSNS_RES = 0x00, + PCF5063X_ADCC1_MUX_BATSNS_SUBTR = 0x10, + PCF5063X_ADCC1_MUX_ADCIN2_RES = 0x20, + PCF5063X_ADCC1_MUX_ADCIN2_SUBTR = 0x30, + PCF5063X_ADCC1_MUX_BATTEMP = 0x60, + PCF5063X_ADCC1_MUX_ADCIN1 = 0x70, +}; +#define PCF5063X_ADCC1_AVERAGE_MASK 0x0c +#define PCF5063X_ADCC1_ADCMUX_MASK 0xf0 + +enum pcf5063X_reg_adcc2 { + PCF5063X_ADCC2_RATIO_NONE = 0x00, + PCF5063X_ADCC2_RATIO_BATTEMP = 0x01, + PCF5063X_ADCC2_RATIO_ADCIN1 = 0x02, + PCF5063X_ADCC2_RATIO_BOTH = 0x03, + PCF5063X_ADCC2_RATIOSETTL_100US = 0x04, +}; +#define PCF5063X_ADCC2_RATIO_MASK 0x03 + +enum pcf5063X_reg_adcc3 { + PCF5063X_ADCC3_ACCSW_EN = 0x01, + PCF5063X_ADCC3_NTCSW_EN = 0x04, + PCF5063X_ADCC3_RES_DIV_TWO = 0x10, + PCF5063X_ADCC3_RES_DIV_THREE = 0x00, +}; + +enum pcf5063X_reg_adcs3 { + PCF5063X_ADCS3_REF_NTCSW = 0x00, + PCF5063X_ADCS3_REF_ACCSW = 0x10, + PCF5063X_ADCS3_REF_2V0 = 0x20, + PCF5063X_ADCS3_REF_VISA = 0x30, + PCF5063X_ADCS3_REF_2V0_2 = 0x70, + PCF5063X_ADCS3_ADCRDY = 0x80, +}; +#define PCF5063X_ADCS3_ADCDAT1L_MASK 0x03 +#define PCF5063X_ADCS3_ADCDAT2L_MASK 0x0c +#define PCF5063X_ADCS3_ADCDAT2L_SHIFT 2 +#define PCF5063X_ASCS3_REF_MASK 0x70 + +enum pcf5063X_regulator_enable { + PCF5063X_REGULATOR_ON = 0x01, + PCF5063X_REGULATOR_ON_GPIO1 = 0x02, + PCF5063X_REGULATOR_ON_GPIO2 = 0x04, + PCF5063X_REGULATOR_ON_GPIO3 = 0x08, +}; +#define PCF5063X_REGULATOR_ON_MASK 0x0f + +enum pcf5063X_regulator_phase { + PCF5063X_REGULATOR_ACTPH1 = 0x00, + PCF5063X_REGULATOR_ACTPH2 = 0x10, + PCF5063X_REGULATOR_ACTPH3 = 0x20, + PCF5063X_REGULATOR_ACTPH4 = 0x30, +}; +#define PCF5063X_REGULATOR_ACTPH_MASK 0x30 + +enum pcf5063X_reg_gpocfg { + PCF5063X_GPOCFG_GPOSEL_0 = 0x00, + PCF5063X_GPOCFG_GPOSEL_LED_NFET = 0x01, + PCF5063X_GPOCFG_GPOSEL_SYSxOK = 0x02, + PCF5063X_GPOCFG_GPOSEL_CLK32K = 0x03, + PCF5063X_GPOCFG_GPOSEL_ADAPUSB = 0x04, + PCF5063X_GPOCFG_GPOSEL_USBxOK = 0x05, + PCF5063X_GPOCFG_GPOSEL_ACTPH4 = 0x06, + PCF5063X_GPOCFG_GPOSEL_1 = 0x07, + PCF5063X_GPOCFG_GPOSEL_INVERSE = 0x08, +}; +#define PCF5063X_GPOCFG_GPOSEL_MASK 0x07 + +enum pcf5063X_reg_mbcc7 { + PCF5063X_MBCC7_USB_100mA = 0x00, + PCF5063X_MBCC7_USB_500mA = 0x01, + PCF5063X_MBCC7_USB_1000mA = 0x02, + PCF5063X_MBCC7_USB_SUSPEND = 0x03, + PCF5063X_MBCC7_BATTEMP_EN = 0x04, + PCF5063X_MBCC7_BATSYSIMAX_1A6 = 0x00, + PCF5063X_MBCC7_BATSYSIMAX_1A8 = 0x40, + PCF5063X_MBCC7_BATSYSIMAX_2A0 = 0x80, + PCF5063X_MBCC7_BATSYSIMAX_2A2 = 0xc0, +}; +#define PCF56033_MBCC7_USB_MASK 0x03 + +enum pcf5063X_reg_mbcc8 { + PCF5063X_MBCC8_USBENASUS = 0x10, +}; + +enum pcf5063X_reg_mbcs1 { + PCF5063X_MBCS1_USBPRES = 0x01, + PCF5063X_MBCS1_USBOK = 0x02, + PCF5063X_MBCS1_ADAPTPRES = 0x04, + PCF5063X_MBCS1_ADAPTOK = 0x08, + PCF5063X_MBCS1_TBAT_OK = 0x00, + PCF5063X_MBCS1_TBAT_ABOVE = 0x10, + PCF5063X_MBCS1_TBAT_BELOW = 0x20, + PCF5063X_MBCS1_TBAT_UNDEF = 0x30, + PCF5063X_MBCS1_PREWDTEXP = 0x40, + PCF5063X_MBCS1_WDTEXP = 0x80, +}; + +enum pcf5063X_reg_mbcs2_mbcmod { + PCF5063X_MBCS2_MBC_PLAY = 0x00, + PCF5063X_MBCS2_MBC_USB_PRE = 0x01, + PCF5063X_MBCS2_MBC_USB_PRE_WAIT = 0x02, + PCF5063X_MBCS2_MBC_USB_FAST = 0x03, + PCF5063X_MBCS2_MBC_USB_FAST_WAIT= 0x04, + PCF5063X_MBCS2_MBC_USB_SUSPEND = 0x05, + PCF5063X_MBCS2_MBC_ADP_PRE = 0x06, + PCF5063X_MBCS2_MBC_ADP_PRE_WAIT = 0x07, + PCF5063X_MBCS2_MBC_ADP_FAST = 0x08, + PCF5063X_MBCS2_MBC_ADP_FAST_WAIT= 0x09, + PCF5063X_MBCS2_MBC_BAT_FULL = 0x0a, + PCF5063X_MBCS2_MBC_HALT = 0x0b, +}; +#define PCF5063X_MBCS2_MBC_MASK 0x0f +enum pcf5063X_reg_mbcs2_chgstat { + PCF5063X_MBCS2_CHGS_NONE = 0x00, + PCF5063X_MBCS2_CHGS_ADAPTER = 0x10, + PCF5063X_MBCS2_CHGS_USB = 0x20, + PCF5063X_MBCS2_CHGS_BOTH = 0x30, +}; +#define PCF5063X_MBCS2_RESSTAT_AUTO 0x40 + +enum pcf5063X_reg_mbcs3 { + PCF5063X_MBCS3_USBLIM_PLAY = 0x01, + PCF5063X_MBCS3_USBLIM_CGH = 0x02, + PCF5063X_MBCS3_TLIM_PLAY = 0x04, + PCF5063X_MBCS3_TLIM_CHG = 0x08, + PCF5063X_MBCS3_ILIM = 0x10, /* 1: Ibat > Icutoff */ + PCF5063X_MBCS3_VLIM = 0x20, /* 1: Vbat == Vmax */ + PCF5063X_MBCS3_VBATSTAT = 0x40, /* 1: Vbat > Vbatcond */ + PCF5063X_MBCS3_VRES = 0x80, /* 1: Vbat > Vth(RES) */ +}; + + +enum pcf5063X_reg_int1 { + PCF5063X_INT1_ADPINS = 0x01, /* Adapter inserted */ + PCF5063X_INT1_ADPREM = 0x02, /* Adapter removed */ + PCF5063X_INT1_USBINS = 0x04, /* USB inserted */ + PCF5063X_INT1_USBREM = 0x08, /* USB removed */ + /* reserved */ + PCF5063X_INT1_ALARM = 0x40, /* RTC alarm time is reached */ + PCF5063X_INT1_SECOND = 0x80, /* RTC periodic second interrupt */ +}; + +enum pcf5063X_reg_int2 { + PCF5063X_INT2_ONKEYR = 0x01, /* ONKEY rising edge */ + PCF5063X_INT2_ONKEYF = 0x02, /* ONKEY falling edge */ + PCF5063X_INT2_EXTON1R = 0x04, /* EXTON1 rising edge */ + PCF5063X_INT2_EXTON1F = 0x08, /* EXTON1 falling edge */ + PCF5063X_INT2_EXTON2R = 0x10, /* EXTON2 rising edge */ + PCF5063X_INT2_EXTON2F = 0x20, /* EXTON2 falling edge */ + PCF5063X_INT2_EXTON3R = 0x40, /* EXTON3 rising edge */ + PCF5063X_INT2_EXTON3F = 0x80, /* EXTON3 falling edge */ +}; + +enum pcf5063X_reg_int3 { + PCF5063X_INT3_BATFULL = 0x01, /* Battery full */ + PCF5063X_INT3_CHGHALT = 0x02, /* Charger halt */ + PCF5063X_INT3_THLIMON = 0x04, + PCF5063X_INT3_THLIMOFF = 0x08, + PCF5063X_INT3_USBLIMON = 0x10, + PCF5063X_INT3_USBLIMOFF = 0x20, + PCF5063X_INT3_ADCRDY = 0x40, /* ADC result ready */ + PCF5063X_INT3_ONKEY1S = 0x80, /* ONKEY pressed 1 second */ +}; + +enum pcf5063X_reg_int4 { + PCF5063X_INT4_LOWSYS = 0x01, + PCF5063X_INT4_LOWBAT = 0x02, + PCF5063X_INT4_HIGHTMP = 0x04, + PCF5063X_INT4_AUTOPWRFAIL = 0x08, + PCF5063X_INT4_DWN1PWRFAIL = 0x10, + PCF5063X_INT4_DWN2PWRFAIL = 0x20, + PCF5063X_INT4_LEDPWRFAIL = 0x40, + PCF5063X_INT4_LEDOVP = 0x80, +}; + +enum pcf5063X_reg_int5 { + PCF5063X_INT5_LDO1PWRFAIL = 0x01, + PCF5063X_INT5_LDO2PWRFAIL = 0x02, + PCF5063X_INT5_LDO3PWRFAIL = 0x04, + PCF5063X_INT5_LDO4PWRFAIL = 0x08, + PCF5063X_INT5_LDO5PWRFAIL = 0x10, + PCF5063X_INT5_LDO6PWRFAIL = 0x20, + PCF5063X_INT5_HCLDOPWRFAIL = 0x40, + PCF5063X_INT5_HCLDOOVL = 0x80, +}; + + +#endif /* PCF5063X_H */ diff --git a/firmware/target/arm/tcc780x/cowond2/backlight-cowond2.c b/firmware/target/arm/tcc780x/cowond2/backlight-cowond2.c index 39a9abf073..d417687804 100644 --- a/firmware/target/arm/tcc780x/cowond2/backlight-cowond2.c +++ b/firmware/target/arm/tcc780x/cowond2/backlight-cowond2.c @@ -22,7 +22,9 @@ #include "system.h" #include "backlight.h" #include "pcf50606.h" +#include "pcf50635.h" #include "tcc780x.h" +#include "power-target.h" int _backlight_init(void) { @@ -35,17 +37,49 @@ int _backlight_init(void) void _backlight_set_brightness(int brightness) { int level = disable_irq_save(); - pcf50606_write(PCF5060X_PWMC1, 0xe1 | (MAX_BRIGHTNESS_SETTING-brightness)<<1); - pcf50606_write(PCF5060X_GPOC1, 0x3); + + if (get_pmu_type() == PCF50606) + { + pcf50606_write(PCF5060X_PWMC1, + 0xe1 | (MAX_BRIGHTNESS_SETTING-brightness)<<1); + pcf50606_write(PCF5060X_GPOC1, 0x3); + } + else + { + static const int brightness_lookup[MAX_BRIGHTNESS_SETTING+1] = + {0x1, 0x8, 0xa, 0xe, 0x12, 0x16, 0x19, 0x1b, 0x1e, + 0x21, 0x24, 0x26, 0x28, 0x2a, 0x2c}; + + pcf50635_write(PCF5063X_REG_LEDOUT, brightness_lookup[brightness]); + } + restore_irq(level); } void _backlight_on(void) { - GPIOA_SET = (1<<6); + if (get_pmu_type() == PCF50606) + { + GPIOA_SET = (1<<6); + } + else + { + int level = disable_irq_save(); + pcf50635_write(PCF5063X_REG_LEDENA, 1); + restore_irq(level); + } } void _backlight_off(void) { - GPIOA_CLEAR = (1<<6); + if (get_pmu_type() == PCF50606) + { + GPIOA_CLEAR = (1<<6); + } + else + { + int level = disable_irq_save(); + pcf50635_write(PCF5063X_REG_LEDENA, 0); + restore_irq(level); + } } diff --git a/firmware/target/arm/tcc780x/cowond2/power-cowond2.c b/firmware/target/arm/tcc780x/cowond2/power-cowond2.c index 8190108dd4..d5f4ec9768 100644 --- a/firmware/target/arm/tcc780x/cowond2/power-cowond2.c +++ b/firmware/target/arm/tcc780x/cowond2/power-cowond2.c @@ -23,31 +23,51 @@ #include "system.h" #include "power.h" #include "pcf50606.h" +#include "pcf50635.h" #include "button-target.h" #include "tuner.h" #include "backlight-target.h" #include "powermgmt.h" +#include "power-target.h" + +static enum pmu_type pmu; + +enum pmu_type get_pmu_type() +{ + return pmu; +} void power_init(void) { - unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */ + /* Configure GPA6 as input and wait a short while */ + GPIOA_DIR &= ~(1<<6); - /* Clear pending interrupts from pcf50606 */ - pcf50606_read_multiple(0x02, data, 3); - - /* Set outputs as per OF - further investigation required. */ - pcf50606_write(PCF5060X_DCDEC1, 0xe4); - pcf50606_write(PCF5060X_IOREGC, 0xf5); - pcf50606_write(PCF5060X_D1REGC1, 0xf5); - pcf50606_write(PCF5060X_D2REGC1, 0xe9); - pcf50606_write(PCF5060X_D3REGC1, 0xf8); /* WM8985 3.3v */ - pcf50606_write(PCF5060X_DCUDC1, 0xe7); - pcf50606_write(PCF5060X_LPREGC1, 0x0); - pcf50606_write(PCF5060X_LPREGC2, 0x2); + udelay(10); + + /* Value of GPA6 determines PMU chip type */ + if (GPIOA & (1<<6)) + { + pmu = PCF50635; + + pcf50635_init(); + } + else + { + pmu = PCF50606; + + /* Configure GPA6 for output (backlight enable) */ + GPIOA_DIR |= (1<<6); + + pcf50606_init(); + + /* Clear pending interrupts */ + unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */ + pcf50606_read_multiple(0x02, data, 3); #ifndef BOOTLOADER - IEN |= EXT3_IRQ_MASK; /* Unmask EXT3 */ + IEN |= EXT3_IRQ_MASK; /* Unmask EXT3 */ #endif + } } void power_off(void) @@ -55,7 +75,7 @@ void power_off(void) /* Turn the backlight off first to avoid a bright stripe on power-off */ _backlight_off(); sleep(HZ/10); - + /* Power off the player using the same mechanism as the OF */ GPIOA_CLEAR = (1<<7); while(true); @@ -114,15 +134,15 @@ bool tuner_power(bool status) in host read mode: */ /* 1. Set direction of the DATA-line to input-mode. */ - GPIOC_DIR &= ~(1 << 30); + GPIOC_DIR &= ~(1 << 30); /* 2. Drive NR_W low */ - GPIOC_CLEAR = (1 << 31); - GPIOC_DIR |= (1 << 31); + GPIOC_CLEAR = (1 << 31); + GPIOC_DIR |= (1 << 31); /* 3. Drive CLOCK high */ - GPIOC_SET = (1 << 29); - GPIOC_DIR |= (1 << 29); + GPIOC_SET = (1 << 29); + GPIOC_DIR |= (1 << 29); lv24020lp_power(true); } diff --git a/firmware/target/arm/tcc780x/cowond2/power-target.h b/firmware/target/arm/tcc780x/cowond2/power-target.h new file mode 100644 index 0000000000..38288f38c8 --- /dev/null +++ b/firmware/target/arm/tcc780x/cowond2/power-target.h @@ -0,0 +1,32 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2009 Rob Purchase + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef _POWER_TARGET_H +#define _POWER_TARGET_H + +enum pmu_type +{ + PCF50606, + PCF50635 +}; + +enum pmu_type get_pmu_type(void); + +#endif /* _POWER_TARGET_H */ diff --git a/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c b/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c index b52d5c46ba..9b2320b7cf 100644 --- a/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c +++ b/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c @@ -23,7 +23,9 @@ #include "adc.h" #include "powermgmt.h" #include "kernel.h" +#include "power-target.h" #include "pcf50606.h" +#include "pcf50635.h" unsigned short current_voltage = 3910; @@ -66,7 +68,11 @@ unsigned int battery_adc_voltage(void) if (TIME_BEFORE(last_tick+HZ, current_tick)) { short adc_val; - pcf50606_read_adc(PCF5060X_ADC_BATVOLT_RES, &adc_val, NULL); + + if (get_pmu_type() == PCF50606) + pcf50606_read_adc(PCF5060X_ADC_BATVOLT_RES, &adc_val, NULL); + else + pcf50635_read_adc(PCF5063X_ADCC1_MUX_BATSNS_RES, &adc_val, NULL); current_voltage = (adc_val * BATTERY_SCALE_FACTOR) >> 10; @@ -75,4 +81,3 @@ unsigned int battery_adc_voltage(void) return current_voltage; } - -- cgit v1.2.3