emdtv_dtv.c revision 1.10 1 1.10 jmcneill /* $NetBSD: emdtv_dtv.c,v 1.10 2013/01/22 12:40:42 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2008, 2011 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 jmcneill * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 jmcneill * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 jmcneill * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 jmcneill * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 jmcneill * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 jmcneill * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 jmcneill * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 jmcneill * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 jmcneill * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 jmcneill * POSSIBILITY OF SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.1 jmcneill #include <sys/cdefs.h>
30 1.10 jmcneill __KERNEL_RCSID(0, "$NetBSD: emdtv_dtv.c,v 1.10 2013/01/22 12:40:42 jmcneill Exp $");
31 1.1 jmcneill
32 1.1 jmcneill #include <sys/param.h>
33 1.1 jmcneill #include <sys/systm.h>
34 1.1 jmcneill #include <sys/device.h>
35 1.1 jmcneill #include <sys/conf.h>
36 1.1 jmcneill
37 1.1 jmcneill #include <dev/usb/usb.h>
38 1.1 jmcneill #include <dev/usb/usbdi.h>
39 1.1 jmcneill #include <dev/usb/usbdi_util.h>
40 1.9 mrg #include <dev/usb/usbdivar.h>
41 1.1 jmcneill #include <dev/usb/usbdevs.h>
42 1.1 jmcneill
43 1.1 jmcneill #include <dev/i2c/i2cvar.h>
44 1.1 jmcneill
45 1.1 jmcneill #include <dev/usb/emdtvvar.h>
46 1.1 jmcneill #include <dev/usb/emdtvreg.h>
47 1.1 jmcneill
48 1.1 jmcneill static void emdtv_dtv_get_devinfo(void *,
49 1.1 jmcneill struct dvb_frontend_info *);
50 1.1 jmcneill static int emdtv_dtv_open(void *, int);
51 1.1 jmcneill static void emdtv_dtv_close(void *);
52 1.1 jmcneill static int emdtv_dtv_set_tuner(void *,
53 1.1 jmcneill const struct dvb_frontend_parameters *);
54 1.1 jmcneill static fe_status_t emdtv_dtv_get_status(void *);
55 1.1 jmcneill static uint16_t emdtv_dtv_get_signal_strength(void *);
56 1.1 jmcneill static uint16_t emdtv_dtv_get_snr(void *);
57 1.5 jmcneill static int emdtv_dtv_start_transfer(void *,
58 1.5 jmcneill void (*)(void *, const struct dtv_payload *),
59 1.5 jmcneill void *);
60 1.1 jmcneill static int emdtv_dtv_stop_transfer(void *);
61 1.1 jmcneill
62 1.1 jmcneill static int emdtv_dtv_tuner_reset(void *);
63 1.1 jmcneill
64 1.1 jmcneill static void emdtv_dtv_isoc_startall(struct emdtv_softc *);
65 1.1 jmcneill static int emdtv_dtv_isoc_start(struct emdtv_softc *,
66 1.1 jmcneill struct emdtv_isoc_xfer *);
67 1.1 jmcneill static void emdtv_dtv_isoc(usbd_xfer_handle, usbd_private_handle,
68 1.1 jmcneill usbd_status);
69 1.1 jmcneill
70 1.1 jmcneill static const struct dtv_hw_if emdtv_dtv_if = {
71 1.1 jmcneill .get_devinfo = emdtv_dtv_get_devinfo,
72 1.1 jmcneill .open = emdtv_dtv_open,
73 1.1 jmcneill .close = emdtv_dtv_close,
74 1.1 jmcneill .set_tuner = emdtv_dtv_set_tuner,
75 1.1 jmcneill .get_status = emdtv_dtv_get_status,
76 1.1 jmcneill .get_signal_strength = emdtv_dtv_get_signal_strength,
77 1.1 jmcneill .get_snr = emdtv_dtv_get_snr,
78 1.1 jmcneill .start_transfer = emdtv_dtv_start_transfer,
79 1.1 jmcneill .stop_transfer = emdtv_dtv_stop_transfer,
80 1.1 jmcneill };
81 1.1 jmcneill
82 1.1 jmcneill void
83 1.1 jmcneill emdtv_dtv_attach(struct emdtv_softc *sc)
84 1.1 jmcneill {
85 1.1 jmcneill usb_endpoint_descriptor_t *ed;
86 1.1 jmcneill usbd_status status;
87 1.1 jmcneill int i;
88 1.1 jmcneill
89 1.1 jmcneill for (i = 0; i < EMDTV_NXFERS; i++) {
90 1.1 jmcneill sc->sc_ix[i].ix_altix = (i & 1) ?
91 1.1 jmcneill &sc->sc_ix[i - 1] : &sc->sc_ix[i + 1];
92 1.1 jmcneill sc->sc_ix[i].ix_sc = sc;
93 1.1 jmcneill }
94 1.1 jmcneill
95 1.1 jmcneill ed = usbd_interface2endpoint_descriptor(sc->sc_iface, 3);
96 1.1 jmcneill if (ed == NULL) {
97 1.1 jmcneill aprint_error_dev(sc->sc_dev, "couldn't find endpoint 3\n");
98 1.1 jmcneill return;
99 1.1 jmcneill }
100 1.1 jmcneill sc->sc_isoc_maxpacketsize = UGETW(ed->wMaxPacketSize);
101 1.1 jmcneill sc->sc_isoc_buflen = sc->sc_isoc_maxpacketsize * EMDTV_NFRAMES;
102 1.1 jmcneill
103 1.1 jmcneill aprint_debug_dev(sc->sc_dev, "calling usbd_open_pipe, ep 0x%02x\n",
104 1.1 jmcneill ed->bEndpointAddress);
105 1.7 jakllsch status = usbd_open_pipe(sc->sc_iface,
106 1.10 jmcneill ed->bEndpointAddress, USBD_EXCLUSIVE_USE|USBD_MPSAFE,
107 1.1 jmcneill &sc->sc_isoc_pipe);
108 1.1 jmcneill if (status != USBD_NORMAL_COMPLETION) {
109 1.1 jmcneill aprint_error_dev(sc->sc_dev, "couldn't open isoc pipe\n");
110 1.1 jmcneill usbd_set_interface(sc->sc_iface, 0);
111 1.1 jmcneill return;
112 1.1 jmcneill }
113 1.1 jmcneill
114 1.1 jmcneill emdtv_write_1(sc, UR_GET_STATUS, 0x48, 0x00);
115 1.1 jmcneill emdtv_write_1(sc, UR_GET_STATUS, 0x12, 0x77);
116 1.1 jmcneill usbd_delay_ms(sc->sc_udev, 6);
117 1.1 jmcneill
118 1.1 jmcneill emdtv_gpio_ctl(sc, EMDTV_GPIO_ANALOG_ON, false);
119 1.1 jmcneill emdtv_gpio_ctl(sc, EMDTV_GPIO_TS1_ON, true);
120 1.1 jmcneill emdtv_gpio_ctl(sc, EMDTV_GPIO_TUNER1_ON, true);
121 1.1 jmcneill emdtv_gpio_ctl(sc, EMDTV_GPIO_DEMOD1_RESET, true);
122 1.1 jmcneill usbd_delay_ms(sc->sc_udev, 100);
123 1.1 jmcneill
124 1.5 jmcneill emdtv_dtv_rescan(sc, NULL, NULL);
125 1.1 jmcneill }
126 1.1 jmcneill
127 1.1 jmcneill void
128 1.1 jmcneill emdtv_dtv_detach(struct emdtv_softc *sc, int flags)
129 1.1 jmcneill {
130 1.1 jmcneill sc->sc_streaming = false;
131 1.1 jmcneill
132 1.1 jmcneill if (sc->sc_dtvdev != NULL) {
133 1.1 jmcneill config_detach(sc->sc_dtvdev, flags);
134 1.1 jmcneill sc->sc_dtvdev = NULL;
135 1.1 jmcneill }
136 1.1 jmcneill
137 1.1 jmcneill if (sc->sc_xc3028)
138 1.1 jmcneill xc3028_close(sc->sc_xc3028);
139 1.1 jmcneill if (sc->sc_lg3303)
140 1.1 jmcneill lg3303_close(sc->sc_lg3303);
141 1.1 jmcneill
142 1.1 jmcneill if (sc->sc_isoc_pipe) {
143 1.1 jmcneill usbd_abort_pipe(sc->sc_isoc_pipe);
144 1.1 jmcneill usbd_close_pipe(sc->sc_isoc_pipe);
145 1.1 jmcneill sc->sc_isoc_pipe = NULL;
146 1.1 jmcneill }
147 1.1 jmcneill }
148 1.1 jmcneill
149 1.5 jmcneill void
150 1.5 jmcneill emdtv_dtv_rescan(struct emdtv_softc *sc, const char *ifattr, const int *locs)
151 1.5 jmcneill {
152 1.5 jmcneill struct dtv_attach_args daa;
153 1.5 jmcneill
154 1.5 jmcneill daa.hw = &emdtv_dtv_if;
155 1.5 jmcneill daa.priv = sc;
156 1.5 jmcneill
157 1.5 jmcneill if (ifattr_match(ifattr, "dtvbus") && sc->sc_dtvdev == NULL)
158 1.5 jmcneill sc->sc_dtvdev = config_found_ia(sc->sc_dev, "dtvbus",
159 1.5 jmcneill &daa, dtv_print);
160 1.5 jmcneill }
161 1.5 jmcneill
162 1.1 jmcneill static void
163 1.1 jmcneill emdtv_dtv_get_devinfo(void *priv, struct dvb_frontend_info *info)
164 1.1 jmcneill {
165 1.1 jmcneill struct emdtv_softc *sc = priv;
166 1.1 jmcneill
167 1.1 jmcneill memset(info, 0, sizeof(*info));
168 1.1 jmcneill strlcpy(info->name, sc->sc_board->eb_name, sizeof(info->name));
169 1.1 jmcneill info->type = FE_ATSC;
170 1.1 jmcneill info->frequency_min = 54000000;
171 1.1 jmcneill info->frequency_max = 858000000;
172 1.1 jmcneill info->frequency_stepsize = 62500;
173 1.1 jmcneill info->caps = FE_CAN_8VSB;
174 1.1 jmcneill }
175 1.1 jmcneill
176 1.1 jmcneill static int
177 1.1 jmcneill emdtv_dtv_open(void *priv, int flags)
178 1.1 jmcneill {
179 1.1 jmcneill struct emdtv_softc *sc = priv;
180 1.1 jmcneill
181 1.1 jmcneill if (sc->sc_dying)
182 1.1 jmcneill return ENXIO;
183 1.1 jmcneill
184 1.1 jmcneill switch (sc->sc_board->eb_tuner) {
185 1.2 jakllsch case EMDTV_TUNER_XC3028:
186 1.2 jakllsch if (sc->sc_xc3028 == NULL) {
187 1.2 jakllsch sc->sc_xc3028 = xc3028_open(sc->sc_dev,
188 1.2 jakllsch &sc->sc_i2c, 0x61 << 1, emdtv_dtv_tuner_reset, sc,
189 1.2 jakllsch XC3028);
190 1.2 jakllsch }
191 1.2 jakllsch if (sc->sc_xc3028 == NULL) {
192 1.2 jakllsch aprint_error_dev(sc->sc_dev, "couldn't open xc3028\n");
193 1.2 jakllsch return ENXIO;
194 1.2 jakllsch }
195 1.2 jakllsch break;
196 1.1 jmcneill case EMDTV_TUNER_XC3028L:
197 1.1 jmcneill if (sc->sc_xc3028 == NULL) {
198 1.1 jmcneill sc->sc_xc3028 = xc3028_open(sc->sc_dev,
199 1.1 jmcneill &sc->sc_i2c, 0x61 << 1, emdtv_dtv_tuner_reset, sc,
200 1.1 jmcneill XC3028L);
201 1.1 jmcneill }
202 1.1 jmcneill if (sc->sc_xc3028 == NULL) {
203 1.1 jmcneill aprint_error_dev(sc->sc_dev, "couldn't open xc3028l\n");
204 1.1 jmcneill return ENXIO;
205 1.1 jmcneill }
206 1.1 jmcneill break;
207 1.1 jmcneill default:
208 1.1 jmcneill aprint_error_dev(sc->sc_dev, "unsupported tuner (%d)\n",
209 1.1 jmcneill sc->sc_board->eb_tuner);
210 1.1 jmcneill return EIO;
211 1.1 jmcneill }
212 1.1 jmcneill
213 1.1 jmcneill switch (sc->sc_board->eb_demod) {
214 1.1 jmcneill case EMDTV_DEMOD_LG3303:
215 1.1 jmcneill if (sc->sc_lg3303 == NULL) {
216 1.1 jmcneill sc->sc_lg3303 = lg3303_open(sc->sc_dev,
217 1.3 jmcneill &sc->sc_i2c, 0x1c, 0);
218 1.1 jmcneill }
219 1.1 jmcneill if (sc->sc_lg3303 == NULL) {
220 1.1 jmcneill aprint_error_dev(sc->sc_dev, "couldn't open lg3303\n");
221 1.1 jmcneill return ENXIO;
222 1.1 jmcneill }
223 1.1 jmcneill break;
224 1.1 jmcneill default:
225 1.1 jmcneill aprint_error_dev(sc->sc_dev, "unsupported demod (%d)\n",
226 1.1 jmcneill sc->sc_board->eb_demod);
227 1.1 jmcneill return EIO;
228 1.1 jmcneill }
229 1.1 jmcneill
230 1.1 jmcneill return 0;
231 1.1 jmcneill }
232 1.1 jmcneill
233 1.1 jmcneill static void
234 1.1 jmcneill emdtv_dtv_close(void *priv)
235 1.1 jmcneill {
236 1.1 jmcneill return;
237 1.1 jmcneill }
238 1.1 jmcneill
239 1.1 jmcneill static int
240 1.1 jmcneill emdtv_dtv_set_tuner(void *priv, const struct dvb_frontend_parameters *params)
241 1.1 jmcneill {
242 1.1 jmcneill struct emdtv_softc *sc = priv;
243 1.1 jmcneill int error;
244 1.1 jmcneill
245 1.1 jmcneill /* Setup demod */
246 1.1 jmcneill error = ENXIO;
247 1.1 jmcneill if (sc->sc_lg3303)
248 1.1 jmcneill error = lg3303_set_modulation(sc->sc_lg3303,
249 1.1 jmcneill params->u.vsb.modulation);
250 1.1 jmcneill if (error)
251 1.1 jmcneill return error;
252 1.1 jmcneill
253 1.1 jmcneill /* Setup tuner */
254 1.1 jmcneill error = ENXIO;
255 1.1 jmcneill if (sc->sc_xc3028)
256 1.1 jmcneill error = xc3028_tune_dtv(sc->sc_xc3028, params);
257 1.1 jmcneill
258 1.1 jmcneill return error;
259 1.1 jmcneill }
260 1.1 jmcneill
261 1.1 jmcneill static fe_status_t
262 1.1 jmcneill emdtv_dtv_get_status(void *priv)
263 1.1 jmcneill {
264 1.1 jmcneill struct emdtv_softc *sc = priv;
265 1.1 jmcneill
266 1.1 jmcneill if (sc->sc_lg3303)
267 1.1 jmcneill return lg3303_get_dtv_status(sc->sc_lg3303);
268 1.1 jmcneill
269 1.1 jmcneill return 0;
270 1.1 jmcneill }
271 1.1 jmcneill
272 1.1 jmcneill uint16_t
273 1.1 jmcneill emdtv_dtv_get_signal_strength(void *priv)
274 1.1 jmcneill {
275 1.4 jmcneill struct emdtv_softc *sc = priv;
276 1.4 jmcneill
277 1.4 jmcneill if (sc->sc_lg3303)
278 1.4 jmcneill return lg3303_get_signal_strength(sc->sc_lg3303);
279 1.4 jmcneill
280 1.1 jmcneill return 0;
281 1.1 jmcneill }
282 1.1 jmcneill
283 1.1 jmcneill uint16_t
284 1.1 jmcneill emdtv_dtv_get_snr(void *priv)
285 1.1 jmcneill {
286 1.4 jmcneill struct emdtv_softc *sc = priv;
287 1.4 jmcneill
288 1.4 jmcneill if (sc->sc_lg3303)
289 1.4 jmcneill return lg3303_get_snr(sc->sc_lg3303);
290 1.4 jmcneill
291 1.1 jmcneill return 0;
292 1.1 jmcneill }
293 1.1 jmcneill
294 1.1 jmcneill static int
295 1.5 jmcneill emdtv_dtv_start_transfer(void *priv,
296 1.5 jmcneill void (*cb)(void *, const struct dtv_payload *), void *arg)
297 1.1 jmcneill {
298 1.1 jmcneill struct emdtv_softc *sc = priv;
299 1.1 jmcneill int i, s;
300 1.1 jmcneill
301 1.1 jmcneill s = splusb();
302 1.1 jmcneill
303 1.1 jmcneill sc->sc_streaming = true;
304 1.5 jmcneill sc->sc_dtvsubmitcb = cb;
305 1.5 jmcneill sc->sc_dtvsubmitarg = arg;
306 1.1 jmcneill
307 1.1 jmcneill aprint_debug_dev(sc->sc_dev, "allocating isoc xfers (pktsz %d)\n",
308 1.1 jmcneill sc->sc_isoc_maxpacketsize);
309 1.1 jmcneill
310 1.8 jmcneill KERNEL_LOCK(1, curlwp);
311 1.1 jmcneill for (i = 0; i < EMDTV_NXFERS; i++) {
312 1.1 jmcneill sc->sc_ix[i].ix_xfer = usbd_alloc_xfer(sc->sc_udev);
313 1.1 jmcneill sc->sc_ix[i].ix_buf = usbd_alloc_buffer(sc->sc_ix[i].ix_xfer,
314 1.1 jmcneill sc->sc_isoc_buflen);
315 1.1 jmcneill aprint_debug_dev(sc->sc_dev, " ix[%d] xfer %p buf %p\n",
316 1.1 jmcneill i, sc->sc_ix[i].ix_xfer, sc->sc_ix[i].ix_buf);
317 1.1 jmcneill }
318 1.8 jmcneill KERNEL_UNLOCK_ONE(curlwp);
319 1.1 jmcneill
320 1.1 jmcneill aprint_debug_dev(sc->sc_dev, "starting isoc transactions\n");
321 1.1 jmcneill
322 1.1 jmcneill emdtv_dtv_isoc_startall(sc);
323 1.1 jmcneill splx(s);
324 1.1 jmcneill
325 1.1 jmcneill return 0;
326 1.1 jmcneill }
327 1.1 jmcneill
328 1.1 jmcneill static int
329 1.1 jmcneill emdtv_dtv_stop_transfer(void *priv)
330 1.1 jmcneill {
331 1.1 jmcneill struct emdtv_softc *sc = priv;
332 1.1 jmcneill int i;
333 1.1 jmcneill
334 1.1 jmcneill aprint_debug_dev(sc->sc_dev, "stopping stream\n");
335 1.1 jmcneill
336 1.1 jmcneill sc->sc_streaming = false;
337 1.1 jmcneill
338 1.8 jmcneill KERNEL_LOCK(1, curlwp);
339 1.1 jmcneill if (sc->sc_isoc_pipe != NULL)
340 1.1 jmcneill usbd_abort_pipe(sc->sc_isoc_pipe);
341 1.1 jmcneill
342 1.1 jmcneill for (i = 0; i < EMDTV_NXFERS; i++)
343 1.1 jmcneill if (sc->sc_ix[i].ix_xfer) {
344 1.1 jmcneill usbd_free_xfer(sc->sc_ix[i].ix_xfer);
345 1.1 jmcneill sc->sc_ix[i].ix_xfer = NULL;
346 1.1 jmcneill sc->sc_ix[i].ix_buf = NULL;
347 1.1 jmcneill }
348 1.8 jmcneill KERNEL_UNLOCK_ONE(curlwp);
349 1.1 jmcneill
350 1.5 jmcneill sc->sc_dtvsubmitcb = NULL;
351 1.5 jmcneill sc->sc_dtvsubmitarg = NULL;
352 1.5 jmcneill
353 1.1 jmcneill return 0;
354 1.1 jmcneill }
355 1.1 jmcneill
356 1.1 jmcneill static void
357 1.1 jmcneill emdtv_dtv_isoc_startall(struct emdtv_softc *sc)
358 1.1 jmcneill {
359 1.1 jmcneill int i;
360 1.1 jmcneill
361 1.1 jmcneill if (sc->sc_streaming == false || sc->sc_dying == true)
362 1.1 jmcneill return;
363 1.1 jmcneill
364 1.1 jmcneill for (i = 0; i < EMDTV_NXFERS; i += 2)
365 1.1 jmcneill emdtv_dtv_isoc_start(sc, &sc->sc_ix[i]);
366 1.1 jmcneill }
367 1.1 jmcneill
368 1.1 jmcneill static int
369 1.1 jmcneill emdtv_dtv_isoc_start(struct emdtv_softc *sc, struct emdtv_isoc_xfer *ix)
370 1.1 jmcneill {
371 1.1 jmcneill int i;
372 1.1 jmcneill
373 1.1 jmcneill if (sc->sc_isoc_pipe == NULL)
374 1.1 jmcneill return EIO;
375 1.1 jmcneill
376 1.1 jmcneill for (i = 0; i < EMDTV_NFRAMES; i++)
377 1.1 jmcneill ix->ix_frlengths[i] = sc->sc_isoc_maxpacketsize;
378 1.1 jmcneill
379 1.1 jmcneill usbd_setup_isoc_xfer(ix->ix_xfer,
380 1.1 jmcneill sc->sc_isoc_pipe,
381 1.1 jmcneill ix,
382 1.1 jmcneill ix->ix_frlengths,
383 1.1 jmcneill EMDTV_NFRAMES,
384 1.1 jmcneill USBD_NO_COPY | USBD_SHORT_XFER_OK,
385 1.1 jmcneill emdtv_dtv_isoc);
386 1.8 jmcneill
387 1.8 jmcneill KERNEL_LOCK(1, curlwp);
388 1.1 jmcneill usbd_transfer(ix->ix_xfer);
389 1.8 jmcneill KERNEL_UNLOCK_ONE(curlwp);
390 1.1 jmcneill
391 1.1 jmcneill return 0;
392 1.1 jmcneill }
393 1.1 jmcneill
394 1.1 jmcneill static void
395 1.1 jmcneill emdtv_dtv_isoc(usbd_xfer_handle xfer, usbd_private_handle priv,
396 1.1 jmcneill usbd_status err)
397 1.1 jmcneill {
398 1.1 jmcneill struct emdtv_isoc_xfer *ix = priv;
399 1.1 jmcneill struct emdtv_softc *sc = ix->ix_sc;
400 1.1 jmcneill struct dtv_payload payload;
401 1.1 jmcneill usbd_pipe_handle isoc = sc->sc_isoc_pipe;
402 1.1 jmcneill uint32_t len;
403 1.1 jmcneill uint8_t *buf;
404 1.1 jmcneill int i;
405 1.1 jmcneill
406 1.1 jmcneill KASSERT(xfer == ix->ix_xfer);
407 1.1 jmcneill
408 1.5 jmcneill if (sc->sc_dying || sc->sc_dtvsubmitcb == NULL)
409 1.1 jmcneill return;
410 1.1 jmcneill
411 1.1 jmcneill if (err) {
412 1.1 jmcneill if (err == USBD_STALLED) {
413 1.1 jmcneill usbd_clear_endpoint_stall_async(isoc);
414 1.1 jmcneill goto resched;
415 1.1 jmcneill }
416 1.1 jmcneill return;
417 1.1 jmcneill }
418 1.1 jmcneill
419 1.1 jmcneill usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL);
420 1.1 jmcneill
421 1.1 jmcneill if (len == 0)
422 1.1 jmcneill goto resched;
423 1.1 jmcneill
424 1.1 jmcneill buf = usbd_get_buffer(xfer);
425 1.1 jmcneill if (buf == NULL)
426 1.1 jmcneill goto resched;
427 1.1 jmcneill
428 1.1 jmcneill for (i = 0; i < EMDTV_NFRAMES; i++, buf += sc->sc_isoc_maxpacketsize) {
429 1.1 jmcneill if (ix->ix_frlengths[i] == 0)
430 1.1 jmcneill continue;
431 1.1 jmcneill payload.data = buf;
432 1.1 jmcneill payload.size = ix->ix_frlengths[i];
433 1.5 jmcneill sc->sc_dtvsubmitcb(sc->sc_dtvsubmitarg, &payload);
434 1.1 jmcneill }
435 1.1 jmcneill
436 1.1 jmcneill resched:
437 1.1 jmcneill emdtv_dtv_isoc_start(sc, ix->ix_altix);
438 1.1 jmcneill }
439 1.1 jmcneill
440 1.1 jmcneill static int
441 1.1 jmcneill emdtv_dtv_tuner_reset(void *opaque)
442 1.1 jmcneill {
443 1.1 jmcneill struct emdtv_softc *sc = opaque;
444 1.1 jmcneill emdtv_gpio_ctl(sc, EMDTV_GPIO_TUNER1_RESET, true);
445 1.1 jmcneill return 0;
446 1.1 jmcneill }
447