Commit | Line | Data |
---|---|---|
74ba9207 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
c46b6562 MA |
2 | /* |
3 | STB6100 Silicon Tuner | |
4 | Copyright (C) Manu Abraham (abraham.manu@gmail.com) | |
5 | ||
6 | Copyright (C) ST Microelectronics | |
7 | ||
c46b6562 MA |
8 | */ |
9 | ||
10 | #include <linux/init.h> | |
11 | #include <linux/kernel.h> | |
12 | #include <linux/module.h> | |
5a0e3ad6 | 13 | #include <linux/slab.h> |
c46b6562 MA |
14 | #include <linux/string.h> |
15 | ||
fada1935 | 16 | #include <media/dvb_frontend.h> |
c46b6562 MA |
17 | #include "stb6100.h" |
18 | ||
19 | static unsigned int verbose; | |
20 | module_param(verbose, int, 0644); | |
21 | ||
8393796d MCC |
22 | /* Max transfer size done by I2C transfer functions */ |
23 | #define MAX_XFER_SIZE 64 | |
c46b6562 MA |
24 | |
25 | #define FE_ERROR 0 | |
26 | #define FE_NOTICE 1 | |
27 | #define FE_INFO 2 | |
28 | #define FE_DEBUG 3 | |
29 | ||
30 | #define dprintk(x, y, z, format, arg...) do { \ | |
31 | if (z) { \ | |
32 | if ((x > FE_ERROR) && (x > y)) \ | |
33 | printk(KERN_ERR "%s: " format "\n", __func__ , ##arg); \ | |
34 | else if ((x > FE_NOTICE) && (x > y)) \ | |
35 | printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg); \ | |
36 | else if ((x > FE_INFO) && (x > y)) \ | |
37 | printk(KERN_INFO "%s: " format "\n", __func__ , ##arg); \ | |
38 | else if ((x > FE_DEBUG) && (x > y)) \ | |
39 | printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg); \ | |
40 | } else { \ | |
41 | if (x > y) \ | |
42 | printk(format, ##arg); \ | |
43 | } \ | |
f14bfe94 | 44 | } while (0) |
c46b6562 MA |
45 | |
46 | struct stb6100_lkup { | |
47 | u32 val_low; | |
48 | u32 val_high; | |
49 | u8 reg; | |
50 | }; | |
51 | ||
f2709c20 MCC |
52 | static void stb6100_release(struct dvb_frontend *fe); |
53 | ||
c46b6562 MA |
54 | static const struct stb6100_lkup lkup[] = { |
55 | { 0, 950000, 0x0a }, | |
56 | { 950000, 1000000, 0x0a }, | |
57 | { 1000000, 1075000, 0x0c }, | |
58 | { 1075000, 1200000, 0x00 }, | |
59 | { 1200000, 1300000, 0x01 }, | |
60 | { 1300000, 1370000, 0x02 }, | |
61 | { 1370000, 1470000, 0x04 }, | |
62 | { 1470000, 1530000, 0x05 }, | |
63 | { 1530000, 1650000, 0x06 }, | |
64 | { 1650000, 1800000, 0x08 }, | |
65 | { 1800000, 1950000, 0x0a }, | |
66 | { 1950000, 2150000, 0x0c }, | |
67 | { 2150000, 9999999, 0x0c }, | |
68 | { 0, 0, 0x00 } | |
69 | }; | |
70 | ||
71 | /* Register names for easy debugging. */ | |
72 | static const char *stb6100_regnames[] = { | |
73 | [STB6100_LD] = "LD", | |
74 | [STB6100_VCO] = "VCO", | |
75 | [STB6100_NI] = "NI", | |
76 | [STB6100_NF_LSB] = "NF", | |
77 | [STB6100_K] = "K", | |
78 | [STB6100_G] = "G", | |
79 | [STB6100_F] = "F", | |
80 | [STB6100_DLB] = "DLB", | |
81 | [STB6100_TEST1] = "TEST1", | |
82 | [STB6100_FCCK] = "FCCK", | |
83 | [STB6100_LPEN] = "LPEN", | |
84 | [STB6100_TEST3] = "TEST3", | |
85 | }; | |
86 | ||
87 | /* Template for normalisation, i.e. setting unused or undocumented | |
88 | * bits as required according to the documentation. | |
89 | */ | |
90 | struct stb6100_regmask { | |
91 | u8 mask; | |
92 | u8 set; | |
93 | }; | |
94 | ||
95 | static const struct stb6100_regmask stb6100_template[] = { | |
96 | [STB6100_LD] = { 0xff, 0x00 }, | |
97 | [STB6100_VCO] = { 0xff, 0x00 }, | |
98 | [STB6100_NI] = { 0xff, 0x00 }, | |
99 | [STB6100_NF_LSB] = { 0xff, 0x00 }, | |
100 | [STB6100_K] = { 0xc7, 0x38 }, | |
101 | [STB6100_G] = { 0xef, 0x10 }, | |
102 | [STB6100_F] = { 0x1f, 0xc0 }, | |
103 | [STB6100_DLB] = { 0x38, 0xc4 }, | |
104 | [STB6100_TEST1] = { 0x00, 0x8f }, | |
105 | [STB6100_FCCK] = { 0x40, 0x0d }, | |
106 | [STB6100_LPEN] = { 0xf0, 0x0b }, | |
107 | [STB6100_TEST3] = { 0x00, 0xde }, | |
108 | }; | |
109 | ||
a931910d MCC |
110 | /* |
111 | * Currently unused. Some boards might need it in the future | |
112 | */ | |
113 | static inline void stb6100_normalise_regs(u8 regs[]) | |
c46b6562 MA |
114 | { |
115 | int i; | |
116 | ||
117 | for (i = 0; i < STB6100_NUMREGS; i++) | |
118 | regs[i] = (regs[i] & stb6100_template[i].mask) | stb6100_template[i].set; | |
119 | } | |
120 | ||
121 | static int stb6100_read_regs(struct stb6100_state *state, u8 regs[]) | |
122 | { | |
123 | int rc; | |
124 | struct i2c_msg msg = { | |
125 | .addr = state->config->tuner_address, | |
126 | .flags = I2C_M_RD, | |
127 | .buf = regs, | |
128 | .len = STB6100_NUMREGS | |
129 | }; | |
130 | ||
c46b6562 | 131 | rc = i2c_transfer(state->i2c, &msg, 1); |
c46b6562 MA |
132 | if (unlikely(rc != 1)) { |
133 | dprintk(verbose, FE_ERROR, 1, "Read (0x%x) err, rc=[%d]", | |
134 | state->config->tuner_address, rc); | |
135 | ||
136 | return -EREMOTEIO; | |
137 | } | |
138 | if (unlikely(verbose > FE_DEBUG)) { | |
139 | int i; | |
140 | ||
141 | dprintk(verbose, FE_DEBUG, 1, " Read from 0x%02x", state->config->tuner_address); | |
142 | for (i = 0; i < STB6100_NUMREGS; i++) | |
143 | dprintk(verbose, FE_DEBUG, 1, " %s: 0x%02x", stb6100_regnames[i], regs[i]); | |
144 | } | |
145 | return 0; | |
146 | } | |
147 | ||
148 | static int stb6100_read_reg(struct stb6100_state *state, u8 reg) | |
149 | { | |
150 | u8 regs[STB6100_NUMREGS]; | |
c46b6562 | 151 | |
f14bfe94 MA |
152 | struct i2c_msg msg = { |
153 | .addr = state->config->tuner_address + reg, | |
154 | .flags = I2C_M_RD, | |
155 | .buf = regs, | |
156 | .len = 1 | |
157 | }; | |
158 | ||
fdf07b02 | 159 | i2c_transfer(state->i2c, &msg, 1); |
f14bfe94 | 160 | |
c46b6562 MA |
161 | if (unlikely(reg >= STB6100_NUMREGS)) { |
162 | dprintk(verbose, FE_ERROR, 1, "Invalid register offset 0x%x", reg); | |
163 | return -EINVAL; | |
164 | } | |
f14bfe94 MA |
165 | if (unlikely(verbose > FE_DEBUG)) { |
166 | dprintk(verbose, FE_DEBUG, 1, " Read from 0x%02x", state->config->tuner_address); | |
167 | dprintk(verbose, FE_DEBUG, 1, " %s: 0x%02x", stb6100_regnames[reg], regs[0]); | |
168 | } | |
169 | ||
170 | return (unsigned int)regs[0]; | |
c46b6562 MA |
171 | } |
172 | ||
173 | static int stb6100_write_reg_range(struct stb6100_state *state, u8 buf[], int start, int len) | |
174 | { | |
175 | int rc; | |
8393796d | 176 | u8 cmdbuf[MAX_XFER_SIZE]; |
c46b6562 MA |
177 | struct i2c_msg msg = { |
178 | .addr = state->config->tuner_address, | |
179 | .flags = 0, | |
180 | .buf = cmdbuf, | |
181 | .len = len + 1 | |
182 | }; | |
183 | ||
7e6bd12f | 184 | if (1 + len > sizeof(cmdbuf)) { |
8393796d MCC |
185 | printk(KERN_WARNING |
186 | "%s: i2c wr: len=%d is too big!\n", | |
187 | KBUILD_MODNAME, len); | |
188 | return -EINVAL; | |
189 | } | |
190 | ||
c46b6562 MA |
191 | if (unlikely(start < 1 || start + len > STB6100_NUMREGS)) { |
192 | dprintk(verbose, FE_ERROR, 1, "Invalid register range %d:%d", | |
193 | start, len); | |
194 | return -EINVAL; | |
195 | } | |
196 | memcpy(&cmdbuf[1], buf, len); | |
197 | cmdbuf[0] = start; | |
198 | ||
199 | if (unlikely(verbose > FE_DEBUG)) { | |
200 | int i; | |
201 | ||
202 | dprintk(verbose, FE_DEBUG, 1, " Write @ 0x%02x: [%d:%d]", state->config->tuner_address, start, len); | |
203 | for (i = 0; i < len; i++) | |
204 | dprintk(verbose, FE_DEBUG, 1, " %s: 0x%02x", stb6100_regnames[start + i], buf[i]); | |
205 | } | |
c46b6562 | 206 | rc = i2c_transfer(state->i2c, &msg, 1); |
c46b6562 MA |
207 | if (unlikely(rc != 1)) { |
208 | dprintk(verbose, FE_ERROR, 1, "(0x%x) write err [%d:%d], rc=[%d]", | |
209 | (unsigned int)state->config->tuner_address, start, len, rc); | |
210 | return -EREMOTEIO; | |
211 | } | |
212 | return 0; | |
213 | } | |
214 | ||
215 | static int stb6100_write_reg(struct stb6100_state *state, u8 reg, u8 data) | |
216 | { | |
3cd890db AB |
217 | u8 tmp = data; /* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */ |
218 | ||
c46b6562 MA |
219 | if (unlikely(reg >= STB6100_NUMREGS)) { |
220 | dprintk(verbose, FE_ERROR, 1, "Invalid register offset 0x%x", reg); | |
221 | return -EREMOTEIO; | |
222 | } | |
3cd890db AB |
223 | tmp = (tmp & stb6100_template[reg].mask) | stb6100_template[reg].set; |
224 | return stb6100_write_reg_range(state, &tmp, reg, 1); | |
c46b6562 MA |
225 | } |
226 | ||
c46b6562 MA |
227 | |
228 | static int stb6100_get_status(struct dvb_frontend *fe, u32 *status) | |
229 | { | |
230 | int rc; | |
231 | struct stb6100_state *state = fe->tuner_priv; | |
232 | ||
f14bfe94 MA |
233 | rc = stb6100_read_reg(state, STB6100_LD); |
234 | if (rc < 0) { | |
235 | dprintk(verbose, FE_ERROR, 1, "%s failed", __func__); | |
c46b6562 | 236 | return rc; |
f14bfe94 | 237 | } |
c46b6562 MA |
238 | return (rc & STB6100_LD_LOCK) ? TUNER_STATUS_LOCKED : 0; |
239 | } | |
240 | ||
241 | static int stb6100_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth) | |
242 | { | |
243 | int rc; | |
244 | u8 f; | |
cffdbfe7 | 245 | u32 bw; |
c46b6562 MA |
246 | struct stb6100_state *state = fe->tuner_priv; |
247 | ||
f14bfe94 MA |
248 | rc = stb6100_read_reg(state, STB6100_F); |
249 | if (rc < 0) | |
c46b6562 MA |
250 | return rc; |
251 | f = rc & STB6100_F_F; | |
252 | ||
cffdbfe7 | 253 | bw = (f + 5) * 2000; /* x2 for ZIF */ |
c46b6562 | 254 | |
cffdbfe7 | 255 | *bandwidth = state->bandwidth = bw * 1000; |
c46b6562 MA |
256 | dprintk(verbose, FE_DEBUG, 1, "bandwidth = %u Hz", state->bandwidth); |
257 | return 0; | |
258 | } | |
259 | ||
260 | static int stb6100_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth) | |
261 | { | |
262 | u32 tmp; | |
263 | int rc; | |
264 | struct stb6100_state *state = fe->tuner_priv; | |
265 | ||
89693b7d | 266 | dprintk(verbose, FE_DEBUG, 1, "set bandwidth to %u Hz", bandwidth); |
c46b6562 | 267 | |
763fbaf6 | 268 | bandwidth /= 2; /* ZIF */ |
c46b6562 | 269 | |
89693b7d | 270 | if (bandwidth >= 36000000) /* F[4:0] BW/2 max =31+5=36 mhz for F=31 */ |
c46b6562 | 271 | tmp = 31; |
89693b7d | 272 | else if (bandwidth <= 5000000) /* bw/2 min = 5Mhz for F=0 */ |
c46b6562 MA |
273 | tmp = 0; |
274 | else /* if 5 < bw/2 < 36 */ | |
6f6c268b | 275 | tmp = (bandwidth + 500000) / 1000000 - 5; |
c46b6562 MA |
276 | |
277 | /* Turn on LPF bandwidth setting clock control, | |
278 | * set bandwidth, wait 10ms, turn off. | |
279 | */ | |
f14bfe94 MA |
280 | rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d | STB6100_FCCK_FCCK); |
281 | if (rc < 0) | |
c46b6562 | 282 | return rc; |
f14bfe94 MA |
283 | rc = stb6100_write_reg(state, STB6100_F, 0xc0 | tmp); |
284 | if (rc < 0) | |
c46b6562 | 285 | return rc; |
f14bfe94 MA |
286 | |
287 | msleep(5); /* This is dangerous as another (related) thread may start */ | |
288 | ||
289 | rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d); | |
290 | if (rc < 0) | |
c46b6562 MA |
291 | return rc; |
292 | ||
f14bfe94 MA |
293 | msleep(10); /* This is dangerous as another (related) thread may start */ |
294 | ||
c46b6562 MA |
295 | return 0; |
296 | } | |
297 | ||
298 | static int stb6100_get_frequency(struct dvb_frontend *fe, u32 *frequency) | |
299 | { | |
300 | int rc; | |
301 | u32 nint, nfrac, fvco; | |
302 | int psd2, odiv; | |
303 | struct stb6100_state *state = fe->tuner_priv; | |
304 | u8 regs[STB6100_NUMREGS]; | |
305 | ||
f14bfe94 MA |
306 | rc = stb6100_read_regs(state, regs); |
307 | if (rc < 0) | |
c46b6562 MA |
308 | return rc; |
309 | ||
310 | odiv = (regs[STB6100_VCO] & STB6100_VCO_ODIV) >> STB6100_VCO_ODIV_SHIFT; | |
311 | psd2 = (regs[STB6100_K] & STB6100_K_PSD2) >> STB6100_K_PSD2_SHIFT; | |
312 | nint = regs[STB6100_NI]; | |
313 | nfrac = ((regs[STB6100_K] & STB6100_K_NF_MSB) << 8) | regs[STB6100_NF_LSB]; | |
314 | fvco = (nfrac * state->reference >> (9 - psd2)) + (nint * state->reference << psd2); | |
315 | *frequency = state->frequency = fvco >> (odiv + 1); | |
316 | ||
317 | dprintk(verbose, FE_DEBUG, 1, | |
318 | "frequency = %u kHz, odiv = %u, psd2 = %u, fxtal = %u kHz, fvco = %u kHz, N(I) = %u, N(F) = %u", | |
319 | state->frequency, odiv, psd2, state->reference, fvco, nint, nfrac); | |
320 | return 0; | |
321 | } | |
322 | ||
323 | ||
324 | static int stb6100_set_frequency(struct dvb_frontend *fe, u32 frequency) | |
325 | { | |
326 | int rc; | |
327 | const struct stb6100_lkup *ptr; | |
328 | struct stb6100_state *state = fe->tuner_priv; | |
1e73fa5d | 329 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
c46b6562 MA |
330 | |
331 | u32 srate = 0, fvco, nint, nfrac; | |
332 | u8 regs[STB6100_NUMREGS]; | |
333 | u8 g, psd2, odiv; | |
334 | ||
f14bfe94 | 335 | dprintk(verbose, FE_DEBUG, 1, "Version 2010-8-14 13:51"); |
3f400925 | 336 | |
5135986e | 337 | if (fe->ops.get_frontend) { |
3f400925 | 338 | dprintk(verbose, FE_DEBUG, 1, "Get frontend parameters"); |
7e3e68bc | 339 | fe->ops.get_frontend(fe, p); |
c46b6562 | 340 | } |
1e73fa5d | 341 | srate = p->symbol_rate; |
c46b6562 | 342 | |
f14bfe94 MA |
343 | /* Set up tuner cleanly, LPF calibration on */ |
344 | rc = stb6100_write_reg(state, STB6100_FCCK, 0x4d | STB6100_FCCK_FCCK); | |
345 | if (rc < 0) | |
346 | return rc; /* allow LPF calibration */ | |
20dafb3b | 347 | |
f14bfe94 MA |
348 | /* PLL Loop disabled, bias on, VCO on, synth on */ |
349 | regs[STB6100_LPEN] = 0xeb; | |
350 | rc = stb6100_write_reg(state, STB6100_LPEN, regs[STB6100_LPEN]); | |
351 | if (rc < 0) | |
20dafb3b AJ |
352 | return rc; |
353 | ||
f14bfe94 | 354 | /* Program the registers with their data values */ |
c46b6562 MA |
355 | |
356 | /* VCO divide ratio (LO divide ratio, VCO prescaler enable). */ | |
357 | if (frequency <= 1075000) | |
358 | odiv = 1; | |
359 | else | |
360 | odiv = 0; | |
c46b6562 | 361 | |
25985edc | 362 | /* VCO enabled, search clock off as per LL3.7, 3.4.1 */ |
f14bfe94 | 363 | regs[STB6100_VCO] = 0xe0 | (odiv << STB6100_VCO_ODIV_SHIFT); |
c46b6562 MA |
364 | |
365 | /* OSM */ | |
366 | for (ptr = lkup; | |
367 | (ptr->val_high != 0) && !CHKRANGE(frequency, ptr->val_low, ptr->val_high); | |
368 | ptr++); | |
f14bfe94 | 369 | |
c46b6562 MA |
370 | if (ptr->val_high == 0) { |
371 | printk(KERN_ERR "%s: frequency out of range: %u kHz\n", __func__, frequency); | |
372 | return -EINVAL; | |
373 | } | |
374 | regs[STB6100_VCO] = (regs[STB6100_VCO] & ~STB6100_VCO_OSM) | ptr->reg; | |
f14bfe94 MA |
375 | rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO]); |
376 | if (rc < 0) | |
377 | return rc; | |
c46b6562 | 378 | |
f14bfe94 MA |
379 | if ((frequency > 1075000) && (frequency <= 1325000)) |
380 | psd2 = 0; | |
381 | else | |
382 | psd2 = 1; | |
c46b6562 MA |
383 | /* F(VCO) = F(LO) * (ODIV == 0 ? 2 : 4) */ |
384 | fvco = frequency << (1 + odiv); | |
385 | /* N(I) = floor(f(VCO) / (f(XTAL) * (PSD2 ? 2 : 1))) */ | |
386 | nint = fvco / (state->reference << psd2); | |
387 | /* N(F) = round(f(VCO) / f(XTAL) * (PSD2 ? 2 : 1) - N(I)) * 2 ^ 9 */ | |
75b697f7 | 388 | nfrac = DIV_ROUND_CLOSEST((fvco - (nint * state->reference << psd2)) |
f14bfe94 MA |
389 | << (9 - psd2), state->reference); |
390 | ||
391 | /* NI */ | |
392 | regs[STB6100_NI] = nint; | |
393 | rc = stb6100_write_reg(state, STB6100_NI, regs[STB6100_NI]); | |
394 | if (rc < 0) | |
395 | return rc; | |
396 | ||
397 | /* NF */ | |
398 | regs[STB6100_NF_LSB] = nfrac; | |
399 | rc = stb6100_write_reg(state, STB6100_NF_LSB, regs[STB6100_NF_LSB]); | |
400 | if (rc < 0) | |
401 | return rc; | |
402 | ||
403 | /* K */ | |
404 | regs[STB6100_K] = (0x38 & ~STB6100_K_PSD2) | (psd2 << STB6100_K_PSD2_SHIFT); | |
405 | regs[STB6100_K] = (regs[STB6100_K] & ~STB6100_K_NF_MSB) | ((nfrac >> 8) & STB6100_K_NF_MSB); | |
406 | rc = stb6100_write_reg(state, STB6100_K, regs[STB6100_K]); | |
407 | if (rc < 0) | |
408 | return rc; | |
409 | ||
410 | /* G Baseband gain. */ | |
411 | if (srate >= 15000000) | |
412 | g = 9; /* +4 dB */ | |
413 | else if (srate >= 5000000) | |
414 | g = 11; /* +8 dB */ | |
415 | else | |
416 | g = 14; /* +14 dB */ | |
417 | ||
418 | regs[STB6100_G] = (0x10 & ~STB6100_G_G) | g; | |
419 | regs[STB6100_G] &= ~STB6100_G_GCT; /* mask GCT */ | |
420 | regs[STB6100_G] |= (1 << 5); /* 2Vp-p Mode */ | |
421 | rc = stb6100_write_reg(state, STB6100_G, regs[STB6100_G]); | |
422 | if (rc < 0) | |
423 | return rc; | |
424 | ||
425 | /* F we don't write as it is set up in BW set */ | |
426 | ||
427 | /* DLB set DC servo loop BW to 160Hz (LLA 3.8 / 2.1) */ | |
428 | regs[STB6100_DLB] = 0xcc; | |
429 | rc = stb6100_write_reg(state, STB6100_DLB, regs[STB6100_DLB]); | |
430 | if (rc < 0) | |
431 | return rc; | |
432 | ||
c46b6562 MA |
433 | dprintk(verbose, FE_DEBUG, 1, |
434 | "frequency = %u, srate = %u, g = %u, odiv = %u, psd2 = %u, fxtal = %u, osm = %u, fvco = %u, N(I) = %u, N(F) = %u", | |
435 | frequency, srate, (unsigned int)g, (unsigned int)odiv, | |
436 | (unsigned int)psd2, state->reference, | |
437 | ptr->reg, fvco, nint, nfrac); | |
c46b6562 | 438 | |
f14bfe94 MA |
439 | /* Set up the test registers */ |
440 | regs[STB6100_TEST1] = 0x8f; | |
441 | rc = stb6100_write_reg(state, STB6100_TEST1, regs[STB6100_TEST1]); | |
442 | if (rc < 0) | |
443 | return rc; | |
444 | regs[STB6100_TEST3] = 0xde; | |
445 | rc = stb6100_write_reg(state, STB6100_TEST3, regs[STB6100_TEST3]); | |
446 | if (rc < 0) | |
c46b6562 MA |
447 | return rc; |
448 | ||
f14bfe94 MA |
449 | /* Bring up tuner according to LLA 3.7 3.4.1, step 2 */ |
450 | regs[STB6100_LPEN] = 0xfb; /* PLL Loop enabled, bias on, VCO on, synth on */ | |
451 | rc = stb6100_write_reg(state, STB6100_LPEN, regs[STB6100_LPEN]); | |
452 | if (rc < 0) | |
c46b6562 MA |
453 | return rc; |
454 | ||
f14bfe94 MA |
455 | msleep(2); |
456 | ||
457 | /* Bring up tuner according to LLA 3.7 3.4.1, step 3 */ | |
c46b6562 | 458 | regs[STB6100_VCO] &= ~STB6100_VCO_OCK; /* VCO fast search */ |
f14bfe94 MA |
459 | rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO]); |
460 | if (rc < 0) | |
c46b6562 MA |
461 | return rc; |
462 | ||
f14bfe94 MA |
463 | msleep(10); /* This is dangerous as another (related) thread may start */ /* wait for LO to lock */ |
464 | ||
c46b6562 MA |
465 | regs[STB6100_VCO] &= ~STB6100_VCO_OSCH; /* vco search disabled */ |
466 | regs[STB6100_VCO] |= STB6100_VCO_OCK; /* search clock off */ | |
f14bfe94 MA |
467 | rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO]); |
468 | if (rc < 0) | |
c46b6562 MA |
469 | return rc; |
470 | ||
f14bfe94 MA |
471 | rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d); |
472 | if (rc < 0) | |
473 | return rc; /* Stop LPF calibration */ | |
7e4e8c52 | 474 | |
f14bfe94 MA |
475 | msleep(10); /* This is dangerous as another (related) thread may start */ |
476 | /* wait for stabilisation, (should not be necessary) */ | |
c46b6562 MA |
477 | return 0; |
478 | } | |
479 | ||
480 | static int stb6100_sleep(struct dvb_frontend *fe) | |
481 | { | |
482 | /* TODO: power down */ | |
483 | return 0; | |
484 | } | |
485 | ||
486 | static int stb6100_init(struct dvb_frontend *fe) | |
487 | { | |
488 | struct stb6100_state *state = fe->tuner_priv; | |
2184e253 | 489 | int refclk = 27000000; /* Hz */ |
c46b6562 | 490 | |
2184e253 MCC |
491 | /* |
492 | * iqsense = 1 | |
493 | * tunerstep = 125000 | |
494 | */ | |
65f0f686 | 495 | state->bandwidth = 36000000; /* Hz */ |
2184e253 | 496 | state->reference = refclk / 1000; /* kHz */ |
c46b6562 | 497 | |
f14bfe94 MA |
498 | /* Set default bandwidth. Modified, PN 13-May-10 */ |
499 | return 0; | |
c46b6562 MA |
500 | } |
501 | ||
65f0f686 | 502 | static int stb6100_set_params(struct dvb_frontend *fe) |
c46b6562 | 503 | { |
65f0f686 | 504 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
c46b6562 | 505 | |
65f0f686 MCC |
506 | if (c->frequency > 0) |
507 | stb6100_set_frequency(fe, c->frequency); | |
c46b6562 | 508 | |
65f0f686 MCC |
509 | if (c->bandwidth_hz > 0) |
510 | stb6100_set_bandwidth(fe, c->bandwidth_hz); | |
c46b6562 MA |
511 | |
512 | return 0; | |
513 | } | |
514 | ||
14c4bf3c | 515 | static const struct dvb_tuner_ops stb6100_ops = { |
c46b6562 MA |
516 | .info = { |
517 | .name = "STB6100 Silicon Tuner", | |
a3f90c75 MCC |
518 | .frequency_min_hz = 950 * MHz, |
519 | .frequency_max_hz = 2150 * MHz, | |
c46b6562 MA |
520 | }, |
521 | ||
522 | .init = stb6100_init, | |
523 | .sleep = stb6100_sleep, | |
524 | .get_status = stb6100_get_status, | |
65f0f686 MCC |
525 | .set_params = stb6100_set_params, |
526 | .get_frequency = stb6100_get_frequency, | |
527 | .get_bandwidth = stb6100_get_bandwidth, | |
f2709c20 | 528 | .release = stb6100_release |
c46b6562 MA |
529 | }; |
530 | ||
531 | struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe, | |
2e4e98e7 | 532 | const struct stb6100_config *config, |
c46b6562 MA |
533 | struct i2c_adapter *i2c) |
534 | { | |
535 | struct stb6100_state *state = NULL; | |
536 | ||
a18d4315 | 537 | state = kzalloc(sizeof (struct stb6100_state), GFP_KERNEL); |
e4533e65 PST |
538 | if (!state) |
539 | return NULL; | |
c46b6562 MA |
540 | |
541 | state->config = config; | |
542 | state->i2c = i2c; | |
543 | state->frontend = fe; | |
3e3263e6 | 544 | state->reference = config->refclock / 1000; /* kHz */ |
c46b6562 MA |
545 | fe->tuner_priv = state; |
546 | fe->ops.tuner_ops = stb6100_ops; | |
547 | ||
3e3263e6 | 548 | printk("%s: Attaching STB6100 \n", __func__); |
c46b6562 | 549 | return fe; |
c46b6562 MA |
550 | } |
551 | ||
f2709c20 MCC |
552 | static void stb6100_release(struct dvb_frontend *fe) |
553 | { | |
554 | struct stb6100_state *state = fe->tuner_priv; | |
555 | ||
556 | fe->tuner_priv = NULL; | |
557 | kfree(state); | |
558 | } | |
559 | ||
c46b6562 MA |
560 | EXPORT_SYMBOL(stb6100_attach); |
561 | MODULE_PARM_DESC(verbose, "Set Verbosity level"); | |
562 | ||
563 | MODULE_AUTHOR("Manu Abraham"); | |
564 | MODULE_DESCRIPTION("STB6100 Silicon tuner"); | |
565 | MODULE_LICENSE("GPL"); |