blob: b971c20624bf0ea8ce97ab4c3b3f0780b72b5ff1 [file] [log] [blame]
Devin Heitmueller968cf782009-03-11 03:00:38 -03001/*
2 * Auvitek AU8522 QAM/8VSB demodulator driver and video decoder
3 *
4 * Copyright (C) 2009 Devin Heitmueller <dheitmueller@linuxtv.org>
5 * Copyright (C) 2005-2008 Auvitek International, Ltd.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * As published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 */
22
23/* Developer notes:
24 *
25 * VBI support is not yet working
Devin Heitmueller968cf782009-03-11 03:00:38 -030026 * Enough is implemented here for CVBS and S-Video inputs, but the actual
27 * analog demodulator code isn't implemented (not needed for xc5000 since it
28 * has its own demodulator and outputs CVBS)
29 *
30 */
31
32#include <linux/kernel.h>
33#include <linux/slab.h>
34#include <linux/videodev2.h>
35#include <linux/i2c.h>
36#include <linux/delay.h>
37#include <media/v4l2-common.h>
Devin Heitmueller968cf782009-03-11 03:00:38 -030038#include <media/v4l2-device.h>
39#include "au8522.h"
40#include "au8522_priv.h"
41
42MODULE_AUTHOR("Devin Heitmueller");
43MODULE_LICENSE("GPL");
44
45static int au8522_analog_debug;
46
Devin Heitmueller968cf782009-03-11 03:00:38 -030047
48module_param_named(analog_debug, au8522_analog_debug, int, 0644);
49
50MODULE_PARM_DESC(analog_debug,
51 "Analog debugging messages [0=Off (default) 1=On]");
52
Devin Heitmueller968cf782009-03-11 03:00:38 -030053struct au8522_register_config {
54 u16 reg_name;
55 u8 reg_val[8];
56};
57
58
59/* Video Decoder Filter Coefficients
60 The values are as follows from left to right
61 0="ATV RF" 1="ATV RF13" 2="CVBS" 3="S-Video" 4="PAL" 5=CVBS13" 6="SVideo13"
62*/
Márton Némethc86a3c32009-12-13 17:19:37 -030063static const struct au8522_register_config filter_coef[] = {
Devin Heitmueller62899a22009-03-15 18:48:52 -030064 {AU8522_FILTER_COEF_R410, {0x25, 0x00, 0x25, 0x25, 0x00, 0x00, 0x00} },
65 {AU8522_FILTER_COEF_R411, {0x20, 0x00, 0x20, 0x20, 0x00, 0x00, 0x00} },
66 {AU8522_FILTER_COEF_R412, {0x03, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00} },
67 {AU8522_FILTER_COEF_R413, {0xe6, 0x00, 0xe6, 0xe6, 0x00, 0x00, 0x00} },
68 {AU8522_FILTER_COEF_R414, {0x40, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00} },
69 {AU8522_FILTER_COEF_R415, {0x1b, 0x00, 0x1b, 0x1b, 0x00, 0x00, 0x00} },
70 {AU8522_FILTER_COEF_R416, {0xc0, 0x00, 0xc0, 0x04, 0x00, 0x00, 0x00} },
71 {AU8522_FILTER_COEF_R417, {0x04, 0x00, 0x04, 0x04, 0x00, 0x00, 0x00} },
72 {AU8522_FILTER_COEF_R418, {0x8c, 0x00, 0x8c, 0x8c, 0x00, 0x00, 0x00} },
73 {AU8522_FILTER_COEF_R419, {0xa0, 0x40, 0xa0, 0xa0, 0x40, 0x40, 0x40} },
74 {AU8522_FILTER_COEF_R41A, {0x21, 0x09, 0x21, 0x21, 0x09, 0x09, 0x09} },
75 {AU8522_FILTER_COEF_R41B, {0x6c, 0x38, 0x6c, 0x6c, 0x38, 0x38, 0x38} },
76 {AU8522_FILTER_COEF_R41C, {0x03, 0xff, 0x03, 0x03, 0xff, 0xff, 0xff} },
77 {AU8522_FILTER_COEF_R41D, {0xbf, 0xc7, 0xbf, 0xbf, 0xc7, 0xc7, 0xc7} },
78 {AU8522_FILTER_COEF_R41E, {0xa0, 0xdf, 0xa0, 0xa0, 0xdf, 0xdf, 0xdf} },
79 {AU8522_FILTER_COEF_R41F, {0x10, 0x06, 0x10, 0x10, 0x06, 0x06, 0x06} },
80 {AU8522_FILTER_COEF_R420, {0xae, 0x30, 0xae, 0xae, 0x30, 0x30, 0x30} },
81 {AU8522_FILTER_COEF_R421, {0xc4, 0x01, 0xc4, 0xc4, 0x01, 0x01, 0x01} },
82 {AU8522_FILTER_COEF_R422, {0x54, 0xdd, 0x54, 0x54, 0xdd, 0xdd, 0xdd} },
83 {AU8522_FILTER_COEF_R423, {0xd0, 0xaf, 0xd0, 0xd0, 0xaf, 0xaf, 0xaf} },
84 {AU8522_FILTER_COEF_R424, {0x1c, 0xf7, 0x1c, 0x1c, 0xf7, 0xf7, 0xf7} },
85 {AU8522_FILTER_COEF_R425, {0x76, 0xdb, 0x76, 0x76, 0xdb, 0xdb, 0xdb} },
86 {AU8522_FILTER_COEF_R426, {0x61, 0xc0, 0x61, 0x61, 0xc0, 0xc0, 0xc0} },
87 {AU8522_FILTER_COEF_R427, {0xd1, 0x2f, 0xd1, 0xd1, 0x2f, 0x2f, 0x2f} },
88 {AU8522_FILTER_COEF_R428, {0x84, 0xd8, 0x84, 0x84, 0xd8, 0xd8, 0xd8} },
89 {AU8522_FILTER_COEF_R429, {0x06, 0xfb, 0x06, 0x06, 0xfb, 0xfb, 0xfb} },
90 {AU8522_FILTER_COEF_R42A, {0x21, 0xd5, 0x21, 0x21, 0xd5, 0xd5, 0xd5} },
91 {AU8522_FILTER_COEF_R42B, {0x0a, 0x3e, 0x0a, 0x0a, 0x3e, 0x3e, 0x3e} },
92 {AU8522_FILTER_COEF_R42C, {0xe6, 0x15, 0xe6, 0xe6, 0x15, 0x15, 0x15} },
93 {AU8522_FILTER_COEF_R42D, {0x01, 0x34, 0x01, 0x01, 0x34, 0x34, 0x34} },
Devin Heitmueller968cf782009-03-11 03:00:38 -030094
95};
Devin Heitmueller62899a22009-03-15 18:48:52 -030096#define NUM_FILTER_COEF (sizeof(filter_coef)\
97 / sizeof(struct au8522_register_config))
Devin Heitmueller968cf782009-03-11 03:00:38 -030098
99
100/* Registers 0x060b through 0x0652 are the LP Filter coefficients
101 The values are as follows from left to right
102 0="SIF" 1="ATVRF/ATVRF13"
103 Note: the "ATVRF/ATVRF13" mode has never been tested
104*/
Márton Némethc86a3c32009-12-13 17:19:37 -0300105static const struct au8522_register_config lpfilter_coef[] = {
Devin Heitmueller62899a22009-03-15 18:48:52 -0300106 {0x060b, {0x21, 0x0b} },
107 {0x060c, {0xad, 0xad} },
108 {0x060d, {0x70, 0xf0} },
109 {0x060e, {0xea, 0xe9} },
110 {0x060f, {0xdd, 0xdd} },
111 {0x0610, {0x08, 0x64} },
112 {0x0611, {0x60, 0x60} },
113 {0x0612, {0xf8, 0xb2} },
114 {0x0613, {0x01, 0x02} },
115 {0x0614, {0xe4, 0xb4} },
116 {0x0615, {0x19, 0x02} },
117 {0x0616, {0xae, 0x2e} },
118 {0x0617, {0xee, 0xc5} },
119 {0x0618, {0x56, 0x56} },
120 {0x0619, {0x30, 0x58} },
121 {0x061a, {0xf9, 0xf8} },
122 {0x061b, {0x24, 0x64} },
123 {0x061c, {0x07, 0x07} },
124 {0x061d, {0x30, 0x30} },
125 {0x061e, {0xa9, 0xed} },
126 {0x061f, {0x09, 0x0b} },
127 {0x0620, {0x42, 0xc2} },
128 {0x0621, {0x1d, 0x2a} },
129 {0x0622, {0xd6, 0x56} },
130 {0x0623, {0x95, 0x8b} },
131 {0x0624, {0x2b, 0x2b} },
132 {0x0625, {0x30, 0x24} },
133 {0x0626, {0x3e, 0x3e} },
134 {0x0627, {0x62, 0xe2} },
135 {0x0628, {0xe9, 0xf5} },
136 {0x0629, {0x99, 0x19} },
137 {0x062a, {0xd4, 0x11} },
138 {0x062b, {0x03, 0x04} },
139 {0x062c, {0xb5, 0x85} },
140 {0x062d, {0x1e, 0x20} },
141 {0x062e, {0x2a, 0xea} },
142 {0x062f, {0xd7, 0xd2} },
143 {0x0630, {0x15, 0x15} },
144 {0x0631, {0xa3, 0xa9} },
145 {0x0632, {0x1f, 0x1f} },
146 {0x0633, {0xf9, 0xd1} },
147 {0x0634, {0xc0, 0xc3} },
148 {0x0635, {0x4d, 0x8d} },
149 {0x0636, {0x21, 0x31} },
150 {0x0637, {0x83, 0x83} },
151 {0x0638, {0x08, 0x8c} },
152 {0x0639, {0x19, 0x19} },
153 {0x063a, {0x45, 0xa5} },
154 {0x063b, {0xef, 0xec} },
155 {0x063c, {0x8a, 0x8a} },
156 {0x063d, {0xf4, 0xf6} },
157 {0x063e, {0x8f, 0x8f} },
158 {0x063f, {0x44, 0x0c} },
159 {0x0640, {0xef, 0xf0} },
160 {0x0641, {0x66, 0x66} },
161 {0x0642, {0xcc, 0xd2} },
162 {0x0643, {0x41, 0x41} },
163 {0x0644, {0x63, 0x93} },
164 {0x0645, {0x8e, 0x8e} },
165 {0x0646, {0xa2, 0x42} },
166 {0x0647, {0x7b, 0x7b} },
167 {0x0648, {0x04, 0x04} },
168 {0x0649, {0x00, 0x00} },
169 {0x064a, {0x40, 0x40} },
170 {0x064b, {0x8c, 0x98} },
171 {0x064c, {0x00, 0x00} },
172 {0x064d, {0x63, 0xc3} },
173 {0x064e, {0x04, 0x04} },
174 {0x064f, {0x20, 0x20} },
175 {0x0650, {0x00, 0x00} },
176 {0x0651, {0x40, 0x40} },
177 {0x0652, {0x01, 0x01} },
Devin Heitmueller968cf782009-03-11 03:00:38 -0300178};
Devin Heitmueller62899a22009-03-15 18:48:52 -0300179#define NUM_LPFILTER_COEF (sizeof(lpfilter_coef)\
180 / sizeof(struct au8522_register_config))
Devin Heitmueller968cf782009-03-11 03:00:38 -0300181
182static inline struct au8522_state *to_state(struct v4l2_subdev *sd)
183{
184 return container_of(sd, struct au8522_state, sd);
185}
186
187static void setup_vbi(struct au8522_state *state, int aud_input)
188{
189 int i;
190
191 /* These are set to zero regardless of what mode we're in */
192 au8522_writereg(state, AU8522_TVDEC_VBI_CTRL_H_REG017H, 0x00);
193 au8522_writereg(state, AU8522_TVDEC_VBI_CTRL_L_REG018H, 0x00);
194 au8522_writereg(state, AU8522_TVDEC_VBI_USER_TOTAL_BITS_REG019H, 0x00);
195 au8522_writereg(state, AU8522_TVDEC_VBI_USER_TUNIT_H_REG01AH, 0x00);
196 au8522_writereg(state, AU8522_TVDEC_VBI_USER_TUNIT_L_REG01BH, 0x00);
197 au8522_writereg(state, AU8522_TVDEC_VBI_USER_THRESH1_REG01CH, 0x00);
198 au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_PAT2_REG01EH, 0x00);
199 au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_PAT1_REG01FH, 0x00);
200 au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_PAT0_REG020H, 0x00);
Devin Heitmueller62899a22009-03-15 18:48:52 -0300201 au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_MASK2_REG021H,
202 0x00);
203 au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_MASK1_REG022H,
204 0x00);
205 au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_MASK0_REG023H,
206 0x00);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300207
208 /* Setup the VBI registers */
Devin Heitmueller62899a22009-03-15 18:48:52 -0300209 for (i = 0x30; i < 0x60; i++)
Devin Heitmueller968cf782009-03-11 03:00:38 -0300210 au8522_writereg(state, i, 0x40);
Devin Heitmueller62899a22009-03-15 18:48:52 -0300211
Devin Heitmueller968cf782009-03-11 03:00:38 -0300212 /* For some reason, every register is 0x40 except register 0x44
213 (confirmed via the HVR-950q USB capture) */
214 au8522_writereg(state, 0x44, 0x60);
215
216 /* Enable VBI (we always do this regardless of whether the user is
217 viewing closed caption info) */
218 au8522_writereg(state, AU8522_TVDEC_VBI_CTRL_H_REG017H,
219 AU8522_TVDEC_VBI_CTRL_H_REG017H_CCON);
220
221}
222
Mauro Carvalho Chehab65c88202014-06-08 13:54:54 -0300223static void setup_decoder_defaults(struct au8522_state *state, bool is_svideo)
Devin Heitmueller968cf782009-03-11 03:00:38 -0300224{
225 int i;
226 int filter_coef_type;
227
228 /* Provide reasonable defaults for picture tuning values */
229 au8522_writereg(state, AU8522_TVDEC_SHARPNESSREG009H, 0x07);
230 au8522_writereg(state, AU8522_TVDEC_BRIGHTNESS_REG00AH, 0xed);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300231 au8522_writereg(state, AU8522_TVDEC_CONTRAST_REG00BH, 0x79);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300232 au8522_writereg(state, AU8522_TVDEC_SATURATION_CB_REG00CH, 0x80);
233 au8522_writereg(state, AU8522_TVDEC_SATURATION_CR_REG00DH, 0x80);
234 au8522_writereg(state, AU8522_TVDEC_HUE_H_REG00EH, 0x00);
235 au8522_writereg(state, AU8522_TVDEC_HUE_L_REG00FH, 0x00);
236
237 /* Other decoder registers */
238 au8522_writereg(state, AU8522_TVDEC_INT_MASK_REG010H, 0x00);
239
Mauro Carvalho Chehab65c88202014-06-08 13:54:54 -0300240 if (is_svideo)
Devin Heitmueller968cf782009-03-11 03:00:38 -0300241 au8522_writereg(state, AU8522_VIDEO_MODE_REG011H, 0x04);
Mauro Carvalho Chehab65c88202014-06-08 13:54:54 -0300242 else
Devin Heitmueller968cf782009-03-11 03:00:38 -0300243 au8522_writereg(state, AU8522_VIDEO_MODE_REG011H, 0x00);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300244
245 au8522_writereg(state, AU8522_TVDEC_PGA_REG012H,
246 AU8522_TVDEC_PGA_REG012H_CVBS);
247 au8522_writereg(state, AU8522_TVDEC_COMB_MODE_REG015H,
248 AU8522_TVDEC_COMB_MODE_REG015H_CVBS);
249 au8522_writereg(state, AU8522_TVDED_DBG_MODE_REG060H,
250 AU8522_TVDED_DBG_MODE_REG060H_CVBS);
251 au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL1_REG061H,
Devin Heitmuellera307cfa2012-08-06 22:46:51 -0300252 AU8522_TVDEC_FORMAT_CTRL1_REG061H_FIELD_LEN_525 |
253 AU8522_TVDEC_FORMAT_CTRL1_REG061H_LINE_LEN_63_492 |
254 AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_MN);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300255 au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL2_REG062H,
Devin Heitmuellera307cfa2012-08-06 22:46:51 -0300256 AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_NTSC);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300257 au8522_writereg(state, AU8522_TVDEC_VCR_DET_LLIM_REG063H,
258 AU8522_TVDEC_VCR_DET_LLIM_REG063H_CVBS);
259 au8522_writereg(state, AU8522_TVDEC_VCR_DET_HLIM_REG064H,
260 AU8522_TVDEC_VCR_DET_HLIM_REG064H_CVBS);
261 au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR1_REG065H,
262 AU8522_TVDEC_COMB_VDIF_THR1_REG065H_CVBS);
263 au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR2_REG066H,
264 AU8522_TVDEC_COMB_VDIF_THR2_REG066H_CVBS);
265 au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR3_REG067H,
266 AU8522_TVDEC_COMB_VDIF_THR3_REG067H_CVBS);
267 au8522_writereg(state, AU8522_TVDEC_COMB_NOTCH_THR_REG068H,
268 AU8522_TVDEC_COMB_NOTCH_THR_REG068H_CVBS);
269 au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR1_REG069H,
270 AU8522_TVDEC_COMB_HDIF_THR1_REG069H_CVBS);
271 au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR2_REG06AH,
272 AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS);
273 au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR3_REG06BH,
274 AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS);
Mauro Carvalho Chehab65c88202014-06-08 13:54:54 -0300275 if (is_svideo) {
Devin Heitmueller301c9f22010-06-27 18:12:42 -0300276 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH,
277 AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_SVIDEO);
278 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH,
279 AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_SVIDEO);
280 } else {
281 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH,
282 AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS);
283 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH,
284 AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS);
285 }
Devin Heitmueller968cf782009-03-11 03:00:38 -0300286 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH,
287 AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS);
288 au8522_writereg(state, AU8522_TVDEC_UV_SEP_THR_REG06FH,
289 AU8522_TVDEC_UV_SEP_THR_REG06FH_CVBS);
290 au8522_writereg(state, AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H,
291 AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H_CVBS);
292 au8522_writereg(state, AU8522_REG071H, AU8522_REG071H_CVBS);
293 au8522_writereg(state, AU8522_REG072H, AU8522_REG072H_CVBS);
294 au8522_writereg(state, AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H,
295 AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H_CVBS);
296 au8522_writereg(state, AU8522_REG074H, AU8522_REG074H_CVBS);
297 au8522_writereg(state, AU8522_REG075H, AU8522_REG075H_CVBS);
298 au8522_writereg(state, AU8522_TVDEC_DCAGC_CTRL_REG077H,
299 AU8522_TVDEC_DCAGC_CTRL_REG077H_CVBS);
300 au8522_writereg(state, AU8522_TVDEC_PIC_START_ADJ_REG078H,
301 AU8522_TVDEC_PIC_START_ADJ_REG078H_CVBS);
302 au8522_writereg(state, AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H,
303 AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H_CVBS);
304 au8522_writereg(state, AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH,
305 AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH_CVBS);
306 au8522_writereg(state, AU8522_TVDEC_INTRP_CTRL_REG07BH,
307 AU8522_TVDEC_INTRP_CTRL_REG07BH_CVBS);
308 au8522_writereg(state, AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H,
309 AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H_CVBS);
310 au8522_writereg(state, AU8522_TOREGAAGC_REG0E5H,
311 AU8522_TOREGAAGC_REG0E5H_CVBS);
312 au8522_writereg(state, AU8522_REG016H, AU8522_REG016H_CVBS);
313
314 setup_vbi(state, 0);
315
Mauro Carvalho Chehab65c88202014-06-08 13:54:54 -0300316 if (is_svideo) {
Devin Heitmueller968cf782009-03-11 03:00:38 -0300317 /* Despite what the table says, for the HVR-950q we still need
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200318 to be in CVBS mode for the S-Video input (reason unknown). */
Devin Heitmueller968cf782009-03-11 03:00:38 -0300319 /* filter_coef_type = 3; */
320 filter_coef_type = 5;
321 } else {
322 filter_coef_type = 5;
323 }
324
325 /* Load the Video Decoder Filter Coefficients */
326 for (i = 0; i < NUM_FILTER_COEF; i++) {
327 au8522_writereg(state, filter_coef[i].reg_name,
328 filter_coef[i].reg_val[filter_coef_type]);
329 }
330
331 /* It's not clear what these registers are for, but they are always
332 set to the same value regardless of what mode we're in */
333 au8522_writereg(state, AU8522_REG42EH, 0x87);
334 au8522_writereg(state, AU8522_REG42FH, 0xa2);
335 au8522_writereg(state, AU8522_REG430H, 0xbf);
336 au8522_writereg(state, AU8522_REG431H, 0xcb);
337 au8522_writereg(state, AU8522_REG432H, 0xa1);
338 au8522_writereg(state, AU8522_REG433H, 0x41);
339 au8522_writereg(state, AU8522_REG434H, 0x88);
340 au8522_writereg(state, AU8522_REG435H, 0xc2);
341 au8522_writereg(state, AU8522_REG436H, 0x3c);
342}
343
Mauro Carvalho Chehab36469312014-06-08 13:54:51 -0300344static void au8522_setup_cvbs_mode(struct au8522_state *state, u8 input_mode)
Devin Heitmueller968cf782009-03-11 03:00:38 -0300345{
346 /* here we're going to try the pre-programmed route */
347 au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
348 AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS);
349
Devin Heitmuellerd2c194c2010-06-27 18:01:40 -0300350 /* PGA in automatic mode */
Devin Heitmueller968cf782009-03-11 03:00:38 -0300351 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
Devin Heitmuellerd2c194c2010-06-27 18:01:40 -0300352
353 /* Enable clamping control */
354 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300355
Mauro Carvalho Chehab36469312014-06-08 13:54:51 -0300356 au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, input_mode);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300357
Mauro Carvalho Chehab65c88202014-06-08 13:54:54 -0300358 setup_decoder_defaults(state, false);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300359
360 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
361 AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
362}
363
Mauro Carvalho Chehab36469312014-06-08 13:54:51 -0300364static void au8522_setup_cvbs_tuner_mode(struct au8522_state *state,
365 u8 input_mode)
Devin Heitmueller968cf782009-03-11 03:00:38 -0300366{
367 /* here we're going to try the pre-programmed route */
368 au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
369 AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS);
370
Devin Heitmuellerd2c194c2010-06-27 18:01:40 -0300371 /* It's not clear why we have to have the PGA in automatic mode while
372 enabling clamp control, but it's what Windows does */
Devin Heitmueller968cf782009-03-11 03:00:38 -0300373 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
374
375 /* Enable clamping control */
376 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x0e);
377
Devin Heitmuellerd2c194c2010-06-27 18:01:40 -0300378 /* Disable automatic PGA (since the CVBS is coming from the tuner) */
Devin Heitmueller968cf782009-03-11 03:00:38 -0300379 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x10);
380
381 /* Set input mode to CVBS on channel 4 with SIF audio input enabled */
Mauro Carvalho Chehab36469312014-06-08 13:54:51 -0300382 au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, input_mode);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300383
Mauro Carvalho Chehab65c88202014-06-08 13:54:54 -0300384 setup_decoder_defaults(state, false);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300385
386 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
387 AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
388}
389
Mauro Carvalho Chehab36469312014-06-08 13:54:51 -0300390static void au8522_setup_svideo_mode(struct au8522_state *state,
391 u8 input_mode)
Devin Heitmueller968cf782009-03-11 03:00:38 -0300392{
393 au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
394 AU8522_MODULE_CLOCK_CONTROL_REG0A3H_SVIDEO);
395
396 /* Set input to Y on Channe1, C on Channel 3 */
Mauro Carvalho Chehab36469312014-06-08 13:54:51 -0300397 au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, input_mode);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300398
Devin Heitmuellerd2c194c2010-06-27 18:01:40 -0300399 /* PGA in automatic mode */
400 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
401
402 /* Enable clamping control */
Devin Heitmueller968cf782009-03-11 03:00:38 -0300403 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00);
404
Mauro Carvalho Chehab65c88202014-06-08 13:54:54 -0300405 setup_decoder_defaults(state, true);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300406
407 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
408 AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
409}
410
411/* ----------------------------------------------------------------------- */
412
413static void disable_audio_input(struct au8522_state *state)
414{
Devin Heitmueller968cf782009-03-11 03:00:38 -0300415 au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x00);
416 au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x00);
417 au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0x00);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300418
419 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H, 0x04);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300420 au8522_writereg(state, AU8522_I2S_CTRL_2_REG112H, 0x02);
421
422 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
Devin Heitmueller2428a2e2010-06-27 17:40:42 -0300423 AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_SVIDEO);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300424}
425
426/* 0=disable, 1=SIF */
Mauro Carvalho Chehabd289cdf2014-06-08 13:54:53 -0300427static void set_audio_input(struct au8522_state *state)
Devin Heitmueller968cf782009-03-11 03:00:38 -0300428{
Mauro Carvalho Chehabd289cdf2014-06-08 13:54:53 -0300429 int aud_input = state->aud_input;
Devin Heitmueller968cf782009-03-11 03:00:38 -0300430 int i;
431
432 /* Note that this function needs to be used in conjunction with setting
433 the input routing via register 0x81 */
434
435 if (aud_input == AU8522_AUDIO_NONE) {
436 disable_audio_input(state);
437 return;
438 }
439
440 if (aud_input != AU8522_AUDIO_SIF) {
441 /* The caller asked for a mode we don't currently support */
Devin Heitmueller62899a22009-03-15 18:48:52 -0300442 printk(KERN_ERR "Unsupported audio mode requested! mode=%d\n",
Devin Heitmueller968cf782009-03-11 03:00:38 -0300443 aud_input);
444 return;
445 }
446
447 /* Load the Audio Decoder Filter Coefficients */
448 for (i = 0; i < NUM_LPFILTER_COEF; i++) {
449 au8522_writereg(state, lpfilter_coef[i].reg_name,
450 lpfilter_coef[i].reg_val[0]);
451 }
452
453 /* Setup audio */
454 au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x00);
455 au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x00);
456 au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0x00);
457 au8522_writereg(state, AU8522_I2C_CONTROL_REG1_REG091H, 0x80);
458 au8522_writereg(state, AU8522_I2C_CONTROL_REG0_REG090H, 0x84);
459 msleep(150);
460 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, 0x00);
Mauro Carvalho Chehabc9f5ccc2014-06-08 13:54:55 -0300461 msleep(10);
462 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
463 AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300464 msleep(50);
465 au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x7F);
466 au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x7F);
467 au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0xff);
468 msleep(80);
469 au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x7F);
470 au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x7F);
471 au8522_writereg(state, AU8522_REG0F9H, AU8522_REG0F9H_AUDIO);
472 au8522_writereg(state, AU8522_AUDIO_MODE_REG0F1H, 0x82);
473 msleep(70);
474 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H, 0x09);
475 au8522_writereg(state, AU8522_AUDIOFREQ_REG606H, 0x03);
476 au8522_writereg(state, AU8522_I2S_CTRL_2_REG112H, 0xc2);
477}
478
479/* ----------------------------------------------------------------------- */
480
Hans Verkuil5a4bdb42013-02-15 08:04:29 -0300481static int au8522_s_ctrl(struct v4l2_ctrl *ctrl)
Devin Heitmueller968cf782009-03-11 03:00:38 -0300482{
Hans Verkuil5a4bdb42013-02-15 08:04:29 -0300483 struct au8522_state *state =
484 container_of(ctrl->handler, struct au8522_state, hdl);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300485
486 switch (ctrl->id) {
487 case V4L2_CID_BRIGHTNESS:
Devin Heitmueller968cf782009-03-11 03:00:38 -0300488 au8522_writereg(state, AU8522_TVDEC_BRIGHTNESS_REG00AH,
Hans Verkuil5a4bdb42013-02-15 08:04:29 -0300489 ctrl->val - 128);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300490 break;
491 case V4L2_CID_CONTRAST:
Devin Heitmueller968cf782009-03-11 03:00:38 -0300492 au8522_writereg(state, AU8522_TVDEC_CONTRAST_REG00BH,
Hans Verkuil5a4bdb42013-02-15 08:04:29 -0300493 ctrl->val);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300494 break;
495 case V4L2_CID_SATURATION:
Devin Heitmueller36a91872009-10-13 23:32:29 -0300496 au8522_writereg(state, AU8522_TVDEC_SATURATION_CB_REG00CH,
Hans Verkuil5a4bdb42013-02-15 08:04:29 -0300497 ctrl->val);
Devin Heitmueller36a91872009-10-13 23:32:29 -0300498 au8522_writereg(state, AU8522_TVDEC_SATURATION_CR_REG00DH,
Hans Verkuil5a4bdb42013-02-15 08:04:29 -0300499 ctrl->val);
Devin Heitmueller36a91872009-10-13 23:32:29 -0300500 break;
Devin Heitmueller968cf782009-03-11 03:00:38 -0300501 case V4L2_CID_HUE:
Devin Heitmueller36a91872009-10-13 23:32:29 -0300502 au8522_writereg(state, AU8522_TVDEC_HUE_H_REG00EH,
Hans Verkuil5a4bdb42013-02-15 08:04:29 -0300503 ctrl->val >> 8);
Devin Heitmueller36a91872009-10-13 23:32:29 -0300504 au8522_writereg(state, AU8522_TVDEC_HUE_L_REG00FH,
Hans Verkuil5a4bdb42013-02-15 08:04:29 -0300505 ctrl->val & 0xFF);
Devin Heitmueller36a91872009-10-13 23:32:29 -0300506 break;
Devin Heitmueller968cf782009-03-11 03:00:38 -0300507 default:
508 return -EINVAL;
509 }
510
511 return 0;
512}
513
514/* ----------------------------------------------------------------------- */
515
Devin Heitmueller968cf782009-03-11 03:00:38 -0300516#ifdef CONFIG_VIDEO_ADV_DEBUG
517static int au8522_g_register(struct v4l2_subdev *sd,
518 struct v4l2_dbg_register *reg)
519{
Devin Heitmueller968cf782009-03-11 03:00:38 -0300520 struct au8522_state *state = to_state(sd);
521
Devin Heitmueller968cf782009-03-11 03:00:38 -0300522 reg->val = au8522_readreg(state, reg->reg & 0xffff);
523 return 0;
524}
525
526static int au8522_s_register(struct v4l2_subdev *sd,
Hans Verkuil977ba3b12013-03-24 08:28:46 -0300527 const struct v4l2_dbg_register *reg)
Devin Heitmueller968cf782009-03-11 03:00:38 -0300528{
Devin Heitmueller968cf782009-03-11 03:00:38 -0300529 struct au8522_state *state = to_state(sd);
530
Devin Heitmueller968cf782009-03-11 03:00:38 -0300531 au8522_writereg(state, reg->reg, reg->val & 0xff);
532 return 0;
533}
534#endif
535
Mauro Carvalho Chehab36469312014-06-08 13:54:51 -0300536static void au8522_video_set(struct au8522_state *state)
Mauro Carvalho Chehab36469312014-06-08 13:54:51 -0300537{
538 u8 input_mode;
539
Mauro Carvalho Chehab38fe3512014-06-08 13:54:52 -0300540 au8522_writereg(state, 0xa4, 1 << 5);
Mauro Carvalho Chehab36469312014-06-08 13:54:51 -0300541
542 switch (state->vid_input) {
543 case AU8522_COMPOSITE_CH1:
544 input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH1;
545 au8522_setup_cvbs_mode(state, input_mode);
546 break;
547 case AU8522_COMPOSITE_CH2:
548 input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH2;
549 au8522_setup_cvbs_mode(state, input_mode);
550 break;
551 case AU8522_COMPOSITE_CH3:
552 input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH3;
553 au8522_setup_cvbs_mode(state, input_mode);
554 break;
555 case AU8522_COMPOSITE_CH4:
556 input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH4;
557 au8522_setup_cvbs_mode(state, input_mode);
558 break;
559 case AU8522_SVIDEO_CH13:
560 input_mode = AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13;
561 au8522_setup_svideo_mode(state, input_mode);
562 break;
563 case AU8522_SVIDEO_CH24:
564 input_mode = AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24;
565 au8522_setup_svideo_mode(state, input_mode);
566 break;
567 default:
568 case AU8522_COMPOSITE_CH4_SIF:
569 input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF;
570 au8522_setup_cvbs_tuner_mode(state, input_mode);
571 break;
572 }
573}
574
Mauro Carvalho Chehab38fe3512014-06-08 13:54:52 -0300575static int au8522_s_stream(struct v4l2_subdev *sd, int enable)
576{
577 struct au8522_state *state = to_state(sd);
578
579 if (enable) {
Mauro Carvalho Chehab38fe3512014-06-08 13:54:52 -0300580 /*
581 * Clear out any state associated with the digital side of the
582 * chip, so that when it gets powered back up it won't think
583 * that it is already tuned
584 */
585 state->current_frequency = 0;
586
587 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
588 0x01);
Mauro Carvalho Chehabc9f5ccc2014-06-08 13:54:55 -0300589 msleep(10);
Mauro Carvalho Chehab38fe3512014-06-08 13:54:52 -0300590
591 au8522_video_set(state);
Mauro Carvalho Chehabd289cdf2014-06-08 13:54:53 -0300592 set_audio_input(state);
593
594 state->operational_mode = AU8522_ANALOG_MODE;
Mauro Carvalho Chehab38fe3512014-06-08 13:54:52 -0300595 } else {
596 /* This does not completely power down the device
597 (it only reduces it from around 140ma to 80ma) */
598 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
599 1 << 5);
600 state->operational_mode = AU8522_SUSPEND_MODE;
601 }
602 return 0;
603}
604
Devin Heitmueller968cf782009-03-11 03:00:38 -0300605static int au8522_s_video_routing(struct v4l2_subdev *sd,
Hans Verkuil5325b422009-04-02 11:26:22 -0300606 u32 input, u32 output, u32 config)
Devin Heitmueller968cf782009-03-11 03:00:38 -0300607{
608 struct au8522_state *state = to_state(sd);
609
Mauro Carvalho Chehab36469312014-06-08 13:54:51 -0300610 switch(input) {
611 case AU8522_COMPOSITE_CH1:
612 case AU8522_SVIDEO_CH13:
613 case AU8522_COMPOSITE_CH4_SIF:
614 state->vid_input = input;
615 break;
616 default:
Devin Heitmueller62899a22009-03-15 18:48:52 -0300617 printk(KERN_ERR "au8522 mode not currently supported\n");
Devin Heitmueller968cf782009-03-11 03:00:38 -0300618 return -EINVAL;
619 }
Mauro Carvalho Chehab38fe3512014-06-08 13:54:52 -0300620
621 if (state->operational_mode == AU8522_ANALOG_MODE)
622 au8522_video_set(state);
623
Devin Heitmueller968cf782009-03-11 03:00:38 -0300624 return 0;
625}
626
627static int au8522_s_audio_routing(struct v4l2_subdev *sd,
Hans Verkuil5325b422009-04-02 11:26:22 -0300628 u32 input, u32 output, u32 config)
Devin Heitmueller968cf782009-03-11 03:00:38 -0300629{
630 struct au8522_state *state = to_state(sd);
Mauro Carvalho Chehabd289cdf2014-06-08 13:54:53 -0300631
632 state->aud_input = input;
633
634 if (state->operational_mode == AU8522_ANALOG_MODE)
635 set_audio_input(state);
636
Devin Heitmueller968cf782009-03-11 03:00:38 -0300637 return 0;
638}
639
640static int au8522_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
641{
642 int val = 0;
643 struct au8522_state *state = to_state(sd);
644 u8 lock_status;
645
646 /* Interrogate the decoder to see if we are getting a real signal */
647 lock_status = au8522_readreg(state, 0x00);
648 if (lock_status == 0xa2)
Devin Heitmuellerd749fb62011-07-24 17:23:09 -0300649 vt->signal = 0xffff;
Devin Heitmueller968cf782009-03-11 03:00:38 -0300650 else
651 vt->signal = 0x00;
652
653 vt->capability |=
654 V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
655 V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
656
657 val = V4L2_TUNER_SUB_MONO;
658 vt->rxsubchans = val;
659 vt->audmode = V4L2_TUNER_MODE_STEREO;
660 return 0;
661}
662
Devin Heitmueller968cf782009-03-11 03:00:38 -0300663/* ----------------------------------------------------------------------- */
664
665static const struct v4l2_subdev_core_ops au8522_core_ops = {
Hans Verkuil5a4bdb42013-02-15 08:04:29 -0300666 .log_status = v4l2_ctrl_subdev_log_status,
Devin Heitmueller968cf782009-03-11 03:00:38 -0300667#ifdef CONFIG_VIDEO_ADV_DEBUG
668 .g_register = au8522_g_register,
669 .s_register = au8522_s_register,
670#endif
671};
672
673static const struct v4l2_subdev_tuner_ops au8522_tuner_ops = {
674 .g_tuner = au8522_g_tuner,
675};
676
677static const struct v4l2_subdev_audio_ops au8522_audio_ops = {
678 .s_routing = au8522_s_audio_routing,
679};
680
681static const struct v4l2_subdev_video_ops au8522_video_ops = {
682 .s_routing = au8522_s_video_routing,
Devin Heitmueller968cf782009-03-11 03:00:38 -0300683 .s_stream = au8522_s_stream,
684};
685
686static const struct v4l2_subdev_ops au8522_ops = {
687 .core = &au8522_core_ops,
688 .tuner = &au8522_tuner_ops,
689 .audio = &au8522_audio_ops,
690 .video = &au8522_video_ops,
691};
692
Hans Verkuil5a4bdb42013-02-15 08:04:29 -0300693static const struct v4l2_ctrl_ops au8522_ctrl_ops = {
694 .s_ctrl = au8522_s_ctrl,
695};
696
Devin Heitmueller968cf782009-03-11 03:00:38 -0300697/* ----------------------------------------------------------------------- */
698
699static int au8522_probe(struct i2c_client *client,
700 const struct i2c_device_id *did)
701{
702 struct au8522_state *state;
Hans Verkuil5a4bdb42013-02-15 08:04:29 -0300703 struct v4l2_ctrl_handler *hdl;
Devin Heitmueller968cf782009-03-11 03:00:38 -0300704 struct v4l2_subdev *sd;
705 int instance;
706 struct au8522_config *demod_config;
707
708 /* Check if the adapter supports the needed features */
709 if (!i2c_check_functionality(client->adapter,
710 I2C_FUNC_SMBUS_BYTE_DATA)) {
711 return -EIO;
712 }
713
714 /* allocate memory for the internal state */
715 instance = au8522_get_state(&state, client->adapter, client->addr);
716 switch (instance) {
717 case 0:
Devin Heitmueller62899a22009-03-15 18:48:52 -0300718 printk(KERN_ERR "au8522_decoder allocation failed\n");
Devin Heitmueller968cf782009-03-11 03:00:38 -0300719 return -EIO;
720 case 1:
721 /* new demod instance */
Devin Heitmueller62899a22009-03-15 18:48:52 -0300722 printk(KERN_INFO "au8522_decoder creating new instance...\n");
Devin Heitmueller968cf782009-03-11 03:00:38 -0300723 break;
724 default:
725 /* existing demod instance */
Devin Heitmueller62899a22009-03-15 18:48:52 -0300726 printk(KERN_INFO "au8522_decoder attach existing instance.\n");
Devin Heitmueller968cf782009-03-11 03:00:38 -0300727 break;
728 }
729
730 demod_config = kzalloc(sizeof(struct au8522_config), GFP_KERNEL);
Roel Kluin40d29512009-09-18 21:03:34 -0300731 if (demod_config == NULL) {
732 if (instance == 1)
733 kfree(state);
734 return -ENOMEM;
735 }
Devin Heitmueller968cf782009-03-11 03:00:38 -0300736 demod_config->demod_address = 0x8e >> 1;
737
738 state->config = demod_config;
739 state->i2c = client->adapter;
740
741 sd = &state->sd;
742 v4l2_i2c_subdev_init(sd, client, &au8522_ops);
743
Hans Verkuil5a4bdb42013-02-15 08:04:29 -0300744 hdl = &state->hdl;
745 v4l2_ctrl_handler_init(hdl, 4);
746 v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
747 V4L2_CID_BRIGHTNESS, 0, 255, 1, 109);
748 v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
749 V4L2_CID_CONTRAST, 0, 255, 1,
750 AU8522_TVDEC_CONTRAST_REG00BH_CVBS);
751 v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
752 V4L2_CID_SATURATION, 0, 255, 1, 128);
753 v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
754 V4L2_CID_HUE, -32768, 32767, 1, 0);
755 sd->ctrl_handler = hdl;
756 if (hdl->error) {
757 int err = hdl->error;
758
759 v4l2_ctrl_handler_free(hdl);
760 kfree(demod_config);
761 kfree(state);
762 return err;
763 }
764
Devin Heitmueller968cf782009-03-11 03:00:38 -0300765 state->c = client;
766 state->vid_input = AU8522_COMPOSITE_CH1;
767 state->aud_input = AU8522_AUDIO_NONE;
768 state->id = 8522;
769 state->rev = 0;
770
771 /* Jam open the i2c gate to the tuner */
772 au8522_writereg(state, 0x106, 1);
773
774 return 0;
775}
776
777static int au8522_remove(struct i2c_client *client)
778{
779 struct v4l2_subdev *sd = i2c_get_clientdata(client);
780 v4l2_device_unregister_subdev(sd);
Hans Verkuil5a4bdb42013-02-15 08:04:29 -0300781 v4l2_ctrl_handler_free(sd->ctrl_handler);
Devin Heitmueller968cf782009-03-11 03:00:38 -0300782 au8522_release_state(to_state(sd));
783 return 0;
784}
785
786static const struct i2c_device_id au8522_id[] = {
787 {"au8522", 0},
788 {}
789};
790
791MODULE_DEVICE_TABLE(i2c, au8522_id);
792
Hans Verkuil978cff62010-09-15 15:52:25 -0300793static struct i2c_driver au8522_driver = {
794 .driver = {
795 .owner = THIS_MODULE,
796 .name = "au8522",
797 },
798 .probe = au8522_probe,
799 .remove = au8522_remove,
800 .id_table = au8522_id,
Devin Heitmueller968cf782009-03-11 03:00:38 -0300801};
Hans Verkuil978cff62010-09-15 15:52:25 -0300802
Axel Linc6e8d862012-02-12 06:56:32 -0300803module_i2c_driver(au8522_driver);