| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: zusb.c,v 1.2 2009/01/28 14:06:15 nonaka Exp $ */ | | 1 | /* $NetBSD: zusb.c,v 1.3 2009/01/28 14:15:56 nonaka Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2008 Christopher Gilbert | | 4 | * Copyright (c) 2008 Christopher Gilbert |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * 1. Redistributions of source code must retain the above copyright | | 7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright | | 9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | | 11 | * documentation and/or other materials provided with the distribution. |
12 | * 3. The name of the company nor the name of the author may be used to | | 12 | * 3. The name of the company nor the name of the author may be used to |
13 | * endorse or promote products derived from this software without specific | | 13 | * endorse or promote products derived from this software without specific |
14 | * prior written permission. | | 14 | * prior written permission. |
| @@ -17,144 +17,145 @@ | | | @@ -17,144 +17,145 @@ |
17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | | 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
20 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | 20 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
22 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 22 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: zusb.c,v 1.2 2009/01/28 14:06:15 nonaka Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: zusb.c,v 1.3 2009/01/28 14:15:56 nonaka Exp $"); |
31 | | | 31 | |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | #include <sys/device.h> | | 33 | #include <sys/device.h> |
34 | #include <sys/kernel.h> | | 34 | #include <sys/kernel.h> |
35 | | | 35 | |
36 | #include <arm/xscale/pxa2x0reg.h> | | 36 | #include <arm/xscale/pxa2x0reg.h> |
37 | #include <arm/xscale/pxa2x0var.h> | | 37 | #include <arm/xscale/pxa2x0var.h> |
38 | #include <arm/xscale/pxa2x0_gpio.h> | | 38 | #include <arm/xscale/pxa2x0_gpio.h> |
39 | | | 39 | |
40 | #include <machine/intr.h> | | 40 | #include <machine/intr.h> |
41 | #include <machine/bus.h> | | 41 | #include <machine/bus.h> |
42 | | | 42 | |
43 | #include <zaurus/zaurus/zaurus_reg.h> | | 43 | #include <zaurus/zaurus/zaurus_reg.h> |
44 | #include <zaurus/zaurus/zaurus_var.h> | | 44 | #include <zaurus/zaurus/zaurus_var.h> |
45 | | | 45 | |
46 | | | 46 | |
47 | #ifdef ZUSB_DEBUG | | 47 | #ifdef ZUSB_DEBUG |
48 | #define DPRINTF(s) printf s | | 48 | #define DPRINTF(s) printf s |
49 | #else | | 49 | #else |
50 | #define DPRINTF(s) | | 50 | #define DPRINTF(s) |
51 | #endif | | 51 | #endif |
52 | | | 52 | |
53 | | | 53 | |
54 | struct zusb_softc { | | 54 | struct zusb_softc { |
55 | struct device sc_dev; | | 55 | device_t sc_dev; |
56 | | | 56 | |
57 | bus_space_tag_t sc_iot; | | 57 | bus_space_tag_t sc_iot; |
58 | bus_space_handle_t sc_ioh; | | 58 | bus_space_handle_t sc_ioh; |
59 | | | 59 | |
60 | void *sc_client_ih; | | 60 | void *sc_client_ih; |
61 | void *sc_host_ih; | | 61 | void *sc_host_ih; |
62 | }; | | 62 | }; |
63 | | | 63 | |
64 | static int zusb_match(struct device *, struct cfdata *, void *); | | 64 | static int zusb_match(struct device *, struct cfdata *, void *); |
65 | static void zusb_attach(struct device *, struct device *, void *); | | 65 | static void zusb_attach(struct device *, struct device *, void *); |
66 | | | 66 | |
67 | CFATTACH_DECL(zusb, sizeof(struct zusb_softc), | | 67 | CFATTACH_DECL_NEW(zusb, sizeof(struct zusb_softc), |
68 | zusb_match, zusb_attach, NULL, NULL); | | 68 | zusb_match, zusb_attach, NULL, NULL); |
69 | | | 69 | |
70 | static int zusb_client_intr(void *); | | 70 | static int zusb_client_intr(void *); |
71 | static int zusb_host_intr(void *); | | 71 | static int zusb_host_intr(void *); |
72 | static void zusb_test_and_enabled_host_port(struct zusb_softc *); | | 72 | static void zusb_test_and_enabled_host_port(struct zusb_softc *); |
73 | | | 73 | |
74 | static int | | 74 | static int |
75 | zusb_match(struct device *parent, struct cfdata *cf, void *aux) | | 75 | zusb_match(device_t parent, cfdata_t cf, void *aux) |
76 | { | | 76 | { |
77 | | | 77 | |
78 | if (ZAURUS_ISC3000) | | 78 | if (ZAURUS_ISC3000) |
79 | return 1; | | 79 | return 1; |
80 | return 0; | | 80 | return 0; |
81 | } | | 81 | } |
82 | | | 82 | |
83 | static void | | 83 | static void |
84 | zusb_attach(struct device *parent, struct device *self, void *aux) | | 84 | zusb_attach(device_t parent, device_t self, void *aux) |
85 | { | | 85 | { |
86 | struct zusb_softc *sc = (struct zusb_softc *)self; | | 86 | struct zusb_softc *sc = device_private(self); |
87 | struct pxaip_attach_args *pxa = aux; | | 87 | struct pxaip_attach_args *pxa = aux; |
88 | | | 88 | |
89 | aprint_normal(": USB Mode detection\n"); | | 89 | aprint_normal(": USB Mode detection\n"); |
90 | | | 90 | |
| | | 91 | sc->sc_dev = self; |
91 | sc->sc_iot = pxa->pxa_iot; | | 92 | sc->sc_iot = pxa->pxa_iot; |
92 | | | 93 | |
93 | /* Map I/O space */ | | 94 | /* Map I/O space */ |
94 | if (bus_space_map(sc->sc_iot, PXA2X0_USBDC_BASE, PXA270_USBDC_SIZE, 0, | | 95 | if (bus_space_map(sc->sc_iot, PXA2X0_USBDC_BASE, PXA270_USBDC_SIZE, 0, |
95 | &sc->sc_ioh)) { | | 96 | &sc->sc_ioh)) { |
96 | aprint_error_dev(&sc->sc_dev, "couldn't map memory space\n"); | | 97 | aprint_error_dev(sc->sc_dev, "couldn't map memory space\n"); |
97 | return; | | 98 | return; |
98 | } | | 99 | } |
99 | | | 100 | |
100 | pxa2x0_gpio_set_function(C3000_USB_DEVICE_PIN, GPIO_IN); | | 101 | pxa2x0_gpio_set_function(C3000_USB_DEVICE_PIN, GPIO_IN); |
101 | sc->sc_client_ih = pxa2x0_gpio_intr_establish(C3000_USB_DEVICE_PIN, | | 102 | sc->sc_client_ih = pxa2x0_gpio_intr_establish(C3000_USB_DEVICE_PIN, |
102 | IST_EDGE_BOTH, IPL_BIO, zusb_client_intr, sc); | | 103 | IST_EDGE_BOTH, IPL_BIO, zusb_client_intr, sc); |
103 | | | 104 | |
104 | pxa2x0_gpio_set_function(C3000_USB_HOST_PIN, GPIO_IN); | | 105 | pxa2x0_gpio_set_function(C3000_USB_HOST_PIN, GPIO_IN); |
105 | sc->sc_host_ih = pxa2x0_gpio_intr_establish(C3000_USB_HOST_PIN, | | 106 | sc->sc_host_ih = pxa2x0_gpio_intr_establish(C3000_USB_HOST_PIN, |
106 | IST_EDGE_BOTH, IPL_BIO, zusb_host_intr, sc); | | 107 | IST_EDGE_BOTH, IPL_BIO, zusb_host_intr, sc); |
107 | | | 108 | |
108 | /* configure port 2 for input */ | | 109 | /* configure port 2 for input */ |
109 | bus_space_write_4(sc->sc_iot, sc->sc_ioh, USBDC_UP2OCR, | | 110 | bus_space_write_4(sc->sc_iot, sc->sc_ioh, USBDC_UP2OCR, |
110 | USBDC_UP2OCR_HXS | USBDC_UP2OCR_HXOE | | | 111 | USBDC_UP2OCR_HXS | USBDC_UP2OCR_HXOE | |
111 | USBDC_UP2OCR_DPPDE | USBDC_UP2OCR_DMPDE); | | 112 | USBDC_UP2OCR_DPPDE | USBDC_UP2OCR_DMPDE); |
112 | | | 113 | |
113 | zusb_test_and_enabled_host_port(sc); | | 114 | zusb_test_and_enabled_host_port(sc); |
114 | } | | 115 | } |
115 | | | 116 | |
116 | static int | | 117 | static int |
117 | zusb_client_intr(void *v) | | 118 | zusb_client_intr(void *v) |
118 | { | | 119 | { |
119 | struct zusb_softc *sc = v; | | 120 | struct zusb_softc *sc = v; |
120 | | | 121 | |
121 | DPRINTF(("%s: USB client cable changed\n", device_xname(&sc->sc_dev))); | | 122 | DPRINTF(("%s: USB client cable changed\n", device_xname(sc->sc_dev))); |
122 | zusb_test_and_enabled_host_port(sc); | | 123 | zusb_test_and_enabled_host_port(sc); |
123 | | | 124 | |
124 | return 1; | | 125 | return 1; |
125 | } | | 126 | } |
126 | | | 127 | |
127 | static int | | 128 | static int |
128 | zusb_host_intr(void *v) | | 129 | zusb_host_intr(void *v) |
129 | { | | 130 | { |
130 | struct zusb_softc *sc = v; | | 131 | struct zusb_softc *sc = v; |
131 | | | 132 | |
132 | DPRINTF(("%s: USB host cable changed\n", device_xname(&sc->sc_dev))); | | 133 | DPRINTF(("%s: USB host cable changed\n", device_xname(sc->sc_dev))); |
133 | zusb_test_and_enabled_host_port(sc); | | 134 | zusb_test_and_enabled_host_port(sc); |
134 | | | 135 | |
135 | return 1; | | 136 | return 1; |
136 | } | | 137 | } |
137 | | | 138 | |
138 | static void | | 139 | static void |
139 | zusb_test_and_enabled_host_port(struct zusb_softc *sc) | | 140 | zusb_test_and_enabled_host_port(struct zusb_softc *sc) |
140 | { | | 141 | { |
141 | int host_cable = pxa2x0_gpio_get_bit(C3000_USB_HOST_PIN); | | 142 | int host_cable = pxa2x0_gpio_get_bit(C3000_USB_HOST_PIN); |
142 | #ifdef ZUSB_DEBUG | | 143 | #ifdef ZUSB_DEBUG |
143 | int client_cable = pxa2x0_gpio_get_bit(C3000_USB_DEVICE_PIN); | | 144 | int client_cable = pxa2x0_gpio_get_bit(C3000_USB_DEVICE_PIN); |
144 | #endif | | 145 | #endif |
145 | | | 146 | |
146 | DPRINTF(("%s: USB cable: host %d, client %d\n", | | 147 | DPRINTF(("%s: USB cable: host %d, client %d\n", |
147 | device_xname(&sc->sc_dev), host_cable, client_cable)); | | 148 | device_xname(sc->sc_dev), host_cable, client_cable)); |
148 | | | 149 | |
149 | if (!host_cable) { | | 150 | if (!host_cable) { |
150 | pxa2x0_gpio_set_function(C3000_USB_HOST_POWER_PIN, | | 151 | pxa2x0_gpio_set_function(C3000_USB_HOST_POWER_PIN, |
151 | GPIO_OUT | GPIO_SET); | | 152 | GPIO_OUT | GPIO_SET); |
152 | DPRINTF(("%s: USB host power enabled\n", | | 153 | DPRINTF(("%s: USB host power enabled\n", |
153 | device_xname(&sc->sc_dev))); | | 154 | device_xname(sc->sc_dev))); |
154 | } else { | | 155 | } else { |
155 | pxa2x0_gpio_set_function(C3000_USB_HOST_POWER_PIN, | | 156 | pxa2x0_gpio_set_function(C3000_USB_HOST_POWER_PIN, |
156 | GPIO_OUT | GPIO_CLR); | | 157 | GPIO_OUT | GPIO_CLR); |
157 | DPRINTF(("%s: USB host power disabled\n", | | 158 | DPRINTF(("%s: USB host power disabled\n", |
158 | device_xname(&sc->sc_dev))); | | 159 | device_xname(sc->sc_dev))); |
159 | } | | 160 | } |
160 | } | | 161 | } |