]>
Commit | Line | Data |
---|---|---|
c46b6562 MA |
1 | /* |
2 | STB6100 Silicon Tuner | |
3 | Copyright (C) Manu Abraham (abraham.manu@gmail.com) | |
4 | ||
5 | Copyright (C) ST Microelectronics | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | */ | |
21 | ||
22 | #include <linux/init.h> | |
23 | #include <linux/kernel.h> | |
24 | #include <linux/module.h> | |
25 | #include <linux/string.h> | |
26 | ||
27 | #include "dvb_frontend.h" | |
28 | #include "stb6100.h" | |
29 | ||
30 | static unsigned int verbose; | |
31 | module_param(verbose, int, 0644); | |
32 | ||
33 | ||
34 | #define FE_ERROR 0 | |
35 | #define FE_NOTICE 1 | |
36 | #define FE_INFO 2 | |
37 | #define FE_DEBUG 3 | |
38 | ||
39 | #define dprintk(x, y, z, format, arg...) do { \ | |
40 | if (z) { \ | |
41 | if ((x > FE_ERROR) && (x > y)) \ | |
42 | printk(KERN_ERR "%s: " format "\n", __func__ , ##arg); \ | |
43 | else if ((x > FE_NOTICE) && (x > y)) \ | |
44 | printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg); \ | |
45 | else if ((x > FE_INFO) && (x > y)) \ | |
46 | printk(KERN_INFO "%s: " format "\n", __func__ , ##arg); \ | |
47 | else if ((x > FE_DEBUG) && (x > y)) \ | |
48 | printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg); \ | |
49 | } else { \ | |
50 | if (x > y) \ | |
51 | printk(format, ##arg); \ | |
52 | } \ | |
53 | } while(0) | |
54 | ||
55 | struct stb6100_lkup { | |
56 | u32 val_low; | |
57 | u32 val_high; | |
58 | u8 reg; | |
59 | }; | |
60 | ||
61 | static int stb6100_release(struct dvb_frontend *fe); | |
62 | ||
63 | static const struct stb6100_lkup lkup[] = { | |
64 | { 0, 950000, 0x0a }, | |
65 | { 950000, 1000000, 0x0a }, | |
66 | { 1000000, 1075000, 0x0c }, | |
67 | { 1075000, 1200000, 0x00 }, | |
68 | { 1200000, 1300000, 0x01 }, | |
69 | { 1300000, 1370000, 0x02 }, | |
70 | { 1370000, 1470000, 0x04 }, | |
71 | { 1470000, 1530000, 0x05 }, | |
72 | { 1530000, 1650000, 0x06 }, | |
73 | { 1650000, 1800000, 0x08 }, | |
74 | { 1800000, 1950000, 0x0a }, | |
75 | { 1950000, 2150000, 0x0c }, | |
76 | { 2150000, 9999999, 0x0c }, | |
77 | { 0, 0, 0x00 } | |
78 | }; | |
79 | ||
80 | /* Register names for easy debugging. */ | |
81 | static const char *stb6100_regnames[] = { | |
82 | [STB6100_LD] = "LD", | |
83 | [STB6100_VCO] = "VCO", | |
84 | [STB6100_NI] = "NI", | |
85 | [STB6100_NF_LSB] = "NF", | |
86 | [STB6100_K] = "K", | |
87 | [STB6100_G] = "G", | |
88 | [STB6100_F] = "F", | |
89 | [STB6100_DLB] = "DLB", | |
90 | [STB6100_TEST1] = "TEST1", | |
91 | [STB6100_FCCK] = "FCCK", | |
92 | [STB6100_LPEN] = "LPEN", | |
93 | [STB6100_TEST3] = "TEST3", | |
94 | }; | |
95 | ||
96 | /* Template for normalisation, i.e. setting unused or undocumented | |
97 | * bits as required according to the documentation. | |
98 | */ | |
99 | struct stb6100_regmask { | |
100 | u8 mask; | |
101 | u8 set; | |
102 | }; | |
103 | ||
104 | static const struct stb6100_regmask stb6100_template[] = { | |
105 | [STB6100_LD] = { 0xff, 0x00 }, | |
106 | [STB6100_VCO] = { 0xff, 0x00 }, | |
107 | [STB6100_NI] = { 0xff, 0x00 }, | |
108 | [STB6100_NF_LSB] = { 0xff, 0x00 }, | |
109 | [STB6100_K] = { 0xc7, 0x38 }, | |
110 | [STB6100_G] = { 0xef, 0x10 }, | |
111 | [STB6100_F] = { 0x1f, 0xc0 }, | |
112 | [STB6100_DLB] = { 0x38, 0xc4 }, | |
113 | [STB6100_TEST1] = { 0x00, 0x8f }, | |
114 | [STB6100_FCCK] = { 0x40, 0x0d }, | |
115 | [STB6100_LPEN] = { 0xf0, 0x0b }, | |
116 | [STB6100_TEST3] = { 0x00, 0xde }, | |
117 | }; | |
118 | ||
119 | static void stb6100_normalise_regs(u8 regs[]) | |
120 | { | |
121 | int i; | |
122 | ||
123 | for (i = 0; i < STB6100_NUMREGS; i++) | |
124 | regs[i] = (regs[i] & stb6100_template[i].mask) | stb6100_template[i].set; | |
125 | } | |
126 | ||
127 | static int stb6100_read_regs(struct stb6100_state *state, u8 regs[]) | |
128 | { | |
129 | int rc; | |
130 | struct i2c_msg msg = { | |
131 | .addr = state->config->tuner_address, | |
132 | .flags = I2C_M_RD, | |
133 | .buf = regs, | |
134 | .len = STB6100_NUMREGS | |
135 | }; | |
136 | ||
c46b6562 | 137 | rc = i2c_transfer(state->i2c, &msg, 1); |
c46b6562 MA |
138 | if (unlikely(rc != 1)) { |
139 | dprintk(verbose, FE_ERROR, 1, "Read (0x%x) err, rc=[%d]", | |
140 | state->config->tuner_address, rc); | |
141 | ||
142 | return -EREMOTEIO; | |
143 | } | |
144 | if (unlikely(verbose > FE_DEBUG)) { | |
145 | int i; | |
146 | ||
147 | dprintk(verbose, FE_DEBUG, 1, " Read from 0x%02x", state->config->tuner_address); | |
148 | for (i = 0; i < STB6100_NUMREGS; i++) | |
149 | dprintk(verbose, FE_DEBUG, 1, " %s: 0x%02x", stb6100_regnames[i], regs[i]); | |
150 | } | |
151 | return 0; | |
152 | } | |
153 | ||
154 | static int stb6100_read_reg(struct stb6100_state *state, u8 reg) | |
155 | { | |
156 | u8 regs[STB6100_NUMREGS]; | |
157 | int rc; | |
158 | ||
159 | if (unlikely(reg >= STB6100_NUMREGS)) { | |
160 | dprintk(verbose, FE_ERROR, 1, "Invalid register offset 0x%x", reg); | |
161 | return -EINVAL; | |
162 | } | |
163 | if ((rc = stb6100_read_regs(state, regs)) < 0) | |
164 | return rc; | |
165 | return (unsigned int)regs[reg]; | |
166 | } | |
167 | ||
168 | static int stb6100_write_reg_range(struct stb6100_state *state, u8 buf[], int start, int len) | |
169 | { | |
170 | int rc; | |
171 | u8 cmdbuf[len + 1]; | |
172 | struct i2c_msg msg = { | |
173 | .addr = state->config->tuner_address, | |
174 | .flags = 0, | |
175 | .buf = cmdbuf, | |
176 | .len = len + 1 | |
177 | }; | |
178 | ||
179 | if (unlikely(start < 1 || start + len > STB6100_NUMREGS)) { | |
180 | dprintk(verbose, FE_ERROR, 1, "Invalid register range %d:%d", | |
181 | start, len); | |
182 | return -EINVAL; | |
183 | } | |
184 | memcpy(&cmdbuf[1], buf, len); | |
185 | cmdbuf[0] = start; | |
186 | ||
187 | if (unlikely(verbose > FE_DEBUG)) { | |
188 | int i; | |
189 | ||
190 | dprintk(verbose, FE_DEBUG, 1, " Write @ 0x%02x: [%d:%d]", state->config->tuner_address, start, len); | |
191 | for (i = 0; i < len; i++) | |
192 | dprintk(verbose, FE_DEBUG, 1, " %s: 0x%02x", stb6100_regnames[start + i], buf[i]); | |
193 | } | |
c46b6562 | 194 | rc = i2c_transfer(state->i2c, &msg, 1); |
c46b6562 MA |
195 | if (unlikely(rc != 1)) { |
196 | dprintk(verbose, FE_ERROR, 1, "(0x%x) write err [%d:%d], rc=[%d]", | |
197 | (unsigned int)state->config->tuner_address, start, len, rc); | |
198 | return -EREMOTEIO; | |
199 | } | |
200 | return 0; | |
201 | } | |
202 | ||
203 | static int stb6100_write_reg(struct stb6100_state *state, u8 reg, u8 data) | |
204 | { | |
205 | if (unlikely(reg >= STB6100_NUMREGS)) { | |
206 | dprintk(verbose, FE_ERROR, 1, "Invalid register offset 0x%x", reg); | |
207 | return -EREMOTEIO; | |
208 | } | |
209 | data = (data & stb6100_template[reg].mask) | stb6100_template[reg].set; | |
210 | return stb6100_write_reg_range(state, &data, reg, 1); | |
211 | } | |
212 | ||
213 | static int stb6100_write_regs(struct stb6100_state *state, u8 regs[]) | |
214 | { | |
215 | stb6100_normalise_regs(regs); | |
216 | return stb6100_write_reg_range(state, ®s[1], 1, STB6100_NUMREGS - 1); | |
217 | } | |
218 | ||
219 | static int stb6100_get_status(struct dvb_frontend *fe, u32 *status) | |
220 | { | |
221 | int rc; | |
222 | struct stb6100_state *state = fe->tuner_priv; | |
223 | ||
224 | if ((rc = stb6100_read_reg(state, STB6100_LD)) < 0) | |
225 | return rc; | |
226 | ||
227 | return (rc & STB6100_LD_LOCK) ? TUNER_STATUS_LOCKED : 0; | |
228 | } | |
229 | ||
230 | static int stb6100_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth) | |
231 | { | |
232 | int rc; | |
233 | u8 f; | |
234 | struct stb6100_state *state = fe->tuner_priv; | |
235 | ||
236 | if ((rc = stb6100_read_reg(state, STB6100_F)) < 0) | |
237 | return rc; | |
238 | f = rc & STB6100_F_F; | |
239 | ||
240 | state->status.bandwidth = (f + 5) * 2000; /* x2 for ZIF */ | |
241 | ||
242 | *bandwidth = state->bandwidth = state->status.bandwidth * 1000; | |
243 | dprintk(verbose, FE_DEBUG, 1, "bandwidth = %u Hz", state->bandwidth); | |
244 | return 0; | |
245 | } | |
246 | ||
247 | static int stb6100_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth) | |
248 | { | |
249 | u32 tmp; | |
250 | int rc; | |
251 | struct stb6100_state *state = fe->tuner_priv; | |
252 | ||
89693b7d | 253 | dprintk(verbose, FE_DEBUG, 1, "set bandwidth to %u Hz", bandwidth); |
c46b6562 | 254 | |
763fbaf6 | 255 | bandwidth /= 2; /* ZIF */ |
c46b6562 | 256 | |
89693b7d | 257 | if (bandwidth >= 36000000) /* F[4:0] BW/2 max =31+5=36 mhz for F=31 */ |
c46b6562 | 258 | tmp = 31; |
89693b7d | 259 | else if (bandwidth <= 5000000) /* bw/2 min = 5Mhz for F=0 */ |
c46b6562 MA |
260 | tmp = 0; |
261 | else /* if 5 < bw/2 < 36 */ | |
6f6c268b | 262 | tmp = (bandwidth + 500000) / 1000000 - 5; |
c46b6562 MA |
263 | |
264 | /* Turn on LPF bandwidth setting clock control, | |
265 | * set bandwidth, wait 10ms, turn off. | |
266 | */ | |
267 | if ((rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d | STB6100_FCCK_FCCK)) < 0) | |
268 | return rc; | |
269 | if ((rc = stb6100_write_reg(state, STB6100_F, 0xc0 | tmp)) < 0) | |
270 | return rc; | |
271 | msleep(1); | |
272 | if ((rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d)) < 0) | |
273 | return rc; | |
274 | ||
275 | return 0; | |
276 | } | |
277 | ||
278 | static int stb6100_get_frequency(struct dvb_frontend *fe, u32 *frequency) | |
279 | { | |
280 | int rc; | |
281 | u32 nint, nfrac, fvco; | |
282 | int psd2, odiv; | |
283 | struct stb6100_state *state = fe->tuner_priv; | |
284 | u8 regs[STB6100_NUMREGS]; | |
285 | ||
286 | if ((rc = stb6100_read_regs(state, regs)) < 0) | |
287 | return rc; | |
288 | ||
289 | odiv = (regs[STB6100_VCO] & STB6100_VCO_ODIV) >> STB6100_VCO_ODIV_SHIFT; | |
290 | psd2 = (regs[STB6100_K] & STB6100_K_PSD2) >> STB6100_K_PSD2_SHIFT; | |
291 | nint = regs[STB6100_NI]; | |
292 | nfrac = ((regs[STB6100_K] & STB6100_K_NF_MSB) << 8) | regs[STB6100_NF_LSB]; | |
293 | fvco = (nfrac * state->reference >> (9 - psd2)) + (nint * state->reference << psd2); | |
294 | *frequency = state->frequency = fvco >> (odiv + 1); | |
295 | ||
296 | dprintk(verbose, FE_DEBUG, 1, | |
297 | "frequency = %u kHz, odiv = %u, psd2 = %u, fxtal = %u kHz, fvco = %u kHz, N(I) = %u, N(F) = %u", | |
298 | state->frequency, odiv, psd2, state->reference, fvco, nint, nfrac); | |
299 | return 0; | |
300 | } | |
301 | ||
302 | ||
303 | static int stb6100_set_frequency(struct dvb_frontend *fe, u32 frequency) | |
304 | { | |
305 | int rc; | |
306 | const struct stb6100_lkup *ptr; | |
307 | struct stb6100_state *state = fe->tuner_priv; | |
308 | struct dvbfe_params params; | |
309 | ||
310 | u32 srate = 0, fvco, nint, nfrac; | |
311 | u8 regs[STB6100_NUMREGS]; | |
312 | u8 g, psd2, odiv; | |
313 | ||
314 | if ((rc = stb6100_read_regs(state, regs)) < 0) | |
315 | return rc; | |
316 | if (fe->ops.get_params) { | |
317 | dprintk(verbose, FE_DEBUG, 1, "Get Frontend parameters"); | |
318 | fe->ops.get_params(fe, ¶ms); | |
319 | } | |
320 | switch (params.delivery) { | |
321 | case DVBFE_DELSYS_DVBS: | |
322 | srate = params.delsys.dvbs.symbol_rate; | |
323 | dprintk(verbose, FE_DEBUG, 1, "Delivery system = DVB-S, Symbol Rate=[%d]", srate); | |
324 | break; | |
325 | case DVBFE_DELSYS_DSS: | |
326 | dprintk(verbose, FE_DEBUG, 1, "Delivery system = DSS, Symbol Rate=[%d]", srate); | |
327 | srate = params.delsys.dss.symbol_rate; | |
328 | break; | |
329 | case DVBFE_DELSYS_DVBS2: | |
330 | dprintk(verbose, FE_DEBUG, 1, "Delivery system = DVB-S2, Symbol Rate=[%d]", srate); | |
331 | srate = params.delsys.dvbs2.symbol_rate; | |
332 | break; | |
333 | default: | |
334 | dprintk(verbose, FE_NOTICE, 1, "symbol rate unknown!"); | |
335 | srate = 22000000; /* just a typical default value */ | |
ddbee1c6 | 336 | break; |
c46b6562 MA |
337 | } |
338 | ||
339 | /* Baseband gain. */ | |
340 | if (srate >= 15000000) | |
341 | g = 8; | |
342 | else if (state->srate >= 5000000) | |
343 | g = 12; | |
344 | else | |
345 | g = 14; | |
d6812086 | 346 | |
c46b6562 | 347 | regs[STB6100_G] = (regs[STB6100_G] & ~STB6100_G_G) | g; |
d6812086 MA |
348 | regs[STB6100_G] &= ~STB6100_G_GCT; /* mask GCT */ |
349 | regs[STB6100_G] |= (1 << 5); /* 2Vp-p Mode */ | |
c46b6562 MA |
350 | |
351 | /* VCO divide ratio (LO divide ratio, VCO prescaler enable). */ | |
352 | if (frequency <= 1075000) | |
353 | odiv = 1; | |
354 | else | |
355 | odiv = 0; | |
356 | regs[STB6100_VCO] = (regs[STB6100_VCO] & ~STB6100_VCO_ODIV) | (odiv << STB6100_VCO_ODIV_SHIFT); | |
357 | ||
358 | if ((frequency > 1075000) && (frequency <= 1325000)) | |
359 | psd2 = 0; | |
360 | else | |
361 | psd2 = 1; | |
362 | regs[STB6100_K] = (regs[STB6100_K] & ~STB6100_K_PSD2) | (psd2 << STB6100_K_PSD2_SHIFT); | |
363 | ||
364 | /* OSM */ | |
365 | for (ptr = lkup; | |
366 | (ptr->val_high != 0) && !CHKRANGE(frequency, ptr->val_low, ptr->val_high); | |
367 | ptr++); | |
368 | if (ptr->val_high == 0) { | |
369 | printk(KERN_ERR "%s: frequency out of range: %u kHz\n", __func__, frequency); | |
370 | return -EINVAL; | |
371 | } | |
372 | regs[STB6100_VCO] = (regs[STB6100_VCO] & ~STB6100_VCO_OSM) | ptr->reg; | |
373 | ||
374 | /* F(VCO) = F(LO) * (ODIV == 0 ? 2 : 4) */ | |
375 | fvco = frequency << (1 + odiv); | |
376 | /* N(I) = floor(f(VCO) / (f(XTAL) * (PSD2 ? 2 : 1))) */ | |
377 | nint = fvco / (state->reference << psd2); | |
378 | /* N(F) = round(f(VCO) / f(XTAL) * (PSD2 ? 2 : 1) - N(I)) * 2 ^ 9 */ | |
379 | nfrac = (((fvco - (nint * state->reference << psd2)) << (9 - psd2)) + state->reference / 2) / state->reference; | |
380 | dprintk(verbose, FE_DEBUG, 1, | |
381 | "frequency = %u, srate = %u, g = %u, odiv = %u, psd2 = %u, fxtal = %u, osm = %u, fvco = %u, N(I) = %u, N(F) = %u", | |
382 | frequency, srate, (unsigned int)g, (unsigned int)odiv, | |
383 | (unsigned int)psd2, state->reference, | |
384 | ptr->reg, fvco, nint, nfrac); | |
385 | regs[STB6100_NI] = nint; | |
386 | regs[STB6100_NF_LSB] = nfrac; | |
387 | regs[STB6100_K] = (regs[STB6100_K] & ~STB6100_K_NF_MSB) | ((nfrac >> 8) & STB6100_K_NF_MSB); | |
388 | regs[STB6100_VCO] |= STB6100_VCO_OSCH; /* VCO search enabled */ | |
389 | regs[STB6100_VCO] |= STB6100_VCO_OCK; /* VCO search clock off */ | |
390 | regs[STB6100_FCCK] |= STB6100_FCCK_FCCK; /* LPF BW setting clock enabled */ | |
391 | regs[STB6100_LPEN] &= ~STB6100_LPEN_LPEN; /* PLL loop disabled */ | |
392 | /* Power up. */ | |
393 | regs[STB6100_LPEN] |= STB6100_LPEN_SYNP | STB6100_LPEN_OSCP | STB6100_LPEN_BEN; | |
394 | ||
395 | if ((rc = stb6100_write_regs(state, regs)) < 0) | |
396 | return rc; | |
397 | ||
398 | regs[STB6100_LPEN] |= STB6100_LPEN_LPEN; /* PLL loop enabled */ | |
399 | if ((rc = stb6100_write_reg(state, STB6100_LPEN, regs[STB6100_LPEN])) < 0) | |
400 | return rc; | |
401 | ||
402 | regs[STB6100_VCO] &= ~STB6100_VCO_OCK; /* VCO fast search */ | |
403 | if ((rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO])) < 0) | |
404 | return rc; | |
405 | ||
406 | msleep(5); /* wait for LO to lock */ | |
407 | regs[STB6100_VCO] &= ~STB6100_VCO_OSCH; /* vco search disabled */ | |
408 | regs[STB6100_VCO] |= STB6100_VCO_OCK; /* search clock off */ | |
409 | if ((rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO])) < 0) | |
410 | return rc; | |
411 | regs[STB6100_FCCK] &= ~STB6100_FCCK_FCCK; /* LPF BW clock disabled */ | |
412 | if ((rc = stb6100_write_reg(state, STB6100_FCCK, regs[STB6100_FCCK])) < 0) | |
413 | return rc; | |
414 | ||
7e4e8c52 MA |
415 | msleep(30); |
416 | ||
c46b6562 MA |
417 | return 0; |
418 | } | |
419 | ||
420 | static int stb6100_sleep(struct dvb_frontend *fe) | |
421 | { | |
422 | /* TODO: power down */ | |
423 | return 0; | |
424 | } | |
425 | ||
426 | static int stb6100_init(struct dvb_frontend *fe) | |
427 | { | |
428 | struct stb6100_state *state = fe->tuner_priv; | |
429 | struct tuner_state *status = &state->status; | |
430 | ||
431 | status->tunerstep = 125000; | |
432 | status->ifreq = 0; | |
433 | status->refclock = 27000000; /* Hz */ | |
434 | status->iqsense = 1; | |
435 | status->bandwidth = 36000; /* kHz */ | |
436 | state->bandwidth = status->bandwidth * 1000; /* MHz */ | |
437 | state->reference = status->refclock / 1000; /* kHz */ | |
438 | ||
439 | /* Set default bandwidth. */ | |
440 | return stb6100_set_bandwidth(fe, status->bandwidth); | |
441 | } | |
442 | ||
443 | static int stb6100_get_state(struct dvb_frontend *fe, | |
444 | enum tuner_param param, | |
445 | struct tuner_state *state) | |
446 | { | |
447 | switch (param) { | |
448 | case DVBFE_TUNER_FREQUENCY: | |
449 | stb6100_get_frequency(fe, &state->frequency); | |
450 | break; | |
451 | case DVBFE_TUNER_TUNERSTEP: | |
452 | break; | |
453 | case DVBFE_TUNER_IFFREQ: | |
454 | break; | |
455 | case DVBFE_TUNER_BANDWIDTH: | |
456 | stb6100_get_bandwidth(fe, &state->bandwidth); | |
457 | break; | |
458 | case DVBFE_TUNER_REFCLOCK: | |
459 | break; | |
460 | default: | |
461 | break; | |
462 | } | |
463 | ||
464 | return 0; | |
465 | } | |
466 | ||
467 | static int stb6100_set_state(struct dvb_frontend *fe, | |
468 | enum tuner_param param, | |
469 | struct tuner_state *state) | |
470 | { | |
471 | struct stb6100_state *tstate = fe->tuner_priv; | |
472 | ||
473 | switch (param) { | |
474 | case DVBFE_TUNER_FREQUENCY: | |
475 | stb6100_set_frequency(fe, state->frequency); | |
7d8f1e57 | 476 | tstate->frequency = state->frequency; |
c46b6562 MA |
477 | break; |
478 | case DVBFE_TUNER_TUNERSTEP: | |
479 | break; | |
480 | case DVBFE_TUNER_IFFREQ: | |
481 | break; | |
482 | case DVBFE_TUNER_BANDWIDTH: | |
483 | stb6100_set_bandwidth(fe, state->bandwidth); | |
7d8f1e57 | 484 | tstate->bandwidth = state->bandwidth; |
c46b6562 MA |
485 | break; |
486 | case DVBFE_TUNER_REFCLOCK: | |
487 | break; | |
488 | default: | |
489 | break; | |
490 | } | |
491 | ||
492 | return 0; | |
493 | } | |
494 | ||
495 | static struct dvb_tuner_ops stb6100_ops = { | |
496 | .info = { | |
497 | .name = "STB6100 Silicon Tuner", | |
498 | .frequency_min = 950000, | |
499 | .frequency_max = 2150000, | |
500 | .frequency_step = 0, | |
501 | }, | |
502 | ||
503 | .init = stb6100_init, | |
504 | .sleep = stb6100_sleep, | |
505 | .get_status = stb6100_get_status, | |
506 | .get_state = stb6100_get_state, | |
507 | .set_state = stb6100_set_state, | |
c46b6562 MA |
508 | .release = stb6100_release |
509 | }; | |
510 | ||
511 | struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe, | |
512 | struct stb6100_config *config, | |
513 | struct i2c_adapter *i2c) | |
514 | { | |
515 | struct stb6100_state *state = NULL; | |
516 | ||
a18d4315 | 517 | state = kzalloc(sizeof (struct stb6100_state), GFP_KERNEL); |
c46b6562 MA |
518 | if (state == NULL) |
519 | goto error; | |
520 | ||
521 | state->config = config; | |
522 | state->i2c = i2c; | |
523 | state->frontend = fe; | |
3e3263e6 | 524 | state->reference = config->refclock / 1000; /* kHz */ |
c46b6562 MA |
525 | fe->tuner_priv = state; |
526 | fe->ops.tuner_ops = stb6100_ops; | |
527 | ||
3e3263e6 | 528 | printk("%s: Attaching STB6100 \n", __func__); |
c46b6562 MA |
529 | return fe; |
530 | ||
531 | error: | |
532 | kfree(state); | |
c46b6562 MA |
533 | return NULL; |
534 | } | |
535 | ||
536 | static int stb6100_release(struct dvb_frontend *fe) | |
537 | { | |
538 | struct stb6100_state *state = fe->tuner_priv; | |
539 | ||
540 | fe->tuner_priv = NULL; | |
c46b6562 MA |
541 | kfree(state); |
542 | ||
543 | return 0; | |
544 | } | |
545 | ||
546 | EXPORT_SYMBOL(stb6100_attach); | |
547 | MODULE_PARM_DESC(verbose, "Set Verbosity level"); | |
548 | ||
549 | MODULE_AUTHOR("Manu Abraham"); | |
550 | MODULE_DESCRIPTION("STB6100 Silicon tuner"); | |
551 | MODULE_LICENSE("GPL"); |