From d462a64a918117991e11dade2d7fa3a28196e07a Mon Sep 17 00:00:00 2001 From: Dave Chapman Date: Sat, 6 Sep 2008 17:50:59 +0000 Subject: Initial commit of iaudio 7 port by Vitja Makarov (FS#9245). Port is at quite an advanced stage, but is troubled by the lack of a reliable NAND driver (similar to the Cowon D2 port) and is not yet suitable for non-developers. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18435 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/ata-nand-telechips.c | 2 +- firmware/target/arm/pcm-telechips.c | 434 +++++++++++++++++++++ firmware/target/arm/tcc77x/adc-tcc77x.c | 3 + firmware/target/arm/tcc77x/app.lds | 123 ++---- firmware/target/arm/tcc77x/boot.lds | 5 + firmware/target/arm/tcc77x/crt0.S | 5 +- firmware/target/arm/tcc77x/debug-tcc77x.c | 5 +- firmware/target/arm/tcc77x/iaudio7/adc-target.h | 28 ++ firmware/target/arm/tcc77x/iaudio7/ata2501.c | 124 ++++++ firmware/target/arm/tcc77x/iaudio7/ata2501.h | 27 ++ firmware/target/arm/tcc77x/iaudio7/audio-iaudio7.c | 99 +++++ .../target/arm/tcc77x/iaudio7/backlight-target.h | 46 +++ .../target/arm/tcc77x/iaudio7/button-iaudio7.c | 81 ++++ firmware/target/arm/tcc77x/iaudio7/button-target.h | 57 +++ firmware/target/arm/tcc77x/iaudio7/lcd-iaudio7.c | 252 ++++++++++++ firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c | 146 +++++++ firmware/target/arm/tcc77x/pcm-tcc77x.c | 77 ---- firmware/target/arm/tcc77x/system-tcc77x.c | 11 +- firmware/target/arm/tcc77x/usb-tcc77x.c | 8 +- firmware/target/arm/tcc780x/pcm-tcc780x.c | 314 --------------- firmware/target/arm/wmcodec-telechips.c | 5 + 21 files changed, 1375 insertions(+), 477 deletions(-) create mode 100644 firmware/target/arm/pcm-telechips.c create mode 100644 firmware/target/arm/tcc77x/iaudio7/adc-target.h create mode 100644 firmware/target/arm/tcc77x/iaudio7/ata2501.c create mode 100644 firmware/target/arm/tcc77x/iaudio7/ata2501.h create mode 100644 firmware/target/arm/tcc77x/iaudio7/audio-iaudio7.c create mode 100644 firmware/target/arm/tcc77x/iaudio7/backlight-target.h create mode 100644 firmware/target/arm/tcc77x/iaudio7/button-iaudio7.c create mode 100644 firmware/target/arm/tcc77x/iaudio7/button-target.h create mode 100644 firmware/target/arm/tcc77x/iaudio7/lcd-iaudio7.c create mode 100644 firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c delete mode 100644 firmware/target/arm/tcc77x/pcm-tcc77x.c delete mode 100644 firmware/target/arm/tcc780x/pcm-tcc780x.c (limited to 'firmware/target') diff --git a/firmware/target/arm/ata-nand-telechips.c b/firmware/target/arm/ata-nand-telechips.c index de688b4ff7..668c8a9d69 100644 --- a/firmware/target/arm/ata-nand-telechips.c +++ b/firmware/target/arm/ata-nand-telechips.c @@ -48,7 +48,7 @@ static struct mutex ata_mtx SHAREDBSS_ATTR; #define SECTOR_SIZE 512 -#ifdef COWON_D2 +#if defined(COWON_D2) || defined(IAUDIO_7) #define SEGMENT_ID_BIGENDIAN #define BLOCKS_PER_SEGMENT 4 #else diff --git a/firmware/target/arm/pcm-telechips.c b/firmware/target/arm/pcm-telechips.c new file mode 100644 index 0000000000..a0ad00eb22 --- /dev/null +++ b/firmware/target/arm/pcm-telechips.c @@ -0,0 +1,434 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Michael Sevakis + * Copyright (C) 2008 by 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. + * + ****************************************************************************/ +#include +#include "system.h" +#include "kernel.h" +#include "logf.h" +#include "audio.h" +#include "sound.h" +#include "pcm.h" + +/* Just for tests enable it to play simple tone */ +//#define PCM_TELECHIPS_TEST + +struct dma_data +{ +/* NOTE: The order of size and p is important if you use assembler + optimised fiq handler, so don't change it. */ + uint16_t *p; + size_t size; +#if NUM_CORES > 1 + unsigned core; +#endif + int locked; + int state; +}; + +/**************************************************************************** + ** Playback DMA transfer + **/ +struct dma_data dma_play_data SHAREDBSS_ATTR = +{ + /* Initialize to a locked, stopped state */ + .p = NULL, + .size = 0, +#if NUM_CORES > 1 + .core = 0x00, +#endif + .locked = 0, + .state = 0 +}; + +static unsigned long pcm_freq SHAREDDATA_ATTR = HW_SAMPR_DEFAULT; /* 44.1 is default */ + +void pcm_postinit(void) +{ +#if defined(IAUDIO_7) + audiohw_postinit(); /* implemented not for all codecs */ +#endif + pcm_apply_settings(); +} + +const void * pcm_play_dma_get_peak_buffer(int *count) +{ + unsigned long addr = (unsigned long)dma_play_data.p; + size_t cnt = dma_play_data.size; + *count = cnt >> 2; + return (void *)((addr + 2) & ~3); +} + +void pcm_play_dma_init(void) +{ + DAVC = 0x0; /* Digital Volume = max */ +#ifdef COWON_D2 + /* Set DAI clock divided from PLL0 (192MHz). + The best approximation of 256*44.1kHz is 11.291MHz. */ + BCLKCTR &= ~DEV_DAI; + PCLK_DAI = (1<<28) | 61682; /* DCO mode */ + BCLKCTR |= DEV_DAI; + + /* Enable DAI block in Master mode, 256fs->32fs, 16bit LSB */ + DAMR = 0x3c8e80; +#elif defined(IAUDIO_7) + BCLKCTR &= ~DEV_DAI; + PCLK_DAI = (0x800b << 16) | (PCLK_DAI & 0xffff); + BCLKCTR |= DEV_DAI; + /* Master mode, 256->64fs, 16bit LSB*/ + DAMR = 0x3cce20; +#else +#error "Target isn't supported" +#endif + /* Set DAI interrupts as FIQs */ + IRQSEL = ~(DAI_RX_IRQ_MASK | DAI_TX_IRQ_MASK); + + pcm_set_frequency(SAMPR_44); + + /* Initialize default register values. */ + audiohw_init(); + + /* Power on */ + audiohw_enable_output(true); + + /* Unmute the master channel (DAC should be at zero point now). */ + audiohw_mute(false); + + dma_play_data.size = 0; +#if NUM_CORES > 1 + dma_play_data.core = 0; /* no core in control */ +#endif +} + +void pcm_apply_settings(void) +{ + pcm_curr_sampr = pcm_freq; +} + +void pcm_set_frequency(unsigned int frequency) +{ + (void) frequency; + pcm_freq = HW_SAMPR_DEFAULT; +} + +static void play_start_pcm(void) +{ + pcm_apply_settings(); + + DAMR &= ~(1<<14); /* disable tx */ + dma_play_data.state = 1; + + if (dma_play_data.size >= 16) + { + DADO_L(0) = *dma_play_data.p++; + DADO_R(0) = *dma_play_data.p++; + DADO_L(1) = *dma_play_data.p++; + DADO_R(1) = *dma_play_data.p++; + DADO_L(2) = *dma_play_data.p++; + DADO_R(2) = *dma_play_data.p++; + DADO_L(3) = *dma_play_data.p++; + DADO_R(3) = *dma_play_data.p++; + dma_play_data.size -= 16; + } + + DAMR |= (1<<14); /* enable tx */ +} + +static void play_stop_pcm(void) +{ + DAMR &= ~(1<<14); /* disable tx */ + dma_play_data.state = 0; +} + +void pcm_play_dma_start(const void *addr, size_t size) +{ + dma_play_data.p = (void *)(((uintptr_t)addr + 2) & ~3); + dma_play_data.size = (size & ~3); + +#if NUM_CORES > 1 + /* This will become more important later - and different ! */ + dma_play_data.core = processor_id(); /* save initiating core */ +#endif + + IEN |= DAI_TX_IRQ_MASK; + + play_start_pcm(); +} + +void pcm_play_dma_stop(void) +{ + play_stop_pcm(); + dma_play_data.size = 0; +#if NUM_CORES > 1 + dma_play_data.core = 0; /* no core in control */ +#endif +} + +void pcm_play_lock(void) +{ + int status = disable_fiq_save(); + + if (++dma_play_data.locked == 1) + { + IEN &= ~DAI_TX_IRQ_MASK; + } + + restore_fiq(status); +} + +void pcm_play_unlock(void) +{ + int status = disable_fiq_save(); + + if (--dma_play_data.locked == 0 && dma_play_data.state != 0) + { + IEN |= DAI_TX_IRQ_MASK; + } + + restore_fiq(status); +} + +void pcm_play_dma_pause(bool pause) +{ + (void) pause; +} + +size_t pcm_get_bytes_waiting(void) +{ + return dma_play_data.size & ~3; +} + +#ifdef HAVE_RECORDING +/* TODO: implement */ +void pcm_rec_dma_init(void) +{ +} + +void pcm_rec_dma_close(void) +{ +} + +void pcm_rec_dma_start(void *addr, size_t size) +{ + (void) addr; + (void) size; +} + +void pcm_rec_dma_stop(void) +{ +} + +void pcm_rec_lock(void) +{ +} + +void pcm_rec_unlock(void) +{ +} + +const void * pcm_rec_dma_get_peak_buffer(int *count) +{ + *count = 0; + return NULL; +} + +void pcm_record_more(void *start, size_t size) +{ +} +#endif + +#if defined(COWON_D2) +/* TODO: hardcoded hex values differs for tcc7xx and tcc8xx */ +void fiq_handler(void) ICODE_ATTR __attribute__((naked)); +void fiq_handler(void) +{ + /* r10 contains DADO_L0 base address (set in crt0.S to minimise code in the + * FIQ handler. r11 contains address of p (also set in crt0.S). Most other + * addresses we need are generated by using offsets with these two. + * r8 and r9 contains local copies of p and size respectively. + * r0-r3 and r12 is a working register. + */ + asm volatile ( + "mov r8, #0xc000 \n" /* DAI_TX_IRQ_MASK | DAI_RX_IRQ_MASK */ + "ldr r9, =0xf3001004 \n" /* CREQ */ + "str r8, [r9] \n" /* clear DAI IRQs */ + + "ldmia r11, { r8-r9 } \n" /* r8 = p, r9 = size */ + "cmp r9, #0x10 \n" /* is size <16? */ + "blt .more_data \n" /* if so, ask pcmbuf for more data */ + + ".fill_fifo: \n" + "ldr r12, [r8], #4 \n" /* load two samples */ + "str r12, [r10, #0x0] \n" /* write top sample to DADO_L0 */ + "mov r12, r12, lsr #16 \n" /* put right sample at the bottom */ + "str r12, [r10, #0x4] \n" /* write low sample to DADO_R0*/ + "ldr r12, [r8], #4 \n" /* load two samples */ + "str r12, [r10, #0x8] \n" /* write top sample to DADO_L1 */ + "mov r12, r12, lsr #16 \n" /* put right sample at the bottom */ + "str r12, [r10, #0xc] \n" /* write low sample to DADO_R1*/ + "ldr r12, [r8], #4 \n" /* load two samples */ + "str r12, [r10, #0x10] \n" /* write top sample to DADO_L2 */ + "mov r12, r12, lsr #16 \n" /* put right sample at the bottom */ + "str r12, [r10, #0x14] \n" /* write low sample to DADO_R2*/ + "ldr r12, [r8], #4 \n" /* load two samples */ + "str r12, [r10, #0x18] \n" /* write top sample to DADO_L3 */ + "mov r12, r12, lsr #16 \n" /* put right sample at the bottom */ + "str r12, [r10, #0x1c] \n" /* write low sample to DADO_R3*/ + "sub r9, r9, #0x10 \n" /* 4 words written */ + "stmia r11, { r8-r9 } \n" /* save p and size */ + + ".exit: \n" + "subs pc, lr, #4 \n" /* FIQ specific return sequence */ + + ".more_data: \n" + "stmfd sp!, { r0-r3, lr } \n" /* stack scratch regs and lr */ + "ldr r2, =pcm_callback_for_more \n" + "ldr r2, [r2] \n" /* get callback address */ + "cmp r2, #0 \n" /* check for null pointer */ + "movne r0, r11 \n" /* r0 = &p */ + "addne r1, r11, #4 \n" /* r1 = &size */ + "blxne r2 \n" /* call pcm_callback_for_more */ + "ldmia r11, { r8-r9 } \n" /* reload p and size */ + "cmp r9, #0x10 \n" /* did we actually get more data? */ + "ldmgefd sp!, { r0-r3, lr } \n" + "bge .fill_fifo \n" /* yes: fill the fifo */ + "ldr r12, =pcm_play_dma_stop \n" + "blx r12 \n" /* no: stop playback */ + "ldr r12, =pcm_play_dma_stopped_callback \n" + "blx r12 \n" + "ldmfd sp!, { r0-r3, lr } \n" + "b .exit \n" + ".ltorg \n" + ); +} +#else /* C version for reference */ +void fiq_handler(void) ICODE_ATTR __attribute__((naked)); +void fiq_handler(void) +{ + asm volatile( "stmfd sp!, {r0-r7, ip, lr} \n" /* Store context */ + "sub sp, sp, #8 \n"); /* Reserve stack */ + + register pcm_more_callback_type get_more; + + if (dma_play_data.size < 16) + { + /* p is empty, get some more data */ + get_more = pcm_callback_for_more; + if (get_more) + { + get_more((unsigned char**)&dma_play_data.p, + &dma_play_data.size); + } + } + + if (dma_play_data.size >= 16) + { + DADO_L(0) = *dma_play_data.p++; + DADO_R(0) = *dma_play_data.p++; + DADO_L(1) = *dma_play_data.p++; + DADO_R(1) = *dma_play_data.p++; + DADO_L(2) = *dma_play_data.p++; + DADO_R(2) = *dma_play_data.p++; + DADO_L(3) = *dma_play_data.p++; + DADO_R(3) = *dma_play_data.p++; + + dma_play_data.size -= 16; + } + else + { + /* No more data, so disable the FIFO/interrupt */ + pcm_play_dma_stop(); + pcm_play_dma_stopped_callback(); + } + + /* Clear FIQ status */ + CREQ = DAI_TX_IRQ_MASK | DAI_RX_IRQ_MASK; + + asm volatile( "add sp, sp, #8 \n" /* Cleanup stack */ + "ldmfd sp!, {r0-r7, ip, lr} \n" /* Restore context */ + "subs pc, lr, #4 \n"); /* Return from FIQ */ +} +#endif + +/* TODO: required by wm8531 codec, why not to implement */ +void i2s_reset(void) +{ +/* DAMR = 0; */ +} + +#ifdef PCM_TELECHIPS_TEST +#include "lcd.h" +#include "sprintf.h" +#include "backlight-target.h" + +static int frame = 0; +static void test_callback_for_more(unsigned char **start, size_t *size) +{ + static unsigned short data[8]; + static int cntr = 0; + int i; + + for (i = 0; i < 8; i ++) { + unsigned short val; + + if (0x100 == (cntr & 0x100)) + val = 0x0fff; + else + val = 0x0000; + data[i] = val; + cntr++; + } + + *start = data; + *size = sizeof(data); + + frame++; +} + +void pcm_telechips_test(void) +{ + static char buf[100]; + unsigned char *data; + size_t size; + + _backlight_on(); + + audiohw_preinit(); + pcm_play_dma_init(); + pcm_postinit(); + + audiohw_mute(false); + audiohw_set_master_vol(0x7f, 0x7f); + + pcm_callback_for_more = test_callback_for_more; + test_callback_for_more(&data, &size); + pcm_play_dma_start(data, size); + + while (1) { + int line = 0; + lcd_clear_display(); + lcd_puts(0, line++, __func__); + snprintf(buf, sizeof(buf), "frame: %d", frame); + lcd_puts(0, line++, buf); + lcd_update(); + sleep(1); + } +} +#endif diff --git a/firmware/target/arm/tcc77x/adc-tcc77x.c b/firmware/target/arm/tcc77x/adc-tcc77x.c index 37bd15398b..f48528639e 100644 --- a/firmware/target/arm/tcc77x/adc-tcc77x.c +++ b/firmware/target/arm/tcc77x/adc-tcc77x.c @@ -104,6 +104,9 @@ unsigned short adc_read(int channel) void adc_init(void) { + /* Initialize ADC clocks */ + PCLKCFG6 = (PCLKCFG6 & 0xffff0000) | 4004; + ADCCON = (1<<4); /* Leave standby mode */ /* IRQ enable, auto power-down, single-mode */ diff --git a/firmware/target/arm/tcc77x/app.lds b/firmware/target/arm/tcc77x/app.lds index 03a427f76b..c50367cb08 100644 --- a/firmware/target/arm/tcc77x/app.lds +++ b/firmware/target/arm/tcc77x/app.lds @@ -1,21 +1,25 @@ #include "config.h" ENTRY(start) - OUTPUT_FORMAT(elf32-littlearm) OUTPUT_ARCH(arm) STARTUP(target/arm/tcc77x/crt0.o) #define PLUGINSIZE PLUGIN_BUFFER_SIZE #define CODECSIZE CODEC_SIZE + +#ifdef DEBUG +#define STUBOFFSET 0x10000 +#else +#define STUBOFFSET 0 +#endif -#include "imx31l.h" - -#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGINSIZE - CODECSIZE +#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGINSIZE - STUBOFFSET - CODECSIZE #define DRAMORIG 0x20000000 #define IRAMORIG 0x00000000 -#define IRAMSIZE IRAM_SIZE +#define IRAMSIZE 64K + /* End of the audio buffer, where the codec buffer starts */ #define ENDAUDIOADDR (DRAMORIG + DRAMSIZE) @@ -23,100 +27,58 @@ STARTUP(target/arm/tcc77x/crt0.o) /* Where the codec buffer ends, and the plugin buffer starts */ #define ENDADDR (ENDAUDIOADDR + CODECSIZE) + MEMORY { - DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE - IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE +#ifdef TCCBOOT + DRAM : ORIGIN = DRAMORIG + DRAMSIZE - 0x100000, LENGTH = 0x100000 +#else + DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE +#endif + IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE } SECTIONS { - .text : - { - loadaddress = .; - _loadaddress = .; - . = ALIGN(0x200); + .text : { + loadaddress = .; + _loadaddress = .; + . = ALIGN(0x200); *(.init.text) + *(.text) *(.text*) *(.glue_7) *(.glue_7t) - . = ALIGN(0x4); - } > DRAM - - .rodata : - { - *(.rodata) /* problems without this, dunno why */ - *(.rodata*) - *(.rodata.str1.1) - *(.rodata.str1.4) - . = ALIGN(0x4); + } > DRAM - /* Pseudo-allocate the copies of the data sections */ - _datacopy = .; - } > DRAM - - /* TRICK ALERT! For RAM execution, we put the .data section at the - same load address as the copy. Thus, we don't waste extra RAM - when we don't actually need the copy. */ - .data : AT ( _datacopy ) - { - _datastart = .; - *(.data*) - . = ALIGN(0x4); - _dataend = .; - } > DRAM - - /DISCARD/ : - { - *(.eh_frame) - } - - .vectors 0x0 : - { - _vectorsstart = .; - *(.vectors); - _vectorsend = .; - } AT> DRAM - - _vectorscopy = LOADADDR(.vectors); - - .iram : - { - _iramstart = .; + .data : { *(.icode) *(.irodata) *(.idata) + *(.data*) + *(.rodata.*) + *(.rodata) . = ALIGN(0x4); - _iramend = .; - } > DRAM - - _iramcopy = LOADADDR(.iram); - - .ibss (NOLOAD) : - { - _iedata = .; - *(.ibss) - . = ALIGN(0x4); - _iend = .; + _dataend = . ; } > DRAM .stack : { - *(.stack) - stackbegin = .; - . += 0x2000; - stackend = .; - } > DRAM - - .bss : - { - _edata = .; - *(.bss*) - *(COMMON) - . = ALIGN(0x4); - _end = .; + *(.stack) + _stackbegin = .; + stackbegin = .; + . += 0x2000; + _stackend = .; + stackend = .; } > DRAM + .bss : { + _edata = .; + *(.bss*); + *(.ibss); + *(COMMON) + _end = .; + } > DRAM .audiobuf ALIGN(4) : { _audiobuffer = .; @@ -128,7 +90,7 @@ SECTIONS audiobufend = .; _audiobufend = .; } > DRAM - + .codec ENDAUDIOADDR: { codecbuf = .; @@ -139,6 +101,5 @@ SECTIONS { _pluginbuf = .; pluginbuf = .; - } + } } - diff --git a/firmware/target/arm/tcc77x/boot.lds b/firmware/target/arm/tcc77x/boot.lds index 890c4ec785..2fd6964d57 100644 --- a/firmware/target/arm/tcc77x/boot.lds +++ b/firmware/target/arm/tcc77x/boot.lds @@ -14,7 +14,11 @@ STARTUP(target/arm/tcc77x/crt0.o) MEMORY { +#ifdef TCCBOOT DRAM : ORIGIN = DRAMORIG + DRAMSIZE - 0x100000, LENGTH = 0x100000 +#else + DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE +#endif IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE } @@ -34,6 +38,7 @@ SECTIONS *(.idata) *(.data*) *(.rodata.*) + *(.rodata) . = ALIGN(0x4); _dataend = . ; } > DRAM diff --git a/firmware/target/arm/tcc77x/crt0.S b/firmware/target/arm/tcc77x/crt0.S index e144c16fae..569930352a 100644 --- a/firmware/target/arm/tcc77x/crt0.S +++ b/firmware/target/arm/tcc77x/crt0.S @@ -82,12 +82,15 @@ start_loc: #ifdef TCCBOOT mov r0, #0x80000000 -#ifdef LOGIK_DAX +#if defined(LOGIK_DAX) ldr r0, [r0, #0x300] /* Hold button is GPIO A, pin 0x2 */ tst r0, #0x2 #elif defined(SANSA_M200) ldr r0, [r0, #0x310] /* Hold button is GPIO B, pin 0x200 */ tst r0, #0x200 +#elif defined(IAUDIO_7) + ldr r0, [r0, #0x300] /* Hold button is !GPIO A, pin 0x2 */ + tst r0, #0x2 #else #error No bootup key detection implemented for this target #endif diff --git a/firmware/target/arm/tcc77x/debug-tcc77x.c b/firmware/target/arm/tcc77x/debug-tcc77x.c index 4566c7ea73..203a6010ce 100644 --- a/firmware/target/arm/tcc77x/debug-tcc77x.c +++ b/firmware/target/arm/tcc77x/debug-tcc77x.c @@ -56,8 +56,11 @@ bool __dbg_hw_info(void) button = button_get(false); button &= ~BUTTON_REPEAT; - +#ifdef BUTTON_SELECT if (button == BUTTON_SELECT) +#else + if (button == BUTTON_STOP) +#endif done=true; snprintf(buf, sizeof(buf), "current tick: %08x Seconds running: %08d", diff --git a/firmware/target/arm/tcc77x/iaudio7/adc-target.h b/firmware/target/arm/tcc77x/iaudio7/adc-target.h new file mode 100644 index 0000000000..1916d93598 --- /dev/null +++ b/firmware/target/arm/tcc77x/iaudio7/adc-target.h @@ -0,0 +1,28 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 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. + * + ****************************************************************************/ +#ifndef _ADC_TARGET_H_ +#define _ADC_TARGET_H_ + +#define NUM_ADC_CHANNELS 8 + +#define ADC_BUTTONS 0 + +#endif /* _ADC_TARGET_H_ */ diff --git a/firmware/target/arm/tcc77x/iaudio7/ata2501.c b/firmware/target/arm/tcc77x/iaudio7/ata2501.c new file mode 100644 index 0000000000..fa165d9d0d --- /dev/null +++ b/firmware/target/arm/tcc77x/iaudio7/ata2501.c @@ -0,0 +1,124 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 Vitja Makarov + * + * 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 "button.h" + +#include "ata2501.h" + +#define STB (1<<5) +#define SDATA (1<<4) +#define RESET (1<<6) +#define SIFMD (1<<7) +#define STB_DELAY 200 + +#define udelay _udelay + +/* do we really need it? */ +static void _udelay(int cycles) +{ + cycles /= 8; + while (cycles--) { + asm("nop;nop;"); + } +} + +/* + TODO: sensitivity using GPIOS +*/ +void ata2501_init(void) +{ + GPIOD_DIR |= (RESET | STB | SIFMD | (1 << 8) | (1 << 9)); + GPIOD_DIR &= ~(SDATA); + + GPIOD &= ~RESET; + udelay(1000); + + GPIOD |= RESET; + + GPIOD &= ~STB; + +#if 1 + GPIOD &= ~((1 << 9) | (1 << 8)); + GPIOD |= ((1 << 8) | SIFMD) | (1 << 9); +#else + GPIOD |= ((1 << 9) | (1 << 8)); + GPIOD &= ~(SIFMD); +#endif +} + +unsigned short ata2501_read(void) +{ + unsigned short ret = 0; + int i; + + for (i = 0; i < 12; i++) { + GPIOD |= STB; + udelay(50); + + ret <<= 1; + if (GPIOD & SDATA) + ret |= 1; + udelay(50); + GPIOD &= ~STB; + udelay(100); + } + + return ret; +} + +#define ATA2501_TEST +#ifdef ATA2501_TEST +#include "lcd.h" +#include "sprintf.h" + +static +void bits(char *str, unsigned short val) +{ + int i; + + for (i = 0; i < 12; i++) + str[i] = (val & (1 << i)) ? '1' : '0'; + str[i] = 0; +} + +void ata2501_test(void) +{ + char buf[100]; + ata2501_init(); + + while (1) { + unsigned short data; + int i, line = 0; + + data = ata2501_read(); + lcd_clear_display(); + lcd_puts(0, line++, "ATA2501 test"); + + bits(buf, data); + lcd_puts(0, line++, buf); + + lcd_update(); + udelay(2000); + } +} +#endif diff --git a/firmware/target/arm/tcc77x/iaudio7/ata2501.h b/firmware/target/arm/tcc77x/iaudio7/ata2501.h new file mode 100644 index 0000000000..465d0b199c --- /dev/null +++ b/firmware/target/arm/tcc77x/iaudio7/ata2501.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 Vitja Makarov + * + * 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 _ATA2501_H_ +#define _ATA2501_H_ + +void ata2501_init(void); +unsigned short ata2501_read(void); + +#endif /* _ATA2501_H_ */ diff --git a/firmware/target/arm/tcc77x/iaudio7/audio-iaudio7.c b/firmware/target/arm/tcc77x/iaudio7/audio-iaudio7.c new file mode 100644 index 0000000000..4e7f58df47 --- /dev/null +++ b/firmware/target/arm/tcc77x/iaudio7/audio-iaudio7.c @@ -0,0 +1,99 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 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" + +int audio_channels = 2; +int audio_output_source = AUDIO_SRC_PLAYBACK; + +void audiohw_enable_output(bool on) +{ + (void) on; +} + +void audio_set_output_source(int source) +{ + int oldmode = set_fiq_status(FIQ_DISABLED); + + if ((unsigned)source >= AUDIO_NUM_SOURCES) + source = AUDIO_SRC_PLAYBACK; + + audio_output_source = source; + set_fiq_status(oldmode); +} + +void audio_input_mux(int source, unsigned flags) +{ + static int last_source = AUDIO_SRC_PLAYBACK; + static bool last_recording = false; + bool recording = flags & SRCF_RECORDING; + + switch (source) + { + default: /* playback - no recording */ + source = AUDIO_SRC_PLAYBACK; + case AUDIO_SRC_PLAYBACK: + audio_channels = 2; + if (source != last_source) + { + audiohw_set_monitor(false); + /* audiohw_disable_recording();*/ + } + break; + + case AUDIO_SRC_MIC: /* recording only */ + GPIOD |= 0x1; + + audio_channels = 1; + if (source != last_source) + { + /*audiohw_set_monitor(false); + audiohw_enable_recording(true); /. source mic */ + } + break; + + case AUDIO_SRC_FMRADIO: /* recording and playback */ + GPIOD &= ~0x1; + + audio_channels = 2; + + if (source == last_source && recording == last_recording) + break; + + last_recording = recording; + + if (recording) + { + /*audiohw_set_monitor(false); + audiohw_enable_recording(false);*/ + } + else + { + /*audiohw_disable_recording(); */ + audiohw_set_monitor(true); /* line 1 analog audio path */ + } + break; + } /* end switch */ + + last_source = source; +} /* audio_input_mux */ diff --git a/firmware/target/arm/tcc77x/iaudio7/backlight-target.h b/firmware/target/arm/tcc77x/iaudio7/backlight-target.h new file mode 100644 index 0000000000..597583b16f --- /dev/null +++ b/firmware/target/arm/tcc77x/iaudio7/backlight-target.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 Vitja Makarov + * + * 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 + +#include +#include "tcc77x.h" + +void power_touch_panel(bool on); + +static inline bool _backlight_init(void) +{ + GPIOD_DIR |= 0x2; + return true; +} + +static inline void _backlight_on(void) +{ + GPIOD |= 0x2; + power_touch_panel(true); +} + +static inline void _backlight_off(void) +{ + GPIOD &= ~0x2; + power_touch_panel(false); +} +#endif /* BACKLIGHT_TARGET_H */ diff --git a/firmware/target/arm/tcc77x/iaudio7/button-iaudio7.c b/firmware/target/arm/tcc77x/iaudio7/button-iaudio7.c new file mode 100644 index 0000000000..3aad4f75a4 --- /dev/null +++ b/firmware/target/arm/tcc77x/iaudio7/button-iaudio7.c @@ -0,0 +1,81 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 Vitja Makarov + * + * 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 "button.h" +#include "adc.h" + +#include "button-target.h" +#include "ata2501.h" + +void button_init_device(void) +{ + ata2501_init(); +} + +/* + touchpad: + 0: stop + 1-8: between next & prev + 9: play + 10: next + 11: prev +*/ + +int button_read_device(void) +{ + int btn = BUTTON_NONE; + int adc; + int sensor; + + if (button_hold()) + return BUTTON_NONE; + + adc = adc_read(0); + sensor = ata2501_read(); + + if (0 == (GPIOA & 4)) + btn |= BUTTON_POWER; + + /* seems they can't be hold together */ + if (adc < 0x120) + btn |= BUTTON_VOLUP; + else if (adc < 0x270) + btn |= BUTTON_VOLDOWN; + else if (adc < 0x300) + btn |= BUTTON_MENU; + + if (sensor & (1 << 0)) + btn |= BUTTON_STOP; + if (sensor & (1 << 9)) + btn |= BUTTON_PLAY; + if (sensor & ((1 << 10) | 0x1c0)) + btn |= BUTTON_RIGHT; + if (sensor & ((1 << 11) | 0xe)) + btn |= BUTTON_LEFT; + + return btn; +} + +bool button_hold(void) +{ + return !(GPIOA & 0x2); +} diff --git a/firmware/target/arm/tcc77x/iaudio7/button-target.h b/firmware/target/arm/tcc77x/iaudio7/button-target.h new file mode 100644 index 0000000000..fafaf4a303 --- /dev/null +++ b/firmware/target/arm/tcc77x/iaudio7/button-target.h @@ -0,0 +1,57 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 Vitja Makarov + * + * 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 _IAUDIO7_BUTTON_TARGET_H_ +#define _IAUDIO7_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); + +/* Main unit's buttons */ +#define BUTTON_POWER 0x00000001 +#define BUTTON_VOLUP 0x00000002 +#define BUTTON_VOLDOWN 0x00000004 +#define BUTTON_MENU 0x00000008 + +#define BUTTON_LEFT 0x00000010 +#define BUTTON_RIGHT 0x00000020 +#define BUTTON_PLAY 0x00000040 +#define BUTTON_STOP 0x00000080 + +#define BUTTON_ON BUTTON_POWER + +#define BUTTON_MAIN (BUTTON_POWER|BUTTON_VOLUP|BUTTON_VOLDOWN| \ + BUTTON_MENU|BUTTON_LEFT|BUTTON_RIGHT| \ + BUTTON_PLAY|BUTTON_STOP) + +/* No remote */ +#define BUTTON_REMOTE 0 + +/* Software power-off */ +#define POWEROFF_BUTTON BUTTON_POWER +#define POWEROFF_COUNT 10 + +#endif /* _IAUDIO7_BUTTON_TARGET_H_ */ diff --git a/firmware/target/arm/tcc77x/iaudio7/lcd-iaudio7.c b/firmware/target/arm/tcc77x/iaudio7/lcd-iaudio7.c new file mode 100644 index 0000000000..bbc20b6860 --- /dev/null +++ b/firmware/target/arm/tcc77x/iaudio7/lcd-iaudio7.c @@ -0,0 +1,252 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2004 by Linus Nielsen Feltzing + * + * 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. + * + ****************************************************************************/ + +/* + Thanks Hein-Pieter van Braam for initial work. + + Mostly based on lcd-h300.c, adapted for the iaudio 7 by Vitja Makarov + */ + +#include + +#include +#include +#include +#include + +#include "hd66789r.h" + +static bool display_on = false; /* is the display turned on? */ + +static inline void lcd_write_reg(int reg, int data) +{ + GPIOA &= ~0x400; + outw(0, 0x50010000); + outw(reg << 1, 0x50010000); + GPIOA |= 0x400; + + outw((data & 0xff00) >> 7, 0x50010008); + outw((data << 24) >> 23, 0x50010008); +} + +static void lcd_write_cmd(int reg) +{ + GPIOA &= ~0x400; + outw(0, 0x50010000); + outw(reg << 1, 0x50010000); + GPIOA |= 0x400; +} + +/* Do what OF do */ +static void lcd_delay(int x) +{ + int i; + + x *= 0xc35; + for (i = 0; i < x * 8; i++) { + } +} + + +static void _display_on(void) +{ + GPIOA_DIR |= 0x8000 | 0x400; + GPIOA |= 0x8000; + + /* power setup */ + lcd_write_reg(R_START_OSC, 0x0001); + lcd_delay(0xf); + lcd_write_reg(R_DISP_CONTROL1, 0x000); + lcd_delay(0xa); + lcd_write_reg(R_POWER_CONTROL2, 0x0002); + lcd_write_reg(R_POWER_CONTROL3, 0x000a); + lcd_write_reg(R_POWER_CONTROL4, 0xc5a); + lcd_write_reg(R_POWER_CONTROL1, 0x0004); + lcd_write_reg(R_POWER_CONTROL1, 0x0134); + lcd_write_reg(R_POWER_CONTROL2, 0x0111); + lcd_write_reg(R_POWER_CONTROL3, 0x001c); + lcd_delay(0x28); + lcd_write_reg(R_POWER_CONTROL4, 0x2c40); + lcd_write_reg(R_POWER_CONTROL1, 0x0510); + lcd_delay(0x3c); + + /* lcd init 2 */ + lcd_write_reg(R_DRV_OUTPUT_CONTROL, 0x0113); + lcd_write_reg(R_DRV_WAVEFORM_CONTROL, 0x0700); + lcd_write_reg(R_ENTRY_MODE, 0x1038); + lcd_write_reg(R_DISP_CONTROL2, 0x0508); // 0x3c8, TMM + lcd_write_reg(R_DISP_CONTROL3, 0x0000); + lcd_write_reg(R_FRAME_CYCLE_CONTROL, 0x0003); + lcd_write_reg(R_RAM_ADDR_SET, 0x0000); + lcd_write_reg(R_GAMMA_FINE_ADJ_POS1, 0x0406); + lcd_write_reg(R_GAMMA_FINE_ADJ_POS2, 0x0303); + lcd_write_reg(R_GAMMA_FINE_ADJ_POS3, 0x0000); + lcd_write_reg(R_GAMMA_GRAD_ADJ_POS, 0x0305); + lcd_write_reg(R_GAMMA_FINE_ADJ_NEG1, 0x0404); + lcd_write_reg(R_GAMMA_FINE_ADJ_NEG2, 0x0000); + lcd_write_reg(R_GAMMA_FINE_ADJ_NEG3, 0x0000); + lcd_write_reg(R_GAMMA_GRAD_ADJ_NEG, 0x0503); + lcd_write_reg(R_GAMMA_AMP_ADJ_RES_POS, 0x1d05); + lcd_write_reg(R_GAMMA_AMP_AVG_ADJ_RES_NEG, 0x1d05); + lcd_write_reg(R_VERT_SCROLL_CONTROL, 0x0000); + lcd_write_reg(R_1ST_SCR_DRV_POS, 0x9f00); + lcd_write_reg(R_2ND_SCR_DRV_POS, 0x9f00); + lcd_write_reg(R_HORIZ_RAM_ADDR_POS, 0x7f00); + lcd_write_reg(R_VERT_RAM_ADDR_POS, 0x9f00); + + /* lcd init 3 */ + lcd_write_reg(R_POWER_CONTROL1, 0x4510); + lcd_write_reg(R_DISP_CONTROL1, 0x0005); + lcd_delay(0x28); + lcd_write_reg(R_DISP_CONTROL1, 0x0025); + lcd_write_reg(R_DISP_CONTROL1, 0x0027); + lcd_delay(0x28); + lcd_write_reg(R_DISP_CONTROL1, 0x0037); + + display_on = true; +} + +void lcd_init_device(void) +{ + /* Configure external memory banks */ + CSCFG1 = 0x3d500023; + + /* may be reset */ + GPIOA |= 0x8000; + + _display_on(); +} + +void lcd_enable(bool on) +{ + if (display_on == on) + return; + + if (on) { + _display_on(); +// lcd_call_enable_hook(); + } else { + /** Off sequence according to datasheet, p. 130 **/ + lcd_write_reg(R_FRAME_CYCLE_CONTROL, 0x0002); /* EQ=0, 18 clks/line */ + lcd_write_reg(R_DISP_CONTROL1, 0x0036); /* GON=1, DTE=1, REV=1, D1-0=10 */ + sleep(2); + + lcd_write_reg(R_DISP_CONTROL1, 0x0026); /* GON=1, DTE=0, REV=1, D1-0=10 */ + sleep(2); + + lcd_write_reg(R_DISP_CONTROL1, 0x0000); /* GON=0, DTE=0, D1-0=00 */ + + lcd_write_reg(R_POWER_CONTROL1, 0x0000); /* SAP2-0=000, AP2-0=000 */ + lcd_write_reg(R_POWER_CONTROL3, 0x0000); /* PON=0 */ + lcd_write_reg(R_POWER_CONTROL4, 0x0000); /* VCOMG=0 */ + + /* datasheet p. 131 */ + lcd_write_reg(R_POWER_CONTROL1, 0x0001); /* STB=1: standby mode */ + + display_on = false; + } +} + +bool lcd_enabled(void) +{ + return display_on; +} + + +#define RGB(r,g,b) ((((r)&0x3f) << 12)|(((g)&0x3f) << 6)|(((b)&0x3f))) + + +void lcd_update(void) +{ + lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); +} + +/* todo: need tests */ +void lcd_update_rect(int sx, int sy, int width, int height) +{ + int x, y; + + if (!display_on) + return; + + if (width <= 0 || height <= 0) /* nothing to do */ + return; + + width += sx; + height += sy; + + if (width > LCD_WIDTH) + width = LCD_WIDTH; + if (height > LCD_HEIGHT) + height = LCD_HEIGHT; + + lcd_write_reg(R_ENTRY_MODE, 0x1028); + /* set update window */ + lcd_write_reg(R_HORIZ_RAM_ADDR_POS, (LCD_HEIGHT - 1) << 8); + lcd_write_reg(R_VERT_RAM_ADDR_POS, ((width - 1) << 8) | sx); + lcd_write_reg(R_RAM_ADDR_SET, (sx << 8) | (LCD_HEIGHT - sy - 1)); + lcd_write_cmd(R_WRITE_DATA_2_GRAM); + + for (y = sy; y < height; y++) { + for (x = sx; x < width; x++) { + fb_data c; + unsigned long color; + + c = lcd_framebuffer[y][x]; + color = + ((c & 0x1f) << 1) | ((c & 0x7e0) << 1) | ((c & 0xf800) << + 2); + + /* TODO: our color is 18-bit */ + outw((color >> 9) & 0x1ff, 0x50010008); + outw((color) & 0x1ff, 0x50010008); + } + } +} + +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; +} + +/* TODO: implement me */ +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) +{ + if (!display_on) + return; + + width &= ~1; /* stay on the safe side */ + height &= ~1; + + panicf("%s", __func__); +} diff --git a/firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c b/firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c new file mode 100644 index 0000000000..ef012cbbdf --- /dev/null +++ b/firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c @@ -0,0 +1,146 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 Vitja Makarov + * + * 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 "cpu.h" +#include "kernel.h" +#include "system.h" +#include "power.h" + +#include "pcf50606.h" + +void power_init(void) +{ + pcf50606_write(PCF5060X_DCDC1, 0x90); + pcf50606_write(PCF5060X_DCDC2, 0x48); + pcf50606_write(PCF5060X_DCDC3, 0xfc); + pcf50606_write(PCF5060X_DCDC4, 0xb1); + + pcf50606_write(PCF5060X_IOREGC, 0xe9); + /* 3.3V, touch-panel */ + pcf50606_write(PCF5060X_D1REGC1, 0xf8); + pcf50606_write(PCF5060X_D2REGC1, 0xf2); + pcf50606_write(PCF5060X_D3REGC1, 0xf5); + + pcf50606_write(PCF5060X_LPREGC1, 0x00); + pcf50606_write(PCF5060X_LPREGC2, 0x02); + + pcf50606_write(PCF5060X_DCUDC1, 0xe6); + pcf50606_write(PCF5060X_DCUDC2, 0x30); + + pcf50606_write(PCF5060X_DCDEC1, 0xe7); + pcf50606_write(PCF5060X_DCDEC2, 0x02); + + pcf50606_write(PCF5060X_INT1M, 0x5b); + pcf50606_write(PCF5060X_INT1M, 0xaf); + pcf50606_write(PCF5060X_INT1M, 0x8f); + + pcf50606_write(PCF5060X_OOCC1, 0x40); + pcf50606_write(PCF5060X_OOCC2, 0x05); + + pcf50606_write(PCF5060X_MBCC3, 0x3a); + pcf50606_write(PCF5060X_GPOC1, 0x00); + pcf50606_write(PCF5060X_BBCC, 0xf8); +} + +/* Control leds on ata2501 board */ +void power_touch_panel(bool on) +{ + if (on) + pcf50606_write(PCF5060X_D1REGC1, 0xf8); + else + pcf50606_write(PCF5060X_D1REGC1, 0x00); +} + +void ide_power_enable(bool on) +{ +} + +bool ide_powered(void) +{ + return true; +} + +void power_off(void) +{ + /* Forcibly cut power to SoC & peripherals by putting the PCF to sleep */ + pcf50606_write(PCF5060X_OOCC1, GOSTDBY | CHGWAK | EXTONWAK); +} + +#if CONFIG_TUNER +#include "tuner.h" + +/** Tuner **/ +static bool powered = false; + +#define TUNNER_CLK (1 << 5) +#define TUNNER_DATA (1 << 6) +#define TUNNER_NR_W (1 << 7) + +bool tuner_power(bool status) +{ + bool old_status; + lv24020lp_lock(); + + old_status = powered; + + if (status != old_status) + { + if (status) + { + /* When power up, host should initialize the 3-wire bus + in host read mode: */ + + /* 1. Set direction of the DATA-line to input-mode. */ + GPIOA_DIR &= ~TUNNER_DATA; + + /* 2. Drive NR_W low */ + GPIOA &= ~TUNNER_NR_W; + GPIOA_DIR |= TUNNER_NR_W; + + /* 3. Drive CLOCK high */ + GPIOA |= TUNNER_CLK; + GPIOA_DIR |= TUNNER_CLK; + + lv24020lp_power(true); + } + else + { + lv24020lp_power(false); + + /* set all as inputs */ + GPIOC_DIR &= ~(TUNNER_CLK | TUNNER_DATA | TUNNER_NR_W); + } + + powered = status; + } + + lv24020lp_unlock(); + return old_status; +} + +#endif /* CONFIG_TUNER */ + +bool charger_inserted(void) +{ + return (GPIOA & 0x1) ? true : false; +} diff --git a/firmware/target/arm/tcc77x/pcm-tcc77x.c b/firmware/target/arm/tcc77x/pcm-tcc77x.c deleted file mode 100644 index 184a264858..0000000000 --- a/firmware/target/arm/tcc77x/pcm-tcc77x.c +++ /dev/null @@ -1,77 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2008 by [whoever fills in these functions] - * - * 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 "kernel.h" -#include "logf.h" -#include "audio.h" -#include "sound.h" -#include "file.h" - -void pcm_postinit(void) -{ -} - -const void * pcm_play_dma_get_peak_buffer(int *count) -{ - (void)count; - return 0; -} - -void pcm_play_dma_init(void) -{ -} - -void pcm_apply_settings(void) -{ -} - -void pcm_set_frequency(unsigned int frequency) -{ - (void)frequency; -} - -void pcm_play_dma_start(const void *addr, size_t size) -{ - (void)addr; - (void)size; -} - -void pcm_play_dma_stop(void) -{ -} - -void pcm_play_lock(void) -{ -} - -void pcm_play_unlock(void) -{ -} - -void pcm_play_dma_pause(bool pause) -{ - (void)pause; -} - -size_t pcm_get_bytes_waiting(void) -{ - return 0; -} diff --git a/firmware/target/arm/tcc77x/system-tcc77x.c b/firmware/target/arm/tcc77x/system-tcc77x.c index c50a8a6651..2c8959fded 100644 --- a/firmware/target/arm/tcc77x/system-tcc77x.c +++ b/firmware/target/arm/tcc77x/system-tcc77x.c @@ -26,6 +26,7 @@ /* Externally defined interrupt handlers */ extern void TIMER(void); extern void ADC(void); +extern void USBD_IRQ(void); void irq(void) { @@ -36,14 +37,22 @@ void irq(void) TIMER(); else if (irq & ADC_IRQ_MASK) ADC(); +#ifdef HAVE_USBSTACK + else if (irq & USBD_IRQ_MASK) + USBD_IRQ(); +#endif else panicf("Unhandled IRQ 0x%08X", irq); } +void fiq_handler(void) __attribute__((interrupt ("FIQ"), naked)); + +#ifdef BOOTLOADER void fiq_handler(void) { /* TODO */ } +#endif void system_reboot(void) { @@ -94,7 +103,7 @@ static void gpio_init(void) GPIOC = 0; GPIOD = 0x180; GPIOE = 0; - GPIOA_DIR = 0x84b0 + GPIOA_DIR = 0x84b0; GPIOB_DIR = 0x80800; GPIOC_DIR = 0x2000000; GPIOD_DIR = 0x3e3; diff --git a/firmware/target/arm/tcc77x/usb-tcc77x.c b/firmware/target/arm/tcc77x/usb-tcc77x.c index 85c8bed3ef..9cfcb503e0 100644 --- a/firmware/target/arm/tcc77x/usb-tcc77x.c +++ b/firmware/target/arm/tcc77x/usb-tcc77x.c @@ -7,7 +7,7 @@ * \/ \/ \/ \/ \/ * $Id$ * - * Copyright (C) 2008 by [whoever fills in these functions] + * Copyright (C) 2008 by Vitja Makarov * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -21,9 +21,15 @@ #include "config.h" #include "usb.h" +#include "system.h" +#include "usb-tcc7xx.h" void usb_init_device(void) { + /* simply switch USB off for now */ + BCLKCTR |= DEV_USBD; + TCC7xx_USB_PHY_CFG = 0x3e4c; + BCLKCTR &= ~DEV_USBD; } void usb_enable(bool on) diff --git a/firmware/target/arm/tcc780x/pcm-tcc780x.c b/firmware/target/arm/tcc780x/pcm-tcc780x.c deleted file mode 100644 index 375274438a..0000000000 --- a/firmware/target/arm/tcc780x/pcm-tcc780x.c +++ /dev/null @@ -1,314 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Michael Sevakis - * Copyright (C) 2008 by 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. - * - ****************************************************************************/ -#include -#include "system.h" -#include "kernel.h" -#include "logf.h" -#include "audio.h" -#include "sound.h" -#include "pcm.h" - -struct dma_data -{ -/* NOTE: The order of size and p is important if you use assembler - optimised fiq handler, so don't change it. */ - uint16_t *p; - size_t size; -#if NUM_CORES > 1 - unsigned core; -#endif - int locked; - int state; -}; - -/**************************************************************************** - ** Playback DMA transfer - **/ -struct dma_data dma_play_data SHAREDBSS_ATTR = -{ - /* Initialize to a locked, stopped state */ - .p = NULL, - .size = 0, -#if NUM_CORES > 1 - .core = 0x00, -#endif - .locked = 0, - .state = 0 -}; - -static unsigned long pcm_freq SHAREDDATA_ATTR = HW_SAMPR_DEFAULT; /* 44.1 is default */ - -void pcm_postinit(void) -{ - /*audiohw_postinit();*/ - pcm_apply_settings(); -} - -const void * pcm_play_dma_get_peak_buffer(int *count) -{ - unsigned long addr = (unsigned long)dma_play_data.p; - size_t cnt = dma_play_data.size; - *count = cnt >> 2; - return (void *)((addr + 2) & ~3); -} - -void pcm_play_dma_init(void) -{ - /* Set DAI clock divided from PLL0 (192MHz). - The best approximation of 256*44.1kHz is 11.291MHz. */ - BCLKCTR &= ~DEV_DAI; - PCLK_DAI = (1<<28) | 61682; /* DCO mode */ - BCLKCTR |= DEV_DAI; - - /* Enable DAI block in Master mode, 256fs->32fs, 16bit LSB */ - DAMR = 0x3c8e80; - DAVC = 0x0; /* Digital Volume = max */ - - /* Set DAI interrupts as FIQs */ - IRQSEL = ~(DAI_RX_IRQ_MASK | DAI_TX_IRQ_MASK); - - pcm_set_frequency(SAMPR_44); - - /* Initialize default register values. */ - audiohw_init(); - - /* Power on */ - audiohw_enable_output(true); - - /* Unmute the master channel (DAC should be at zero point now). */ - audiohw_mute(false); - - dma_play_data.size = 0; -#if NUM_CORES > 1 - dma_play_data.core = 0; /* no core in control */ -#endif -} - -void pcm_apply_settings(void) -{ - pcm_curr_sampr = pcm_freq; -} - -void pcm_set_frequency(unsigned int frequency) -{ - (void) frequency; - pcm_freq = HW_SAMPR_DEFAULT; -} - -static void play_start_pcm(void) -{ - pcm_apply_settings(); - - DAMR &= ~(1<<14); /* disable tx */ - dma_play_data.state = 1; - - if (dma_play_data.size >= 16) - { - DADO_L(0) = *dma_play_data.p++; - DADO_R(0) = *dma_play_data.p++; - DADO_L(1) = *dma_play_data.p++; - DADO_R(1) = *dma_play_data.p++; - DADO_L(2) = *dma_play_data.p++; - DADO_R(2) = *dma_play_data.p++; - DADO_L(3) = *dma_play_data.p++; - DADO_R(3) = *dma_play_data.p++; - dma_play_data.size -= 16; - } - - DAMR |= (1<<14); /* enable tx */ -} - -static void play_stop_pcm(void) -{ - DAMR &= ~(1<<14); /* disable tx */ - dma_play_data.state = 0; -} - -void pcm_play_dma_start(const void *addr, size_t size) -{ - dma_play_data.p = (void *)(((uintptr_t)addr + 2) & ~3); - dma_play_data.size = (size & ~3); - -#if NUM_CORES > 1 - /* This will become more important later - and different ! */ - dma_play_data.core = processor_id(); /* save initiating core */ -#endif - - IEN |= DAI_TX_IRQ_MASK; - - play_start_pcm(); -} - -void pcm_play_dma_stop(void) -{ - play_stop_pcm(); - dma_play_data.size = 0; -#if NUM_CORES > 1 - dma_play_data.core = 0; /* no core in control */ -#endif -} - -void pcm_play_lock(void) -{ - int status = disable_fiq_save(); - - if (++dma_play_data.locked == 1) - { - IEN &= ~DAI_TX_IRQ_MASK; - } - - restore_fiq(status); -} - -void pcm_play_unlock(void) -{ - int status = disable_fiq_save(); - - if (--dma_play_data.locked == 0 && dma_play_data.state != 0) - { - IEN |= DAI_TX_IRQ_MASK; - } - - restore_fiq(status); -} - -void pcm_play_dma_pause(bool pause) -{ - (void) pause; -} - -size_t pcm_get_bytes_waiting(void) -{ - return dma_play_data.size & ~3; -} - -#if 1 -void fiq_handler(void) ICODE_ATTR __attribute__((naked)); -void fiq_handler(void) -{ - /* r10 contains DADO_L0 base address (set in crt0.S to minimise code in the - * FIQ handler. r11 contains address of p (also set in crt0.S). Most other - * addresses we need are generated by using offsets with these two. - * r8 and r9 contains local copies of p and size respectively. - * r0-r3 and r12 is a working register. - */ - asm volatile ( - "mov r8, #0xc000 \n" /* DAI_TX_IRQ_MASK | DAI_RX_IRQ_MASK */ - "ldr r9, =0xf3001004 \n" /* CREQ */ - "str r8, [r9] \n" /* clear DAI IRQs */ - - "ldmia r11, { r8-r9 } \n" /* r8 = p, r9 = size */ - "cmp r9, #0x10 \n" /* is size <16? */ - "blt .more_data \n" /* if so, ask pcmbuf for more data */ - - ".fill_fifo: \n" - "ldr r12, [r8], #4 \n" /* load two samples */ - "str r12, [r10, #0x0] \n" /* write top sample to DADO_L0 */ - "mov r12, r12, lsr #16 \n" /* put right sample at the bottom */ - "str r12, [r10, #0x4] \n" /* write low sample to DADO_R0*/ - "ldr r12, [r8], #4 \n" /* load two samples */ - "str r12, [r10, #0x8] \n" /* write top sample to DADO_L1 */ - "mov r12, r12, lsr #16 \n" /* put right sample at the bottom */ - "str r12, [r10, #0xc] \n" /* write low sample to DADO_R1*/ - "ldr r12, [r8], #4 \n" /* load two samples */ - "str r12, [r10, #0x10] \n" /* write top sample to DADO_L2 */ - "mov r12, r12, lsr #16 \n" /* put right sample at the bottom */ - "str r12, [r10, #0x14] \n" /* write low sample to DADO_R2*/ - "ldr r12, [r8], #4 \n" /* load two samples */ - "str r12, [r10, #0x18] \n" /* write top sample to DADO_L3 */ - "mov r12, r12, lsr #16 \n" /* put right sample at the bottom */ - "str r12, [r10, #0x1c] \n" /* write low sample to DADO_R3*/ - "sub r9, r9, #0x10 \n" /* 4 words written */ - "stmia r11, { r8-r9 } \n" /* save p and size */ - - ".exit: \n" - "subs pc, lr, #4 \n" /* FIQ specific return sequence */ - - ".more_data: \n" - "stmfd sp!, { r0-r3, lr } \n" /* stack scratch regs and lr */ - "ldr r2, =pcm_callback_for_more \n" - "ldr r2, [r2] \n" /* get callback address */ - "cmp r2, #0 \n" /* check for null pointer */ - "movne r0, r11 \n" /* r0 = &p */ - "addne r1, r11, #4 \n" /* r1 = &size */ - "blxne r2 \n" /* call pcm_callback_for_more */ - "ldmia r11, { r8-r9 } \n" /* reload p and size */ - "cmp r9, #0x10 \n" /* did we actually get more data? */ - "ldmgefd sp!, { r0-r3, lr } \n" - "bge .fill_fifo \n" /* yes: fill the fifo */ - "ldr r12, =pcm_play_dma_stop \n" - "blx r12 \n" /* no: stop playback */ - "ldr r12, =pcm_play_dma_stopped_callback \n" - "blx r12 \n" - "ldmfd sp!, { r0-r3, lr } \n" - "b .exit \n" - ".ltorg \n" - ); -} -#else /* C version for reference */ -void fiq_handler(void) ICODE_ATTR __attribute__((naked)); -void fiq_handler(void) -{ - asm volatile( "stmfd sp!, {r0-r7, ip, lr} \n" /* Store context */ - "sub sp, sp, #8 \n"); /* Reserve stack */ - - register pcm_more_callback_type get_more; - - if (dma_play_data.size < 16) - { - /* p is empty, get some more data */ - get_more = pcm_callback_for_more; - if (get_more) - { - get_more((unsigned char**)&dma_play_data.p, - &dma_play_data.size); - } - } - - if (dma_play_data.size >= 16) - { - DADO_L(0) = *dma_play_data.p++; - DADO_R(0) = *dma_play_data.p++; - DADO_L(1) = *dma_play_data.p++; - DADO_R(1) = *dma_play_data.p++; - DADO_L(2) = *dma_play_data.p++; - DADO_R(2) = *dma_play_data.p++; - DADO_L(3) = *dma_play_data.p++; - DADO_R(3) = *dma_play_data.p++; - - dma_play_data.size -= 16; - } - else - { - /* No more data, so disable the FIFO/interrupt */ - pcm_play_dma_stop(); - pcm_play_dma_stopped_callback(); - } - - /* Clear FIQ status */ - CREQ = DAI_TX_IRQ_MASK | DAI_RX_IRQ_MASK; - - asm volatile( "add sp, sp, #8 \n" /* Cleanup stack */ - "ldmfd sp!, {r0-r7, ip, lr} \n" /* Restore context */ - "subs pc, lr, #4 \n"); /* Return from FIQ */ -} -#endif diff --git a/firmware/target/arm/wmcodec-telechips.c b/firmware/target/arm/wmcodec-telechips.c index 985a72dccc..5fcc46154b 100644 --- a/firmware/target/arm/wmcodec-telechips.c +++ b/firmware/target/arm/wmcodec-telechips.c @@ -34,6 +34,8 @@ #if defined(COWON_D2) /* The D2's audio codec uses an I2C address of 0x34 */ #define I2C_AUDIO_ADDRESS 0x34 +#elif defined (IAUDIO_7) +#define I2C_AUDIO_ADDRESS 0x34 #else #error wmcodec not implemented for this target! #endif @@ -41,6 +43,9 @@ void audiohw_init(void) { +#if defined(HAVE_WM8731) || defined(HAVE_WM8751) + audiohw_preinit(); +#endif } void wmcodec_write(int reg, int data) -- cgit v1.2.3