From b729a7d75ec5b2fb73aa67c8f986e2793f8efcaf Mon Sep 17 00:00:00 2001 From: Michael Sparmann Date: Sun, 11 Oct 2009 18:20:56 +0000 Subject: iPod Nano 2G PMU rework, added backlight brightness setting and USB charging speed setting git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23114 a1c6a512-1295-4272-9138-f99709370657 --- firmware/export/config-ipodnano2g.h | 12 ++-- firmware/export/s5l8700.h | 4 +- .../arm/s5l8700/ipodnano2g/backlight-nano2g.c | 2 +- .../target/arm/s5l8700/ipodnano2g/pmu-nano2g.c | 80 +++++++++++++++------- .../target/arm/s5l8700/ipodnano2g/pmu-target.h | 10 ++- .../target/arm/s5l8700/ipodnano2g/power-nano2g.c | 42 +++++++----- .../arm/s5l8700/ipodnano2g/powermgmt-nano2g.c | 1 - .../target/arm/s5l8700/ipodnano2g/rtc-nano2g.c | 4 +- 8 files changed, 104 insertions(+), 51 deletions(-) (limited to 'firmware') diff --git a/firmware/export/config-ipodnano2g.h b/firmware/export/config-ipodnano2g.h index 5e92ea889a..cca87aabce 100644 --- a/firmware/export/config-ipodnano2g.h +++ b/firmware/export/config-ipodnano2g.h @@ -104,7 +104,7 @@ /* Define this for LCD backlight available */ #define HAVE_BACKLIGHT -/* #define HAVE_BACKLIGHT_BRIGHTNESS - not yet */ +#define HAVE_BACKLIGHT_BRIGHTNESS /* Define this if you have a software controlled poweroff */ #define HAVE_SW_POWEROFF @@ -138,6 +138,8 @@ /* I2C interface */ #define CONFIG_I2C I2C_S5L8700 +#define HAVE_USB_CHARGING_ENABLE + /* The size of the flash ROM */ #define FLASH_SIZE 0x400000 @@ -187,9 +189,9 @@ #define MIN_CONTRAST_SETTING 1 #define MAX_CONTRAST_SETTING 30 #define DEFAULT_CONTRAST_SETTING 19 /* Match boot contrast */ +#endif /* Main LCD backlight brightness range and defaults */ -#define MIN_BRIGHTNESS_SETTING 0 -#define MAX_BRIGHTNESS_SETTING 31 -#define DEFAULT_BRIGHTNESS_SETTING 20 -#endif +#define MIN_BRIGHTNESS_SETTING 1 +#define MAX_BRIGHTNESS_SETTING 0x2e +#define DEFAULT_BRIGHTNESS_SETTING 0x20 diff --git a/firmware/export/s5l8700.h b/firmware/export/s5l8700.h index e649b92c14..f08abee8ff 100644 --- a/firmware/export/s5l8700.h +++ b/firmware/export/s5l8700.h @@ -552,14 +552,14 @@ #define PDAT7 (*(REG32_PTR_T)(0x3CF00074)) /* The data register for port 7 */ #define PCON10 (*(REG32_PTR_T)(0x3CF000A0)) /* Configures the pins of port 10 */ #define PDAT10 (*(REG32_PTR_T)(0x3CF000A4)) /* The data register for port 10 */ +#define PCON11 (*(REG32_PTR_T)(0x3CF000B0)) /* Configures the pins of port 11 */ +#define PDAT11 (*(REG32_PTR_T)(0x3CF000B4)) /* The data register for port 11 */ #define PCON13 (*(REG32_PTR_T)(0x3CF000D0)) /* Configures the pins of port 13 */ #define PDAT13 (*(REG32_PTR_T)(0x3CF000D4)) /* The data register for port 13 */ #define PCON14 (*(REG32_PTR_T)(0x3CF000E0)) /* Configures the pins of port 14 */ #define PDAT14 (*(REG32_PTR_T)(0x3CF000E4)) /* The data register for port 14 */ #define PCON_ASRAM (*(REG32_PTR_T)(0x3CF000F0)) /* Configures the pins of port nor flash */ #define PCON_SDRAM (*(REG32_PTR_T)(0x3CF000F4)) /* Configures the pins of port sdram */ -#define PCON11 (*(REG32_PTR_T)(0x3CF000F8)) /* Configures the pins of port 11 */ -#define PDAT11 (*(REG32_PTR_T)(0x3CF000FC)) /* The data register for port 11 */ /* 25. UART */ diff --git a/firmware/target/arm/s5l8700/ipodnano2g/backlight-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/backlight-nano2g.c index 21ba3e0bf0..705b5858bf 100644 --- a/firmware/target/arm/s5l8700/ipodnano2g/backlight-nano2g.c +++ b/firmware/target/arm/s5l8700/ipodnano2g/backlight-nano2g.c @@ -28,7 +28,7 @@ void _backlight_set_brightness(int brightness) { - (void)brightness; + pmu_write(0x28, brightness); } void _backlight_on(void) diff --git a/firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c index ca2b5f2775..be026a8cf4 100644 --- a/firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c +++ b/firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c @@ -57,50 +57,84 @@ void pmu_init(void) pmu_initialized = 1; } -int pmu_read_battery_voltage(void) +int pmu_read_adc(unsigned int adc) { int data = 0; if (!pmu_initialized) pmu_init(); mutex_lock(&pmu_adc_mutex); - pmu_write(0x54, 0x05); + pmu_write(0x54, 5 | (adc << 4)); while ((data & 0x80) == 0) { yield(); data = pmu_read(0x57); } - int millivolts = ((pmu_read(0x55) << 2) | (data & 3)) * 6; + int value = (pmu_read(0x55) << 2) | (data & 3); mutex_unlock(&pmu_adc_mutex); - return millivolts; + return value; +} + +/* millivolts */ +int pmu_read_battery_voltage(void) +{ + return pmu_read_adc(0) * 6; } +/* milliamps */ int pmu_read_battery_current(void) { - int data = 0; - if (!pmu_initialized) pmu_init(); - mutex_lock(&pmu_adc_mutex); - pmu_write(0x54, 0x25); - while ((data & 0x80) == 0) - { - yield(); - data = pmu_read(0x57); - } - int milliamps = (pmu_read(0x55) << 2) | (data & 3); - mutex_unlock(&pmu_adc_mutex); - return milliamps; + return pmu_read_adc(2); } -void pmu_switch_power(int gate, int onoff) +void pmu_ldo_on_in_standby(unsigned int ldo, int onoff) { - if (gate < 4) + if (ldo < 4) { - unsigned char newval = pmu_read(0x3B) & ~(1 << (2 * gate)); - if (onoff) newval |= 1 << (2 * gate); + unsigned char newval = pmu_read(0x3B) & ~(1 << (2 * ldo)); + if (onoff) newval |= 1 << (2 * ldo); pmu_write(0x3B, newval); } - else if (gate < 7) + else if (ldo < 8) { - unsigned char newval = pmu_read(0x3C) & ~(1 << (2 * (gate - 4))); - if (onoff) newval |= 1 << (2 * (gate - 4)); + unsigned char newval = pmu_read(0x3C) & ~(1 << (2 * (ldo - 4))); + if (onoff) newval |= 1 << (2 * (ldo - 4)); pmu_write(0x3C, newval); } } + +void pmu_ldo_set_voltage(unsigned int ldo, unsigned char voltage) +{ + if (ldo > 6) return; + pmu_write(0x2d + (ldo << 1), voltage); +} + +void pmu_ldo_power_on(unsigned int ldo) +{ + if (ldo > 6) return; + pmu_write(0x2e + (ldo << 1), 1); +} + +void pmu_ldo_power_off(unsigned int ldo) +{ + if (ldo > 6) return; + pmu_write(0x2e + (ldo << 1), 0); +} + +void pmu_set_wake_condition(unsigned char condition) +{ + pmu_write(0xd, condition); +} + +void pmu_enter_standby(void) +{ + pmu_write(0xc, 1); +} + +void pmu_read_rtc(unsigned char* buffer) +{ + pmu_read_multiple(0x59, 7, buffer); +} + +void pmu_write_rtc(unsigned char* buffer) +{ + pmu_write_multiple(0x59, 7, buffer); +} diff --git a/firmware/target/arm/s5l8700/ipodnano2g/pmu-target.h b/firmware/target/arm/s5l8700/ipodnano2g/pmu-target.h index 43b0f54308..53f4dacc1b 100644 --- a/firmware/target/arm/s5l8700/ipodnano2g/pmu-target.h +++ b/firmware/target/arm/s5l8700/ipodnano2g/pmu-target.h @@ -28,9 +28,17 @@ unsigned char pmu_read(int address); void pmu_write(int address, unsigned char val); void pmu_read_multiple(int address, int count, unsigned char* buffer); void pmu_write_multiple(int address, int count, unsigned char* buffer); +int pmu_read_adc(unsigned int adc); int pmu_read_battery_voltage(void); int pmu_read_battery_current(void); void pmu_init(void); -void pmu_switch_power(int gate, int onoff); +void pmu_ldo_on_in_standby(unsigned int ldo, int onoff); +void pmu_ldo_set_voltage(unsigned int ldo, unsigned char voltage); +void pmu_ldo_power_on(unsigned int ldo); +void pmu_ldo_power_off(unsigned int ldo); +void pmu_set_wake_condition(unsigned char condition); +void pmu_enter_standby(void); +void pmu_read_rtc(unsigned char* buffer); +void pmu_write_rtc(unsigned char* buffer); #endif diff --git a/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c index cba1514aad..de3dbed853 100644 --- a/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c +++ b/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c @@ -32,18 +32,16 @@ void power_off(void) { - pmu_switch_power(0, 0); - pmu_switch_power(2, 0); - pmu_switch_power(3, 0); - pmu_switch_power(4, 0); - pmu_switch_power(6, 0); - pmu_switch_power(7, 0); - - pmu_write(0x36, pmu_read(0x36) & 0xF0); - pmu_write(0x34, pmu_read(0x34) & 0xF0); - pmu_write(0xD, pmu_read(0xD) | 0x40); - pmu_write(0xD, pmu_read(0xD) | 0x02); - pmu_write(0xC, 1); + pmu_ldo_on_in_standby(0, 0); + pmu_ldo_on_in_standby(1, 0); + pmu_ldo_on_in_standby(2, 0); + pmu_ldo_on_in_standby(3, 0); + pmu_ldo_on_in_standby(4, 0); + pmu_ldo_on_in_standby(5, 0); + pmu_ldo_on_in_standby(6, 0); + pmu_ldo_on_in_standby(7, 0); + pmu_set_wake_condition(0x42); /* USB inserted or EXTON1 */ + pmu_enter_standby(); while(1); } @@ -54,15 +52,27 @@ void power_init(void) } #if CONFIG_CHARGING + +#ifdef HAVE_USB_CHARGING_ENABLE +bool usb_charging_enable(bool on) +{ + PDAT11 = (PDAT11 & ~1) | (on ? 1 : 0); + return on; +} + +bool usb_charging_enabled(void) +{ + return PDAT11 & 1; +} +#endif + unsigned int power_input_status(void) { - /* TODO */ - return POWER_INPUT_NONE; + return (PDAT14 & 0x80) ? POWER_INPUT_NONE : POWER_INPUT_MAIN; } bool charging_state(void) { - /* TODO */ - return false; + return (PDAT14 & 0x80) ? false : true; } #endif /* CONFIG_CHARGING */ diff --git a/firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c index 937905f5f4..689e369da2 100644 --- a/firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c +++ b/firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c @@ -61,4 +61,3 @@ unsigned int battery_adc_voltage(void) { return pmu_read_battery_voltage(); } - diff --git a/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c index bad9581d8f..39cecc5291 100644 --- a/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c +++ b/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c @@ -33,7 +33,7 @@ int rtc_read_datetime(struct tm *tm) unsigned int i; unsigned char buf[7]; - pmu_read_multiple(0x59, sizeof(buf), buf); + pmu_read_rtc(buf); for (i = 0; i < sizeof(buf); i++) buf[i] = BCD2DEC(buf[i]); @@ -65,7 +65,7 @@ int rtc_write_datetime(const struct tm *tm) for (i = 0; i < sizeof(buf); i++) buf[i] = DEC2BCD(buf[i]); - pmu_write_multiple(0x59, sizeof(buf), buf); + pmu_write_rtc(buf); return 0; } -- cgit v1.2.3