diff options
Diffstat (limited to 'drivers/media/video/usbvision/usbvision-i2c.c')
-rw-r--r-- | drivers/media/video/usbvision/usbvision-i2c.c | 147 |
1 files changed, 42 insertions, 105 deletions
diff --git a/drivers/media/video/usbvision/usbvision-i2c.c b/drivers/media/video/usbvision/usbvision-i2c.c index 6057098282ca..dd2f8f27c73b 100644 --- a/drivers/media/video/usbvision/usbvision-i2c.c +++ b/drivers/media/video/usbvision/usbvision-i2c.c | |||
@@ -202,72 +202,78 @@ static struct i2c_algorithm usbvision_algo = { | |||
202 | }; | 202 | }; |
203 | 203 | ||
204 | 204 | ||
205 | /* | ||
206 | * registering functions to load algorithms at runtime | ||
207 | */ | ||
208 | static int usbvision_i2c_usb_add_bus(struct i2c_adapter *adap) | ||
209 | { | ||
210 | PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]"); | ||
211 | PDEBUG(DBG_I2C, "ALGO debugging is enabled [i2c]"); | ||
212 | |||
213 | /* register new adapter to i2c module... */ | ||
214 | |||
215 | adap->algo = &usbvision_algo; | ||
216 | |||
217 | adap->timeout = 100; /* default values, should */ | ||
218 | adap->retries = 3; /* be replaced by defines */ | ||
219 | |||
220 | i2c_add_adapter(adap); | ||
221 | |||
222 | PDEBUG(DBG_I2C,"i2c bus for %s registered", adap->name); | ||
223 | |||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | /* ----------------------------------------------------------------------- */ | 205 | /* ----------------------------------------------------------------------- */ |
228 | /* usbvision specific I2C functions */ | 206 | /* usbvision specific I2C functions */ |
229 | /* ----------------------------------------------------------------------- */ | 207 | /* ----------------------------------------------------------------------- */ |
230 | static struct i2c_adapter i2c_adap_template; | 208 | static struct i2c_adapter i2c_adap_template; |
231 | static struct i2c_client i2c_client_template; | ||
232 | 209 | ||
233 | int usbvision_i2c_register(struct usb_usbvision *usbvision) | 210 | int usbvision_i2c_register(struct usb_usbvision *usbvision) |
234 | { | 211 | { |
212 | static unsigned short saa711x_addrs[] = { | ||
213 | 0x4a >> 1, 0x48 >> 1, /* SAA7111, SAA7111A and SAA7113 */ | ||
214 | 0x42 >> 1, 0x40 >> 1, /* SAA7114, SAA7115 and SAA7118 */ | ||
215 | I2C_CLIENT_END }; | ||
216 | |||
235 | memcpy(&usbvision->i2c_adap, &i2c_adap_template, | 217 | memcpy(&usbvision->i2c_adap, &i2c_adap_template, |
236 | sizeof(struct i2c_adapter)); | 218 | sizeof(struct i2c_adapter)); |
237 | memcpy(&usbvision->i2c_client, &i2c_client_template, | ||
238 | sizeof(struct i2c_client)); | ||
239 | 219 | ||
240 | sprintf(usbvision->i2c_adap.name + strlen(usbvision->i2c_adap.name), | 220 | sprintf(usbvision->i2c_adap.name + strlen(usbvision->i2c_adap.name), |
241 | " #%d", usbvision->vdev->num); | 221 | " #%d", usbvision->vdev->num); |
242 | PDEBUG(DBG_I2C,"Adaptername: %s", usbvision->i2c_adap.name); | 222 | PDEBUG(DBG_I2C,"Adaptername: %s", usbvision->i2c_adap.name); |
243 | usbvision->i2c_adap.dev.parent = &usbvision->dev->dev; | 223 | usbvision->i2c_adap.dev.parent = &usbvision->dev->dev; |
244 | 224 | ||
245 | i2c_set_adapdata(&usbvision->i2c_adap, usbvision); | 225 | i2c_set_adapdata(&usbvision->i2c_adap, &usbvision->v4l2_dev); |
246 | i2c_set_clientdata(&usbvision->i2c_client, usbvision); | ||
247 | |||
248 | usbvision->i2c_client.adapter = &usbvision->i2c_adap; | ||
249 | 226 | ||
250 | if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) { | 227 | if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) { |
251 | printk(KERN_ERR "usbvision_register: can't write reg\n"); | 228 | printk(KERN_ERR "usbvision_register: can't write reg\n"); |
252 | return -EBUSY; | 229 | return -EBUSY; |
253 | } | 230 | } |
254 | 231 | ||
255 | #ifdef CONFIG_MODULES | 232 | PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]"); |
233 | PDEBUG(DBG_I2C, "ALGO debugging is enabled [i2c]"); | ||
234 | |||
235 | /* register new adapter to i2c module... */ | ||
236 | |||
237 | usbvision->i2c_adap.algo = &usbvision_algo; | ||
238 | |||
239 | usbvision->i2c_adap.timeout = 100; /* default values, should */ | ||
240 | usbvision->i2c_adap.retries = 3; /* be replaced by defines */ | ||
241 | |||
242 | i2c_add_adapter(&usbvision->i2c_adap); | ||
243 | |||
244 | PDEBUG(DBG_I2C, "i2c bus for %s registered", usbvision->i2c_adap.name); | ||
245 | |||
256 | /* Request the load of the i2c modules we need */ | 246 | /* Request the load of the i2c modules we need */ |
257 | switch (usbvision_device_data[usbvision->DevModel].Codec) { | 247 | switch (usbvision_device_data[usbvision->DevModel].Codec) { |
258 | case CODEC_SAA7113: | 248 | case CODEC_SAA7113: |
259 | request_module("saa7115"); | ||
260 | break; | ||
261 | case CODEC_SAA7111: | 249 | case CODEC_SAA7111: |
262 | request_module("saa7115"); | 250 | v4l2_i2c_new_probed_subdev(&usbvision->i2c_adap, "saa7115", |
251 | "saa7115_auto", saa711x_addrs); | ||
263 | break; | 252 | break; |
264 | } | 253 | } |
265 | if (usbvision_device_data[usbvision->DevModel].Tuner == 1) { | 254 | if (usbvision_device_data[usbvision->DevModel].Tuner == 1) { |
266 | request_module("tuner"); | 255 | struct v4l2_subdev *sd; |
256 | enum v4l2_i2c_tuner_type type; | ||
257 | struct tuner_setup tun_setup; | ||
258 | |||
259 | sd = v4l2_i2c_new_probed_subdev(&usbvision->i2c_adap, "tuner", | ||
260 | "tuner", v4l2_i2c_tuner_addrs(ADDRS_DEMOD)); | ||
261 | /* depending on whether we found a demod or not, select | ||
262 | the tuner type. */ | ||
263 | type = sd ? ADDRS_TV_WITH_DEMOD : ADDRS_TV; | ||
264 | |||
265 | sd = v4l2_i2c_new_probed_subdev(&usbvision->i2c_adap, "tuner", | ||
266 | "tuner", v4l2_i2c_tuner_addrs(type)); | ||
267 | |||
268 | if (usbvision->tuner_type != -1) { | ||
269 | tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; | ||
270 | tun_setup.type = usbvision->tuner_type; | ||
271 | tun_setup.addr = v4l2_i2c_subdev_addr(sd); | ||
272 | call_all(usbvision, tuner, s_type_addr, &tun_setup); | ||
273 | } | ||
267 | } | 274 | } |
268 | #endif | ||
269 | 275 | ||
270 | return usbvision_i2c_usb_add_bus(&usbvision->i2c_adap); | 276 | return 0; |
271 | } | 277 | } |
272 | 278 | ||
273 | int usbvision_i2c_unregister(struct usb_usbvision *usbvision) | 279 | int usbvision_i2c_unregister(struct usb_usbvision *usbvision) |
@@ -280,67 +286,6 @@ int usbvision_i2c_unregister(struct usb_usbvision *usbvision) | |||
280 | return 0; | 286 | return 0; |
281 | } | 287 | } |
282 | 288 | ||
283 | void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd, | ||
284 | void *arg) | ||
285 | { | ||
286 | i2c_clients_command(&usbvision->i2c_adap, cmd, arg); | ||
287 | } | ||
288 | |||
289 | static int attach_inform(struct i2c_client *client) | ||
290 | { | ||
291 | struct usb_usbvision *usbvision; | ||
292 | |||
293 | usbvision = (struct usb_usbvision *)i2c_get_adapdata(client->adapter); | ||
294 | |||
295 | switch (client->addr << 1) { | ||
296 | case 0x42 << 1: | ||
297 | case 0x43 << 1: | ||
298 | case 0x4a << 1: | ||
299 | case 0x4b << 1: | ||
300 | PDEBUG(DBG_I2C,"attach_inform: tda9887 detected."); | ||
301 | break; | ||
302 | case 0x42: | ||
303 | PDEBUG(DBG_I2C,"attach_inform: saa7114 detected."); | ||
304 | break; | ||
305 | case 0x4a: | ||
306 | PDEBUG(DBG_I2C,"attach_inform: saa7113 detected."); | ||
307 | break; | ||
308 | case 0x48: | ||
309 | PDEBUG(DBG_I2C,"attach_inform: saa7111 detected."); | ||
310 | break; | ||
311 | case 0xa0: | ||
312 | PDEBUG(DBG_I2C,"attach_inform: eeprom detected."); | ||
313 | break; | ||
314 | |||
315 | default: | ||
316 | { | ||
317 | struct tuner_setup tun_setup; | ||
318 | |||
319 | PDEBUG(DBG_I2C,"attach inform: detected I2C address %x", client->addr << 1); | ||
320 | usbvision->tuner_addr = client->addr; | ||
321 | |||
322 | if ((usbvision->have_tuner) && (usbvision->tuner_type != -1)) { | ||
323 | tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; | ||
324 | tun_setup.type = usbvision->tuner_type; | ||
325 | tun_setup.addr = usbvision->tuner_addr; | ||
326 | call_i2c_clients(usbvision, TUNER_SET_TYPE_ADDR, &tun_setup); | ||
327 | } | ||
328 | } | ||
329 | break; | ||
330 | } | ||
331 | return 0; | ||
332 | } | ||
333 | |||
334 | static int detach_inform(struct i2c_client *client) | ||
335 | { | ||
336 | struct usb_usbvision *usbvision; | ||
337 | |||
338 | usbvision = (struct usb_usbvision *)i2c_get_adapdata(client->adapter); | ||
339 | |||
340 | PDEBUG(DBG_I2C,"usbvision[%d] detaches %s", usbvision->nr, client->name); | ||
341 | return 0; | ||
342 | } | ||
343 | |||
344 | static int | 289 | static int |
345 | usbvision_i2c_read_max4(struct usb_usbvision *usbvision, unsigned char addr, | 290 | usbvision_i2c_read_max4(struct usb_usbvision *usbvision, unsigned char addr, |
346 | char *buf, short len) | 291 | char *buf, short len) |
@@ -513,14 +458,6 @@ static int usbvision_i2c_read(struct usb_usbvision *usbvision, unsigned char add | |||
513 | static struct i2c_adapter i2c_adap_template = { | 458 | static struct i2c_adapter i2c_adap_template = { |
514 | .owner = THIS_MODULE, | 459 | .owner = THIS_MODULE, |
515 | .name = "usbvision", | 460 | .name = "usbvision", |
516 | .id = I2C_HW_B_BT848, /* FIXME */ | ||
517 | .client_register = attach_inform, | ||
518 | .client_unregister = detach_inform, | ||
519 | .class = I2C_CLASS_TV_ANALOG, | ||
520 | }; | ||
521 | |||
522 | static struct i2c_client i2c_client_template = { | ||
523 | .name = "usbvision internal", | ||
524 | }; | 461 | }; |
525 | 462 | ||
526 | /* | 463 | /* |