Staging: strip: delete the driver
[linux/fpc-iii.git] / drivers / media / dvb / frontends / tda826x.c
blob06c94800b9402955ccbf799f8ee66e93c2a4f956
1 /*
2 Driver for Philips tda8262/tda8263 DVBS Silicon tuners
4 (c) 2006 Andrew de Quincey
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
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.
23 #include <linux/slab.h>
24 #include <linux/module.h>
25 #include <linux/dvb/frontend.h>
26 #include <asm/types.h>
28 #include "tda826x.h"
30 static int debug;
31 #define dprintk(args...) \
32 do { \
33 if (debug) printk(KERN_DEBUG "tda826x: " args); \
34 } while (0)
36 struct tda826x_priv {
37 /* i2c details */
38 int i2c_address;
39 struct i2c_adapter *i2c;
40 u8 has_loopthrough:1;
41 u32 frequency;
44 static int tda826x_release(struct dvb_frontend *fe)
46 kfree(fe->tuner_priv);
47 fe->tuner_priv = NULL;
48 return 0;
51 static int tda826x_sleep(struct dvb_frontend *fe)
53 struct tda826x_priv *priv = fe->tuner_priv;
54 int ret;
55 u8 buf [] = { 0x00, 0x8d };
56 struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 2 };
58 dprintk("%s:\n", __func__);
60 if (!priv->has_loopthrough)
61 buf[1] = 0xad;
63 if (fe->ops.i2c_gate_ctrl)
64 fe->ops.i2c_gate_ctrl(fe, 1);
65 if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
66 dprintk("%s: i2c error\n", __func__);
68 if (fe->ops.i2c_gate_ctrl)
69 fe->ops.i2c_gate_ctrl(fe, 0);
71 return (ret == 1) ? 0 : ret;
74 static int tda826x_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
76 struct tda826x_priv *priv = fe->tuner_priv;
77 int ret;
78 u32 div;
79 u32 ksyms;
80 u32 bandwidth;
81 u8 buf [11];
82 struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 11 };
84 dprintk("%s:\n", __func__);
86 div = (params->frequency + (1000-1)) / 1000;
88 /* BW = ((1 + RO) * SR/2 + 5) * 1.3 [SR in MSPS, BW in MHz] */
89 /* with R0 = 0.35 and some transformations: */
90 ksyms = params->u.qpsk.symbol_rate / 1000;
91 bandwidth = (878 * ksyms + 6500000) / 1000000 + 1;
92 if (bandwidth < 5)
93 bandwidth = 5;
94 else if (bandwidth > 36)
95 bandwidth = 36;
97 buf[0] = 0x00; // subaddress
98 buf[1] = 0x09; // powerdown RSSI + the magic value 1
99 if (!priv->has_loopthrough)
100 buf[1] |= 0x20; // power down loopthrough if not needed
101 buf[2] = (1<<5) | 0x0b; // 1Mhz + 0.45 VCO
102 buf[3] = div >> 7;
103 buf[4] = div << 1;
104 buf[5] = ((bandwidth - 5) << 3) | 7; /* baseband cut-off */
105 buf[6] = 0xfe; // baseband gain 9 db + no RF attenuation
106 buf[7] = 0x83; // charge pumps at high, tests off
107 buf[8] = 0x80; // recommended value 4 for AMPVCO + disable ports.
108 buf[9] = 0x1a; // normal caltime + recommended values for SELTH + SELVTL
109 buf[10] = 0xd4; // recommended value 13 for BBIAS + unknown bit set on
111 if (fe->ops.i2c_gate_ctrl)
112 fe->ops.i2c_gate_ctrl(fe, 1);
113 if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
114 dprintk("%s: i2c error\n", __func__);
116 if (fe->ops.i2c_gate_ctrl)
117 fe->ops.i2c_gate_ctrl(fe, 0);
119 priv->frequency = div * 1000;
121 return (ret == 1) ? 0 : ret;
124 static int tda826x_get_frequency(struct dvb_frontend *fe, u32 *frequency)
126 struct tda826x_priv *priv = fe->tuner_priv;
127 *frequency = priv->frequency;
128 return 0;
131 static struct dvb_tuner_ops tda826x_tuner_ops = {
132 .info = {
133 .name = "Philips TDA826X",
134 .frequency_min = 950000,
135 .frequency_max = 2175000
137 .release = tda826x_release,
138 .sleep = tda826x_sleep,
139 .set_params = tda826x_set_params,
140 .get_frequency = tda826x_get_frequency,
143 struct dvb_frontend *tda826x_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c, int has_loopthrough)
145 struct tda826x_priv *priv = NULL;
146 u8 b1 [] = { 0, 0 };
147 struct i2c_msg msg[2] = {
148 { .addr = addr, .flags = 0, .buf = NULL, .len = 0 },
149 { .addr = addr, .flags = I2C_M_RD, .buf = b1, .len = 2 }
151 int ret;
153 dprintk("%s:\n", __func__);
155 if (fe->ops.i2c_gate_ctrl)
156 fe->ops.i2c_gate_ctrl(fe, 1);
157 ret = i2c_transfer (i2c, msg, 2);
158 if (fe->ops.i2c_gate_ctrl)
159 fe->ops.i2c_gate_ctrl(fe, 0);
161 if (ret != 2)
162 return NULL;
163 if (!(b1[1] & 0x80))
164 return NULL;
166 priv = kzalloc(sizeof(struct tda826x_priv), GFP_KERNEL);
167 if (priv == NULL)
168 return NULL;
170 priv->i2c_address = addr;
171 priv->i2c = i2c;
172 priv->has_loopthrough = has_loopthrough;
174 memcpy(&fe->ops.tuner_ops, &tda826x_tuner_ops, sizeof(struct dvb_tuner_ops));
176 fe->tuner_priv = priv;
178 return fe;
180 EXPORT_SYMBOL(tda826x_attach);
182 module_param(debug, int, 0644);
183 MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
185 MODULE_DESCRIPTION("DVB TDA826x driver");
186 MODULE_AUTHOR("Andrew de Quincey");
187 MODULE_LICENSE("GPL");