[ARM] pxa: update defconfig for Verdex Pro
[linux-2.6/verdex.git] / drivers / media / dvb / frontends / tda826x.c
bloba051554b5e2589aeb32060ebb0a41c1c38b65e84
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/module.h>
24 #include <linux/dvb/frontend.h>
25 #include <asm/types.h>
27 #include "tda826x.h"
29 static int debug;
30 #define dprintk(args...) \
31 do { \
32 if (debug) printk(KERN_DEBUG "tda826x: " args); \
33 } while (0)
35 struct tda826x_priv {
36 /* i2c details */
37 int i2c_address;
38 struct i2c_adapter *i2c;
39 u8 has_loopthrough:1;
40 u32 frequency;
43 static int tda826x_release(struct dvb_frontend *fe)
45 kfree(fe->tuner_priv);
46 fe->tuner_priv = NULL;
47 return 0;
50 static int tda826x_sleep(struct dvb_frontend *fe)
52 struct tda826x_priv *priv = fe->tuner_priv;
53 int ret;
54 u8 buf [] = { 0x00, 0x8d };
55 struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 2 };
57 dprintk("%s:\n", __func__);
59 if (!priv->has_loopthrough)
60 buf[1] = 0xad;
62 if (fe->ops.i2c_gate_ctrl)
63 fe->ops.i2c_gate_ctrl(fe, 1);
64 if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
65 dprintk("%s: i2c error\n", __func__);
67 if (fe->ops.i2c_gate_ctrl)
68 fe->ops.i2c_gate_ctrl(fe, 0);
70 return (ret == 1) ? 0 : ret;
73 static int tda826x_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
75 struct tda826x_priv *priv = fe->tuner_priv;
76 int ret;
77 u32 div;
78 u32 ksyms;
79 u32 bandwidth;
80 u8 buf [11];
81 struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 11 };
83 dprintk("%s:\n", __func__);
85 div = (params->frequency + (1000-1)) / 1000;
87 /* BW = ((1 + RO) * SR/2 + 5) * 1.3 [SR in MSPS, BW in MHz] */
88 /* with R0 = 0.35 and some transformations: */
89 ksyms = params->u.qpsk.symbol_rate / 1000;
90 bandwidth = (878 * ksyms + 6500000) / 1000000 + 1;
91 if (bandwidth < 5)
92 bandwidth = 5;
93 else if (bandwidth > 36)
94 bandwidth = 36;
96 buf[0] = 0x00; // subaddress
97 buf[1] = 0x09; // powerdown RSSI + the magic value 1
98 if (!priv->has_loopthrough)
99 buf[1] |= 0x20; // power down loopthrough if not needed
100 buf[2] = (1<<5) | 0x0b; // 1Mhz + 0.45 VCO
101 buf[3] = div >> 7;
102 buf[4] = div << 1;
103 buf[5] = ((bandwidth - 5) << 3) | 7; /* baseband cut-off */
104 buf[6] = 0xfe; // baseband gain 9 db + no RF attenuation
105 buf[7] = 0x83; // charge pumps at high, tests off
106 buf[8] = 0x80; // recommended value 4 for AMPVCO + disable ports.
107 buf[9] = 0x1a; // normal caltime + recommended values for SELTH + SELVTL
108 buf[10] = 0xd4; // recommended value 13 for BBIAS + unknown bit set on
110 if (fe->ops.i2c_gate_ctrl)
111 fe->ops.i2c_gate_ctrl(fe, 1);
112 if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
113 dprintk("%s: i2c error\n", __func__);
115 if (fe->ops.i2c_gate_ctrl)
116 fe->ops.i2c_gate_ctrl(fe, 0);
118 priv->frequency = div * 1000;
120 return (ret == 1) ? 0 : ret;
123 static int tda826x_get_frequency(struct dvb_frontend *fe, u32 *frequency)
125 struct tda826x_priv *priv = fe->tuner_priv;
126 *frequency = priv->frequency;
127 return 0;
130 static struct dvb_tuner_ops tda826x_tuner_ops = {
131 .info = {
132 .name = "Philips TDA826X",
133 .frequency_min = 950000,
134 .frequency_max = 2175000
136 .release = tda826x_release,
137 .sleep = tda826x_sleep,
138 .set_params = tda826x_set_params,
139 .get_frequency = tda826x_get_frequency,
142 struct dvb_frontend *tda826x_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c, int has_loopthrough)
144 struct tda826x_priv *priv = NULL;
145 u8 b1 [] = { 0, 0 };
146 struct i2c_msg msg[2] = {
147 { .addr = addr, .flags = 0, .buf = NULL, .len = 0 },
148 { .addr = addr, .flags = I2C_M_RD, .buf = b1, .len = 2 }
150 int ret;
152 dprintk("%s:\n", __func__);
154 if (fe->ops.i2c_gate_ctrl)
155 fe->ops.i2c_gate_ctrl(fe, 1);
156 ret = i2c_transfer (i2c, msg, 2);
157 if (fe->ops.i2c_gate_ctrl)
158 fe->ops.i2c_gate_ctrl(fe, 0);
160 if (ret != 2)
161 return NULL;
162 if (!(b1[1] & 0x80))
163 return NULL;
165 priv = kzalloc(sizeof(struct tda826x_priv), GFP_KERNEL);
166 if (priv == NULL)
167 return NULL;
169 priv->i2c_address = addr;
170 priv->i2c = i2c;
171 priv->has_loopthrough = has_loopthrough;
173 memcpy(&fe->ops.tuner_ops, &tda826x_tuner_ops, sizeof(struct dvb_tuner_ops));
175 fe->tuner_priv = priv;
177 return fe;
179 EXPORT_SYMBOL(tda826x_attach);
181 module_param(debug, int, 0644);
182 MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
184 MODULE_DESCRIPTION("DVB TDA826x driver");
185 MODULE_AUTHOR("Andrew de Quincey");
186 MODULE_LICENSE("GPL");