Reworked iPod Nano 2G PMU code, added RTC and battery ADC.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22967 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
6b8a78f793
commit
be25469b9b
8 changed files with 213 additions and 27 deletions
|
@ -1332,6 +1332,8 @@ target/arm/s5l8700/ipodnano2g/power-nano2g.c
|
|||
target/arm/s5l8700/ipodnano2g/audio-nano2g.c
|
||||
target/arm/s5l8700/ipodnano2g/ftl-nano2g.c
|
||||
target/arm/s5l8700/ipodnano2g/nand-nano2g.c
|
||||
target/arm/s5l8700/ipodnano2g/pmu-nano2g.c
|
||||
target/arm/s5l8700/ipodnano2g/rtc-nano2g.c
|
||||
#endif
|
||||
|
||||
#ifndef SIMULATOR
|
||||
|
|
|
@ -83,8 +83,7 @@
|
|||
#define CONFIG_CODEC SWCODEC
|
||||
|
||||
/* define this if you have a real-time clock */
|
||||
//#define CONFIG_RTC RTC_S5L8700
|
||||
#define CONFIG_RTC RTC_S35390A
|
||||
#define CONFIG_RTC RTC_NANO2G
|
||||
|
||||
#define CONFIG_LCD LCD_NANO2G
|
||||
|
||||
|
|
|
@ -263,6 +263,8 @@ Lyre prototype 1*/
|
|||
#define RTC_S5L8700 14
|
||||
#define RTC_S35390A 15
|
||||
#define RTC_JZ47XX 16 /* Ingenic Jz47XX */
|
||||
#define RTC_NANO2G 17 /* This seems to be a PCFxxxxx,
|
||||
but we don't know which one */
|
||||
|
||||
/* USB On-the-go */
|
||||
#define USBOTG_M66591 6591 /* M:Robe 500 */
|
||||
|
|
|
@ -23,23 +23,9 @@
|
|||
#include "config.h"
|
||||
#include "backlight.h"
|
||||
#include "backlight-target.h"
|
||||
#include "i2c-s5l8700.h"
|
||||
#include "pmu-target.h"
|
||||
|
||||
|
||||
static unsigned char bl_i2c_readbyte(int address)
|
||||
{
|
||||
unsigned char tmp;
|
||||
|
||||
i2c_read(0xe6, address, 1, &tmp);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static void bl_i2c_writebyte(int address, unsigned char val)
|
||||
{
|
||||
i2c_write(0xe6, address, 1, &val);
|
||||
}
|
||||
|
||||
void _backlight_set_brightness(int brightness)
|
||||
{
|
||||
(void)brightness;
|
||||
|
@ -47,19 +33,19 @@ void _backlight_set_brightness(int brightness)
|
|||
|
||||
void _backlight_on(void)
|
||||
{
|
||||
bl_i2c_writebyte(0x29,1);
|
||||
pmu_write(0x29, 1);
|
||||
}
|
||||
|
||||
void _backlight_off(void)
|
||||
{
|
||||
bl_i2c_writebyte(0x29,0);
|
||||
pmu_write(0x29, 0);
|
||||
}
|
||||
|
||||
bool _backlight_init(void)
|
||||
{
|
||||
bl_i2c_writebyte(0x2a,6);
|
||||
bl_i2c_writebyte(0x28,0x2e);
|
||||
bl_i2c_writebyte(0x2b,20);
|
||||
pmu_write(0x2a, 6);
|
||||
pmu_write(0x28, 0x2e);
|
||||
pmu_write(0x2b, 20);
|
||||
|
||||
_backlight_on();
|
||||
|
||||
|
|
90
firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c
Normal file
90
firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c
Normal file
|
@ -0,0 +1,90 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright © 2008 Rafaël Carré
|
||||
*
|
||||
* 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 "config.h"
|
||||
#include "kernel.h"
|
||||
#include "i2c-s5l8700.h"
|
||||
|
||||
static struct mutex pmu_adc_mutex;
|
||||
int pmu_initialized;
|
||||
|
||||
unsigned char pmu_read(int address)
|
||||
{
|
||||
unsigned char tmp;
|
||||
|
||||
i2c_read(0xe6, address, 1, &tmp);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void pmu_write(int address, unsigned char val)
|
||||
{
|
||||
i2c_write(0xe6, address, 1, &val);
|
||||
}
|
||||
|
||||
void pmu_read_multiple(int address, int count, unsigned char* buffer)
|
||||
{
|
||||
i2c_read(0xe6, address, count, buffer);
|
||||
}
|
||||
|
||||
void pmu_write_multiple(int address, int count, unsigned char* buffer)
|
||||
{
|
||||
i2c_write(0xe6, address, count, buffer);
|
||||
}
|
||||
|
||||
void pmu_init(void)
|
||||
{
|
||||
if (pmu_initialized) return;
|
||||
mutex_init(&pmu_adc_mutex);
|
||||
pmu_initialized = 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
35
firmware/target/arm/s5l8700/ipodnano2g/pmu-target.h
Normal file
35
firmware/target/arm/s5l8700/ipodnano2g/pmu-target.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright © 2009 Michael Sparmann
|
||||
*
|
||||
* 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 __PMU_NANO2G_H__
|
||||
#define __PMU_NANO2G_H__
|
||||
|
||||
#include "config.h"
|
||||
|
||||
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_battery_voltage(void);
|
||||
int pmu_read_battery_current(void);
|
||||
void pmu_init(void);
|
||||
|
||||
#endif
|
|
@ -20,9 +20,8 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
#include "adc.h"
|
||||
#include "adc-target.h"
|
||||
#include "powermgmt.h"
|
||||
#include "pmu-target.h"
|
||||
|
||||
const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
|
||||
{
|
||||
|
@ -52,14 +51,14 @@ const unsigned short percent_to_volt_charge[11] =
|
|||
};
|
||||
#endif /* CONFIG_CHARGING */
|
||||
|
||||
/* ADC should read 0x3ff=5.12V */
|
||||
#define BATTERY_SCALE_FACTOR 5125
|
||||
/* ADC should read 0x3ff=6.00V */
|
||||
#define BATTERY_SCALE_FACTOR 6000
|
||||
/* full-scale ADC readout (2^10) in millivolt */
|
||||
|
||||
|
||||
/* Returns battery voltage from ADC [millivolts] */
|
||||
unsigned int battery_adc_voltage(void)
|
||||
{
|
||||
return 4000;
|
||||
return pmu_read_battery_voltage();
|
||||
}
|
||||
|
||||
|
|
73
firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c
Normal file
73
firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2002 by Linus Nielsen Feltzing, Uwe Freese, Laurent Baum
|
||||
*
|
||||
* 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 "config.h"
|
||||
#include "rtc.h"
|
||||
#include "kernel.h"
|
||||
#include "system.h"
|
||||
#include "pmu-target.h"
|
||||
|
||||
void rtc_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
int rtc_read_datetime(struct tm *tm)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned char buf[7];
|
||||
|
||||
pmu_read_multiple(0x59, sizeof(buf), buf);
|
||||
|
||||
for (i = 0; i < sizeof(buf); i++)
|
||||
buf[i] = BCD2DEC(buf[i]);
|
||||
|
||||
tm->tm_sec = buf[0];
|
||||
tm->tm_min = buf[1];
|
||||
tm->tm_hour = buf[2];
|
||||
tm->tm_wday = buf[3];
|
||||
tm->tm_mday = buf[4];
|
||||
tm->tm_mon = buf[5] - 1;
|
||||
tm->tm_year = buf[6] + 100;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rtc_write_datetime(const struct tm *tm)
|
||||
{
|
||||
unsigned int i;
|
||||
int rc, oldlevel;
|
||||
unsigned char buf[7];
|
||||
|
||||
buf[0] = tm->tm_sec;
|
||||
buf[1] = tm->tm_min;
|
||||
buf[2] = tm->tm_hour;
|
||||
buf[3] = tm->tm_wday;
|
||||
buf[4] = tm->tm_mday;
|
||||
buf[5] = tm->tm_mon + 1;
|
||||
buf[6] = tm->tm_year - 100;
|
||||
|
||||
for (i = 0; i < sizeof(buf); i++)
|
||||
buf[i] = DEC2BCD(buf[i]);
|
||||
|
||||
pmu_write_multiple(0x59, sizeof(buf), buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in a new issue