freemyipod r221 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r220‎ | r221 | r222 >
Date:02:58, 13 October 2010
Author:theseven
Status:new
Tags:
Comment:
emBIOS: Only power up the USB core if something is attached, to save power.
Modified paths:
  • /apps/iloader/main.c (modified) (history)
  • /embios/trunk/power.h (modified) (history)
  • /embios/trunk/target/ipodnano2g/power.c (modified) (history)
  • /embios/trunk/target/ipodnano2g/s5l8701.h (modified) (history)
  • /embios/trunk/target/ipodnano4g/power.c (modified) (history)
  • /embios/trunk/usb/synopsysotg.c (modified) (history)

Diff [purge]

Index: apps/iloader/main.c
@@ -188,7 +188,7 @@
189189 break;
190190
191191 case 0x1:
192 - cputs(1, "iLoader terminated on user's behalf\n");
 192+ cputs(1, "iLoader terminated on user's request\n");
193193 return;
194194
195195 case 0x2:
Index: embios/trunk/target/ipodnano2g/s5l8701.h
@@ -79,6 +79,8 @@
8080 #define PDAT10 (*((volatile uint32_t*)(0x3CF000A4)))
8181 #define PCON11 (*((volatile uint32_t*)(0x3CF000B0)))
8282 #define PDAT11 (*((volatile uint32_t*)(0x3CF000B4)))
 83+#define PCON14 (*((volatile uint32_t*)(0x3CF000E0)))
 84+#define PDAT14 (*((volatile uint32_t*)(0x3CF000E4)))
8385 #define PCON15 (*((volatile uint32_t*)(0x3CF000F0)))
8486 #define PUNK15 (*((volatile uint32_t*)(0x3CF000FC)))
8587
Index: embios/trunk/target/ipodnano2g/power.c
@@ -50,9 +50,19 @@
5151 {
5252 pmu_init();
5353 pmu_write(0x1e, 15); /* Vcore = 1.000V */
54 -}
 54+}
5555
5656 bool charging_state(void)
5757 {
5858 return (PDAT11 & 0x10) ? false : true;
5959 }
 60+
 61+bool external_power_state(void)
 62+{
 63+ return (PDAT14 & 8) ? false : true;
 64+}
 65+
 66+bool vbus_state(void)
 67+{
 68+ return (PDAT14 & 8) ? false : true;
 69+}
Index: embios/trunk/target/ipodnano4g/power.c
@@ -41,3 +41,13 @@
4242 {
4343 return false;
4444 }
 45+
 46+bool external_power_state(void)
 47+{
 48+ return true;
 49+}
 50+
 51+bool vbus_state(void)
 52+{
 53+ return true;
 54+}
Index: embios/trunk/power.h
@@ -30,5 +30,8 @@
3131 void power_off(void);
3232 void power_init(void);
3333 bool charging_state(void);
 34+bool external_power_state(void);
 35+bool vbus_state(void);
3436
 37+
3538 #endif
Index: embios/trunk/usb/synopsysotg.c
@@ -33,6 +33,7 @@
3434 #include "util.h"
3535 #include "interrupt.h"
3636 #include "clockgates.h"
 37+#include "power.h"
3738
3839
3940 struct ep_type
@@ -47,6 +48,7 @@
4849
4950 static struct ep_type endpoints[5];
5051 static struct usb_ctrlrequest ctrlreq CACHEALIGN_ATTR;
 52+static uint32_t synopsysotg_stack[0x40] STACK_ATTR;
5153
5254 int usb_drv_port_speed(void)
5355 {
@@ -351,6 +353,45 @@
352354 }
353355 }
354356
 357+void usb_drv_power_up(void)
 358+{
 359+ /* Enable USB clock */
 360+ clockgate_enable(CLOCKGATE_USB_1, true);
 361+ clockgate_enable(CLOCKGATE_USB_2, true);
 362+ PCGCCTL = 0;
 363+
 364+ /* reset the beast */
 365+ usb_reset();
 366+}
 367+
 368+void usb_drv_power_down(void)
 369+{
 370+ DCTL = 0x802; /* Soft Disconnect */
 371+
 372+ ORSTCON = 1; /* Put the PHY into reset (needed to get current down) */
 373+ PCGCCTL = 1; /* Shut down PHY clock */
 374+ OPHYPWR = 0xF; /* PHY: Power down */
 375+
 376+ clockgate_enable(CLOCKGATE_USB_1, false);
 377+ clockgate_enable(CLOCKGATE_USB_2, false);
 378+}
 379+
 380+void usb_check_vbus()
 381+{
 382+ bool oldstate = false;
 383+ while (true)
 384+ {
 385+ sleep(200000);
 386+ bool newstate = vbus_state();
 387+ if (oldstate != newstate)
 388+ {
 389+ if (newstate) usb_drv_power_up();
 390+ else usb_drv_power_down();
 391+ oldstate = newstate;
 392+ }
 393+ }
 394+}
 395+
355396 void usb_drv_init(void)
356397 {
357398 unsigned int i;
@@ -365,8 +406,10 @@
366407 /* unmask irq */
367408 interrupt_enable(IRQ_USB_FUNC, true);
368409
369 - /* reset the beast */
370 - usb_reset();
 410+ thread_create("synopsysotg", usb_check_vbus, synopsysotg_stack,
 411+ sizeof(synopsysotg_stack), OS_THREAD, 63, true);
 412+
 413+ usb_drv_power_down();
371414 }
372415
373416 int usb_drv_get_max_out_size()