xref: /netbsd-src/sys/dev/usb/auvitekvar.h (revision 6b71feb71da51fbb1ded3bcd4220b786dc77872a)
1 /* $NetBSD: auvitekvar.h,v 1.10 2022/03/13 12:49:36 riastradh Exp $ */
2 
3 /*-
4  * Copyright (c) 2010 Jared D. McNeill <jmcneill@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/dtv/dtvif.h>
37 
38 #include <dev/usb/usb.h>
39 #include <dev/usb/usbdi.h>
40 #include <dev/usb/usbdi_util.h>
41 #include <dev/i2c/i2cvar.h>
42 
43 #include <dev/i2c/au8522var.h>
44 #include <dev/i2c/xc5kvar.h>
45 #include <dev/i2c/xc5kreg.h>
46 
47 struct auvitek_softc;
48 
49 enum auvitek_board {
50 	AUVITEK_BOARD_HVR_850,
51 	AUVITEK_BOARD_HVR_950Q,
52 };
53 
54 #define	AUVITEK_NISOC_XFERS	16
55 #define	AUVITEK_NBULK_XFERS	1
56 #define AUVITEK_XFER_ALTNO	5
57 #define	AUVITEK_BULK_BUFLEN	58658	/* BDA driver uses the same */
58 
59 struct auvitek_isoc {
60 	struct auvitek_xfer	*i_ax;
61 	struct usbd_xfer	*i_xfer;
62 	uint8_t			*i_buf;
63 	uint16_t		*i_frlengths;
64 };
65 
66 struct auvitek_videobuf {
67 	uint8_t			av_buf[720*480*2];
68 	uint32_t		av_el, av_eb;
69 	uint32_t		av_ol, av_ob;
70 	uint32_t		av_stride;
71 };
72 
73 struct auvitek_xfer {
74 	struct auvitek_softc	*ax_sc;
75 	int			ax_endpt;
76 	uint16_t		ax_maxpktlen;
77 	struct usbd_pipe *	ax_pipe;
78 	struct auvitek_isoc	ax_i[AUVITEK_NISOC_XFERS];
79 	uint32_t		ax_nframes;
80 	uint32_t		ax_uframe_len;
81 	uint8_t			ax_frinfo;
82 	int			ax_frno;
83 	struct auvitek_videobuf	ax_av;
84 };
85 
86 struct auvitek_bulk_xfer {
87 	struct auvitek_softc	*bx_sc;
88 	struct usbd_xfer	*bx_xfer;
89 	uint8_t			*bx_buffer;
90 };
91 
92 struct auvitek_bulk {
93 	struct auvitek_softc	*ab_sc;
94 	int			ab_endpt;
95 	struct usbd_pipe	*ab_pipe;
96 	struct auvitek_bulk_xfer ab_bx[AUVITEK_NBULK_XFERS];
97 	bool			ab_running;
98 };
99 
100 struct auvitek_softc {
101 	device_t		sc_dev;
102 	device_t		sc_videodev, sc_dtvdev, sc_audiodev, sc_i2cdev;
103 	struct i2c_controller	sc_i2c;
104 	kmutex_t		sc_i2c_lock;
105 	bool			sc_i2c_attached;
106 
107 	struct usbd_device     *sc_udev;
108 	int			sc_uport;
109 	struct usbd_interface  *sc_isoc_iface;
110 	struct usbd_interface  *sc_bulk_iface;
111 
112 	char			sc_running;
113 	char			sc_dying;
114 
115 	enum auvitek_board	sc_board;
116 	const char		*sc_descr;
117 	uint8_t			sc_i2c_clkdiv;
118 
119 	struct au8522		*sc_au8522;
120 	struct xc5k		*sc_xc5k;
121 	kmutex_t		sc_subdev_lock;
122 
123 	unsigned int		sc_ainput, sc_vinput;
124 	uint32_t		sc_curfreq;
125 	void			(*sc_dtvsubmitcb)(void *,
126 				    const struct dtv_payload *);
127 	void			*sc_dtvsubmitarg;
128 
129 	struct auvitek_xfer	sc_ax;
130 	struct auvitek_bulk	sc_ab;
131 
132 	char			sc_businfo[32];
133 };
134 
135 /* auvitek.c */
136 uint8_t	auvitek_read_1(struct auvitek_softc *, uint16_t);
137 void	auvitek_write_1(struct auvitek_softc *, uint16_t, uint8_t);
138 void	auvitek_attach_tuner(device_t);
139 
140 /* auvitek_audio.c */
141 int	auvitek_audio_attach(struct auvitek_softc *);
142 int	auvitek_audio_detach(struct auvitek_softc *, int);
143 void	auvitek_audio_childdet(struct auvitek_softc *, device_t);
144 
145 /* auvitek_board.c */
146 void	auvitek_board_init(struct auvitek_softc *);
147 int	auvitek_board_tuner_reset(void *);
148 unsigned int auvitek_board_get_if_frequency(struct auvitek_softc *);
149 
150 /* auvitek_i2c.c */
151 int	auvitek_i2c_attach(struct auvitek_softc *);
152 int	auvitek_i2c_detach(struct auvitek_softc *, int);
153 void	auvitek_i2c_rescan(struct auvitek_softc *, const char *, const int *);
154 void	auvitek_i2c_childdet(struct auvitek_softc *, device_t);
155 
156 /* auvitek_video.c */
157 int	auvitek_video_attach(struct auvitek_softc *);
158 int	auvitek_video_detach(struct auvitek_softc *, int);
159 void	auvitek_video_rescan(struct auvitek_softc *, const char *, const int *);
160 void	auvitek_video_childdet(struct auvitek_softc *, device_t);
161 
162 /* auvitek_dtv.c */
163 int	auvitek_dtv_attach(struct auvitek_softc *);
164 int	auvitek_dtv_detach(struct auvitek_softc *, int);
165 void	auvitek_dtv_rescan(struct auvitek_softc *, const char *, const int *);
166 void	auvitek_dtv_childdet(struct auvitek_softc *, device_t);
167 
168 #endif /* !_AUVITEKVAR_H */
169