Home | History | Annotate | Line # | Download | only in usb
auvitekvar.h revision 1.3
      1 /* $NetBSD: auvitekvar.h,v 1.3 2011/07/09 15:00:45 jmcneill Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2010 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #ifndef _AUVITEKVAR_H
     30 #define _AUVITEKVAR_H
     31 
     32 #include <sys/mutex.h>
     33 #include <sys/condvar.h>
     34 #include <sys/kthread.h>
     35 
     36 #include <dev/usb/usb.h>
     37 #include <dev/usb/usbdi.h>
     38 #include <dev/usb/usbdi_util.h>
     39 #include <dev/i2c/i2cvar.h>
     40 
     41 #include <dev/i2c/au8522var.h>
     42 #include <dev/i2c/xc5kvar.h>
     43 #include <dev/i2c/xc5kreg.h>
     44 
     45 struct auvitek_softc;
     46 
     47 enum auvitek_board {
     48 	AUVITEK_BOARD_HVR_850,
     49 	AUVITEK_BOARD_HVR_950Q,
     50 };
     51 
     52 #define	AUVITEK_NISOC_XFERS	16
     53 #define	AUVITEK_NBULK_XFERS	1
     54 #define AUVITEK_XFER_ALTNO	5
     55 #define	AUVITEK_BULK_BUFLEN	58658	/* BDA driver uses the same */
     56 
     57 struct auvitek_isoc {
     58 	struct auvitek_xfer	*i_ax;
     59 	usbd_xfer_handle	i_xfer;
     60 	uint8_t			*i_buf;
     61 	uint16_t		*i_frlengths;
     62 };
     63 
     64 struct auvitek_videobuf {
     65 	uint8_t			av_buf[720*480*2];
     66 	uint32_t		av_el, av_eb;
     67 	uint32_t		av_ol, av_ob;
     68 	uint32_t		av_stride;
     69 };
     70 
     71 struct auvitek_xfer {
     72 	struct auvitek_softc	*ax_sc;
     73 	int			ax_endpt;
     74 	uint16_t		ax_maxpktlen;
     75 	usbd_pipe_handle	ax_pipe;
     76 	struct auvitek_isoc	ax_i[AUVITEK_NISOC_XFERS];
     77 	uint32_t		ax_nframes;
     78 	uint32_t		ax_uframe_len;
     79 	uint8_t			ax_frinfo;
     80 	int			ax_frno;
     81 	struct auvitek_videobuf	ax_av;
     82 };
     83 
     84 struct auvitek_bulk_xfer {
     85 	struct auvitek_softc	*bx_sc;
     86 	usbd_xfer_handle	bx_xfer;
     87 	uint8_t			*bx_buffer;
     88 };
     89 
     90 struct auvitek_bulk {
     91 	struct auvitek_softc	*ab_sc;
     92 	int			ab_endpt;
     93 	usbd_pipe_handle	ab_pipe;
     94 	struct auvitek_bulk_xfer ab_bx[AUVITEK_NBULK_XFERS];
     95 	bool			ab_running;
     96 	kmutex_t		ab_lock;
     97 	kcondvar_t		ab_cv;
     98 };
     99 
    100 struct auvitek_softc {
    101 	device_t		sc_dev;
    102 	device_t		sc_videodev, sc_dtvdev, sc_audiodev;
    103 	struct i2c_controller	sc_i2c;
    104 	kmutex_t		sc_i2c_lock;
    105 
    106 	usbd_device_handle	sc_udev;
    107 	int			sc_uport;
    108 	usbd_interface_handle	sc_isoc_iface;
    109 	usbd_interface_handle	sc_bulk_iface;
    110 
    111 	char			sc_running;
    112 	char			sc_dying;
    113 
    114 	enum auvitek_board	sc_board;
    115 	const char		*sc_descr;
    116 	uint8_t			sc_i2c_clkdiv;
    117 
    118 	struct au8522		*sc_au8522;
    119 	struct xc5k		*sc_xc5k;
    120 	kmutex_t		sc_subdev_lock;
    121 
    122 	unsigned int		sc_ainput, sc_vinput;
    123 	uint32_t		sc_curfreq;
    124 
    125 	struct auvitek_xfer	sc_ax;
    126 	struct auvitek_bulk	sc_ab;
    127 
    128 	char			sc_businfo[32];
    129 };
    130 
    131 /* auvitek.c */
    132 uint8_t	auvitek_read_1(struct auvitek_softc *, uint16_t);
    133 void	auvitek_write_1(struct auvitek_softc *, uint16_t, uint8_t);
    134 
    135 /* auvitek_audio.c */
    136 int	auvitek_audio_attach(struct auvitek_softc *);
    137 int	auvitek_audio_detach(struct auvitek_softc *, int);
    138 void	auvitek_audio_childdet(struct auvitek_softc *, device_t);
    139 
    140 /* auvitek_board.c */
    141 void	auvitek_board_init(struct auvitek_softc *);
    142 int	auvitek_board_tuner_reset(void *);
    143 unsigned int auvitek_board_get_if_frequency(struct auvitek_softc *);
    144 
    145 /* auvitek_i2c.c */
    146 int	auvitek_i2c_attach(struct auvitek_softc *);
    147 int	auvitek_i2c_detach(struct auvitek_softc *, int);
    148 
    149 /* auvitek_video.c */
    150 int	auvitek_video_attach(struct auvitek_softc *);
    151 int	auvitek_video_detach(struct auvitek_softc *, int);
    152 void	auvitek_video_childdet(struct auvitek_softc *, device_t);
    153 
    154 /* auvitek_dtv.c */
    155 int	auvitek_dtv_attach(struct auvitek_softc *);
    156 int	auvitek_dtv_detach(struct auvitek_softc *, int);
    157 void	auvitek_dtv_childdet(struct auvitek_softc *, device_t);
    158 
    159 #endif /* !_AUVITEKVAR_H */
    160