diff options
Diffstat (limited to 'firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c')
-rw-r--r-- | firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c new file mode 100644 index 0000000000..d873c19ed3 --- /dev/null +++ b/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c | |||
@@ -0,0 +1,135 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "config.h" | ||
22 | #include "cpu.h" | ||
23 | #include "system.h" | ||
24 | #include "kernel.h" | ||
25 | #include "ata.h" | ||
26 | #include "usb.h" | ||
27 | #include "usb_core.h" | ||
28 | #include "usb_drv.h" | ||
29 | #include "usb-target.h" | ||
30 | #include "mc13783.h" | ||
31 | #include "ccm-imx31.h" | ||
32 | #include "avic-imx31.h" | ||
33 | #include "power-gigabeat-s.h" | ||
34 | |||
35 | static int usb_status = USB_EXTRACTED; | ||
36 | |||
37 | static void enable_transceiver(bool enable) | ||
38 | { | ||
39 | if (enable) | ||
40 | { | ||
41 | if (GPIO1_DR & (1 << 30)) | ||
42 | { | ||
43 | imx31_regclr32(&GPIO3_DR, (1 << 16)); /* Reset ISP1504 */ | ||
44 | sleep(HZ/100); | ||
45 | imx31_regset32(&GPIO3_DR, (1 << 16)); | ||
46 | sleep(HZ/10); | ||
47 | imx31_regclr32(&GPIO1_DR, (1 << 30)); /* Select ISP1504 */ | ||
48 | } | ||
49 | } | ||
50 | else | ||
51 | { | ||
52 | imx31_regset32(&GPIO1_DR, (1 << 30)); /* Deselect ISP1504 */ | ||
53 | } | ||
54 | } | ||
55 | |||
56 | /* Read the immediate state of the cable from the PMIC */ | ||
57 | bool usb_plugged(void) | ||
58 | { | ||
59 | return mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_USB4V4S; | ||
60 | } | ||
61 | |||
62 | void usb_connect_event(void) | ||
63 | { | ||
64 | int status = usb_plugged() ? USB_INSERTED : USB_EXTRACTED; | ||
65 | usb_status = status; | ||
66 | /* Notify power that USB charging is potentially available */ | ||
67 | charger_usb_detect_event(status); | ||
68 | usb_status_event((status == USB_INSERTED) ? USB_POWERED : USB_UNPOWERED); | ||
69 | } | ||
70 | |||
71 | int usb_detect(void) | ||
72 | { | ||
73 | return usb_status; | ||
74 | } | ||
75 | |||
76 | void usb_init_device(void) | ||
77 | { | ||
78 | /* Do one-time inits */ | ||
79 | usb_drv_startup(); | ||
80 | |||
81 | /* Initially poll */ | ||
82 | usb_connect_event(); | ||
83 | |||
84 | /* Enable PMIC event */ | ||
85 | mc13783_enable_event(MC13783_USB_EVENT); | ||
86 | } | ||
87 | |||
88 | void usb_enable(bool on) | ||
89 | { | ||
90 | /* Module clock should be on since since this could be called with | ||
91 | * OFF initially and writing module registers would hardlock otherwise. */ | ||
92 | ccm_module_clock_gating(CG_USBOTG, CGM_ON_RUN_WAIT); | ||
93 | enable_transceiver(true); | ||
94 | |||
95 | if (on) | ||
96 | { | ||
97 | usb_core_init(); | ||
98 | } | ||
99 | else | ||
100 | { | ||
101 | usb_core_exit(); | ||
102 | enable_transceiver(false); | ||
103 | ccm_module_clock_gating(CG_USBOTG, CGM_OFF); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | void usb_attach(void) | ||
108 | { | ||
109 | usb_drv_attach(); | ||
110 | } | ||
111 | |||
112 | static void __attribute__((interrupt("IRQ"))) USB_OTG_HANDLER(void) | ||
113 | { | ||
114 | usb_drv_int(); /* Call driver handler */ | ||
115 | } | ||
116 | |||
117 | void usb_drv_int_enable(bool enable) | ||
118 | { | ||
119 | if (enable) | ||
120 | { | ||
121 | avic_enable_int(INT_USB_OTG, INT_TYPE_IRQ, INT_PRIO_DEFAULT, | ||
122 | USB_OTG_HANDLER); | ||
123 | } | ||
124 | else | ||
125 | { | ||
126 | avic_disable_int(INT_USB_OTG); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | /* Called during the bus reset interrupt when in detect mode */ | ||
131 | void usb_drv_usb_detect_event(void) | ||
132 | { | ||
133 | if (usb_drv_powered()) | ||
134 | usb_status_event(USB_INSERTED); | ||
135 | } | ||