From fad79dc6364e1e0d42216f4636a4fc504a594307 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Wed, 11 Apr 2007 20:44:32 +0000 Subject: Moved archos USB handling to target tree. Minor simplification for coldfire (only one usb-target.h). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13110 a1c6a512-1295-4272-9138-f99709370657 --- firmware/SOURCES | 4 ++ firmware/target/coldfire/iaudio/usb-target.h | 24 ------- firmware/target/coldfire/iriver/usb-target.h | 24 ------- firmware/target/coldfire/usb-target.h | 24 +++++++ firmware/target/sh/archos/fm_v2/usb-fm_v2.c | 46 +++++++++++++ firmware/target/sh/archos/ondio/usb-ondio.c | 58 +++++++++++++++++ firmware/target/sh/archos/player/usb-player.c | 41 ++++++++++++ firmware/target/sh/archos/recorder/usb-recorder.c | 46 +++++++++++++ firmware/target/sh/usb-target.h | 24 +++++++ firmware/usb.c | 78 +---------------------- 10 files changed, 244 insertions(+), 125 deletions(-) delete mode 100644 firmware/target/coldfire/iaudio/usb-target.h delete mode 100644 firmware/target/coldfire/iriver/usb-target.h create mode 100644 firmware/target/coldfire/usb-target.h create mode 100644 firmware/target/sh/archos/fm_v2/usb-fm_v2.c create mode 100644 firmware/target/sh/archos/ondio/usb-ondio.c create mode 100644 firmware/target/sh/archos/player/usb-player.c create mode 100644 firmware/target/sh/archos/recorder/usb-recorder.c create mode 100644 firmware/target/sh/usb-target.h (limited to 'firmware') diff --git a/firmware/SOURCES b/firmware/SOURCES index 9f90919817..a05314160d 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -318,6 +318,7 @@ target/sh/archos/ata-as-archos.S target/sh/archos/player/button-player.c target/sh/archos/player/lcd-as-player.S target/sh/archos/player/lcd-player.c +target/sh/archos/player/usb-player.c #endif /* SIMULATOR */ #endif /* ARCHOS_PLAYER */ @@ -328,6 +329,7 @@ target/sh/archos/ata-as-archos.S target/sh/archos/lcd-archos-bitmap.c target/sh/archos/lcd-as-archos-bitmap.S target/sh/archos/recorder/button-recorder.c +target/sh/archos/recorder/usb-recorder.c #endif /* SIMULATOR */ #endif /* ARCHOS_RECORDER */ @@ -338,6 +340,7 @@ target/sh/archos/ata-as-archos.S target/sh/archos/lcd-archos-bitmap.c target/sh/archos/lcd-as-archos-bitmap.S target/sh/archos/fm_v2/button-fm_v2.c +target/sh/archos/fm_v2/usb-fm_v2.c #endif /* SIMULATOR */ #endif /* ARCHOS_FMRECORDER || ARCHOS_RECORDERV2 */ @@ -346,6 +349,7 @@ target/sh/archos/fm_v2/button-fm_v2.c target/sh/archos/lcd-archos-bitmap.c target/sh/archos/lcd-as-archos-bitmap.S target/sh/archos/ondio/button-ondio.c +target/sh/archos/ondio/usb-ondio.c #endif /* SIMULATOR */ #endif /* ARCHOS_ONDIOFM || ARCHOS_ONDIOFM */ diff --git a/firmware/target/coldfire/iaudio/usb-target.h b/firmware/target/coldfire/iaudio/usb-target.h deleted file mode 100644 index ab8cac6f99..0000000000 --- a/firmware/target/coldfire/iaudio/usb-target.h +++ /dev/null @@ -1,24 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Linus Nielsen Feltzing - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#ifndef USB_TARGET_H -#define USB_TARGET_H - -bool usb_init_device(void); - -#endif diff --git a/firmware/target/coldfire/iriver/usb-target.h b/firmware/target/coldfire/iriver/usb-target.h deleted file mode 100644 index ab8cac6f99..0000000000 --- a/firmware/target/coldfire/iriver/usb-target.h +++ /dev/null @@ -1,24 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Linus Nielsen Feltzing - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#ifndef USB_TARGET_H -#define USB_TARGET_H - -bool usb_init_device(void); - -#endif diff --git a/firmware/target/coldfire/usb-target.h b/firmware/target/coldfire/usb-target.h new file mode 100644 index 0000000000..ab8cac6f99 --- /dev/null +++ b/firmware/target/coldfire/usb-target.h @@ -0,0 +1,24 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef USB_TARGET_H +#define USB_TARGET_H + +bool usb_init_device(void); + +#endif diff --git a/firmware/target/sh/archos/fm_v2/usb-fm_v2.c b/firmware/target/sh/archos/fm_v2/usb-fm_v2.c new file mode 100644 index 0000000000..2b4632e4f7 --- /dev/null +++ b/firmware/target/sh/archos/fm_v2/usb-fm_v2.c @@ -0,0 +1,46 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Jens Arnold + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include +#include "adc.h" +#include "cpu.h" +#include "hwcompat.h" +#include "system.h" + +bool usb_detect(void) +{ + return (adc_read(ADC_USB_POWER) <= 512) ? true : false; +} + +void usb_enable(bool on) +{ + if(read_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/ondio/usb-ondio.c b/firmware/target/sh/archos/ondio/usb-ondio.c new file mode 100644 index 0000000000..7c09bf3877 --- /dev/null +++ b/firmware/target/sh/archos/ondio/usb-ondio.c @@ -0,0 +1,58 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Jens Arnold + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include +#include "adc.h" +#include "ata_mmc.h" +#include "cpu.h" +#include "hwcompat.h" +#include "system.h" + +bool usb_detect(void) +{ + return (adc_read(ADC_USB_POWER) <= 512) ? true : false; +} + +void usb_enable(bool on) +{ + if (on) + { + mmc_enable_int_flash_clock(!mmc_detect()); + + if (!(read_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 (!(read_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/usb-player.c b/firmware/target/sh/archos/player/usb-player.c new file mode 100644 index 0000000000..c10e222f0a --- /dev/null +++ b/firmware/target/sh/archos/player/usb-player.c @@ -0,0 +1,41 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Jens Arnold + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include +#include "cpu.h" +#include "system.h" + +bool usb_detect(void) +{ + return (PADR & 0x8000) ? false : true; +} + +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/usb-recorder.c b/firmware/target/sh/archos/recorder/usb-recorder.c new file mode 100644 index 0000000000..2934b32a3c --- /dev/null +++ b/firmware/target/sh/archos/recorder/usb-recorder.c @@ -0,0 +1,46 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Jens Arnold + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include +#include "adc.h" +#include "cpu.h" +#include "hwcompat.h" +#include "system.h" + +bool usb_detect(void) +{ + return (adc_read(ADC_USB_POWER) > 500) ? true : false; +} + +void usb_enable(bool on) +{ + if(read_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/usb-target.h b/firmware/target/sh/usb-target.h new file mode 100644 index 0000000000..65fa31fb85 --- /dev/null +++ b/firmware/target/sh/usb-target.h @@ -0,0 +1,24 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Jens Arnold + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef USB_TARGET_H +#define USB_TARGET_H + +bool usb_init_device(void); + +#endif diff --git a/firmware/usb.c b/firmware/usb.c index 13adc3b391..217aaf8b84 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -32,18 +32,11 @@ #include "disk.h" #include "panic.h" #include "lcd.h" -#include "adc.h" #include "usb.h" #include "button.h" #include "sprintf.h" #include "string.h" -#include "hwcompat.h" -#ifdef HAVE_MMC -#include "ata_mmc.h" -#endif -#ifdef TARGET_TREE #include "usb-target.h" -#endif #ifdef IRIVER_H300_SERIES #include "pcf50606.h" /* for pcf50606_usb_charging_... */ #endif @@ -56,8 +49,6 @@ bool do_screendump_instead_of_usb = false; void screen_dump(void); /* Nasty again. Defined in apps/ too */ #endif -#define USB_REALLY_BRAVE - #if !defined(SIMULATOR) && !defined(USB_NONE) /* Messages from usb_tick and thread states */ @@ -93,10 +84,7 @@ void screen_dump(void); /* Nasty again. Defined in apps/ too */ #endif #endif /* HAVE_USB_POWER */ -/* The ADC tick reads one channel per tick, and we want to check 3 successive - readings on the USB voltage channel. This doesn't apply to the Player, but - debouncing the USB detection port won't hurt us either. */ -#define NUM_POLL_READINGS (NUM_ADC_CHANNELS * 3) +#define NUM_POLL_READINGS (HZ/5) static int countdown; static int usb_state; @@ -115,46 +103,6 @@ static struct event_queue usb_queue; static bool last_usb_status; static bool usb_monitor_enabled; -#ifndef TARGET_TREE -void usb_enable(bool on) -{ -#ifdef USB_ENABLE_ONDIOSTYLE - PACR2 &= ~0x04C0; /* use PA3, PA5 as GPIO */ - if(on) - { -#ifdef HAVE_MMC - mmc_enable_int_flash_clock(!mmc_detect()); -#endif - if (!(read_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 (!(read_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 */ - } - or_b(0x28, &PAIORL); /* output for USB enable and card detect */ -#else -#ifdef HAVE_LCD_BITMAP - if(read_hw_mask() & USB_ACTIVE_HIGH) - on = !on; -#endif - if(on) - { - and_b(~0x04, &PADRH); /* enable USB */ - } - else - { - or_b(0x04, &PADRH); - } - or_b(0x04, &PAIORH); -#endif -} -#endif #ifndef BOOTLOADER static void usb_slave_mode(bool on) @@ -246,13 +194,9 @@ static void usb_thread(void) if(num_acks_to_expect == 0) { DEBUGF("All threads have acknowledged the connect.\n"); -#ifdef USB_REALLY_BRAVE usb_slave_mode(true); usb_state = USB_INSERTED; cpu_idle_mode(true); -#else - system_reboot(); -#endif } else { @@ -330,23 +274,6 @@ static void usb_thread(void) } #endif -#ifndef TARGET_TREE -bool usb_detect(void) -{ - bool current_status; - -#ifdef USB_RECORDERSTYLE - current_status = (adc_read(ADC_USB_POWER) > 500)?true:false; -#endif -#ifdef USB_FMRECORDERSTYLE - current_status = (adc_read(ADC_USB_POWER) <= 512)?true:false; -#endif -#ifdef USB_PLAYERSTYLE - current_status = (PADR & 0x8000)?false:true; -#endif - return current_status; -} -#endif #ifndef BOOTLOADER static void usb_tick(void) @@ -402,10 +329,7 @@ void usb_init(void) usb_monitor_enabled = false; countdown = -1; -#ifdef TARGET_TREE usb_init_device(); -#endif - usb_enable(false); /* We assume that the USB cable is extracted */ -- cgit