Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* dvb-usb-i2c.c is part of the DVB USB library.
0003  *
0004  * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@posteo.de)
0005  * see dvb-usb-init.c for copyright information.
0006  *
0007  * This file contains functions for (de-)initializing an I2C adapter.
0008  */
0009 #include "dvb-usb-common.h"
0010 
0011 int dvb_usb_i2c_init(struct dvb_usb_device *d)
0012 {
0013     int ret = 0;
0014 
0015     if (!(d->props.caps & DVB_USB_IS_AN_I2C_ADAPTER))
0016         return 0;
0017 
0018     if (d->props.i2c_algo == NULL) {
0019         err("no i2c algorithm specified");
0020         ret = -EINVAL;
0021         goto err;
0022     }
0023 
0024     strscpy(d->i2c_adap.name, d->desc->name, sizeof(d->i2c_adap.name));
0025     d->i2c_adap.algo      = d->props.i2c_algo;
0026     d->i2c_adap.algo_data = NULL;
0027     d->i2c_adap.dev.parent = &d->udev->dev;
0028 
0029     i2c_set_adapdata(&d->i2c_adap, d);
0030 
0031     ret = i2c_add_adapter(&d->i2c_adap);
0032     if (ret < 0) {
0033         err("could not add i2c adapter");
0034         goto err;
0035     }
0036 
0037     d->state |= DVB_USB_STATE_I2C;
0038 
0039 err:
0040     return ret;
0041 }
0042 
0043 int dvb_usb_i2c_exit(struct dvb_usb_device *d)
0044 {
0045     if (d->state & DVB_USB_STATE_I2C)
0046         i2c_del_adapter(&d->i2c_adap);
0047     d->state &= ~DVB_USB_STATE_I2C;
0048     return 0;
0049 }