From 152847977a420487d9c3728841101ef708e41373 Mon Sep 17 00:00:00 2001 From: Michael Sparmann Date: Sun, 2 Jan 2011 23:16:27 +0000 Subject: New port: iPod Classic (also known as iPod 6G/6.5G/7G) Major known issues: - No bootloader yet - No support for the first-generation 160GB CE-ATA hard disk drive yet - Audio playback is slow, only FLAC seems to reach realtime git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28953 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/s5l8702/ipod6g/adc-ipod6g.c | 39 +++ firmware/target/arm/s5l8702/ipod6g/adc-target.h | 33 +++ firmware/target/arm/s5l8702/ipod6g/ata-ipod6g.c | 197 ++++++++++++++ firmware/target/arm/s5l8702/ipod6g/ata-target.h | 47 ++++ firmware/target/arm/s5l8702/ipod6g/audio-ipod6g.c | 65 +++++ .../target/arm/s5l8702/ipod6g/backlight-ipod6g.c | 67 +++++ .../target/arm/s5l8702/ipod6g/backlight-target.h | 29 ++ firmware/target/arm/s5l8702/ipod6g/button-target.h | 78 ++++++ .../target/arm/s5l8702/ipod6g/cscodec-ipod6g.c | 64 +++++ .../target/arm/s5l8702/ipod6g/lcd-asm-ipod6g.S | 295 +++++++++++++++++++++ firmware/target/arm/s5l8702/ipod6g/lcd-ipod6g.c | 286 ++++++++++++++++++++ firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c | 143 ++++++++++ firmware/target/arm/s5l8702/ipod6g/pmu-target.h | 46 ++++ firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c | 75 ++++++ .../target/arm/s5l8702/ipod6g/powermgmt-ipod6g.c | 88 ++++++ firmware/target/arm/s5l8702/ipod6g/rtc-ipod6g.c | 72 +++++ 16 files changed, 1624 insertions(+) create mode 100644 firmware/target/arm/s5l8702/ipod6g/adc-ipod6g.c create mode 100644 firmware/target/arm/s5l8702/ipod6g/adc-target.h create mode 100644 firmware/target/arm/s5l8702/ipod6g/ata-ipod6g.c create mode 100644 firmware/target/arm/s5l8702/ipod6g/ata-target.h create mode 100644 firmware/target/arm/s5l8702/ipod6g/audio-ipod6g.c create mode 100644 firmware/target/arm/s5l8702/ipod6g/backlight-ipod6g.c create mode 100644 firmware/target/arm/s5l8702/ipod6g/backlight-target.h create mode 100644 firmware/target/arm/s5l8702/ipod6g/button-target.h create mode 100644 firmware/target/arm/s5l8702/ipod6g/cscodec-ipod6g.c create mode 100644 firmware/target/arm/s5l8702/ipod6g/lcd-asm-ipod6g.S create mode 100644 firmware/target/arm/s5l8702/ipod6g/lcd-ipod6g.c create mode 100644 firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c create mode 100644 firmware/target/arm/s5l8702/ipod6g/pmu-target.h create mode 100644 firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c create mode 100644 firmware/target/arm/s5l8702/ipod6g/powermgmt-ipod6g.c create mode 100644 firmware/target/arm/s5l8702/ipod6g/rtc-ipod6g.c (limited to 'firmware/target/arm/s5l8702/ipod6g') diff --git a/firmware/target/arm/s5l8702/ipod6g/adc-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/adc-ipod6g.c new file mode 100644 index 0000000000..201af5ee00 --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/adc-ipod6g.c @@ -0,0 +1,39 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: adc-s5l8700.c 21775 2009-07-11 14:12:02Z bertrik $ + * + * Copyright (C) 2009 by Bertrik Sikken + * + * 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 "inttypes.h" +#include "s5l8702.h" +#include "adc.h" +#include "adc-target.h" +#include "pmu-target.h" +#include "kernel.h" + +unsigned short adc_read(int channel) +{ + return pmu_read_adc(channel); +} + +void adc_init(void) +{ +} + diff --git a/firmware/target/arm/s5l8702/ipod6g/adc-target.h b/firmware/target/arm/s5l8702/ipod6g/adc-target.h new file mode 100644 index 0000000000..d4dce3d31f --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/adc-target.h @@ -0,0 +1,33 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: adc-target.h 21734 2009-07-09 20:17:47Z bertrik $ + * + * Copyright (C) 2006 by Barry Wardell + * + * 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 _ADC_TARGET_H_ +#define _ADC_TARGET_H_ + +#define NUM_ADC_CHANNELS 4 + +#define ADC_UNKNOWN_0 0 +#define ADC_UNKNOWN_1 1 +#define ADC_BATTERY 2 +#define ADC_UNKNOWN_3 3 + +#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ + +#endif diff --git a/firmware/target/arm/s5l8702/ipod6g/ata-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/ata-ipod6g.c new file mode 100644 index 0000000000..f1577ee857 --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/ata-ipod6g.c @@ -0,0 +1,197 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: ata-meg-fx.c 27935 2010-08-28 23:12:11Z funman $ + * + * Copyright (C) 2011 by 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. + * + ****************************************************************************/ +#include "config.h" +#include "cpu.h" +#include "kernel.h" +#include "thread.h" +#include "system.h" +#include "power.h" +#include "panic.h" +#include "pmu-target.h" +#include "ata.h" +#include "ata-target.h" +#include "s5l8702.h" + + +static struct wakeup ata_wakeup; + +#ifdef HAVE_ATA_DMA +static uint32_t ata_dma_flags; +#endif + + +void ata_reset(void) +{ + ATA_SWRST = 1; + sleep(HZ / 100); + ATA_SWRST = 0; + sleep(HZ / 10); +} + +void ata_enable(bool on) +{ + if (on) + { + PWRCON(0) &= ~(1 << 5); + ATA_CFG = 0x41; + sleep(HZ / 100); + ATA_CFG = 0x40; + sleep(HZ / 20); + ata_reset(); + ATA_CCONTROL = 1; + sleep(HZ / 5); + ATA_PIO_TIME = 0x191f7; + *ATA_HCYL = 0; + while (!(ATA_PIO_READY & 2)) yield(); + } + else + { + ATA_CCONTROL = 0; + while (!(ATA_CCONTROL & 2)) yield(); + PWRCON(1) |= 1 << 5; + } +} + +bool ata_is_coldstart(void) +{ + return false; +} + +void ata_device_init(void) +{ + VIC0INTENABLE = 1 << IRQ_ATA; +} + +uint16_t ata_read_cbr(uint32_t volatile* reg) +{ + while (!(ATA_PIO_READY & 2)); + volatile uint32_t __attribute__((unused)) dummy = *reg; + while (!(ATA_PIO_READY & 1)); + return ATA_PIO_RDATA; +} + +void ata_write_cbr(uint32_t volatile* reg, uint16_t data) +{ + while (!(ATA_PIO_READY & 2)); + *reg = data; +} + +void ata_set_pio_timings(int mode) +{ + if (mode >= 4) ATA_PIO_TIME = 0x7083; + if (mode >= 3) ATA_PIO_TIME = 0x2072; + else ATA_PIO_TIME = 0x11f3; +} + +#ifdef HAVE_ATA_DMA +static void ata_set_mdma_timings(unsigned int mode) +{ + if (mode >= 2) ATA_MDMA_TIME = 0x5072; + if (mode >= 1) ATA_MDMA_TIME = 0x7083; + else ATA_MDMA_TIME = 0x1c175; +} + +static void ata_set_udma_timings(unsigned int mode) +{ + if (mode >= 4) ATA_UDMA_TIME = 0x2010a52; + if (mode >= 3) ATA_UDMA_TIME = 0x2020a52; + if (mode >= 2) ATA_UDMA_TIME = 0x3030a52; + if (mode >= 1) ATA_UDMA_TIME = 0x3050a52; + else ATA_UDMA_TIME = 0x5071152; +} + +void ata_dma_set_mode(unsigned char mode) +{ + unsigned int modeidx = mode & 0x07; + unsigned int dmamode = mode & 0xf8; + + if (dmamode == 0x40 && modeidx <= ATA_MAX_UDMA) + { + /* Using Ultra DMA */ + ata_set_udma_timings(dmamode); + ata_dma_flags = 0x60c; + } + else if (dmamode == 0x20 && modeidx <= ATA_MAX_MWDMA) + { + /* Using Multiword DMA */ + ata_set_mdma_timings(dmamode); + ata_dma_flags = 0x408; + } + else + { + /* Don't understand this - force PIO. */ + ata_dma_flags = 0; + } +} + +bool ata_dma_setup(void *addr, unsigned long bytes, bool write) +{ + if ((((int)addr) & 0xf) || (((int)bytes) & 0xf) || !ata_dma_flags) + return false; + + if (write) clean_dcache(); + else invalidate_dcache(); + ATA_CCOMMAND = 2; + + if (write) + { + ATA_SBUF_START = addr; + ATA_SBUF_SIZE = bytes; + ATA_CFG |= 0x10; + } + else + { + ATA_TBUF_START = addr; + ATA_TBUF_SIZE = bytes; + ATA_CFG &= ~0x10; + } + ATA_XFR_NUM = bytes - 1; + + return true; +} + +bool ata_dma_finish(void) +{ + ATA_CFG |= ata_dma_flags; + ATA_CFG &= ~0x180; + wakeup_wait(&ata_wakeup, TIMEOUT_NOBLOCK); + ATA_IRQ = 0x1f; + ATA_IRQ_MASK = 1; + ATA_CCOMMAND = 1; + if (wakeup_wait(&ata_wakeup, HZ / 2) != OBJ_WAIT_SUCCEEDED) + { + ATA_CCOMMAND = 2; + ATA_CFG &= ~0x100c; + return false; + } + ATA_CCOMMAND = 2; + ATA_CFG &= ~0x100c; + return true; +} +#endif /* HAVE_ATA_DMA */ + +void INT_ATA(void) +{ + uint32_t ata_irq = ATA_IRQ; + ATA_IRQ = ata_irq; + if (ata_irq & ATA_IRQ_MASK) wakeup_signal(&ata_wakeup); + ATA_IRQ_MASK = 0; +} diff --git a/firmware/target/arm/s5l8702/ipod6g/ata-target.h b/firmware/target/arm/s5l8702/ipod6g/ata-target.h new file mode 100644 index 0000000000..e2e7bd298c --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/ata-target.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: ata-target.h 25525 2010-04-07 20:01:21Z torne $ + * + * Copyright (C) 2011 by 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 ATA_TARGET_H +#define ATA_TARGET_H + +#include "inttypes.h" +#include "s5l8702.h" + +#ifdef BOOTLOADER +#define ATA_DRIVER_CLOSE +#endif + +#define ATA_SWAP_IDENTIFY(word) (swap16(word)) + +void ata_reset(void); +void ata_device_init(void); +bool ata_is_coldstart(void); +uint16_t ata_read_cbr(uint32_t volatile* reg); +void ata_write_cbr(uint32_t volatile* reg, uint16_t data); + +#define ATA_OUT8(reg, data) ata_write_cbr(reg, data) +#define ATA_OUT16(reg, data) ata_write_cbr(reg, data) +#define ATA_IN8(reg) ata_read_cbr(reg) +#define ATA_IN16(reg) ata_read_cbr(reg) + +#define ATA_SET_DEVICE_FEATURES +void ata_set_pio_timings(int mode); + +#endif diff --git a/firmware/target/arm/s5l8702/ipod6g/audio-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/audio-ipod6g.c new file mode 100644 index 0000000000..6ede3d0c30 --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/audio-ipod6g.c @@ -0,0 +1,65 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: audio-nano2g.c 23095 2009-10-11 09:17:12Z dave $ + * + * Copyright (C) 2006 by Michael Sevakis + * + * 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 "system.h" +#include "cpu.h" +#include "audio.h" +#include "sound.h" + +#if INPUT_SRC_CAPS != 0 +void audio_set_output_source(int source) +{ + if ((unsigned)source >= AUDIO_NUM_SOURCES) + source = AUDIO_SRC_PLAYBACK; +} /* audio_set_output_source */ + +void audio_input_mux(int source, unsigned flags) +{ + (void)flags; + /* Prevent pops from unneeded switching */ + static int last_source = AUDIO_SRC_PLAYBACK; + + switch (source) + { + default: /* playback - no recording */ + source = AUDIO_SRC_PLAYBACK; + case AUDIO_SRC_PLAYBACK: +#ifdef HAVE_RECORDING + if (source != last_source) + { + audiohw_set_monitor(false); + audiohw_disable_recording(); + } +#endif + break; +#ifdef HAVE_LINE_REC + case AUDIO_SRC_LINEIN: /* recording only */ + if (source != last_source) + { + audiohw_set_monitor(false); + audiohw_enable_recording(false); /* source line */ + } + break; +#endif + } /* end switch */ + + last_source = source; +} /* audio_input_mux */ +#endif /* INPUT_SRC_CAPS != 0 */ diff --git a/firmware/target/arm/s5l8702/ipod6g/backlight-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/backlight-ipod6g.c new file mode 100644 index 0000000000..dc21d161de --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/backlight-ipod6g.c @@ -0,0 +1,67 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: backlight-nano2g.c 28601 2010-11-14 20:39:18Z theseven $ + * + * Copyright (C) 2009 by Dave Chapman + * + * 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 + +#include "config.h" +#include "kernel.h" +#include "backlight.h" +#include "backlight-target.h" +#include "pmu-target.h" + +#ifdef HAVE_LCD_SLEEP +bool lcd_active(void); +void lcd_awake(void); +void lcd_update(void); +#endif + +void _backlight_set_brightness(int brightness) +{ + pmu_write(0x28, brightness); +} + +void _backlight_on(void) +{ +#ifdef HAVE_LCD_SLEEP + if (!lcd_active()) + { + lcd_awake(); + lcd_update(); + sleep(HZ/8); + } +#endif + pmu_write(0x29, 1); +} + +void _backlight_off(void) +{ + pmu_write(0x29, 0); +} + +bool _backlight_init(void) +{ + pmu_write(0x2a, 6); + pmu_write(0x28, 0x20); + pmu_write(0x2b, 20); + + _backlight_on(); + + return true; +} diff --git a/firmware/target/arm/s5l8702/ipod6g/backlight-target.h b/firmware/target/arm/s5l8702/ipod6g/backlight-target.h new file mode 100644 index 0000000000..05a8addfea --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/backlight-target.h @@ -0,0 +1,29 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: backlight-target.h 21478 2009-06-23 18:11:03Z bertrik $ + * + * Copyright (C) 2008 by Marcoen Hirschberg + * + * 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 BACKLIGHT_TARGET_H +#define BACKLIGHT_TARGET_H + +bool _backlight_init(void); +void _backlight_on(void); +void _backlight_off(void); +void _backlight_set_brightness(int brightness); + +#endif diff --git a/firmware/target/arm/s5l8702/ipod6g/button-target.h b/firmware/target/arm/s5l8702/ipod6g/button-target.h new file mode 100644 index 0000000000..0bd89d1d2a --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/button-target.h @@ -0,0 +1,78 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: button-target.h 21828 2009-07-12 22:16:51Z dave $ + * + * Copyright (C) 2006 by Barry Wardell + * + * 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 _BUTTON_TARGET_H_ +#define _BUTTON_TARGET_H_ + +#include +#include "config.h" + +#define HAS_BUTTON_HOLD + +bool button_hold(void); +void button_init_device(void); +int button_read_device(void); + +void ipod_mini_button_int(void); +void ipod_3g_button_int(void); +void ipod_4g_button_int(void); + +/* iPod specific button codes */ + +#define BUTTON_SELECT 0x00000001 +#define BUTTON_MENU 0x00000002 + +#define BUTTON_LEFT 0x00000004 +#define BUTTON_RIGHT 0x00000008 +#define BUTTON_SCROLL_FWD 0x00000010 +#define BUTTON_SCROLL_BACK 0x00000020 + +#define BUTTON_PLAY 0x00000040 + +#define BUTTON_MAIN (BUTTON_SELECT|BUTTON_MENU\ + |BUTTON_LEFT|BUTTON_RIGHT|BUTTON_SCROLL_FWD\ + |BUTTON_SCROLL_BACK|BUTTON_PLAY) + + /* Remote control's buttons */ +#ifdef IPOD_ACCESSORY_PROTOCOL +#define BUTTON_RC_PLAY 0x00100000 +#define BUTTON_RC_STOP 0x00080000 + +#define BUTTON_RC_LEFT 0x00040000 +#define BUTTON_RC_RIGHT 0x00020000 +#define BUTTON_RC_VOL_UP 0x00010000 +#define BUTTON_RC_VOL_DOWN 0x00008000 + +#define BUTTON_REMOTE (BUTTON_RC_PLAY|BUTTON_RC_STOP\ + |BUTTON_RC_LEFT|BUTTON_RC_RIGHT\ + |BUTTON_RC_VOL_UP|BUTTON_RC_VOL_DOWN) +#else +#define BUTTON_REMOTE 0 +#endif + +/* This is for later +#define BUTTON_SCROLL_TOUCH 0x00000200 +*/ + + +#define POWEROFF_BUTTON BUTTON_PLAY +#define POWEROFF_COUNT 40 + +#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/arm/s5l8702/ipod6g/cscodec-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/cscodec-ipod6g.c new file mode 100644 index 0000000000..460b254730 --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/cscodec-ipod6g.c @@ -0,0 +1,64 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: wmcodec-s5l8700.c 22025 2009-07-25 00:49:13Z dave $ + * + * S5L8702-specific code for Cirrus codecs + * + * Copyright (c) 2010 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. + * + ****************************************************************************/ + +#include "system.h" +#include "audiohw.h" +#include "i2c-s5l8702.h" +#include "s5l8702.h" +#include "cscodec.h" + +void audiohw_init(void) +{ +#ifdef HAVE_CS42L55 + audiohw_preinit(); +#endif +} + +unsigned char cscodec_read(int reg) +{ + unsigned char data; + i2c_read(0, 0x94, reg, 1, &data); + return data; +} + +void cscodec_write(int reg, unsigned char data) +{ + i2c_write(0, 0x94, reg, 1, &data); +} + +void cscodec_power(bool state) +{ + (void)state; //TODO: Figure out which LDO this is +} + +void cscodec_reset(bool state) +{ + if (state) PDAT(3) &= ~8; + else PDAT(3) |= 8; +} + +void cscodec_clock(bool state) +{ + if (state) CLKCON0C &= ~0xffff; + else CLKCON0C |= 0x8000; +} diff --git a/firmware/target/arm/s5l8702/ipod6g/lcd-asm-ipod6g.S b/firmware/target/arm/s5l8702/ipod6g/lcd-asm-ipod6g.S new file mode 100644 index 0000000000..2b170f329b --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/lcd-asm-ipod6g.S @@ -0,0 +1,295 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: lcd-as-video.S 26756 2010-06-11 04:41:36Z funman $ + * + * Copyright (C) 2010 by Andree Buschmann + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * #define FORCE_FIFO_WAIT + * + * This is not needed in YUV blitting when the LCD IF is fast enough. In this + * case YUV-to-RGB conversion per pixel needs longer than the transfer of a + * pixel via the LCD IF. For iPod nano 2G this is true if the LCD IF is + * configured to use LCD_PHTIME = 0x00 (see lcd-nano2g.c). + ****************************************************************************/ + +#include "config.h" + + .section .icode, "ax", %progbits + +/**************************************************************************** + * void lcd_write_line(const fb_data *addr, + * int pixelcount, + * const unsigned int lcd_base_addr); + * + * Writes pixelcount pixels from src-pointer (lcd_framebuffer) to LCD dataport. + */ + .align 2 + .global lcd_write_line + .type lcd_write_line, %function + /* r0 = addr, must be aligned */ + /* r1 = pixel count, must be even */ +lcd_write_line: /* r2 = LCD_BASE */ + stmfd sp!, {r4-r6, lr} /* save non-scratch registers */ + add r12, r2, #0x40 /* LCD_WDATA = LCD data port */ + +.loop: + ldmia r0!, {r3, r5} /* read 2 pixel (=8 byte) */ + + /* wait for FIFO half full */ +.fifo_wait: + ldr lr, [r2, #0x1C] /* while (LCD_STATUS & 0x08); */ + tst lr, #0x8 + bgt .fifo_wait + + mov r4, r3, asr #16 /* r3 = 1st pixel, r4 = 2nd pixel */ + mov r6, r5, asr #16 /* r5 = 3rd pixel, r6 = 4th pixel */ + stmia r12, {r3-r6} /* write pixels (lowest 16 bit used) */ + + subs r1, r1, #4 + bgt .loop + + ldmpc regs=r4-r6 + +/**************************************************************************** + * extern void lcd_write_yuv420_lines(unsigned char const * const src[3], + * const unsigned LCD_BASE, + * int width, + * int stride); + * + * Conversion from Motion JPEG and MPEG Y'PbPr to RGB is: + * |R| |1.164 0.000 1.596| |Y' - 16| + * |G| = |1.164 -0.391 -0.813| |Pb - 128| + * |B| |1.164 2.018 0.000| |Pr - 128| + * + * Scaled, normalized, rounded and tweaked to yield RGB 565: + * |R| |74 0 101| |Y' - 16| >> 9 + * |G| = |74 -24 -51| |Cb - 128| >> 8 + * |B| |74 128 0| |Cr - 128| >> 9 + * + * Converts two lines from YUV to RGB565 and writes to LCD at once. First loop + * loads Cb/Cr, calculates the chroma offset and saves them to buffer. Within + * the second loop these chroma offset are reloaded from buffer. Within each + * loop two pixels are calculated and written to LCD. + */ + .align 2 + .global lcd_write_yuv420_lines + .type lcd_write_yuv420_lines, %function +lcd_write_yuv420_lines: + /* r0 = src = yuv_src */ + /* r1 = dst = LCD_BASE */ + /* r2 = width */ + /* r3 = stride */ + stmfd sp!, { r4-r10, lr } /* save non-scratch */ + ldmia r0, { r9, r10, r12 } /* r9 = yuv_src[0] = Y'_p */ + /* r10 = yuv_src[1] = Cb_p */ + /* r12 = yuv_src[2] = Cr_p */ + add r3, r9, r3 /* r3 = &ysrc[stride] */ + add r4, r2, r2, asr #1 /* chroma buffer lenght = width/2 *3 */ + mov r4, r4, asl #2 /* use words for str/ldm possibility */ + add r4, r4, #19 /* plus room for 4 additional words, */ + bic r4, r4, #3 /* rounded up to multiples of 4 byte */ + sub sp, sp, r4 /* and allocate on stack */ + stmia sp, {r1-r4} /* LCD_BASE, width, &ysrc[stride], stack_alloc */ + + mov r7, r2 /* r7 = loop count */ + add r8, sp, #16 /* chroma buffer */ + add lr, r1, #0x40 /* LCD data port = LCD_BASE + 0x40 */ + + /* 1st loop start */ +10: /* loop start */ + + ldrb r0, [r10], #1 /* r0 = *usrc++ = *Cb_p++ */ + ldrb r1, [r12], #1 /* r1 = *vsrc++ = *Cr_p++ */ + + sub r0, r0, #128 /* r0 = Cb-128 */ + sub r1, r1, #128 /* r1 = Cr-128 */ + + add r2, r1, r1, asl #1 /* r2 = Cr*51 + Cb*24 */ + add r2, r2, r2, asl #4 + add r2, r2, r0, asl #3 + add r2, r2, r0, asl #4 + + add r4, r1, r1, asl #2 /* r1 = Cr*101 */ + add r4, r4, r1, asl #5 + add r1, r4, r1, asl #6 + + add r1, r1, #256 /* r1 = rv = (r1 + 256) >> 9 */ + mov r1, r1, asr #9 + rsb r2, r2, #128 /* r2 = guv = (-r2 + 128) >> 8 */ + mov r2, r2, asr #8 + add r0, r0, #2 /* r0 = bu = (Cb*128 + 256) >> 9 */ + mov r0, r0, asr #2 + stmia r8!, {r0-r2} /* store r0, r1 and r2 to chroma buffer */ + + /* 1st loop, first pixel */ + ldrb r5, [r9], #1 /* r5 = *ysrc++ = *Y'_p++ */ + sub r5, r5, #16 /* r5 = (Y'-16) * 74 */ + add r3, r5, r5, asl #2 + add r5, r3, r5, asl #5 + + add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */ + add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */ + add r4, r0, r5, asr #8 /* r4 = b = (Y >> 9) + bu */ + + orr r5, r6, r4 /* check if clamping is needed... */ + orr r5, r5, r3, asr #1 /* ...at all */ + cmp r5, #31 + bls 15f /* -> no clamp */ + cmp r6, #31 /* clamp r */ + mvnhi r6, r6, asr #31 + andhi r6, r6, #31 + cmp r3, #63 /* clamp g */ + mvnhi r3, r3, asr #31 + andhi r3, r3, #63 + cmp r4, #31 /* clamp b */ + mvnhi r4, r4, asr #31 + andhi r4, r4, #31 +15: /* no clamp */ + + /* calculate pixel_1 and save to r4 for later pixel packing */ + orr r4, r4, r3, lsl #5 /* pixel_1 = r<<11 | g<<5 | b */ + orr r4, r4, r6, lsl #11 /* r4 = pixel_1 */ + + /* 1st loop, second pixel */ + ldrb r5, [r9], #1 /* r5 = *ysrc++ = *Y'_p++ */ + sub r5, r5, #16 /* r5 = (Y'-16) * 74 */ + add r3, r5, r5, asl #2 + add r5, r3, r5, asl #5 + + add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */ + add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */ + add r5, r0, r5, asr #8 /* r5 = b = (Y >> 9) + bu */ + + orr r0, r6, r5 /* check if clamping is needed... */ + orr r0, r0, r3, asr #1 /* ...at all */ + cmp r0, #31 + bls 15f /* -> no clamp */ + cmp r6, #31 /* clamp r */ + mvnhi r6, r6, asr #31 + andhi r6, r6, #31 + cmp r3, #63 /* clamp g */ + mvnhi r3, r3, asr #31 + andhi r3, r3, #63 + cmp r5, #31 /* clamp b */ + mvnhi r5, r5, asr #31 + andhi r5, r5, #31 +15: /* no clamp */ + + /* calculate pixel_2 and pack with pixel_1 before writing */ + orr r5, r5, r3, lsl #5 /* pixel_2 = r<<11 | g<<5 | b */ + orr r5, r5, r6, lsl #11 /* r5 = pixel_2 */ +#ifdef FORCE_FIFO_WAIT + /* wait for FIFO half full */ +.fifo_wait1: + ldr r3, [lr, #-0x24] /* while (LCD_STATUS & 0x08); */ + tst r3, #0x8 + bgt .fifo_wait1 +#endif + stmia lr, {r4,r5} /* write pixel_1 and pixel_2 */ + + subs r7, r7, #2 /* check for loop end */ + bgt 10b /* back to beginning */ + /* 1st loop end */ + + /* Reload several registers for pointer rewinding for next loop */ + add r8, sp, #16 /* chroma buffer */ + ldmia sp, { r1, r7, r9} /* r1 = LCD_BASE */ + /* r7 = loop count */ + /* r9 = &ysrc[stride] */ + + /* 2nd loop start */ +20: /* loop start */ + /* restore r0 (bu), r1 (rv) and r2 (guv) from chroma buffer */ + ldmia r8!, {r0-r2} + + /* 2nd loop, first pixel */ + ldrb r5, [r9], #1 /* r5 = *ysrc++ = *Y'_p++ */ + sub r5, r5, #16 /* r5 = (Y'-16) * 74 */ + add r3, r5, r5, asl #2 + add r5, r3, r5, asl #5 + + add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */ + add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */ + add r4, r0, r5, asr #8 /* r4 = b = (Y >> 9) + bu */ + + orr r5, r6, r4 /* check if clamping is needed... */ + orr r5, r5, r3, asr #1 /* ...at all */ + cmp r5, #31 + bls 15f /* -> no clamp */ + cmp r6, #31 /* clamp r */ + mvnhi r6, r6, asr #31 + andhi r6, r6, #31 + cmp r3, #63 /* clamp g */ + mvnhi r3, r3, asr #31 + andhi r3, r3, #63 + cmp r4, #31 /* clamp b */ + mvnhi r4, r4, asr #31 + andhi r4, r4, #31 +15: /* no clamp */ + /* calculate pixel_1 and save to r4 for later pixel packing */ + orr r4, r4, r3, lsl #5 /* pixel_1 = r<<11 | g<<5 | b */ + orr r4, r4, r6, lsl #11 /* r4 = pixel_1 */ + + /* 2nd loop, second pixel */ + ldrb r5, [r9], #1 /* r5 = *ysrc++ = *Y'_p++ */ + sub r5, r5, #16 /* r5 = (Y'-16) * 74 */ + add r3, r5, r5, asl #2 + add r5, r3, r5, asl #5 + + add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */ + add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */ + add r5, r0, r5, asr #8 /* r5 = b = (Y >> 9) + bu */ + + orr r0, r6, r5 /* check if clamping is needed... */ + orr r0, r0, r3, asr #1 /* ...at all */ + cmp r0, #31 + bls 15f /* -> no clamp */ + cmp r6, #31 /* clamp r */ + mvnhi r6, r6, asr #31 + andhi r6, r6, #31 + cmp r3, #63 /* clamp g */ + mvnhi r3, r3, asr #31 + andhi r3, r3, #63 + cmp r5, #31 /* clamp b */ + mvnhi r5, r5, asr #31 + andhi r5, r5, #31 +15: /* no clamp */ + + /* calculate pixel_2 and pack with pixel_1 before writing */ + orr r5, r5, r3, lsl #5 /* pixel_2 = r<<11 | g<<5 | b */ + orr r5, r5, r6, lsl #11 /* r5 = pixel_2 */ +#ifdef FORCE_FIFO_WAIT + /* wait for FIFO half full */ +.fifo_wait2: + ldr r3, [lr, #-0x24] /* while (LCD_STATUS & 0x08); */ + tst r3, #0x8 + bgt .fifo_wait2 +#endif + stmia lr, {r4,r5} /* write pixel_1 and pixel_2 */ + + subs r7, r7, #2 /* check for loop end */ + bgt 20b /* back to beginning */ + /* 2nd loop end */ + + ldr r3, [sp, #12] + add sp, sp, r3 /* deallocate buffer */ + ldmpc regs=r4-r10 /* restore registers */ + + .ltorg + .size lcd_write_yuv420_lines, .-lcd_write_yuv420_lines diff --git a/firmware/target/arm/s5l8702/ipod6g/lcd-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/lcd-ipod6g.c new file mode 100644 index 0000000000..1de6a8e62f --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/lcd-ipod6g.c @@ -0,0 +1,286 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: lcd-nano2g.c 28868 2010-12-21 06:59:17Z Buschel $ + * + * Copyright (C) 2009 by Dave Chapman + * + * 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 "hwcompat.h" +#include "kernel.h" +#include "lcd.h" +#include "system.h" +#include "cpu.h" +#include "pmu-target.h" +#include "power.h" + + +#define R_HORIZ_GRAM_ADDR_SET 0x200 +#define R_VERT_GRAM_ADDR_SET 0x201 +#define R_WRITE_DATA_TO_GRAM 0x202 +#define R_HORIZ_ADDR_START_POS 0x210 +#define R_HORIZ_ADDR_END_POS 0x211 +#define R_VERT_ADDR_START_POS 0x212 +#define R_VERT_ADDR_END_POS 0x213 + + +/* LCD type 1 register defines */ + +#define R_COLUMN_ADDR_SET 0x2a +#define R_ROW_ADDR_SET 0x2b +#define R_MEMORY_WRITE 0x2c + + +/** globals **/ + +int lcd_type; /* also needed in debug-s5l8702.c */ + + +static inline void s5l_lcd_write_cmd_data(int cmd, int data) +{ + while (LCD_STATUS & 0x10); + LCD_WCMD = cmd; + + while (LCD_STATUS & 0x10); + LCD_WDATA = data; +} + +static inline void s5l_lcd_write_cmd(unsigned short cmd) +{ + while (LCD_STATUS & 0x10); + LCD_WCMD = cmd; +} + +static inline void s5l_lcd_write_data(unsigned short data) +{ + while (LCD_STATUS & 0x10); + LCD_WDATA = data; +} + +/*** hardware configuration ***/ + +int lcd_default_contrast(void) +{ + return 0x1f; +} + +void lcd_set_contrast(int val) +{ + (void)val; +} + +void lcd_set_invert_display(bool yesno) +{ + (void)yesno; +} + +void lcd_set_flip(bool yesno) +{ + (void)yesno; +} + +bool lcd_active(void) +{ + return true; +} + +void lcd_shutdown(void) +{ + pmu_write(0x2b, 0); /* Kill the backlight, instantly. */ + pmu_write(0x29, 0); + + if (lcd_type == 3) + { + s5l_lcd_write_cmd_data(0x7, 0x172); + s5l_lcd_write_cmd_data(0x30, 0x3ff); + sleep(HZ / 10); + s5l_lcd_write_cmd_data(0x7, 0x120); + s5l_lcd_write_cmd_data(0x30, 0x0); + s5l_lcd_write_cmd_data(0x100, 0x780); + s5l_lcd_write_cmd_data(0x7, 0x0); + s5l_lcd_write_cmd_data(0x101, 0x260); + s5l_lcd_write_cmd_data(0x102, 0xa9); + sleep(HZ / 30); + s5l_lcd_write_cmd_data(0x100, 0x700); + s5l_lcd_write_cmd_data(0x100, 0x704); + } + else if (lcd_type == 1) + { + s5l_lcd_write_cmd(0x28); + s5l_lcd_write_cmd(0x10); + sleep(HZ / 10); + } + else + { + s5l_lcd_write_cmd(0x28); + sleep(HZ / 20); + s5l_lcd_write_cmd(0x10); + sleep(HZ / 20); + } +} + +void lcd_sleep(void) +{ + lcd_shutdown(); +} + +/* LCD init */ +void lcd_init_device(void) +{ + /* Detect lcd type */ + lcd_type = (PDAT6 & 0x30) >> 4; +} + +/*** Update functions ***/ + +static inline void lcd_write_pixel(fb_data pixel) +{ + LCD_WDATA = pixel; +} + +/* Update the display. + This must be called after all other LCD functions that change the display. */ +void lcd_update(void) ICODE_ATTR; +void lcd_update(void) +{ + lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); +} + +/* Line write helper function. */ +extern void lcd_write_line(const fb_data *addr, + int pixelcount, + const unsigned int lcd_base_addr); + +/* Update a fraction of the display. */ +void lcd_update_rect(int, int, int, int) ICODE_ATTR; +void lcd_update_rect(int x, int y, int width, int height) +{ + int y0, x0, y1, x1; + fb_data* p; + + /* Both x and width need to be preprocessed due to asm optimizations */ + x = x & ~1; /* ensure x is even */ + width = (width + 3) & ~3; /* ensure width is a multiple of 4 */ + + x0 = x; /* start horiz */ + y0 = y; /* start vert */ + x1 = (x + width) - 1; /* max horiz */ + y1 = (y + height) - 1; /* max vert */ + + if (lcd_type & 2) { + s5l_lcd_write_cmd_data(R_HORIZ_ADDR_START_POS, x0); + s5l_lcd_write_cmd_data(R_HORIZ_ADDR_END_POS, x1); + s5l_lcd_write_cmd_data(R_VERT_ADDR_START_POS, y0); + s5l_lcd_write_cmd_data(R_VERT_ADDR_END_POS, y1); + + s5l_lcd_write_cmd_data(R_HORIZ_GRAM_ADDR_SET, (x1 << 8) | x0); + s5l_lcd_write_cmd_data(R_VERT_GRAM_ADDR_SET, (y1 << 8) | y0); + + s5l_lcd_write_cmd(R_WRITE_DATA_TO_GRAM); + } else { + s5l_lcd_write_cmd(R_COLUMN_ADDR_SET); + s5l_lcd_write_data(x0 >> 8); + s5l_lcd_write_data(x0 & 0xff); + s5l_lcd_write_data(x1 >> 8); + s5l_lcd_write_data(x1 & 0xff); + + s5l_lcd_write_cmd(R_ROW_ADDR_SET); + s5l_lcd_write_data(y0 >> 8); + s5l_lcd_write_data(y0 & 0xff); + s5l_lcd_write_data(y1 >> 8); + s5l_lcd_write_data(y1 & 0xff); + + s5l_lcd_write_cmd(R_MEMORY_WRITE); + } + for (y = y0; y <= y1; y++) + for (x = x0; x <= x1; x++) + s5l_lcd_write_data(lcd_framebuffer[y][x]); + return; + + /* Copy display bitmap to hardware */ + p = &lcd_framebuffer[y0][x0]; + if (LCD_WIDTH == width) { + /* Write all lines at once */ + lcd_write_line(p, height*LCD_WIDTH, LCD_BASE); + } else { + y1 = height; + do { + /* Write a single line */ + lcd_write_line(p, width, LCD_BASE); + p += LCD_WIDTH; + } while (--y1 > 0 ); + } +} + +/* Line write helper function for lcd_yuv_blit. Writes two lines of yuv420. */ +extern void lcd_write_yuv420_lines(unsigned char const * const src[3], + const unsigned int lcd_baseadress, + int width, + int stride); + +/* Blit a YUV bitmap directly to the LCD */ +void lcd_blit_yuv(unsigned char * const src[3], + int src_x, int src_y, int stride, + int x, int y, int width, int height) +{ + unsigned int z, y0, x0, y1, x1;; + unsigned char const * yuv_src[3]; + + width = (width + 1) & ~1; /* ensure width is even */ + + x0 = x; /* start horiz */ + y0 = y; /* start vert */ + x1 = (x + width) - 1; /* max horiz */ + y1 = (y + height) - 1; /* max vert */ + + if (lcd_type & 2) { + s5l_lcd_write_cmd_data(R_HORIZ_ADDR_START_POS, x0); + s5l_lcd_write_cmd_data(R_HORIZ_ADDR_END_POS, x1); + s5l_lcd_write_cmd_data(R_VERT_ADDR_START_POS, y0); + s5l_lcd_write_cmd_data(R_VERT_ADDR_END_POS, y1); + + s5l_lcd_write_cmd_data(R_HORIZ_GRAM_ADDR_SET, (x1 << 8) | x0); + s5l_lcd_write_cmd_data(R_VERT_GRAM_ADDR_SET, (y1 << 8) | y0); + + s5l_lcd_write_cmd(0); + s5l_lcd_write_cmd(R_WRITE_DATA_TO_GRAM); + } else { + s5l_lcd_write_cmd(R_COLUMN_ADDR_SET); + s5l_lcd_write_data(x0); /* Start column */ + s5l_lcd_write_data(x1); /* End column */ + + s5l_lcd_write_cmd(R_ROW_ADDR_SET); + s5l_lcd_write_data(y0); /* Start row */ + s5l_lcd_write_data(y1); /* End row */ + + s5l_lcd_write_cmd(R_MEMORY_WRITE); + } + + z = stride * src_y; + yuv_src[0] = src[0] + z + src_x; + yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1); + yuv_src[2] = src[2] + (yuv_src[1] - src[1]); + + height >>= 1; + + do { + lcd_write_yuv420_lines(yuv_src, LCD_BASE, width, stride); + yuv_src[0] += stride << 1; + yuv_src[1] += stride >> 1; /* Skip down one chroma line */ + yuv_src[2] += stride >> 1; + } while (--height > 0); +} diff --git a/firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c new file mode 100644 index 0000000000..73d8f98083 --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c @@ -0,0 +1,143 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: pmu-nano2g.c 27752 2010-08-08 10:49:32Z bertrik $ + * + * 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-s5l8702.h" +#include "pmu-target.h" + +static struct mutex pmu_adc_mutex; + +int pmu_read_multiple(int address, int count, unsigned char* buffer) +{ + return i2c_read(0, 0xe6, address, count, buffer); +} + +int pmu_write_multiple(int address, int count, unsigned char* buffer) +{ + return i2c_write(0, 0xe6, address, count, buffer); +} + +unsigned char pmu_read(int address) +{ + unsigned char tmp; + + pmu_read_multiple(address, 1, &tmp); + + return tmp; +} + +int pmu_write(int address, unsigned char val) +{ + return pmu_write_multiple(address, 1, &val); +} + +void pmu_init(void) +{ + mutex_init(&pmu_adc_mutex); +} + +int pmu_read_adc(unsigned int adc) +{ + int data = 0; + 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) +{ + return pmu_read_adc(0) * 6; +} + +/* milliamps */ +int pmu_read_battery_current(void) +{ +// return pmu_read_adc(2); + return 0; +} + +void pmu_ldo_on_in_standby(unsigned int ldo, int onoff) +{ + if (ldo < 4) + { + unsigned char newval = pmu_read(0x3B) & ~(1 << (2 * ldo)); + if (onoff) newval |= 1 << (2 * ldo); + pmu_write(0x3B, newval); + } + else if (ldo < 8) + { + 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_hdd_power(bool on) +{ + pmu_write(0x1b, on ? 1 : 0); +} + +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/s5l8702/ipod6g/pmu-target.h b/firmware/target/arm/s5l8702/ipod6g/pmu-target.h new file mode 100644 index 0000000000..a8c7851d97 --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/pmu-target.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: pmu-target.h 24721 2010-02-17 15:54:48Z theseven $ + * + * 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_TARGET_H__ +#define __PMU_TARGET_H__ + +#include +#include "config.h" + +unsigned char pmu_read(int address); +int pmu_write(int address, unsigned char val); +int pmu_read_multiple(int address, int count, unsigned char* buffer); +int 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_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); +void pmu_hdd_power(bool on); + +#endif diff --git a/firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c new file mode 100644 index 0000000000..973e26968f --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c @@ -0,0 +1,75 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: power-nano2g.c 28190 2010-10-01 18:09:10Z Buschel $ + * + * Copyright © 2009 Bertrik Sikken + * + * 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 +#include "config.h" +#include "inttypes.h" +#include "s5l8702.h" +#include "power.h" +#include "panic.h" +#include "pmu-target.h" +#include "usb_core.h" /* for usb_charging_maxcurrent_change */ + +static int idepowered; + +void power_off(void) +{ + pmu_set_wake_condition(0x42); /* USB inserted or EXTON1 */ + pmu_enter_standby(); + + while(1); +} + +void power_init(void) +{ + idepowered = false; +} + +void ide_power_enable(bool on) +{ + idepowered = on; + pmu_hdd_power(on); +} + +bool ide_powered() +{ + return idepowered; +} + +#if CONFIG_CHARGING + +#ifdef HAVE_USB_CHARGING_ENABLE +void usb_charging_maxcurrent_change(int maxcurrent) +{ + bool on = (maxcurrent >= 500); + GPIOCMD = 0xb060e | (on ? 1 : 0); +} +#endif + +unsigned int power_input_status(void) +{ + return (PDAT(12) & 8) ? POWER_INPUT_NONE : POWER_INPUT_MAIN_CHARGER; +} + +bool charging_state(void) +{ + return false; //TODO: Figure out +} +#endif /* CONFIG_CHARGING */ diff --git a/firmware/target/arm/s5l8702/ipod6g/powermgmt-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/powermgmt-ipod6g.c new file mode 100644 index 0000000000..3bd3791eeb --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/powermgmt-ipod6g.c @@ -0,0 +1,88 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: powermgmt-nano2g.c 28159 2010-09-24 22:42:06Z Buschel $ + * + * 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 "powermgmt.h" +#include "pmu-target.h" +#include "power.h" +#include "audiohw.h" + +const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = +{ + 3600 +}; + +const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = +{ + 3350 +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ +const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = +{ + { 3550, 3783, 3830, 3882, 3911, 3949, 3996, 4067, 4148, 4228, 4310 } +}; + +#if CONFIG_CHARGING +/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ +const unsigned short percent_to_volt_charge[11] = +{ + 3550, 3783, 3830, 3882, 3911, 3949, 3996, 4067, 4148, 4228, 4310 +}; +#endif /* CONFIG_CHARGING */ + +/* 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) +{ + int compensation = (10 * (pmu_read_battery_current() - 7)) / 12; + if (charging_state()) return pmu_read_battery_voltage() - compensation; + return pmu_read_battery_voltage() + compensation; +} + + +#ifdef HAVE_ACCESSORY_SUPPLY +void accessory_supply_set(bool enable) +{ + if (enable) + { + /* Accessory voltage supply on */ +//TODO: pmu_ldo_power_on(6); + } + else + { + /* Accessory voltage supply off */ +//TODO: pmu_ldo_power_off(6); + } +} +#endif + +#ifdef HAVE_LINEOUT_POWEROFF +void lineout_set(bool enable) +{ + /* Call audio hardware driver implementation */ + audiohw_enable_lineout(enable); +} +#endif diff --git a/firmware/target/arm/s5l8702/ipod6g/rtc-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/rtc-ipod6g.c new file mode 100644 index 0000000000..76ef8ecb00 --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/rtc-ipod6g.c @@ -0,0 +1,72 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: rtc-nano2g.c 23114 2009-10-11 18:20:56Z theseven $ + * + * 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_rtc(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; + 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_rtc(buf); + + return 0; +} + -- cgit v1.2.3