diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2008-12-18 11:43:45 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-12-30 06:39:32 -0500 |
commit | 12f91a3fac52ea0fb0913b4e0e66e7357f31251c (patch) | |
tree | bfcbc84c51523b59cff6dfb7c2bf457e879a7f8c /drivers/media/video/tda9875.c | |
parent | 973909e816baa85a969d2edd5ac12a1ca8669cec (diff) |
V4L/DVB (9966): tda9875: convert to v4l2_subdev.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/tda9875.c')
-rw-r--r-- | drivers/media/video/tda9875.c | 348 |
1 files changed, 151 insertions, 197 deletions
diff --git a/drivers/media/video/tda9875.c b/drivers/media/video/tda9875.c index 792f0b079909..56f0c0eb500f 100644 --- a/drivers/media/video/tda9875.c +++ b/drivers/media/video/tda9875.c | |||
@@ -25,11 +25,10 @@ | |||
25 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
26 | #include <linux/errno.h> | 26 | #include <linux/errno.h> |
27 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
28 | #include <linux/videodev2.h> | ||
29 | #include <media/v4l2-common.h> | ||
30 | #include <linux/i2c.h> | 28 | #include <linux/i2c.h> |
31 | #include <linux/init.h> | 29 | #include <linux/videodev2.h> |
32 | 30 | #include <media/v4l2-device.h> | |
31 | #include <media/v4l2-i2c-drv-legacy.h> | ||
33 | #include <media/i2c-addr.h> | 32 | #include <media/i2c-addr.h> |
34 | 33 | ||
35 | static int debug; /* insmod parameter */ | 34 | static int debug; /* insmod parameter */ |
@@ -46,13 +45,15 @@ I2C_CLIENT_INSMOD; | |||
46 | 45 | ||
47 | /* This is a superset of the TDA9875 */ | 46 | /* This is a superset of the TDA9875 */ |
48 | struct tda9875 { | 47 | struct tda9875 { |
48 | struct v4l2_subdev sd; | ||
49 | int rvol, lvol; | 49 | int rvol, lvol; |
50 | int bass, treble; | 50 | int bass, treble; |
51 | struct i2c_client c; | ||
52 | }; | 51 | }; |
53 | 52 | ||
54 | static struct i2c_driver driver; | 53 | static inline struct tda9875 *to_state(struct v4l2_subdev *sd) |
55 | static struct i2c_client client_template; | 54 | { |
55 | return container_of(sd, struct tda9875, sd); | ||
56 | } | ||
56 | 57 | ||
57 | #define dprintk if (debug) printk | 58 | #define dprintk if (debug) printk |
58 | 59 | ||
@@ -105,15 +106,16 @@ static struct i2c_client client_template; | |||
105 | 106 | ||
106 | /* Begin code */ | 107 | /* Begin code */ |
107 | 108 | ||
108 | static int tda9875_write(struct i2c_client *client, int subaddr, unsigned char val) | 109 | static int tda9875_write(struct v4l2_subdev *sd, int subaddr, unsigned char val) |
109 | { | 110 | { |
111 | struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
110 | unsigned char buffer[2]; | 112 | unsigned char buffer[2]; |
111 | dprintk("In tda9875_write\n"); | 113 | |
112 | dprintk("Writing %d 0x%x\n", subaddr, val); | 114 | v4l2_dbg(1, debug, sd, "Writing %d 0x%x\n", subaddr, val); |
113 | buffer[0] = subaddr; | 115 | buffer[0] = subaddr; |
114 | buffer[1] = val; | 116 | buffer[1] = val; |
115 | if (2 != i2c_master_send(client,buffer,2)) { | 117 | if (2 != i2c_master_send(client, buffer, 2)) { |
116 | printk(KERN_WARNING "tda9875: I/O error, trying (write %d 0x%x)\n", | 118 | v4l2_warn(sd, "I/O error, trying (write %d 0x%x)\n", |
117 | subaddr, val); | 119 | subaddr, val); |
118 | return -1; | 120 | return -1; |
119 | } | 121 | } |
@@ -121,7 +123,7 @@ static int tda9875_write(struct i2c_client *client, int subaddr, unsigned char v | |||
121 | } | 123 | } |
122 | 124 | ||
123 | 125 | ||
124 | static int i2c_read_register(struct i2c_adapter *adap, int addr, int reg) | 126 | static int i2c_read_register(struct i2c_client *client, int addr, int reg) |
125 | { | 127 | { |
126 | unsigned char write[1]; | 128 | unsigned char write[1]; |
127 | unsigned char read[1]; | 129 | unsigned char read[1]; |
@@ -129,150 +131,83 @@ static int i2c_read_register(struct i2c_adapter *adap, int addr, int reg) | |||
129 | { addr, 0, 1, write }, | 131 | { addr, 0, 1, write }, |
130 | { addr, I2C_M_RD, 1, read } | 132 | { addr, I2C_M_RD, 1, read } |
131 | }; | 133 | }; |
134 | |||
132 | write[0] = reg; | 135 | write[0] = reg; |
133 | 136 | ||
134 | if (2 != i2c_transfer(adap,msgs,2)) { | 137 | if (2 != i2c_transfer(client->adapter, msgs, 2)) { |
135 | printk(KERN_WARNING "tda9875: I/O error (read2)\n"); | 138 | v4l_warn(client, "I/O error (read2)\n"); |
136 | return -1; | 139 | return -1; |
137 | } | 140 | } |
138 | dprintk("tda9875: chip_read2: reg%d=0x%x\n",reg,read[0]); | 141 | v4l_dbg(1, debug, client, "chip_read2: reg%d=0x%x\n", reg, read[0]); |
139 | return read[0]; | 142 | return read[0]; |
140 | } | 143 | } |
141 | 144 | ||
142 | static void tda9875_set(struct i2c_client *client) | 145 | static void tda9875_set(struct v4l2_subdev *sd) |
143 | { | 146 | { |
144 | struct tda9875 *tda = i2c_get_clientdata(client); | 147 | struct tda9875 *tda = to_state(sd); |
145 | unsigned char a; | 148 | unsigned char a; |
146 | 149 | ||
147 | dprintk(KERN_DEBUG "tda9875_set(%04x,%04x,%04x,%04x)\n", | 150 | v4l2_dbg(1, debug, sd, "tda9875_set(%04x,%04x,%04x,%04x)\n", |
148 | tda->lvol,tda->rvol,tda->bass,tda->treble); | 151 | tda->lvol, tda->rvol, tda->bass, tda->treble); |
149 | |||
150 | 152 | ||
151 | a = tda->lvol & 0xff; | 153 | a = tda->lvol & 0xff; |
152 | tda9875_write(client, TDA9875_MVL, a); | 154 | tda9875_write(sd, TDA9875_MVL, a); |
153 | a =tda->rvol & 0xff; | 155 | a =tda->rvol & 0xff; |
154 | tda9875_write(client, TDA9875_MVR, a); | 156 | tda9875_write(sd, TDA9875_MVR, a); |
155 | a =tda->bass & 0xff; | 157 | a =tda->bass & 0xff; |
156 | tda9875_write(client, TDA9875_MBA, a); | 158 | tda9875_write(sd, TDA9875_MBA, a); |
157 | a =tda->treble & 0xff; | 159 | a =tda->treble & 0xff; |
158 | tda9875_write(client, TDA9875_MTR, a); | 160 | tda9875_write(sd, TDA9875_MTR, a); |
159 | } | 161 | } |
160 | 162 | ||
161 | static void do_tda9875_init(struct i2c_client *client) | 163 | static void do_tda9875_init(struct v4l2_subdev *sd) |
162 | { | 164 | { |
163 | struct tda9875 *t = i2c_get_clientdata(client); | 165 | struct tda9875 *t = to_state(sd); |
164 | dprintk("In tda9875_init\n"); | 166 | |
165 | tda9875_write(client, TDA9875_CFG, 0xd0 ); /*reg de config 0 (reset)*/ | 167 | v4l2_dbg(1, debug, sd, "In tda9875_init\n"); |
166 | tda9875_write(client, TDA9875_MSR, 0x03 ); /* Monitor 0b00000XXX*/ | 168 | tda9875_write(sd, TDA9875_CFG, 0xd0); /*reg de config 0 (reset)*/ |
167 | tda9875_write(client, TDA9875_C1MSB, 0x00 ); /*Car1(FM) MSB XMHz*/ | 169 | tda9875_write(sd, TDA9875_MSR, 0x03); /* Monitor 0b00000XXX*/ |
168 | tda9875_write(client, TDA9875_C1MIB, 0x00 ); /*Car1(FM) MIB XMHz*/ | 170 | tda9875_write(sd, TDA9875_C1MSB, 0x00); /*Car1(FM) MSB XMHz*/ |
169 | tda9875_write(client, TDA9875_C1LSB, 0x00 ); /*Car1(FM) LSB XMHz*/ | 171 | tda9875_write(sd, TDA9875_C1MIB, 0x00); /*Car1(FM) MIB XMHz*/ |
170 | tda9875_write(client, TDA9875_C2MSB, 0x00 ); /*Car2(NICAM) MSB XMHz*/ | 172 | tda9875_write(sd, TDA9875_C1LSB, 0x00); /*Car1(FM) LSB XMHz*/ |
171 | tda9875_write(client, TDA9875_C2MIB, 0x00 ); /*Car2(NICAM) MIB XMHz*/ | 173 | tda9875_write(sd, TDA9875_C2MSB, 0x00); /*Car2(NICAM) MSB XMHz*/ |
172 | tda9875_write(client, TDA9875_C2LSB, 0x00 ); /*Car2(NICAM) LSB XMHz*/ | 174 | tda9875_write(sd, TDA9875_C2MIB, 0x00); /*Car2(NICAM) MIB XMHz*/ |
173 | tda9875_write(client, TDA9875_DCR, 0x00 ); /*Demod config 0x00*/ | 175 | tda9875_write(sd, TDA9875_C2LSB, 0x00); /*Car2(NICAM) LSB XMHz*/ |
174 | tda9875_write(client, TDA9875_DEEM, 0x44 ); /*DE-Emph 0b0100 0100*/ | 176 | tda9875_write(sd, TDA9875_DCR, 0x00); /*Demod config 0x00*/ |
175 | tda9875_write(client, TDA9875_FMAT, 0x00 ); /*FM Matrix reg 0x00*/ | 177 | tda9875_write(sd, TDA9875_DEEM, 0x44); /*DE-Emph 0b0100 0100*/ |
176 | tda9875_write(client, TDA9875_SC1, 0x00 ); /* SCART 1 (SC1)*/ | 178 | tda9875_write(sd, TDA9875_FMAT, 0x00); /*FM Matrix reg 0x00*/ |
177 | tda9875_write(client, TDA9875_SC2, 0x01 ); /* SCART 2 (sc2)*/ | 179 | tda9875_write(sd, TDA9875_SC1, 0x00); /* SCART 1 (SC1)*/ |
178 | 180 | tda9875_write(sd, TDA9875_SC2, 0x01); /* SCART 2 (sc2)*/ | |
179 | tda9875_write(client, TDA9875_CH1V, 0x10 ); /* Channel volume 1 mute*/ | 181 | |
180 | tda9875_write(client, TDA9875_CH2V, 0x10 ); /* Channel volume 2 mute */ | 182 | tda9875_write(sd, TDA9875_CH1V, 0x10); /* Channel volume 1 mute*/ |
181 | tda9875_write(client, TDA9875_DACOS, 0x02 ); /* sig DAC i/o(in:nicam)*/ | 183 | tda9875_write(sd, TDA9875_CH2V, 0x10); /* Channel volume 2 mute */ |
182 | tda9875_write(client, TDA9875_ADCIS, 0x6f ); /* sig ADC input(in:mono)*/ | 184 | tda9875_write(sd, TDA9875_DACOS, 0x02); /* sig DAC i/o(in:nicam)*/ |
183 | tda9875_write(client, TDA9875_LOSR, 0x00 ); /* line out (in:mono)*/ | 185 | tda9875_write(sd, TDA9875_ADCIS, 0x6f); /* sig ADC input(in:mono)*/ |
184 | tda9875_write(client, TDA9875_AER, 0x00 ); /*06 Effect (AVL+PSEUDO) */ | 186 | tda9875_write(sd, TDA9875_LOSR, 0x00); /* line out (in:mono)*/ |
185 | tda9875_write(client, TDA9875_MCS, 0x44 ); /* Main ch select (DAC) */ | 187 | tda9875_write(sd, TDA9875_AER, 0x00); /*06 Effect (AVL+PSEUDO) */ |
186 | tda9875_write(client, TDA9875_MVL, 0x03 ); /* Vol Main left 10dB */ | 188 | tda9875_write(sd, TDA9875_MCS, 0x44); /* Main ch select (DAC) */ |
187 | tda9875_write(client, TDA9875_MVR, 0x03 ); /* Vol Main right 10dB*/ | 189 | tda9875_write(sd, TDA9875_MVL, 0x03); /* Vol Main left 10dB */ |
188 | tda9875_write(client, TDA9875_MBA, 0x00 ); /* Main Bass Main 0dB*/ | 190 | tda9875_write(sd, TDA9875_MVR, 0x03); /* Vol Main right 10dB*/ |
189 | tda9875_write(client, TDA9875_MTR, 0x00 ); /* Main Treble Main 0dB*/ | 191 | tda9875_write(sd, TDA9875_MBA, 0x00); /* Main Bass Main 0dB*/ |
190 | tda9875_write(client, TDA9875_ACS, 0x44 ); /* Aux chan select (dac)*/ | 192 | tda9875_write(sd, TDA9875_MTR, 0x00); /* Main Treble Main 0dB*/ |
191 | tda9875_write(client, TDA9875_AVL, 0x00 ); /* Vol Aux left 0dB*/ | 193 | tda9875_write(sd, TDA9875_ACS, 0x44); /* Aux chan select (dac)*/ |
192 | tda9875_write(client, TDA9875_AVR, 0x00 ); /* Vol Aux right 0dB*/ | 194 | tda9875_write(sd, TDA9875_AVL, 0x00); /* Vol Aux left 0dB*/ |
193 | tda9875_write(client, TDA9875_ABA, 0x00 ); /* Aux Bass Main 0dB*/ | 195 | tda9875_write(sd, TDA9875_AVR, 0x00); /* Vol Aux right 0dB*/ |
194 | tda9875_write(client, TDA9875_ATR, 0x00 ); /* Aux Aigus Main 0dB*/ | 196 | tda9875_write(sd, TDA9875_ABA, 0x00); /* Aux Bass Main 0dB*/ |
195 | 197 | tda9875_write(sd, TDA9875_ATR, 0x00); /* Aux Aigus Main 0dB*/ | |
196 | tda9875_write(client, TDA9875_MUT, 0xcc ); /* General mute */ | 198 | |
197 | 199 | tda9875_write(sd, TDA9875_MUT, 0xcc); /* General mute */ | |
198 | t->lvol=t->rvol =0; /* 0dB */ | 200 | |
199 | t->bass=0; /* 0dB */ | 201 | t->lvol = t->rvol = 0; /* 0dB */ |
200 | t->treble=0; /* 0dB */ | 202 | t->bass = 0; /* 0dB */ |
201 | tda9875_set(client); | 203 | t->treble = 0; /* 0dB */ |
202 | 204 | tda9875_set(sd); | |
203 | } | 205 | } |
204 | 206 | ||
205 | 207 | ||
206 | /* *********************** * | 208 | static int tda9875_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
207 | * i2c interface functions * | ||
208 | * *********************** */ | ||
209 | |||
210 | static int tda9875_checkit(struct i2c_adapter *adap, int addr) | ||
211 | { | ||
212 | int dic,rev; | ||
213 | |||
214 | dic=i2c_read_register(adap,addr,254); | ||
215 | rev=i2c_read_register(adap,addr,255); | ||
216 | |||
217 | if(dic==0 || dic==2) { // tda9875 and tda9875A | ||
218 | printk("tda9875: TDA9875%s Rev.%d detected at 0x%x\n", | ||
219 | dic==0?"":"A", rev,addr<<1); | ||
220 | return 1; | ||
221 | } | ||
222 | printk("tda9875: no such chip at 0x%x (dic=0x%x rev=0x%x)\n",addr<<1,dic,rev); | ||
223 | return(0); | ||
224 | } | ||
225 | |||
226 | static int tda9875_attach(struct i2c_adapter *adap, int addr, int kind) | ||
227 | { | 209 | { |
228 | struct tda9875 *t; | 210 | struct tda9875 *t = to_state(sd); |
229 | struct i2c_client *client; | ||
230 | dprintk("In tda9875_attach\n"); | ||
231 | |||
232 | t = kzalloc(sizeof *t,GFP_KERNEL); | ||
233 | if (!t) | ||
234 | return -ENOMEM; | ||
235 | |||
236 | client = &t->c; | ||
237 | memcpy(client,&client_template,sizeof(struct i2c_client)); | ||
238 | client->adapter = adap; | ||
239 | client->addr = addr; | ||
240 | i2c_set_clientdata(client, t); | ||
241 | |||
242 | if(!tda9875_checkit(adap,addr)) { | ||
243 | kfree(t); | ||
244 | return 1; | ||
245 | } | ||
246 | |||
247 | do_tda9875_init(client); | ||
248 | printk(KERN_INFO "tda9875: init\n"); | ||
249 | |||
250 | i2c_attach_client(client); | ||
251 | return 0; | ||
252 | } | ||
253 | |||
254 | static int tda9875_probe(struct i2c_adapter *adap) | ||
255 | { | ||
256 | if (adap->class & I2C_CLASS_TV_ANALOG) | ||
257 | return i2c_probe(adap, &addr_data, tda9875_attach); | ||
258 | return 0; | ||
259 | } | ||
260 | |||
261 | static int tda9875_detach(struct i2c_client *client) | ||
262 | { | ||
263 | struct tda9875 *t = i2c_get_clientdata(client); | ||
264 | |||
265 | do_tda9875_init(client); | ||
266 | i2c_detach_client(client); | ||
267 | |||
268 | kfree(t); | ||
269 | return 0; | ||
270 | } | ||
271 | |||
272 | static int tda9875_get_ctrl(struct i2c_client *client, | ||
273 | struct v4l2_control *ctrl) | ||
274 | { | ||
275 | struct tda9875 *t = i2c_get_clientdata(client); | ||
276 | 211 | ||
277 | switch (ctrl->id) { | 212 | switch (ctrl->id) { |
278 | case V4L2_CID_AUDIO_VOLUME: | 213 | case V4L2_CID_AUDIO_VOLUME: |
@@ -304,10 +239,9 @@ static int tda9875_get_ctrl(struct i2c_client *client, | |||
304 | return -EINVAL; | 239 | return -EINVAL; |
305 | } | 240 | } |
306 | 241 | ||
307 | static int tda9875_set_ctrl(struct i2c_client *client, | 242 | static int tda9875_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
308 | struct v4l2_control *ctrl) | ||
309 | { | 243 | { |
310 | struct tda9875 *t = i2c_get_clientdata(client); | 244 | struct tda9875 *t = to_state(sd); |
311 | int chvol=0, volume, balance, left, right; | 245 | int chvol=0, volume, balance, left, right; |
312 | 246 | ||
313 | switch (ctrl->id) { | 247 | switch (ctrl->id) { |
@@ -371,85 +305,105 @@ static int tda9875_set_ctrl(struct i2c_client *client, | |||
371 | t->rvol = -84 & 0xff; | 305 | t->rvol = -84 & 0xff; |
372 | } | 306 | } |
373 | 307 | ||
374 | //printk("tda9875 bal:%04x vol:%04x bass:%04x treble:%04x\n",va->balance,va->volume,va->bass,va->treble); | 308 | tda9875_set(sd); |
375 | |||
376 | tda9875_set(client); | ||
377 | |||
378 | return 0; | 309 | return 0; |
379 | } | 310 | } |
380 | 311 | ||
381 | 312 | static int tda9875_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) | |
382 | static int tda9875_command(struct i2c_client *client, | ||
383 | unsigned int cmd, void *arg) | ||
384 | { | 313 | { |
385 | dprintk("In tda9875_command...\n"); | 314 | switch (qc->id) { |
386 | 315 | case V4L2_CID_AUDIO_VOLUME: | |
387 | switch (cmd) { | 316 | case V4L2_CID_AUDIO_BASS: |
388 | /* --- v4l ioctls --- */ | 317 | case V4L2_CID_AUDIO_TREBLE: |
389 | /* take care: bttv does userspace copying, we'll get a | ||
390 | kernel pointer here... */ | ||
391 | case VIDIOC_QUERYCTRL: | ||
392 | { | ||
393 | struct v4l2_queryctrl *qc = arg; | ||
394 | |||
395 | switch (qc->id) { | ||
396 | case V4L2_CID_AUDIO_VOLUME: | ||
397 | case V4L2_CID_AUDIO_BASS: | ||
398 | case V4L2_CID_AUDIO_TREBLE: | ||
399 | default: | ||
400 | return -EINVAL; | ||
401 | } | ||
402 | return v4l2_ctrl_query_fill_std(qc); | 318 | return v4l2_ctrl_query_fill_std(qc); |
403 | } | 319 | } |
404 | case VIDIOC_S_CTRL: | 320 | return -EINVAL; |
405 | return tda9875_set_ctrl(client, arg); | 321 | } |
406 | 322 | ||
407 | case VIDIOC_G_CTRL: | 323 | static int tda9875_command(struct i2c_client *client, unsigned cmd, void *arg) |
408 | return tda9875_get_ctrl(client, arg); | 324 | { |
325 | return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg); | ||
326 | } | ||
409 | 327 | ||
410 | default: /* Not VIDEOCGAUDIO or VIDEOCSAUDIO */ | 328 | /* ----------------------------------------------------------------------- */ |
411 | 329 | ||
412 | /* nothing */ | 330 | static const struct v4l2_subdev_core_ops tda9875_core_ops = { |
413 | dprintk("Default\n"); | 331 | .queryctrl = tda9875_queryctrl, |
332 | .g_ctrl = tda9875_g_ctrl, | ||
333 | .s_ctrl = tda9875_s_ctrl, | ||
334 | }; | ||
414 | 335 | ||
415 | } /* end of (cmd) switch */ | 336 | static const struct v4l2_subdev_ops tda9875_ops = { |
337 | .core = &tda9875_core_ops, | ||
338 | }; | ||
416 | 339 | ||
417 | return 0; | 340 | /* ----------------------------------------------------------------------- */ |
418 | } | ||
419 | 341 | ||
420 | 342 | ||
421 | static struct i2c_driver driver = { | 343 | /* *********************** * |
422 | .driver = { | 344 | * i2c interface functions * |
423 | .name = "tda9875", | 345 | * *********************** */ |
424 | }, | ||
425 | .id = I2C_DRIVERID_TDA9875, | ||
426 | .attach_adapter = tda9875_probe, | ||
427 | .detach_client = tda9875_detach, | ||
428 | .command = tda9875_command, | ||
429 | }; | ||
430 | 346 | ||
431 | static struct i2c_client client_template = | 347 | static int tda9875_checkit(struct i2c_client *client, int addr) |
432 | { | 348 | { |
433 | .name = "tda9875", | 349 | int dic, rev; |
434 | .driver = &driver, | ||
435 | }; | ||
436 | 350 | ||
437 | static int __init tda9875_init(void) | 351 | dic = i2c_read_register(client, addr, 254); |
438 | { | 352 | rev = i2c_read_register(client, addr, 255); |
439 | return i2c_add_driver(&driver); | 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); | ||
361 | return 0; | ||
440 | } | 362 | } |
441 | 363 | ||
442 | static void __exit tda9875_fini(void) | 364 | static int tda9875_probe(struct i2c_client *client, |
365 | const struct i2c_device_id *id) | ||
443 | { | 366 | { |
444 | i2c_del_driver(&driver); | 367 | struct tda9875 *t; |
368 | struct v4l2_subdev *sd; | ||
369 | |||
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; | ||
445 | } | 384 | } |
446 | 385 | ||
447 | module_init(tda9875_init); | 386 | static int tda9875_remove(struct i2c_client *client) |
448 | module_exit(tda9875_fini); | 387 | { |
388 | struct v4l2_subdev *sd = i2c_get_clientdata(client); | ||
449 | 389 | ||
450 | /* | 390 | do_tda9875_init(sd); |
451 | * Local variables: | 391 | v4l2_device_unregister_subdev(sd); |
452 | * c-basic-offset: 8 | 392 | kfree(to_state(sd)); |
453 | * End: | 393 | return 0; |
454 | */ | 394 | } |
455 | 395 | ||
396 | static const struct i2c_device_id tda9875_id[] = { | ||
397 | { "tda9875", 0 }, | ||
398 | { } | ||
399 | }; | ||
400 | MODULE_DEVICE_TABLE(i2c, tda9875_id); | ||
401 | |||
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 | }; | ||