Home | History | Annotate | Line # | Download | only in usb
emdtv_dtv.c revision 1.2
      1  1.2  jakllsch /* $NetBSD: emdtv_dtv.c,v 1.2 2011/07/13 14:34:45 jakllsch 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.2  jakllsch __KERNEL_RCSID(0, "$NetBSD: emdtv_dtv.c,v 1.2 2011/07/13 14:34:45 jakllsch 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.1  jmcneill #include <dev/usb/usbdevs.h>
     41  1.1  jmcneill 
     42  1.1  jmcneill #include <dev/i2c/i2cvar.h>
     43  1.1  jmcneill 
     44  1.1  jmcneill #include <dev/usb/emdtvvar.h>
     45  1.1  jmcneill #include <dev/usb/emdtvreg.h>
     46  1.1  jmcneill 
     47  1.1  jmcneill static void		emdtv_dtv_get_devinfo(void *,
     48  1.1  jmcneill 			    struct dvb_frontend_info *);
     49  1.1  jmcneill static int		emdtv_dtv_open(void *, int);
     50  1.1  jmcneill static void		emdtv_dtv_close(void *);
     51  1.1  jmcneill static int		emdtv_dtv_set_tuner(void *,
     52  1.1  jmcneill 			    const struct dvb_frontend_parameters *);
     53  1.1  jmcneill static fe_status_t	emdtv_dtv_get_status(void *);
     54  1.1  jmcneill static uint16_t		emdtv_dtv_get_signal_strength(void *);
     55  1.1  jmcneill static uint16_t		emdtv_dtv_get_snr(void *);
     56  1.1  jmcneill static int		emdtv_dtv_start_transfer(void *);
     57  1.1  jmcneill static int		emdtv_dtv_stop_transfer(void *);
     58  1.1  jmcneill 
     59  1.1  jmcneill static int		emdtv_dtv_tuner_reset(void *);
     60  1.1  jmcneill 
     61  1.1  jmcneill static void		emdtv_dtv_isoc_startall(struct emdtv_softc *);
     62  1.1  jmcneill static int		emdtv_dtv_isoc_start(struct emdtv_softc *,
     63  1.1  jmcneill 			    struct emdtv_isoc_xfer *);
     64  1.1  jmcneill static void		emdtv_dtv_isoc(usbd_xfer_handle, usbd_private_handle,
     65  1.1  jmcneill 			    usbd_status);
     66  1.1  jmcneill 
     67  1.1  jmcneill static const struct dtv_hw_if emdtv_dtv_if = {
     68  1.1  jmcneill 	.get_devinfo = emdtv_dtv_get_devinfo,
     69  1.1  jmcneill 	.open = emdtv_dtv_open,
     70  1.1  jmcneill 	.close = emdtv_dtv_close,
     71  1.1  jmcneill 	.set_tuner = emdtv_dtv_set_tuner,
     72  1.1  jmcneill 	.get_status = emdtv_dtv_get_status,
     73  1.1  jmcneill 	.get_signal_strength = emdtv_dtv_get_signal_strength,
     74  1.1  jmcneill 	.get_snr = emdtv_dtv_get_snr,
     75  1.1  jmcneill 	.start_transfer = emdtv_dtv_start_transfer,
     76  1.1  jmcneill 	.stop_transfer = emdtv_dtv_stop_transfer,
     77  1.1  jmcneill };
     78  1.1  jmcneill 
     79  1.1  jmcneill void
     80  1.1  jmcneill emdtv_dtv_attach(struct emdtv_softc *sc)
     81  1.1  jmcneill {
     82  1.1  jmcneill 	usb_endpoint_descriptor_t *ed;
     83  1.1  jmcneill 	usbd_status status;
     84  1.1  jmcneill 	struct dtv_attach_args daa;
     85  1.1  jmcneill 	int i;
     86  1.1  jmcneill 
     87  1.1  jmcneill 	for (i = 0; i < EMDTV_NXFERS; i++) {
     88  1.1  jmcneill 		sc->sc_ix[i].ix_altix = (i & 1) ?
     89  1.1  jmcneill 		    &sc->sc_ix[i - 1] : &sc->sc_ix[i + 1];
     90  1.1  jmcneill 		sc->sc_ix[i].ix_sc = sc;
     91  1.1  jmcneill 	}
     92  1.1  jmcneill 
     93  1.1  jmcneill 	ed = usbd_interface2endpoint_descriptor(sc->sc_iface, 3);
     94  1.1  jmcneill 	if (ed == NULL) {
     95  1.1  jmcneill 		aprint_error_dev(sc->sc_dev, "couldn't find endpoint 3\n");
     96  1.1  jmcneill 		return;
     97  1.1  jmcneill 	}
     98  1.1  jmcneill 	sc->sc_isoc_maxpacketsize = UGETW(ed->wMaxPacketSize);
     99  1.1  jmcneill 	sc->sc_isoc_buflen = sc->sc_isoc_maxpacketsize * EMDTV_NFRAMES;
    100  1.1  jmcneill 
    101  1.1  jmcneill 	aprint_debug_dev(sc->sc_dev, "calling usbd_open_pipe, ep 0x%02x\n",
    102  1.1  jmcneill 	    ed->bEndpointAddress);
    103  1.1  jmcneill 	status = usbd_open_pipe(sc->sc_iface,
    104  1.1  jmcneill 	    ed->bEndpointAddress, USBD_EXCLUSIVE_USE,
    105  1.1  jmcneill 	    &sc->sc_isoc_pipe);
    106  1.1  jmcneill 	if (status != USBD_NORMAL_COMPLETION) {
    107  1.1  jmcneill 		aprint_error_dev(sc->sc_dev, "couldn't open isoc pipe\n");
    108  1.1  jmcneill 		usbd_set_interface(sc->sc_iface, 0);
    109  1.1  jmcneill 		return;
    110  1.1  jmcneill 	}
    111  1.1  jmcneill 
    112  1.1  jmcneill 	emdtv_write_1(sc, UR_GET_STATUS, 0x48, 0x00);
    113  1.1  jmcneill 	emdtv_write_1(sc, UR_GET_STATUS, 0x12, 0x77);
    114  1.1  jmcneill 	usbd_delay_ms(sc->sc_udev, 6);
    115  1.1  jmcneill 
    116  1.1  jmcneill 	emdtv_gpio_ctl(sc, EMDTV_GPIO_ANALOG_ON, false);
    117  1.1  jmcneill 	emdtv_gpio_ctl(sc, EMDTV_GPIO_TS1_ON, true);
    118  1.1  jmcneill 	emdtv_gpio_ctl(sc, EMDTV_GPIO_TUNER1_ON, true);
    119  1.1  jmcneill 	emdtv_gpio_ctl(sc, EMDTV_GPIO_DEMOD1_RESET, true);
    120  1.1  jmcneill 	usbd_delay_ms(sc->sc_udev, 100);
    121  1.1  jmcneill 
    122  1.1  jmcneill 	daa.hw = &emdtv_dtv_if;
    123  1.1  jmcneill 	daa.priv = sc;
    124  1.1  jmcneill 	sc->sc_dtvdev = config_found_ia(sc->sc_dev, "dtvbus", &daa, dtv_print);
    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.1  jmcneill static void
    150  1.1  jmcneill emdtv_dtv_get_devinfo(void *priv, struct dvb_frontend_info *info)
    151  1.1  jmcneill {
    152  1.1  jmcneill 	struct emdtv_softc *sc = priv;
    153  1.1  jmcneill 
    154  1.1  jmcneill 	memset(info, 0, sizeof(*info));
    155  1.1  jmcneill 	strlcpy(info->name, sc->sc_board->eb_name, sizeof(info->name));
    156  1.1  jmcneill 	info->type = FE_ATSC;
    157  1.1  jmcneill 	info->frequency_min = 54000000;
    158  1.1  jmcneill 	info->frequency_max = 858000000;
    159  1.1  jmcneill 	info->frequency_stepsize = 62500;
    160  1.1  jmcneill 	info->caps = FE_CAN_8VSB;
    161  1.1  jmcneill }
    162  1.1  jmcneill 
    163  1.1  jmcneill static int
    164  1.1  jmcneill emdtv_dtv_open(void *priv, int flags)
    165  1.1  jmcneill {
    166  1.1  jmcneill 	struct emdtv_softc *sc = priv;
    167  1.1  jmcneill 
    168  1.1  jmcneill 	if (sc->sc_dying)
    169  1.1  jmcneill 		return ENXIO;
    170  1.1  jmcneill 
    171  1.1  jmcneill 	switch (sc->sc_board->eb_tuner) {
    172  1.2  jakllsch 	case EMDTV_TUNER_XC3028:
    173  1.2  jakllsch 		if (sc->sc_xc3028 == NULL) {
    174  1.2  jakllsch 			sc->sc_xc3028 = xc3028_open(sc->sc_dev,
    175  1.2  jakllsch 			    &sc->sc_i2c, 0x61 << 1, emdtv_dtv_tuner_reset, sc,
    176  1.2  jakllsch 			    XC3028);
    177  1.2  jakllsch 		}
    178  1.2  jakllsch 		if (sc->sc_xc3028 == NULL) {
    179  1.2  jakllsch 			aprint_error_dev(sc->sc_dev, "couldn't open xc3028\n");
    180  1.2  jakllsch 			return ENXIO;
    181  1.2  jakllsch 		}
    182  1.2  jakllsch 		break;
    183  1.1  jmcneill 	case EMDTV_TUNER_XC3028L:
    184  1.1  jmcneill 		if (sc->sc_xc3028 == NULL) {
    185  1.1  jmcneill 			sc->sc_xc3028 = xc3028_open(sc->sc_dev,
    186  1.1  jmcneill 			    &sc->sc_i2c, 0x61 << 1, emdtv_dtv_tuner_reset, sc,
    187  1.1  jmcneill 			    XC3028L);
    188  1.1  jmcneill 		}
    189  1.1  jmcneill 		if (sc->sc_xc3028 == NULL) {
    190  1.1  jmcneill 			aprint_error_dev(sc->sc_dev, "couldn't open xc3028l\n");
    191  1.1  jmcneill 			return ENXIO;
    192  1.1  jmcneill 		}
    193  1.1  jmcneill 		break;
    194  1.1  jmcneill 	default:
    195  1.1  jmcneill 		aprint_error_dev(sc->sc_dev, "unsupported tuner (%d)\n",
    196  1.1  jmcneill 		    sc->sc_board->eb_tuner);
    197  1.1  jmcneill 		return EIO;
    198  1.1  jmcneill 	}
    199  1.1  jmcneill 
    200  1.1  jmcneill 	switch (sc->sc_board->eb_demod) {
    201  1.1  jmcneill 	case EMDTV_DEMOD_LG3303:
    202  1.1  jmcneill 		if (sc->sc_lg3303 == NULL) {
    203  1.1  jmcneill 			sc->sc_lg3303 = lg3303_open(sc->sc_dev,
    204  1.1  jmcneill 			    &sc->sc_i2c, 0x1c);
    205  1.1  jmcneill 		}
    206  1.1  jmcneill 		if (sc->sc_lg3303 == NULL) {
    207  1.1  jmcneill 			aprint_error_dev(sc->sc_dev, "couldn't open lg3303\n");
    208  1.1  jmcneill 			return ENXIO;
    209  1.1  jmcneill 		}
    210  1.1  jmcneill 		break;
    211  1.1  jmcneill 	default:
    212  1.1  jmcneill 		aprint_error_dev(sc->sc_dev, "unsupported demod (%d)\n",
    213  1.1  jmcneill 		    sc->sc_board->eb_demod);
    214  1.1  jmcneill 		return EIO;
    215  1.1  jmcneill 	}
    216  1.1  jmcneill 
    217  1.1  jmcneill 	return 0;
    218  1.1  jmcneill }
    219  1.1  jmcneill 
    220  1.1  jmcneill static void
    221  1.1  jmcneill emdtv_dtv_close(void *priv)
    222  1.1  jmcneill {
    223  1.1  jmcneill 	return;
    224  1.1  jmcneill }
    225  1.1  jmcneill 
    226  1.1  jmcneill static int
    227  1.1  jmcneill emdtv_dtv_set_tuner(void *priv, const struct dvb_frontend_parameters *params)
    228  1.1  jmcneill {
    229  1.1  jmcneill 	struct emdtv_softc *sc = priv;
    230  1.1  jmcneill 	int error;
    231  1.1  jmcneill 
    232  1.1  jmcneill 	/* Setup demod */
    233  1.1  jmcneill 	error = ENXIO;
    234  1.1  jmcneill 	if (sc->sc_lg3303)
    235  1.1  jmcneill 		error = lg3303_set_modulation(sc->sc_lg3303,
    236  1.1  jmcneill 		    params->u.vsb.modulation);
    237  1.1  jmcneill 	if (error)
    238  1.1  jmcneill 		return error;
    239  1.1  jmcneill 
    240  1.1  jmcneill 	/* Setup tuner */
    241  1.1  jmcneill 	error = ENXIO;
    242  1.1  jmcneill 	if (sc->sc_xc3028)
    243  1.1  jmcneill 		error = xc3028_tune_dtv(sc->sc_xc3028, params);
    244  1.1  jmcneill 
    245  1.1  jmcneill 	return error;
    246  1.1  jmcneill }
    247  1.1  jmcneill 
    248  1.1  jmcneill static fe_status_t
    249  1.1  jmcneill emdtv_dtv_get_status(void *priv)
    250  1.1  jmcneill {
    251  1.1  jmcneill 	struct emdtv_softc *sc = priv;
    252  1.1  jmcneill 
    253  1.1  jmcneill 	if (sc->sc_lg3303)
    254  1.1  jmcneill 		return lg3303_get_dtv_status(sc->sc_lg3303);
    255  1.1  jmcneill 
    256  1.1  jmcneill 	return 0;
    257  1.1  jmcneill }
    258  1.1  jmcneill 
    259  1.1  jmcneill uint16_t
    260  1.1  jmcneill emdtv_dtv_get_signal_strength(void *priv)
    261  1.1  jmcneill {
    262  1.1  jmcneill 	return 0;
    263  1.1  jmcneill }
    264  1.1  jmcneill 
    265  1.1  jmcneill uint16_t
    266  1.1  jmcneill emdtv_dtv_get_snr(void *priv)
    267  1.1  jmcneill {
    268  1.1  jmcneill 	return 0;
    269  1.1  jmcneill }
    270  1.1  jmcneill 
    271  1.1  jmcneill static int
    272  1.1  jmcneill emdtv_dtv_start_transfer(void *priv)
    273  1.1  jmcneill {
    274  1.1  jmcneill 	struct emdtv_softc *sc = priv;
    275  1.1  jmcneill 	int i, s;
    276  1.1  jmcneill 
    277  1.1  jmcneill 	s = splusb();
    278  1.1  jmcneill 
    279  1.1  jmcneill 	sc->sc_streaming = true;
    280  1.1  jmcneill 
    281  1.1  jmcneill 	aprint_debug_dev(sc->sc_dev, "allocating isoc xfers (pktsz %d)\n",
    282  1.1  jmcneill 	    sc->sc_isoc_maxpacketsize);
    283  1.1  jmcneill 
    284  1.1  jmcneill 	for (i = 0; i < EMDTV_NXFERS; i++) {
    285  1.1  jmcneill 		sc->sc_ix[i].ix_xfer = usbd_alloc_xfer(sc->sc_udev);
    286  1.1  jmcneill 		sc->sc_ix[i].ix_buf = usbd_alloc_buffer(sc->sc_ix[i].ix_xfer,
    287  1.1  jmcneill 		    sc->sc_isoc_buflen);
    288  1.1  jmcneill 		aprint_debug_dev(sc->sc_dev, "  ix[%d] xfer %p buf %p\n",
    289  1.1  jmcneill 		    i, sc->sc_ix[i].ix_xfer, sc->sc_ix[i].ix_buf);
    290  1.1  jmcneill 	}
    291  1.1  jmcneill 
    292  1.1  jmcneill 	aprint_debug_dev(sc->sc_dev, "starting isoc transactions\n");
    293  1.1  jmcneill 
    294  1.1  jmcneill 	emdtv_dtv_isoc_startall(sc);
    295  1.1  jmcneill 	splx(s);
    296  1.1  jmcneill 
    297  1.1  jmcneill 	return 0;
    298  1.1  jmcneill }
    299  1.1  jmcneill 
    300  1.1  jmcneill static int
    301  1.1  jmcneill emdtv_dtv_stop_transfer(void *priv)
    302  1.1  jmcneill {
    303  1.1  jmcneill 	struct emdtv_softc *sc = priv;
    304  1.1  jmcneill 	int i;
    305  1.1  jmcneill 
    306  1.1  jmcneill 	aprint_debug_dev(sc->sc_dev, "stopping stream\n");
    307  1.1  jmcneill 
    308  1.1  jmcneill 	sc->sc_streaming = false;
    309  1.1  jmcneill 
    310  1.1  jmcneill 	if (sc->sc_isoc_pipe != NULL)
    311  1.1  jmcneill 		usbd_abort_pipe(sc->sc_isoc_pipe);
    312  1.1  jmcneill 
    313  1.1  jmcneill 	for (i = 0; i < EMDTV_NXFERS; i++)
    314  1.1  jmcneill 		if (sc->sc_ix[i].ix_xfer) {
    315  1.1  jmcneill 			usbd_free_xfer(sc->sc_ix[i].ix_xfer);
    316  1.1  jmcneill 			sc->sc_ix[i].ix_xfer = NULL;
    317  1.1  jmcneill 			sc->sc_ix[i].ix_buf = NULL;
    318  1.1  jmcneill 		}
    319  1.1  jmcneill 
    320  1.1  jmcneill 	return 0;
    321  1.1  jmcneill }
    322  1.1  jmcneill 
    323  1.1  jmcneill static void
    324  1.1  jmcneill emdtv_dtv_isoc_startall(struct emdtv_softc *sc)
    325  1.1  jmcneill {
    326  1.1  jmcneill 	int i;
    327  1.1  jmcneill 
    328  1.1  jmcneill 	if (sc->sc_streaming == false || sc->sc_dying == true)
    329  1.1  jmcneill 		return;
    330  1.1  jmcneill 
    331  1.1  jmcneill 	for (i = 0; i < EMDTV_NXFERS; i += 2)
    332  1.1  jmcneill 		emdtv_dtv_isoc_start(sc, &sc->sc_ix[i]);
    333  1.1  jmcneill }
    334  1.1  jmcneill 
    335  1.1  jmcneill static int
    336  1.1  jmcneill emdtv_dtv_isoc_start(struct emdtv_softc *sc, struct emdtv_isoc_xfer *ix)
    337  1.1  jmcneill {
    338  1.1  jmcneill 	int i;
    339  1.1  jmcneill 
    340  1.1  jmcneill 	if (sc->sc_isoc_pipe == NULL)
    341  1.1  jmcneill 		return EIO;
    342  1.1  jmcneill 
    343  1.1  jmcneill 	for (i = 0; i < EMDTV_NFRAMES; i++)
    344  1.1  jmcneill 		ix->ix_frlengths[i] = sc->sc_isoc_maxpacketsize;
    345  1.1  jmcneill 
    346  1.1  jmcneill 	usbd_setup_isoc_xfer(ix->ix_xfer,
    347  1.1  jmcneill 			     sc->sc_isoc_pipe,
    348  1.1  jmcneill 			     ix,
    349  1.1  jmcneill 			     ix->ix_frlengths,
    350  1.1  jmcneill 			     EMDTV_NFRAMES,
    351  1.1  jmcneill 			     USBD_NO_COPY | USBD_SHORT_XFER_OK,
    352  1.1  jmcneill 			     emdtv_dtv_isoc);
    353  1.1  jmcneill 	usbd_transfer(ix->ix_xfer);
    354  1.1  jmcneill 
    355  1.1  jmcneill 	return 0;
    356  1.1  jmcneill }
    357  1.1  jmcneill 
    358  1.1  jmcneill static void
    359  1.1  jmcneill emdtv_dtv_isoc(usbd_xfer_handle xfer, usbd_private_handle priv,
    360  1.1  jmcneill     usbd_status err)
    361  1.1  jmcneill {
    362  1.1  jmcneill 	struct emdtv_isoc_xfer *ix = priv;
    363  1.1  jmcneill 	struct emdtv_softc *sc = ix->ix_sc;
    364  1.1  jmcneill 	struct dtv_payload payload;
    365  1.1  jmcneill 	usbd_pipe_handle isoc = sc->sc_isoc_pipe;
    366  1.1  jmcneill 	uint32_t len;
    367  1.1  jmcneill 	uint8_t *buf;
    368  1.1  jmcneill 	int i;
    369  1.1  jmcneill 
    370  1.1  jmcneill 	KASSERT(xfer == ix->ix_xfer);
    371  1.1  jmcneill 
    372  1.1  jmcneill 	if (sc->sc_dying)
    373  1.1  jmcneill 		return;
    374  1.1  jmcneill 
    375  1.1  jmcneill 	if (err) {
    376  1.1  jmcneill 		if (err == USBD_STALLED) {
    377  1.1  jmcneill 			usbd_clear_endpoint_stall_async(isoc);
    378  1.1  jmcneill 			goto resched;
    379  1.1  jmcneill 		}
    380  1.1  jmcneill 		return;
    381  1.1  jmcneill 	}
    382  1.1  jmcneill 
    383  1.1  jmcneill 	usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL);
    384  1.1  jmcneill 
    385  1.1  jmcneill 	if (len == 0)
    386  1.1  jmcneill 		goto resched;
    387  1.1  jmcneill 
    388  1.1  jmcneill 	buf = usbd_get_buffer(xfer);
    389  1.1  jmcneill 	if (buf == NULL)
    390  1.1  jmcneill 		goto resched;
    391  1.1  jmcneill 
    392  1.1  jmcneill 	for (i = 0; i < EMDTV_NFRAMES; i++, buf += sc->sc_isoc_maxpacketsize) {
    393  1.1  jmcneill 		if (ix->ix_frlengths[i] == 0)
    394  1.1  jmcneill 			continue;
    395  1.1  jmcneill 		payload.data = buf;
    396  1.1  jmcneill 		payload.size = ix->ix_frlengths[i];
    397  1.1  jmcneill 		dtv_submit_payload(sc->sc_dtvdev, &payload);
    398  1.1  jmcneill 	}
    399  1.1  jmcneill 
    400  1.1  jmcneill resched:
    401  1.1  jmcneill 	emdtv_dtv_isoc_start(sc, ix->ix_altix);
    402  1.1  jmcneill }
    403  1.1  jmcneill 
    404  1.1  jmcneill static int
    405  1.1  jmcneill emdtv_dtv_tuner_reset(void *opaque)
    406  1.1  jmcneill {
    407  1.1  jmcneill 	struct emdtv_softc *sc = opaque;
    408  1.1  jmcneill 	emdtv_gpio_ctl(sc, EMDTV_GPIO_TUNER1_RESET, true);
    409  1.1  jmcneill 	return 0;
    410  1.1  jmcneill }
    411