blob: d8950028d0211b94b47958657e96d3a7959fd531 [file] [log] [blame]
Manu Abrahame415c682009-04-06 15:45:20 -03001/*
2 STV6110(A) Silicon tuner driver
3
4 Copyright (C) Manu Abraham <abraham.manu@gmail.com>
5
6 Copyright (C) ST Microelectronics
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22
23#include <linux/init.h>
24#include <linux/kernel.h>
25#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Manu Abrahame415c682009-04-06 15:45:20 -030027#include <linux/string.h>
28
Mauro Carvalho Chehabfada1932017-12-28 13:03:51 -050029#include <media/dvb_frontend.h>
Manu Abrahame415c682009-04-06 15:45:20 -030030
31#include "stv6110x_reg.h"
32#include "stv6110x.h"
33#include "stv6110x_priv.h"
34
Mauro Carvalho Chehab83937962013-11-02 05:05:18 -030035/* Max transfer size done by I2C transfer functions */
36#define MAX_XFER_SIZE 64
37
Manu Abrahame415c682009-04-06 15:45:20 -030038static unsigned int verbose;
39module_param(verbose, int, 0644);
40MODULE_PARM_DESC(verbose, "Set Verbosity level");
41
Manu Abrahame415c682009-04-06 15:45:20 -030042static int stv6110x_read_reg(struct stv6110x_state *stv6110x, u8 reg, u8 *data)
43{
44 int ret;
45 const struct stv6110x_config *config = stv6110x->config;
46 u8 b0[] = { reg };
47 u8 b1[] = { 0 };
48 struct i2c_msg msg[] = {
Mauro Carvalho Chehab6e6a8b52018-01-04 13:08:56 -050049 { .addr = config->addr, .flags = 0, .buf = b0, .len = 1 },
Manu Abrahame415c682009-04-06 15:45:20 -030050 { .addr = config->addr, .flags = I2C_M_RD, .buf = b1, .len = 1 }
51 };
52
53 ret = i2c_transfer(stv6110x->i2c, msg, 2);
54 if (ret != 2) {
55 dprintk(FE_ERROR, 1, "I/O Error");
56 return -EREMOTEIO;
57 }
Andreas Regelf2b2fd42009-04-16 08:38:46 -030058 *data = b1[0];
Manu Abrahame415c682009-04-06 15:45:20 -030059
60 return 0;
61}
62
Andreas Regel0c3f9fd2010-01-05 19:22:45 -030063static int stv6110x_write_regs(struct stv6110x_state *stv6110x, int start, u8 data[], int len)
Manu Abrahame415c682009-04-06 15:45:20 -030064{
65 int ret;
66 const struct stv6110x_config *config = stv6110x->config;
Mauro Carvalho Chehab83937962013-11-02 05:05:18 -030067 u8 buf[MAX_XFER_SIZE];
68
Andreas Regel0c3f9fd2010-01-05 19:22:45 -030069 struct i2c_msg msg = {
70 .addr = config->addr,
71 .flags = 0,
72 .buf = buf,
73 .len = len + 1
74 };
75
Mauro Carvalho Chehab83937962013-11-02 05:05:18 -030076 if (1 + len > sizeof(buf)) {
77 printk(KERN_WARNING
78 "%s: i2c wr: len=%d is too big!\n",
79 KBUILD_MODNAME, len);
80 return -EINVAL;
81 }
82
Andreas Regel0c3f9fd2010-01-05 19:22:45 -030083 if (start + len > 8)
84 return -EINVAL;
85
86 buf[0] = start;
87 memcpy(&buf[1], data, len);
Manu Abrahame415c682009-04-06 15:45:20 -030088
89 ret = i2c_transfer(stv6110x->i2c, &msg, 1);
90 if (ret != 1) {
91 dprintk(FE_ERROR, 1, "I/O Error");
92 return -EREMOTEIO;
93 }
94
95 return 0;
96}
97
Andreas Regel0c3f9fd2010-01-05 19:22:45 -030098static int stv6110x_write_reg(struct stv6110x_state *stv6110x, u8 reg, u8 data)
99{
Arnd Bergmann3cd890d2017-11-30 11:55:46 -0500100 u8 tmp = data; /* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */
101
102 return stv6110x_write_regs(stv6110x, reg, &tmp, 1);
Andreas Regel0c3f9fd2010-01-05 19:22:45 -0300103}
104
Manu Abrahame415c682009-04-06 15:45:20 -0300105static int stv6110x_init(struct dvb_frontend *fe)
106{
107 struct stv6110x_state *stv6110x = fe->tuner_priv;
108 int ret;
Manu Abrahame415c682009-04-06 15:45:20 -0300109
Andreas Regelec2d3a62010-01-05 19:23:13 -0300110 ret = stv6110x_write_regs(stv6110x, 0, stv6110x->regs,
111 ARRAY_SIZE(stv6110x->regs));
Andreas Regel0c3f9fd2010-01-05 19:22:45 -0300112 if (ret < 0) {
113 dprintk(FE_ERROR, 1, "Initialization failed");
114 return -1;
Manu Abrahame415c682009-04-06 15:45:20 -0300115 }
116
117 return 0;
118}
119
120static int stv6110x_set_frequency(struct dvb_frontend *fe, u32 frequency)
121{
122 struct stv6110x_state *stv6110x = fe->tuner_priv;
123 u32 rDiv, divider;
Andreas Regel7c236e32009-11-13 18:22:02 -0300124 s32 pVal, pCalc, rDivOpt = 0, pCalcOpt = 1000;
Manu Abrahame415c682009-04-06 15:45:20 -0300125 u8 i;
126
Andreas Regelec2d3a62010-01-05 19:23:13 -0300127 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_K, (REFCLOCK_MHz - 16));
Manu Abrahame415c682009-04-06 15:45:20 -0300128
129 if (frequency <= 1023000) {
Andreas Regelec2d3a62010-01-05 19:23:13 -0300130 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 1);
131 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 0);
Manu Abrahame415c682009-04-06 15:45:20 -0300132 pVal = 40;
133 } else if (frequency <= 1300000) {
Andreas Regelec2d3a62010-01-05 19:23:13 -0300134 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 1);
135 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 1);
Manu Abrahame415c682009-04-06 15:45:20 -0300136 pVal = 40;
137 } else if (frequency <= 2046000) {
Andreas Regelec2d3a62010-01-05 19:23:13 -0300138 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 0);
139 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 0);
Manu Abrahame415c682009-04-06 15:45:20 -0300140 pVal = 20;
141 } else {
Andreas Regelec2d3a62010-01-05 19:23:13 -0300142 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 0);
143 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 1);
Manu Abrahame415c682009-04-06 15:45:20 -0300144 pVal = 20;
145 }
146
147 for (rDiv = 0; rDiv <= 3; rDiv++) {
148 pCalc = (REFCLOCK_kHz / 100) / R_DIV(rDiv);
149
Andreas Regel7c236e32009-11-13 18:22:02 -0300150 if ((abs((s32)(pCalc - pVal))) < (abs((s32)(pCalcOpt - pVal))))
Manu Abrahame415c682009-04-06 15:45:20 -0300151 rDivOpt = rDiv;
Andreas Regel7c236e32009-11-13 18:22:02 -0300152
153 pCalcOpt = (REFCLOCK_kHz / 100) / R_DIV(rDivOpt);
Manu Abrahame415c682009-04-06 15:45:20 -0300154 }
155
156 divider = (frequency * R_DIV(rDivOpt) * pVal) / REFCLOCK_kHz;
157 divider = (divider + 5) / 10;
158
Andreas Regelec2d3a62010-01-05 19:23:13 -0300159 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_R_DIV, rDivOpt);
160 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_N_DIV_11_8, MSB(divider));
161 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG0], TNG0_N_DIV_7_0, LSB(divider));
Manu Abrahame415c682009-04-06 15:45:20 -0300162
163 /* VCO Auto calibration */
Andreas Regelec2d3a62010-01-05 19:23:13 -0300164 STV6110x_SETFIELD(stv6110x->regs[STV6110x_STAT1], STAT1_CALVCO_STRT, 1);
Manu Abrahame415c682009-04-06 15:45:20 -0300165
Andreas Regelec2d3a62010-01-05 19:23:13 -0300166 stv6110x_write_reg(stv6110x, STV6110x_CTRL1, stv6110x->regs[STV6110x_CTRL1]);
167 stv6110x_write_reg(stv6110x, STV6110x_TNG1, stv6110x->regs[STV6110x_TNG1]);
168 stv6110x_write_reg(stv6110x, STV6110x_TNG0, stv6110x->regs[STV6110x_TNG0]);
169 stv6110x_write_reg(stv6110x, STV6110x_STAT1, stv6110x->regs[STV6110x_STAT1]);
Manu Abrahame415c682009-04-06 15:45:20 -0300170
171 for (i = 0; i < TRIALS; i++) {
Andreas Regelec2d3a62010-01-05 19:23:13 -0300172 stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x->regs[STV6110x_STAT1]);
173 if (!STV6110x_GETFIELD(STAT1_CALVCO_STRT, stv6110x->regs[STV6110x_STAT1]))
Manu Abrahame415c682009-04-06 15:45:20 -0300174 break;
175 msleep(1);
176 }
177
178 return 0;
179}
180
181static int stv6110x_get_frequency(struct dvb_frontend *fe, u32 *frequency)
182{
183 struct stv6110x_state *stv6110x = fe->tuner_priv;
184
Andreas Regelec2d3a62010-01-05 19:23:13 -0300185 stv6110x_read_reg(stv6110x, STV6110x_TNG1, &stv6110x->regs[STV6110x_TNG1]);
186 stv6110x_read_reg(stv6110x, STV6110x_TNG0, &stv6110x->regs[STV6110x_TNG0]);
Manu Abrahame415c682009-04-06 15:45:20 -0300187
Andreas Regelec2d3a62010-01-05 19:23:13 -0300188 *frequency = (MAKEWORD16(STV6110x_GETFIELD(TNG1_N_DIV_11_8, stv6110x->regs[STV6110x_TNG1]),
189 STV6110x_GETFIELD(TNG0_N_DIV_7_0, stv6110x->regs[STV6110x_TNG0]))) * REFCLOCK_kHz;
Manu Abrahame415c682009-04-06 15:45:20 -0300190
Andreas Regelec2d3a62010-01-05 19:23:13 -0300191 *frequency /= (1 << (STV6110x_GETFIELD(TNG1_R_DIV, stv6110x->regs[STV6110x_TNG1]) +
192 STV6110x_GETFIELD(TNG1_DIV4SEL, stv6110x->regs[STV6110x_TNG1])));
Manu Abrahame415c682009-04-06 15:45:20 -0300193
194 *frequency >>= 2;
195
196 return 0;
197}
198
199static int stv6110x_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth)
200{
201 struct stv6110x_state *stv6110x = fe->tuner_priv;
202 u32 halfbw;
203 u8 i;
204
205 halfbw = bandwidth >> 1;
206
207 if (halfbw > 36000000)
Andreas Regelec2d3a62010-01-05 19:23:13 -0300208 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_CF, 31); /* LPF */
Manu Abrahame415c682009-04-06 15:45:20 -0300209 else if (halfbw < 5000000)
Andreas Regelec2d3a62010-01-05 19:23:13 -0300210 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_CF, 0); /* LPF */
Manu Abrahame415c682009-04-06 15:45:20 -0300211 else
Andreas Regelec2d3a62010-01-05 19:23:13 -0300212 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_CF, ((halfbw / 1000000) - 5)); /* LPF */
Manu Abrahame415c682009-04-06 15:45:20 -0300213
214
Andreas Regelec2d3a62010-01-05 19:23:13 -0300215 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_RCCLK_OFF, 0x0); /* cal. clk activated */
216 STV6110x_SETFIELD(stv6110x->regs[STV6110x_STAT1], STAT1_CALRC_STRT, 0x1); /* LPF auto cal */
Manu Abrahame415c682009-04-06 15:45:20 -0300217
Andreas Regelec2d3a62010-01-05 19:23:13 -0300218 stv6110x_write_reg(stv6110x, STV6110x_CTRL3, stv6110x->regs[STV6110x_CTRL3]);
219 stv6110x_write_reg(stv6110x, STV6110x_STAT1, stv6110x->regs[STV6110x_STAT1]);
Manu Abrahame415c682009-04-06 15:45:20 -0300220
221 for (i = 0; i < TRIALS; i++) {
Andreas Regelec2d3a62010-01-05 19:23:13 -0300222 stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x->regs[STV6110x_STAT1]);
223 if (!STV6110x_GETFIELD(STAT1_CALRC_STRT, stv6110x->regs[STV6110x_STAT1]))
Manu Abrahame415c682009-04-06 15:45:20 -0300224 break;
225 msleep(1);
226 }
Andreas Regelec2d3a62010-01-05 19:23:13 -0300227 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_RCCLK_OFF, 0x1); /* cal. done */
228 stv6110x_write_reg(stv6110x, STV6110x_CTRL3, stv6110x->regs[STV6110x_CTRL3]);
Manu Abrahame415c682009-04-06 15:45:20 -0300229
230 return 0;
231}
232
233static int stv6110x_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
234{
235 struct stv6110x_state *stv6110x = fe->tuner_priv;
236
Andreas Regelec2d3a62010-01-05 19:23:13 -0300237 stv6110x_read_reg(stv6110x, STV6110x_CTRL3, &stv6110x->regs[STV6110x_CTRL3]);
238 *bandwidth = (STV6110x_GETFIELD(CTRL3_CF, stv6110x->regs[STV6110x_CTRL3]) + 5) * 2000000;
Manu Abrahame415c682009-04-06 15:45:20 -0300239
240 return 0;
241}
242
243static int stv6110x_set_refclock(struct dvb_frontend *fe, u32 refclock)
244{
245 struct stv6110x_state *stv6110x = fe->tuner_priv;
246
247 /* setup divider */
248 switch (refclock) {
249 default:
250 case 1:
Andreas Regelec2d3a62010-01-05 19:23:13 -0300251 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 0);
Manu Abrahame415c682009-04-06 15:45:20 -0300252 break;
253 case 2:
Andreas Regelec2d3a62010-01-05 19:23:13 -0300254 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 1);
Manu Abrahame415c682009-04-06 15:45:20 -0300255 break;
256 case 4:
Andreas Regelec2d3a62010-01-05 19:23:13 -0300257 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 2);
Manu Abrahame415c682009-04-06 15:45:20 -0300258 break;
259 case 8:
260 case 0:
Andreas Regelec2d3a62010-01-05 19:23:13 -0300261 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 3);
Manu Abrahame415c682009-04-06 15:45:20 -0300262 break;
263 }
Andreas Regelec2d3a62010-01-05 19:23:13 -0300264 stv6110x_write_reg(stv6110x, STV6110x_CTRL2, stv6110x->regs[STV6110x_CTRL2]);
Manu Abrahame415c682009-04-06 15:45:20 -0300265
266 return 0;
267}
268
269static int stv6110x_get_bbgain(struct dvb_frontend *fe, u32 *gain)
270{
271 struct stv6110x_state *stv6110x = fe->tuner_priv;
272
Andreas Regelec2d3a62010-01-05 19:23:13 -0300273 stv6110x_read_reg(stv6110x, STV6110x_CTRL2, &stv6110x->regs[STV6110x_CTRL2]);
274 *gain = 2 * STV6110x_GETFIELD(CTRL2_BBGAIN, stv6110x->regs[STV6110x_CTRL2]);
Manu Abrahame415c682009-04-06 15:45:20 -0300275
276 return 0;
277}
278
279static int stv6110x_set_bbgain(struct dvb_frontend *fe, u32 gain)
280{
281 struct stv6110x_state *stv6110x = fe->tuner_priv;
282
Andreas Regelec2d3a62010-01-05 19:23:13 -0300283 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_BBGAIN, gain / 2);
284 stv6110x_write_reg(stv6110x, STV6110x_CTRL2, stv6110x->regs[STV6110x_CTRL2]);
Manu Abrahame415c682009-04-06 15:45:20 -0300285
286 return 0;
287}
288
289static int stv6110x_set_mode(struct dvb_frontend *fe, enum tuner_mode mode)
290{
291 struct stv6110x_state *stv6110x = fe->tuner_priv;
292 int ret;
293
294 switch (mode) {
295 case TUNER_SLEEP:
Andreas Regelec2d3a62010-01-05 19:23:13 -0300296 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_SYN, 0);
297 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_RX, 0);
298 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_LPT, 0);
Manu Abrahame415c682009-04-06 15:45:20 -0300299 break;
300
301 case TUNER_WAKE:
Andreas Regelec2d3a62010-01-05 19:23:13 -0300302 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_SYN, 1);
303 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_RX, 1);
304 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_LPT, 1);
Manu Abrahame415c682009-04-06 15:45:20 -0300305 break;
306 }
307
Andreas Regelec2d3a62010-01-05 19:23:13 -0300308 ret = stv6110x_write_reg(stv6110x, STV6110x_CTRL1, stv6110x->regs[STV6110x_CTRL1]);
Manu Abrahame415c682009-04-06 15:45:20 -0300309 if (ret < 0) {
310 dprintk(FE_ERROR, 1, "I/O Error");
311 return -EIO;
312 }
313
314 return 0;
315}
316
317static int stv6110x_sleep(struct dvb_frontend *fe)
318{
Guy Martine65f8c42010-05-07 04:34:40 -0300319 if (fe->tuner_priv)
320 return stv6110x_set_mode(fe, TUNER_SLEEP);
321
322 return 0;
Manu Abrahame415c682009-04-06 15:45:20 -0300323}
324
325static int stv6110x_get_status(struct dvb_frontend *fe, u32 *status)
326{
327 struct stv6110x_state *stv6110x = fe->tuner_priv;
328
Andreas Regelec2d3a62010-01-05 19:23:13 -0300329 stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x->regs[STV6110x_STAT1]);
Manu Abrahame415c682009-04-06 15:45:20 -0300330
Andreas Regelec2d3a62010-01-05 19:23:13 -0300331 if (STV6110x_GETFIELD(STAT1_LOCK, stv6110x->regs[STV6110x_STAT1]))
Manu Abrahame415c682009-04-06 15:45:20 -0300332 *status = TUNER_PHASELOCKED;
333 else
334 *status = 0;
335
336 return 0;
337}
338
339
Mauro Carvalho Chehabf2709c22016-11-18 20:30:51 -0200340static void stv6110x_release(struct dvb_frontend *fe)
341{
342 struct stv6110x_state *stv6110x = fe->tuner_priv;
343
344 fe->tuner_priv = NULL;
345 kfree(stv6110x);
346}
347
Julia Lawall14c4bf32016-09-11 11:44:12 -0300348static const struct dvb_tuner_ops stv6110x_ops = {
Manu Abrahame415c682009-04-06 15:45:20 -0300349 .info = {
350 .name = "STV6110(A) Silicon Tuner",
351 .frequency_min = 950000,
352 .frequency_max = 2150000,
353 .frequency_step = 0,
354 },
Mauro Carvalho Chehabf2709c22016-11-18 20:30:51 -0200355 .release = stv6110x_release
Manu Abrahame415c682009-04-06 15:45:20 -0300356};
357
Julia Lawall242c5032015-12-06 13:34:26 -0200358static const struct stv6110x_devctl stv6110x_ctl = {
Manu Abrahame415c682009-04-06 15:45:20 -0300359 .tuner_init = stv6110x_init,
Manu Abrahamc5b74b02010-01-23 05:49:08 -0300360 .tuner_sleep = stv6110x_sleep,
Manu Abrahame415c682009-04-06 15:45:20 -0300361 .tuner_set_mode = stv6110x_set_mode,
362 .tuner_set_frequency = stv6110x_set_frequency,
363 .tuner_get_frequency = stv6110x_get_frequency,
364 .tuner_set_bandwidth = stv6110x_set_bandwidth,
365 .tuner_get_bandwidth = stv6110x_get_bandwidth,
366 .tuner_set_bbgain = stv6110x_set_bbgain,
367 .tuner_get_bbgain = stv6110x_get_bbgain,
368 .tuner_set_refclk = stv6110x_set_refclock,
369 .tuner_get_status = stv6110x_get_status,
370};
371
Julia Lawall242c5032015-12-06 13:34:26 -0200372const struct stv6110x_devctl *stv6110x_attach(struct dvb_frontend *fe,
Manu Abrahame415c682009-04-06 15:45:20 -0300373 const struct stv6110x_config *config,
374 struct i2c_adapter *i2c)
375{
376 struct stv6110x_state *stv6110x;
Andreas Regelec2d3a62010-01-05 19:23:13 -0300377 u8 default_regs[] = {0x07, 0x11, 0xdc, 0x85, 0x17, 0x01, 0xe6, 0x1e};
Manu Abrahame415c682009-04-06 15:45:20 -0300378
379 stv6110x = kzalloc(sizeof (struct stv6110x_state), GFP_KERNEL);
Dan Carpenter83b66012010-05-05 02:58:18 -0300380 if (!stv6110x)
381 return NULL;
Manu Abrahame415c682009-04-06 15:45:20 -0300382
383 stv6110x->i2c = i2c;
384 stv6110x->config = config;
385 stv6110x->devctl = &stv6110x_ctl;
Andreas Regelec2d3a62010-01-05 19:23:13 -0300386 memcpy(stv6110x->regs, default_regs, 8);
Manu Abrahame415c682009-04-06 15:45:20 -0300387
Andreas Regelca108b32010-01-05 19:24:10 -0300388 /* setup divider */
389 switch (stv6110x->config->clk_div) {
390 default:
391 case 1:
392 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 0);
393 break;
394 case 2:
395 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 1);
396 break;
397 case 4:
398 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 2);
399 break;
400 case 8:
401 case 0:
402 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 3);
403 break;
404 }
405
Manu Abrahame415c682009-04-06 15:45:20 -0300406 fe->tuner_priv = stv6110x;
407 fe->ops.tuner_ops = stv6110x_ops;
408
Dan Carpenter83b66012010-05-05 02:58:18 -0300409 printk(KERN_INFO "%s: Attaching STV6110x\n", __func__);
Manu Abrahame415c682009-04-06 15:45:20 -0300410 return stv6110x->devctl;
Manu Abrahame415c682009-04-06 15:45:20 -0300411}
412EXPORT_SYMBOL(stv6110x_attach);
413
414MODULE_AUTHOR("Manu Abraham");
415MODULE_DESCRIPTION("STV6110x Silicon tuner");
416MODULE_LICENSE("GPL");