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
This commit is contained in:
Michael Sparmann 2009-10-11 18:20:56 +00:00
parent 4ecc5a1e9b
commit b729a7d75e
8 changed files with 112 additions and 59 deletions

View file

@ -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

View file

@ -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 */

View file

@ -28,7 +28,7 @@
void _backlight_set_brightness(int brightness)
{
(void)brightness;
pmu_write(0x28, brightness);
}
void _backlight_on(void)

View file

@ -57,50 +57,84 @@ void pmu_init(void)
pmu_initialized = 1;
}
int pmu_read_adc(unsigned int adc)
{
int data = 0;
if (!pmu_initialized) pmu_init();
mutex_lock(&pmu_adc_mutex);
pmu_write(0x54, 5 | (adc << 4));
while ((data & 0x80) == 0)
{
yield();
data = pmu_read(0x57);
}
int value = (pmu_read(0x55) << 2) | (data & 3);
mutex_unlock(&pmu_adc_mutex);
return value;
}
/* millivolts */
int pmu_read_battery_voltage(void)
{
int data = 0;
if (!pmu_initialized) pmu_init();
mutex_lock(&pmu_adc_mutex);
pmu_write(0x54, 0x05);
while ((data & 0x80) == 0)
{
yield();
data = pmu_read(0x57);
}
int millivolts = ((pmu_read(0x55) << 2) | (data & 3)) * 6;
mutex_unlock(&pmu_adc_mutex);
return millivolts;
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);
}

View file

@ -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

View file

@ -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 */

View file

@ -61,4 +61,3 @@ unsigned int battery_adc_voltage(void)
{
return pmu_read_battery_voltage();
}

View file

@ -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;
}