Subversion Repositories freemyipod

Rev

Rev 87 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 87 Rev 221
Line 31... Line 31...
31
#include "usb_ch9.h"
31
#include "usb_ch9.h"
32
#include "synopsysotg.h"
32
#include "synopsysotg.h"
33
#include "util.h"
33
#include "util.h"
34
#include "interrupt.h"
34
#include "interrupt.h"
35
#include "clockgates.h"
35
#include "clockgates.h"
-
 
36
#include "power.h"
36
 
37
 
37
 
38
 
38
struct ep_type
39
struct ep_type
39
{
40
{
40
    bool active;
41
    bool active;
Line 45... Line 46...
45
    struct wakeup complete;
46
    struct wakeup complete;
46
} ;
47
} ;
47
 
48
 
48
static struct ep_type endpoints[5];
49
static struct ep_type endpoints[5];
49
static struct usb_ctrlrequest ctrlreq CACHEALIGN_ATTR;
50
static struct usb_ctrlrequest ctrlreq CACHEALIGN_ATTR;
-
 
51
static uint32_t synopsysotg_stack[0x40] STACK_ATTR;
50
 
52
 
51
int usb_drv_port_speed(void)
53
int usb_drv_port_speed(void)
52
{
54
{
53
    return (DSTS & 2) == 0 ? 1 : 0;
55
    return (DSTS & 2) == 0 ? 1 : 0;
54
}
56
}
Line 349... Line 351...
349
        if (stall) DOEPCTL(endpoint) |= 0x00200000;
351
        if (stall) DOEPCTL(endpoint) |= 0x00200000;
350
        else DOEPCTL(endpoint) &= ~0x00200000;
352
        else DOEPCTL(endpoint) &= ~0x00200000;
351
    }
353
    }
352
}
354
}
353
 
355
 
-
 
356
void usb_drv_power_up(void)
-
 
357
{
-
 
358
    /* Enable USB clock */
-
 
359
    clockgate_enable(CLOCKGATE_USB_1, true);
-
 
360
    clockgate_enable(CLOCKGATE_USB_2, true);
-
 
361
    PCGCCTL = 0;
-
 
362
 
-
 
363
    /* reset the beast */
-
 
364
    usb_reset();
-
 
365
}
-
 
366
 
-
 
367
void usb_drv_power_down(void)
-
 
368
{
-
 
369
    DCTL = 0x802;  /* Soft Disconnect */
-
 
370
 
-
 
371
    ORSTCON = 1;  /* Put the PHY into reset (needed to get current down) */
-
 
372
    PCGCCTL = 1;  /* Shut down PHY clock */
-
 
373
    OPHYPWR = 0xF;  /* PHY: Power down */
-
 
374
    
-
 
375
    clockgate_enable(CLOCKGATE_USB_1, false);
-
 
376
    clockgate_enable(CLOCKGATE_USB_2, false);
-
 
377
}
-
 
378
 
-
 
379
void usb_check_vbus()
-
 
380
{
-
 
381
    bool oldstate = false;
-
 
382
    while (true)
-
 
383
    {
-
 
384
        sleep(200000);
-
 
385
        bool newstate = vbus_state();
-
 
386
        if (oldstate != newstate)
-
 
387
        {
-
 
388
            if (newstate) usb_drv_power_up();
-
 
389
            else usb_drv_power_down();
-
 
390
            oldstate = newstate;
-
 
391
        }
-
 
392
    }
-
 
393
}
-
 
394
 
354
void usb_drv_init(void)
395
void usb_drv_init(void)
355
{
396
{
356
    unsigned int i;
397
    unsigned int i;
357
    for (i = 0; i < sizeof(endpoints)/sizeof(struct ep_type); i++)
398
    for (i = 0; i < sizeof(endpoints)/sizeof(struct ep_type); i++)
358
        wakeup_init(&endpoints[i].complete);
399
        wakeup_init(&endpoints[i].complete);
Line 363... Line 404...
363
    PCGCCTL = 0;
404
    PCGCCTL = 0;
364
 
405
 
365
    /* unmask irq */
406
    /* unmask irq */
366
    interrupt_enable(IRQ_USB_FUNC, true);
407
    interrupt_enable(IRQ_USB_FUNC, true);
367
 
408
 
368
    /* reset the beast */
409
    thread_create("synopsysotg", usb_check_vbus, synopsysotg_stack,
-
 
410
                  sizeof(synopsysotg_stack), OS_THREAD, 63, true);
-
 
411
 
369
    usb_reset();
412
    usb_drv_power_down();
370
}
413
}
371
 
414
 
372
int usb_drv_get_max_out_size()
415
int usb_drv_get_max_out_size()
373
{
416
{
374
    return usb_drv_port_speed() ? 262144 : 32768;
417
    return usb_drv_port_speed() ? 262144 : 32768;