2 * Infineon TUA 9001 silicon tuner driver
4 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "tua9001_priv.h"
25 static int tua9001_wr_reg(struct tua9001_priv
*priv
, u8 reg
, u16 val
)
28 u8 buf
[3] = { reg
, (val
>> 8) & 0xff, (val
>> 0) & 0xff };
29 struct i2c_msg msg
[1] = {
31 .addr
= priv
->cfg
->i2c_addr
,
38 ret
= i2c_transfer(priv
->i2c
, msg
, 1);
42 dev_warn(&priv
->i2c
->dev
, "%s: i2c wr failed=%d reg=%02x\n",
43 KBUILD_MODNAME
, ret
, reg
);
50 static int tua9001_release(struct dvb_frontend
*fe
)
52 struct tua9001_priv
*priv
= fe
->tuner_priv
;
55 dev_dbg(&priv
->i2c
->dev
, "%s:\n", __func__
);
58 ret
= fe
->callback(priv
->i2c
, DVB_FRONTEND_COMPONENT_TUNER
,
61 kfree(fe
->tuner_priv
);
62 fe
->tuner_priv
= NULL
;
67 static int tua9001_init(struct dvb_frontend
*fe
)
69 struct tua9001_priv
*priv
= fe
->tuner_priv
;
72 struct reg_val data
[] = {
90 dev_dbg(&priv
->i2c
->dev
, "%s:\n", __func__
);
93 ret
= fe
->callback(priv
->i2c
, DVB_FRONTEND_COMPONENT_TUNER
,
94 TUA9001_CMD_RESETN
, 0);
99 if (fe
->ops
.i2c_gate_ctrl
)
100 fe
->ops
.i2c_gate_ctrl(fe
, 1); /* open i2c-gate */
102 for (i
= 0; i
< ARRAY_SIZE(data
); i
++) {
103 ret
= tua9001_wr_reg(priv
, data
[i
].reg
, data
[i
].val
);
105 goto err_i2c_gate_ctrl
;
109 if (fe
->ops
.i2c_gate_ctrl
)
110 fe
->ops
.i2c_gate_ctrl(fe
, 0); /* close i2c-gate */
113 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
118 static int tua9001_sleep(struct dvb_frontend
*fe
)
120 struct tua9001_priv
*priv
= fe
->tuner_priv
;
123 dev_dbg(&priv
->i2c
->dev
, "%s:\n", __func__
);
126 ret
= fe
->callback(priv
->i2c
, DVB_FRONTEND_COMPONENT_TUNER
,
127 TUA9001_CMD_RESETN
, 1);
130 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
135 static int tua9001_set_params(struct dvb_frontend
*fe
)
137 struct tua9001_priv
*priv
= fe
->tuner_priv
;
138 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
142 struct reg_val data
[2];
144 dev_dbg(&priv
->i2c
->dev
, "%s: delivery_system=%d frequency=%d " \
145 "bandwidth_hz=%d\n", __func__
,
146 c
->delivery_system
, c
->frequency
, c
->bandwidth_hz
);
148 switch (c
->delivery_system
) {
150 switch (c
->bandwidth_hz
) {
176 frequency
= (c
->frequency
- 150000000);
182 data
[1].val
= frequency
;
184 if (fe
->ops
.i2c_gate_ctrl
)
185 fe
->ops
.i2c_gate_ctrl(fe
, 1); /* open i2c-gate */
188 ret
= fe
->callback(priv
->i2c
, DVB_FRONTEND_COMPONENT_TUNER
,
189 TUA9001_CMD_RXEN
, 0);
191 goto err_i2c_gate_ctrl
;
194 for (i
= 0; i
< ARRAY_SIZE(data
); i
++) {
195 ret
= tua9001_wr_reg(priv
, data
[i
].reg
, data
[i
].val
);
197 goto err_i2c_gate_ctrl
;
201 ret
= fe
->callback(priv
->i2c
, DVB_FRONTEND_COMPONENT_TUNER
,
202 TUA9001_CMD_RXEN
, 1);
204 goto err_i2c_gate_ctrl
;
208 if (fe
->ops
.i2c_gate_ctrl
)
209 fe
->ops
.i2c_gate_ctrl(fe
, 0); /* close i2c-gate */
212 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
217 static int tua9001_get_if_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
219 struct tua9001_priv
*priv
= fe
->tuner_priv
;
221 dev_dbg(&priv
->i2c
->dev
, "%s:\n", __func__
);
223 *frequency
= 0; /* Zero-IF */
228 static const struct dvb_tuner_ops tua9001_tuner_ops
= {
230 .name
= "Infineon TUA 9001",
232 .frequency_min
= 170000000,
233 .frequency_max
= 862000000,
237 .release
= tua9001_release
,
239 .init
= tua9001_init
,
240 .sleep
= tua9001_sleep
,
241 .set_params
= tua9001_set_params
,
243 .get_if_frequency
= tua9001_get_if_frequency
,
246 struct dvb_frontend
*tua9001_attach(struct dvb_frontend
*fe
,
247 struct i2c_adapter
*i2c
, struct tua9001_config
*cfg
)
249 struct tua9001_priv
*priv
= NULL
;
252 priv
= kzalloc(sizeof(struct tua9001_priv
), GFP_KERNEL
);
260 ret
= fe
->callback(priv
->i2c
, DVB_FRONTEND_COMPONENT_TUNER
,
265 ret
= fe
->callback(priv
->i2c
, DVB_FRONTEND_COMPONENT_TUNER
,
266 TUA9001_CMD_RXEN
, 0);
270 ret
= fe
->callback(priv
->i2c
, DVB_FRONTEND_COMPONENT_TUNER
,
271 TUA9001_CMD_RESETN
, 1);
276 dev_info(&priv
->i2c
->dev
,
277 "%s: Infineon TUA 9001 successfully attached\n",
280 memcpy(&fe
->ops
.tuner_ops
, &tua9001_tuner_ops
,
281 sizeof(struct dvb_tuner_ops
));
283 fe
->tuner_priv
= priv
;
286 dev_dbg(&i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
290 EXPORT_SYMBOL(tua9001_attach
);
292 MODULE_DESCRIPTION("Infineon TUA 9001 silicon tuner driver");
293 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
294 MODULE_LICENSE("GPL");