summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2006-01-07 00:43:48 +0000
committerDave Chapman <dave@dchapman.com>2006-01-07 00:43:48 +0000
commitb82c441f290cda0faffbf467aaf4eb990c07dcc9 (patch)
tree894ad24dee14e64cd89ca8c135332d5578a4e906
parentee927e6514d38fe29524aea39d1f0883d3005ad3 (diff)
downloadrockbox-b82c441f290cda0faffbf467aaf4eb990c07dcc9.tar.gz
rockbox-b82c441f290cda0faffbf467aaf4eb990c07dcc9.zip
iPod: Add USB detection. When inserting the USB cable, hold down MENU to charge via USB, otherwise Rockbox will reboot into the Disk Mode application stored in flash
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8303 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/export/config-ipodcolor.h3
-rw-r--r--firmware/export/config-ipodnano.h3
-rw-r--r--firmware/export/config-ipodvideo.h3
-rw-r--r--firmware/export/pp5020.h3
-rw-r--r--firmware/usb.c74
5 files changed, 82 insertions, 4 deletions
diff --git a/firmware/export/config-ipodcolor.h b/firmware/export/config-ipodcolor.h
index 778055f3d7..b88c9bc7a4 100644
--- a/firmware/export/config-ipodcolor.h
+++ b/firmware/export/config-ipodcolor.h
@@ -84,6 +84,9 @@
84 84
85#define USB_IPODSTYLE 85#define USB_IPODSTYLE
86 86
87/* define this if the unit can be powered or charged via USB */
88#define HAVE_USB_POWER
89
87/* Virtual LED (icon) */ 90/* Virtual LED (icon) */
88#define CONFIG_LED LED_VIRTUAL 91#define CONFIG_LED LED_VIRTUAL
89 92
diff --git a/firmware/export/config-ipodnano.h b/firmware/export/config-ipodnano.h
index 86cc279bb8..207aa18fa2 100644
--- a/firmware/export/config-ipodnano.h
+++ b/firmware/export/config-ipodnano.h
@@ -86,6 +86,9 @@
86 86
87#define USB_IPODSTYLE 87#define USB_IPODSTYLE
88 88
89/* define this if the unit can be powered or charged via USB */
90#define HAVE_USB_POWER
91
89/* Virtual LED (icon) */ 92/* Virtual LED (icon) */
90#define CONFIG_LED LED_VIRTUAL 93#define CONFIG_LED LED_VIRTUAL
91 94
diff --git a/firmware/export/config-ipodvideo.h b/firmware/export/config-ipodvideo.h
index e06e999e1c..d6d9bbc92f 100644
--- a/firmware/export/config-ipodvideo.h
+++ b/firmware/export/config-ipodvideo.h
@@ -86,6 +86,9 @@
86 86
87#define USB_IPODSTYLE 87#define USB_IPODSTYLE
88 88
89/* define this if the unit can be powered or charged via USB */
90#define HAVE_USB_POWER
91
89/* Virtual LED (icon) */ 92/* Virtual LED (icon) */
90#define CONFIG_LED LED_VIRTUAL 93#define CONFIG_LED LED_VIRTUAL
91 94
diff --git a/firmware/export/pp5020.h b/firmware/export/pp5020.h
index d2dbffc615..14dd2ba1c1 100644
--- a/firmware/export/pp5020.h
+++ b/firmware/export/pp5020.h
@@ -87,4 +87,7 @@
87#define PP5020_SER1_MASK (1 << (PP5020_SER1_IRQ-32)) 87#define PP5020_SER1_MASK (1 << (PP5020_SER1_IRQ-32))
88#define PP5020_I2C_MASK (1 << (PP5020_I2C_IRQ-32)) 88#define PP5020_I2C_MASK (1 << (PP5020_I2C_IRQ-32))
89 89
90#define USB2D_IDENT (*(volatile unsigned long*)(0xc5000000))
91#define USB_STATUS (*(volatile unsigned long*)(0xc50001a4))
92
90#endif 93#endif
diff --git a/firmware/usb.c b/firmware/usb.c
index c453cb7a2b..23e2e33737 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -9,6 +9,11 @@
9 * 9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing 10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 * 11 *
12 * iPod driver based on code from the ipodlinux project - http://ipodlinux.org
13 * Adapted for Rockbox in January 2006
14 * Original file: podzilla/usb.c
15 * Copyright (C) 2005 Adam Johnston
16 *
12 * All files in this archive are subject to the GNU General Public License. 17 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement. 18 * See the file COPYING in the source tree root for full license agreement.
14 * 19 *
@@ -31,6 +36,7 @@
31#include "usb.h" 36#include "usb.h"
32#include "button.h" 37#include "button.h"
33#include "sprintf.h" 38#include "sprintf.h"
39#include "string.h"
34#include "hwcompat.h" 40#include "hwcompat.h"
35#ifdef HAVE_MMC 41#ifdef HAVE_MMC
36#include "ata_mmc.h" 42#include "ata_mmc.h"
@@ -62,6 +68,9 @@ void screen_dump(void); /* Nasty again. Defined in apps/ too */
62#elif CONFIG_KEYPAD == ONDIO_PAD 68#elif CONFIG_KEYPAD == ONDIO_PAD
63#define USBPOWER_BUTTON BUTTON_MENU 69#define USBPOWER_BUTTON BUTTON_MENU
64#define USBPOWER_BTN_IGNORE BUTTON_OFF 70#define USBPOWER_BTN_IGNORE BUTTON_OFF
71#elif CONFIG_KEYPAD == IPOD_4G_PAD
72#define USBPOWER_BUTTON BUTTON_MENU
73#define USBPOWER_BTN_IGNORE BUTTON_PLAY
65#endif 74#endif
66#endif /* HAVE_USB_POWER */ 75#endif /* HAVE_USB_POWER */
67 76
@@ -155,8 +164,22 @@ void usb_enable(bool on)
155 } 164 }
156 165
157#elif defined(USB_IPODSTYLE) 166#elif defined(USB_IPODSTYLE)
158 /* TODO: Implement USB_IPODSTYLE */ 167 /* For the ipod, we can only do one thing with USB mode - reboot
159 (void) on; 168 into Apple's flash-based disk-mode. This does not return. */
169 if (on)
170 {
171 /* The following code is copied from ipodlinux - it doesn't work on the
172 iPod Video */
173 unsigned char* storage_ptr = (unsigned char *)0x40017F00;
174 char* diskmode = "diskmode\0";
175 char* hotstuff = "hotstuff\0";
176
177 memcpy(storage_ptr, diskmode, 9);
178 storage_ptr = (unsigned char *)0x40017f08;
179 memcpy(storage_ptr, hotstuff, 9);
180 outl(1, 0x40017F10);
181 outl(inl(0x60006004) | 0x4, 0x60006004);
182 }
160#else 183#else
161#ifdef HAVE_LCD_BITMAP 184#ifdef HAVE_LCD_BITMAP
162 if(read_hw_mask() & USB_ACTIVE_HIGH) 185 if(read_hw_mask() & USB_ACTIVE_HIGH)
@@ -375,8 +398,12 @@ bool usb_detect(void)
375 current_status = (GPIO1_READ & 0x80)?true:false; 398 current_status = (GPIO1_READ & 0x80)?true:false;
376#endif 399#endif
377#ifdef USB_IPODSTYLE 400#ifdef USB_IPODSTYLE
378 /* TODO: Implement USB_IPODSTYLE */ 401 /* The following check is in the ipodlinux source, with the
379 current_status = false; 402 comment "USB2D_IDENT is bad" if USB2D_IDENT != 0x22FA05 */
403 if (USB2D_IDENT != 0x22FA05) {
404 return false;
405 }
406 current_status = (USB_STATUS & 0x800)?true:false;
380#endif 407#endif
381 return current_status; 408 return current_status;
382} 409}
@@ -465,6 +492,45 @@ void usb_init(void)
465 or_l(0x01000040, &GPIO_FUNCTION); 492 or_l(0x01000040, &GPIO_FUNCTION);
466#endif 493#endif
467 494
495#elif defined(USB_IPODSTYLE)
496 int r0;
497 outl(inl(0x70000084) | 0x200, 0x70000084);
498
499 outl(inl(0x7000002C) | 0x3000000, 0x7000002C);
500 outl(inl(0x6000600C) | 0x400000, 0x6000600C);
501
502 outl(inl(0x60006004) | 0x400000, 0x60006004); /* reset usb start */
503 outl(inl(0x60006004) & ~0x400000, 0x60006004); /* reset usb end */
504
505 outl(inl(0x70000020) | 0x80000000, 0x70000020);
506 while ((inl(0x70000028) & 0x80) == 0);
507
508 outl(inl(0xc5000184) | 0x100, 0xc5000184);
509 while ((inl(0xc5000184) & 0x100) != 0);
510
511 outl(inl(0xc50001A4) | 0x5F000000, 0xc50001A4);
512 if ((inl(0xc50001A4) & 0x100) == 0) {
513 outl(inl(0xc50001A8) & ~0x3, 0xc50001A8);
514 outl(inl(0xc50001A8) | 0x2, 0xc50001A8);
515 outl(inl(0x70000028) | 0x4000, 0x70000028);
516 outl(inl(0x70000028) | 0x2, 0x70000028);
517 } else {
518 outl(inl(0xc50001A8) | 0x3, 0xc50001A8);
519 outl(inl(0x70000028) &~0x4000, 0x70000028);
520 outl(inl(0x70000028) | 0x2, 0x70000028);
521 }
522 outl(inl(0xc5000140) | 0x2, 0xc5000140);
523 while((inl(0xc5000140) & 0x2) != 0);
524 r0 = inl(0xc5000184);
525
526 /* Note from IPL source (referring to next 5 lines of code:
527 THIS NEEDS TO BE CHANGED ONCE THERE IS KERNEL USB */
528 outl(inl(0x70000020) | 0x80000000, 0x70000020);
529 outl(inl(0x6000600C) | 0x400000, 0x6000600C);
530 while ((inl(0x70000028) & 0x80) == 0);
531 outl(inl(0x70000028) | 0x2, 0x70000028);
532
533 udelay(0x186A0);
468#endif 534#endif
469 535
470 usb_enable(false); 536 usb_enable(false);