1 // SPDX-License-Identifier: GPL-2.0
4 * Sony CXD2880 DVB-T2/T tuner + demodulator driver
5 * common monitor functions
7 * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
10 #include "cxd2880_common.h"
11 #include "cxd2880_tnrdmd_mon.h"
13 static const u8 rf_lvl_seq
[2] = {
17 int cxd2880_tnrdmd_mon_rf_lvl(struct cxd2880_tnrdmd
*tnr_dmd
,
23 if (!tnr_dmd
|| !rf_lvl_db
)
26 if (tnr_dmd
->state
!= CXD2880_TNRDMD_STATE_ACTIVE
)
29 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
35 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
41 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
47 ret
= tnr_dmd
->io
->write_regs(tnr_dmd
->io
,
53 usleep_range(2000, 3000);
55 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
61 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
67 if (rdata
[0] || rdata
[1])
70 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
77 cxd2880_convert2s_complement((rdata
[0] << 3) |
78 ((rdata
[1] & 0xe0) >> 5), 11);
82 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
88 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
94 if (tnr_dmd
->rf_lvl_cmpstn
)
95 ret
= tnr_dmd
->rf_lvl_cmpstn(tnr_dmd
, rf_lvl_db
);
100 int cxd2880_tnrdmd_mon_rf_lvl_sub(struct cxd2880_tnrdmd
*tnr_dmd
,
103 if (!tnr_dmd
|| !rf_lvl_db
)
106 if (tnr_dmd
->diver_mode
!= CXD2880_TNRDMD_DIVERMODE_MAIN
)
109 return cxd2880_tnrdmd_mon_rf_lvl(tnr_dmd
->diver_sub
, rf_lvl_db
);
112 int cxd2880_tnrdmd_mon_internal_cpu_status(struct cxd2880_tnrdmd
113 *tnr_dmd
, u16
*status
)
118 if (!tnr_dmd
|| !status
)
121 ret
= tnr_dmd
->io
->write_reg(tnr_dmd
->io
,
126 ret
= tnr_dmd
->io
->read_regs(tnr_dmd
->io
,
132 *status
= (data
[0] << 8) | data
[1];
137 int cxd2880_tnrdmd_mon_internal_cpu_status_sub(struct
142 if (!tnr_dmd
|| !status
)
145 if (tnr_dmd
->diver_mode
!= CXD2880_TNRDMD_DIVERMODE_MAIN
)
148 return cxd2880_tnrdmd_mon_internal_cpu_status(tnr_dmd
->diver_sub
,