dvb-usb-i2c.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* dvb-usb-i2c.c is part of the DVB USB library.
  3. *
  4. * Copyright (C) 2004-6 Patrick Boettcher ([email protected])
  5. * see dvb-usb-init.c for copyright information.
  6. *
  7. * This file contains functions for (de-)initializing an I2C adapter.
  8. */
  9. #include "dvb-usb-common.h"
  10. int dvb_usb_i2c_init(struct dvb_usb_device *d)
  11. {
  12. int ret = 0;
  13. if (!(d->props.caps & DVB_USB_IS_AN_I2C_ADAPTER))
  14. return 0;
  15. if (d->props.i2c_algo == NULL) {
  16. err("no i2c algorithm specified");
  17. ret = -EINVAL;
  18. goto err;
  19. }
  20. strscpy(d->i2c_adap.name, d->desc->name, sizeof(d->i2c_adap.name));
  21. d->i2c_adap.algo = d->props.i2c_algo;
  22. d->i2c_adap.algo_data = NULL;
  23. d->i2c_adap.dev.parent = &d->udev->dev;
  24. i2c_set_adapdata(&d->i2c_adap, d);
  25. ret = i2c_add_adapter(&d->i2c_adap);
  26. if (ret < 0) {
  27. err("could not add i2c adapter");
  28. goto err;
  29. }
  30. d->state |= DVB_USB_STATE_I2C;
  31. err:
  32. return ret;
  33. }
  34. int dvb_usb_i2c_exit(struct dvb_usb_device *d)
  35. {
  36. if (d->state & DVB_USB_STATE_I2C)
  37. i2c_del_adapter(&d->i2c_adap);
  38. d->state &= ~DVB_USB_STATE_I2C;
  39. return 0;
  40. }