diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2020-07-15 19:40:55 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2020-07-24 21:20:13 +0000 |
commit | 092c340a2062fa98b7387fc5fd63578ddae7d0b6 (patch) | |
tree | 98ec96946eeb2ae709cb0528cc6998e21bb9b290 /firmware/target/sh/archos | |
parent | 17f7cc92c258bc456a27c3e7c5a19c9409851879 (diff) | |
download | rockbox-092c340a2062fa98b7387fc5fd63578ddae7d0b6.tar.gz rockbox-092c340a2062fa98b7387fc5fd63578ddae7d0b6.zip |
[1/4] Remove SH support and all archos targets
This removes all code specific to SH targets
Change-Id: I7980523785d2596e65c06430f4638eec74a06061
Diffstat (limited to 'firmware/target/sh/archos')
47 files changed, 0 insertions, 6766 deletions
diff --git a/firmware/target/sh/archos/app.lds b/firmware/target/sh/archos/app.lds deleted file mode 100644 index 225f11f705..0000000000 --- a/firmware/target/sh/archos/app.lds +++ /dev/null @@ -1,145 +0,0 @@ -#include "config.h" - -ENTRY(start) - -OUTPUT_FORMAT(elf32-sh) -STARTUP(target/sh/crt0.o) - -#define PLUGINSIZE PLUGIN_BUFFER_SIZE -#define CODECSIZE CODEC_SIZE - -#ifdef DEBUG -#define STUBOFFSET 0x10000 -#else -#define STUBOFFSET 0 -#endif - -#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGINSIZE - STUBOFFSET - CODECSIZE - -#define DRAMORIG 0x09000000 + STUBOFFSET -#define IRAMORIG 0x0f000000 -#define IRAMSIZE 0x1000 - -/* End of the audio buffer, where the codec buffer starts */ -#define ENDAUDIOADDR (DRAMORIG + DRAMSIZE) - -/* 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 -} - -SECTIONS -{ - .vectors : - { - loadaddress = .; - _loadaddress = .; - KEEP(*(.resetvectors)); - *(.resetvectors); - KEEP(*(.vectors)); - *(.vectors); - } > DRAM - - .text : - { - . = ALIGN(0x200); - *(.init.text) - *(.text*) - . = ALIGN(0x4); - } > DRAM - - .rodata : - { - *(.rodata) /* problems without this, dunno why */ - *(.rodata*) - *(.rodata.str1.1) - *(.rodata.str1.4) - . = ALIGN(0x4); - - /* 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) - } - - .iram IRAMORIG : - { - _iramstart = .; - *(.icode) - *(.irodata) - *(.idata) - _iramend = .; - } > IRAM AT> DRAM - - _iramcopy = LOADADDR(.iram); - _noloaddram = LOADADDR(.iram); - - .ibss (NOLOAD) : - { - _iedata = .; - *(.ibss) - . = ALIGN(0x4); - _iend = .; - } > IRAM - - .stack _noloaddram (NOLOAD) : - { - *(.stack) - _stackbegin = .; - . += 0x2000; - _stackend = .; - } > DRAM - - .bss (NOLOAD) : - { - _edata = .; - *(.bss*) - *(COMMON) - . = ALIGN(0x4); - _end = .; - } > DRAM - - .audiobuf (NOLOAD) : - { - . = ALIGN(4); - _audiobuffer = .; - audiobuffer = .; - } > DRAM - - .audiobufend ENDAUDIOADDR (NOLOAD) : - { - audiobufend = .; - _audiobufend = .; - } > DRAM - - .codec ENDAUDIOADDR (NOLOAD) : - { - codecbuf = .; - _codecbuf = .; - } - - .plugin ENDADDR (NOLOAD) : - { - _pluginbuf = .; - pluginbuf = .; - } -} - diff --git a/firmware/target/sh/archos/ata-archos.c b/firmware/target/sh/archos/ata-archos.c deleted file mode 100644 index 2046d3b33f..0000000000 --- a/firmware/target/sh/archos/ata-archos.c +++ /dev/null @@ -1,71 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Jens Arnold - * - * 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 <stdbool.h> -#include "kernel.h" -#include "system.h" -#include "ata-driver.h" -#include "hwcompat.h" - -#define ATA_CONTROL1 ((volatile unsigned char*)0x06200206) -#define ATA_CONTROL2 ((volatile unsigned char*)0x06200306) - -volatile unsigned char* ata_control; - -void ata_reset(void) -{ - /* state HRR0 */ - and_b(~0x02, &PADRH); /* assert _RESET */ - sleep(1); /* > 25us */ - - /* state HRR1 */ - or_b(0x02, &PADRH); /* negate _RESET */ - sleep(1); /* > 2ms */ -} - -void ata_enable(bool on) -{ - if(on) - and_b(~0x80, &PADRL); /* enable ATA */ - else - or_b(0x80, &PADRL); /* disable ATA */ - - or_b(0x80, &PAIORL); -} - -void ata_device_init(void) -{ - or_b(0x02, &PAIORH); /* output for ATA reset */ - or_b(0x02, &PADRH); /* release ATA reset */ - PACR2 &= 0xBFFF; /* GPIO function for PA7 (IDE enable) */ - - if (HW_MASK & ATA_ADDRESS_200) - ata_control = ATA_CONTROL1; - else - ata_control = ATA_CONTROL2; -} - -bool ata_is_coldstart(void) -{ - return (PACR2 & 0x4000) != 0; -} diff --git a/firmware/target/sh/archos/ata-as-archos.S b/firmware/target/sh/archos/ata-as-archos.S deleted file mode 100644 index c403c4c921..0000000000 --- a/firmware/target/sh/archos/ata-as-archos.S +++ /dev/null @@ -1,233 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2004-2006 by Jens Arnold - * - * 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. - * - ****************************************************************************/ - - .section .icode,"ax",@progbits - - .align 2 - .global _copy_read_sectors - .type _copy_read_sectors,@function - -/* Read a number of words from the ATA data port - * - * Assumes wordcount to be a multiple of 4 - * - * Arguments: - * r4 - buffer address - * r5 - word count - * - * Register usage: - * r0 - scratch - * r1/r2 - read buffers - * r3 - mask (if unaligned) - * r4 - current address - * r5 - end address - * r6 - ata port - */ - -_copy_read_sectors: - add r5, r5 /* words -> bytes */ - add r4, r5 /* bytes -> end address */ - add #-12, r5 /* adjust for offsets */ - mov.l .ata_data, r6 - - mov r4, r0 - tst #1, r0 /* 16-bit aligned ? */ - bt .r_aligned /* yes, do word copy */ - - /* not 16-bit aligned */ - mov #-1, r3 /* prepare a bit mask for high byte */ - shll8 r3 /* r3 = 0xFFFFFF00 */ - - mov.w @r6, r2 /* read first word (1st round) */ - mov.b r2, @r4 /* store low byte of first word */ - bra .r_start_b /* jump into loop after next instr. */ - add #-5, r4 /* adjust for dest. offsets; now even */ - - .align 2 -.r_loop_b: /* main loop: copy 4 words in a row */ - mov.w @r6, r2 /* read first word (2+ round) */ - and r3, r1 /* get high byte of fourth word (2+ round) */ - extu.b r2, r0 /* get low byte of first word (2+ round) */ - or r1, r0 /* combine with high byte of fourth word */ - mov.w r0, @(4, r4) /* store at buf[4] */ - nop /* maintain alignment */ -.r_start_b: - mov.w @r6, r1 /* read second word */ - and r3, r2 /* get high byte of first word */ - extu.b r1, r0 /* get low byte of second word */ - or r2, r0 /* combine with high byte of first word */ - mov.w r0, @(6, r4) /* store at buf[6] */ - add #8, r4 /* buf += 8 */ - mov.w @r6, r2 /* read third word */ - and r3, r1 /* get high byte of second word */ - extu.b r2, r0 /* get low byte of third word */ - or r1, r0 /* combine with high byte of second word */ - mov.w r0, @r4 /* store at buf[0] */ - cmp/hi r4, r5 /* check for end */ - mov.w @r6, r1 /* read fourth word */ - and r3, r2 /* get high byte of third word */ - extu.b r1, r0 /* get low byte of fourth word */ - or r2, r0 /* combine with high byte of third word */ - mov.w r0, @(2, r4) /* store at buf[2] */ - bt .r_loop_b - /* 24 instructions for 4 copies, takes 30 clock cycles (4 wait) */ - /* avg. 7.5 cycles per word */ - - swap.b r1, r0 /* get high byte of last word */ - rts - mov.b r0, @(4, r4) /* and store it */ - - /* 16-bit aligned, loop(read and store word) */ -.r_aligned: - mov.w @r6, r2 /* read first word (1st round) */ - bra .r_start_w /* jump into loop after next instr. */ - add #-6, r4 /* adjust for destination offsets */ - - .align 2 -.r_loop_w: /* main loop: copy 4 words in a row */ - mov.w @r6, r2 /* read first word (2+ round) */ - swap.b r1, r0 /* swap fourth word (2+ round) */ - mov.w r0, @(4, r4) /* store fourth word (2+ round) */ - nop /* maintain alignment */ -.r_start_w: - mov.w @r6, r1 /* read second word */ - swap.b r2, r0 /* swap first word */ - mov.w r0, @(6, r4) /* store first word in buf[6] */ - add #8, r4 /* buf += 8 */ - mov.w @r6, r2 /* read third word */ - swap.b r1, r0 /* swap second word */ - mov.w r0, @r4 /* store second word in buf[0] */ - cmp/hi r4, r5 /* check for end */ - mov.w @r6, r1 /* read fourth word */ - swap.b r2, r0 /* swap third word */ - mov.w r0, @(2, r4) /* store third word */ - bt .r_loop_w - /* 16 instructions for 4 copies, takes 22 clock cycles (4 wait) */ - /* avg. 5.5 cycles per word */ - - swap.b r1, r0 /* swap fourth word (last round) */ - rts - mov.w r0, @(4, r4) /* and store it */ - -.r_end: - .size _copy_read_sectors,.r_end-_copy_read_sectors - - .align 2 - .global _copy_write_sectors - .type _copy_write_sectors,@function - -/* Write a number of words to the ATA data port - * - * Assumes wordcount to be a multiple of 2. - * Writing is not unrolled as much as reading, for several reasons: - * - * - a similar instruction sequence is faster for writing than for reading - * because the auto-incrementing load instructions can be used - * - writing profits from warp mode - * - * Both of these add up to have writing faster than the more unrolled reading. - * - * Arguments: - * r4 - buffer address - * r5 - word count - * - * Register usage: - * r0/r1 - scratch - * r2/r3 - write buffers - * r4 - current address - * r5 - end address - * r6 - mask (if unaligned) - * r7 - ata port - */ - -_copy_write_sectors: - add r5, r5 /* words -> bytes */ - add r4, r5 /* bytes -> end address */ - add #-4, r5 /* adjust for offsets */ - mov.l .ata_data, r7 - - mov r4, r0 - tst #1, r0 /* 16-bit aligned ? */ - bt .w_aligned /* yes, do word copy */ - - /* not 16-bit aligned */ - mov #-1, r6 /* prepare a bit mask for high byte */ - shll8 r6 /* r6 = 0xFFFFFF00 */ - - mov.b @r4+, r2 /* load (initial old second) first byte */ - mov.w @r4+, r3 /* load (initial) first word */ - bra .w_start_b - extu.b r2, r0 /* extend unsigned */ - - .align 2 -.w_loop_b: /* main loop: copy 2 words in a row */ - mov.w @r4+, r3 /* load first word (2+ round) */ - extu.b r2, r0 /* put away low byte of second word (2+ round) */ - and r6, r2 /* get high byte of second word (2+ round) */ - or r1, r2 /* combine with low byte of old first word */ - mov.w r2, @r7 /* write that */ -.w_start_b: - cmp/hi r4, r5 /* check for end */ - mov.w @r4+, r2 /* load second word */ - extu.b r3, r1 /* put away low byte of first word */ - and r6, r3 /* get high byte of first word */ - or r0, r3 /* combine with high byte of old second word */ - mov.w r3, @r7 /* write that */ - bt .w_loop_b - /* 12 instructions for 2 copies, takes 14 clock cycles */ - /* avg. 7 cycles per word */ - - /* the loop "overreads" 1 byte past the buffer end, however, the last */ - /* byte is not written to disk */ - and r6, r2 /* get high byte of last word */ - or r1, r2 /* combine with low byte of old first word */ - rts - mov.w r2, @r7 /* write last word */ - - /* 16-bit aligned, loop(load and write word) */ -.w_aligned: - bra .w_start_w /* jump into loop after next instr. */ - mov.w @r4+, r2 /* load first word (1st round) */ - - .align 2 -.w_loop_w: /* main loop: copy 2 words in a row */ - mov.w @r4+, r2 /* load first word (2+ round) */ - swap.b r1, r0 /* swap second word (2+ round) */ - mov.w r0, @r7 /* write second word (2+ round) */ -.w_start_w: - cmp/hi r4, r5 /* check for end */ - mov.w @r4+, r1 /* load second word */ - swap.b r2, r0 /* swap first word */ - mov.w r0, @r7 /* write first word */ - bt .w_loop_w - /* 8 instructions for 2 copies, takes 10 clock cycles */ - /* avg. 5 cycles per word */ - - swap.b r1, r0 /* swap second word (last round) */ - rts - mov.w r0, @r7 /* and write it */ - -.w_end: - .size _copy_write_sectors,.w_end-_copy_write_sectors - - .align 2 -.ata_data: - .long 0x06104100 /* ATA data port */ diff --git a/firmware/target/sh/archos/ata-target.h b/firmware/target/sh/archos/ata-target.h deleted file mode 100644 index dc55cdd5d5..0000000000 --- a/firmware/target/sh/archos/ata-target.h +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Jens Arnold - * - * 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 - -/* asm optimised read & write loops */ -#define ATA_OPTIMIZED_READING -#define ATA_OPTIMIZED_WRITING - -#define ATA_SWAP_WORDS - -#define ATA_IOBASE 0x06100100 -#define ATA_DATA (*((volatile unsigned short*)0x06104100)) -#define ATA_CONTROL (*ata_control) - -#define ATA_ERROR (*((volatile unsigned char*)ATA_IOBASE + 1)) -#define ATA_NSECTOR (*((volatile unsigned char*)ATA_IOBASE + 2)) -#define ATA_SECTOR (*((volatile unsigned char*)ATA_IOBASE + 3)) -#define ATA_LCYL (*((volatile unsigned char*)ATA_IOBASE + 4)) -#define ATA_HCYL (*((volatile unsigned char*)ATA_IOBASE + 5)) -#define ATA_SELECT (*((volatile unsigned char*)ATA_IOBASE + 6)) -#define ATA_COMMAND (*((volatile unsigned char*)ATA_IOBASE + 7)) - -extern volatile unsigned char* ata_control; - - -#endif diff --git a/firmware/target/sh/archos/audio-archos.c b/firmware/target/sh/archos/audio-archos.c deleted file mode 100644 index 2c2579bec5..0000000000 --- a/firmware/target/sh/archos/audio-archos.c +++ /dev/null @@ -1,543 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Code that has been in mpeg.c before, now creating an encapsulated play - * data module, to be used by other sources than file playback as well. - * - * 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. - * - ****************************************************************************/ -#include <stdbool.h> -#include "config.h" -#include "debug.h" -#include "panic.h" -#include <kernel.h> -#include "mp3_playback.h" -#include "sound.h" -#include "i2c.h" -#include "system.h" -#include "audiohw.h" - -/* hacking into mpeg.c, recording is still there */ -#if CONFIG_CODEC == MAS3587F -enum -{ - MPEG_DECODER, - MPEG_ENCODER -} mpeg_mode; -#endif /* #ifdef MAS3587F */ - -#if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)) && !defined(SIMULATOR) -extern unsigned long shadow_io_control_main; -extern unsigned shadow_codec_reg0; -#endif - -/**** globals ****/ - -/* own version, independent of mpeg.c */ -static bool paused; /* playback is paused */ -static bool playing; /* We are playing an MP3 stream */ - -/* the registered callback function to ask for more mp3 data */ -static mp3_play_callback_t callback_for_more; - -/* list of tracks in memory */ -#define MAX_ID3_TAGS (1<<4) /* Must be power of 2 */ -#define MAX_ID3_TAGS_MASK (MAX_ID3_TAGS - 1) - -bool audio_is_initialized = false; - -/* FIX: this code pretty much assumes a MAS */ - -/* dirty calls to mpeg.c */ -extern void playback_tick(void); -extern void rec_tick(void); - -unsigned long mas_version_code; - -#if CONFIG_CODEC == MAS3507D -static void mas_poll_start(void) -{ - unsigned int count; - - count = 9 * FREQ / 10000 / 8; /* 0.9 ms */ - - /* We are using timer 1 */ - - TSTR &= ~0x02; /* Stop the timer */ - TSNC &= ~0x02; /* No synchronization */ - TMDR &= ~0x02; /* Operate normally */ - - TCNT1 = 0; /* Start counting at 0 */ - GRA1 = count; - TCR1 = 0x23; /* Clear at GRA match, sysclock/8 */ - - /* Enable interrupt on level 5 */ - IPRC = (IPRC & ~0x000f) | 0x0005; - - TSR1 &= ~0x02; - TIER1 = 0xf9; /* Enable GRA match interrupt */ - - TSTR |= 0x02; /* Start timer 1 */ -} -#elif CONFIG_CODEC != SWCODEC -static void postpone_dma_tick(void) -{ - unsigned int count; - - count = 8 * FREQ / 10000 / 8; /* 0.8 ms */ - - /* We are using timer 1 */ - - TSTR &= ~0x02; /* Stop the timer */ - TSNC &= ~0x02; /* No synchronization */ - TMDR &= ~0x02; /* Operate normally */ - - TCNT1 = 0; /* Start counting at 0 */ - GRA1 = count; - TCR1 = 0x23; /* Clear at GRA match, sysclock/8 */ - - /* Enable interrupt on level 5 */ - IPRC = (IPRC & ~0x000f) | 0x0005; - - TSR1 &= ~0x02; - TIER1 = 0xf9; /* Enable GRA match interrupt */ - - TSTR |= 0x02; /* Start timer 1 */ -} -#endif - -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) -void demand_irq_enable(bool on) -{ - int oldlevel = disable_irq_save(); - - if(on) - { - IPRA = (IPRA & 0xfff0) | 0x000b; - ICR &= ~0x0010; /* IRQ3 level sensitive */ - } - else - IPRA &= 0xfff0; - - restore_irq(oldlevel); -} -#endif /* #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ - - -static void play_tick(void) -{ - if(playing && !paused) - { - /* Start DMA if it is disabled and the DEMAND pin is high */ - if(!(SCR0 & 0x80) && (PBDR & 0x4000)) - { - SCR0 |= 0x80; - } - - playback_tick(); /* dirty call to mpeg.c */ - } -} - -void DEI3(void) __attribute__((interrupt_handler)); -void DEI3(void) -{ - const void* start; - size_t size = 0; - - if (callback_for_more != NULL) - { - callback_for_more(&start, &size); - } - - if (size > 0) - { - DTCR3 = size & 0xffff; - SAR3 = (unsigned int) start; - } - else - { - CHCR3 &= ~0x0001; /* Disable the DMA interrupt */ - } - - CHCR3 &= ~0x0002; /* Clear DMA interrupt */ -} - -void IMIA1(void) __attribute__((interrupt_handler)); -void IMIA1(void) /* Timer 1 interrupt */ -{ - if(playing) - play_tick(); - TSR1 &= ~0x01; -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) - /* Disable interrupt */ - IPRC &= ~0x000f; -#endif -} - -void IRQ6(void) __attribute__((interrupt_handler)); -void IRQ6(void) /* PB14: MAS stop demand IRQ */ -{ - SCR0 &= ~0x80; -} - -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) -void IRQ3(void) __attribute__((interrupt_handler)); -void IRQ3(void) /* PA15: MAS demand IRQ */ -{ - /* Begin with setting the IRQ to edge sensitive */ - ICR |= 0x0010; - -#if CONFIG_CODEC == MAS3587F - if(mpeg_mode == MPEG_ENCODER) - rec_tick(); - else -#endif - postpone_dma_tick(); - - /* Workaround for sh-elf-gcc 3.3.x bug with -O2 or -Os and ISRs - * (invalid cross-jump optimisation) */ - asm volatile (""); -} -#endif /* #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ - -static void setup_sci0(void) -{ - /* PB15 is I/O, PB14 is IRQ6, PB12 is SCK0, PB9 is TxD0 */ - PBCR1 = (PBCR1 & 0x0cff) | 0x1208; - - /* Set PB12 to output */ - or_b(0x10, &PBIORH); - - /* Disable serial port */ - SCR0 = 0x00; - - /* Synchronous, no prescale */ - SMR0 = 0x80; - - /* Set baudrate 1Mbit/s */ - BRR0 = 0x02; - - /* use SCK as serial clock output */ - SCR0 = 0x01; - - /* Clear FER and PER */ - SSR0 &= 0xe7; - - /* Set interrupt ITU2 and SCI0 priority to 0 */ - IPRD &= 0x0ff0; - - /* set PB15 and PB14 to inputs */ - and_b(~0x80, &PBIORH); - and_b(~0x40, &PBIORH); - - /* Enable End of DMA interrupt at prio 8 */ - IPRC = (IPRC & 0xf0ff) | 0x0800; - - /* Enable Tx (only!) */ - SCR0 |= 0x20; -} - -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) -static void init_playback(void) -{ - unsigned long val; - int rc; - - mp3_play_pause(false); - - mas_reset(); - - /* Enable the audio CODEC and the DSP core, max analog voltage range */ - rc = mas_direct_config_write(MAS_CONTROL, 0x8c00); - if(rc < 0) - panicf("mas_ctrl_w: %d", rc); - - /* Stop the current application */ - val = 0; - mas_writemem(MAS_BANK_D0, MAS_D0_APP_SELECT, &val, 1); - do - { - mas_readmem(MAS_BANK_D0, MAS_D0_APP_RUNNING, &val, 1); - } while(val); - - /* Enable the D/A Converter */ - shadow_codec_reg0 = 0x0001; - mas_codec_writereg(0x0, shadow_codec_reg0); - - /* ADC scale 0%, DSP scale 100% */ - mas_codec_writereg(6, 0x0000); - mas_codec_writereg(7, 0x4000); - -#ifdef HAVE_SPDIF_OUT - val = 0x09; /* Disable SDO and SDI, low impedance S/PDIF outputs */ -#else - val = 0x2d; /* Disable SDO and SDI, disable S/PDIF output */ -#endif - mas_writemem(MAS_BANK_D0, MAS_D0_INTERFACE_CONTROL, &val, 1); - - /* Set Demand mode and validate all settings */ - shadow_io_control_main = 0x25; - mas_writemem(MAS_BANK_D0, MAS_D0_IO_CONTROL_MAIN, &shadow_io_control_main, 1); - - /* Start the Layer2/3 decoder applications */ - val = 0x0c; - mas_writemem(MAS_BANK_D0, MAS_D0_APP_SELECT, &val, 1); - do - { - mas_readmem(MAS_BANK_D0, MAS_D0_APP_RUNNING, &val, 1); - } while((val & 0x0c) != 0x0c); - -#if CONFIG_CODEC == MAS3587F - mpeg_mode = MPEG_DECODER; -#endif - - /* set IRQ6 to edge detect */ - ICR |= 0x02; - - /* set IRQ6 prio 8 */ - IPRB = ( IPRB & 0xff0f ) | 0x0080; - - DEBUGF("MAS Decoding application started\n"); -} -#endif /* #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ - -void mp3_init(int volume, int bass, int treble, int balance, int loudness, - int avc, int channel_config, int stereo_width, - int mdb_strength, int mdb_harmonics, - int mdb_center, int mdb_shape, bool mdb_enable, - bool superbass) -{ -#if CONFIG_CODEC == MAS3507D - unsigned long val; - (void)loudness; - (void)avc; - (void)mdb_strength; - (void)mdb_harmonics; - (void)mdb_center; - (void)mdb_shape; - (void)mdb_enable; - (void)superbass; -#endif - - setup_sci0(); - -#ifdef HAVE_MAS_SIBI_CONTROL - and_b(~0x01, &PBDRH); /* drive SIBI low */ - or_b(0x01, &PBIORH); /* output for PB8 */ -#endif - -#if CONFIG_CODEC == MAS3507D - mas_reset(); -#elif CONFIG_CODEC == MAS3587F - or_b(0x08, &PAIORH); /* output for /PR */ - init_playback(); - - mas_version_code = mas_readver(); - DEBUGF("MAS3587 derivate %d, version %c%d\n", - (mas_version_code & 0xf000) >> 12, - 'A' + ((mas_version_code & 0x0f00) >> 8), mas_version_code & 0xff); -#elif CONFIG_CODEC == MAS3539F - or_b(0x08, &PAIORH); /* output for /PR */ - init_playback(); - - mas_version_code = mas_readver(); - DEBUGF("MAS3539 derivate %d, version %c%d\n", - (mas_version_code & 0xf000) >> 12, - 'A' + ((mas_version_code & 0x0f00) >> 8), mas_version_code & 0xff); -#endif - -#ifdef HAVE_DAC3550A - dac_init(); -#endif - -#if CONFIG_CODEC == MAS3507D - /* set IRQ6 to edge detect */ - ICR |= 0x02; - - /* set IRQ6 prio 8 */ - IPRB = ( IPRB & 0xff0f ) | 0x0080; - - mas_readmem(MAS_BANK_D1, 0xff7, &mas_version_code, 1); - - mas_writereg(0x3b, 0x20); /* Don't ask why. The data sheet doesn't say */ - mas_run(1); - sleep(HZ); - - /* Clear the upper 12 bits of the 32-bit samples */ - mas_writereg(0xc5, 0); - mas_writereg(0xc6, 0); - - /* We need to set the PLL for a 14.31818MHz crystal */ - if(mas_version_code == 0x0601) /* Version F10? */ - { - val = 0x5d9d0; - mas_writemem(MAS_BANK_D0, 0x32d, &val, 1); - val = 0xfffceceb; - mas_writemem(MAS_BANK_D0, 0x32e, &val, 1); - val = 0x0; - mas_writemem(MAS_BANK_D0, 0x32f, &val, 1); - mas_run(0x475); - } - else - { - val = 0x5d9d0; - mas_writemem(MAS_BANK_D0, 0x36d, &val, 1); - val = 0xfffceceb; - mas_writemem(MAS_BANK_D0, 0x36e, &val, 1); - val = 0x0; - mas_writemem(MAS_BANK_D0, 0x36f, &val, 1); - mas_run(0xfcb); - } - -#endif - -#if CONFIG_CODEC == MAS3507D - mas_poll_start(); - - mas_writereg(MAS_REG_KPRESCALE, 0xe9400); - dac_enable(true); -#endif - -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) - ICR &= ~0x0010; /* IRQ3 level sensitive */ - PACR1 = (PACR1 & 0x3fff) | 0x4000; /* PA15 is IRQ3 */ -#endif - - /* Must be done before calling sound_set() */ - audio_is_initialized = true; - - sound_set(SOUND_BASS, bass); - sound_set(SOUND_TREBLE, treble); - sound_set(SOUND_BALANCE, balance); - sound_set(SOUND_VOLUME, volume); - sound_set(SOUND_CHANNELS, channel_config); - sound_set(SOUND_STEREO_WIDTH, stereo_width); - -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) - sound_set(SOUND_LOUDNESS, loudness); - sound_set(SOUND_AVC, avc); - sound_set(SOUND_MDB_STRENGTH, mdb_strength); - sound_set(SOUND_MDB_HARMONICS, mdb_harmonics); - sound_set(SOUND_MDB_CENTER, mdb_center); - sound_set(SOUND_MDB_SHAPE, mdb_shape); - sound_set(SOUND_MDB_ENABLE, mdb_enable); - sound_set(SOUND_SUPERBASS, superbass); -#endif - - playing = false; - paused = true; -} - -void mp3_shutdown(void) -{ -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) - unsigned long val = 1; - mas_writemem(MAS_BANK_D0, MAS_D0_SOFT_MUTE, &val, 1); /* Mute */ -#endif - -#if CONFIG_CODEC == MAS3507D - dac_volume(0, 0, false); -#endif -} - -/* new functions, to be exported to plugin API */ - -#if CONFIG_CODEC == MAS3587F -void mp3_play_init(void) -{ -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) - init_playback(); -#endif - playing = false; - paused = true; - callback_for_more = NULL; -} -#endif - -void mp3_play_data(const void* start, size_t size, - mp3_play_callback_t get_more) -{ - /* init DMA */ - DAR3 = 0x5FFFEC3; - CHCR3 &= ~0x0002; /* Clear interrupt */ - CHCR3 = 0x1504; /* Single address destination, TXI0, IE=1 */ - DMAOR = 0x0001; /* Enable DMA */ - - callback_for_more = get_more; - - SAR3 = (unsigned int)start; - DTCR3 = size & 0xffff; - - playing = true; - paused = true; - - CHCR3 |= 0x0001; /* Enable DMA IRQ */ - -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) - demand_irq_enable(true); -#endif -} - -void mp3_play_pause(bool play) -{ - if (paused && play) - { /* resume playback */ - SCR0 |= 0x80; - paused = false; - } - else if (!paused && !play) - { /* stop playback */ - SCR0 &= 0x7f; - paused = true; - } -} - -bool mp3_pause_done(void) -{ - unsigned long frame_count; - - if (!paused) - return false; - - mas_readmem(MAS_BANK_D0, MAS_D0_MPEG_FRAME_COUNT, &frame_count, 1); - /* This works because the frame counter never wraps, - * i.e. zero always means lost sync. */ - return frame_count == 0; -} - -void mp3_play_stop(void) -{ - playing = false; - mp3_play_pause(false); - CHCR3 &= ~0x0001; /* Disable the DMA interrupt */ -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) - demand_irq_enable(false); -#endif -} - -bool mp3_is_playing(void) -{ - return playing; -} - - -/* returns the next byte position which would be transferred */ -unsigned char* mp3_get_pos(void) -{ - return (unsigned char*)SAR3; -} diff --git a/firmware/target/sh/archos/boot.lds b/firmware/target/sh/archos/boot.lds deleted file mode 100644 index b3c2c90a6c..0000000000 --- a/firmware/target/sh/archos/boot.lds +++ /dev/null @@ -1,81 +0,0 @@ -#include "config.h" - -ENTRY(start) -OUTPUT_FORMAT(elf32-sh) -STARTUP(target/sh/crt0.o) - -#define DRAMSIZE (MEMORYSIZE * 0x100000) - -#define DRAMORIG 0x09000000 -#define IRAMORIG 0x0f000000 -#define IRAMSIZE 0x1000 -#define FLASHORIG 0x02000000 + ROM_START -#define FLASHSIZE 256K - ROM_START - -MEMORY -{ - DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE - IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE - FLASH : ORIGIN = FLASHORIG, LENGTH = FLASHSIZE -} - -SECTIONS -{ - .vectors : - { - _datacopy = .; - } > FLASH - - .data : AT ( _datacopy ) - { - _datastart = .; - KEEP(*(.resetvectors)); - *(.resetvectors); - KEEP(*(.vectors)); - *(.vectors); - . = ALIGN(0x200); - *(.icode) - *(.irodata) - *(.idata) - *(.data*) - . = ALIGN(0x4); - _dataend = .; - . = ALIGN(0x10); /* Maintain proper alignment for .text section */ - } > IRAM - - /* TRICK ALERT! Newer versions of the linker don't allow output sections - to overlap even if one of them is empty, so advance the location pointer - "by hand" */ - .text LOADADDR(.data) + SIZEOF(.data) : - { - *(.init.text) - *(.text*) - . = ALIGN(0x4); - } > FLASH - - .rodata : - { - *(.rodata*) - . = ALIGN(0x4); - _iramcopy = .; - } > FLASH - - .stack : - { - *(.stack) - _stackbegin = .; - stackbegin = .; - . += 0x2000; - _stackend = .; - stackend = .; - } > IRAM - - .bss : - { - _edata = .; - *(.ibss) - *(.bss*) - *(COMMON) - _end = .; - } > IRAM -} diff --git a/firmware/target/sh/archos/descramble.S b/firmware/target/sh/archos/descramble.S deleted file mode 100644 index 0ab5e93dce..0000000000 --- a/firmware/target/sh/archos/descramble.S +++ /dev/null @@ -1,121 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2004 by Jens Arnold - * - * 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. - * - ****************************************************************************/ - - .section .icode,"ax",@progbits - - .align 2 /* this aligns to 2^2=4 byte bounday */ - .global _descramble - .type _descramble,@function - -/* Descramble a block of byte data, from source to dest, processing len - * bytes. Size only limited by the len argument. Note that len must - * be an even multiple of 4 (something rolo_load() already assumes. - * (Does the Archos firmware loader also require that?). - * - * Returns the 16-bit "sum" checksum of the descrambled data. - * - * Arguments: - * r4 - source (unsigned char*) - * r5 - dest (unsigned char*) - * r6 - len (unsigned int) - * - * Register usage: - * r0 - data - * r1 - temp - * r2 - checksum - * r3 - current src address - * r4 - source - * r5 - dest - * r6 - len -> source_end - * r7 - dest_end - * r8 - len / 4 - */ - -_descramble: - mov.l r8,@-r15 - mov r6,r8 - shlr2 r8 /* r8 = len / 4 */ - mov r5,r7 - add r6,r7 /* dest_end = dest + len */ - add r4,r6 /* source_end = source + len */ - mov r4,r3 /* addr = source */ - mov #0,r2 /* checksum = 0 */ - -.loop: - mov.b @r3,r0 /* data = *addr */ - add r8,r3 /* addr += len / 4 */ - extu.b r0,r0 /* zero extend data byte */ - swap.b r0,r1 /* byte swap low word to temp */ - or r1,r0 /* r0's two lower bytes now identical */ - shlr r0 /* -> this equals "rotr.b r0" now */ - not r0,r0 /* negate */ - extu.b r0,r0 /* zero extend low byte (only needed for sum) */ - mov.b r0,@r5 /* *dest = data */ - add r0,r2 /* checksum += data */ - add #1,r5 /* dest++ */ - cmp/hi r3,r6 /* addr < source_end ? */ - bt .loop - - add #1,r4 /* source++ */ - mov r4,r3 /* addr = source */ - cmp/hi r5,r7 /* dest < dest_end */ - bt .loop - -/* 15 clock cycles if no reset of source address, 19 if reset, - * avg. 16 cycles per byte. Magnus' Version needed 17-22 cycles per byte - */ - - mov.l @r15+,r8 - rts - extu.w r2,r0 - - -/* Move len bytes from source to dest (which must be suitably aligned for - * long moves) and jump to dest + 0x200. - * - * Arguments: - * r4 - source - * r5 - dest - * r6 - len - */ - - .align 2 - .global _rolo_restart - .type _rolo_restart,@function - -_rolo_restart: - mov r5,r0 - sub r4,r0 /* r0 = dest - source */ - add #-4,r0 /* adjust for early increment */ - add r4,r6 /* r6 = source + len */ - -.copy: /* loop takes 6 cycles per longword */ - mov.l @r4+,r1 - cmp/hi r4,r6 - mov.l r1,@(r0,r4) - bt .copy - - mov.l @r5+,r0 /* start address from image */ - jmp @r0 - mov.l @r5+,r15 /* stack pointer from image */ - -.end: - .size _descramble,.end-_descramble diff --git a/firmware/target/sh/archos/fm_v2/adc-target.h b/firmware/target/sh/archos/fm_v2/adc-target.h deleted file mode 100644 index 0070828cf3..0000000000 --- a/firmware/target/sh/archos/fm_v2/adc-target.h +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 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. - * - ****************************************************************************/ -#ifndef _ADC_TARGET_H_ -#define _ADC_TARGET_H_ - -#define NUM_ADC_CHANNELS 8 - -#define ADC_BATTERY 0 /* Battery voltage always reads 0x3FF due to - silly scaling */ -#define ADC_CHARGE_REGULATOR 0 /* Uh, we read the battery voltage? */ -#define ADC_USB_POWER 1 /* USB, reads 0x000 when USB is inserted */ -#define ADC_BUTTON_OFF 2 /* the off button, high value if pressed */ -#define ADC_BUTTON_ON 3 /* the on button, low value if pressed */ -#define ADC_BUTTON_ROW1 4 /* Used for scanning the keys, different - voltages for different keys */ -#define ADC_BUTTON_ROW2 5 /* Used for scanning the keys, different - voltages for different keys */ -#define ADC_UNREG_POWER 6 /* Battery voltage with a better scaling */ -#define ADC_EXT_POWER 7 /* The external power voltage, 0v or 2.7v */ - -#define EXT_SCALE_FACTOR 14800 - -#endif /* _ADC_TARGET_H_ */ diff --git a/firmware/target/sh/archos/fm_v2/backlight-target.h b/firmware/target/sh/archos/fm_v2/backlight-target.h deleted file mode 100644 index c3dd395eca..0000000000 --- a/firmware/target/sh/archos/fm_v2/backlight-target.h +++ /dev/null @@ -1,51 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2007 by Jens Arnold - * - * 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 "config.h" -#include "rtc.h" - -#define backlight_hw_init() true - -static inline void backlight_hw_on(void) -{ - rtc_write(0x13, 0x10); /* 32 kHz square wave */ - rtc_write(0x0a, rtc_read(0x0a) | 0x40); /* Enable square wave */ -} - -static inline void backlight_hw_off(void) -{ - /* While on, backlight is flashing at 32 kHz. If the square wave output - is disabled while the backlight is lit, it will become constantly lit, - (brighter) and slowly fade. This resets the square wave counter and - results in the unlit state */ - unsigned char rtc_0a = rtc_read(0x0a) & ~0x40; - rtc_write(0x0a, rtc_0a); /* Disable square wave */ - rtc_write(0x13, 0xF0); /* 1 Hz square wave */ - rtc_write(0x0a, rtc_0a | 0x40); /* Enable square wave */ - - /* When the square wave output is disabled in the unlit state, - the backlight stays off */ - rtc_write(0x0a, rtc_0a); -} - -#endif diff --git a/firmware/target/sh/archos/fm_v2/button-fm_v2.c b/firmware/target/sh/archos/fm_v2/button-fm_v2.c deleted file mode 100644 index 458917d2d5..0000000000 --- a/firmware/target/sh/archos/fm_v2/button-fm_v2.c +++ /dev/null @@ -1,99 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Jens Arnold - * - * 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 "system.h" -#include "button.h" -#include "backlight.h" -#include "adc.h" - -/* - Recorder FM/V2 hardware button hookup - ===================================== - - F1, F2, F3, UP: connected to AN4 through a resistor network - DOWN, PLAY, LEFT, RIGHT: likewise connected to AN5 - - The voltage on AN4/ AN5 depends on which keys (or key combo) is pressed - FM/V2 has PLAY and RIGHT switched compared to plain recorder - - ON: AN3, low active - OFF: AN2, high active -*/ - -void button_init_device(void) -{ - /* Set PB4 and PB8 as input pins */ - PBCR1 &= 0xfffc; /* PB8MD = 00 */ - PBCR2 &= 0xfcff; /* PB4MD = 00 */ - PBIOR &= ~0x0110; /* Inputs */ -} - -int button_read_device(void) -{ - int btn = BUTTON_NONE; - int data; - - /* check F1..F3 and UP */ - data = adc_read(ADC_BUTTON_ROW1); - if (data >= 150) - { - if (data >= 545) - if (data >= 700) - btn = BUTTON_F3; - else - btn = BUTTON_UP; - else - if (data >= 385) - btn = BUTTON_F2; - else - btn = BUTTON_F1; - } - - /* Some units have mushy keypads, so pressing UP also activates - the Left/Right buttons. Let's combat that by skipping the AN5 - checks when UP is pressed. */ - if(!(btn & BUTTON_UP)) - { - /* check DOWN, PLAY, LEFT, RIGHT */ - data = adc_read(ADC_BUTTON_ROW2); - if (data >= 150) - { - if (data >= 545) - if (data >= 700) - btn |= BUTTON_DOWN; - else - btn |= BUTTON_RIGHT; - else - if (data >= 385) - btn |= BUTTON_LEFT; - else - btn |= BUTTON_PLAY; - } - } - - if ( adc_read(ADC_BUTTON_ON) < 512 ) - btn |= BUTTON_ON; - if ( adc_read(ADC_BUTTON_OFF) > 512 ) - btn |= BUTTON_OFF; - - return btn; -} diff --git a/firmware/target/sh/archos/fm_v2/button-target.h b/firmware/target/sh/archos/fm_v2/button-target.h deleted file mode 100644 index 47eb48c32d..0000000000 --- a/firmware/target/sh/archos/fm_v2/button-target.h +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Jens Arnold - * - * 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_ - - /* Main unit's buttons */ -#define BUTTON_ON 0x00000001 -#define BUTTON_OFF 0x00000002 - -#define BUTTON_LEFT 0x00000004 -#define BUTTON_RIGHT 0x00000008 -#define BUTTON_UP 0x00000010 -#define BUTTON_DOWN 0x00000020 - -#define BUTTON_PLAY 0x00000040 - -#define BUTTON_F1 0x00000080 -#define BUTTON_F2 0x00000100 -#define BUTTON_F3 0x00000200 - -#define BUTTON_MAIN (BUTTON_ON|BUTTON_OFF|BUTTON_LEFT|BUTTON_RIGHT\ - |BUTTON_UP|BUTTON_DOWN|BUTTON_PLAY\ - |BUTTON_F1|BUTTON_F2|BUTTON_F3) - -#define POWEROFF_BUTTON BUTTON_OFF -#define POWEROFF_COUNT 10 - -#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/sh/archos/fm_v2/power-fm_v2.c b/firmware/target/sh/archos/fm_v2/power-fm_v2.c deleted file mode 100644 index ce1ef19970..0000000000 --- a/firmware/target/sh/archos/fm_v2/power-fm_v2.c +++ /dev/null @@ -1,115 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 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. - * - ****************************************************************************/ -#include "config.h" -#include "cpu.h" -#include <stdbool.h> -#include "adc.h" -#include "kernel.h" -#include "system.h" -#include "power.h" -#include "usb.h" - -#if CONFIG_TUNER -bool tuner_power(bool status) -{ - (void)status; - return true; -} - -#endif /* #if CONFIG_TUNER */ - -void power_init(void) -{ - PBCR2 &= ~0x0c00; /* GPIO for PB5 */ - or_b(0x20, &PBIORL); - or_b(0x20, &PBDRL); /* hold power */ -} - -unsigned int power_input_status(void) -{ - unsigned int status = POWER_INPUT_NONE; - - /* FM or V2 can also charge from the USB port */ - if (adc_read(ADC_CHARGE_REGULATOR) < 0x1FF) - status = POWER_INPUT_MAIN_CHARGER; - -#ifdef HAVE_USB_POWER - if (usb_detect() == USB_INSERTED) - status |= POWER_INPUT_USB_CHARGER; -#endif - - return status; -} - -/* Returns true if the unit is charging the batteries. */ -bool charging_state(void) -{ - /* We use the information from the ADC_EXT_POWER ADC channel, which - tells us the charging current from the LTC1734. When DC is - connected (either via the external adapter, or via USB), we try - to determine if it is actively charging or only maintaining the - charge. My tests show that ADC readings below about 0x80 means - that the LTC1734 is only maintaining the charge. */ - return adc_read(ADC_EXT_POWER) >= 0x80; -} - -void ide_power_enable(bool on) -{ - bool touched = false; - - if(on) - { - or_b(0x20, &PADRL); - touched = true; - } -#ifdef HAVE_ATA_POWER_OFF - if(!on) - { - and_b(~0x20, &PADRL); - touched = true; - } -#endif /* HAVE_ATA_POWER_OFF */ - -/* late port preparation, else problems with read/modify/write - of other bits on same port, while input and floating high */ - if (touched) - { - or_b(0x20, &PAIORL); /* PA5 is an output */ - PACR2 &= 0xFBFF; /* GPIO for PA5 */ - } -} - - -bool ide_powered(void) -{ - if ((PACR2 & 0x0400) || !(PAIORL & 0x20)) /* not configured for output */ - return true; /* would be floating high, disk on */ - else - return (PADRL & 0x20) != 0; -} - -void power_off(void) -{ - disable_irq(); - and_b(~0x20, &PBDRL); - or_b(0x20, &PBIORL); - while(1); -} diff --git a/firmware/target/sh/archos/fm_v2/powermgmt-fm_v2.c b/firmware/target/sh/archos/fm_v2/powermgmt-fm_v2.c deleted file mode 100644 index 5dd7f26d2f..0000000000 --- a/firmware/target/sh/archos/fm_v2/powermgmt-fm_v2.c +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese - * Revisions copyright (C) 2005 by Gerald Van Baren - * - * 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 "adc.h" -#include "powermgmt.h" - -const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = -{ - 2800 -}; - -const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = -{ - 2580 -}; - -/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ -const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = -{ - /* measured values */ - { 2600, 2850, 2950, 3030, 3110, 3200, 3300, 3450, 3600, 3800, 4000 } -}; - -/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ -const unsigned short percent_to_volt_charge[11] = -{ - /* TODO: This is identical to the discharge curve. - * Calibrate charging curve using a battery_bench log. */ - 2600, 2850, 2950, 3030, 3110, 3200, 3300, 3450, 3600, 3800, 4000 -}; - -/* Battery scale factor (guessed, seems to be 1,25 * value from recorder) */ -#define BATTERY_SCALE_FACTOR 8275 -/* full-scale ADC readout (2^10) in millivolt */ - -/* Returns battery voltage from ADC [millivolts] */ -int _battery_voltage(void) -{ - return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10; -} diff --git a/firmware/target/sh/archos/fm_v2/usb-fm_v2.c b/firmware/target/sh/archos/fm_v2/usb-fm_v2.c deleted file mode 100644 index 5b11d778b6..0000000000 --- a/firmware/target/sh/archos/fm_v2/usb-fm_v2.c +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2007 by Jens Arnold - * - * 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 <stdbool.h> -#include "adc.h" -#include "cpu.h" -#include "hwcompat.h" -#include "system.h" -#include "usb.h" - -int usb_detect(void) -{ - return (adc_read(ADC_USB_POWER) <= 512) ? USB_INSERTED : USB_EXTRACTED; -} - -void usb_enable(bool on) -{ - if(HW_MASK & USB_ACTIVE_HIGH) - on = !on; - - if(on) - and_b(~0x04, &PADRH); /* enable USB */ - else - or_b(0x04, &PADRH); -} - -void usb_init_device(void) -{ - usb_enable(false); - or_b(0x04, &PAIORH); -} diff --git a/firmware/target/sh/archos/i2c-archos.c b/firmware/target/sh/archos/i2c-archos.c deleted file mode 100644 index 5b415926f2..0000000000 --- a/firmware/target/sh/archos/i2c-archos.c +++ /dev/null @@ -1,254 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 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. - * - ****************************************************************************/ -#include "lcd.h" -#include "cpu.h" -#include "kernel.h" -#include "thread.h" -#include "debug.h" -#include "system.h" -#include "i2c.h" - -/* cute little functions, atomic read-modify-write */ - -/* SDA is PB7 */ -#define SDA_LO and_b(~0x80, &PBDRL) -#define SDA_HI or_b(0x80, &PBDRL) -#define SDA_INPUT and_b(~0x80, &PBIORL) -#define SDA_OUTPUT or_b(0x80, &PBIORL) -#define SDA (PBDRL & 0x80) - -#if CONFIG_I2C == I2C_ONDIO -/* Ondio pinout, SCL moved to PB6 */ -#define SCL_INPUT and_b(~0x40, &PBIORL) -#define SCL_OUTPUT or_b(0x40, &PBIORL) -#define SCL_LO and_b(~0x40, &PBDRL) -#define SCL_HI or_b(0x40, &PBDRL) -#define SCL (PBDRL & 0x40) -#else -/* "classic" pinout, SCL is PB13 */ -#define SCL_INPUT and_b(~0x20, &PBIORH) -#define SCL_OUTPUT or_b(0x20, &PBIORH) -#define SCL_LO and_b(~0x20, &PBDRH) -#define SCL_HI or_b(0x20, &PBDRH) -#define SCL (PBDRH & 0x20) -#endif - -/* arbitrary delay loop */ -#define DELAY do { int _x; for(_x=0;_x<20;_x++);} while (0) - -static struct mutex i2c_mtx SHAREDBSS_ATTR; - -void i2c_begin(void) -{ - mutex_lock(&i2c_mtx); -} - -void i2c_end(void) -{ - mutex_unlock(&i2c_mtx); -} - -void i2c_start(void) -{ - SDA_OUTPUT; - SDA_HI; - SCL_HI; - SDA_LO; - DELAY; - SCL_LO; -} - -void i2c_stop(void) -{ - SDA_LO; - SCL_HI; - DELAY; - SDA_HI; -} - -void i2c_init(void) -{ - int i; - - mutex_init(&i2c_mtx); - -#if CONFIG_I2C == I2C_ONDIO - /* make PB6 & PB7 general I/O */ - PBCR2 &= ~0xf000; -#else /* not Ondio */ - /* make PB7 & PB13 general I/O */ - PBCR1 &= ~0x0c00; /* PB13 */ - PBCR2 &= ~0xc000; /* PB7 */ -#endif - - SCL_OUTPUT; - SDA_OUTPUT; - SDA_HI; - SCL_LO; - for (i=0;i<3;i++) - i2c_stop(); -} - -void i2c_ack(int bit) -{ - /* Here's the deal. The MAS is slow, and sometimes needs to wait - before it can receive the acknowledge. Therefore it forces the clock - low until it is ready. We need to poll the clock line until it goes - high before we release the ack. */ - - SCL_LO; /* Set the clock low */ - if ( bit ) - { - SDA_HI; - } - else - { - SDA_LO; - } - - SCL_INPUT; /* Set the clock to input */ - while(!SCL) /* and wait for the MAS to release it */ - sleep(0); - - DELAY; - SCL_OUTPUT; - SCL_LO; -} - -int i2c_getack(void) -{ - int ret = 1; - - /* Here's the deal. The MAS is slow, and sometimes needs to wait - before it can send the acknowledge. Therefore it forces the clock - low until it is ready. We need to poll the clock line until it goes - high before we read the ack. */ - -#ifdef HAVE_I2C_LOW_FIRST - SDA_LO; /* First, discharge the data line */ -#endif - SDA_INPUT; /* And set to input */ - SCL_INPUT; /* Set the clock to input */ - while(!SCL) /* and wait for the MAS to release it */ - sleep(0); - - if (SDA) - /* ack failed */ - ret = 0; - - SCL_OUTPUT; - SCL_LO; - SDA_HI; - SDA_OUTPUT; - return ret; -} - -void i2c_outb(unsigned char byte) -{ - int i; - - /* clock out each bit, MSB first */ - for ( i=0x80; i; i>>=1 ) { - if ( i & byte ) - { - SDA_HI; - } - else - { - SDA_LO; - } - SCL_HI; - SCL_LO; - } - - SDA_HI; -} - -unsigned char i2c_inb(int ack) -{ - int i; - unsigned char byte = 0; - - /* clock in each bit, MSB first */ - for ( i=0x80; i; i>>=1 ) { -#ifdef HAVE_I2C_LOW_FIRST - /* Tricky business. Here we discharge the data line by driving it low - and then set it to input to see if it stays low or goes high */ - SDA_LO; /* First, discharge the data line */ -#endif - SDA_INPUT; /* And set to input */ - SCL_HI; - if ( SDA ) - byte |= i; - SCL_LO; - SDA_OUTPUT; - } - - i2c_ack(ack); - - return byte; -} - -int i2c_write(int address, const unsigned char* buf, int count ) -{ - int i,x=0; - - i2c_start(); - i2c_outb(address & 0xfe); - if (i2c_getack()) - { - for (i=0; i<count; i++) - { - i2c_outb(buf[i]); - if (!i2c_getack()) - { - x=-2; - break; - } - } - } - else - { - debugf("i2c_write() - no ack\n"); - x=-1; - } - i2c_stop(); - return x; -} - -#if 0 /* Currently unused, left for reference and future use */ -int i2c_read(int address, unsigned char* buf, int count ) -{ - int i,x=0; - - i2c_start(); - i2c_outb(address | 1); - if (i2c_getack()) { - for (i=0; i<count; i++) { - buf[i] = i2c_inb(0); - } - } - else - x=-1; - i2c_stop(); - return x; -} -#endif diff --git a/firmware/target/sh/archos/lcd-archos-bitmap.c b/firmware/target/sh/archos/lcd-archos-bitmap.c deleted file mode 100644 index f23289053d..0000000000 --- a/firmware/target/sh/archos/lcd-archos-bitmap.c +++ /dev/null @@ -1,224 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Alan Korr - * - * 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" - -/*** definitions ***/ - -#define LCD_SET_LOWER_COLUMN_ADDRESS ((char)0x00) -#define LCD_SET_HIGHER_COLUMN_ADDRESS ((char)0x10) -#define LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO ((char)0x20) -#define LCD_SET_POWER_CONTROL_REGISTER ((char)0x28) -#define LCD_SET_DISPLAY_START_LINE ((char)0x40) -#define LCD_SET_CONTRAST_CONTROL_REGISTER ((char)0x81) -#define LCD_SET_SEGMENT_REMAP ((char)0xA0) -#define LCD_SET_LCD_BIAS ((char)0xA2) -#define LCD_SET_ENTIRE_DISPLAY_OFF ((char)0xA4) -#define LCD_SET_ENTIRE_DISPLAY_ON ((char)0xA5) -#define LCD_SET_NORMAL_DISPLAY ((char)0xA6) -#define LCD_SET_REVERSE_DISPLAY ((char)0xA7) -#define LCD_SET_MULTIPLEX_RATIO ((char)0xA8) -#define LCD_SET_BIAS_TC_OSC ((char)0xA9) -#define LCD_SET_1OVER4_BIAS_RATIO ((char)0xAA) -#define LCD_SET_INDICATOR_OFF ((char)0xAC) -#define LCD_SET_INDICATOR_ON ((char)0xAD) -#define LCD_SET_DISPLAY_OFF ((char)0xAE) -#define LCD_SET_DISPLAY_ON ((char)0xAF) -#define LCD_SET_PAGE_ADDRESS ((char)0xB0) -#define LCD_SET_COM_OUTPUT_SCAN_DIRECTION ((char)0xC0) -#define LCD_SET_TOTAL_FRAME_PHASES ((char)0xD2) -#define LCD_SET_DISPLAY_OFFSET ((char)0xD3) -#define LCD_SET_READ_MODIFY_WRITE_MODE ((char)0xE0) -#define LCD_SOFTWARE_RESET ((char)0xE2) -#define LCD_NOP ((char)0xE3) -#define LCD_SET_END_OF_READ_MODIFY_WRITE_MODE ((char)0xEE) - -/* LCD command codes */ -#define LCD_CNTL_RESET 0xe2 /* Software reset */ -#define LCD_CNTL_POWER 0x2f /* Power control */ -#define LCD_CNTL_CONTRAST 0x81 /* Contrast */ -#define LCD_CNTL_OUTSCAN 0xc8 /* Output scan direction */ -#define LCD_CNTL_SEGREMAP 0xa1 /* Segment remap */ -#define LCD_CNTL_DISPON 0xaf /* Display on */ - -#define LCD_CNTL_PAGE 0xb0 /* Page address */ -#define LCD_CNTL_HIGHCOL 0x10 /* Upper column address */ -#define LCD_CNTL_LOWCOL 0x00 /* Lower column address */ - -/** globals **/ - -static int xoffset; /* needed for flip */ - -/*** hardware configuration ***/ - -int lcd_default_contrast(void) -{ - return (HW_MASK & LCD_CONTRAST_BIAS) ? 31 : 49; -} - -void lcd_set_contrast(int val) -{ - lcd_write_command(LCD_CNTL_CONTRAST); - lcd_write_command(val); -} - -void lcd_set_invert_display(bool yesno) -{ - if (yesno) - lcd_write_command(LCD_SET_REVERSE_DISPLAY); - else - lcd_write_command(LCD_SET_NORMAL_DISPLAY); -} - -/* turn the display upside down (call lcd_update() afterwards) */ -void lcd_set_flip(bool yesno) -{ -#ifdef HAVE_DISPLAY_FLIPPED - if (!yesno) -#else - if (yesno) -#endif - { - lcd_write_command(LCD_SET_SEGMENT_REMAP); - lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION); - xoffset = 132 - LCD_WIDTH; /* 132 colums minus the 112 we have */ - } - else - { - lcd_write_command(LCD_SET_SEGMENT_REMAP | 0x01); - lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION | 0x08); - xoffset = 0; - } -} - -void lcd_init_device(void) -{ - /* Initialize PB0-3 as output pins */ - PBCR2 &= 0xff00; /* MD = 00 */ - PBIOR |= 0x000f; /* IOR = 1 */ - - /* inits like the original firmware */ - lcd_write_command(LCD_SOFTWARE_RESET); - lcd_write_command(LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO + 4); - lcd_write_command(LCD_SET_1OVER4_BIAS_RATIO + 0); /* force 1/4 bias: 0 */ - lcd_write_command(LCD_SET_POWER_CONTROL_REGISTER + 7); - /* power control register: op-amp=1, regulator=1, booster=1 */ - lcd_write_command(LCD_SET_DISPLAY_ON); - lcd_write_command(LCD_SET_NORMAL_DISPLAY); - lcd_set_flip(false); - lcd_write_command(LCD_SET_DISPLAY_START_LINE + 0); - lcd_set_contrast(lcd_default_contrast()); - lcd_write_command(LCD_SET_PAGE_ADDRESS); - lcd_write_command(LCD_SET_LOWER_COLUMN_ADDRESS + 0); - lcd_write_command(LCD_SET_HIGHER_COLUMN_ADDRESS + 0); - - lcd_clear_display(); - lcd_update(); -} - -/*** Update functions ***/ - -/* Performance function that works with an external buffer - note that by and bheight are in 8-pixel units! */ -void lcd_blit_mono(const unsigned char *data, int x, int by, int width, - int bheight, int stride) -{ - /* Copy display bitmap to hardware */ - while (bheight--) - { - lcd_write_command (LCD_CNTL_PAGE | (by++ & 0xf)); - lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset)>>4) & 0xf)); - lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf)); - - lcd_write_data(data, width); - data += stride; - } -} - -/* Helper function for lcd_grey_phase_blit(). */ -void lcd_grey_data(unsigned char *values, unsigned char *phases, int count); - -/* Performance function that works with an external buffer - note that by and bheight are in 8-pixel units! */ -void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases, - int x, int by, int width, int bheight, int stride) -{ - stride <<= 3; /* 8 pixels per block */ - while (bheight--) - { - lcd_write_command (LCD_CNTL_PAGE | (by++ & 0xf)); - lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset)>>4) & 0xf)); - lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf)); - - lcd_grey_data(values, phases, width); - values += stride; - phases += stride; - } -} - - -/* Update the display. - This must be called after all other LCD functions that change the display. */ -void lcd_update(void) -{ - int y; - - /* Copy display bitmap to hardware */ - for (y = 0; y < LCD_FBHEIGHT; y++) - { - lcd_write_command (LCD_CNTL_PAGE | (y & 0xf)); - lcd_write_command (LCD_CNTL_HIGHCOL | ((xoffset >> 4) & 0xf)); - lcd_write_command (LCD_CNTL_LOWCOL | (xoffset & 0xf)); - - lcd_write_data (FBADDR(0, y), LCD_WIDTH); - } -} - -/* Update a fraction of the display. */ -void lcd_update_rect(int x, int y, int width, int height) -{ - int ymax; - - /* The Y coordinates have to work on even 8 pixel rows */ - ymax = (y + height-1) >> 3; - y >>= 3; - - if(x + width > LCD_WIDTH) - width = LCD_WIDTH - x; - if (width <= 0) - return; /* nothing left to do, 0 is harmful to lcd_write_data() */ - if(ymax >= LCD_FBHEIGHT) - ymax = LCD_FBHEIGHT-1; - - /* Copy specified rectange bitmap to hardware */ - for (; y <= ymax; y++) - { - lcd_write_command (LCD_CNTL_PAGE | (y & 0xf)); - lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset) >> 4) & 0xf)); - lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf)); - - lcd_write_data (FBADDR(x,y), width); - } -} diff --git a/firmware/target/sh/archos/lcd-as-archos-bitmap.S b/firmware/target/sh/archos/lcd-as-archos-bitmap.S deleted file mode 100644 index 0396483737..0000000000 --- a/firmware/target/sh/archos/lcd-as-archos-bitmap.S +++ /dev/null @@ -1,354 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2004 by Jens Arnold - * Based on the work of Alan Korr and Jörg Hohensohn - * - * 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" - -#define LCDR (PBDR_ADDR+1) - -#define LCD_SD 1 /* PB0 = 1 --- 0001 */ -#define LCD_SC 2 /* PB1 = 1 --- 0010 */ -#define LCD_DS 4 /* PB2 = 1 --- 0100 */ -#define LCD_CS 8 /* PB3 = 1 --- 1000 */ - -/* - * About /CS,DS,SC,SD - * ------------------ - * - * LCD on JBP and JBR uses a SPI protocol to receive orders (SDA and SCK lines) - * - * - /CS -> Chip Selection line : - * 0 : LCD chipset is activated. - * - DS -> Data Selection line, latched at the rising edge - * of the 8th serial clock (*) : - * 0 : instruction register, - * 1 : data register; - * - SC -> Serial Clock line (SDA). - * - SD -> Serial Data line (SCK), latched at the rising edge - * of each serial clock (*). - * - * _ _ - * /CS \ / - * \______________________________________________________/ - * _____ ____ ____ ____ ____ ____ ____ ____ ____ _____ - * SD \/ D7 \/ D6 \/ D5 \/ D4 \/ D3 \/ D2 \/ D1 \/ D0 \/ - * _____/\____/\____/\____/\____/\____/\____/\____/\____/\_____ - * - * _____ _ _ _ _ _ _ _ ________ - * SC \ * \ * \ * \ * \ * \ * \ * \ * - * \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ - * _ _________________________________________________________ - * DS \/ - * _/\_________________________________________________________ - * - */ - - .section .icode,"ax",@progbits - - .align 2 - .global _lcd_write_command - .type _lcd_write_command,@function - -/* Write a command byte to the lcd controller - * - * Arguments: - * r4 - data byte (int) - * - * Register usage: - * r0 - scratch - * r1 - data byte (copied) - * r2 - precalculated port value (CS, DS and SC low, SD high), - * negated (neg)! - * r3 - lcd port address - * r5 - 1 (byte count for reuse of the loop in _lcd_write_data) - */ - -_lcd_write_command: - mov.l .lcdr, r3 /* put lcd data port address in r3 */ - mov r4, r1 /* copy data byte to r1 */ - - /* This code will fail if an interrupt changes the contents of PBDRL. - * If so, we must disable the interrupt here. */ - - mov.b @r3, r0 /* r0 = PBDRL */ - mov #0, r5 /* fake end address - stop after first iteration */ - or #(LCD_SD), r0 /* r0 |= LCD_SD */ - and #(~(LCD_CS|LCD_DS|LCD_SC)), r0 /* r0 &= ~(LCD_CS|LCD_DS|LCD_SC) */ - - bra .single_transfer /* jump into the transfer loop */ - neg r0, r2 /* r2 = 0 - r0 */ - - - .align 2 - .global _lcd_write_data - .type _lcd_write_data,@function - -/* A high performance function to write data to the display, - * one or multiple bytes. - * - * Arguments: - * r4 - data address - * r5 - byte count - * - * Register usage: - * r0 - scratch - * r1 - current data byte - * r2 - precalculated port value (CS and SC low, DS and SD high), - * negated (neg)! - * r3 - lcd port address - */ - -_lcd_write_data: - mov.l .lcdr, r3 /* put lcd data port address in r3 */ - add r4, r5 /* end address */ - - /* This code will fail if an interrupt changes the contents of PBDRL. - * If so, we must disable the interrupt here. If disabling interrupts - * for a long time (~9200 clks = ~830 µs for transferring 112 bytes on - * recorders)is undesirable, the loop has to be rewritten to - * disable/precalculate/transfer/enable for each iteration. However, - * this would significantly decrease performance. */ - - mov.b @r3, r0 /* r0 = PBDRL */ - or #(LCD_DS|LCD_SD), r0 /* r0 |= LCD_DS|LCD_SD */ - and #(~(LCD_CS|LCD_SC)), r0 /* r0 &= ~(LCD_CS|LCD_SC) */ - neg r0, r2 /* r2 = 0 - r0 */ - - /* loop exploits that SD is on bit 0 for recorders and Ondios */ - - .align 2 -.multi_transfer: - mov.b @r4+, r1 /* load data byte from memory */ - nop - -.single_transfer: - shll16 r1 /* shift data to most significant byte */ - shll8 r1 - not r1, r1 /* and invert for use with negc */ - - shll r1 /* shift the MSB into carry */ - negc r2, r0 /* carry to SD, SC low */ - shll r1 /* next shift here for alignment */ - mov.b r0, @r3 /* set data to port */ - or #(LCD_SC), r0 /* rise SC (independent of SD level) */ - mov.b r0, @r3 /* set to port */ - - negc r2, r0 - mov.b r0, @r3 - or #(LCD_SC), r0 - mov.b r0, @r3 - - shll r1 - negc r2, r0 - shll r1 - mov.b r0, @r3 - or #(LCD_SC), r0 - mov.b r0, @r3 - - negc r2, r0 - mov.b r0, @r3 - or #(LCD_SC), r0 - mov.b r0, @r3 - - shll r1 - negc r2, r0 - shll r1 - mov.b r0, @r3 - or #(LCD_SC), r0 - mov.b r0, @r3 - - negc r2, r0 - mov.b r0, @r3 - or #(LCD_SC), r0 - mov.b r0, @r3 - - shll r1 - negc r2, r0 - shll r1 - mov.b r0, @r3 - or #(LCD_SC), r0 - mov.b r0, @r3 - - negc r2, r0 - mov.b r0, @r3 - or #(LCD_SC), r0 - mov.b r0, @r3 - - cmp/hi r4, r5 /* some blocks left? */ - bt .multi_transfer - - or #(LCD_CS|LCD_DS|LCD_SD|LCD_SC), r0 /* restore port */ - rts - mov.b r0, @r3 - - /* This is the place to reenable the interrupts, if we have disabled - * them. See above. */ - -#ifndef BOOTLOADER - .align 2 - .global _lcd_grey_data - .type _lcd_grey_data,@function - -/* A high performance function to write grey phase data to the display, - * one or multiple pixels. - * - * Arguments: - * r4 - pixel value data address - * r5 - pixel phase data address - * r6 - pixel block count - * - * Register usage: - * r0 - scratch / phase signs mask - * r1 - scratch - * r2 - precalculated port value (CS and SC low, DS and SD high), - * negated (neg)! - * r3 - lcd port address - * r4 - current value address - * r5 - current phase address - * r6 - end address - * r7/r8 - current/next block of phases (alternating) - * r9/r10 - current blocks of values - * r11 - 0x00000080 \ - * r12 - 0x00008000 > for phase sign check - * r13 - 0x00800000 / - */ - -_lcd_grey_data: - mov.l r8, @-r15 /* save r8 */ - mov.l r9, @-r15 /* save r9 */ - mov.l r10, @-r15 /* save r10 */ - shll2 r6 /* v */ - mov.l r11, @-r15 /* save r11 */ - shll r6 /* r6 *= 8; (8 pixels per block) */ - mov.l .lcdr, r3 /* put lcd data port address in r3 */ - add r4, r6 /* end address */ - - /* This code will fail if an interrupt changes the contents of PBDRL. - * If so, we must disable the interrupt here. If disabling interrupts - * for a long time is undesirable, the loop has to be rewritten to - * disable/precalculate/transfer/enable for each iteration. However, - * this would significantly decrease performance. */ - - mov.b @r3, r0 /* r0 = PBDRL */ - or #(LCD_DS|LCD_SD), r0 /* r0 |= LCD_DS|LCD_SD */ - mov.l r12, @-r15 /* save r12 */ - and #(~(LCD_CS|LCD_SC)), r0 /* r0 &= ~(LCD_CS|LCD_SC) */ - mov.l r13, @-r15 /* save r13 */ - neg r0, r2 /* r2 = 0 - r0 */ - - /* loop exploits that SD is on bit 0 for recorders and Ondios */ - - mov.w .ptest, r11 - swap.b r11, r12 - mov.l @r5, r7 - swap.w r11, r13 - mov.l .pmask, r0 - -.greyloop: - cmp/pz r7 - mov.l @r4+, r9 - negc r2, r1 - mov.b r1, @r3 - add #(LCD_SC), r1 - mov.b r1, @r3 - - tst r13, r7 - mov.l @r4+, r10 - negc r2, r1 - mov.b r1, @r3 - add #(LCD_SC), r1 - mov.b r1, @r3 - - tst r12, r7 - mov.l @(4,r5), r8 - negc r2, r1 - mov.b r1, @r3 - add #(LCD_SC), r1 - mov.b r1, @r3 - - tst r11, r7 - or r0, r7 - negc r2, r1 - mov.b r1, @r3 - add #(LCD_SC), r1 - mov.b r1, @r3 - - cmp/pz r8 - sub r9, r7 - negc r2, r1 - mov.b r1, @r3 - add #(LCD_SC), r1 - mov.b r1, @r3 - - tst r13, r8 - mov.l r7, @r5 - negc r2, r1 - mov.b r1, @r3 - add #(LCD_SC), r1 - mov.b r1, @r3 - - tst r12, r8 - mov.l @(8,r5), r7 - negc r2, r1 - mov.b r1, @r3 - add #(LCD_SC), r1 - mov.b r1, @r3 - - tst r11, r8 - or r0, r8 - negc r2, r1 - mov.b r1, @r3 - add #(LCD_SC), r1 - mov.b r1, @r3 - - sub r10, r8 - mov.l r8, @(4,r5) - - add #8, r5 - cmp/hi r4, r6 - bt .greyloop - - mov.l @r15+, r13 /* restore r13 */ - mov #(LCD_CS|LCD_DS|LCD_SD|LCD_SC), r0 - mov.l @r15+, r12 /* restore r12 */ - or r0, r1 /* restore port */ - mov.l @r15+, r11 /* restore r11 */ - mov.l @r15+, r10 /* restore r10 */ - mov.l @r15+, r9 /* restore r9 */ - mov.l @r15+, r8 /* restore r8 */ - rts - mov.b r1, @r3 - - /* This is the place to reenable the interrupts, if we have disabled - * them. See above. */ - -.ptest: - .short 0x0080 - - .align 2 -.pmask: - .long 0x80808080 -#endif - - .align 2 -.lcdr: - .long LCDR diff --git a/firmware/target/sh/archos/mascodec-archos.c b/firmware/target/sh/archos/mascodec-archos.c deleted file mode 100644 index faa5c7ef2b..0000000000 --- a/firmware/target/sh/archos/mascodec-archos.c +++ /dev/null @@ -1,491 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 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. - * - ****************************************************************************/ -#include "stdbool.h" -#include "config.h" -#include "sh7034.h" -#include "i2c.h" -#include "debug.h" -#include "mas35xx.h" -#include "kernel.h" -#include "system.h" -#include "hwcompat.h" - -static int mas_devread(unsigned long *dest, int len); - -#if 0 /* Currently unused, left for reference and future use */ -int mas_default_read(unsigned short *buf) -{ - unsigned char *dest = (unsigned char *)buf; - int ret = 0; - - i2c_begin(); - - i2c_start(); - i2c_outb(MAS_DEV_WRITE); - if (i2c_getack()) { - i2c_outb(MAS_DATA_READ); - if (i2c_getack()) { - i2c_start(); - i2c_outb(MAS_DEV_READ); - if (i2c_getack()) { - dest[0] = i2c_inb(0); - dest[1] = i2c_inb(1); - } - else - ret = -3; - } - else - ret = -2; - } - else - ret = -1; - - i2c_stop(); - - i2c_end(); - return ret; -} -#endif - -#if CONFIG_CODEC == MAS3507D -int mas_run(unsigned short address) -{ - int ret = 0; - unsigned char buf[3]; - - i2c_begin(); - - buf[0] = MAS_DATA_WRITE; - buf[1] = address >> 8; - buf[2] = address & 0xff; - - /* send run command */ - if (i2c_write(MAS_DEV_WRITE,buf,3)) - { - ret = -1; - } - - i2c_end(); - return ret; -} -#endif - -/* note: 'len' is number of 32-bit words, not number of bytes! */ -int mas_readmem(int bank, int addr, unsigned long* dest, int len) -{ - int ret = 0; - unsigned char buf[7]; - - i2c_begin(); - - buf[0] = MAS_DATA_WRITE; - buf[1] = bank?MAS_CMD_READ_D1_MEM:MAS_CMD_READ_D0_MEM; - buf[2] = 0x00; - buf[3] = (len & 0xff00) >> 8; - buf[4] = len & 0xff; - buf[5] = (addr & 0xff00) >> 8; - buf[6] = addr & 0xff; - - /* send read command */ - if (i2c_write(MAS_DEV_WRITE,buf,7)) - { - ret = -1; - } - - ret = mas_devread(dest, len); - - i2c_end(); - return ret; -} - -/* note: 'len' is number of 32-bit words, not number of bytes! */ -int mas_writemem(int bank, int addr, const unsigned long* src, int len) -{ - int ret = 0; - int i, j; - unsigned char buf[60]; - const unsigned char* ptr = (const unsigned char*)src; - - i2c_begin(); - - i=0; - buf[i++] = MAS_DATA_WRITE; - buf[i++] = bank?MAS_CMD_WRITE_D1_MEM:MAS_CMD_WRITE_D0_MEM; - buf[i++] = 0x00; - buf[i++] = (len & 0xff00) >> 8; - buf[i++] = len & 0xff; - buf[i++] = (addr & 0xff00) >> 8; - buf[i++] = addr & 0xff; - - j = 0; - while(len--) { -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) - buf[i++] = 0; - buf[i++] = ptr[j+1]; - buf[i++] = ptr[j+2]; - buf[i++] = ptr[j+3]; -#else - buf[i++] = ptr[j+2]; - buf[i++] = ptr[j+3]; - buf[i++] = 0; - buf[i++] = ptr[j+1]; -#endif - j += 4; - } - - /* send write command */ - if (i2c_write(MAS_DEV_WRITE,buf,i)) - { - ret = -1; - } - - i2c_end(); - return ret; -} - -int mas_readreg(int reg) -{ - int ret = 0; - unsigned char buf[16]; - unsigned long value; - - i2c_begin(); - - buf[0] = MAS_DATA_WRITE; - buf[1] = MAS_CMD_READ_REG | (reg >> 4); - buf[2] = (reg & 0x0f) << 4; - - /* send read command */ - if (i2c_write(MAS_DEV_WRITE,buf,3)) - { - ret = -1; - } - else - { - if(mas_devread(&value, 1)) - { - ret = -2; - } - else - { - ret = value; - } - } - - i2c_end(); - return ret; -} - -int mas_writereg(int reg, unsigned int val) -{ - int ret = 0; - unsigned char buf[5]; - - i2c_begin(); - - buf[0] = MAS_DATA_WRITE; - buf[1] = MAS_CMD_WRITE_REG | (reg >> 4); -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) - buf[2] = ((reg & 0x0f) << 4) | (val >> 16 & 0x0f); - buf[3] = (val >> 8) & 0xff; - buf[4] = val & 0xff; -#else - buf[2] = ((reg & 0x0f) << 4) | (val & 0x0f); - buf[3] = (val >> 12) & 0xff; - buf[4] = (val >> 4) & 0xff; -#endif - - /* send write command */ - if (i2c_write(MAS_DEV_WRITE,buf,5)) - { - ret = -1; - } - - i2c_end(); - return ret; -} - -/* note: 'len' is number of 32-bit words, not number of bytes! */ -static int mas_devread(unsigned long *dest, int len) -{ - int ret = 0; - unsigned char* ptr = (unsigned char*)dest; - int i; - - /* handle read-back */ - /* Remember, the MAS values are only 20 bits, so we set - the upper 12 bits to 0 */ - i2c_start(); - i2c_outb(MAS_DEV_WRITE); - if (i2c_getack()) { - i2c_outb(MAS_DATA_READ); - if (i2c_getack()) { - i2c_start(); - i2c_outb(MAS_DEV_READ); - if (i2c_getack()) { - for (i=0;len;i++) { - len--; -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) - i2c_inb(0); /* Dummy read */ - ptr[i*4+0] = 0; - ptr[i*4+1] = i2c_inb(0) & 0x0f; - ptr[i*4+2] = i2c_inb(0); - if(len) - ptr[i*4+3] = i2c_inb(0); - else - ptr[i*4+3] = i2c_inb(1); /* NAK the last byte */ -#else - ptr[i*4+2] = i2c_inb(0); - ptr[i*4+3] = i2c_inb(0); - ptr[i*4+0] = i2c_inb(0); - if(len) - ptr[i*4+1] = i2c_inb(0); - else - ptr[i*4+1] = i2c_inb(1); /* NAK the last byte */ -#endif - } - } - else - ret = -3; - } - else - ret = -2; - } - else - ret = -1; - - i2c_stop(); - - return ret; -} - -void mas_reset(void) -{ - or_b(0x01, &PAIORH); - -#if CONFIG_CODEC == MAS3507D - /* PB5 is "MAS enable". make it GPIO output and high */ - PBCR2 &= ~0x0c00; - or_b(0x20, &PBIORL); - or_b(0x20, &PBDRL); - - and_b(~0x01, &PADRH); - sleep(HZ/100); - or_b(0x01, &PADRH); - sleep(HZ/5); -#elif (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) - if (HW_MASK & ATA_ADDRESS_200) - { - and_b(~0x01, &PADRH); - sleep(HZ/100); - or_b(0x01, &PADRH); - sleep(HZ/5); - } - else - { - /* Older recorder models don't invert the POR signal */ - or_b(0x01, &PADRH); - sleep(HZ/100); - and_b(~0x01, &PADRH); - sleep(HZ/5); - } -#endif -} - -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) -#if 0 /* Currently unused, left for reference and future use */ -int mas_direct_config_read(unsigned char reg) -{ - int ret = 0; - unsigned char tmp[2]; - - i2c_begin(); - - i2c_start(); - i2c_outb(MAS_DEV_WRITE); - if (i2c_getack()) { - i2c_outb(reg); - if (i2c_getack()) { - i2c_start(); - i2c_outb(MAS_DEV_READ); - if (i2c_getack()) { - tmp[0] = i2c_inb(0); - tmp[1] = i2c_inb(1); /* NAK the last byte */ - ret = (tmp[0] << 8) | tmp[1]; - } - else - ret = -3; - } - else - ret = -2; - } - else - ret = -1; - - i2c_stop(); - - i2c_end(); - return ret; -} -#endif - -int mas_direct_config_write(unsigned char reg, unsigned int val) -{ - int ret = 0; - unsigned char buf[3]; - - i2c_begin(); - - buf[0] = reg; - buf[1] = (val >> 8) & 0xff; - buf[2] = val & 0xff; - - /* send write command */ - if (i2c_write(MAS_DEV_WRITE,buf,3)) - { - ret = -1; - } - - i2c_end(); - return ret; -} - -int mas_codec_writereg(int reg, unsigned int val) -{ - int ret = 0; - unsigned char buf[5]; - - i2c_begin(); - - buf[0] = MAS_CODEC_WRITE; - buf[1] = (reg >> 8) & 0xff; - buf[2] = reg & 0xff; - buf[3] = (val >> 8) & 0xff; - buf[4] = val & 0xff; - - /* send write command */ - if (i2c_write(MAS_DEV_WRITE,buf,5)) - { - ret = -1; - } - - i2c_end(); - return ret; -} - -int mas_codec_readreg(int reg) -{ - int ret = 0; - unsigned char buf[16]; - unsigned char tmp[2]; - - i2c_begin(); - - buf[0] = MAS_CODEC_WRITE; - buf[1] = (reg >> 8) & 0xff; - buf[2] = reg & 0xff; - - /* send read command */ - if (i2c_write(MAS_DEV_WRITE,buf,3)) - { - ret = -1; - } - else - { - i2c_start(); - i2c_outb(MAS_DEV_WRITE); - if (i2c_getack()) { - i2c_outb(MAS_CODEC_READ); - if (i2c_getack()) { - i2c_start(); - i2c_outb(MAS_DEV_READ); - if (i2c_getack()) { - tmp[0] = i2c_inb(0); - tmp[1] = i2c_inb(1); /* NAK the last byte */ - ret = (tmp[0] << 8) | tmp[1]; - } - else - ret = -4; - } - else - ret = -3; - } - else - ret = -2; - - i2c_stop(); - } - - i2c_end(); - return ret; -} - -unsigned long mas_readver(void) -{ - int ret = 0; - unsigned char buf[16]; - unsigned long value; - - i2c_begin(); - - buf[0] = MAS_DATA_WRITE; - buf[1] = MAS_CMD_READ_IC_VER; - buf[2] = 0; - - /* send read command */ - if (i2c_write(MAS_DEV_WRITE,buf,3)) - { - ret = -1; - } - else - { - if(mas_devread(&value, 1)) - { - ret = -2; - } - else - { - ret = value; - } - } - - i2c_end(); - return ret; -} - -#endif - -#if CONFIG_TUNER & S1A0903X01 -static int pllfreq; - -void mas_store_pllfreq(int freq) -{ - pllfreq = freq; -} - -int mas_get_pllfreq(void) -{ - return pllfreq; -} -#endif - - - diff --git a/firmware/target/sh/archos/ondio/adc-target.h b/firmware/target/sh/archos/ondio/adc-target.h deleted file mode 100644 index a39ee110f3..0000000000 --- a/firmware/target/sh/archos/ondio/adc-target.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 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. - * - ****************************************************************************/ -#ifndef _ADC_TARGET_H_ -#define _ADC_TARGET_H_ - -#define NUM_ADC_CHANNELS 8 - -#define ADC_MMC_SWITCH 0 /* low values if MMC inserted */ -#define ADC_USB_POWER 1 /* USB, reads 0x000 when USB is inserted */ -#define ADC_BUTTON_OPTION 2 /* the option button, low value if pressed */ -#define ADC_BUTTON_ONOFF 3 /* the on/off button, high value if pressed */ -#define ADC_BUTTON_ROW1 4 /* Used for scanning the keys, different - voltages for different keys */ -#define ADC_USB_ACTIVE 5 /* USB bridge activity */ -#define ADC_UNREG_POWER 7 /* Battery voltage */ - -#define EXT_SCALE_FACTOR 14800 - -#endif /* _ADC_TARGET_H_ */ diff --git a/firmware/target/sh/archos/ondio/ata_mmc.c b/firmware/target/sh/archos/ondio/ata_mmc.c deleted file mode 100644 index f252e1c4ce..0000000000 --- a/firmware/target/sh/archos/ondio/ata_mmc.c +++ /dev/null @@ -1,978 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2004 by Jens Arnold - * - * 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 "ata_mmc.h" -#include "sdmmc.h" -#include "kernel.h" -#include "led.h" -#include "sh7034.h" -#include "system.h" -#include "debug.h" -#include "panic.h" -#include "power.h" -#include "string.h" -#include "hwcompat.h" -#include "adc.h" -#include "bitswap.h" -#include "storage.h" - - -#ifdef HAVE_MULTIDRIVE -#define MMC_NUM_DRIVES 2 -#else -#define MMC_NUM_DRIVES 1 -#endif - -#define BLOCK_SIZE 512 /* fixed */ - -/* Command definitions */ -#define CMD_GO_IDLE_STATE 0x40 /* R1 */ -#define CMD_SEND_OP_COND 0x41 /* R1 */ -#define CMD_SEND_CSD 0x49 /* R1 */ -#define CMD_SEND_CID 0x4a /* R1 */ -#define CMD_STOP_TRANSMISSION 0x4c /* R1 */ -#define CMD_SEND_STATUS 0x4d /* R2 */ -#define CMD_SET_BLOCKLEN 0x50 /* R1 */ -#define CMD_READ_SINGLE_BLOCK 0x51 /* R1 */ -#define CMD_READ_MULTIPLE_BLOCK 0x52 /* R1 */ -#define CMD_WRITE_BLOCK 0x58 /* R1b */ -#define CMD_WRITE_MULTIPLE_BLOCK 0x59 /* R1b */ -#define CMD_READ_OCR 0x7a /* R3 */ - -/* Response formats: - R1 = single byte, msb=0, various error flags - R1b = R1 + busy token(s) - R2 = 2 bytes (1st byte identical to R1), additional flags - R3 = 5 bytes (R1 + OCR register) -*/ - -#define R1_PARAMETER_ERR 0x40 -#define R1_ADDRESS_ERR 0x20 -#define R1_ERASE_SEQ_ERR 0x10 -#define R1_COM_CRC_ERR 0x08 -#define R1_ILLEGAL_CMD 0x04 -#define R1_ERASE_RESET 0x02 -#define R1_IN_IDLE_STATE 0x01 - -#define R2_OUT_OF_RANGE 0x80 -#define R2_ERASE_PARAM 0x40 -#define R2_WP_VIOLATION 0x20 -#define R2_CARD_ECC_FAIL 0x10 -#define R2_CC_ERROR 0x08 -#define R2_ERROR 0x04 -#define R2_ERASE_SKIP 0x02 -#define R2_CARD_LOCKED 0x01 - -/* Data start tokens */ - -#define DT_START_BLOCK 0xfe -#define DT_START_WRITE_MULTIPLE 0xfc -#define DT_STOP_TRAN 0xfd - -/* for compatibility */ -static long last_disk_activity = -1; - -/* private variables */ - -#ifdef CONFIG_STORAGE_MULTI -static int mmc_first_drive = 0; -#else -#define mmc_first_drive 0 -#endif - -static struct mutex mmc_mutex SHAREDBSS_ATTR; - -static bool initialized = false; -static bool new_mmc_circuit; - -static enum { - MMC_UNKNOWN, - MMC_UNTOUCHED, - MMC_TOUCHED -} mmc_status = MMC_UNKNOWN; - -static enum { - SER_POLL_WRITE, - SER_POLL_READ, - SER_DISABLED -} serial_mode; - -static const unsigned char dummy[] = { - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF -}; - -/* 2 buffers used alternatively for writing, including start token, - * dummy CRC and an extra byte to keep word alignment. */ -static unsigned char write_buffer[2][BLOCK_SIZE+4]; -static int current_buffer = 0; -static const unsigned char *send_block_addr = NULL; - -static tCardInfo card_info[2]; -#ifndef HAVE_MULTIDRIVE -static int current_card = 0; -#endif -static bool last_mmc_status = false; -static int countdown = -1; /* for mmc switch debouncing. -1 because the - countdown should not happen if the card - is inserted at boot */ -static bool usb_activity; /* monitoring the USB bridge */ -static long last_usb_activity; - -/* private function declarations */ - -static int select_card(int card_no); -static void deselect_card(void); -static void setup_sci1(int bitrate_register); -static void set_sci1_poll_read(void); -static void write_transfer(const unsigned char *buf, int len) - __attribute__ ((section(".icode"))); -static void read_transfer(unsigned char *buf, int len) - __attribute__ ((section(".icode"))); -static unsigned char poll_byte(long timeout); -static unsigned char poll_busy(long timeout); -static unsigned char send_cmd(int cmd, unsigned long parameter, void *data); -static int receive_cxd(unsigned char *buf); -static int initialize_card(int card_no); -static int receive_block(unsigned char *inbuf, long timeout); -static void send_block_prepare(void); -static int send_block_send(unsigned char start_token, long timeout, - bool prepare_next); -static void mmc_tick(void); - -/* implementation */ - -static void enable_controller(bool on) -{ - PBCR1 &= ~0x0CF0; /* PB13, PB11 and PB10 become GPIO, - * if not modified below */ - if (on) - PBCR1 |= 0x08A0; /* as SCK1, TxD1, RxD1 */ - - and_b(~0x80, &PADRL); /* assert flash reset */ - sleep(HZ/100); - or_b(0x80, &PADRL); /* de-assert flash reset */ - sleep(HZ/100); - card_info[0].initialized = false; - card_info[1].initialized = false; -} - -void mmc_enable_int_flash_clock(bool on) -{ - /* Internal flash clock is enabled by setting PA12 high with the new - * clock circuit, and by setting it low with the old clock circuit */ - if (on ^ new_mmc_circuit) - and_b(~0x10, &PADRH); /* clear clock gate PA12 */ - else - or_b(0x10, &PADRH); /* set clock gate PA12 */ -} - -static int select_card(int card_no) -{ - mutex_lock(&mmc_mutex); - led(true); - last_disk_activity = current_tick; - - mmc_enable_int_flash_clock(card_no == 0); - - if (!card_info[card_no].initialized) - { - setup_sci1(7); /* Initial rate: 375 kbps (need <= 400 per mmc specs) */ - write_transfer(dummy, 10); /* allow the card to synchronize */ - while (!(SSR1 & SCI_TEND)); - } - - if (card_no == 0) /* internal */ - and_b(~0x04, &PADRH); /* assert CS */ - else /* external */ - and_b(~0x02, &PADRH); /* assert CS */ - - if (card_info[card_no].initialized) - { - setup_sci1(card_info[card_no].bitrate_register); - return 0; - } - else - { - return initialize_card(card_no); - } -} - -static void deselect_card(void) -{ - while (!(SSR1 & SCI_TEND)); /* wait for end of transfer */ - or_b(0x06, &PADRH); /* deassert CS (both cards) */ - - led(false); - mutex_unlock(&mmc_mutex); - last_disk_activity = current_tick; -} - -static void setup_sci1(int bitrate_register) -{ - while (!(SSR1 & SCI_TEND)); /* wait for end of transfer */ - - SCR1 = 0; /* disable serial port */ - SMR1 = SYNC_MODE; /* no prescale */ - BRR1 = bitrate_register; - SSR1 = 0; - - SCR1 = SCI_TE; /* enable transmitter */ - serial_mode = SER_POLL_WRITE; -} - -static void set_sci1_poll_read(void) -{ - while (!(SSR1 & SCI_TEND)); /* wait for end of transfer */ - SCR1 = 0; /* disable transmitter (& receiver) */ - SCR1 = (SCI_TE|SCI_RE); /* re-enable transmitter & receiver */ - while (!(SSR1 & SCI_TEND)); /* wait for SCI init completion (!) */ - serial_mode = SER_POLL_READ; - TDR1 = 0xFF; /* send do-nothing while reading */ -} - -static void write_transfer(const unsigned char *buf, int len) -{ - const unsigned char *buf_end = buf + len; - register unsigned char data; - - if (serial_mode != SER_POLL_WRITE) - { - while (!(SSR1 & SCI_TEND)); /* wait for end of transfer */ - SCR1 = 0; /* disable transmitter & receiver */ - SSR1 = 0; /* clear all flags */ - SCR1 = SCI_TE; /* enable transmitter only */ - serial_mode = SER_POLL_WRITE; - } - - while (buf < buf_end) - { - data = fliptable[(signed char)(*buf++)]; /* bitswap */ - while (!(SSR1 & SCI_TDRE)); /* wait for end of transfer */ - TDR1 = data; /* write byte */ - SSR1 = 0; /* start transmitting */ - } -} - -/* don't call this with len == 0 */ -static void read_transfer(unsigned char *buf, int len) -{ - unsigned char *buf_end = buf + len - 1; - register signed char data; - - if (serial_mode != SER_POLL_READ) - set_sci1_poll_read(); - - SSR1 = 0; /* start receiving first byte */ - while (buf < buf_end) - { - while (!(SSR1 & SCI_RDRF)); /* wait for data */ - data = RDR1; /* read byte */ - SSR1 = 0; /* start receiving */ - *buf++ = fliptable[data]; /* bitswap */ - } - while (!(SSR1 & SCI_RDRF)); /* wait for last byte */ - *buf = fliptable[(signed char)(RDR1)]; /* read & bitswap */ -} - -/* returns 0xFF on timeout, timeout is in bytes */ -static unsigned char poll_byte(long timeout) -{ - long i; - unsigned char data = 0; /* stop the compiler complaining */ - - if (serial_mode != SER_POLL_READ) - set_sci1_poll_read(); - - i = 0; - do { - SSR1 = 0; /* start receiving */ - while (!(SSR1 & SCI_RDRF)); /* wait for data */ - data = RDR1; /* read byte */ - } while ((data == 0xFF) && (++i < timeout)); - - return fliptable[(signed char)data]; -} - -/* returns 0 on timeout, timeout is in bytes */ -static unsigned char poll_busy(long timeout) -{ - long i; - unsigned char data, dummy; - - if (serial_mode != SER_POLL_READ) - set_sci1_poll_read(); - - /* get data response */ - SSR1 = 0; /* start receiving */ - while (!(SSR1 & SCI_RDRF)); /* wait for data */ - data = fliptable[(signed char)(RDR1)]; /* read byte */ - - /* wait until the card is ready again */ - i = 0; - do { - SSR1 = 0; /* start receiving */ - while (!(SSR1 & SCI_RDRF)); /* wait for data */ - dummy = RDR1; /* read byte */ - } while ((dummy != 0xFF) && (++i < timeout)); - - return (dummy == 0xFF) ? data : 0; -} - -/* Send MMC command and get response. Returns R1 byte directly. - * Returns further R2 or R3 bytes in *data (can be NULL for other commands) */ -static unsigned char send_cmd(int cmd, unsigned long parameter, void *data) -{ - static struct { - unsigned char cmd; - unsigned long parameter; - const unsigned char crc7; /* fixed, valid for CMD0 only */ - const unsigned char trailer; - } __attribute__((packed)) command = {0x40, 0, 0x95, 0xFF}; - - unsigned char ret; - - command.cmd = cmd; - command.parameter = htobe32(parameter); - - write_transfer((unsigned char *)&command, sizeof(command)); - - ret = poll_byte(20); - - switch (cmd) - { - case CMD_SEND_CSD: /* R1 response, leave open */ - case CMD_SEND_CID: - case CMD_READ_SINGLE_BLOCK: - case CMD_READ_MULTIPLE_BLOCK: - return ret; - - case CMD_SEND_STATUS: /* R2 response, close with dummy */ - read_transfer(data, 1); - break; - - case CMD_READ_OCR: /* R3 response, close with dummy */ - read_transfer(data, 4); - break; - - default: /* R1 response, close with dummy */ - break; /* also catches block writes */ - } - write_transfer(dummy, 1); - return ret; -} - -/* Receive CID/ CSD data (16 bytes) */ -static int receive_cxd(unsigned char *buf) -{ - if (poll_byte(20) != DT_START_BLOCK) - { - write_transfer(dummy, 1); - return -1; /* not start of data */ - } - - read_transfer(buf, 16); - write_transfer(dummy, 3); /* 2 bytes dontcare crc + 1 byte trailer */ - return 0; -} - - -static int initialize_card(int card_no) -{ - int rc, i; - int blk_exp, ts_exp, taac_exp; - tCardInfo *card = &card_info[card_no]; - - static const char mantissa[] = { /* *10 */ - 0, 10, 12, 13, 15, 20, 25, 30, - 35, 40, 45, 50, 55, 60, 70, 80 - }; - static const int exponent[] = { /* use varies */ - 1, 10, 100, 1000, 10000, 100000, 1000000, - 10000000, 100000000, 1000000000 - }; - - if (card_no == 1) - mmc_status = MMC_TOUCHED; - - /* switch to SPI mode */ - if (send_cmd(CMD_GO_IDLE_STATE, 0, NULL) != 0x01) - return -1; /* error or no response */ - - /* initialize card */ - for (i = HZ;;) /* try for 1 second*/ - { - sleep(1); - if (send_cmd(CMD_SEND_OP_COND, 0, NULL) == 0) - break; - if (--i <= 0) - return -2; /* timeout */ - } - - /* get OCR register */ - if (send_cmd(CMD_READ_OCR, 0, &card->ocr)) - return -3; - card->ocr = betoh32(card->ocr); /* no-op on big endian */ - - /* check voltage */ - if (!(card->ocr & 0x00100000)) /* 3.2 .. 3.3 V */ - return -4; - - /* get CSD register */ - if (send_cmd(CMD_SEND_CSD, 0, NULL)) - return -5; - rc = receive_cxd((unsigned char*)card->csd); - if (rc) - return rc * 10 - 5; - - blk_exp = card_extract_bits(card->csd, 83, 4); - if (blk_exp < 9) /* block size < 512 bytes not supported */ - return -6; - - card->numblocks = (card_extract_bits(card->csd, 73, 12) + 1) - << (card_extract_bits(card->csd, 49, 3) + 2 + blk_exp - 9); - card->blocksize = BLOCK_SIZE; - - /* max transmission speed, clock divider */ - ts_exp = card_extract_bits(card->csd, 98, 3); - ts_exp = (ts_exp > 3) ? 3 : ts_exp; - card->speed = mantissa[card_extract_bits(card->csd, 102, 4)] - * exponent[ts_exp + 4]; - card->bitrate_register = (FREQ/4-1) / card->speed; - - /* NSAC, TAAC, read timeout */ - card->nsac = 100 * card_extract_bits(card->csd, 111, 8); - card->taac = mantissa[card_extract_bits(card->csd, 118, 4)]; - taac_exp = card_extract_bits(card->csd, 114, 3); - card->read_timeout = ((FREQ/4) / (card->bitrate_register + 1) - * card->taac / exponent[9 - taac_exp] - + (10 * card->nsac)); - card->read_timeout /= 8; /* clocks -> bytes */ - card->taac = card->taac * exponent[taac_exp] / 10; - - /* r2w_factor, write timeout */ - card->r2w_factor = BIT_N(card_extract_bits(card->csd, 28, 3)); - card->write_timeout = card->read_timeout * card->r2w_factor; - - if (card->r2w_factor > 32) /* Such cards often need extra read delay */ - card->read_timeout *= 4; - - /* switch to full speed */ - setup_sci1(card->bitrate_register); - - /* always use 512 byte blocks */ - if (send_cmd(CMD_SET_BLOCKLEN, BLOCK_SIZE, NULL)) - return -7; - - /* get CID register */ - if (send_cmd(CMD_SEND_CID, 0, NULL)) - return -8; - rc = receive_cxd((unsigned char*)card->cid); - if (rc) - return rc * 10 - 8; - - card->initialized = true; - return 0; -} - -tCardInfo *mmc_card_info(int card_no) -{ - tCardInfo *card = &card_info[card_no]; - - if (!card->initialized && ((card_no == 0) || mmc_detect())) - { - select_card(card_no); - deselect_card(); - } - return card; -} - -/* Receive one block with DMA and bitswap it (chasing bitswap). */ -static int receive_block(unsigned char *inbuf, long timeout) -{ - unsigned long buf_end; - - if (poll_byte(timeout) != DT_START_BLOCK) - { - write_transfer(dummy, 1); - return -1; /* not start of data */ - } - - while (!(SSR1 & SCI_TEND)); /* wait for end of transfer */ - - SCR1 = 0; /* disable serial */ - SSR1 = 0; /* clear all flags */ - - /* setup DMA channel 0 */ - CHCR0 = 0; /* disable */ - SAR0 = RDR1_ADDR; - DAR0 = (unsigned long) inbuf; - DTCR0 = BLOCK_SIZE; - CHCR0 = 0x4601; /* fixed source address, RXI1, enable */ - DMAOR = 0x0001; - SCR1 = (SCI_RE|SCI_RIE); /* kick off DMA */ - - /* DMA receives 2 bytes more than DTCR2, but the last 2 bytes are not - * stored. The first extra byte is available from RDR1 after the DMA ends, - * the second one is lost because of the SCI overrun. However, this - * behaviour conveniently discards the crc. */ - - yield(); /* be nice */ - - /* Bitswap received data, chasing the DMA pointer */ - buf_end = (unsigned long)inbuf + BLOCK_SIZE; - do - { - /* Call bitswap whenever (a multiple of) 8 bytes are - * available (value optimised by experimentation). */ - int swap_now = (DAR0 - (unsigned long)inbuf) & ~0x00000007; - if (swap_now) - { - bitswap(inbuf, swap_now); - inbuf += swap_now; - } - } - while ((unsigned long)inbuf < buf_end); - - while (!(CHCR0 & 0x0002)); /* wait for end of DMA */ - while (!(SSR1 & SCI_ORER)); /* wait for the trailing bytes */ - SCR1 = 0; - serial_mode = SER_DISABLED; - - write_transfer(dummy, 1); /* send trailer */ - last_disk_activity = current_tick; - return 0; -} - -/* Prepare a block for sending by copying it to the next write buffer - * and bitswapping it. */ -static void send_block_prepare(void) -{ - unsigned char *dest; - - current_buffer ^= 1; /* toggle buffer */ - dest = write_buffer[current_buffer] + 2; - - memcpy(dest, send_block_addr, BLOCK_SIZE); - bitswap(dest, BLOCK_SIZE); - - send_block_addr += BLOCK_SIZE; -} - -/* Send one block with DMA from the current write buffer, possibly preparing - * the next block within the next write buffer in the background. */ -static int send_block_send(unsigned char start_token, long timeout, - bool prepare_next) -{ - int rc = 0; - unsigned char *curbuf = write_buffer[current_buffer]; - - curbuf[1] = fliptable[(signed char)start_token]; - *(unsigned short *)(curbuf + BLOCK_SIZE + 2) = 0xFFFF; - - while (!(SSR1 & SCI_TEND)); /* wait for end of transfer */ - - SCR1 = 0; /* disable serial */ - SSR1 = 0; /* clear all flags */ - - /* setup DMA channel 0 */ - CHCR0 = 0; /* disable */ - SAR0 = (unsigned long)(curbuf + 1); - DAR0 = TDR1_ADDR; - DTCR0 = BLOCK_SIZE + 3; /* start token + block + dummy crc */ - CHCR0 = 0x1701; /* fixed dest. address, TXI1, enable */ - DMAOR = 0x0001; - SCR1 = (SCI_TE|SCI_TIE); /* kick off DMA */ - - if (prepare_next) - send_block_prepare(); - yield(); /* be nice */ - - while (!(CHCR0 & 0x0002)); /* wait for end of DMA */ - while (!(SSR1 & SCI_TEND)); /* wait for end of transfer */ - SCR1 = 0; - serial_mode = SER_DISABLED; - - if ((poll_busy(timeout) & 0x1F) != 0x05) /* something went wrong */ - rc = -1; - - write_transfer(dummy, 1); - last_disk_activity = current_tick; - - return rc; -} - -int mmc_read_sectors(IF_MD(int drive,) - unsigned long start, - int incount, - void* inbuf) -{ - int rc = 0; - int lastblock = 0; - unsigned long end_block; - tCardInfo *card; -#ifndef HAVE_MULTIDRIVE - int drive = current_card; -#endif - - card = &card_info[drive]; - rc = select_card(drive); - if (rc) - { - rc = rc * 10 - 1; - goto error; - } - - end_block = start + incount; - if (end_block > card->numblocks) - { - rc = -2; - goto error; - } - - /* Some cards don't like reading the very last block with - * CMD_READ_MULTIPLE_BLOCK, so make sure this block is always - * read with CMD_READ_SINGLE_BLOCK. */ - if (end_block == card->numblocks) - lastblock = 1; - - if (incount > 1) - { - /* MMC4.2: make multiplication conditional */ - if (send_cmd(CMD_READ_MULTIPLE_BLOCK, start * BLOCK_SIZE, NULL)) - { - rc = -3; - goto error; - } - while (--incount >= lastblock) - { - rc = receive_block(inbuf, card->read_timeout); - if (rc) - { - /* If an error occurs during multiple block reading, the - * host still needs to send CMD_STOP_TRANSMISSION */ - send_cmd(CMD_STOP_TRANSMISSION, 0, NULL); - rc = rc * 10 - 4; - goto error; - } - inbuf += BLOCK_SIZE; - start++; - /* ^^ necessary for the abovementioned last block special case */ - } - if (send_cmd(CMD_STOP_TRANSMISSION, 0, NULL)) - { - rc = -5; - goto error; - } - } - if (incount > 0) - { - /* MMC4.2: make multiplication conditional */ - if (send_cmd(CMD_READ_SINGLE_BLOCK, start * BLOCK_SIZE, NULL)) - { - rc = -6; - goto error; - } - rc = receive_block(inbuf, card->read_timeout); - if (rc) - { - rc = rc * 10 - 7; - goto error; - } - } - - error: - - deselect_card(); - - return rc; -} - -int mmc_write_sectors(IF_MD(int drive,) - unsigned long start, - int count, - const void* buf) -{ - int rc = 0; - int write_cmd; - unsigned char start_token; - tCardInfo *card; -#ifndef HAVE_MULTIDRIVE - int drive = current_card; -#endif - - card = &card_info[drive]; - rc = select_card(drive); - if (rc) - { - rc = rc * 10 - 1; - goto error; - } - - if (start + count > card->numblocks) - panicf("Writing past end of card"); - - send_block_addr = buf; - send_block_prepare(); - - if (count > 1) - { - write_cmd = CMD_WRITE_MULTIPLE_BLOCK; - start_token = DT_START_WRITE_MULTIPLE; - } - else - { - write_cmd = CMD_WRITE_BLOCK; - start_token = DT_START_BLOCK; - } - /* MMC4.2: make multiplication conditional */ - if (send_cmd(write_cmd, start * BLOCK_SIZE, NULL)) - { - rc = -2; - goto error; - } - while (--count >= 0) - { - rc = send_block_send(start_token, card->write_timeout, count > 0); - if (rc) - { - rc = rc * 10 - 3; - break; - /* If an error occurs during multiple block writing, - * the STOP_TRAN token still needs to be sent. */ - } - } - if (write_cmd == CMD_WRITE_MULTIPLE_BLOCK) - { - static const unsigned char stop_tran = DT_STOP_TRAN; - write_transfer(&stop_tran, 1); - poll_busy(card->write_timeout); - } - - error: - - deselect_card(); - - return rc; -} - -bool mmc_disk_is_active(void) -{ - /* this is correct unless early return from write gets implemented */ - return mutex_test(&mmc_mutex); -} - -bool mmc_detect(void) -{ - return (adc_read(ADC_MMC_SWITCH) < 0x200); -} - -bool mmc_touched(void) -{ - if (mmc_status == MMC_UNKNOWN) /* try to detect */ - { - mutex_lock(&mmc_mutex); - setup_sci1(7); /* safe value */ - and_b(~0x02, &PADRH); /* assert CS */ - if (send_cmd(CMD_SEND_OP_COND, 0, NULL) == 0xFF) - mmc_status = MMC_UNTOUCHED; - else - mmc_status = MMC_TOUCHED; - - deselect_card(); - } - return mmc_status == MMC_TOUCHED; -} - -bool mmc_usb_active(int delayticks) -{ - /* reading "inactive" is delayed by user-supplied monoflop value */ - return (usb_activity || - TIME_BEFORE(current_tick, last_usb_activity + delayticks)); -} - -static void mmc_tick(void) -{ - bool current_status; - - if (new_mmc_circuit) - /* USB bridge activity is 0 on idle, ~527 on active */ - current_status = adc_read(ADC_USB_ACTIVE) > 0x100; - else - current_status = adc_read(ADC_USB_ACTIVE) < 0x190; - - if (!current_status && usb_activity) - last_usb_activity = current_tick; - usb_activity = current_status; - - current_status = mmc_detect(); - /* Only report when the status has changed */ - if (current_status != last_mmc_status) - { - last_mmc_status = current_status; - countdown = HZ/3; - } - else - { - /* Count down until it gets negative */ - if (countdown >= 0) - countdown--; - - if (countdown == 0) - { - if (current_status) - { - queue_broadcast(SYS_HOTSWAP_INSERTED, mmc_first_drive + 1); - } - else - { - queue_broadcast(SYS_HOTSWAP_EXTRACTED, mmc_first_drive + 1); - mmc_status = MMC_UNTOUCHED; - card_info[1].initialized = false; - } - } - } -} - -void mmc_enable(bool on) -{ - mutex_lock(&mmc_mutex); - enable_controller(on); - mutex_unlock(&mmc_mutex); -} - -int mmc_init(void) -{ - int rc = 0; - - if (!initialized) - mutex_init(&mmc_mutex); - - mutex_lock(&mmc_mutex); - led(false); - - last_mmc_status = mmc_detect(); -#ifndef HAVE_MULTIDRIVE - /* Use MMC if inserted, internal flash otherwise */ - current_card = last_mmc_status ? 1 : 0; -#endif - - if (!initialized) - { - if (!last_mmc_status) - mmc_status = MMC_UNTOUCHED; - - /* Port setup */ - PACR1 &= ~0x0F3C; /* GPIO function for PA13 (flash busy), PA12 - * (clk gate), PA10 (flash CS), PA9 (MMC CS) */ - PACR2 &= ~0x4000; /* GPIO for PA7 (flash reset) */ - PADR |= 0x0680; /* set all the selects + reset high (=inactive) */ - PAIOR |= 0x1680; /* make outputs for them and the PA12 clock gate */ - - PBCR1 &= ~0x0CF0; /* GPIO function for PB13, PB11 and PB10 */ - PBDR |= 0x2C00; /* SCK1, TxD1 and RxD1 high in GPIO */ - PBIOR |= 0x2000; /* SCK1 output */ - PBIOR &= ~0x0C00; /* TxD1, RxD1 input */ - - IPRE &= 0x0FFF; /* disable SCI1 interrupts for the CPU */ - - new_mmc_circuit = ((HW_MASK & MMC_CLOCK_POLARITY) != 0); - tick_add_task(mmc_tick); - initialized = true; - } - enable_controller(true); - - mutex_unlock(&mmc_mutex); - return rc; -} - -long mmc_last_disk_activity(void) -{ - return last_disk_activity; -} - -#ifdef STORAGE_GET_INFO -void mmc_get_info(IF_MD(int drive,) struct storage_info *info) -{ -#ifndef HAVE_MULTIDRIVE - const int drive=0; -#endif - info->sector_size=card_info[drive].blocksize; - info->num_sectors=card_info[drive].numblocks; - info->vendor="Rockbox"; - if(drive==0) - { - info->product="Internal Storage"; - } - else - { - info->product="MMC Card Slot"; - } - info->revision="0.00"; -} -#endif - -#ifdef HAVE_HOTSWAP -bool mmc_removable(IF_MD_NONVOID(int drive)) -{ -#ifndef HAVE_MULTIDRIVE - const int drive=0; -#endif - return (drive==1); -} - -bool mmc_present(IF_MD_NONVOID(int drive)) -{ -#ifndef HAVE_MULTIDRIVE - const int drive=0; -#endif - if(drive==0) - { - return true; - } - else - { - return mmc_detect(); - } -} -#endif - -void mmc_spin(void) -{ -} - -void mmc_spindown(int seconds) -{ - (void)seconds; -} - -#ifdef CONFIG_STORAGE_MULTI -int mmc_num_drives(int first_drive) -{ - mmc_first_drive = first_drive; - return MMC_NUM_DRIVES; -} -#endif /* CONFIG_STORAGE_MULTI */ - -int mmc_event(long id, intptr_t data) -{ - return storage_event_default_handler(id, data, last_disk_activity, - STORAGE_MMC); -} diff --git a/firmware/target/sh/archos/ondio/backlight-target.h b/firmware/target/sh/archos/ondio/backlight-target.h deleted file mode 100644 index 438c8c926a..0000000000 --- a/firmware/target/sh/archos/ondio/backlight-target.h +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2007 by Jens Arnold - * - * 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 "config.h" -#include "cpu.h" - -#ifdef HAVE_BACKLIGHT -/* A stock Ondio has no backlight, it needs a hardware mod. */ - -static inline bool backlight_hw_init(void) -{ - PACR1 &= ~0x3000; /* Set PA14 (backlight control) to GPIO */ - or_b(0x40, &PADRH); /* drive it high */ - or_b(0x40, &PAIORH); /* ..and output */ - return true; -} - -static inline void backlight_hw_on(void) -{ - or_b(0x40, &PADRH); /* drive it high */ -} - -static inline void backlight_hw_off(void) -{ - and_b(~0x40, &PADRH); /* drive it low */ -} -#endif /* HAVE_BACKLIGHT */ - -#endif diff --git a/firmware/target/sh/archos/ondio/button-ondio.c b/firmware/target/sh/archos/ondio/button-ondio.c deleted file mode 100644 index e3b370bc1f..0000000000 --- a/firmware/target/sh/archos/ondio/button-ondio.c +++ /dev/null @@ -1,71 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Jens Arnold - * - * 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 "system.h" -#include "button.h" -#include "backlight.h" -#include "adc.h" - -/* - Ondio hardware button hookup - ============================ - - LEFT, RIGHT, UP, DOWN: connected to AN4 through a resistor network - - The voltage on AN4 depends on which keys (or key combo) is pressed - - OPTION: AN2, high active (assigned as MENU) - ON/OFF: AN3, low active (assigned as OFF) -*/ - -void button_init_device(void) -{ -} - -int button_read_device(void) -{ - int btn = BUTTON_NONE; - int data; - - /* Check the 4 direction keys */ - data = adc_read(ADC_BUTTON_ROW1); - if (data >= 165) - { - if (data >= 585) - if (data >= 755) - btn = BUTTON_LEFT; - else - btn = BUTTON_RIGHT; - else - if (data >= 415) - btn = BUTTON_UP; - else - btn = BUTTON_DOWN; - } - - if(adc_read(ADC_BUTTON_OPTION) > 0x200) /* active high */ - btn |= BUTTON_MENU; - if(adc_read(ADC_BUTTON_ONOFF) < 0x120) /* active low */ - btn |= BUTTON_OFF; - - return btn; -} diff --git a/firmware/target/sh/archos/ondio/button-target.h b/firmware/target/sh/archos/ondio/button-target.h deleted file mode 100644 index a84be2851a..0000000000 --- a/firmware/target/sh/archos/ondio/button-target.h +++ /dev/null @@ -1,39 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Jens Arnold - * - * 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_ - -#define BUTTON_OFF 0x00000001 -#define BUTTON_MENU 0x00000002 - -#define BUTTON_LEFT 0x00000004 -#define BUTTON_RIGHT 0x00000008 -#define BUTTON_UP 0x00000010 -#define BUTTON_DOWN 0x00000020 - -#define BUTTON_MAIN (BUTTON_OFF|BUTTON_MENU|BUTTON_LEFT|BUTTON_RIGHT\ - |BUTTON_UP|BUTTON_DOWN) - -#define POWEROFF_BUTTON BUTTON_OFF -#define POWEROFF_COUNT 10 - -#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/sh/archos/ondio/fmradio_i2c-ondio.c b/firmware/target/sh/archos/ondio/fmradio_i2c-ondio.c deleted file mode 100644 index b901bd0019..0000000000 --- a/firmware/target/sh/archos/ondio/fmradio_i2c-ondio.c +++ /dev/null @@ -1,202 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * Physical interface of the Philips TEA5767 in Archos Ondio - * - * Copyright (C) 2002 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. - * - ****************************************************************************/ - -#include "config.h" -#include "cpu.h" -#include "kernel.h" -#include "logf.h" -#include "system.h" -#include "fmradio_i2c.h" - -#if (CONFIG_TUNER & TEA5767) - -/* cute little functions, atomic read-modify-write */ -/* SDA is PB4 */ -#define SDA_LO and_b(~0x10, &PBDRL) -#define SDA_HI or_b(0x10, &PBDRL) -#define SDA_INPUT and_b(~0x10, &PBIORL) -#define SDA_OUTPUT or_b(0x10, &PBIORL) -#define SDA (PBDR & 0x0010) - -/* SCL is PB1 */ -#define SCL_INPUT and_b(~0x02, &PBIORL) -#define SCL_OUTPUT or_b(0x02, &PBIORL) -#define SCL_LO and_b(~0x02, &PBDRL) -#define SCL_HI or_b(0x02, &PBDRL) -#define SCL (PBDR & 0x0002) - -/* arbitrary delay loop */ -#define DELAY do { int _x; for(_x=0;_x<20;_x++);} while (0) - -static void fmradio_i2c_start(void) -{ - SDA_OUTPUT; - SDA_HI; - SCL_HI; - SDA_LO; - DELAY; - SCL_LO; -} - -static void fmradio_i2c_stop(void) -{ - SDA_LO; - SCL_HI; - DELAY; - SDA_HI; -} - - -static void fmradio_i2c_ack(bool nack) -{ - /* Here's the deal. The slave is slow, and sometimes needs to wait - before it can receive the acknowledge. Therefore it forces the clock - low until it is ready. We need to poll the clock line until it goes - high before we release the ack. */ - - SCL_LO; /* Set the clock low */ - - if (nack) - SDA_HI; - else - SDA_LO; - - SCL_INPUT; /* Set the clock to input */ - while(!SCL) /* and wait for the slave to release it */ - sleep(0); - - DELAY; - SCL_OUTPUT; - SCL_LO; -} - -static int fmradio_i2c_getack(void) -{ - int ret = 1; - - /* Here's the deal. The slave is slow, and sometimes needs to wait - before it can send the acknowledge. Therefore it forces the clock - low until it is ready. We need to poll the clock line until it goes - high before we read the ack. */ - - SDA_INPUT; /* And set to input */ - SCL_INPUT; /* Set the clock to input */ - while(!SCL) /* and wait for the slave to release it */ - sleep(0); - - if (SDA) - /* ack failed */ - ret = 0; - - SCL_OUTPUT; - SCL_LO; - SDA_HI; - SDA_OUTPUT; - return ret; -} - -static void fmradio_i2c_outb(unsigned char byte) -{ - int i; - - /* clock out each bit, MSB first */ - for ( i=0x80; i; i>>=1 ) { - if ( i & byte ) - { - SDA_HI; - } - else - { - SDA_LO; - } - SCL_HI; - SCL_LO; - } - - SDA_HI; -} - -static unsigned char fmradio_i2c_inb(void) -{ - int i; - unsigned char byte = 0; - - /* clock in each bit, MSB first */ - for ( i=0x80; i; i>>=1 ) { - SDA_INPUT; /* And set to input */ - SCL_HI; - if ( SDA ) - byte |= i; - SCL_LO; - SDA_OUTPUT; - } - - return byte; -} - -int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count) -{ - int i,x=0; - - fmradio_i2c_start(); - fmradio_i2c_outb(address & 0xfe); - if (fmradio_i2c_getack()) - { - for (i=0; i<count; i++) - { - fmradio_i2c_outb(buf[i]); - if (!fmradio_i2c_getack()) - { - x=-2; - break; - } - } - } - else - { - logf("fmradio_i2c_write() - no ack\n"); - x=-1; - } - fmradio_i2c_stop(); - return x; -} - -int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) -{ - int i,x=0; - - fmradio_i2c_start(); - fmradio_i2c_outb(address | 1); - if (fmradio_i2c_getack()) { - for (i=count; i>0; i--) - { - *buf++ = fmradio_i2c_inb(); - fmradio_i2c_ack(i == 1); - } - } - else - x=-1; - fmradio_i2c_stop(); - return x; -} - -#endif diff --git a/firmware/target/sh/archos/ondio/power-ondio.c b/firmware/target/sh/archos/ondio/power-ondio.c deleted file mode 100644 index d7bbc08f4f..0000000000 --- a/firmware/target/sh/archos/ondio/power-ondio.c +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 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. - * - ****************************************************************************/ -#include "config.h" -#include "cpu.h" -#include <stdbool.h> -#include "kernel.h" -#include "system.h" -#include "power.h" -#include "usb.h" -#include "backlight-target.h" - -#if CONFIG_TUNER - -static bool powered = false; - -bool tuner_power(bool status) -{ - bool old_status = powered; - - powered = status; - if (status) - { - and_b(~0x04, &PADRL); /* drive PA2 low for tuner enable */ - sleep(1); /* let the voltage settle */ - } - else - or_b(0x04, &PADRL); /* drive PA2 high for tuner disable */ - return old_status; -} - -#endif /* #if CONFIG_TUNER */ - -void power_init(void) -{ - PBCR2 &= ~0x0c00; /* GPIO for PB5 */ - or_b(0x20, &PBIORL); - or_b(0x20, &PBDRL); /* hold power */ -#ifndef HAVE_BACKLIGHT - /* Disable backlight on backlight-modded Ondios when running - * a standard build (always on otherwise). */ - PACR1 &= ~0x3000; /* Set PA14 (backlight control) to GPIO */ - and_b(~0x40, &PADRH); /* drive it low */ - or_b(0x40, &PAIORH); /* ..and output */ -#endif - PACR2 &= ~0x0030; /* GPIO for PA2 */ - or_b(0x04, &PADRL); /* drive PA2 high for tuner disable */ - or_b(0x04, &PAIORL); /* output for PA2 */ -} - -void power_off(void) -{ - disable_irq(); -#ifdef HAVE_BACKLIGHT - /* Switch off the light on backlight-modded Ondios */ - backlight_hw_off(); -#endif - and_b(~0x20, &PBDRL); - or_b(0x20, &PBIORL); - while(1); -} diff --git a/firmware/target/sh/archos/ondio/powermgmt-ondio.c b/firmware/target/sh/archos/ondio/powermgmt-ondio.c deleted file mode 100644 index dc3cab031f..0000000000 --- a/firmware/target/sh/archos/ondio/powermgmt-ondio.c +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese - * Revisions copyright (C) 2005 by Gerald Van Baren - * - * 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 "adc.h" -#include "powermgmt.h" - -const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = -{ - 3100, 3450 -}; - -const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = -{ - 2700, 2800 -}; - -/* voltages (millivolt) of 0%, 10%, ... 100% */ -const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = -{ - /* measured values */ - { 2800, 3250, 3410, 3530, 3640, 3740, 3850, 3950, 4090, 4270, 4750 }, /* Alkaline */ - { 3100, 3550, 3630, 3690, 3720, 3740, 3760, 3780, 3800, 3860, 4050 } /* NiMH */ -}; - -#define BATTERY_SCALE_FACTOR 4849 /* average from 3 Ondios */ -/* full-scale ADC readout (2^10) in millivolt */ - -/* Returns battery voltage from ADC [millivolts] */ -int _battery_voltage(void) -{ - return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10; -} - diff --git a/firmware/target/sh/archos/ondio/usb-ondio.c b/firmware/target/sh/archos/ondio/usb-ondio.c deleted file mode 100644 index 093ebd3ad8..0000000000 --- a/firmware/target/sh/archos/ondio/usb-ondio.c +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2007 by Jens Arnold - * - * 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 <stdbool.h> -#include "adc.h" -#include "ata_mmc.h" -#include "cpu.h" -#include "hwcompat.h" -#include "system.h" -#include "usb.h" - -int usb_detect(void) -{ - return (adc_read(ADC_USB_POWER) <= 512) ? USB_INSERTED : USB_EXTRACTED; -} - -void usb_enable(bool on) -{ - if (on) - { - mmc_enable_int_flash_clock(!mmc_detect()); - - if (!(HW_MASK & MMC_CLOCK_POLARITY)) - and_b(~0x20, &PBDRH); /* old circuit needs SCK1 = low while on USB */ - or_b(0x20, &PADRL); /* enable USB */ - and_b(~0x08, &PADRL); /* assert card detect */ - } - else - { - if (!(HW_MASK & MMC_CLOCK_POLARITY)) - or_b(0x20, &PBDRH); /* reset SCK1 = high for old circuit */ - and_b(~0x20, &PADRL); /* disable USB */ - or_b(0x08, &PADRL); /* deassert card detect */ - } -} - -void usb_init_device(void) -{ - PACR2 &= ~0x04C0; /* use PA3 (card detect) and PA5 (USB enabled) as GPIO */ - and_b(~0x20, &PADRL); /* disable USB */ - or_b(0x08, &PADRL); /* deassert card detect */ - or_b(0x28, &PAIORL); /* output for USB enable and card detect */ -} diff --git a/firmware/target/sh/archos/player/adc-target.h b/firmware/target/sh/archos/player/adc-target.h deleted file mode 100644 index a26f79de28..0000000000 --- a/firmware/target/sh/archos/player/adc-target.h +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 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. - * - ****************************************************************************/ -#ifndef _ADC_TARGET_H_ -#define _ADC_TARGET_H_ - -#define NUM_ADC_CHANNELS 8 - -#define ADC_BUTTON_LEFT 0 -#define ADC_BUTTON_MENU 1 -#define ADC_BUTTON_RIGHT 2 -#define ADC_BUTTON_PLAY 3 -#define ADC_UNREG_POWER 6 /* Battery voltage with a better scaling */ -#define ADC_EXT_POWER 7 /* The external power voltage, 0v or 2.7v */ - -#define EXT_SCALE_FACTOR 14800 - -#endif /* _ADC_TARGET_H_ */ diff --git a/firmware/target/sh/archos/player/backlight-target.h b/firmware/target/sh/archos/player/backlight-target.h deleted file mode 100644 index b97d21a40f..0000000000 --- a/firmware/target/sh/archos/player/backlight-target.h +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2007 by Jens Arnold - * - * 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 "config.h" -#include "cpu.h" - -static inline bool backlight_hw_init(void) -{ - PACR1 &= ~0x3000; /* Set PA14 (backlight control) to GPIO */ - and_b(~0x40, &PADRH); /* drive and set low */ - or_b(0x40, &PAIORH); /* ..and output */ - return true; -} - -static inline void backlight_hw_on(void) -{ - and_b(~0x40, &PADRH); /* drive and set low */ - or_b(0x40, &PAIORH); -} - -static inline void backlight_hw_off(void) -{ - and_b(~0x40, &PAIORH); /* let it float (up) */ -} - -#endif diff --git a/firmware/target/sh/archos/player/button-player.c b/firmware/target/sh/archos/player/button-player.c deleted file mode 100644 index 3cf634853e..0000000000 --- a/firmware/target/sh/archos/player/button-player.c +++ /dev/null @@ -1,76 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Jens Arnold - * - * 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 "system.h" -#include "button.h" -#include "backlight.h" -#include "adc.h" - -/* - Player hardware button hookup - ============================= - - Player - ------ - LEFT: AN0 - MENU: AN1 - RIGHT: AN2 - PLAY: AN3 - - STOP: PA11 - ON: PA5 - - All buttons are low active -*/ - -void button_init_device(void) -{ - /* set PA5 and PA11 as input pins */ - PACR1 &= 0xff3f; /* PA11MD = 00 */ - PACR2 &= 0xfbff; /* PA5MD = 0 */ - PAIOR &= ~0x0820; /* Inputs */ -} - -int button_read_device(void) -{ - int btn = BUTTON_NONE; - int data; - - /* buttons are active low */ - if (adc_read(ADC_BUTTON_LEFT) < 0x180) - btn = BUTTON_LEFT; - if (adc_read(ADC_BUTTON_MENU) < 0x180) - btn |= BUTTON_MENU; - if (adc_read(ADC_BUTTON_RIGHT) < 0x180) - btn |= BUTTON_RIGHT; - if (adc_read(ADC_BUTTON_PLAY) < 0x180) - btn |= BUTTON_PLAY; - - /* check port A pins for ON and STOP */ - data = PADR; - if ( !(data & 0x0020) ) - btn |= BUTTON_ON; - if ( !(data & 0x0800) ) - btn |= BUTTON_STOP; - - return btn; -} diff --git a/firmware/target/sh/archos/player/button-target.h b/firmware/target/sh/archos/player/button-target.h deleted file mode 100644 index dd85d731be..0000000000 --- a/firmware/target/sh/archos/player/button-target.h +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Jens Arnold - * - * 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_ - -#define HAS_SERIAL_REMOTE - - /* Main unit's buttons */ -#define BUTTON_ON 0x00000001 -#define BUTTON_STOP 0x00000002 - -#define BUTTON_LEFT 0x00000004 -#define BUTTON_RIGHT 0x00000008 -#define BUTTON_PLAY 0x00000010 -#define BUTTON_MENU 0x00000020 - -#define BUTTON_MAIN (BUTTON_ON|BUTTON_STOP|BUTTON_LEFT|BUTTON_RIGHT\ - |BUTTON_PLAY|BUTTON_MENU) - - /* Remote control's buttons */ -#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) - -#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/sh/archos/player/hwcompat-player.c b/firmware/target/sh/archos/player/hwcompat-player.c deleted file mode 100644 index 49a333d708..0000000000 --- a/firmware/target/sh/archos/player/hwcompat-player.c +++ /dev/null @@ -1,28 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 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. - * - ****************************************************************************/ - -#include <stdbool.h> -#include "hwcompat.h" - -bool is_new_player(void) -{ - return (ROM_VERSION > 449) || (ROM_VERSION == 116); -} diff --git a/firmware/target/sh/archos/player/lcd-as-player.S b/firmware/target/sh/archos/player/lcd-as-player.S deleted file mode 100644 index 19f812c1c7..0000000000 --- a/firmware/target/sh/archos/player/lcd-as-player.S +++ /dev/null @@ -1,274 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2004 by Jens Arnold - * Based on the work of Alan Korr and Jörg Hohensohn - * - * 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" - -#define LCDR (PBDR_ADDR+1) - -#define LCD_DS 1 /* PB0 = 1 --- 0001 --- LCD-DS */ -#define LCD_CS 2 /* PB1 = 1 --- 0010 --- /LCD-CS */ -#define LCD_SD 4 /* PB2 = 1 --- 0100 --- LCD-SD */ -#define LCD_SC 8 /* PB3 = 1 --- 1000 --- LCD-SC */ - -/* - * About /CS,DS,SC,SD - * ------------------ - * - * LCD on JBP and JBR uses a SPI protocol to receive orders (SDA and SCK lines) - * - * - /CS -> Chip Selection line : - * 0 : LCD chipset is activated. - * - DS -> Data Selection line, latched at the rising edge - * of the 8th serial clock (*) : - * 0 : instruction register, - * 1 : data register; - * - SC -> Serial Clock line (SDA). - * - SD -> Serial Data line (SCK), latched at the rising edge - * of each serial clock (*). - * - * _ _ - * /CS \ / - * \______________________________________________________/ - * _____ ____ ____ ____ ____ ____ ____ ____ ____ _____ - * SD \/ D7 \/ D6 \/ D5 \/ D4 \/ D3 \/ D2 \/ D1 \/ D0 \/ - * _____/\____/\____/\____/\____/\____/\____/\____/\____/\_____ - * - * _____ _ _ _ _ _ _ _ ________ - * SC \ * \ * \ * \ * \ * \ * \ * \ * - * \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ - * _ _________________________________________________________ - * DS \/ - * _/\_________________________________________________________ - * - */ - - .section .icode,"ax",@progbits - - .align 2 - .global _lcd_write_command - .type _lcd_write_command,@function - -/* Write a command byte to the lcd controller - * - * Arguments: - * r4 - command byte (int) - * - * Register usage: - * r0 - scratch - * r1 - command byte (copied) - * r2 - precalculated port value (CS, DS and SC low, SD high) - * r3 - lcd port address - * r5 - 1 (byte count for reuse of the loop in _lcd_write_data) - */ - -_lcd_write_command: - mov.l .lcdr, r3 /* put lcd data port address in r3 */ - mov r4, r1 /* copy data byte to r1 */ - mov #0, r5 /* fake end address - stop after first iteration */ - - /* This code will fail if an interrupt changes the contents of PBDRL. - * If so, we must disable the interrupt here. */ - - mov.b @r3, r0 /* r0 = PBDRL */ - or #(LCD_SD), r0 /* r0 |= LCD_SD */ - and #(~(LCD_CS|LCD_DS|LCD_SC)),r0 /* r0 &= ~(LCD_CS|LCD_DS|LCD_SC) */ - - bra .single_transfer /* jump into the transfer loop */ - mov r0, r2 - - - .align 2 - .global _lcd_write_command_e - .type _lcd_write_command_e,@function - -/* Write a command byte and a data byte to the lcd controller - * - * Arguments: - * r4 - command byte - * r5 - data byte - * - * Register usage: - * r0 - scratch - * r1 - command/data byte (copied) - * r2 - precalculated port value (CS, DS and SC low, SD high) - * r3 - lcd port address - * r5 - fake end address - * r6 - data byte (saved) - * r7 - saved pr - */ - -_lcd_write_command_e: - mov.l .lcdr, r3 /* put lcd data port address in r3 */ - mov r4, r1 /* copy data byte to r1 */ - mov r5, r6 - mov #0, r5 /* fake end address - stop after first iteration */ - - /* This code will fail if an interrupt changes the contents of PBDRL. - * If so, we must disable the interrupt here. */ - - mov.b @r3, r0 /* r0 = PBDRL */ - or #(LCD_SD), r0 /* r0 |= LCD_SD */ - and #(~(LCD_CS|LCD_DS|LCD_SC)),r0 /* r0 &= ~(LCD_CS|LCD_DS|LCD_SC) */ - - sts pr, r7 - bsr .single_transfer /* jump into the transfer loop */ - mov r0, r2 - - lds r7, pr - mov r6, r1 - or #(LCD_DS|LCD_SD), r0 /* r0 |= LCD_DS|LCD_SD */ - and #(~(LCD_CS|LCD_SC)), r0 /* r0 &= ~(LCD_CS|LCD_SC) */ - bra .single_transfer /* jump into the transfer loop */ - mov r0, r2 - - - .align 2 - .global _lcd_write_data - .type _lcd_write_data,@function - - -/* A high performance function to write data to the display, - * one or multiple bytes. - * - * Arguments: - * r4 - data address - * r5 - byte count - * - * Register usage: - * r0 - scratch - * r1 - current data byte - * r2 - precalculated port value (CS and SC low, DS and SD high) - * r3 - lcd port address - * r4 - current address - * r5 - end address - */ - -_lcd_write_data: - mov.l .lcdr, r3 /* put lcd data port address in r3 */ - add r4, r5 /* end address */ - - /* This code will fail if an interrupt changes the contents of PBDRL. - * If so, we must disable the interrupt here. If disabling interrupts - * for a long time (~9200 clks = ~830 µs for transferring 112 bytes on - * recorders)is undesirable, the loop has to be rewritten to - * disable/precalculate/transfer/enable for each iteration. However, - * this would significantly decrease performance. */ - - mov.b @r3, r0 /* r0 = PBDRL */ - or #(LCD_DS|LCD_SD), r0 /* r0 |= LCD_DS|LCD_SD */ - and #(~(LCD_CS|LCD_SC)), r0 /* r0 &= ~(LCD_CS|LCD_SC) */ - mov r0, r2 - - .align 2 -.multi_transfer: - mov.b @r4+, r1 /* load data byte from memory */ - -.single_transfer: - shll16 r1 /* shift data to most significant byte */ - shll8 r1 - - shll r1 /* shift the msb into carry */ - mov r2, r0 /* copy precalculated port value */ - bt 1f /* data bit = 1? */ - and #(~LCD_SD), r0 /* no: r0 &= ~LCD_SD */ -1: - shll r1 /* next shift here for alignment */ - mov.b r0, @r3 /* set data to port */ - or #(LCD_SC), r0 /* rise SC (independent of SD level) */ - mov.b r0, @r3 /* set to port */ - - mov r2, r0 - bt 1f - and #(~LCD_SD), r0 -1: - mov.b r0, @r3 - or #(LCD_SC), r0 - mov.b r0, @r3 - - shll r1 - mov r2, r0 - bt 1f - and #(~LCD_SD), r0 -1: - shll r1 - mov.b r0, @r3 - or #(LCD_SC), r0 - mov.b r0, @r3 - - mov r2, r0 - bt 1f - and #(~LCD_SD), r0 -1: - mov.b r0, @r3 - or #(LCD_SC), r0 - mov.b r0, @r3 - - shll r1 - mov r2, r0 - bt 1f - and #(~LCD_SD), r0 -1: - shll r1 - mov.b r0, @r3 - or #(LCD_SC), r0 - mov.b r0, @r3 - - mov r2, r0 - bt 1f - and #(~LCD_SD), r0 -1: - mov.b r0, @r3 - or #(LCD_SC), r0 - mov.b r0, @r3 - - shll r1 - mov r2, r0 - bt 1f - and #(~LCD_SD), r0 -1: - shll r1 - mov.b r0, @r3 - or #(LCD_SC), r0 - mov.b r0, @r3 - - mov r2, r0 - bt 1f - and #(~LCD_SD), r0 -1: - mov.b r0, @r3 - or #(LCD_SC), r0 - mov.b r0, @r3 - - cmp/hi r4, r5 /* some blocks left? */ - bt .multi_transfer - - or #(LCD_CS|LCD_DS|LCD_SD|LCD_SC),r0 /* restore port */ - rts - mov.b r0, @r3 - - /* This is the place to reenable the interrupts, if we have disabled - * them. See above. */ - - .align 2 -.lcdr: - .long LCDR diff --git a/firmware/target/sh/archos/player/lcd-player.c b/firmware/target/sh/archos/player/lcd-player.c deleted file mode 100644 index 95b0164bf5..0000000000 --- a/firmware/target/sh/archos/player/lcd-player.c +++ /dev/null @@ -1,213 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2007 by Jens Arnold - * Based on the work of Alan Korr, Kjell Ericson and others - * - * 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 <string.h> -#include "config.h" -#include "system.h" -#include "kernel.h" -#include "hwcompat.h" -#include "lcd.h" -#include "lcd-charcell.h" - -#define OLD_LCD_DDRAM ((char)0xB0) /* Display data (characters) */ -#define OLD_LCD_CGRAM ((char)0x80) /* Character generator (patterns) */ -#define OLD_LCD_ICONRAM ((char)0xE0) -#define OLD_LCD_CONTRAST_SET ((char)0xA8) -#define OLD_LCD_NOP ((char)0x00) -#define OLD_LCD_SYSTEM_SET ((char)0x60) -#define OLD_LCD_SET_POWER_SAVE_OSC_CONTROL ((char)0x40) -#define OLD_LCD_SET_POWER_CONTROL ((char)0x50) -#define OLD_LCD_SET_DISPLAY_CONTROL ((char)0x30) - -#define NEW_LCD_DDRAM ((char)0x80) /* Display data (characters) */ -#define NEW_LCD_CGRAM ((char)0xC0) /* Character generator (patterns) */ -#define NEW_LCD_ICONRAM ((char)0x40) -#define NEW_LCD_CONTRAST_SET ((char)0x50) -#define NEW_LCD_NOP ((char)0x00) -#define NEW_LCD_FUNCTION_SET ((char)0x10) -#define NEW_LCD_SET_POWER_SAVE_OSC_CONTROL ((char)0x0c) -#define NEW_LCD_SET_POWER_CONTROL_REG ((char)0x20) -#define NEW_LCD_SET_DISPLAY_CONTROL ((char)0x28) -#define NEW_LCD_SET_DOUBLE_HEIGHT ((char)0x08) - -#define LCD_CURSOR(x,y) ((char)(lcd_ddram+((y)*16+(x)))) -#define LCD_ICON(i) ((char)(lcd_iconram+i)) - -static bool new_lcd; -static char lcd_contrast_set; -static char lcd_ddram; -static char lcd_cgram; -static char lcd_iconram; - -/* hardware configuration */ - -int lcd_default_contrast(void) -{ - return 30; -} - -void lcd_set_contrast(int val) -{ - lcd_write_command_e(lcd_contrast_set, 31 - val); -} - -/* charcell specific */ - -void lcd_double_height(bool on) -{ - if(new_lcd) - lcd_write_command(on ? (NEW_LCD_SET_DOUBLE_HEIGHT|1) - : NEW_LCD_SET_DOUBLE_HEIGHT); -} - -void lcd_icon(int icon, bool enable) -{ - static const struct { - char pos; - char mask; - } icontab[] = { - { 0, 0x02}, { 0, 0x08}, { 0, 0x04}, { 0, 0x10}, /* Battery */ - { 2, 0x04}, /* USB */ - { 3, 0x10}, /* Play */ - { 4, 0x10}, /* Record */ - { 5, 0x02}, /* Pause */ - { 5, 0x10}, /* Audio */ - { 6, 0x02}, /* Repeat */ - { 7, 0x01}, /* 1 */ - { 9, 0x04}, /* Volume */ - { 9, 0x02}, { 9, 0x01}, {10, 0x08}, {10, 0x04}, {10, 0x01}, /* Vol 1-5 */ - {10, 0x10}, /* Param */ - }; - static char icon_mirror[11] = {0}; - - int pos, mask; - - pos = icontab[icon].pos; - mask = icontab[icon].mask; - - if (enable) - icon_mirror[pos] |= mask; - else - icon_mirror[pos] &= ~mask; - - lcd_write_command_e(LCD_ICON(pos), icon_mirror[pos]); -} - -/* device specific init */ -void lcd_init_device(void) -{ - unsigned char data_vector[64]; - - /* LCD init for cold start */ - PBCR2 &= 0xff00; /* Set PB0..PB3 to GPIO */ - or_b(0x0f, &PBDRL); /* ... high */ - or_b(0x0f, &PBIORL); /* ... and output */ - - new_lcd = is_new_player(); - - if (new_lcd) - { - lcd_contrast_set = NEW_LCD_CONTRAST_SET; - lcd_ddram = NEW_LCD_DDRAM; - lcd_cgram = NEW_LCD_CGRAM; - lcd_iconram = NEW_LCD_ICONRAM; - - lcd_write_command(NEW_LCD_FUNCTION_SET|1); /* CGRAM selected */ - lcd_write_command_e(NEW_LCD_CONTRAST_SET, 0x08); - lcd_write_command(NEW_LCD_SET_POWER_SAVE_OSC_CONTROL|2); - /* oscillator on */ - lcd_write_command(NEW_LCD_SET_POWER_CONTROL_REG|7); - /* opamp buffer + voltage booster on */ - - memset(data_vector, 0x20, 64); - lcd_write_command(NEW_LCD_DDRAM); /* Set DDRAM address */ - lcd_write_data(data_vector, 64); /* all spaces */ - - memset(data_vector, 0, 64); - lcd_write_command(NEW_LCD_CGRAM); /* Set CGRAM address */ - lcd_write_data(data_vector, 64); /* zero out */ - lcd_write_command(NEW_LCD_ICONRAM); /* Set ICONRAM address */ - lcd_write_data(data_vector, 16); /* zero out */ - - lcd_write_command(NEW_LCD_SET_DISPLAY_CONTROL|1); /* display on */ - } - else - { - lcd_contrast_set = OLD_LCD_CONTRAST_SET; - lcd_ddram = OLD_LCD_DDRAM; - lcd_cgram = OLD_LCD_CGRAM; - lcd_iconram = OLD_LCD_ICONRAM; - - lcd_write_command(OLD_LCD_NOP); - lcd_write_command(OLD_LCD_SYSTEM_SET|1); /* CGRAM selected */ - lcd_write_command(OLD_LCD_SET_POWER_SAVE_OSC_CONTROL|2); - /* oscillator on */ - lcd_write_command(OLD_LCD_SET_POWER_CONTROL|7); - /* voltage regulator, voltage follower and booster on */ - - memset(data_vector, 0x24, 13); - lcd_write_command(OLD_LCD_DDRAM); /* Set DDRAM address */ - lcd_write_data(data_vector, 13); /* all spaces */ - lcd_write_command(OLD_LCD_DDRAM + 0x10); - lcd_write_data(data_vector, 13); - lcd_write_command(OLD_LCD_DDRAM + 0x20); - lcd_write_data(data_vector, 13); - - memset(data_vector, 0, 32); - lcd_write_command(OLD_LCD_CGRAM); /* Set CGRAM address */ - lcd_write_data(data_vector, 32); /* zero out */ - lcd_write_command(OLD_LCD_ICONRAM); /* Set ICONRAM address */ - lcd_write_data(data_vector, 13); /* zero out */ - lcd_write_command(OLD_LCD_ICONRAM + 0x10); - lcd_write_data(data_vector, 13); - - sleep(HZ/10); - lcd_write_command(OLD_LCD_SET_DISPLAY_CONTROL|1); /* display on */ - } - lcd_set_contrast(lcd_default_contrast()); -} - -/*** Update functions ***/ - -void lcd_update(void) -{ - int y; - - for (y = 0; y < lcd_pattern_count; y++) - { - if (lcd_patterns[y].count > 0) - { - lcd_write_command(lcd_cgram | (y << 3)); - lcd_write_data(lcd_patterns[y].pattern, 7); - } - } - for (y = 0; y < LCD_HEIGHT; y++) - { - lcd_write_command(LCD_CURSOR(0, y)); - lcd_write_data(lcd_charbuffer[y], LCD_WIDTH); - } - if (lcd_cursor.visible) - { - lcd_write_command_e(LCD_CURSOR(lcd_cursor.x, lcd_cursor.y), - lcd_cursor.hw_char); - } -} diff --git a/firmware/target/sh/archos/player/power-player.c b/firmware/target/sh/archos/player/power-player.c deleted file mode 100644 index 33f5959021..0000000000 --- a/firmware/target/sh/archos/player/power-player.c +++ /dev/null @@ -1,84 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 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. - * - ****************************************************************************/ -#include "config.h" -#include "cpu.h" -#include <stdbool.h> -#include "kernel.h" -#include "system.h" -#include "power.h" -#include "usb.h" - -void power_init(void) -{ -} - -unsigned int power_input_status(void) -{ - /* Player */ - return ((PADR & 1) == 0) ? - POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; -} - -void ide_power_enable(bool on) -{ - bool touched = false; - - if(on) - { - or_b(0x10, &PBDRL); - touched = true; - } -#ifdef HAVE_ATA_POWER_OFF - if(!on) - { - and_b(~0x10, &PBDRL); - touched = true; - } -#endif /* HAVE_ATA_POWER_OFF */ - -/* late port preparation, else problems with read/modify/write - of other bits on same port, while input and floating high */ - if (touched) - { - or_b(0x10, &PBIORL); /* PB4 is an output */ - PBCR2 &= ~0x0300; /* GPIO for PB4 */ - } -} - - -bool ide_powered(void) -{ - /* This is not correct for very old players, since these are unable to - * control hd power. However, driving the pin doesn't hurt, because it - * is not connected anywhere */ - if ((PBCR2 & 0x0300) || !(PBIORL & 0x10)) /* not configured for output */ - return false; /* would be floating low, disk off */ - else - return (PBDRL & 0x10) != 0; -} - -void power_off(void) -{ - disable_irq(); - and_b(~0x08, &PADRH); - or_b(0x08, &PAIORH); - while(1); -} diff --git a/firmware/target/sh/archos/player/powermgmt-player.c b/firmware/target/sh/archos/player/powermgmt-player.c deleted file mode 100644 index 8aa03d88a5..0000000000 --- a/firmware/target/sh/archos/player/powermgmt-player.c +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese - * Revisions copyright (C) 2005 by Gerald Van Baren - * - * 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 "adc.h" -#include "powermgmt.h" - -const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = -{ - 4750 -}; - -const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = -{ - 4400 -}; - -/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ -const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = -{ - /* original values were taken directly after charging, but it should show - 100% after turning off the device for some hours, too */ - { 4500, 4810, 4910, 4970, 5030, 5070, 5120, 5140, 5170, 5250, 5400 } - /* orig. values: ...,5280,5600 */ -}; - -/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ -const unsigned short percent_to_volt_charge[11] = -{ - /* values guessed, see - http://www.seattlerobotics.org/encoder/200210/LiIon2.pdf until someone - measures voltages over a charging cycle */ - 4760, 5440, 5510, 5560, 5610, 5640, 5660, 5760, 5820, 5840, 5850 /* NiMH */ -}; - -#define BATTERY_SCALE_FACTOR 6703 -/* full-scale ADC readout (2^10) in millivolt */ - -/* Returns battery voltage from ADC [millivolts] */ -int _battery_voltage(void) -{ - return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10; -} - - diff --git a/firmware/target/sh/archos/player/usb-player.c b/firmware/target/sh/archos/player/usb-player.c deleted file mode 100644 index 76f2a2dcdd..0000000000 --- a/firmware/target/sh/archos/player/usb-player.c +++ /dev/null @@ -1,44 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2007 by Jens Arnold - * - * 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 <stdbool.h> -#include "cpu.h" -#include "system.h" -#include "usb.h" - -int usb_detect(void) -{ - return (PADR & 0x8000) ? USB_EXTRACTED : USB_INSERTED; -} - -void usb_enable(bool on) -{ - if(on) - and_b(~0x04, &PADRH); - else - or_b(0x04, &PADRH); -} - -void usb_init_device(void) -{ - or_b(0x04, &PADRH); - or_b(0x04, &PAIORH); -} diff --git a/firmware/target/sh/archos/recorder/adc-target.h b/firmware/target/sh/archos/recorder/adc-target.h deleted file mode 100644 index 06c48a5021..0000000000 --- a/firmware/target/sh/archos/recorder/adc-target.h +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 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. - * - ****************************************************************************/ -#ifndef _ADC_TARGET_H_ -#define _ADC_TARGET_H_ - -#define NUM_ADC_CHANNELS 8 - -/* normal JBR channel assignment */ -#define ADC_BATTERY 0 /* Battery voltage always reads 0x3FF due to - silly scaling */ -#define ADC_CHARGE_REGULATOR 1 /* Regulator reference voltage, should read - about 0x1c0 when charging, else 0x3FF */ -#define ADC_USB_POWER 2 /* USB, reads 0x3FF when USB is inserted */ -#define ADC_BUTTON_ROW1 4 /* Used for scanning the keys, different - voltages for different keys */ -#define ADC_BUTTON_ROW2 5 /* Used for scanning the keys, different - voltages for different keys */ -#define ADC_UNREG_POWER 6 /* Battery voltage with a better scaling */ -#define ADC_EXT_POWER 7 /* The external power voltage, 0v or 2.7v */ - -#define EXT_SCALE_FACTOR 14800 - -#endif /* _ADC_TARGET_H_ */ diff --git a/firmware/target/sh/archos/recorder/backlight-target.h b/firmware/target/sh/archos/recorder/backlight-target.h deleted file mode 100644 index c3dd395eca..0000000000 --- a/firmware/target/sh/archos/recorder/backlight-target.h +++ /dev/null @@ -1,51 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2007 by Jens Arnold - * - * 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 "config.h" -#include "rtc.h" - -#define backlight_hw_init() true - -static inline void backlight_hw_on(void) -{ - rtc_write(0x13, 0x10); /* 32 kHz square wave */ - rtc_write(0x0a, rtc_read(0x0a) | 0x40); /* Enable square wave */ -} - -static inline void backlight_hw_off(void) -{ - /* While on, backlight is flashing at 32 kHz. If the square wave output - is disabled while the backlight is lit, it will become constantly lit, - (brighter) and slowly fade. This resets the square wave counter and - results in the unlit state */ - unsigned char rtc_0a = rtc_read(0x0a) & ~0x40; - rtc_write(0x0a, rtc_0a); /* Disable square wave */ - rtc_write(0x13, 0xF0); /* 1 Hz square wave */ - rtc_write(0x0a, rtc_0a | 0x40); /* Enable square wave */ - - /* When the square wave output is disabled in the unlit state, - the backlight stays off */ - rtc_write(0x0a, rtc_0a); -} - -#endif diff --git a/firmware/target/sh/archos/recorder/button-recorder.c b/firmware/target/sh/archos/recorder/button-recorder.c deleted file mode 100644 index 5e5e67487d..0000000000 --- a/firmware/target/sh/archos/recorder/button-recorder.c +++ /dev/null @@ -1,110 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Jens Arnold - * - * 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 "system.h" -#include "button.h" -#include "backlight.h" -#include "adc.h" - -/* - Recorder hardware button hookup - =============================== - - F1, F2, F3, UP: connected to AN4 through a resistor network - DOWN, PLAY, LEFT, RIGHT: likewise connected to AN5 - - The voltage on AN4/ AN5 depends on which keys (or key combo) is pressed - - ON: PB8, low active - OFF: PB4, low active -*/ - -void button_init_device(void) -{ - /* Set PB4 and PB8 as input pins */ - PBCR1 &= 0xfffc; /* PB8MD = 00 */ - PBCR2 &= 0xfcff; /* PB4MD = 00 */ - PBIOR &= ~0x0110; /* Inputs */ -} - -int button_read_device(void) -{ - int btn = BUTTON_NONE; - int data; - static int off_button_count = 0; - - /* check F1..F3 and UP */ - data = adc_read(ADC_BUTTON_ROW1); - if (data >= 250) - { - if (data >= 700) - if (data >= 900) - btn = BUTTON_F3; - else - btn = BUTTON_UP; - else - if (data >= 500) - btn = BUTTON_F2; - else - btn = BUTTON_F1; - } - - /* Some units have mushy keypads, so pressing UP also activates - the Left/Right buttons. Let's combat that by skipping the AN5 - checks when UP is pressed. */ - if(!(btn & BUTTON_UP)) - { - /* check DOWN, PLAY, LEFT, RIGHT */ - data = adc_read(ADC_BUTTON_ROW2); - if (data >= 250) - { - if (data >= 700) - if (data >= 900) - btn |= BUTTON_DOWN; - else - btn |= BUTTON_PLAY; - else - if (data >= 500) - btn |= BUTTON_LEFT; - else - btn |= BUTTON_RIGHT; - } - } - - /* check port B pins for ON and OFF */ - data = PBDR; - if ((data & 0x0100) == 0) - btn |= BUTTON_ON; - - if ((data & 0x0010) == 0) - { - /* When the batteries are low, the low-battery shutdown logic causes - * spurious OFF events due to voltage fluctuation on some units. - * Only accept OFF when read several times in sequence. */ - if (++off_button_count > 3) - btn |= BUTTON_OFF; - } - else - off_button_count = 0; - - return btn; -} diff --git a/firmware/target/sh/archos/recorder/button-target.h b/firmware/target/sh/archos/recorder/button-target.h deleted file mode 100644 index f387fafe10..0000000000 --- a/firmware/target/sh/archos/recorder/button-target.h +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Jens Arnold - * - * 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_ - -#define HAS_SERIAL_REMOTE - - /* Main unit's buttons */ -#define BUTTON_ON 0x00000001 -#define BUTTON_OFF 0x00000002 - -#define BUTTON_LEFT 0x00000004 -#define BUTTON_RIGHT 0x00000008 -#define BUTTON_UP 0x00000010 -#define BUTTON_DOWN 0x00000020 - -#define BUTTON_PLAY 0x00000040 - -#define BUTTON_F1 0x00000080 -#define BUTTON_F2 0x00000100 -#define BUTTON_F3 0x00000200 - -#define BUTTON_MAIN (BUTTON_ON|BUTTON_OFF|BUTTON_LEFT|BUTTON_RIGHT\ - |BUTTON_UP|BUTTON_DOWN|BUTTON_PLAY\ - |BUTTON_F1|BUTTON_F2|BUTTON_F3) - - /* Remote control's buttons */ -#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) - -#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/sh/archos/recorder/power-recorder.c b/firmware/target/sh/archos/recorder/power-recorder.c deleted file mode 100644 index 48cfdc1e17..0000000000 --- a/firmware/target/sh/archos/recorder/power-recorder.c +++ /dev/null @@ -1,107 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 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. - * - ****************************************************************************/ -#include "config.h" -#include "cpu.h" -#include <stdbool.h> -#include "adc.h" -#include "kernel.h" -#include "system.h" -#include "power.h" -#include "powermgmt-target.h" -#include "usb.h" - -static bool charger_on; - -void power_init(void) -{ - PBCR2 &= ~0x0c00; /* GPIO for PB5 */ - or_b(0x20, &PBIORL); /* Set charging control bit to output */ - charger_enable(false); /* Default to charger OFF */ -} - -unsigned int power_input_status(void) -{ - /* Recorder */ - return (adc_read(ADC_EXT_POWER) > 0x100) ? - POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; -} - -void charger_enable(bool on) -{ - if(on) - { - and_b(~0x20, &PBDRL); - } - else - { - or_b(0x20, &PBDRL); - } - - charger_on = on; -} - -bool charger_enabled(void) -{ - return charger_on; -} - -void ide_power_enable(bool on) -{ - bool touched = false; - - if(on) - { - or_b(0x20, &PADRL); - touched = true; - } -#ifdef HAVE_ATA_POWER_OFF - if(!on) - { - and_b(~0x20, &PADRL); - touched = true; - } -#endif /* HAVE_ATA_POWER_OFF */ - -/* late port preparation, else problems with read/modify/write - of other bits on same port, while input and floating high */ - if (touched) - { - or_b(0x20, &PAIORL); /* PA5 is an output */ - PACR2 &= 0xFBFF; /* GPIO for PA5 */ - } -} - - -bool ide_powered(void) -{ - if ((PACR2 & 0x0400) || !(PAIORL & 0x20)) /* not configured for output */ - return true; /* would be floating high, disk on */ - else - return (PADRL & 0x20) != 0; -} - -void power_off(void) -{ - disable_irq(); - and_b(~0x10, &PBDRL); - or_b(0x10, &PBIORL); - while(1); -} diff --git a/firmware/target/sh/archos/recorder/powermgmt-recorder.c b/firmware/target/sh/archos/recorder/powermgmt-recorder.c deleted file mode 100644 index ca6067a4cc..0000000000 --- a/firmware/target/sh/archos/recorder/powermgmt-recorder.c +++ /dev/null @@ -1,501 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese - * Revisions copyright (C) 2005 by Gerald Van Baren - * - * 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 "system.h" -#include <stdio.h> -#include "debug.h" -#include "storage.h" -#include "adc.h" -#include "power.h" -#include "powermgmt.h" - -const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = -{ - 4750 -}; - -const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = -{ - 4400 -}; - -/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ -const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = -{ - /* original values were taken directly after charging, but it should show - 100% after turning off the device for some hours, too */ - { 4500, 4810, 4910, 4970, 5030, 5070, 5120, 5140, 5170, 5250, 5400 } - /* orig. values: ...,5280,5600 */ -}; - -/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ -const unsigned short percent_to_volt_charge[11] = -{ - /* values guessed, see - http://www.seattlerobotics.org/encoder/200210/LiIon2.pdf until someone - measures voltages over a charging cycle */ - 4760, 5440, 5510, 5560, 5610, 5640, 5660, 5760, 5820, 5840, 5850 /* NiMH */ -}; - -#define BATTERY_SCALE_FACTOR 6620 -/* full-scale ADC readout (2^10) in millivolt */ - -/* Returns battery voltage from ADC [millivolts] */ -int _battery_voltage(void) -{ - return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10; -} - -void powermgmt_init_target(void) -{ -} - -/** Charger control **/ -#ifdef CHARGING_DEBUG_FILE -#include "file.h" -#define DEBUG_FILE_NAME "/powermgmt.csv" -#define DEBUG_MESSAGE_LEN 133 -static char debug_message[DEBUG_MESSAGE_LEN]; -static int fd = -1; /* write debug information to this file */ -static int wrcount = 0; -#endif /* CHARGING_DEBUG_FILE */ - -/* - * For a complete description of the charging algorithm read - * docs/CHARGING_ALGORITHM. - */ -int long_delta; /* long term delta battery voltage */ -int short_delta; /* short term delta battery voltage */ -static bool disk_activity_last_cycle = false; /* flag set to aid charger time - * calculation */ -char power_message[POWER_MESSAGE_LEN] = ""; /* message that's shown in - debug menu */ - /* percentage at which charging - starts */ -int powermgmt_last_cycle_startstop_min = 0; /* how many minutes ago was the - charging started or - stopped? */ -int powermgmt_last_cycle_level = 0; /* which level had the - batteries at this time? */ -int trickle_sec = 0; /* how many seconds should the - charger be enabled per - minute for trickle - charging? */ -int pid_p = 0; /* PID proportional term */ -int pid_i = 0; /* PID integral term */ - -static unsigned int target_voltage = TRICKLE_VOLTAGE; /* desired topoff/trickle - * voltage level */ -static int charge_max_time_idle = 0; /* max. charging duration, calculated at - * beginning of charging */ -static int charge_max_time_now = 0; /* max. charging duration including - * hdd activity */ -static int minutes_disk_activity = 0; /* count minutes of hdd use during - * charging */ -static int last_disk_activity = CHARGE_END_LONGD + 1; /* last hdd use x mins ago */ - -#ifdef CHARGING_DEBUG_FILE -static void debug_file_close(void) -{ - if (fd >= 0) { - close(fd); - fd = -1; - } -} - -static void debug_file_log(void) -{ - if (usb_inserted()) { - /* It is probably too late to close the file but we can try... */ - debug_file_close(); - } - else if (fd < 0) { - fd = open(DEBUG_FILE_NAME, O_WRONLY | O_APPEND | O_CREAT, 0666); - - if (fd >= 0) { - snprintf(debug_message, DEBUG_MESSAGE_LEN, - "cycle_min, bat_millivolts, bat_percent, chgr_state" - " ,charge_state, pid_p, pid_i, trickle_sec\n"); - write(fd, debug_message, strlen(debug_message)); - wrcount = 99; /* force a flush */ - } - } - else { - snprintf(debug_message, DEBUG_MESSAGE_LEN, - "%d, %d, %d, %d, %d, %d, %d, %d\n", - powermgmt_last_cycle_startstop_min, battery_voltage(), - battery_level(), charger_input_state, charge_state, - pid_p, pid_i, trickle_sec); - write(fd, debug_message, strlen(debug_message)); - wrcount++; - } -} - -static void debug_file_sync(void) -{ - /* - * If we have a lot of pending writes or if the disk is spining, - * fsync the debug log file. - */ - if (wrcount > 10 || (wrcount > 0 && storage_disk_is_active())) { - if (fd >= 0) - fsync(fd); - - wrcount = 0; - } -} -#else /* !CHARGING_DEBUG_FILE */ -#define debug_file_close() -#define debug_file_log() -#define debug_file_sync() -#endif /* CHARGING_DEBUG_FILE */ - -/* - * Do tasks that should be done every step. - */ -static void do_frequent_tasks(void) -{ - if (storage_disk_is_active()) { - /* flag hdd use for charging calculation */ - disk_activity_last_cycle = true; - } - - debug_file_sync(); -} - -/* - * The charger was just plugged in. If the battery level is - * nearly charged, just trickle. If the battery is low, start - * a full charge cycle. If the battery level is in between, - * top-off and then trickle. - */ -static void charger_plugged(void) -{ - int battery_percent = battery_level(); - - pid_p = 0; - pid_i = 0; - powermgmt_last_cycle_level = battery_percent; - powermgmt_last_cycle_startstop_min = 0; - - snprintf(power_message, POWER_MESSAGE_LEN, "Charger plugged in"); - - if (battery_percent > START_TOPOFF_CHG) { - - if (battery_percent >= START_TRICKLE_CHG) { - charge_state = TRICKLE; - target_voltage = TRICKLE_VOLTAGE; - } - else { - charge_state = TOPOFF; - target_voltage = TOPOFF_VOLTAGE; - } - } - else { - /* - * Start the charger full strength - */ - int i = CHARGE_MAX_MIN_1500 * get_battery_capacity() / 1500; - charge_max_time_idle = i * (100 + 35 - battery_percent) / 100; - - if (charge_max_time_idle > i) - charge_max_time_idle = i; - - charge_max_time_now = charge_max_time_idle; - - snprintf(power_message, POWER_MESSAGE_LEN, - "ChgAt %d%% max %dm", battery_percent, - charge_max_time_now); - - /* - * Enable the charger after the max time calc is done, - * because battery_level depends on if the charger is - * on. - */ - DEBUGF("power: charger inserted and battery" - " not full, charging\n"); - trickle_sec = 60; - long_delta = short_delta = 999999; - charge_state = CHARGING; - } -} - -/* - * The charger was just unplugged. - */ -static void charger_unplugged(void) -{ - DEBUGF("power: charger disconnected, disabling\n"); - - charger_enable(false); - powermgmt_last_cycle_level = battery_level(); - powermgmt_last_cycle_startstop_min = 0; - trickle_sec = 0; - pid_p = 0; - pid_i = 0; - charge_state = DISCHARGING; - snprintf(power_message, POWER_MESSAGE_LEN, "Charger: discharge"); -} - -static void charging_step(void) -{ - int i; - - /* alter charge time max length with extra disk use */ - if (disk_activity_last_cycle) { - minutes_disk_activity++; - charge_max_time_now = charge_max_time_idle + - minutes_disk_activity*2 / 5; - disk_activity_last_cycle = false; - last_disk_activity = 0; - } - else { - last_disk_activity++; - } - - /* - * Check the delta voltage over the last X minutes so we can do - * our end-of-charge logic based on the battery level change - * (no longer use minimum time as logic for charge end has 50 - * minutes minimum charge built in). - */ - if (powermgmt_last_cycle_startstop_min > CHARGE_END_SHORTD) { - short_delta = power_history[0] - - power_history[CHARGE_END_SHORTD - 1]; - } - - if (powermgmt_last_cycle_startstop_min > CHARGE_END_LONGD) { - /* - * Scan the history: the points where measurement is taken need to - * be fairly static. Check prior to short delta 'area'. Also only - * check first and last 10 cycles (delta in middle OK). - */ - long_delta = power_history[0] - - power_history[CHARGE_END_LONGD - 1]; - - for (i = CHARGE_END_SHORTD; i < CHARGE_END_SHORTD + 10; i++) - { - if ((power_history[i] - power_history[i+1]) > 50 || - (power_history[i] - power_history[i+1]) < -50) { - long_delta = 777777; - break; - } - } - - for (i = CHARGE_END_LONGD - 11; i < CHARGE_END_LONGD - 1 ; i++) - { - if ((power_history[i] - power_history[i+1]) > 50 || - (power_history[i] - power_history[i+1]) < -50) { - long_delta = 888888; - break; - } - } - } - - snprintf(power_message, POWER_MESSAGE_LEN, - "Chg %dm, max %dm", powermgmt_last_cycle_startstop_min, - charge_max_time_now); - - /* - * End of charge criteria (any qualify): - * 1) Charged a long time - * 2) DeltaV went negative for a short time ( & long delta static) - * 3) DeltaV was negative over a longer period (no disk use only) - * - * Note: short_delta and long_delta are millivolts - */ - if (powermgmt_last_cycle_startstop_min >= charge_max_time_now || - (short_delta <= -50 && long_delta < 50) || - (long_delta < -20 && last_disk_activity > CHARGE_END_LONGD)) { - - int battery_percent = battery_level(); - - if (powermgmt_last_cycle_startstop_min > charge_max_time_now) { - DEBUGF("power: powermgmt_last_cycle_startstop_min > charge_max_time_now, " - "enough!\n"); - /* - * Have charged too long and deltaV detection did not - * work! - */ - snprintf(power_message, POWER_MESSAGE_LEN, - "Chg tmout %d min", charge_max_time_now); - /* - * Switch to trickle charging. We skip the top-off - * since we've effectively done the top-off operation - * already since we charged for the maximum full - * charge time. - */ - powermgmt_last_cycle_level = battery_percent; - powermgmt_last_cycle_startstop_min = 0; - charge_state = TRICKLE; - - /* - * Set trickle charge target to a relative voltage instead - * of an arbitrary value - the fully charged voltage may - * vary according to ambient temp, battery condition etc. - * Trickle target is -0.15v from full voltage acheived. - * Topup target is -0.05v from full voltage. - */ - target_voltage = power_history[0] - 150; - - } - else { - if(short_delta <= -5) { - DEBUGF("power: short-term negative" - " delta, enough!\n"); - snprintf(power_message, POWER_MESSAGE_LEN, - "end negd %d %dmin", short_delta, - powermgmt_last_cycle_startstop_min); - target_voltage = power_history[CHARGE_END_SHORTD - 1] - 50; - } - else { - DEBUGF("power: long-term small " - "positive delta, enough!\n"); - snprintf(power_message, POWER_MESSAGE_LEN, - "end lowd %d %dmin", long_delta, - powermgmt_last_cycle_startstop_min); - target_voltage = power_history[CHARGE_END_LONGD - 1] - 50; - } - - /* - * Switch to top-off charging. - */ - powermgmt_last_cycle_level = battery_percent; - powermgmt_last_cycle_startstop_min = 0; - charge_state = TOPOFF; - } - } -} - -static void topoff_trickle_step(void) -{ - unsigned int millivolts; - - /* - *Time to switch from topoff to trickle? - */ - if (charge_state == TOPOFF && - powermgmt_last_cycle_startstop_min > TOPOFF_MAX_MIN) { - - powermgmt_last_cycle_level = battery_level(); - powermgmt_last_cycle_startstop_min = 0; - charge_state = TRICKLE; - target_voltage = target_voltage - 100; - } - /* - * Adjust trickle charge time (proportional and integral terms). - * Note: I considered setting the level higher if the USB is - * plugged in, but it doesn't appear to be necessary and will - * generate more heat [gvb]. - */ - millivolts = battery_voltage(); - - pid_p = ((signed)target_voltage - (signed)millivolts) / 5; - if (pid_p <= PID_DEADZONE && pid_p >= -PID_DEADZONE) - pid_p = 0; - - if ((unsigned)millivolts < target_voltage) { - if (pid_i < 60) - pid_i++; /* limit so it doesn't "wind up" */ - } - else { - if (pid_i > 0) - pid_i--; /* limit so it doesn't "wind up" */ - } - - trickle_sec = pid_p + pid_i; - - if (trickle_sec > 60) - trickle_sec = 60; - - if (trickle_sec < 0) - trickle_sec = 0; -} - -void charging_algorithm_step(void) -{ - static int pwm_counter = 0; /* PWM total cycle in steps */ - static int pwm_duty = 0; /* PWM duty cycle in steps */ - - switch (charger_input_state) - { - case CHARGER_PLUGGED: - charger_plugged(); - break; - - case CHARGER_UNPLUGGED: - charger_unplugged(); - break; - - case CHARGER: - case NO_CHARGER: - do_frequent_tasks(); - - if (pwm_counter > 0) { - if (pwm_duty > 0 && --pwm_duty <= 0) - charger_enable(false); /* Duty cycle expired */ - - if (--pwm_counter > 0) - return; - - /* PWM cycle is complete */ - powermgmt_last_cycle_startstop_min++; - debug_file_log(); - } - break; - } - - switch (charge_state) - { - case CHARGING: - charging_step(); - break; - - case TOPOFF: - case TRICKLE: - topoff_trickle_step(); - break; - - case DISCHARGING: - default: - break; - } - - /* If 100%, ensure pwm_on never expires and briefly disables the - * charger. */ - pwm_duty = (trickle_sec < 60) ? trickle_sec*2 : 0; - pwm_counter = 60*2; - charger_enable(trickle_sec > 0); -} - -void charging_algorithm_close(void) -{ -#ifdef CHARGING_DEBUG_FILE - debug_file_close(); -#endif /* CHARGING_DEBUG_FILE */ -} - -/* Returns true if the unit is charging the batteries. */ -bool charging_state(void) -{ - return charge_state == CHARGING; -} diff --git a/firmware/target/sh/archos/recorder/powermgmt-target.h b/firmware/target/sh/archos/recorder/powermgmt-target.h deleted file mode 100644 index 6b68d05bd4..0000000000 --- a/firmware/target/sh/archos/recorder/powermgmt-target.h +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese - * Revisions copyright (C) 2005 by Gerald Van Baren - * - * 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 POWERMGMT_TARGET_H -#define POWERMGMT_TARGET_H - -/* - * Define CHARGING_DEBUG_FILE to create a csv (spreadsheet) with battery - * information in it (one sample per minute/connect/disconnect). - * - * This is only for very low level debug. - */ -#undef CHARGING_DEBUG_FILE - - -/* stop when N minutes have passed with avg delta being < -0.05 V */ -#define CHARGE_END_SHORTD 6 -/* stop when N minutes have passed with avg delta being < -0.02 V */ -#define CHARGE_END_LONGD 50 - -/* Battery % to start at top-off */ -#define START_TOPOFF_CHG 85 -/* Battery % to start at trickle */ -#define START_TRICKLE_CHG 95 -/* power thread status message */ -#define POWER_MESSAGE_LEN 32 -/* minutes: maximum charging time for 1500 mAh batteries - * actual max time depends also on BATTERY_CAPACITY! */ -#define CHARGE_MAX_MIN_1500 450 -/* minutes: minimum charging time */ -#define CHARGE_MIN_MIN 10 -/* After charging, go to top off charge. How long should top off charge be? */ -#define TOPOFF_MAX_MIN 90 -/* which voltage is best? (millivolts) */ -#define TOPOFF_VOLTAGE 5650 -/* After top off charge, go to trickle harge. How long should trickle - * charge be? */ -#define TRICKLE_MAX_MIN 720 /* 12 hrs */ -/* which voltage is best? (millivolts) */ -#define TRICKLE_VOLTAGE 5450 -/* initial trickle_sec for topoff */ -#define START_TOPOFF_SEC 25 -/* initial trickle_sec for trickle */ -#define START_TRICKLE_SEC 15 - -#define PID_DEADZONE 4 /* PID proportional deadzone */ - -extern char power_message[POWER_MESSAGE_LEN]; - -extern int long_delta; /* long term delta battery voltage */ -extern int short_delta; /* short term delta battery voltage */ - -extern int powermgmt_last_cycle_startstop_min; /* how many minutes ago was - the charging started or - stopped? */ -extern int powermgmt_last_cycle_level; /* which level had the batteries - at this time? */ - -extern int pid_p; /* PID proportional term */ -extern int pid_i; /* PID integral term */ -extern int trickle_sec; /* how many seconds should the - charger be enabled per - minute for trickle - charging? */ -void charger_enable(bool on); -bool charger_enabled(void); - -/* Battery filter lengths in samples */ -#define BATT_AVE_SAMPLES 32 - -#endif /* POWERMGMT_TARGET_H */ diff --git a/firmware/target/sh/archos/recorder/usb-recorder.c b/firmware/target/sh/archos/recorder/usb-recorder.c deleted file mode 100644 index f8b462b802..0000000000 --- a/firmware/target/sh/archos/recorder/usb-recorder.c +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2007 by Jens Arnold - * - * 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 <stdbool.h> -#include "adc.h" -#include "cpu.h" -#include "hwcompat.h" -#include "system.h" -#include "usb.h" - -int usb_detect(void) -{ - return (adc_read(ADC_USB_POWER) > 500) ? USB_INSERTED : USB_EXTRACTED; -} - -void usb_enable(bool on) -{ - if(HW_MASK & USB_ACTIVE_HIGH) - on = !on; - - if(on) - and_b(~0x04, &PADRH); /* enable USB */ - else - or_b(0x04, &PADRH); -} - -void usb_init_device(void) -{ - usb_enable(false); - or_b(0x04, &PAIORH); -} diff --git a/firmware/target/sh/archos/timer-archos.c b/firmware/target/sh/archos/timer-archos.c deleted file mode 100644 index 98a3afb4b6..0000000000 --- a/firmware/target/sh/archos/timer-archos.c +++ /dev/null @@ -1,84 +0,0 @@ -/*************************************************************************** -* __________ __ ___. -* Open \______ \ ____ ____ | | _\_ |__ _______ ___ -* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / -* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < -* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ -* \/ \/ \/ \/ \/ -* $Id$ -* -* Copyright (C) 2005 Jens Arnold -* -* 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 "cpu.h" -#include "system.h" -#include "timer.h" - -void IMIA4(void) __attribute__((interrupt_handler)); -void IMIA4(void) -{ - if (pfn_timer != NULL) - pfn_timer(); - and_b(~0x01, &TSR4); /* clear the interrupt */ -} - -bool timer_set(long cycles, bool start) -{ - int phi = 0; /* bits for the prescaler */ - int prescale = 1; - - while (cycles > 0x10000) - { /* work out the smallest prescaler that makes it fit */ - phi++; - prescale <<= 1; - cycles >>= 1; - } - - if (prescale > 8) - return false; - - if (start) - { - if (pfn_unregister != NULL) - { - pfn_unregister(); - pfn_unregister = NULL; - } - - and_b(~0x10, &TSTR); /* Stop the timer 4 */ - and_b(~0x10, &TSNC); /* No synchronization */ - and_b(~0x10, &TMDR); /* Operate normally */ - - TIER4 = 0xF9; /* Enable GRA match interrupt */ - } - - TCR4 = 0x20 | phi; /* clear at GRA match, set prescaler */ - GRA4 = (unsigned short)(cycles - 1); - if (start || (TCNT4 >= GRA4)) - TCNT4 = 0; - and_b(~0x01, &TSR4); /* clear an eventual interrupt */ - - return true; -} - -bool timer_start(void) -{ - IPRD = (IPRD & 0xFF0F) | 1 << 4; /* interrupt priority */ - or_b(0x10, &TSTR); /* start timer 4 */ - return true; -} - -void timer_stop(void) -{ - and_b(~0x10, &TSTR); /* stop the timer 4 */ - IPRD = (IPRD & 0xFF0F); /* disable interrupt */ -} diff --git a/firmware/target/sh/archos/uart-archos.c b/firmware/target/sh/archos/uart-archos.c deleted file mode 100644 index d17678f812..0000000000 --- a/firmware/target/sh/archos/uart-archos.c +++ /dev/null @@ -1,167 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Alan Korr & Nick Robinson - * - * 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 <stdio.h> -#include <stdlib.h> -#include <stdarg.h> - -#include "config.h" -#include "button.h" -#include "cpu.h" -#include "system.h" -#include "kernel.h" -#include "serial.h" - -/* FIX: this doesn't work on iRiver or iPod yet */ -/* iFP7xx has no remote */ - -/* Received byte identifiers */ -#define PLAY 0xC1 -#define STOP 0xC2 -#define PREV 0xC4 -#define NEXT 0xC8 -#define VOLUP 0xD0 -#define VOLDN 0xE0 - -void serial_setup (void) -{ - /* Set PB10 function to serial Rx */ - PBCR1 = (PBCR1 & 0xffcf) | 0x0020; - - SMR1 = 0x00; - SCR1 = 0; - BRR1 = (FREQ/(32*9600))-1; - and_b(0, &SSR1); /* The status bits must be read before they are cleared, - so we do an AND operation */ - - /* Let the hardware settle. The serial port needs to wait "at least - the interval required to transmit or receive one bit" before it - can be used. */ - sleep(1); - - SCR1 = 0x10; /* Enable the receiver, no interrupt */ -} - -int tx_rdy(void) -{ - /* a dummy */ - return 1; -} - -static int rx_rdy(void) -{ - if(SSR1 & SCI_RDRF) - return 1; - else - return 0; -} - -void tx_writec(unsigned char c) -{ - /* a dummy */ - (void)c; -} - -static unsigned char rx_readc(void) -{ - char tmp; - /* Read byte and clear the Rx Full bit */ - tmp = RDR1; - and_b(~SCI_RDRF, &SSR1); - return tmp; -} - - -/* This function returns the received remote control code only if it is - received without errors before or after the reception. - It therefore returns the received code on the second call after the - code has been received. */ -int remote_control_rx(void) -{ - static int last_valid_button = BUTTON_NONE; - static int last_was_error = false; - int btn; - int ret = BUTTON_NONE; - - /* Errors? Just clear'em. The receiver stops if we don't */ - if(SSR1 & (SCI_ORER | SCI_FER | SCI_PER)) { - and_b(~(SCI_ORER | SCI_FER | SCI_PER), &SSR1); - last_valid_button = BUTTON_NONE; - last_was_error = true; - return BUTTON_NONE; - } - - if(rx_rdy()) { - btn = rx_readc(); - - if(last_was_error) - { - last_valid_button = BUTTON_NONE; - ret = BUTTON_NONE; - } - else - { - switch (btn) - { - case STOP: - last_valid_button = BUTTON_RC_STOP; - break; - - case PLAY: - last_valid_button = BUTTON_RC_PLAY; - break; - - case VOLUP: - last_valid_button = BUTTON_RC_VOL_UP; - break; - - case VOLDN: - last_valid_button = BUTTON_RC_VOL_DOWN; - break; - - case PREV: - last_valid_button = BUTTON_RC_LEFT; - break; - - case NEXT: - last_valid_button = BUTTON_RC_RIGHT; - break; - - default: - last_valid_button = BUTTON_NONE; - break; - } - } - } - else - { - /* This means that a valid remote control character was received - the last time we were called, with no receiver errors either before - or after. Then we can assume that there really is a remote control - attached, and return the button code. */ - ret = last_valid_button; - last_valid_button = BUTTON_NONE; - } - - last_was_error = false; - - return ret; -} - |