1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Rob Purchase 2009-10-10 17:35:02 +00:00
parent 31464f7930
commit 16ada4cb81
9 changed files with 679 additions and 27 deletions

View file

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

View file

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

View file

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

View file

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