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