From cb896cdd04ae04cbf9cb59990c920e579ea6887a Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Wed, 1 Aug 2007 22:44:02 +0000 Subject: Firewire detection with reboot into diskmode for all iPods that support it (all but Nano and Video). * Hack for compiling iPod G3 removed. * Code cleanup. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14131 a1c6a512-1295-4272-9138-f99709370657 --- apps/bitmaps/native/SOURCES | 4 + apps/bitmaps/native/usblogo.fw.128x39x2.bmp | Bin 0 -> 5062 bytes firmware/SOURCES | 23 ++-- firmware/export/config-ipod1g2g.h | 3 +- firmware/export/config-ipod3g.h | 3 +- firmware/export/pp5002.h | 5 - firmware/target/arm/usb-fw-pp5002.c | 70 ++++++++++++ firmware/target/arm/usb-fw-pp502x.c | 168 ++++++++++++++++++++++++++++ firmware/target/arm/usb-pp.c | 157 -------------------------- 9 files changed, 258 insertions(+), 175 deletions(-) create mode 100644 apps/bitmaps/native/usblogo.fw.128x39x2.bmp create mode 100644 firmware/target/arm/usb-fw-pp5002.c create mode 100644 firmware/target/arm/usb-fw-pp502x.c delete mode 100644 firmware/target/arm/usb-pp.c diff --git a/apps/bitmaps/native/SOURCES b/apps/bitmaps/native/SOURCES index 62deb0afac..094b2d61b1 100644 --- a/apps/bitmaps/native/SOURCES +++ b/apps/bitmaps/native/SOURCES @@ -31,7 +31,11 @@ usblogo.176x48x16.bmp usblogo.128x37x16.bmp #endif #elif LCD_DEPTH > 1 /* greyscale */ +#ifdef IPOD_1G2G /* use firewire logo */ +usblogo.fw.128x39x2.bmp +#else usblogo.128x33x2.bmp +#endif #else /* monochrome */ #if LCD_WIDTH == 112 usblogo.100x20x1.bmp diff --git a/apps/bitmaps/native/usblogo.fw.128x39x2.bmp b/apps/bitmaps/native/usblogo.fw.128x39x2.bmp new file mode 100644 index 0000000000..bdf7af52b7 Binary files /dev/null and b/apps/bitmaps/native/usblogo.fw.128x39x2.bmp differ diff --git a/firmware/SOURCES b/firmware/SOURCES index 91cead088d..ccd6f11570 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -382,7 +382,7 @@ target/arm/sandisk/sansa-e200/lcd-e200.c target/arm/sandisk/sansa-e200/lcd-as-e200.S target/arm/sandisk/sansa-e200/adc-e200.c target/arm/sandisk/sansa-e200/backlight-e200.c -target/arm/usb-pp.c +target/arm/usb-fw-pp502x.c target/arm/sandisk/sansa-e200/button-e200.c target/arm/sandisk/sansa-e200/power-e200.c target/arm/i2s-pp.c @@ -497,7 +497,7 @@ target/arm/iriver/h10/backlight-h10.c target/arm/iriver/h10/button-h10.c target/arm/iriver/h10/lcd-h10_20gb.c target/arm/iriver/h10/power-h10.c -target/arm/usb-pp.c +target/arm/usb-fw-pp502x.c #endif /* SIMULATOR */ #endif /* IRIVER_H10 */ @@ -512,7 +512,7 @@ target/arm/iriver/h10/backlight-h10.c target/arm/iriver/h10/button-h10.c target/arm/iriver/h10/lcd-h10_5gb.c target/arm/iriver/h10/power-h10.c -target/arm/usb-pp.c +target/arm/usb-fw-pp502x.c #endif /* SIMULATOR */ #endif /* IRIVER_H10_5GB */ @@ -551,7 +551,7 @@ target/arm/tatung/tpj1022/backlight-tpj1022.c target/arm/tatung/tpj1022/button-tpj1022.c target/arm/tatung/tpj1022/lcd-tpj1022.c target/arm/tatung/tpj1022/power-tpj1022.c -target/arm/usb-pp.c +target/arm/usb-fw-pp502x.c #endif /* SIMULATOR */ #endif /* ELIO_TPJ1022 */ @@ -567,7 +567,7 @@ target/arm/ipod/backlight-4g_color.c target/arm/ipod/button-clickwheel.c target/arm/ipod/lcd-gray.c target/arm/ipod/power-ipod.c -target/arm/usb-pp.c +target/arm/usb-fw-pp502x.c #endif /* SIMULATOR */ #endif /* IPOD_4G */ @@ -583,7 +583,7 @@ target/arm/ipod/backlight-4g_color.c target/arm/ipod/button-clickwheel.c target/arm/ipod/lcd-color_nano.c target/arm/ipod/power-ipod.c -target/arm/usb-pp.c +target/arm/usb-fw-pp502x.c #endif /* SIMULATOR */ #endif /* IPOD_COLOR */ @@ -599,7 +599,7 @@ target/arm/ipod/backlight-nano_video.c target/arm/ipod/button-clickwheel.c target/arm/ipod/lcd-color_nano.c target/arm/ipod/power-ipod.c -target/arm/usb-pp.c +target/arm/usb-fw-pp502x.c #endif /* SIMULATOR */ #endif /* IPOD_NANO */ @@ -615,7 +615,7 @@ target/arm/ipod/backlight-nano_video.c target/arm/ipod/button-clickwheel.c target/arm/ipod/power-ipod.c target/arm/ipod/video/lcd-video.c -target/arm/usb-pp.c +target/arm/usb-fw-pp502x.c #endif /* SIMULATOR */ #endif /* IPOD_VIDEO */ @@ -630,7 +630,7 @@ target/arm/ipod/3g/backlight-3g.c target/arm/ipod/button-1g-3g.c target/arm/ipod/lcd-gray.c target/arm/ipod/power-ipod.c -target/arm/usb-pp.c +target/arm/usb-fw-pp5002.c #endif /* SIMULATOR */ #endif /* IPOD_3G */ @@ -644,6 +644,7 @@ target/arm/ipod/1g2g/backlight-1g2g.c target/arm/ipod/button-1g-3g.c target/arm/ipod/lcd-gray.c target/arm/ipod/power-ipod.c +target/arm/usb-fw-pp5002.c #endif /* SIMULATOR */ #endif /* IPOD_1G2G */ @@ -659,7 +660,7 @@ target/arm/ipod/backlight-mini1g_mini2g.c target/arm/ipod/button-mini1g.c target/arm/ipod/lcd-gray.c target/arm/ipod/power-ipod.c -target/arm/usb-pp.c +target/arm/usb-fw-pp502x.c #endif /* SIMULATOR */ #endif /* IPOD_MINI */ @@ -675,7 +676,7 @@ target/arm/ipod/backlight-mini1g_mini2g.c target/arm/ipod/button-clickwheel.c target/arm/ipod/lcd-gray.c target/arm/ipod/power-ipod.c -target/arm/usb-pp.c +target/arm/usb-fw-pp502x.c #endif /* SIMULATOR */ #endif /* IPOD_MINI2G */ diff --git a/firmware/export/config-ipod1g2g.h b/firmware/export/config-ipod1g2g.h index 0eb3614dd6..37ebb32f86 100644 --- a/firmware/export/config-ipod1g2g.h +++ b/firmware/export/config-ipod1g2g.h @@ -110,7 +110,8 @@ /* Offset ( in the firmware file's header ) to the real data */ #define FIRMWARE_OFFSET_FILE_DATA 8 -#define USB_NONE +#define USB_IPODSTYLE +/* actually firewire only, but handled like USB */ /* Virtual LED (icon) */ #define CONFIG_LED LED_VIRTUAL diff --git a/firmware/export/config-ipod3g.h b/firmware/export/config-ipod3g.h index c3e63e87e3..466fb19601 100644 --- a/firmware/export/config-ipod3g.h +++ b/firmware/export/config-ipod3g.h @@ -110,7 +110,8 @@ /* Offset ( in the firmware file's header ) to the real data */ #define FIRMWARE_OFFSET_FILE_DATA 8 -#define USB_NONE +#define USB_IPODSTYLE +/* actually both firewire and USB, USB isn't handled yet */ /* Virtual LED (icon) */ #define CONFIG_LED LED_VIRTUAL diff --git a/firmware/export/pp5002.h b/firmware/export/pp5002.h index 83f8456bf0..9d757ead7d 100644 --- a/firmware/export/pp5002.h +++ b/firmware/export/pp5002.h @@ -141,9 +141,4 @@ #define MMAP3_LOGICAL (*(volatile unsigned long *)(0xf000f018)) #define MMAP3_PHYSICAL (*(volatile unsigned long *)(0xf000f01c)) -/* FIXME: These are PP502x definitions, but without them, iPod 3rd gen - * doesn't compile. The correct values for 3rd gen are not yet known. */ -#define DEV_INIT (*(volatile unsigned long *)(0x70000020)) -#define INIT_USB 0x80000000 - #endif diff --git a/firmware/target/arm/usb-fw-pp5002.c b/firmware/target/arm/usb-fw-pp5002.c new file mode 100644 index 0000000000..e64d4f8f81 --- /dev/null +++ b/firmware/target/arm/usb-fw-pp5002.c @@ -0,0 +1,70 @@ +/*************************************************************************** + * __________ __ ___. + * 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 "ata.h" +#include "cpu.h" +#include "string.h" +#include "system.h" +#include "usb.h" +#include "usb-target.h" + +void usb_init_device(void) +{ + /* TODO: add USB init for iPod 3rd gen */ + +#if defined(IPOD_1G2G) || defined(IPOD_3G) + /* GPIO C bit 7 is firewire detect */ + GPIOC_ENABLE |= 0x80; + GPIOC_OUTPUT_EN &= ~0x80; +#endif +} + +void usb_enable(bool on) +{ + /* This device specific code will eventually give way to proper USB + handling, which should be the same for all PP5002 targets. */ + if (on) + { +#ifdef IPOD_ARCH + /* For iPod, we can only do one thing with USB mode atm - reboot + into the flash-based disk-mode. This does not return. */ + + ata_sleepnow(); /* Immediately spindown the disk. */ + sleep(HZ*2); + + memcpy((void *)0x40017f00, "diskmodehotstuff\1", 17); + + system_reboot(); /* Reboot */ +#endif + } +} + +bool usb_detect(void) +{ +#if defined(IPOD_1G2G) || defined(IPOD_3G) + /* GPIO C bit 7 is firewire detect */ + if (!(GPIOC_INPUT_VAL & 0x80)) + return true; +#endif + + /* TODO: add USB detection for iPod 3rd gen */ + + return false; +} diff --git a/firmware/target/arm/usb-fw-pp502x.c b/firmware/target/arm/usb-fw-pp502x.c new file mode 100644 index 0000000000..92e3dee562 --- /dev/null +++ b/firmware/target/arm/usb-fw-pp502x.c @@ -0,0 +1,168 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Linus Nielsen Feltzing + * + * iPod driver based on code from the ipodlinux project - http://ipodlinux.org + * Adapted for Rockbox in January 2006 + * Original file: podzilla/usb.c + * Copyright (C) 2005 Adam Johnston + * + * 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 "cpu.h" +#include "kernel.h" +#include "thread.h" +#include "system.h" +#include "debug.h" +#include "ata.h" +#include "fat.h" +#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" + +#include "usb-target.h" +#include "arcotg_udc.h" + +void usb_init_device(void) +{ + int r0; + outl(inl(0x70000084) | 0x200, 0x70000084); + + outl(inl(0x7000002C) | 0x3000000, 0x7000002C); + DEV_EN |= DEV_USB; + + DEV_RS |= DEV_USB; /* reset usb start */ + DEV_RS &=~DEV_USB;/* reset usb end */ + + DEV_INIT |= INIT_USB; + while ((inl(0x70000028) & 0x80) == 0); + + UDC_PORTSC1 |= PORTSCX_PORT_RESET; + while ((UDC_PORTSC1 & PORTSCX_PORT_RESET) != 0); + + UDC_OTGSC |= 0x5F000000; + if( (UDC_OTGSC & 0x100) == 0) { + UDC_USBMODE &=~ USB_MODE_CTRL_MODE_HOST; + UDC_USBMODE |= USB_MODE_CTRL_MODE_DEVICE; + outl(inl(0x70000028) | 0x4000, 0x70000028); + outl(inl(0x70000028) | 0x2, 0x70000028); + } else { + UDC_USBMODE |= USB_MODE_CTRL_MODE_DEVICE; + outl(inl(0x70000028) &~0x4000, 0x70000028); + outl(inl(0x70000028) | 0x2, 0x70000028); + } + + + UDC_USBCMD |= USB_CMD_CTRL_RESET; + while((UDC_USBCMD & USB_CMD_CTRL_RESET) != 0); + + r0 = UDC_PORTSC1; + + /* Note from IPL source (referring to next 5 lines of code: + THIS NEEDS TO BE CHANGED ONCE THERE IS KERNEL USB */ + DEV_INIT |= INIT_USB; + DEV_EN |= DEV_USB; + while ((inl(0x70000028) & 0x80) == 0); + outl(inl(0x70000028) | 0x2, 0x70000028); + + udelay(0x186A0); + + dr_controller_setup(); + +#if defined(IPOD_COLOR) || defined(IPOD_4G) \ + || defined(IPOD_MINI) || defined(IPOD_MINI2G) + /* GPIO C bit 1 is firewire detect */ + GPIOC_ENABLE |= 0x02; + GPIOC_OUTPUT_EN &= ~0x02; +#endif +} + +void usb_enable(bool on) +{ + /* This device specific code will eventually give way to proper USB + handling, which should be the same for all PP502x targets. */ + if (on) + { +#if defined(IPOD_ARCH) || defined(IRIVER_H10) || defined (IRIVER_H10_5GB) + /* For the H10 and iPod, we can only do one thing with USB mode - reboot + into the flash-based disk-mode. This does not return. */ + +#if defined(IRIVER_H10) || defined (IRIVER_H10_5GB) + if(button_status()==BUTTON_RIGHT) +#endif + { + ata_sleepnow(); /* Immediately spindown the disk. */ + sleep(HZ*2); + +#ifdef IPOD_ARCH /* The following code is based on ipodlinux */ +#if CONFIG_CPU == PP5020 + memcpy((void *)0x40017f00, "diskmode\0\0hotstuff\0\0\1", 21); +#elif CONFIG_CPU == PP5022 + memcpy((void *)0x4001ff00, "diskmode\0\0hotstuff\0\0\1", 21); +#endif +#endif + + system_reboot(); /* Reboot */ + } +#endif + } +} + +bool usb_detect(void) +{ + static bool prev_usbstatus1 = false; + bool usbstatus1,usbstatus2; + +#if defined(IPOD_COLOR) || defined(IPOD_4G) \ + || defined(IPOD_MINI) || defined(IPOD_MINI2G) + /* GPIO C bit 1 is firewire detect */ + if (!(GPIOC_INPUT_VAL & 0x02)) + return true; +#endif + + /* UDC_ID should have the bit format: + [31:24] = 0x0 + [23:16] = 0x22 (Revision number) + [15:14] = 0x3 (Reserved) + [13:8] = 0x3a (NID - 1's compliment of ID) + [7:6] = 0x0 (Reserved) + [5:0] = 0x05 (ID) */ + if (UDC_ID != 0x22FA05) { + return false; + } + + usbstatus1 = (UDC_OTGSC & 0x800) ? true : false; + if ((usbstatus1 == true) && (prev_usbstatus1 == false)) { + dr_controller_run(); + } else if ((usbstatus1 == false) && (prev_usbstatus1 == true)) { + dr_controller_stop(); + } + + prev_usbstatus1 = usbstatus1; + usbstatus2 = (UDC_PORTSC1 & PORTSCX_CURRENT_CONNECT_STATUS) ? true : false; + + if (usbstatus1 && usbstatus2) { + return true; + } else { + return false; + } +} diff --git a/firmware/target/arm/usb-pp.c b/firmware/target/arm/usb-pp.c deleted file mode 100644 index b497e86804..0000000000 --- a/firmware/target/arm/usb-pp.c +++ /dev/null @@ -1,157 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Linus Nielsen Feltzing - * - * iPod driver based on code from the ipodlinux project - http://ipodlinux.org - * Adapted for Rockbox in January 2006 - * Original file: podzilla/usb.c - * Copyright (C) 2005 Adam Johnston - * - * 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 "cpu.h" -#include "kernel.h" -#include "thread.h" -#include "system.h" -#include "debug.h" -#include "ata.h" -#include "fat.h" -#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" - -#include "usb-target.h" -#include "arcotg_udc.h" - -void usb_init_device(void) -{ - int r0; - outl(inl(0x70000084) | 0x200, 0x70000084); - - outl(inl(0x7000002C) | 0x3000000, 0x7000002C); - DEV_EN |= DEV_USB; - - DEV_RS |= DEV_USB; /* reset usb start */ - DEV_RS &=~DEV_USB;/* reset usb end */ - - DEV_INIT |= INIT_USB; - while ((inl(0x70000028) & 0x80) == 0); - - UDC_PORTSC1 |= PORTSCX_PORT_RESET; - while ((UDC_PORTSC1 & PORTSCX_PORT_RESET) != 0); - - UDC_OTGSC |= 0x5F000000; - if( (UDC_OTGSC & 0x100) == 0) { - UDC_USBMODE &=~ USB_MODE_CTRL_MODE_HOST; - UDC_USBMODE |= USB_MODE_CTRL_MODE_DEVICE; - outl(inl(0x70000028) | 0x4000, 0x70000028); - outl(inl(0x70000028) | 0x2, 0x70000028); - } else { - UDC_USBMODE |= USB_MODE_CTRL_MODE_DEVICE; - outl(inl(0x70000028) &~0x4000, 0x70000028); - outl(inl(0x70000028) | 0x2, 0x70000028); - } - - - UDC_USBCMD |= USB_CMD_CTRL_RESET; - while((UDC_USBCMD & USB_CMD_CTRL_RESET) != 0); - - r0 = UDC_PORTSC1; - - /* Note from IPL source (referring to next 5 lines of code: - THIS NEEDS TO BE CHANGED ONCE THERE IS KERNEL USB */ - DEV_INIT |= INIT_USB; - DEV_EN |= DEV_USB; - while ((inl(0x70000028) & 0x80) == 0); - outl(inl(0x70000028) | 0x2, 0x70000028); - - udelay(0x186A0); - - - dr_controller_setup(); -} - -void usb_enable(bool on) -{ - /* This device specific code will eventually give way to proper USB - handling, which should be the same for all PortalPlayer targets. */ - if (on) - { -#if defined(IPOD_ARCH) || defined(IRIVER_H10) || defined (IRIVER_H10_5GB) - /* For the H10 and iPod, we can only do one thing with USB mode - reboot - into the flash-based disk-mode. This does not return. */ - - /* The following code is copied from ipodlinux */ -#if defined(IPOD_COLOR) || defined(IPOD_3G) || \ - defined(IPOD_4G) || defined(IPOD_MINI) - unsigned char* storage_ptr = (unsigned char *)0x40017F00; -#elif defined(IPOD_NANO) || defined(IPOD_VIDEO) || defined(IPOD_MINI2G) - unsigned char* storage_ptr = (unsigned char *)0x4001FF00; -#endif - -#if defined(IRIVER_H10) || defined (IRIVER_H10_5GB) - if(button_status()==BUTTON_RIGHT) -#endif - { - ata_sleepnow(); /* Immediately spindown the disk. */ - sleep(HZ*2); -#ifdef IPOD_ARCH - memcpy(storage_ptr, "diskmode\0\0hotstuff\0\0\1", 21); -#endif - system_reboot(); /* Reboot */ - } -#endif - } -} - -bool usb_detect(void) -{ - static bool prev_usbstatus1 = false; - bool usbstatus1,usbstatus2; - - /* UDC_ID should have the bit format: - [31:24] = 0x0 - [23:16] = 0x22 (Revision number) - [15:14] = 0x3 (Reserved) - [13:8] = 0x3a (NID - 1's compliment of ID) - [7:6] = 0x0 (Reserved) - [5:0] = 0x05 (ID) */ - if (UDC_ID != 0x22FA05) { - return false; - } - - usbstatus1 = (UDC_OTGSC & 0x800) ? true : false; - if ((usbstatus1 == true) && (prev_usbstatus1 == false)) { - dr_controller_run(); - } else if ((usbstatus1 == false) && (prev_usbstatus1 == true)) { - dr_controller_stop(); - } - - prev_usbstatus1 = usbstatus1; - usbstatus2 = (UDC_PORTSC1 & PORTSCX_CURRENT_CONNECT_STATUS) ? true : false; - - if (usbstatus1 && usbstatus2) { - return true; - } else { - return false; - } -} -- cgit v1.2.3