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) |
| 23 | * |
| 24 | * |
| 25 | * Revision: 0.7 - maxvol module parm to set maximium volume 0db or +20db |
| 26 | * store if muted so we can return it |
| 27 | * change balance only if flaged to |
| 28 | * Revision: 0.6 - added tone controls |
| 29 | * Revision: 0.5 - Fixed odd balance problem |
| 30 | * Revision: 0.4 - added muting |
| 31 | * Revision: 0.3 - Fixed silly reversed volume controls. :) |
| 32 | * Revision: 0.2 - Cleaned up #defines |
| 33 | * fixed volume control |
| 34 | * Added I2C_DRIVERID_TDA7432 |
| 35 | * added loudness insmod control |
| 36 | * Revision: 0.1 - initial version |
| 37 | */ |
| 38 | |
| 39 | #include <linux/module.h> |
| 40 | #include <linux/init.h> |
| 41 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/string.h> |
| 43 | #include <linux/timer.h> |
| 44 | #include <linux/delay.h> |
| 45 | #include <linux/errno.h> |
| 46 | #include <linux/slab.h> |
Hans Verkuil | 33b687c | 2008-07-25 05:32:50 -0300 | [diff] [blame] | 47 | #include <linux/videodev2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/i2c.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 50 | #include <media/v4l2-device.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 51 | #include <media/v4l2-ioctl.h> |
Mauro Carvalho Chehab | fa3fcce | 2006-03-23 21:45:24 -0300 | [diff] [blame] | 52 | #include <media/i2c-addr.h> |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 53 | #include <media/v4l2-i2c-drv-legacy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | #ifndef VIDEO_AUDIO_BALANCE |
| 56 | # define VIDEO_AUDIO_BALANCE 32 |
| 57 | #endif |
| 58 | |
| 59 | MODULE_AUTHOR("Eric Sandeen <eric_sandeen@bigfoot.com>"); |
| 60 | MODULE_DESCRIPTION("bttv driver for the tda7432 audio processor chip"); |
| 61 | MODULE_LICENSE("GPL"); |
| 62 | |
| 63 | static int maxvol; |
| 64 | static int loudness; /* disable loudness by default */ |
| 65 | static int debug; /* insmod parameter */ |
| 66 | module_param(debug, int, S_IRUGO | S_IWUSR); |
| 67 | module_param(loudness, int, S_IRUGO); |
| 68 | MODULE_PARM_DESC(maxvol,"Set maximium volume to +20db (0), default is 0db(1)"); |
| 69 | module_param(maxvol, int, S_IRUGO | S_IWUSR); |
| 70 | |
| 71 | |
| 72 | /* Address to scan (I2C address of this chip) */ |
| 73 | static unsigned short normal_i2c[] = { |
Mauro Carvalho Chehab | 09df1c1 | 2006-03-18 08:31:34 -0300 | [diff] [blame] | 74 | I2C_ADDR_TDA7432 >> 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | I2C_CLIENT_END, |
| 76 | }; |
Hans Verkuil | f87086e | 2008-07-18 00:50:58 -0300 | [diff] [blame] | 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | I2C_CLIENT_INSMOD; |
| 79 | |
| 80 | /* Structure of address and subaddresses for the tda7432 */ |
| 81 | |
| 82 | struct tda7432 { |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 83 | struct v4l2_subdev sd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | int addr; |
| 85 | int input; |
| 86 | int volume; |
| 87 | int muted; |
| 88 | int bass, treble; |
| 89 | int lf, lr, rf, rr; |
| 90 | int loud; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | }; |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 92 | |
| 93 | static inline struct tda7432 *to_state(struct v4l2_subdev *sd) |
| 94 | { |
| 95 | return container_of(sd, struct tda7432, sd); |
| 96 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /* The TDA7432 is made by STS-Thompson |
| 99 | * http://www.st.com |
| 100 | * http://us.st.com/stonline/books/pdf/docs/4056.pdf |
| 101 | * |
| 102 | * TDA7432: I2C-bus controlled basic audio processor |
| 103 | * |
| 104 | * The TDA7432 controls basic audio functions like volume, balance, |
| 105 | * and tone control (including loudness). It also has four channel |
| 106 | * output (for front and rear). Since most vidcap cards probably |
| 107 | * don't have 4 channel output, this driver will set front & rear |
| 108 | * together (no independent control). |
| 109 | */ |
| 110 | |
| 111 | /* Subaddresses for TDA7432 */ |
| 112 | |
| 113 | #define TDA7432_IN 0x00 /* Input select */ |
| 114 | #define TDA7432_VL 0x01 /* Volume */ |
| 115 | #define TDA7432_TN 0x02 /* Bass, Treble (Tone) */ |
| 116 | #define TDA7432_LF 0x03 /* Attenuation LF (Left Front) */ |
| 117 | #define TDA7432_LR 0x04 /* Attenuation LR (Left Rear) */ |
| 118 | #define TDA7432_RF 0x05 /* Attenuation RF (Right Front) */ |
| 119 | #define TDA7432_RR 0x06 /* Attenuation RR (Right Rear) */ |
| 120 | #define TDA7432_LD 0x07 /* Loudness */ |
| 121 | |
| 122 | |
| 123 | /* Masks for bits in TDA7432 subaddresses */ |
| 124 | |
| 125 | /* Many of these not used - just for documentation */ |
| 126 | |
| 127 | /* Subaddress 0x00 - Input selection and bass control */ |
| 128 | |
| 129 | /* Bits 0,1,2 control input: |
| 130 | * 0x00 - Stereo input |
| 131 | * 0x02 - Mono input |
| 132 | * 0x03 - Mute (Using Attenuators Plays better with modules) |
| 133 | * Mono probably isn't used - I'm guessing only the stereo |
| 134 | * input is connected on most cards, so we'll set it to stereo. |
| 135 | * |
| 136 | * Bit 3 controls bass cut: 0/1 is non-symmetric/symmetric bass cut |
| 137 | * Bit 4 controls bass range: 0/1 is extended/standard bass range |
| 138 | * |
| 139 | * Highest 3 bits not used |
| 140 | */ |
| 141 | |
| 142 | #define TDA7432_STEREO_IN 0 |
| 143 | #define TDA7432_MONO_IN 2 /* Probably won't be used */ |
| 144 | #define TDA7432_BASS_SYM 1 << 3 |
| 145 | #define TDA7432_BASS_NORM 1 << 4 |
| 146 | |
| 147 | /* Subaddress 0x01 - Volume */ |
| 148 | |
| 149 | /* Lower 7 bits control volume from -79dB to +32dB in 1dB steps |
| 150 | * Recommended maximum is +20 dB |
| 151 | * |
| 152 | * +32dB: 0x00 |
| 153 | * +20dB: 0x0c |
| 154 | * 0dB: 0x20 |
| 155 | * -79dB: 0x6f |
| 156 | * |
| 157 | * MSB (bit 7) controls loudness: 1/0 is loudness on/off |
| 158 | */ |
| 159 | |
| 160 | #define TDA7432_VOL_0DB 0x20 |
| 161 | #define TDA7432_LD_ON 1 << 7 |
| 162 | |
| 163 | |
| 164 | /* Subaddress 0x02 - Tone control */ |
| 165 | |
| 166 | /* Bits 0,1,2 control absolute treble gain from 0dB to 14dB |
| 167 | * 0x0 is 14dB, 0x7 is 0dB |
| 168 | * |
| 169 | * Bit 3 controls treble attenuation/gain (sign) |
| 170 | * 1 = gain (+) |
| 171 | * 0 = attenuation (-) |
| 172 | * |
| 173 | * Bits 4,5,6 control absolute bass gain from 0dB to 14dB |
| 174 | * (This is only true for normal base range, set in 0x00) |
| 175 | * 0x0 << 4 is 14dB, 0x7 is 0dB |
| 176 | * |
| 177 | * Bit 7 controls bass attenuation/gain (sign) |
| 178 | * 1 << 7 = gain (+) |
| 179 | * 0 << 7 = attenuation (-) |
| 180 | * |
| 181 | * Example: |
| 182 | * 1 1 0 1 0 1 0 1 is +4dB bass, -4dB treble |
| 183 | */ |
| 184 | |
| 185 | #define TDA7432_TREBLE_0DB 0xf |
| 186 | #define TDA7432_TREBLE 7 |
| 187 | #define TDA7432_TREBLE_GAIN 1 << 3 |
| 188 | #define TDA7432_BASS_0DB 0xf |
| 189 | #define TDA7432_BASS 7 << 4 |
| 190 | #define TDA7432_BASS_GAIN 1 << 7 |
| 191 | |
| 192 | |
| 193 | /* Subaddress 0x03 - Left Front attenuation */ |
| 194 | /* Subaddress 0x04 - Left Rear attenuation */ |
| 195 | /* Subaddress 0x05 - Right Front attenuation */ |
| 196 | /* Subaddress 0x06 - Right Rear attenuation */ |
| 197 | |
| 198 | /* Bits 0,1,2,3,4 control attenuation from 0dB to -37.5dB |
| 199 | * in 1.5dB steps. |
| 200 | * |
| 201 | * 0x00 is 0dB |
| 202 | * 0x1f is -37.5dB |
| 203 | * |
| 204 | * Bit 5 mutes that channel when set (1 = mute, 0 = unmute) |
| 205 | * We'll use the mute on the input, though (above) |
| 206 | * Bits 6,7 unused |
| 207 | */ |
| 208 | |
| 209 | #define TDA7432_ATTEN_0DB 0x00 |
| 210 | #define TDA7432_MUTE 0x1 << 5 |
| 211 | |
| 212 | |
| 213 | /* Subaddress 0x07 - Loudness Control */ |
| 214 | |
| 215 | /* Bits 0,1,2,3 control loudness from 0dB to -15dB in 1dB steps |
| 216 | * when bit 4 is NOT set |
| 217 | * |
| 218 | * 0x0 is 0dB |
| 219 | * 0xf is -15dB |
| 220 | * |
| 221 | * If bit 4 is set, then there is a flat attenuation according to |
| 222 | * the lower 4 bits, as above. |
| 223 | * |
| 224 | * Bits 5,6,7 unused |
| 225 | */ |
| 226 | |
| 227 | |
| 228 | |
| 229 | /* Begin code */ |
| 230 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 231 | static int tda7432_write(struct v4l2_subdev *sd, int subaddr, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 233 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | unsigned char buffer[2]; |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 235 | |
| 236 | v4l2_dbg(2, debug, sd, "In tda7432_write\n"); |
| 237 | v4l2_dbg(1, debug, sd, "Writing %d 0x%x\n", subaddr, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | buffer[0] = subaddr; |
| 239 | buffer[1] = val; |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 240 | if (2 != i2c_master_send(client, buffer, 2)) { |
| 241 | v4l2_err(sd, "I/O error, trying (write %d 0x%x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | subaddr, val); |
| 243 | return -1; |
| 244 | } |
| 245 | return 0; |
| 246 | } |
| 247 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 248 | static int tda7432_set(struct v4l2_subdev *sd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 250 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 251 | struct tda7432 *t = to_state(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | unsigned char buf[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 254 | v4l2_dbg(1, debug, sd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | "tda7432: 7432_set(0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x)\n", |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 256 | t->input, t->volume, t->bass, t->treble, t->lf, t->lr, |
| 257 | t->rf, t->rr, t->loud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | buf[0] = TDA7432_IN; |
| 259 | buf[1] = t->input; |
| 260 | buf[2] = t->volume; |
| 261 | buf[3] = t->bass; |
| 262 | buf[4] = t->treble; |
| 263 | buf[5] = t->lf; |
| 264 | buf[6] = t->lr; |
| 265 | buf[7] = t->rf; |
| 266 | buf[8] = t->rr; |
| 267 | buf[9] = t->loud; |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 268 | if (10 != i2c_master_send(client, buf, 10)) { |
| 269 | v4l2_err(sd, "I/O error, trying tda7432_set\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | return -1; |
| 271 | } |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 276 | static void do_tda7432_init(struct v4l2_subdev *sd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 278 | struct tda7432 *t = to_state(sd); |
| 279 | |
| 280 | v4l2_dbg(2, debug, sd, "In tda7432_init\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
| 282 | t->input = TDA7432_STEREO_IN | /* Main (stereo) input */ |
| 283 | TDA7432_BASS_SYM | /* Symmetric bass cut */ |
| 284 | TDA7432_BASS_NORM; /* Normal bass range */ |
| 285 | t->volume = 0x3b ; /* -27dB Volume */ |
| 286 | if (loudness) /* Turn loudness on? */ |
| 287 | t->volume |= TDA7432_LD_ON; |
Mauro Carvalho Chehab | 7a00d45 | 2006-08-25 16:53:09 -0300 | [diff] [blame] | 288 | t->muted = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | t->treble = TDA7432_TREBLE_0DB; /* 0dB Treble */ |
| 290 | t->bass = TDA7432_BASS_0DB; /* 0dB Bass */ |
| 291 | t->lf = TDA7432_ATTEN_0DB; /* 0dB attenuation */ |
| 292 | t->lr = TDA7432_ATTEN_0DB; /* 0dB attenuation */ |
| 293 | t->rf = TDA7432_ATTEN_0DB; /* 0dB attenuation */ |
| 294 | t->rr = TDA7432_ATTEN_0DB; /* 0dB attenuation */ |
| 295 | t->loud = loudness; /* insmod parameter */ |
| 296 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 297 | tda7432_set(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 300 | static int tda7432_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | { |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 302 | struct tda7432 *t = to_state(sd); |
Mauro Carvalho Chehab | 7a00d45 | 2006-08-25 16:53:09 -0300 | [diff] [blame] | 303 | |
| 304 | switch (ctrl->id) { |
| 305 | case V4L2_CID_AUDIO_MUTE: |
| 306 | ctrl->value=t->muted; |
| 307 | return 0; |
| 308 | case V4L2_CID_AUDIO_VOLUME: |
| 309 | if (!maxvol){ /* max +20db */ |
| 310 | ctrl->value = ( 0x6f - (t->volume & 0x7F) ) * 630; |
| 311 | } else { /* max 0db */ |
| 312 | ctrl->value = ( 0x6f - (t->volume & 0x7F) ) * 829; |
| 313 | } |
| 314 | return 0; |
| 315 | case V4L2_CID_AUDIO_BALANCE: |
| 316 | { |
| 317 | if ( (t->lf) < (t->rf) ) |
| 318 | /* right is attenuated, balance shifted left */ |
| 319 | ctrl->value = (32768 - 1057*(t->rf)); |
| 320 | else |
| 321 | /* left is attenuated, balance shifted right */ |
| 322 | ctrl->value = (32768 + 1057*(t->lf)); |
| 323 | return 0; |
| 324 | } |
| 325 | case V4L2_CID_AUDIO_BASS: |
| 326 | { |
| 327 | /* Bass/treble 4 bits each */ |
| 328 | int bass=t->bass; |
| 329 | if(bass >= 0x8) |
| 330 | bass = ~(bass - 0x8) & 0xf; |
| 331 | ctrl->value = (bass << 12)+(bass << 8)+(bass << 4)+(bass); |
| 332 | return 0; |
| 333 | } |
| 334 | case V4L2_CID_AUDIO_TREBLE: |
| 335 | { |
| 336 | int treble=t->treble; |
| 337 | if(treble >= 0x8) |
| 338 | treble = ~(treble - 0x8) & 0xf; |
| 339 | ctrl->value = (treble << 12)+(treble << 8)+(treble << 4)+(treble); |
| 340 | return 0; |
| 341 | } |
| 342 | } |
| 343 | return -EINVAL; |
| 344 | } |
| 345 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 346 | static int tda7432_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
Mauro Carvalho Chehab | 7a00d45 | 2006-08-25 16:53:09 -0300 | [diff] [blame] | 347 | { |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 348 | struct tda7432 *t = to_state(sd); |
Mauro Carvalho Chehab | 7a00d45 | 2006-08-25 16:53:09 -0300 | [diff] [blame] | 349 | |
| 350 | switch (ctrl->id) { |
| 351 | case V4L2_CID_AUDIO_MUTE: |
| 352 | t->muted=ctrl->value; |
| 353 | break; |
| 354 | case V4L2_CID_AUDIO_VOLUME: |
| 355 | if(!maxvol){ /* max +20db */ |
| 356 | t->volume = 0x6f - ((ctrl->value)/630); |
| 357 | } else { /* max 0db */ |
| 358 | t->volume = 0x6f - ((ctrl->value)/829); |
| 359 | } |
| 360 | if (loudness) /* Turn on the loudness bit */ |
| 361 | t->volume |= TDA7432_LD_ON; |
| 362 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 363 | tda7432_write(sd, TDA7432_VL, t->volume); |
Mauro Carvalho Chehab | 7a00d45 | 2006-08-25 16:53:09 -0300 | [diff] [blame] | 364 | return 0; |
| 365 | case V4L2_CID_AUDIO_BALANCE: |
| 366 | if (ctrl->value < 32768) { |
| 367 | /* shifted to left, attenuate right */ |
| 368 | t->rr = (32768 - ctrl->value)/1057; |
| 369 | t->rf = t->rr; |
| 370 | t->lr = TDA7432_ATTEN_0DB; |
| 371 | t->lf = TDA7432_ATTEN_0DB; |
| 372 | } else if(ctrl->value > 32769) { |
| 373 | /* shifted to right, attenuate left */ |
| 374 | t->lf = (ctrl->value - 32768)/1057; |
| 375 | t->lr = t->lf; |
| 376 | t->rr = TDA7432_ATTEN_0DB; |
| 377 | t->rf = TDA7432_ATTEN_0DB; |
| 378 | } else { |
| 379 | /* centered */ |
| 380 | t->rr = TDA7432_ATTEN_0DB; |
| 381 | t->rf = TDA7432_ATTEN_0DB; |
| 382 | t->lf = TDA7432_ATTEN_0DB; |
| 383 | t->lr = TDA7432_ATTEN_0DB; |
| 384 | } |
| 385 | break; |
| 386 | case V4L2_CID_AUDIO_BASS: |
| 387 | t->bass = ctrl->value >> 12; |
| 388 | if(t->bass>= 0x8) |
| 389 | t->bass = (~t->bass & 0xf) + 0x8 ; |
| 390 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 391 | tda7432_write(sd, TDA7432_TN, 0x10 | (t->bass << 4) | t->treble); |
Mauro Carvalho Chehab | 7a00d45 | 2006-08-25 16:53:09 -0300 | [diff] [blame] | 392 | return 0; |
| 393 | case V4L2_CID_AUDIO_TREBLE: |
| 394 | t->treble= ctrl->value >> 12; |
| 395 | if(t->treble>= 0x8) |
| 396 | t->treble = (~t->treble & 0xf) + 0x8 ; |
| 397 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 398 | tda7432_write(sd, TDA7432_TN, 0x10 | (t->bass << 4) | t->treble); |
Mauro Carvalho Chehab | 7a00d45 | 2006-08-25 16:53:09 -0300 | [diff] [blame] | 399 | return 0; |
| 400 | default: |
| 401 | return -EINVAL; |
| 402 | } |
| 403 | |
| 404 | /* Used for both mute and balance changes */ |
| 405 | if (t->muted) |
| 406 | { |
| 407 | /* Mute & update balance*/ |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 408 | tda7432_write(sd, TDA7432_LF, t->lf | TDA7432_MUTE); |
| 409 | tda7432_write(sd, TDA7432_LR, t->lr | TDA7432_MUTE); |
| 410 | tda7432_write(sd, TDA7432_RF, t->rf | TDA7432_MUTE); |
| 411 | tda7432_write(sd, TDA7432_RR, t->rr | TDA7432_MUTE); |
Mauro Carvalho Chehab | 7a00d45 | 2006-08-25 16:53:09 -0300 | [diff] [blame] | 412 | } else { |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 413 | tda7432_write(sd, TDA7432_LF, t->lf); |
| 414 | tda7432_write(sd, TDA7432_LR, t->lr); |
| 415 | tda7432_write(sd, TDA7432_RF, t->rf); |
| 416 | tda7432_write(sd, TDA7432_RR, t->rr); |
Mauro Carvalho Chehab | 7a00d45 | 2006-08-25 16:53:09 -0300 | [diff] [blame] | 417 | } |
| 418 | return 0; |
| 419 | } |
| 420 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 421 | static int tda7432_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | { |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 423 | switch (qc->id) { |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 424 | case V4L2_CID_AUDIO_VOLUME: |
Hans Verkuil | 10afbef | 2009-02-21 18:47:24 -0300 | [diff] [blame^] | 425 | return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 58880); |
| 426 | case V4L2_CID_AUDIO_MUTE: |
| 427 | return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0); |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 428 | case V4L2_CID_AUDIO_BALANCE: |
| 429 | case V4L2_CID_AUDIO_BASS: |
| 430 | case V4L2_CID_AUDIO_TREBLE: |
Hans Verkuil | 10afbef | 2009-02-21 18:47:24 -0300 | [diff] [blame^] | 431 | return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | } |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 433 | return -EINVAL; |
| 434 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 436 | static int tda7432_command(struct i2c_client *client, unsigned cmd, void *arg) |
| 437 | { |
| 438 | return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg); |
| 439 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 441 | /* ----------------------------------------------------------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 443 | static const struct v4l2_subdev_core_ops tda7432_core_ops = { |
| 444 | .queryctrl = tda7432_queryctrl, |
| 445 | .g_ctrl = tda7432_g_ctrl, |
| 446 | .s_ctrl = tda7432_s_ctrl, |
| 447 | }; |
| 448 | |
| 449 | static const struct v4l2_subdev_ops tda7432_ops = { |
| 450 | .core = &tda7432_core_ops, |
| 451 | }; |
| 452 | |
| 453 | /* ----------------------------------------------------------------------- */ |
| 454 | |
| 455 | /* *********************** * |
| 456 | * i2c interface functions * |
| 457 | * *********************** */ |
| 458 | |
| 459 | static int tda7432_probe(struct i2c_client *client, |
| 460 | const struct i2c_device_id *id) |
| 461 | { |
| 462 | struct tda7432 *t; |
| 463 | struct v4l2_subdev *sd; |
| 464 | |
| 465 | v4l_info(client, "chip found @ 0x%02x (%s)\n", |
| 466 | client->addr << 1, client->adapter->name); |
| 467 | |
| 468 | t = kzalloc(sizeof(*t), GFP_KERNEL); |
| 469 | if (!t) |
| 470 | return -ENOMEM; |
| 471 | sd = &t->sd; |
| 472 | v4l2_i2c_subdev_init(sd, client, &tda7432_ops); |
| 473 | if (loudness < 0 || loudness > 15) { |
| 474 | v4l2_warn(sd, "loudness parameter must be between 0 and 15\n"); |
| 475 | if (loudness < 0) |
| 476 | loudness = 0; |
| 477 | if (loudness > 15) |
| 478 | loudness = 15; |
| 479 | } |
| 480 | |
| 481 | do_tda7432_init(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | return 0; |
| 483 | } |
| 484 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 485 | static int tda7432_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | { |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 487 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 489 | do_tda7432_init(sd); |
| 490 | v4l2_device_unregister_subdev(sd); |
| 491 | kfree(to_state(sd)); |
| 492 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 495 | static const struct i2c_device_id tda7432_id[] = { |
| 496 | { "tda7432", 0 }, |
| 497 | { } |
| 498 | }; |
| 499 | MODULE_DEVICE_TABLE(i2c, tda7432_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 501 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
| 502 | .name = "tda7432", |
Hans Verkuil | d531305 | 2008-12-18 13:04:05 -0300 | [diff] [blame] | 503 | .command = tda7432_command, |
| 504 | .probe = tda7432_probe, |
| 505 | .remove = tda7432_remove, |
| 506 | .id_table = tda7432_id, |
| 507 | }; |