diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2007-09-14 03:50:44 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-01-25 16:01:24 -0500 |
commit | 08e140544029192a123cc2cbf28edeb5d5462ad2 (patch) | |
tree | e1fe6cd54e5d57b6f0735d95045f0f5c26573c34 | |
parent | 88307eb3c69c80a705072e68463d8f72005fc027 (diff) |
V4L/DVB (6461): tvaudio: convert to bus-based I2C API
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
-rw-r--r-- | drivers/media/video/tvaudio.c | 198 |
1 files changed, 84 insertions, 114 deletions
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c index bb510dd5ddab..a75560540e79 100644 --- a/drivers/media/video/tvaudio.c +++ b/drivers/media/video/tvaudio.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <media/tvaudio.h> | 31 | #include <media/tvaudio.h> |
32 | #include <media/v4l2-common.h> | 32 | #include <media/v4l2-common.h> |
33 | #include <media/v4l2-chip-ident.h> | 33 | #include <media/v4l2-chip-ident.h> |
34 | #include <media/v4l2-i2c-drv-legacy.h> | ||
34 | 35 | ||
35 | #include <media/i2c-addr.h> | 36 | #include <media/i2c-addr.h> |
36 | 37 | ||
@@ -109,7 +110,7 @@ static struct CHIPDESC chiplist[]; | |||
109 | 110 | ||
110 | /* current state of the chip */ | 111 | /* current state of the chip */ |
111 | struct CHIPSTATE { | 112 | struct CHIPSTATE { |
112 | struct i2c_client c; | 113 | struct i2c_client *c; |
113 | 114 | ||
114 | /* index into CHIPDESC array */ | 115 | /* index into CHIPDESC array */ |
115 | int type; | 116 | int type; |
@@ -145,10 +146,6 @@ static unsigned short normal_i2c[] = { | |||
145 | I2C_CLIENT_END }; | 146 | I2C_CLIENT_END }; |
146 | I2C_CLIENT_INSMOD; | 147 | I2C_CLIENT_INSMOD; |
147 | 148 | ||
148 | static struct i2c_driver driver; | ||
149 | static struct i2c_client client_template; | ||
150 | |||
151 | |||
152 | /* ---------------------------------------------------------------------- */ | 149 | /* ---------------------------------------------------------------------- */ |
153 | /* i2c I/O functions */ | 150 | /* i2c I/O functions */ |
154 | 151 | ||
@@ -157,24 +154,24 @@ static int chip_write(struct CHIPSTATE *chip, int subaddr, int val) | |||
157 | unsigned char buffer[2]; | 154 | unsigned char buffer[2]; |
158 | 155 | ||
159 | if (-1 == subaddr) { | 156 | if (-1 == subaddr) { |
160 | v4l_dbg(1, debug, &chip->c, "%s: chip_write: 0x%x\n", | 157 | v4l_dbg(1, debug, chip->c, "%s: chip_write: 0x%x\n", |
161 | chip->c.name, val); | 158 | chip->c->name, val); |
162 | chip->shadow.bytes[1] = val; | 159 | chip->shadow.bytes[1] = val; |
163 | buffer[0] = val; | 160 | buffer[0] = val; |
164 | if (1 != i2c_master_send(&chip->c,buffer,1)) { | 161 | if (1 != i2c_master_send(chip->c,buffer,1)) { |
165 | v4l_warn(&chip->c, "%s: I/O error (write 0x%x)\n", | 162 | v4l_warn(chip->c, "%s: I/O error (write 0x%x)\n", |
166 | chip->c.name, val); | 163 | chip->c->name, val); |
167 | return -1; | 164 | return -1; |
168 | } | 165 | } |
169 | } else { | 166 | } else { |
170 | v4l_dbg(1, debug, &chip->c, "%s: chip_write: reg%d=0x%x\n", | 167 | v4l_dbg(1, debug, chip->c, "%s: chip_write: reg%d=0x%x\n", |
171 | chip->c.name, subaddr, val); | 168 | chip->c->name, subaddr, val); |
172 | chip->shadow.bytes[subaddr+1] = val; | 169 | chip->shadow.bytes[subaddr+1] = val; |
173 | buffer[0] = subaddr; | 170 | buffer[0] = subaddr; |
174 | buffer[1] = val; | 171 | buffer[1] = val; |
175 | if (2 != i2c_master_send(&chip->c,buffer,2)) { | 172 | if (2 != i2c_master_send(chip->c,buffer,2)) { |
176 | v4l_warn(&chip->c, "%s: I/O error (write reg%d=0x%x)\n", | 173 | v4l_warn(chip->c, "%s: I/O error (write reg%d=0x%x)\n", |
177 | chip->c.name, subaddr, val); | 174 | chip->c->name, subaddr, val); |
178 | return -1; | 175 | return -1; |
179 | } | 176 | } |
180 | } | 177 | } |
@@ -197,12 +194,12 @@ static int chip_read(struct CHIPSTATE *chip) | |||
197 | { | 194 | { |
198 | unsigned char buffer; | 195 | unsigned char buffer; |
199 | 196 | ||
200 | if (1 != i2c_master_recv(&chip->c,&buffer,1)) { | 197 | if (1 != i2c_master_recv(chip->c,&buffer,1)) { |
201 | v4l_warn(&chip->c, "%s: I/O error (read)\n", | 198 | v4l_warn(chip->c, "%s: I/O error (read)\n", |
202 | chip->c.name); | 199 | chip->c->name); |
203 | return -1; | 200 | return -1; |
204 | } | 201 | } |
205 | v4l_dbg(1, debug, &chip->c, "%s: chip_read: 0x%x\n",chip->c.name, buffer); | 202 | v4l_dbg(1, debug, chip->c, "%s: chip_read: 0x%x\n",chip->c->name, buffer); |
206 | return buffer; | 203 | return buffer; |
207 | } | 204 | } |
208 | 205 | ||
@@ -211,17 +208,17 @@ static int chip_read2(struct CHIPSTATE *chip, int subaddr) | |||
211 | unsigned char write[1]; | 208 | unsigned char write[1]; |
212 | unsigned char read[1]; | 209 | unsigned char read[1]; |
213 | struct i2c_msg msgs[2] = { | 210 | struct i2c_msg msgs[2] = { |
214 | { chip->c.addr, 0, 1, write }, | 211 | { chip->c->addr, 0, 1, write }, |
215 | { chip->c.addr, I2C_M_RD, 1, read } | 212 | { chip->c->addr, I2C_M_RD, 1, read } |
216 | }; | 213 | }; |
217 | write[0] = subaddr; | 214 | write[0] = subaddr; |
218 | 215 | ||
219 | if (2 != i2c_transfer(chip->c.adapter,msgs,2)) { | 216 | if (2 != i2c_transfer(chip->c->adapter,msgs,2)) { |
220 | v4l_warn(&chip->c, "%s: I/O error (read2)\n", chip->c.name); | 217 | v4l_warn(chip->c, "%s: I/O error (read2)\n", chip->c->name); |
221 | return -1; | 218 | return -1; |
222 | } | 219 | } |
223 | v4l_dbg(1, debug, &chip->c, "%s: chip_read2: reg%d=0x%x\n", | 220 | v4l_dbg(1, debug, chip->c, "%s: chip_read2: reg%d=0x%x\n", |
224 | chip->c.name, subaddr,read[0]); | 221 | chip->c->name, subaddr,read[0]); |
225 | return read[0]; | 222 | return read[0]; |
226 | } | 223 | } |
227 | 224 | ||
@@ -233,8 +230,8 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd) | |||
233 | return 0; | 230 | return 0; |
234 | 231 | ||
235 | /* update our shadow register set; print bytes if (debug > 0) */ | 232 | /* update our shadow register set; print bytes if (debug > 0) */ |
236 | v4l_dbg(1, debug, &chip->c, "%s: chip_cmd(%s): reg=%d, data:", | 233 | v4l_dbg(1, debug, chip->c, "%s: chip_cmd(%s): reg=%d, data:", |
237 | chip->c.name, name,cmd->bytes[0]); | 234 | chip->c->name, name,cmd->bytes[0]); |
238 | for (i = 1; i < cmd->count; i++) { | 235 | for (i = 1; i < cmd->count; i++) { |
239 | if (debug) | 236 | if (debug) |
240 | printk(" 0x%x",cmd->bytes[i]); | 237 | printk(" 0x%x",cmd->bytes[i]); |
@@ -244,8 +241,8 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd) | |||
244 | printk("\n"); | 241 | printk("\n"); |
245 | 242 | ||
246 | /* send data to the chip */ | 243 | /* send data to the chip */ |
247 | if (cmd->count != i2c_master_send(&chip->c,cmd->bytes,cmd->count)) { | 244 | if (cmd->count != i2c_master_send(chip->c,cmd->bytes,cmd->count)) { |
248 | v4l_warn(&chip->c, "%s: I/O error (%s)\n", chip->c.name, name); | 245 | v4l_warn(chip->c, "%s: I/O error (%s)\n", chip->c->name, name); |
249 | return -1; | 246 | return -1; |
250 | } | 247 | } |
251 | return 0; | 248 | return 0; |
@@ -269,7 +266,7 @@ static int chip_thread(void *data) | |||
269 | struct CHIPSTATE *chip = data; | 266 | struct CHIPSTATE *chip = data; |
270 | struct CHIPDESC *desc = chiplist + chip->type; | 267 | struct CHIPDESC *desc = chiplist + chip->type; |
271 | 268 | ||
272 | v4l_dbg(1, debug, &chip->c, "%s: thread started\n", chip->c.name); | 269 | v4l_dbg(1, debug, chip->c, "%s: thread started\n", chip->c->name); |
273 | set_freezable(); | 270 | set_freezable(); |
274 | for (;;) { | 271 | for (;;) { |
275 | set_current_state(TASK_INTERRUPTIBLE); | 272 | set_current_state(TASK_INTERRUPTIBLE); |
@@ -279,7 +276,7 @@ static int chip_thread(void *data) | |||
279 | try_to_freeze(); | 276 | try_to_freeze(); |
280 | if (kthread_should_stop()) | 277 | if (kthread_should_stop()) |
281 | break; | 278 | break; |
282 | v4l_dbg(1, debug, &chip->c, "%s: thread wakeup\n", chip->c.name); | 279 | v4l_dbg(1, debug, chip->c, "%s: thread wakeup\n", chip->c->name); |
283 | 280 | ||
284 | /* don't do anything for radio or if mode != auto */ | 281 | /* don't do anything for radio or if mode != auto */ |
285 | if (chip->radio || chip->mode != 0) | 282 | if (chip->radio || chip->mode != 0) |
@@ -292,7 +289,7 @@ static int chip_thread(void *data) | |||
292 | mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000)); | 289 | mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000)); |
293 | } | 290 | } |
294 | 291 | ||
295 | v4l_dbg(1, debug, &chip->c, "%s: thread exiting\n", chip->c.name); | 292 | v4l_dbg(1, debug, chip->c, "%s: thread exiting\n", chip->c->name); |
296 | return 0; | 293 | return 0; |
297 | } | 294 | } |
298 | 295 | ||
@@ -304,7 +301,7 @@ static void generic_checkmode(struct CHIPSTATE *chip) | |||
304 | if (mode == chip->prevmode) | 301 | if (mode == chip->prevmode) |
305 | return; | 302 | return; |
306 | 303 | ||
307 | v4l_dbg(1, debug, &chip->c, "%s: thread checkmode\n", chip->c.name); | 304 | v4l_dbg(1, debug, chip->c, "%s: thread checkmode\n", chip->c->name); |
308 | chip->prevmode = mode; | 305 | chip->prevmode = mode; |
309 | 306 | ||
310 | if (mode & V4L2_TUNER_MODE_STEREO) | 307 | if (mode & V4L2_TUNER_MODE_STEREO) |
@@ -353,7 +350,7 @@ static int tda9840_getmode(struct CHIPSTATE *chip) | |||
353 | if (val & TDA9840_ST_STEREO) | 350 | if (val & TDA9840_ST_STEREO) |
354 | mode |= V4L2_TUNER_MODE_STEREO; | 351 | mode |= V4L2_TUNER_MODE_STEREO; |
355 | 352 | ||
356 | v4l_dbg(1, debug, &chip->c, "tda9840_getmode(): raw chip read: %d, return: %d\n", | 353 | v4l_dbg(1, debug, chip->c, "tda9840_getmode(): raw chip read: %d, return: %d\n", |
357 | val, mode); | 354 | val, mode); |
358 | return mode; | 355 | return mode; |
359 | } | 356 | } |
@@ -657,7 +654,7 @@ static int tda9873_getmode(struct CHIPSTATE *chip) | |||
657 | mode |= V4L2_TUNER_MODE_STEREO; | 654 | mode |= V4L2_TUNER_MODE_STEREO; |
658 | if (val & TDA9873_DUAL) | 655 | if (val & TDA9873_DUAL) |
659 | mode |= V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; | 656 | mode |= V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; |
660 | v4l_dbg(1, debug, &chip->c, "tda9873_getmode(): raw chip read: %d, return: %d\n", | 657 | v4l_dbg(1, debug, chip->c, "tda9873_getmode(): raw chip read: %d, return: %d\n", |
661 | val, mode); | 658 | val, mode); |
662 | return mode; | 659 | return mode; |
663 | } | 660 | } |
@@ -668,12 +665,12 @@ static void tda9873_setmode(struct CHIPSTATE *chip, int mode) | |||
668 | /* int adj_data = chip->shadow.bytes[TDA9873_AD+1] ; */ | 665 | /* int adj_data = chip->shadow.bytes[TDA9873_AD+1] ; */ |
669 | 666 | ||
670 | if ((sw_data & TDA9873_INP_MASK) != TDA9873_INTERNAL) { | 667 | if ((sw_data & TDA9873_INP_MASK) != TDA9873_INTERNAL) { |
671 | v4l_dbg(1, debug, &chip->c, "tda9873_setmode(): external input\n"); | 668 | v4l_dbg(1, debug, chip->c, "tda9873_setmode(): external input\n"); |
672 | return; | 669 | return; |
673 | } | 670 | } |
674 | 671 | ||
675 | v4l_dbg(1, debug, &chip->c, "tda9873_setmode(): chip->shadow.bytes[%d] = %d\n", TDA9873_SW+1, chip->shadow.bytes[TDA9873_SW+1]); | 672 | v4l_dbg(1, debug, chip->c, "tda9873_setmode(): chip->shadow.bytes[%d] = %d\n", TDA9873_SW+1, chip->shadow.bytes[TDA9873_SW+1]); |
676 | v4l_dbg(1, debug, &chip->c, "tda9873_setmode(): sw_data = %d\n", sw_data); | 673 | v4l_dbg(1, debug, chip->c, "tda9873_setmode(): sw_data = %d\n", sw_data); |
677 | 674 | ||
678 | switch (mode) { | 675 | switch (mode) { |
679 | case V4L2_TUNER_MODE_MONO: | 676 | case V4L2_TUNER_MODE_MONO: |
@@ -694,7 +691,7 @@ static void tda9873_setmode(struct CHIPSTATE *chip, int mode) | |||
694 | } | 691 | } |
695 | 692 | ||
696 | chip_write(chip, TDA9873_SW, sw_data); | 693 | chip_write(chip, TDA9873_SW, sw_data); |
697 | v4l_dbg(1, debug, &chip->c, "tda9873_setmode(): req. mode %d; chip_write: %d\n", | 694 | v4l_dbg(1, debug, chip->c, "tda9873_setmode(): req. mode %d; chip_write: %d\n", |
698 | mode, sw_data); | 695 | mode, sw_data); |
699 | } | 696 | } |
700 | 697 | ||
@@ -833,7 +830,7 @@ static int tda9874a_setup(struct CHIPSTATE *chip) | |||
833 | chip_write(chip, TDA9874A_SDACOSR, (tda9874a_mode) ? 0x81:0x80); | 830 | chip_write(chip, TDA9874A_SDACOSR, (tda9874a_mode) ? 0x81:0x80); |
834 | chip_write(chip, TDA9874A_AOSR, 0x00); /* or 0x10 */ | 831 | chip_write(chip, TDA9874A_AOSR, 0x00); /* or 0x10 */ |
835 | } | 832 | } |
836 | v4l_dbg(1, debug, &chip->c, "tda9874a_setup(): %s [0x%02X].\n", | 833 | v4l_dbg(1, debug, chip->c, "tda9874a_setup(): %s [0x%02X].\n", |
837 | tda9874a_modelist[tda9874a_STD].name,tda9874a_STD); | 834 | tda9874a_modelist[tda9874a_STD].name,tda9874a_STD); |
838 | return 1; | 835 | return 1; |
839 | } | 836 | } |
@@ -876,7 +873,7 @@ static int tda9874a_getmode(struct CHIPSTATE *chip) | |||
876 | mode |= V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; | 873 | mode |= V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; |
877 | } | 874 | } |
878 | 875 | ||
879 | v4l_dbg(1, debug, &chip->c, "tda9874a_getmode(): DSR=0x%X, NSR=0x%X, NECR=0x%X, return: %d.\n", | 876 | v4l_dbg(1, debug, chip->c, "tda9874a_getmode(): DSR=0x%X, NSR=0x%X, NECR=0x%X, return: %d.\n", |
880 | dsr, nsr, necr, mode); | 877 | dsr, nsr, necr, mode); |
881 | return mode; | 878 | return mode; |
882 | } | 879 | } |
@@ -922,7 +919,7 @@ static void tda9874a_setmode(struct CHIPSTATE *chip, int mode) | |||
922 | chip_write(chip, TDA9874A_AOSR, aosr); | 919 | chip_write(chip, TDA9874A_AOSR, aosr); |
923 | chip_write(chip, TDA9874A_MDACOSR, mdacosr); | 920 | chip_write(chip, TDA9874A_MDACOSR, mdacosr); |
924 | 921 | ||
925 | v4l_dbg(1, debug, &chip->c, "tda9874a_setmode(): req. mode %d; AOSR=0x%X, MDACOSR=0x%X.\n", | 922 | v4l_dbg(1, debug, chip->c, "tda9874a_setmode(): req. mode %d; AOSR=0x%X, MDACOSR=0x%X.\n", |
926 | mode, aosr, mdacosr); | 923 | mode, aosr, mdacosr); |
927 | 924 | ||
928 | } else { /* dic == 0x07 */ | 925 | } else { /* dic == 0x07 */ |
@@ -957,7 +954,7 @@ static void tda9874a_setmode(struct CHIPSTATE *chip, int mode) | |||
957 | chip_write(chip, TDA9874A_FMMR, fmmr); | 954 | chip_write(chip, TDA9874A_FMMR, fmmr); |
958 | chip_write(chip, TDA9874A_AOSR, aosr); | 955 | chip_write(chip, TDA9874A_AOSR, aosr); |
959 | 956 | ||
960 | v4l_dbg(1, debug, &chip->c, "tda9874a_setmode(): req. mode %d; FMMR=0x%X, AOSR=0x%X.\n", | 957 | v4l_dbg(1, debug, chip->c, "tda9874a_setmode(): req. mode %d; FMMR=0x%X, AOSR=0x%X.\n", |
961 | mode, fmmr, aosr); | 958 | mode, fmmr, aosr); |
962 | } | 959 | } |
963 | } | 960 | } |
@@ -971,10 +968,10 @@ static int tda9874a_checkit(struct CHIPSTATE *chip) | |||
971 | if(-1 == (sic = chip_read2(chip,TDA9874A_SIC))) | 968 | if(-1 == (sic = chip_read2(chip,TDA9874A_SIC))) |
972 | return 0; | 969 | return 0; |
973 | 970 | ||
974 | v4l_dbg(1, debug, &chip->c, "tda9874a_checkit(): DIC=0x%X, SIC=0x%X.\n", dic, sic); | 971 | v4l_dbg(1, debug, chip->c, "tda9874a_checkit(): DIC=0x%X, SIC=0x%X.\n", dic, sic); |
975 | 972 | ||
976 | if((dic == 0x11)||(dic == 0x07)) { | 973 | if((dic == 0x11)||(dic == 0x07)) { |
977 | v4l_info(&chip->c, "found tda9874%s.\n", (dic == 0x11) ? "a":"h"); | 974 | v4l_info(chip->c, "found tda9874%s.\n", (dic == 0x11) ? "a":"h"); |
978 | tda9874a_dic = dic; /* remember device id. */ | 975 | tda9874a_dic = dic; /* remember device id. */ |
979 | return 1; | 976 | return 1; |
980 | } | 977 | } |
@@ -1097,7 +1094,7 @@ static int tda8425_initialize(struct CHIPSTATE *chip) | |||
1097 | int inputmap[4] = { /* tuner */ TDA8425_S1_CH2, /* radio */ TDA8425_S1_CH1, | 1094 | int inputmap[4] = { /* tuner */ TDA8425_S1_CH2, /* radio */ TDA8425_S1_CH1, |
1098 | /* extern */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF}; | 1095 | /* extern */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF}; |
1099 | 1096 | ||
1100 | if (chip->c.adapter->id == I2C_HW_B_RIVA) { | 1097 | if (chip->c->adapter->id == I2C_HW_B_RIVA) { |
1101 | memcpy (desc->inputmap, inputmap, sizeof (inputmap)); | 1098 | memcpy (desc->inputmap, inputmap, sizeof (inputmap)); |
1102 | } | 1099 | } |
1103 | return 0; | 1100 | return 0; |
@@ -1185,7 +1182,7 @@ static int ta8874z_getmode(struct CHIPSTATE *chip) | |||
1185 | }else if (!(val & TA8874Z_B0)){ | 1182 | }else if (!(val & TA8874Z_B0)){ |
1186 | mode |= V4L2_TUNER_MODE_STEREO; | 1183 | mode |= V4L2_TUNER_MODE_STEREO; |
1187 | } | 1184 | } |
1188 | /* v4l_dbg(1, debug, &chip->c, "ta8874z_getmode(): raw chip read: 0x%02x, return: 0x%02x\n", val, mode); */ | 1185 | /* v4l_dbg(1, debug, chip->c, "ta8874z_getmode(): raw chip read: 0x%02x, return: 0x%02x\n", val, mode); */ |
1189 | return mode; | 1186 | return mode; |
1190 | } | 1187 | } |
1191 | 1188 | ||
@@ -1198,7 +1195,7 @@ static void ta8874z_setmode(struct CHIPSTATE *chip, int mode) | |||
1198 | { | 1195 | { |
1199 | int update = 1; | 1196 | int update = 1; |
1200 | audiocmd *t = NULL; | 1197 | audiocmd *t = NULL; |
1201 | v4l_dbg(1, debug, &chip->c, "ta8874z_setmode(): mode: 0x%02x\n", mode); | 1198 | v4l_dbg(1, debug, chip->c, "ta8874z_setmode(): mode: 0x%02x\n", mode); |
1202 | 1199 | ||
1203 | switch(mode){ | 1200 | switch(mode){ |
1204 | case V4L2_TUNER_MODE_MONO: | 1201 | case V4L2_TUNER_MODE_MONO: |
@@ -1464,51 +1461,55 @@ static struct CHIPDESC chiplist[] = { | |||
1464 | /* ---------------------------------------------------------------------- */ | 1461 | /* ---------------------------------------------------------------------- */ |
1465 | /* i2c registration */ | 1462 | /* i2c registration */ |
1466 | 1463 | ||
1467 | static int chip_attach(struct i2c_adapter *adap, int addr, int kind) | 1464 | static int chip_probe(struct i2c_client *client) |
1468 | { | 1465 | { |
1469 | struct CHIPSTATE *chip; | 1466 | struct CHIPSTATE *chip; |
1470 | struct CHIPDESC *desc; | 1467 | struct CHIPDESC *desc; |
1471 | 1468 | ||
1469 | if (debug) { | ||
1470 | printk(KERN_INFO "tvaudio: TV audio decoder + audio/video mux driver\n"); | ||
1471 | printk(KERN_INFO "tvaudio: known chips: "); | ||
1472 | for (desc = chiplist; desc->name != NULL; desc++) | ||
1473 | printk("%s%s", (desc == chiplist) ? "" : ", ", desc->name); | ||
1474 | printk("\n"); | ||
1475 | } | ||
1476 | |||
1472 | chip = kzalloc(sizeof(*chip),GFP_KERNEL); | 1477 | chip = kzalloc(sizeof(*chip),GFP_KERNEL); |
1473 | if (!chip) | 1478 | if (!chip) |
1474 | return -ENOMEM; | 1479 | return -ENOMEM; |
1475 | memcpy(&chip->c,&client_template,sizeof(struct i2c_client)); | 1480 | chip->c = client; |
1476 | chip->c.adapter = adap; | 1481 | i2c_set_clientdata(client, chip); |
1477 | chip->c.addr = addr; | ||
1478 | i2c_set_clientdata(&chip->c, chip); | ||
1479 | 1482 | ||
1480 | /* find description for the chip */ | 1483 | /* find description for the chip */ |
1481 | v4l_dbg(1, debug, &chip->c, "chip found @ 0x%x\n", addr<<1); | 1484 | v4l_dbg(1, debug, client, "chip found @ 0x%x\n", client->addr<<1); |
1482 | for (desc = chiplist; desc->name != NULL; desc++) { | 1485 | for (desc = chiplist; desc->name != NULL; desc++) { |
1483 | if (0 == *(desc->insmodopt)) | 1486 | if (0 == *(desc->insmodopt)) |
1484 | continue; | 1487 | continue; |
1485 | if (addr < desc->addr_lo || | 1488 | if (client->addr < desc->addr_lo || |
1486 | addr > desc->addr_hi) | 1489 | client->addr > desc->addr_hi) |
1487 | continue; | 1490 | continue; |
1488 | if (desc->checkit && !desc->checkit(chip)) | 1491 | if (desc->checkit && !desc->checkit(chip)) |
1489 | continue; | 1492 | continue; |
1490 | break; | 1493 | break; |
1491 | } | 1494 | } |
1492 | if (desc->name == NULL) { | 1495 | if (desc->name == NULL) { |
1493 | v4l_dbg(1, debug, &chip->c, "no matching chip description found\n"); | 1496 | v4l_dbg(1, debug, client, "no matching chip description found\n"); |
1494 | return -EIO; | 1497 | return -EIO; |
1495 | } | 1498 | } |
1496 | v4l_info(&chip->c, "%s found @ 0x%x (%s)\n", desc->name, addr<<1, adap->name); | 1499 | v4l_info(client, "%s found @ 0x%x (%s)\n", desc->name, client->addr<<1, client->adapter->name); |
1497 | if (desc->flags) { | 1500 | if (desc->flags) { |
1498 | v4l_dbg(1, debug, &chip->c, "matches:%s%s%s.\n", | 1501 | v4l_dbg(1, debug, client, "matches:%s%s%s.\n", |
1499 | (desc->flags & CHIP_HAS_VOLUME) ? " volume" : "", | 1502 | (desc->flags & CHIP_HAS_VOLUME) ? " volume" : "", |
1500 | (desc->flags & CHIP_HAS_BASSTREBLE) ? " bass/treble" : "", | 1503 | (desc->flags & CHIP_HAS_BASSTREBLE) ? " bass/treble" : "", |
1501 | (desc->flags & CHIP_HAS_INPUTSEL) ? " audiomux" : ""); | 1504 | (desc->flags & CHIP_HAS_INPUTSEL) ? " audiomux" : ""); |
1502 | } | 1505 | } |
1503 | 1506 | ||
1504 | /* fill required data structures */ | 1507 | /* fill required data structures */ |
1505 | strcpy(chip->c.name, desc->name); | 1508 | strcpy(client->name, desc->name); |
1506 | chip->type = desc-chiplist; | 1509 | chip->type = desc-chiplist; |
1507 | chip->shadow.count = desc->registers+1; | 1510 | chip->shadow.count = desc->registers+1; |
1508 | chip->prevmode = -1; | 1511 | chip->prevmode = -1; |
1509 | chip->audmode = V4L2_TUNER_MODE_LANG1; | 1512 | chip->audmode = V4L2_TUNER_MODE_LANG1; |
1510 | /* register */ | ||
1511 | i2c_attach_client(&chip->c); | ||
1512 | 1513 | ||
1513 | /* initialization */ | 1514 | /* initialization */ |
1514 | if (desc->initialize != NULL) | 1515 | if (desc->initialize != NULL) |
@@ -1535,28 +1536,17 @@ static int chip_attach(struct i2c_adapter *adap, int addr, int kind) | |||
1535 | init_timer(&chip->wt); | 1536 | init_timer(&chip->wt); |
1536 | chip->wt.function = chip_thread_wake; | 1537 | chip->wt.function = chip_thread_wake; |
1537 | chip->wt.data = (unsigned long)chip; | 1538 | chip->wt.data = (unsigned long)chip; |
1538 | chip->thread = kthread_run(chip_thread, chip, chip->c.name); | 1539 | chip->thread = kthread_run(chip_thread, chip, chip->c->name); |
1539 | if (IS_ERR(chip->thread)) { | 1540 | if (IS_ERR(chip->thread)) { |
1540 | v4l_warn(&chip->c, "%s: failed to create kthread\n", | 1541 | v4l_warn(chip->c, "%s: failed to create kthread\n", |
1541 | chip->c.name); | 1542 | chip->c->name); |
1542 | chip->thread = NULL; | 1543 | chip->thread = NULL; |
1543 | } | 1544 | } |
1544 | } | 1545 | } |
1545 | return 0; | 1546 | return 0; |
1546 | } | 1547 | } |
1547 | 1548 | ||
1548 | static int chip_probe(struct i2c_adapter *adap) | 1549 | static int chip_remove(struct i2c_client *client) |
1549 | { | ||
1550 | /* don't attach on saa7146 based cards, | ||
1551 | because dedicated drivers are used */ | ||
1552 | if ((adap->id == I2C_HW_SAA7146)) | ||
1553 | return 0; | ||
1554 | if (adap->class & I2C_CLASS_TV_ANALOG) | ||
1555 | return i2c_probe(adap, &addr_data, chip_attach); | ||
1556 | return 0; | ||
1557 | } | ||
1558 | |||
1559 | static int chip_detach(struct i2c_client *client) | ||
1560 | { | 1550 | { |
1561 | struct CHIPSTATE *chip = i2c_get_clientdata(client); | 1551 | struct CHIPSTATE *chip = i2c_get_clientdata(client); |
1562 | 1552 | ||
@@ -1567,7 +1557,6 @@ static int chip_detach(struct i2c_client *client) | |||
1567 | chip->thread = NULL; | 1557 | chip->thread = NULL; |
1568 | } | 1558 | } |
1569 | 1559 | ||
1570 | i2c_detach_client(&chip->c); | ||
1571 | kfree(chip); | 1560 | kfree(chip); |
1572 | return 0; | 1561 | return 0; |
1573 | } | 1562 | } |
@@ -1693,7 +1682,7 @@ static int chip_command(struct i2c_client *client, | |||
1693 | struct CHIPSTATE *chip = i2c_get_clientdata(client); | 1682 | struct CHIPSTATE *chip = i2c_get_clientdata(client); |
1694 | struct CHIPDESC *desc = chiplist + chip->type; | 1683 | struct CHIPDESC *desc = chiplist + chip->type; |
1695 | 1684 | ||
1696 | v4l_dbg(1, debug, &chip->c, "%s: chip_command 0x%x\n", chip->c.name, cmd); | 1685 | v4l_dbg(1, debug, chip->c, "%s: chip_command 0x%x\n", chip->c->name, cmd); |
1697 | 1686 | ||
1698 | switch (cmd) { | 1687 | switch (cmd) { |
1699 | case AUDC_SET_RADIO: | 1688 | case AUDC_SET_RADIO: |
@@ -1830,44 +1819,25 @@ static int chip_command(struct i2c_client *client, | |||
1830 | return 0; | 1819 | return 0; |
1831 | } | 1820 | } |
1832 | 1821 | ||
1833 | static struct i2c_driver driver = { | 1822 | static int chip_legacy_probe(struct i2c_adapter *adap) |
1834 | .driver = { | ||
1835 | .name = "tvaudio", | ||
1836 | }, | ||
1837 | .id = I2C_DRIVERID_TVAUDIO, | ||
1838 | .attach_adapter = chip_probe, | ||
1839 | .detach_client = chip_detach, | ||
1840 | .command = chip_command, | ||
1841 | }; | ||
1842 | |||
1843 | static struct i2c_client client_template = | ||
1844 | { | ||
1845 | .name = "(unset)", | ||
1846 | .driver = &driver, | ||
1847 | }; | ||
1848 | |||
1849 | static int __init audiochip_init_module(void) | ||
1850 | { | ||
1851 | struct CHIPDESC *desc; | ||
1852 | |||
1853 | if (debug) { | ||
1854 | printk(KERN_INFO "tvaudio: TV audio decoder + audio/video mux driver\n"); | ||
1855 | printk(KERN_INFO "tvaudio: known chips: "); | ||
1856 | for (desc = chiplist; desc->name != NULL; desc++) | ||
1857 | printk("%s%s", (desc == chiplist) ? "" : ", ", desc->name); | ||
1858 | printk("\n"); | ||
1859 | } | ||
1860 | |||
1861 | return i2c_add_driver(&driver); | ||
1862 | } | ||
1863 | |||
1864 | static void __exit audiochip_cleanup_module(void) | ||
1865 | { | 1823 | { |
1866 | i2c_del_driver(&driver); | 1824 | /* don't attach on saa7146 based cards, |
1825 | because dedicated drivers are used */ | ||
1826 | if ((adap->id == I2C_HW_SAA7146)) | ||
1827 | return 0; | ||
1828 | if (adap->class & I2C_CLASS_TV_ANALOG) | ||
1829 | return 1; | ||
1830 | return 0; | ||
1867 | } | 1831 | } |
1868 | 1832 | ||
1869 | module_init(audiochip_init_module); | 1833 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
1870 | module_exit(audiochip_cleanup_module); | 1834 | .name = "tvaudio", |
1835 | .driverid = I2C_DRIVERID_TVAUDIO, | ||
1836 | .command = chip_command, | ||
1837 | .probe = chip_probe, | ||
1838 | .remove = chip_remove, | ||
1839 | .legacy_probe = chip_legacy_probe, | ||
1840 | }; | ||
1871 | 1841 | ||
1872 | /* | 1842 | /* |
1873 | * Local variables: | 1843 | * Local variables: |