]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/media/dvb-frontends/cxd2880/cxd2880_io.c
This is the driver for Sony CXD2880 DVB-T2/T tuner + demodulator. It includes the...
[mirror_ubuntu-artful-kernel.git] / drivers / media / dvb-frontends / cxd2880 / cxd2880_io.c
1 /*
2 * cxd2880_io.c
3 * Sony CXD2880 DVB-T2/T tuner + demodulator driver
4 * register I/O interface functions
5 *
6 * Copyright (C) 2016, 2017 Sony Semiconductor Solutions Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; version 2 of the License.
11 *
12 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
15 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
18 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, see <http://www.gnu.org/licenses/>.
25 */
26
27 #include "cxd2880_io.h"
28
29 enum cxd2880_ret cxd2880_io_common_write_one_reg(struct cxd2880_io *io,
30 enum cxd2880_io_tgt tgt,
31 u8 sub_address, u8 data)
32 {
33 enum cxd2880_ret ret = CXD2880_RESULT_OK;
34
35 if (!io)
36 return CXD2880_RESULT_ERROR_ARG;
37
38 ret = io->write_regs(io, tgt, sub_address, &data, 1);
39
40 return ret;
41 }
42
43 enum cxd2880_ret cxd2880_io_set_reg_bits(struct cxd2880_io *io,
44 enum cxd2880_io_tgt tgt,
45 u8 sub_address, u8 data, u8 mask)
46 {
47 enum cxd2880_ret ret = CXD2880_RESULT_OK;
48
49 if (!io)
50 return CXD2880_RESULT_ERROR_ARG;
51
52 if (mask == 0x00)
53 return CXD2880_RESULT_OK;
54
55 if (mask != 0xFF) {
56 u8 rdata = 0x00;
57
58 ret = io->read_regs(io, tgt, sub_address, &rdata, 1);
59 if (ret != CXD2880_RESULT_OK)
60 return ret;
61
62 data = (u8)((data & mask) | (rdata & (mask ^ 0xFF)));
63 }
64
65 ret = io->write_reg(io, tgt, sub_address, data);
66
67 return ret;
68 }