-
Notifications
You must be signed in to change notification settings - Fork 4
/
tuner_ftm4862.c
260 lines (212 loc) · 5.77 KB
/
tuner_ftm4862.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
* Driver for FTM4862 tuners.
*
* Copyright (C) 2018 Igor Mokrushin aka McMCC <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "tuner_ftm4862.h"
static struct mxl608_config mxl608_config = {
.xtal_freq_hz = MXL608_XTAL_24MHz,
.if_freq_hz = MXL608_IF_5MHz,
.agc_type = MXL608_AGC_SELF,
.i2c_address = 0x60,
.xtal_cap = 16,
.gain_level = 11,
.if_out_gain_level = 11,
.agc_set_point = 66,
.agc_invert_pol = 0,
.invert_if = 1,
.loop_thru_enable = 0,
.clk_out_enable = 1,
.clk_out_div = 0,
.clk_out_ext = 0,
.xtal_sharing_mode = 0,
.single_supply_3_3V = 1,
};
static struct rda5815m_config rda5815m_config = {
.i2c_address = 0x0c,
};
static int ftm4862_init(struct dvb_frontend *fe)
{
int ret = 0;
ret = rda5815m_init(fe);
ret |= mxl608_init(fe);
return ret;
}
static int ftm4862_get_frequency(struct dvb_frontend *fe, u32 *frequency)
{
struct dual_tuner_priv *state = fe->tuner_priv;
*frequency = state->frequency;
return 0;
}
static int ftm4862_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
{
struct dual_tuner_priv *state = fe->tuner_priv;
*bandwidth = state->bandwidth;
return 0;
}
static int ftm4862_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
{
int ret = 0;
struct dtv_frontend_properties *c = &fe->dtv_property_cache;
*frequency = 0;
switch (c->delivery_system) {
case SYS_ATSC:
case SYS_DVBC_ANNEX_A:
case SYS_DVBC_ANNEX_C:
case SYS_DVBC_ANNEX_B:
case SYS_DVBT:
case SYS_DVBT2:
ret = mxl608_get_if_frequency(fe, frequency);
break;
default:
break;
}
return ret;
}
static int ftm4862_get_status(struct dvb_frontend *fe, u32 *status)
{
int ret = 0;
struct dtv_frontend_properties *c = &fe->dtv_property_cache;
*status = 0;
switch (c->delivery_system) {
case SYS_ATSC:
case SYS_DVBC_ANNEX_A:
case SYS_DVBC_ANNEX_C:
case SYS_DVBC_ANNEX_B:
case SYS_DVBT:
case SYS_DVBT2:
ret = mxl608_get_status(fe, status);
break;
case SYS_DVBS:
case SYS_DVBS2:
default:
*status |= TUNER_STATUS_LOCKED;
break;
}
return ret;
}
static void ftm4862_release(struct dvb_frontend *fe)
{
struct dual_tuner_priv *state = fe->tuner_priv;
fe->tuner_priv = NULL;
kfree(state);
}
static int ftm4862_sleep(struct dvb_frontend *fe)
{
int ret = 0;
ret = rda5815m_sleep(fe);
ret |= mxl608_sleep(fe);
return ret;
}
static int ftm4862_set_params(struct dvb_frontend *fe)
{
int ret = -1;
struct dtv_frontend_properties *c = &fe->dtv_property_cache;
struct dual_tuner_priv *state = fe->tuner_priv;
dev_dbg(&state->i2c->dev,"delivery_system=%d frequency=%d " \
"symbol_rate=%d bandwidth_hz=%d\n",
c->delivery_system, c->frequency, c->symbol_rate,
c->bandwidth_hz);
switch (c->delivery_system) {
case SYS_ATSC:
case SYS_DVBC_ANNEX_A:
case SYS_DVBC_ANNEX_C:
case SYS_DVBC_ANNEX_B:
case SYS_DVBT:
case SYS_DVBT2:
ret = mxl608_set_params(fe);
break;
case SYS_DVBS:
case SYS_DVBS2:
default:
ret = rda5815m_set_params(fe);
break;
}
return ret;
}
static struct dvb_tuner_ops ftm4862_tuner_ops = {
.info = {
.name = "FTM4862 dual tuner MxL608 + RDA5815M"
},
.init = ftm4862_init,
.sleep = ftm4862_sleep,
.set_params = ftm4862_set_params,
.get_status = ftm4862_get_status,
.get_frequency = ftm4862_get_frequency,
.get_bandwidth = ftm4862_get_bandwidth,
.release = ftm4862_release,
.get_if_frequency = ftm4862_get_if_frequency,
};
struct dvb_frontend *ftm4862_attach(struct dvb_frontend *fe,
struct ftm4862_config *cfg, struct i2c_adapter *i2c)
{
struct dual_tuner_priv *state = NULL;
int ret = 0;
u8 val = 0;
state = kzalloc(sizeof(struct dual_tuner_priv), GFP_KERNEL);
if (!state) {
ret = -ENOMEM;
dev_err(&i2c->dev, "kzalloc() failed\n");
goto err1;
}
state->config = &mxl608_config;
state->cfg = &rda5815m_config;
state->i2c = i2c;
if (fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 1);
ret = mxl608_get_chip_id(state);
/* check return value of mxl608_get_chip_id */
if (ret)
goto err2;
if (!state->cfg->xtal_freq)
state->cfg->xtal_freq = 27; /* default set 27 MHz */
ret = rda5815m_read_reg(state, 0x00, &val);
if (ret) {
dev_err(&i2c->dev, "ERROR: %s() failed read reg = 0x00, exited...\n", __func__);
goto err2;
}
if (val != 0x58) {
dev_err(&i2c->dev, "ERROR: %s() RDA5815M unable to identify device(id = 0x%02X), exited...\n", __func__, val);
goto err2;
}
dev_info(&i2c->dev, "RDA5815M detected id = 0x%02X\n", val);
ret = rda5815m_read_reg(state, 0x01, &val);
if (!ret)
dev_info(&i2c->dev, "RDA5815M Chip Rev. = 0x%02X\n", val);
else
goto err2;
ret = rda5815m_read_reg(state, 0x02, &val);
if (!ret)
dev_info(&i2c->dev, "RDA5815M recommended use I2C address = 0x%02X\n", val);
else
goto err2;
dev_info(&i2c->dev, "Attaching FTM4862\n");
fe->tuner_priv = state;
memcpy(&fe->ops.tuner_ops, &ftm4862_tuner_ops,
sizeof(struct dvb_tuner_ops));
return fe;
err2:
if (fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 0);
kfree(state);
err1:
return NULL;
}
EXPORT_SYMBOL(ftm4862_attach);
MODULE_DESCRIPTION("FTM4862 tuner driver");
MODULE_AUTHOR("Igor Mokrushin <[email protected]>");
MODULE_LICENSE("GPL");