auvitekvar.h revision 1.6 1 /* $NetBSD: auvitekvar.h,v 1.6 2011/10/02 16:30:58 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/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 usbd_xfer_handle 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 usbd_pipe_handle 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 usbd_xfer_handle bx_xfer;
89 uint8_t *bx_buffer;
90 };
91
92 struct auvitek_bulk {
93 struct auvitek_softc *ab_sc;
94 int ab_endpt;
95 usbd_pipe_handle ab_pipe;
96 struct auvitek_bulk_xfer ab_bx[AUVITEK_NBULK_XFERS];
97 bool ab_running;
98 kmutex_t ab_lock;
99 kcondvar_t ab_cv;
100 };
101
102 struct auvitek_softc {
103 device_t sc_dev;
104 device_t sc_videodev, sc_dtvdev, sc_audiodev, sc_i2cdev;
105 struct i2c_controller sc_i2c;
106 kmutex_t sc_i2c_lock;
107
108 usbd_device_handle sc_udev;
109 int sc_uport;
110 usbd_interface_handle sc_isoc_iface;
111 usbd_interface_handle sc_bulk_iface;
112
113 char sc_running;
114 char sc_dying;
115
116 enum auvitek_board sc_board;
117 const char *sc_descr;
118 uint8_t sc_i2c_clkdiv;
119
120 struct au8522 *sc_au8522;
121 struct xc5k *sc_xc5k;
122 kmutex_t sc_subdev_lock;
123
124 unsigned int sc_ainput, sc_vinput;
125 uint32_t sc_curfreq;
126 void (*sc_dtvsubmitcb)(void *,
127 const struct dtv_payload *);
128 void *sc_dtvsubmitarg;
129
130 struct auvitek_xfer sc_ax;
131 struct auvitek_bulk sc_ab;
132
133 char sc_businfo[32];
134 };
135
136 /* auvitek.c */
137 uint8_t auvitek_read_1(struct auvitek_softc *, uint16_t);
138 void auvitek_write_1(struct auvitek_softc *, uint16_t, uint8_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