cxd2880_io.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * cxd2880_io.c
  4. * Sony CXD2880 DVB-T2/T tuner + demodulator driver
  5. * register I/O interface functions
  6. *
  7. * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
  8. */
  9. #include "cxd2880_io.h"
  10. int cxd2880_io_common_write_one_reg(struct cxd2880_io *io,
  11. enum cxd2880_io_tgt tgt,
  12. u8 sub_address, u8 data)
  13. {
  14. if (!io)
  15. return -EINVAL;
  16. return io->write_regs(io, tgt, sub_address, &data, 1);
  17. }
  18. int cxd2880_io_set_reg_bits(struct cxd2880_io *io,
  19. enum cxd2880_io_tgt tgt,
  20. u8 sub_address, u8 data, u8 mask)
  21. {
  22. int ret;
  23. if (!io)
  24. return -EINVAL;
  25. if (mask == 0x00)
  26. return 0;
  27. if (mask != 0xff) {
  28. u8 rdata = 0x00;
  29. ret = io->read_regs(io, tgt, sub_address, &rdata, 1);
  30. if (ret)
  31. return ret;
  32. data = (data & mask) | (rdata & (mask ^ 0xff));
  33. }
  34. return io->write_reg(io, tgt, sub_address, data);
  35. }
  36. int cxd2880_io_write_multi_regs(struct cxd2880_io *io,
  37. enum cxd2880_io_tgt tgt,
  38. const struct cxd2880_reg_value reg_value[],
  39. u8 size)
  40. {
  41. int ret;
  42. int i;
  43. if (!io)
  44. return -EINVAL;
  45. for (i = 0; i < size ; i++) {
  46. ret = io->write_reg(io, tgt, reg_value[i].addr,
  47. reg_value[i].value);
  48. if (ret)
  49. return ret;
  50. }
  51. return 0;
  52. }