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