Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / media / dvb-frontends / cxd2880 / cxd2880_io.c
blob9d932bccfa6cae890687def6e41ae8d9e9d22b25
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
7 * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
8 */
10 #include "cxd2880_io.h"
12 int cxd2880_io_common_write_one_reg(struct cxd2880_io *io,
13 enum cxd2880_io_tgt tgt,
14 u8 sub_address, u8 data)
16 if (!io)
17 return -EINVAL;
19 return io->write_regs(io, tgt, sub_address, &data, 1);
22 int cxd2880_io_set_reg_bits(struct cxd2880_io *io,
23 enum cxd2880_io_tgt tgt,
24 u8 sub_address, u8 data, u8 mask)
26 int ret;
28 if (!io)
29 return -EINVAL;
31 if (mask == 0x00)
32 return 0;
34 if (mask != 0xff) {
35 u8 rdata = 0x00;
37 ret = io->read_regs(io, tgt, sub_address, &rdata, 1);
38 if (ret)
39 return ret;
41 data = (data & mask) | (rdata & (mask ^ 0xff));
44 return io->write_reg(io, tgt, sub_address, data);
47 int cxd2880_io_write_multi_regs(struct cxd2880_io *io,
48 enum cxd2880_io_tgt tgt,
49 const struct cxd2880_reg_value reg_value[],
50 u8 size)
52 int ret;
53 int i;
55 if (!io)
56 return -EINVAL;
58 for (i = 0; i < size ; i++) {
59 ret = io->write_reg(io, tgt, reg_value[i].addr,
60 reg_value[i].value);
61 if (ret)
62 return ret;
65 return 0;