Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * For the TDA9875 chip |
| 3 | * (The TDA9875 is used on the Diamond DTV2000 french version |
| 4 | * Other cards probably use these chips as well.) |
| 5 | * This driver will not complain if used with any |
| 6 | * other i2c device with the same address. |
| 7 | * |
| 8 | * Copyright (c) 2000 Guillaume Delvit based on Gerd Knorr source and |
| 9 | * Eric Sandeen |
Mauro Carvalho Chehab | 5eba357 | 2006-08-25 16:53:10 -0300 | [diff] [blame] | 10 | * Copyright (c) 2006 Mauro Carvalho Chehab <mchehab@infradead.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * This code is placed under the terms of the GNU General Public License |
| 12 | * Based on tda9855.c by Steve VanDeBogart (vandebo@uclink.berkeley.edu) |
| 13 | * Which was based on tda8425.c by Greg Alexander (c) 1998 |
| 14 | * |
| 15 | * OPTIONS: |
| 16 | * debug - set to 1 if you'd like to see debug messages |
| 17 | * |
| 18 | * Revision: 0.1 - original version |
| 19 | */ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/string.h> |
| 24 | #include <linux/timer.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/errno.h> |
| 27 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/i2c.h> |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 29 | #include <linux/videodev2.h> |
| 30 | #include <media/v4l2-device.h> |
Mauro Carvalho Chehab | fa3fcce | 2006-03-23 21:45:24 -0300 | [diff] [blame] | 31 | #include <media/i2c-addr.h> |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | static int debug; /* insmod parameter */ |
| 34 | module_param(debug, int, S_IRUGO | S_IWUSR); |
| 35 | MODULE_LICENSE("GPL"); |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | /* This is a superset of the TDA9875 */ |
| 39 | struct tda9875 { |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 40 | struct v4l2_subdev sd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | int rvol, lvol; |
| 42 | int bass, treble; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 45 | static inline struct tda9875 *to_state(struct v4l2_subdev *sd) |
| 46 | { |
| 47 | return container_of(sd, struct tda9875, sd); |
| 48 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | #define dprintk if (debug) printk |
| 51 | |
| 52 | /* The TDA9875 is made by Philips Semiconductor |
| 53 | * http://www.semiconductors.philips.com |
| 54 | * TDA9875: I2C-bus controlled DSP audio processor, FM demodulator |
| 55 | * |
| 56 | */ |
| 57 | |
| 58 | /* subaddresses for TDA9875 */ |
| 59 | #define TDA9875_MUT 0x12 /*General mute (value --> 0b11001100*/ |
| 60 | #define TDA9875_CFG 0x01 /* Config register (value --> 0b00000000 */ |
| 61 | #define TDA9875_DACOS 0x13 /*DAC i/o select (ADC) 0b0000100*/ |
| 62 | #define TDA9875_LOSR 0x16 /*Line output select regirter 0b0100 0001*/ |
| 63 | |
| 64 | #define TDA9875_CH1V 0x0c /*Channel 1 volume (mute)*/ |
| 65 | #define TDA9875_CH2V 0x0d /*Channel 2 volume (mute)*/ |
| 66 | #define TDA9875_SC1 0x14 /*SCART 1 in (mono)*/ |
| 67 | #define TDA9875_SC2 0x15 /*SCART 2 in (mono)*/ |
| 68 | |
| 69 | #define TDA9875_ADCIS 0x17 /*ADC input select (mono) 0b0110 000*/ |
| 70 | #define TDA9875_AER 0x19 /*Audio effect (AVL+Pseudo) 0b0000 0110*/ |
| 71 | #define TDA9875_MCS 0x18 /*Main channel select (DAC) 0b0000100*/ |
| 72 | #define TDA9875_MVL 0x1a /* Main volume gauche */ |
| 73 | #define TDA9875_MVR 0x1b /* Main volume droite */ |
| 74 | #define TDA9875_MBA 0x1d /* Main Basse */ |
| 75 | #define TDA9875_MTR 0x1e /* Main treble */ |
| 76 | #define TDA9875_ACS 0x1f /* Auxilary channel select (FM) 0b0000000*/ |
| 77 | #define TDA9875_AVL 0x20 /* Auxilary volume gauche */ |
| 78 | #define TDA9875_AVR 0x21 /* Auxilary volume droite */ |
| 79 | #define TDA9875_ABA 0x22 /* Auxilary Basse */ |
| 80 | #define TDA9875_ATR 0x23 /* Auxilary treble */ |
| 81 | |
| 82 | #define TDA9875_MSR 0x02 /* Monitor select register */ |
| 83 | #define TDA9875_C1MSB 0x03 /* Carrier 1 (FM) frequency register MSB */ |
| 84 | #define TDA9875_C1MIB 0x04 /* Carrier 1 (FM) frequency register (16-8]b */ |
| 85 | #define TDA9875_C1LSB 0x05 /* Carrier 1 (FM) frequency register LSB */ |
| 86 | #define TDA9875_C2MSB 0x06 /* Carrier 2 (nicam) frequency register MSB */ |
| 87 | #define TDA9875_C2MIB 0x07 /* Carrier 2 (nicam) frequency register (16-8]b */ |
| 88 | #define TDA9875_C2LSB 0x08 /* Carrier 2 (nicam) frequency register LSB */ |
| 89 | #define TDA9875_DCR 0x09 /* Demodulateur configuration regirter*/ |
| 90 | #define TDA9875_DEEM 0x0a /* FM de-emphasis regirter*/ |
| 91 | #define TDA9875_FMAT 0x0b /* FM Matrix regirter*/ |
| 92 | |
| 93 | /* values */ |
| 94 | #define TDA9875_MUTE_ON 0xff /* general mute */ |
| 95 | #define TDA9875_MUTE_OFF 0xcc /* general no mute */ |
| 96 | |
| 97 | |
| 98 | |
| 99 | /* Begin code */ |
| 100 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 101 | static int tda9875_write(struct v4l2_subdev *sd, int subaddr, unsigned char val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 103 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | unsigned char buffer[2]; |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 105 | |
| 106 | v4l2_dbg(1, debug, sd, "Writing %d 0x%x\n", subaddr, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | buffer[0] = subaddr; |
| 108 | buffer[1] = val; |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 109 | if (2 != i2c_master_send(client, buffer, 2)) { |
| 110 | v4l2_warn(sd, "I/O error, trying (write %d 0x%x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | subaddr, val); |
| 112 | return -1; |
| 113 | } |
| 114 | return 0; |
| 115 | } |
| 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 118 | static int i2c_read_register(struct i2c_client *client, int addr, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 120 | unsigned char write[1]; |
| 121 | unsigned char read[1]; |
| 122 | struct i2c_msg msgs[2] = { |
| 123 | { addr, 0, 1, write }, |
| 124 | { addr, I2C_M_RD, 1, read } |
| 125 | }; |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 126 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 127 | write[0] = reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 129 | if (2 != i2c_transfer(client->adapter, msgs, 2)) { |
| 130 | v4l_warn(client, "I/O error (read2)\n"); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 131 | return -1; |
| 132 | } |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 133 | v4l_dbg(1, debug, client, "chip_read2: reg%d=0x%x\n", reg, read[0]); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 134 | return read[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 137 | static void tda9875_set(struct v4l2_subdev *sd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 139 | struct tda9875 *tda = to_state(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | unsigned char a; |
| 141 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 142 | v4l2_dbg(1, debug, sd, "tda9875_set(%04x,%04x,%04x,%04x)\n", |
| 143 | tda->lvol, tda->rvol, tda->bass, tda->treble); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | a = tda->lvol & 0xff; |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 146 | tda9875_write(sd, TDA9875_MVL, a); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | a =tda->rvol & 0xff; |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 148 | tda9875_write(sd, TDA9875_MVR, a); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | a =tda->bass & 0xff; |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 150 | tda9875_write(sd, TDA9875_MBA, a); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | a =tda->treble & 0xff; |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 152 | tda9875_write(sd, TDA9875_MTR, a); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 155 | static void do_tda9875_init(struct v4l2_subdev *sd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 157 | struct tda9875 *t = to_state(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 159 | v4l2_dbg(1, debug, sd, "In tda9875_init\n"); |
| 160 | tda9875_write(sd, TDA9875_CFG, 0xd0); /*reg de config 0 (reset)*/ |
| 161 | tda9875_write(sd, TDA9875_MSR, 0x03); /* Monitor 0b00000XXX*/ |
| 162 | tda9875_write(sd, TDA9875_C1MSB, 0x00); /*Car1(FM) MSB XMHz*/ |
| 163 | tda9875_write(sd, TDA9875_C1MIB, 0x00); /*Car1(FM) MIB XMHz*/ |
| 164 | tda9875_write(sd, TDA9875_C1LSB, 0x00); /*Car1(FM) LSB XMHz*/ |
| 165 | tda9875_write(sd, TDA9875_C2MSB, 0x00); /*Car2(NICAM) MSB XMHz*/ |
| 166 | tda9875_write(sd, TDA9875_C2MIB, 0x00); /*Car2(NICAM) MIB XMHz*/ |
| 167 | tda9875_write(sd, TDA9875_C2LSB, 0x00); /*Car2(NICAM) LSB XMHz*/ |
| 168 | tda9875_write(sd, TDA9875_DCR, 0x00); /*Demod config 0x00*/ |
| 169 | tda9875_write(sd, TDA9875_DEEM, 0x44); /*DE-Emph 0b0100 0100*/ |
| 170 | tda9875_write(sd, TDA9875_FMAT, 0x00); /*FM Matrix reg 0x00*/ |
| 171 | tda9875_write(sd, TDA9875_SC1, 0x00); /* SCART 1 (SC1)*/ |
| 172 | tda9875_write(sd, TDA9875_SC2, 0x01); /* SCART 2 (sc2)*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 174 | tda9875_write(sd, TDA9875_CH1V, 0x10); /* Channel volume 1 mute*/ |
| 175 | tda9875_write(sd, TDA9875_CH2V, 0x10); /* Channel volume 2 mute */ |
| 176 | tda9875_write(sd, TDA9875_DACOS, 0x02); /* sig DAC i/o(in:nicam)*/ |
| 177 | tda9875_write(sd, TDA9875_ADCIS, 0x6f); /* sig ADC input(in:mono)*/ |
| 178 | tda9875_write(sd, TDA9875_LOSR, 0x00); /* line out (in:mono)*/ |
| 179 | tda9875_write(sd, TDA9875_AER, 0x00); /*06 Effect (AVL+PSEUDO) */ |
| 180 | tda9875_write(sd, TDA9875_MCS, 0x44); /* Main ch select (DAC) */ |
| 181 | tda9875_write(sd, TDA9875_MVL, 0x03); /* Vol Main left 10dB */ |
| 182 | tda9875_write(sd, TDA9875_MVR, 0x03); /* Vol Main right 10dB*/ |
| 183 | tda9875_write(sd, TDA9875_MBA, 0x00); /* Main Bass Main 0dB*/ |
| 184 | tda9875_write(sd, TDA9875_MTR, 0x00); /* Main Treble Main 0dB*/ |
| 185 | tda9875_write(sd, TDA9875_ACS, 0x44); /* Aux chan select (dac)*/ |
| 186 | tda9875_write(sd, TDA9875_AVL, 0x00); /* Vol Aux left 0dB*/ |
| 187 | tda9875_write(sd, TDA9875_AVR, 0x00); /* Vol Aux right 0dB*/ |
| 188 | tda9875_write(sd, TDA9875_ABA, 0x00); /* Aux Bass Main 0dB*/ |
| 189 | tda9875_write(sd, TDA9875_ATR, 0x00); /* Aux Aigus Main 0dB*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 191 | tda9875_write(sd, TDA9875_MUT, 0xcc); /* General mute */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 193 | t->lvol = t->rvol = 0; /* 0dB */ |
| 194 | t->bass = 0; /* 0dB */ |
| 195 | t->treble = 0; /* 0dB */ |
| 196 | tda9875_set(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 200 | static int tda9875_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 202 | struct tda9875 *t = to_state(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Mauro Carvalho Chehab | 5eba357 | 2006-08-25 16:53:10 -0300 | [diff] [blame] | 204 | switch (ctrl->id) { |
| 205 | case V4L2_CID_AUDIO_VOLUME: |
| 206 | { |
| 207 | int left = (t->lvol+84)*606; |
| 208 | int right = (t->rvol+84)*606; |
| 209 | |
| 210 | ctrl->value=max(left,right); |
| 211 | return 0; |
| 212 | } |
| 213 | case V4L2_CID_AUDIO_BALANCE: |
| 214 | { |
| 215 | int left = (t->lvol+84)*606; |
| 216 | int right = (t->rvol+84)*606; |
| 217 | int volume = max(left,right); |
| 218 | int balance = (32768*min(left,right))/ |
| 219 | (volume ? volume : 1); |
| 220 | ctrl->value=(left<right)? |
| 221 | (65535-balance) : balance; |
| 222 | return 0; |
| 223 | } |
| 224 | case V4L2_CID_AUDIO_BASS: |
| 225 | ctrl->value = (t->bass+12)*2427; /* min -12 max +15 */ |
| 226 | return 0; |
| 227 | case V4L2_CID_AUDIO_TREBLE: |
| 228 | ctrl->value = (t->treble+12)*2730;/* min -12 max +12 */ |
| 229 | return 0; |
| 230 | } |
| 231 | return -EINVAL; |
| 232 | } |
| 233 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 234 | static int tda9875_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
Mauro Carvalho Chehab | 5eba357 | 2006-08-25 16:53:10 -0300 | [diff] [blame] | 235 | { |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 236 | struct tda9875 *t = to_state(sd); |
Hans Verkuil | cf8e193 | 2009-01-17 13:09:11 -0300 | [diff] [blame] | 237 | int chvol = 0, volume = 0, balance = 0, left, right; |
Mauro Carvalho Chehab | 5eba357 | 2006-08-25 16:53:10 -0300 | [diff] [blame] | 238 | |
| 239 | switch (ctrl->id) { |
| 240 | case V4L2_CID_AUDIO_VOLUME: |
| 241 | left = (t->lvol+84)*606; |
| 242 | right = (t->rvol+84)*606; |
| 243 | |
| 244 | volume = max(left,right); |
| 245 | balance = (32768*min(left,right))/ |
| 246 | (volume ? volume : 1); |
| 247 | balance =(left<right)? |
| 248 | (65535-balance) : balance; |
| 249 | |
| 250 | volume = ctrl->value; |
| 251 | |
| 252 | chvol=1; |
| 253 | break; |
| 254 | case V4L2_CID_AUDIO_BALANCE: |
| 255 | left = (t->lvol+84)*606; |
| 256 | right = (t->rvol+84)*606; |
| 257 | |
| 258 | volume=max(left,right); |
| 259 | |
| 260 | balance = ctrl->value; |
| 261 | |
| 262 | chvol=1; |
| 263 | break; |
| 264 | case V4L2_CID_AUDIO_BASS: |
| 265 | t->bass = ((ctrl->value/2400)-12) & 0xff; |
| 266 | if (t->bass > 15) |
| 267 | t->bass = 15; |
| 268 | if (t->bass < -12) |
| 269 | t->bass = -12 & 0xff; |
| 270 | break; |
| 271 | case V4L2_CID_AUDIO_TREBLE: |
| 272 | t->treble = ((ctrl->value/2700)-12) & 0xff; |
| 273 | if (t->treble > 12) |
| 274 | t->treble = 12; |
| 275 | if (t->treble < -12) |
| 276 | t->treble = -12 & 0xff; |
| 277 | break; |
| 278 | default: |
| 279 | return -EINVAL; |
| 280 | } |
| 281 | |
| 282 | if (chvol) { |
| 283 | left = (min(65536 - balance,32768) * |
| 284 | volume) / 32768; |
| 285 | right = (min(balance,32768) * |
| 286 | volume) / 32768; |
| 287 | t->lvol = ((left/606)-84) & 0xff; |
| 288 | if (t->lvol > 24) |
| 289 | t->lvol = 24; |
| 290 | if (t->lvol < -84) |
| 291 | t->lvol = -84 & 0xff; |
| 292 | |
| 293 | t->rvol = ((right/606)-84) & 0xff; |
| 294 | if (t->rvol > 24) |
| 295 | t->rvol = 24; |
| 296 | if (t->rvol < -84) |
| 297 | t->rvol = -84 & 0xff; |
| 298 | } |
| 299 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 300 | tda9875_set(sd); |
Mauro Carvalho Chehab | 5eba357 | 2006-08-25 16:53:10 -0300 | [diff] [blame] | 301 | return 0; |
| 302 | } |
| 303 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 304 | static int tda9875_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) |
Mauro Carvalho Chehab | 5eba357 | 2006-08-25 16:53:10 -0300 | [diff] [blame] | 305 | { |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 306 | switch (qc->id) { |
| 307 | case V4L2_CID_AUDIO_VOLUME: |
Hans Verkuil | 10afbef | 2009-02-21 18:47:24 -0300 | [diff] [blame] | 308 | return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 58880); |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 309 | case V4L2_CID_AUDIO_BASS: |
| 310 | case V4L2_CID_AUDIO_TREBLE: |
Hans Verkuil | 10afbef | 2009-02-21 18:47:24 -0300 | [diff] [blame] | 311 | return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 313 | return -EINVAL; |
| 314 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 316 | /* ----------------------------------------------------------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 318 | static const struct v4l2_subdev_core_ops tda9875_core_ops = { |
| 319 | .queryctrl = tda9875_queryctrl, |
| 320 | .g_ctrl = tda9875_g_ctrl, |
| 321 | .s_ctrl = tda9875_s_ctrl, |
| 322 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 324 | static const struct v4l2_subdev_ops tda9875_ops = { |
| 325 | .core = &tda9875_core_ops, |
| 326 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 328 | /* ----------------------------------------------------------------------- */ |
| 329 | |
| 330 | |
| 331 | /* *********************** * |
| 332 | * i2c interface functions * |
| 333 | * *********************** */ |
| 334 | |
| 335 | static int tda9875_checkit(struct i2c_client *client, int addr) |
| 336 | { |
| 337 | int dic, rev; |
| 338 | |
| 339 | dic = i2c_read_register(client, addr, 254); |
| 340 | rev = i2c_read_register(client, addr, 255); |
| 341 | |
| 342 | if (dic == 0 || dic == 2) { /* tda9875 and tda9875A */ |
| 343 | v4l_info(client, "tda9875%s rev. %d detected at 0x%02x\n", |
| 344 | dic == 0 ? "" : "A", rev, addr << 1); |
| 345 | return 1; |
| 346 | } |
| 347 | v4l_info(client, "no such chip at 0x%02x (dic=0x%x rev=0x%x)\n", |
| 348 | addr << 1, dic, rev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | return 0; |
| 350 | } |
| 351 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 352 | static int tda9875_probe(struct i2c_client *client, |
| 353 | const struct i2c_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | { |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 355 | struct tda9875 *t; |
| 356 | struct v4l2_subdev *sd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 358 | v4l_info(client, "chip found @ 0x%02x (%s)\n", |
| 359 | client->addr << 1, client->adapter->name); |
| 360 | |
| 361 | if (!tda9875_checkit(client, client->addr)) |
| 362 | return -ENODEV; |
| 363 | |
| 364 | t = kzalloc(sizeof(*t), GFP_KERNEL); |
| 365 | if (!t) |
| 366 | return -ENOMEM; |
| 367 | sd = &t->sd; |
| 368 | v4l2_i2c_subdev_init(sd, client, &tda9875_ops); |
| 369 | |
| 370 | do_tda9875_init(sd); |
| 371 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 374 | static int tda9875_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | { |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 376 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
| 377 | |
| 378 | do_tda9875_init(sd); |
| 379 | v4l2_device_unregister_subdev(sd); |
| 380 | kfree(to_state(sd)); |
| 381 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 384 | static const struct i2c_device_id tda9875_id[] = { |
| 385 | { "tda9875", 0 }, |
| 386 | { } |
| 387 | }; |
| 388 | MODULE_DEVICE_TABLE(i2c, tda9875_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
Hans Verkuil | cd5882c | 2010-09-15 15:37:46 -0300 | [diff] [blame] | 390 | static struct i2c_driver tda9875_driver = { |
| 391 | .driver = { |
| 392 | .owner = THIS_MODULE, |
| 393 | .name = "tda9875", |
| 394 | }, |
| 395 | .probe = tda9875_probe, |
| 396 | .remove = tda9875_remove, |
| 397 | .id_table = tda9875_id, |
Hans Verkuil | 12f91a3 | 2008-12-18 13:43:45 -0300 | [diff] [blame] | 398 | }; |
Hans Verkuil | cd5882c | 2010-09-15 15:37:46 -0300 | [diff] [blame] | 399 | |
| 400 | static __init int init_tda9875(void) |
| 401 | { |
| 402 | return i2c_add_driver(&tda9875_driver); |
| 403 | } |
| 404 | |
| 405 | static __exit void exit_tda9875(void) |
| 406 | { |
| 407 | i2c_del_driver(&tda9875_driver); |
| 408 | } |
| 409 | |
| 410 | module_init(init_tda9875); |
| 411 | module_exit(exit_tda9875); |