1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * For the STS-Thompson TDA7432 audio processor chip
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Handles audio functions: volume, balance, tone, loudness
6*4882a593Smuzhiyun * This driver will not complain if used with any
7*4882a593Smuzhiyun * other i2c device with the same address.
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * Muting and tone control by Jonathan Isom <jisom@ematic.com>
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * Copyright (c) 2000 Eric Sandeen <eric_sandeen@bigfoot.com>
12*4882a593Smuzhiyun * Copyright (c) 2006 Mauro Carvalho Chehab <mchehab@kernel.org>
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * Based on tda9855.c by Steve VanDeBogart (vandebo@uclink.berkeley.edu)
15*4882a593Smuzhiyun * Which was based on tda8425.c by Greg Alexander (c) 1998
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * OPTIONS:
18*4882a593Smuzhiyun * debug - set to 1 if you'd like to see debug messages
19*4882a593Smuzhiyun * set to 2 if you'd like to be inundated with debug messages
20*4882a593Smuzhiyun *
21*4882a593Smuzhiyun * loudness - set between 0 and 15 for varying degrees of loudness effect
22*4882a593Smuzhiyun *
23*4882a593Smuzhiyun * maxvol - set maximum volume to +20db (1), default is 0db(0)
24*4882a593Smuzhiyun */
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun #include <linux/module.h>
27*4882a593Smuzhiyun #include <linux/init.h>
28*4882a593Smuzhiyun #include <linux/kernel.h>
29*4882a593Smuzhiyun #include <linux/string.h>
30*4882a593Smuzhiyun #include <linux/timer.h>
31*4882a593Smuzhiyun #include <linux/delay.h>
32*4882a593Smuzhiyun #include <linux/errno.h>
33*4882a593Smuzhiyun #include <linux/slab.h>
34*4882a593Smuzhiyun #include <linux/videodev2.h>
35*4882a593Smuzhiyun #include <linux/i2c.h>
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun #include <media/v4l2-device.h>
38*4882a593Smuzhiyun #include <media/v4l2-ioctl.h>
39*4882a593Smuzhiyun #include <media/v4l2-ctrls.h>
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun #ifndef VIDEO_AUDIO_BALANCE
42*4882a593Smuzhiyun # define VIDEO_AUDIO_BALANCE 32
43*4882a593Smuzhiyun #endif
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun MODULE_AUTHOR("Eric Sandeen <eric_sandeen@bigfoot.com>");
46*4882a593Smuzhiyun MODULE_DESCRIPTION("bttv driver for the tda7432 audio processor chip");
47*4882a593Smuzhiyun MODULE_LICENSE("GPL");
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun static int maxvol;
50*4882a593Smuzhiyun static int loudness; /* disable loudness by default */
51*4882a593Smuzhiyun static int debug; /* insmod parameter */
52*4882a593Smuzhiyun module_param(debug, int, S_IRUGO | S_IWUSR);
53*4882a593Smuzhiyun MODULE_PARM_DESC(debug, "Set debugging level from 0 to 3. Default is off(0).");
54*4882a593Smuzhiyun module_param(loudness, int, S_IRUGO);
55*4882a593Smuzhiyun MODULE_PARM_DESC(loudness, "Turn loudness on(1) else off(0). Default is off(0).");
56*4882a593Smuzhiyun module_param(maxvol, int, S_IRUGO | S_IWUSR);
57*4882a593Smuzhiyun MODULE_PARM_DESC(maxvol, "Set maximum volume to +20dB(0) else +0dB(1). Default is +20dB(0).");
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun /* Structure of address and subaddresses for the tda7432 */
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun struct tda7432 {
63*4882a593Smuzhiyun struct v4l2_subdev sd;
64*4882a593Smuzhiyun struct v4l2_ctrl_handler hdl;
65*4882a593Smuzhiyun struct {
66*4882a593Smuzhiyun /* bass/treble cluster */
67*4882a593Smuzhiyun struct v4l2_ctrl *bass;
68*4882a593Smuzhiyun struct v4l2_ctrl *treble;
69*4882a593Smuzhiyun };
70*4882a593Smuzhiyun struct {
71*4882a593Smuzhiyun /* mute/balance cluster */
72*4882a593Smuzhiyun struct v4l2_ctrl *mute;
73*4882a593Smuzhiyun struct v4l2_ctrl *balance;
74*4882a593Smuzhiyun };
75*4882a593Smuzhiyun };
76*4882a593Smuzhiyun
to_state(struct v4l2_subdev * sd)77*4882a593Smuzhiyun static inline struct tda7432 *to_state(struct v4l2_subdev *sd)
78*4882a593Smuzhiyun {
79*4882a593Smuzhiyun return container_of(sd, struct tda7432, sd);
80*4882a593Smuzhiyun }
81*4882a593Smuzhiyun
to_sd(struct v4l2_ctrl * ctrl)82*4882a593Smuzhiyun static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun return &container_of(ctrl->handler, struct tda7432, hdl)->sd;
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun /* The TDA7432 is made by STS-Thompson
88*4882a593Smuzhiyun * http://www.st.com
89*4882a593Smuzhiyun * http://us.st.com/stonline/books/pdf/docs/4056.pdf
90*4882a593Smuzhiyun *
91*4882a593Smuzhiyun * TDA7432: I2C-bus controlled basic audio processor
92*4882a593Smuzhiyun *
93*4882a593Smuzhiyun * The TDA7432 controls basic audio functions like volume, balance,
94*4882a593Smuzhiyun * and tone control (including loudness). It also has four channel
95*4882a593Smuzhiyun * output (for front and rear). Since most vidcap cards probably
96*4882a593Smuzhiyun * don't have 4 channel output, this driver will set front & rear
97*4882a593Smuzhiyun * together (no independent control).
98*4882a593Smuzhiyun */
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun /* Subaddresses for TDA7432 */
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun #define TDA7432_IN 0x00 /* Input select */
103*4882a593Smuzhiyun #define TDA7432_VL 0x01 /* Volume */
104*4882a593Smuzhiyun #define TDA7432_TN 0x02 /* Bass, Treble (Tone) */
105*4882a593Smuzhiyun #define TDA7432_LF 0x03 /* Attenuation LF (Left Front) */
106*4882a593Smuzhiyun #define TDA7432_LR 0x04 /* Attenuation LR (Left Rear) */
107*4882a593Smuzhiyun #define TDA7432_RF 0x05 /* Attenuation RF (Right Front) */
108*4882a593Smuzhiyun #define TDA7432_RR 0x06 /* Attenuation RR (Right Rear) */
109*4882a593Smuzhiyun #define TDA7432_LD 0x07 /* Loudness */
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun /* Masks for bits in TDA7432 subaddresses */
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun /* Many of these not used - just for documentation */
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun /* Subaddress 0x00 - Input selection and bass control */
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun /* Bits 0,1,2 control input:
119*4882a593Smuzhiyun * 0x00 - Stereo input
120*4882a593Smuzhiyun * 0x02 - Mono input
121*4882a593Smuzhiyun * 0x03 - Mute (Using Attenuators Plays better with modules)
122*4882a593Smuzhiyun * Mono probably isn't used - I'm guessing only the stereo
123*4882a593Smuzhiyun * input is connected on most cards, so we'll set it to stereo.
124*4882a593Smuzhiyun *
125*4882a593Smuzhiyun * Bit 3 controls bass cut: 0/1 is non-symmetric/symmetric bass cut
126*4882a593Smuzhiyun * Bit 4 controls bass range: 0/1 is extended/standard bass range
127*4882a593Smuzhiyun *
128*4882a593Smuzhiyun * Highest 3 bits not used
129*4882a593Smuzhiyun */
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun #define TDA7432_STEREO_IN 0
132*4882a593Smuzhiyun #define TDA7432_MONO_IN 2 /* Probably won't be used */
133*4882a593Smuzhiyun #define TDA7432_BASS_SYM 1 << 3
134*4882a593Smuzhiyun #define TDA7432_BASS_NORM 1 << 4
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun /* Subaddress 0x01 - Volume */
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun /* Lower 7 bits control volume from -79dB to +32dB in 1dB steps
139*4882a593Smuzhiyun * Recommended maximum is +20 dB
140*4882a593Smuzhiyun *
141*4882a593Smuzhiyun * +32dB: 0x00
142*4882a593Smuzhiyun * +20dB: 0x0c
143*4882a593Smuzhiyun * 0dB: 0x20
144*4882a593Smuzhiyun * -79dB: 0x6f
145*4882a593Smuzhiyun *
146*4882a593Smuzhiyun * MSB (bit 7) controls loudness: 1/0 is loudness on/off
147*4882a593Smuzhiyun */
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun #define TDA7432_VOL_0DB 0x20
150*4882a593Smuzhiyun #define TDA7432_LD_ON 1 << 7
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun /* Subaddress 0x02 - Tone control */
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun /* Bits 0,1,2 control absolute treble gain from 0dB to 14dB
156*4882a593Smuzhiyun * 0x0 is 14dB, 0x7 is 0dB
157*4882a593Smuzhiyun *
158*4882a593Smuzhiyun * Bit 3 controls treble attenuation/gain (sign)
159*4882a593Smuzhiyun * 1 = gain (+)
160*4882a593Smuzhiyun * 0 = attenuation (-)
161*4882a593Smuzhiyun *
162*4882a593Smuzhiyun * Bits 4,5,6 control absolute bass gain from 0dB to 14dB
163*4882a593Smuzhiyun * (This is only true for normal base range, set in 0x00)
164*4882a593Smuzhiyun * 0x0 << 4 is 14dB, 0x7 is 0dB
165*4882a593Smuzhiyun *
166*4882a593Smuzhiyun * Bit 7 controls bass attenuation/gain (sign)
167*4882a593Smuzhiyun * 1 << 7 = gain (+)
168*4882a593Smuzhiyun * 0 << 7 = attenuation (-)
169*4882a593Smuzhiyun *
170*4882a593Smuzhiyun * Example:
171*4882a593Smuzhiyun * 1 1 0 1 0 1 0 1 is +4dB bass, -4dB treble
172*4882a593Smuzhiyun */
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun #define TDA7432_TREBLE_0DB 0xf
175*4882a593Smuzhiyun #define TDA7432_TREBLE 7
176*4882a593Smuzhiyun #define TDA7432_TREBLE_GAIN 1 << 3
177*4882a593Smuzhiyun #define TDA7432_BASS_0DB 0xf
178*4882a593Smuzhiyun #define TDA7432_BASS 7 << 4
179*4882a593Smuzhiyun #define TDA7432_BASS_GAIN 1 << 7
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun /* Subaddress 0x03 - Left Front attenuation */
183*4882a593Smuzhiyun /* Subaddress 0x04 - Left Rear attenuation */
184*4882a593Smuzhiyun /* Subaddress 0x05 - Right Front attenuation */
185*4882a593Smuzhiyun /* Subaddress 0x06 - Right Rear attenuation */
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun /* Bits 0,1,2,3,4 control attenuation from 0dB to -37.5dB
188*4882a593Smuzhiyun * in 1.5dB steps.
189*4882a593Smuzhiyun *
190*4882a593Smuzhiyun * 0x00 is 0dB
191*4882a593Smuzhiyun * 0x1f is -37.5dB
192*4882a593Smuzhiyun *
193*4882a593Smuzhiyun * Bit 5 mutes that channel when set (1 = mute, 0 = unmute)
194*4882a593Smuzhiyun * We'll use the mute on the input, though (above)
195*4882a593Smuzhiyun * Bits 6,7 unused
196*4882a593Smuzhiyun */
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun #define TDA7432_ATTEN_0DB 0x00
199*4882a593Smuzhiyun #define TDA7432_MUTE 0x1 << 5
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun /* Subaddress 0x07 - Loudness Control */
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun /* Bits 0,1,2,3 control loudness from 0dB to -15dB in 1dB steps
205*4882a593Smuzhiyun * when bit 4 is NOT set
206*4882a593Smuzhiyun *
207*4882a593Smuzhiyun * 0x0 is 0dB
208*4882a593Smuzhiyun * 0xf is -15dB
209*4882a593Smuzhiyun *
210*4882a593Smuzhiyun * If bit 4 is set, then there is a flat attenuation according to
211*4882a593Smuzhiyun * the lower 4 bits, as above.
212*4882a593Smuzhiyun *
213*4882a593Smuzhiyun * Bits 5,6,7 unused
214*4882a593Smuzhiyun */
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun /* Begin code */
219*4882a593Smuzhiyun
tda7432_write(struct v4l2_subdev * sd,int subaddr,int val)220*4882a593Smuzhiyun static int tda7432_write(struct v4l2_subdev *sd, int subaddr, int val)
221*4882a593Smuzhiyun {
222*4882a593Smuzhiyun struct i2c_client *client = v4l2_get_subdevdata(sd);
223*4882a593Smuzhiyun unsigned char buffer[2];
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun v4l2_dbg(2, debug, sd, "In tda7432_write\n");
226*4882a593Smuzhiyun v4l2_dbg(1, debug, sd, "Writing %d 0x%x\n", subaddr, val);
227*4882a593Smuzhiyun buffer[0] = subaddr;
228*4882a593Smuzhiyun buffer[1] = val;
229*4882a593Smuzhiyun if (2 != i2c_master_send(client, buffer, 2)) {
230*4882a593Smuzhiyun v4l2_err(sd, "I/O error, trying (write %d 0x%x)\n",
231*4882a593Smuzhiyun subaddr, val);
232*4882a593Smuzhiyun return -1;
233*4882a593Smuzhiyun }
234*4882a593Smuzhiyun return 0;
235*4882a593Smuzhiyun }
236*4882a593Smuzhiyun
tda7432_set(struct v4l2_subdev * sd)237*4882a593Smuzhiyun static int tda7432_set(struct v4l2_subdev *sd)
238*4882a593Smuzhiyun {
239*4882a593Smuzhiyun struct i2c_client *client = v4l2_get_subdevdata(sd);
240*4882a593Smuzhiyun unsigned char buf[16];
241*4882a593Smuzhiyun
242*4882a593Smuzhiyun buf[0] = TDA7432_IN;
243*4882a593Smuzhiyun buf[1] = TDA7432_STEREO_IN | /* Main (stereo) input */
244*4882a593Smuzhiyun TDA7432_BASS_SYM | /* Symmetric bass cut */
245*4882a593Smuzhiyun TDA7432_BASS_NORM; /* Normal bass range */
246*4882a593Smuzhiyun buf[2] = 0x3b;
247*4882a593Smuzhiyun if (loudness) /* Turn loudness on? */
248*4882a593Smuzhiyun buf[2] |= TDA7432_LD_ON;
249*4882a593Smuzhiyun buf[3] = TDA7432_TREBLE_0DB | (TDA7432_BASS_0DB << 4);
250*4882a593Smuzhiyun buf[4] = TDA7432_ATTEN_0DB;
251*4882a593Smuzhiyun buf[5] = TDA7432_ATTEN_0DB;
252*4882a593Smuzhiyun buf[6] = TDA7432_ATTEN_0DB;
253*4882a593Smuzhiyun buf[7] = TDA7432_ATTEN_0DB;
254*4882a593Smuzhiyun buf[8] = loudness;
255*4882a593Smuzhiyun if (9 != i2c_master_send(client, buf, 9)) {
256*4882a593Smuzhiyun v4l2_err(sd, "I/O error, trying tda7432_set\n");
257*4882a593Smuzhiyun return -1;
258*4882a593Smuzhiyun }
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun return 0;
261*4882a593Smuzhiyun }
262*4882a593Smuzhiyun
tda7432_log_status(struct v4l2_subdev * sd)263*4882a593Smuzhiyun static int tda7432_log_status(struct v4l2_subdev *sd)
264*4882a593Smuzhiyun {
265*4882a593Smuzhiyun struct tda7432 *state = to_state(sd);
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun v4l2_ctrl_handler_log_status(&state->hdl, sd->name);
268*4882a593Smuzhiyun return 0;
269*4882a593Smuzhiyun }
270*4882a593Smuzhiyun
tda7432_s_ctrl(struct v4l2_ctrl * ctrl)271*4882a593Smuzhiyun static int tda7432_s_ctrl(struct v4l2_ctrl *ctrl)
272*4882a593Smuzhiyun {
273*4882a593Smuzhiyun struct v4l2_subdev *sd = to_sd(ctrl);
274*4882a593Smuzhiyun struct tda7432 *t = to_state(sd);
275*4882a593Smuzhiyun u8 bass, treble, volume;
276*4882a593Smuzhiyun u8 lf, lr, rf, rr;
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun switch (ctrl->id) {
279*4882a593Smuzhiyun case V4L2_CID_AUDIO_MUTE:
280*4882a593Smuzhiyun if (t->balance->val < 0) {
281*4882a593Smuzhiyun /* shifted to left, attenuate right */
282*4882a593Smuzhiyun rr = rf = -t->balance->val;
283*4882a593Smuzhiyun lr = lf = TDA7432_ATTEN_0DB;
284*4882a593Smuzhiyun } else if (t->balance->val > 0) {
285*4882a593Smuzhiyun /* shifted to right, attenuate left */
286*4882a593Smuzhiyun rr = rf = TDA7432_ATTEN_0DB;
287*4882a593Smuzhiyun lr = lf = t->balance->val;
288*4882a593Smuzhiyun } else {
289*4882a593Smuzhiyun /* centered */
290*4882a593Smuzhiyun rr = rf = TDA7432_ATTEN_0DB;
291*4882a593Smuzhiyun lr = lf = TDA7432_ATTEN_0DB;
292*4882a593Smuzhiyun }
293*4882a593Smuzhiyun if (t->mute->val) {
294*4882a593Smuzhiyun lf |= TDA7432_MUTE;
295*4882a593Smuzhiyun lr |= TDA7432_MUTE;
296*4882a593Smuzhiyun rf |= TDA7432_MUTE;
297*4882a593Smuzhiyun rr |= TDA7432_MUTE;
298*4882a593Smuzhiyun }
299*4882a593Smuzhiyun /* Mute & update balance*/
300*4882a593Smuzhiyun tda7432_write(sd, TDA7432_LF, lf);
301*4882a593Smuzhiyun tda7432_write(sd, TDA7432_LR, lr);
302*4882a593Smuzhiyun tda7432_write(sd, TDA7432_RF, rf);
303*4882a593Smuzhiyun tda7432_write(sd, TDA7432_RR, rr);
304*4882a593Smuzhiyun return 0;
305*4882a593Smuzhiyun case V4L2_CID_AUDIO_VOLUME:
306*4882a593Smuzhiyun volume = 0x6f - ctrl->val;
307*4882a593Smuzhiyun if (loudness) /* Turn on the loudness bit */
308*4882a593Smuzhiyun volume |= TDA7432_LD_ON;
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun tda7432_write(sd, TDA7432_VL, volume);
311*4882a593Smuzhiyun return 0;
312*4882a593Smuzhiyun case V4L2_CID_AUDIO_BASS:
313*4882a593Smuzhiyun bass = t->bass->val;
314*4882a593Smuzhiyun treble = t->treble->val;
315*4882a593Smuzhiyun if (bass >= 0x8)
316*4882a593Smuzhiyun bass = 14 - (bass - 8);
317*4882a593Smuzhiyun if (treble >= 0x8)
318*4882a593Smuzhiyun treble = 14 - (treble - 8);
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun tda7432_write(sd, TDA7432_TN, 0x10 | (bass << 4) | treble);
321*4882a593Smuzhiyun return 0;
322*4882a593Smuzhiyun }
323*4882a593Smuzhiyun return -EINVAL;
324*4882a593Smuzhiyun }
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun /* ----------------------------------------------------------------------- */
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun static const struct v4l2_ctrl_ops tda7432_ctrl_ops = {
329*4882a593Smuzhiyun .s_ctrl = tda7432_s_ctrl,
330*4882a593Smuzhiyun };
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun static const struct v4l2_subdev_core_ops tda7432_core_ops = {
333*4882a593Smuzhiyun .log_status = tda7432_log_status,
334*4882a593Smuzhiyun };
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun static const struct v4l2_subdev_ops tda7432_ops = {
337*4882a593Smuzhiyun .core = &tda7432_core_ops,
338*4882a593Smuzhiyun };
339*4882a593Smuzhiyun
340*4882a593Smuzhiyun /* ----------------------------------------------------------------------- */
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun /* *********************** *
343*4882a593Smuzhiyun * i2c interface functions *
344*4882a593Smuzhiyun * *********************** */
345*4882a593Smuzhiyun
tda7432_probe(struct i2c_client * client,const struct i2c_device_id * id)346*4882a593Smuzhiyun static int tda7432_probe(struct i2c_client *client,
347*4882a593Smuzhiyun const struct i2c_device_id *id)
348*4882a593Smuzhiyun {
349*4882a593Smuzhiyun struct tda7432 *t;
350*4882a593Smuzhiyun struct v4l2_subdev *sd;
351*4882a593Smuzhiyun
352*4882a593Smuzhiyun v4l_info(client, "chip found @ 0x%02x (%s)\n",
353*4882a593Smuzhiyun client->addr << 1, client->adapter->name);
354*4882a593Smuzhiyun
355*4882a593Smuzhiyun t = devm_kzalloc(&client->dev, sizeof(*t), GFP_KERNEL);
356*4882a593Smuzhiyun if (!t)
357*4882a593Smuzhiyun return -ENOMEM;
358*4882a593Smuzhiyun sd = &t->sd;
359*4882a593Smuzhiyun v4l2_i2c_subdev_init(sd, client, &tda7432_ops);
360*4882a593Smuzhiyun v4l2_ctrl_handler_init(&t->hdl, 5);
361*4882a593Smuzhiyun v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
362*4882a593Smuzhiyun V4L2_CID_AUDIO_VOLUME, 0, maxvol ? 0x68 : 0x4f, 1, maxvol ? 0x5d : 0x47);
363*4882a593Smuzhiyun t->mute = v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
364*4882a593Smuzhiyun V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
365*4882a593Smuzhiyun t->balance = v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
366*4882a593Smuzhiyun V4L2_CID_AUDIO_BALANCE, -31, 31, 1, 0);
367*4882a593Smuzhiyun t->bass = v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
368*4882a593Smuzhiyun V4L2_CID_AUDIO_BASS, 0, 14, 1, 7);
369*4882a593Smuzhiyun t->treble = v4l2_ctrl_new_std(&t->hdl, &tda7432_ctrl_ops,
370*4882a593Smuzhiyun V4L2_CID_AUDIO_TREBLE, 0, 14, 1, 7);
371*4882a593Smuzhiyun sd->ctrl_handler = &t->hdl;
372*4882a593Smuzhiyun if (t->hdl.error) {
373*4882a593Smuzhiyun int err = t->hdl.error;
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun v4l2_ctrl_handler_free(&t->hdl);
376*4882a593Smuzhiyun return err;
377*4882a593Smuzhiyun }
378*4882a593Smuzhiyun v4l2_ctrl_cluster(2, &t->bass);
379*4882a593Smuzhiyun v4l2_ctrl_cluster(2, &t->mute);
380*4882a593Smuzhiyun v4l2_ctrl_handler_setup(&t->hdl);
381*4882a593Smuzhiyun if (loudness < 0 || loudness > 15) {
382*4882a593Smuzhiyun v4l2_warn(sd, "loudness parameter must be between 0 and 15\n");
383*4882a593Smuzhiyun if (loudness < 0)
384*4882a593Smuzhiyun loudness = 0;
385*4882a593Smuzhiyun if (loudness > 15)
386*4882a593Smuzhiyun loudness = 15;
387*4882a593Smuzhiyun }
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun tda7432_set(sd);
390*4882a593Smuzhiyun return 0;
391*4882a593Smuzhiyun }
392*4882a593Smuzhiyun
tda7432_remove(struct i2c_client * client)393*4882a593Smuzhiyun static int tda7432_remove(struct i2c_client *client)
394*4882a593Smuzhiyun {
395*4882a593Smuzhiyun struct v4l2_subdev *sd = i2c_get_clientdata(client);
396*4882a593Smuzhiyun struct tda7432 *t = to_state(sd);
397*4882a593Smuzhiyun
398*4882a593Smuzhiyun tda7432_set(sd);
399*4882a593Smuzhiyun v4l2_device_unregister_subdev(sd);
400*4882a593Smuzhiyun v4l2_ctrl_handler_free(&t->hdl);
401*4882a593Smuzhiyun return 0;
402*4882a593Smuzhiyun }
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun static const struct i2c_device_id tda7432_id[] = {
405*4882a593Smuzhiyun { "tda7432", 0 },
406*4882a593Smuzhiyun { }
407*4882a593Smuzhiyun };
408*4882a593Smuzhiyun MODULE_DEVICE_TABLE(i2c, tda7432_id);
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun static struct i2c_driver tda7432_driver = {
411*4882a593Smuzhiyun .driver = {
412*4882a593Smuzhiyun .name = "tda7432",
413*4882a593Smuzhiyun },
414*4882a593Smuzhiyun .probe = tda7432_probe,
415*4882a593Smuzhiyun .remove = tda7432_remove,
416*4882a593Smuzhiyun .id_table = tda7432_id,
417*4882a593Smuzhiyun };
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun module_i2c_driver(tda7432_driver);
420