summaryrefslogtreecommitdiff
path: root/firmware/target/arm/gigabeat/meg-fx/usb-meg-fx.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/gigabeat/meg-fx/usb-meg-fx.c')
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/usb-meg-fx.c77
1 files changed, 58 insertions, 19 deletions
diff --git a/firmware/target/arm/gigabeat/meg-fx/usb-meg-fx.c b/firmware/target/arm/gigabeat/meg-fx/usb-meg-fx.c
index 6e0f31e8c7..2415a099ba 100644
--- a/firmware/target/arm/gigabeat/meg-fx/usb-meg-fx.c
+++ b/firmware/target/arm/gigabeat/meg-fx/usb-meg-fx.c
@@ -20,33 +20,72 @@
20#include <stdbool.h> 20#include <stdbool.h>
21#include "cpu.h" 21#include "cpu.h"
22#include "system.h" 22#include "system.h"
23#include "kernel.h"
23 24
24void usb_init_device(void) 25#define USB_RST_ASSERT GPBDAT &= ~(1 << 4)
25{ 26#define USB_RST_DEASSERT GPBDAT |= (1 << 4)
26} 27
28#define USB_ATA_ENABLE GPBDAT |= (1 << 5)
29#define USB_ATA_DISABLE GPBDAT &= ~(1 << 5)
30
31#define USB_VPLUS_PWR_ASSERT GPBDAT |= (1 << 6)
32#define USB_VPLUS_PWR_DEASSERT GPBDAT &= ~(1 << 6)
27 33
28bool usb_detect(void) 34#define USB_IS_PRESENT (!(GPFDAT & 1))
35
36
37
38/* The usb detect is one pin to the cpu active low */
39inline bool usb_detect(void)
29{ 40{
30 return (GPFDAT & 1) ? false : true; 41 return USB_IS_PRESENT;
31} 42}
32 43
33void usb_enable(bool on)
34{
35 if(on) {
36 int i;
37 44
38 GPBDAT &= 0x7EF;
39 GPBCON |= 1<<8;
40 45
41 GPGDAT &= 0xE7FF; 46void usb_init_device(void)
42 GPGDAT |= 1<<11; 47{
48 USB_VPLUS_PWR_ASSERT;
49 sleep(HZ/20);
50
51 /* Reset the usb port */
52 /* Make sure the cpu pin for reset line is set to output */
53 GPBCON = (GPBCON & ~0x300) | 0x100;
54 USB_RST_ASSERT;
55 sleep(HZ/25);
56 USB_RST_DEASSERT;
57
58 /* needed to complete the reset */
59 USB_ATA_ENABLE;
60
61 sleep(HZ/15); /* 66ms */
62
63 USB_ATA_DISABLE;
64
65 sleep(HZ/25);
66
67 /* leave chip in low power mode */
68 USB_VPLUS_PWR_DEASSERT;
69
70 sleep(HZ/25);
71}
72
43 73
44 for (i = 0; i < 10000000; i++) {continue;}
45 74
46 GPBCON &= 0x2FFCFF; 75void usb_enable(bool on)
47 GPBDAT |= 1<<5; 76{
48 GPBDAT |= 1<<6; 77 if (on)
49 } else { 78 {
50 /* TODO how turn USB mode back off again? */ 79 /* make sure ata_en is high */
80 USB_VPLUS_PWR_ASSERT;
81 USB_ATA_ENABLE;
82 }
83 else
84 {
85 /* make sure ata_en is low */
86 USB_ATA_DISABLE;
87 USB_VPLUS_PWR_DEASSERT;
51 } 88 }
89
90 sleep(HZ/20); // > 50ms for detecting the enable state change
52} 91}