blob: 34815b0b97e486964641d0337567bda932d691b8 [file] [log] [blame]
Andrew de Quincey6bca3582006-08-08 09:10:10 -03001 /*
2 Driver for Philips tda8262/tda8263 DVBS Silicon tuners
3
4 (c) 2006 Andrew de Quincey
5
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.
10
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
14
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
23#include <linux/module.h>
24#include <linux/dvb/frontend.h>
25#include <asm/types.h>
26
27#include "tda826x.h"
28
Andrew de Quincey8b9a4662006-08-08 09:10:11 -030029static int debug = 0;
30#define dprintk(args...) \
31 do { \
32 if (debug) printk(KERN_DEBUG "tda826x: " args); \
33 } while (0)
34
Andrew de Quincey6bca3582006-08-08 09:10:10 -030035struct tda826x_priv {
36 /* i2c details */
37 int i2c_address;
38 struct i2c_adapter *i2c;
39 u8 has_loopthrough:1;
40 u32 frequency;
41};
42
43static int tda826x_release(struct dvb_frontend *fe)
44{
45 if (fe->tuner_priv)
46 kfree(fe->tuner_priv);
47 fe->tuner_priv = NULL;
48 return 0;
49}
50
51static int tda826x_sleep(struct dvb_frontend *fe)
52{
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 };
57
Andrew de Quincey8b9a4662006-08-08 09:10:11 -030058 dprintk("%s:\n", __FUNCTION__);
59
Andrew de Quincey6bca3582006-08-08 09:10:10 -030060 if (!priv->has_loopthrough)
61 buf[1] = 0xad;
62
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) {
Andrew de Quincey8b9a4662006-08-08 09:10:11 -030066 dprintk("%s: i2c error\n", __FUNCTION__);
Andrew de Quincey6bca3582006-08-08 09:10:10 -030067 }
68 if (fe->ops.i2c_gate_ctrl)
69 fe->ops.i2c_gate_ctrl(fe, 0);
Andrew de Quincey6bca3582006-08-08 09:10:10 -030070
71 return (ret == 1) ? 0 : ret;
72}
73
74static int tda826x_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
75{
76 struct tda826x_priv *priv = fe->tuner_priv;
77 int ret;
78 u32 div;
79 u8 buf [11];
80 struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 11 };
81
Andrew de Quincey8b9a4662006-08-08 09:10:11 -030082 dprintk("%s:\n", __FUNCTION__);
83
Andrew de Quincey6bca3582006-08-08 09:10:10 -030084 div = (params->frequency + (1000-1)) / 1000;
85
86 buf[0] = 0x00; // subaddress
87 buf[1] = 0x09; // powerdown RSSI + the magic value 1
88 if (!priv->has_loopthrough)
89 buf[1] |= 0x20; // power down loopthrough if not needed
90 buf[2] = (1<<5) | 0x0b; // 1Mhz + 0.45 VCO
91 buf[3] = div >> 7;
92 buf[4] = div << 1;
93 buf[5] = 0xff; // basedband filter to max
94 buf[6] = 0xfe; // gains at max + no RF attenuation
95 buf[7] = 0x83; // charge pumps at high, tests off
96 buf[8] = 0x80; // recommended value 4 for AMPVCO + disable ports.
97 buf[9] = 0x1a; // normal caltime + recommended values for SELTH + SELVTL
98 buf[10] = 0xd4; // recommended value 13 for BBIAS + unknown bit set on
99
100 if (fe->ops.i2c_gate_ctrl)
101 fe->ops.i2c_gate_ctrl(fe, 1);
102 if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
Andrew de Quincey8b9a4662006-08-08 09:10:11 -0300103 dprintk("%s: i2c error\n", __FUNCTION__);
Andrew de Quincey6bca3582006-08-08 09:10:10 -0300104 }
105 if (fe->ops.i2c_gate_ctrl)
106 fe->ops.i2c_gate_ctrl(fe, 0);
107
108 priv->frequency = div * 1000;
Andrew de Quincey6bca3582006-08-08 09:10:10 -0300109
110 return (ret == 1) ? 0 : ret;
111}
112
113static int tda826x_get_frequency(struct dvb_frontend *fe, u32 *frequency)
114{
115 struct tda826x_priv *priv = fe->tuner_priv;
116 *frequency = priv->frequency;
117 return 0;
118}
119
120static struct dvb_tuner_ops tda826x_tuner_ops = {
Trent Piephoef09c072006-08-08 09:10:11 -0300121 .info = {
122 .name = "Philips TDA826X",
123 .frequency_min = 950000,
Alexey Dobriyand027c4d2006-11-03 07:14:32 -0300124 .frequency_max = 2175000
Trent Piephoef09c072006-08-08 09:10:11 -0300125 },
Andrew de Quincey6bca3582006-08-08 09:10:10 -0300126 .release = tda826x_release,
127 .sleep = tda826x_sleep,
128 .set_params = tda826x_set_params,
129 .get_frequency = tda826x_get_frequency,
130};
131
132struct dvb_frontend *tda826x_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c, int has_loopthrough)
133{
134 struct tda826x_priv *priv = NULL;
135 u8 b1 [] = { 0, 0 };
Andrew de Quinceye4a49d72006-08-08 15:48:07 -0300136 struct i2c_msg msg = { .addr = addr, .flags = I2C_M_RD, .buf = b1, .len = 2 };
Andrew de Quincey6bca3582006-08-08 09:10:10 -0300137 int ret;
138
Andrew de Quincey8b9a4662006-08-08 09:10:11 -0300139 dprintk("%s:\n", __FUNCTION__);
140
Andrew de Quincey6bca3582006-08-08 09:10:10 -0300141 if (fe->ops.i2c_gate_ctrl)
142 fe->ops.i2c_gate_ctrl(fe, 1);
Andrew de Quinceye4a49d72006-08-08 15:48:07 -0300143 ret = i2c_transfer (i2c, &msg, 1);
Andrew de Quincey6bca3582006-08-08 09:10:10 -0300144 if (fe->ops.i2c_gate_ctrl)
145 fe->ops.i2c_gate_ctrl(fe, 0);
146
Andrew de Quinceye4a49d72006-08-08 15:48:07 -0300147 if (ret != 1)
Andrew de Quincey6bca3582006-08-08 09:10:10 -0300148 return NULL;
149 if (!(b1[1] & 0x80))
150 return NULL;
151
152 priv = kzalloc(sizeof(struct tda826x_priv), GFP_KERNEL);
153 if (priv == NULL)
154 return NULL;
155
156 priv->i2c_address = addr;
157 priv->i2c = i2c;
158 priv->has_loopthrough = has_loopthrough;
159
160 memcpy(&fe->ops.tuner_ops, &tda826x_tuner_ops, sizeof(struct dvb_tuner_ops));
Andrew de Quincey6bca3582006-08-08 09:10:10 -0300161
162 fe->tuner_priv = priv;
Andrew de Quincey6bca3582006-08-08 09:10:10 -0300163
164 return fe;
165}
166EXPORT_SYMBOL(tda826x_attach);
167
Andrew de Quincey8b9a4662006-08-08 09:10:11 -0300168module_param(debug, int, 0644);
169MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
170
Andrew de Quincey6bca3582006-08-08 09:10:10 -0300171MODULE_DESCRIPTION("DVB TDA826x driver");
172MODULE_AUTHOR("Andrew de Quincey");
173MODULE_LICENSE("GPL");