Taken from https://github.com/knight-rider/ptx/tree/master/pt3_dvb, these routines simplify I2C binding of subdevices. Applicable at least to the followings: drivers/media/pci/bt8xx/bttv-input.c drivers/media/pci/cx23885/cx23885-dvb.c drivers/media/pci/cx23885/cx23885-i2c.c drivers/media/pci/cx23885/cx23885.h drivers/media/pci/cx25821/cx25821-i2c.c drivers/media/pci/cx25821/cx25821.h drivers/media/pci/cx88/cx88-input.c drivers/media/pci/cx88/cx88-video.c drivers/media/pci/pt3/pt3.c drivers/media/pci/saa7134/saa7134-i2c.c drivers/media/pci/saa7134/saa7134-input.c drivers/media/pci/saa7134/saa7134.h drivers/media/pci/saa7164/saa7164-i2c.c drivers/media/pci/saa7164/saa7164.h drivers/media/usb/au0828/au0828-i2c.c drivers/media/usb/au0828/au0828.h drivers/media/usb/cx231xx/cx231xx-dvb.c drivers/media/usb/cx231xx/cx231xx-i2c.c drivers/media/usb/cx231xx/cx231xx-input.c drivers/media/usb/cx231xx/cx231xx.h drivers/media/usb/dvb-usb-v2/af9035.c drivers/media/usb/dvb-usb-v2/anysee.c drivers/media/usb/dvb-usb-v2/dvbsky.c drivers/media/usb/dvb-usb-v2/rtl28xxu.c drivers/media/usb/dvb-usb/cxusb.c drivers/media/usb/em28xx/em28xx-cards.c drivers/media/usb/em28xx/em28xx-dvb.c drivers/media/usb/em28xx/em28xx-i2c.c drivers/media/usb/em28xx/em28xx.h drivers/media/usb/go7007/s2250-board.c drivers/media/usb/hdpvr/hdpvr-i2c.c drivers/media/usb/stk1160/stk1160-i2c.c drivers/media/usb/stk1160/stk1160.h drivers/media/usb/tm6000/tm6000-cards.c drivers/media/usb/tm6000/tm6000-i2c.c drivers/media/usb/tm6000/tm6000.h drivers/media/usb/usbvision/usbvision-i2c.c drivers/media/usb/usbvision/usbvision-video.c drivers/media/usb/usbvision/usbvision.h Signed-off-by: Буди Романто, AreMa Inc <knightrider@xxxxxx> --- drivers/media/dvb-core/dvbdev.c | 24 ++++++++++++++++++++++++ drivers/media/dvb-core/dvbdev.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c index 983db75..f449543 100644 --- a/drivers/media/dvb-core/dvbdev.c +++ b/drivers/media/dvb-core/dvbdev.c @@ -284,6 +284,30 @@ void dvb_unregister_device(struct dvb_device *dvbdev) } EXPORT_SYMBOL(dvb_unregister_device); +struct i2c_client *dvb_register_subdev(struct i2c_adapter *adap, struct i2c_board_info const *info) +{ + struct i2c_client *clt; + + request_module("%s", info->type); + clt = i2c_new_device(adap, info); + if (clt && clt->dev.driver) + if (!try_module_get(clt->dev.driver->owner)) { + i2c_unregister_device(clt); + clt = NULL; + } + return clt; +} +EXPORT_SYMBOL(dvb_register_subdev); + +void dvb_unregister_subdev(struct i2c_client *clt) +{ + if (clt) { + module_put(clt->dev.driver->owner); + i2c_unregister_device(clt); + } +} +EXPORT_SYMBOL(dvb_unregister_subdev); + static int dvbdev_check_free_adapter_num(int num) { struct list_head *entry; diff --git a/drivers/media/dvb-core/dvbdev.h b/drivers/media/dvb-core/dvbdev.h index f96b28e..cff2296 100644 --- a/drivers/media/dvb-core/dvbdev.h +++ b/drivers/media/dvb-core/dvbdev.h @@ -109,6 +109,9 @@ extern int dvb_register_device (struct dvb_adapter *adap, extern void dvb_unregister_device (struct dvb_device *dvbdev); +extern struct i2c_client *dvb_register_subdev(struct i2c_adapter *adap, struct i2c_board_info const *info); +extern void dvb_unregister_subdev(struct i2c_client *clt); + extern int dvb_generic_open (struct inode *inode, struct file *file); extern int dvb_generic_release (struct inode *inode, struct file *file); extern long dvb_generic_ioctl (struct file *file, -- 1.8.4.5 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html