2 * Infineon TUA9001 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.
17 #include "tua9001_priv.h"
19 static int tua9001_init(struct dvb_frontend
*fe
)
21 struct tua9001_dev
*dev
= fe
->tuner_priv
;
22 struct i2c_client
*client
= dev
->client
;
24 static const struct tua9001_reg_val data
[] = {
42 dev_dbg(&client
->dev
, "\n");
45 ret
= fe
->callback(client
->adapter
,
46 DVB_FRONTEND_COMPONENT_TUNER
,
47 TUA9001_CMD_RESETN
, 0);
52 for (i
= 0; i
< ARRAY_SIZE(data
); i
++) {
53 ret
= regmap_write(dev
->regmap
, data
[i
].reg
, data
[i
].val
);
59 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
63 static int tua9001_sleep(struct dvb_frontend
*fe
)
65 struct tua9001_dev
*dev
= fe
->tuner_priv
;
66 struct i2c_client
*client
= dev
->client
;
69 dev_dbg(&client
->dev
, "\n");
72 ret
= fe
->callback(client
->adapter
,
73 DVB_FRONTEND_COMPONENT_TUNER
,
74 TUA9001_CMD_RESETN
, 1);
80 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
84 static int tua9001_set_params(struct dvb_frontend
*fe
)
86 struct tua9001_dev
*dev
= fe
->tuner_priv
;
87 struct i2c_client
*client
= dev
->client
;
88 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
91 struct tua9001_reg_val data
[2];
94 "delivery_system=%u frequency=%u bandwidth_hz=%u\n",
95 c
->delivery_system
, c
->frequency
, c
->bandwidth_hz
);
97 switch (c
->delivery_system
) {
99 switch (c
->bandwidth_hz
) {
125 data
[1].val
= div_u64((u64
) (c
->frequency
- 150000000) * 48, 1000000);
128 ret
= fe
->callback(client
->adapter
,
129 DVB_FRONTEND_COMPONENT_TUNER
,
130 TUA9001_CMD_RXEN
, 0);
135 for (i
= 0; i
< ARRAY_SIZE(data
); i
++) {
136 ret
= regmap_write(dev
->regmap
, data
[i
].reg
, data
[i
].val
);
142 ret
= fe
->callback(client
->adapter
,
143 DVB_FRONTEND_COMPONENT_TUNER
,
144 TUA9001_CMD_RXEN
, 1);
150 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
154 static int tua9001_get_if_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
156 struct tua9001_dev
*dev
= fe
->tuner_priv
;
157 struct i2c_client
*client
= dev
->client
;
159 dev_dbg(&client
->dev
, "\n");
161 *frequency
= 0; /* Zero-IF */
165 static const struct dvb_tuner_ops tua9001_tuner_ops
= {
167 .name
= "Infineon TUA9001",
168 .frequency_min
= 170000000,
169 .frequency_max
= 862000000,
172 .init
= tua9001_init
,
173 .sleep
= tua9001_sleep
,
174 .set_params
= tua9001_set_params
,
176 .get_if_frequency
= tua9001_get_if_frequency
,
179 static int tua9001_probe(struct i2c_client
*client
,
180 const struct i2c_device_id
*id
)
182 struct tua9001_dev
*dev
;
183 struct tua9001_platform_data
*pdata
= client
->dev
.platform_data
;
184 struct dvb_frontend
*fe
= pdata
->dvb_frontend
;
186 static const struct regmap_config regmap_config
= {
191 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
197 dev
->fe
= pdata
->dvb_frontend
;
198 dev
->client
= client
;
199 dev
->regmap
= devm_regmap_init_i2c(client
, ®map_config
);
200 if (IS_ERR(dev
->regmap
)) {
201 ret
= PTR_ERR(dev
->regmap
);
206 ret
= fe
->callback(client
->adapter
,
207 DVB_FRONTEND_COMPONENT_TUNER
,
212 ret
= fe
->callback(client
->adapter
,
213 DVB_FRONTEND_COMPONENT_TUNER
,
214 TUA9001_CMD_RXEN
, 0);
218 ret
= fe
->callback(client
->adapter
,
219 DVB_FRONTEND_COMPONENT_TUNER
,
220 TUA9001_CMD_RESETN
, 1);
225 fe
->tuner_priv
= dev
;
226 memcpy(&fe
->ops
.tuner_ops
, &tua9001_tuner_ops
,
227 sizeof(struct dvb_tuner_ops
));
228 i2c_set_clientdata(client
, dev
);
230 dev_info(&client
->dev
, "Infineon TUA9001 successfully attached\n");
235 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
239 static int tua9001_remove(struct i2c_client
*client
)
241 struct tua9001_dev
*dev
= i2c_get_clientdata(client
);
242 struct dvb_frontend
*fe
= dev
->fe
;
245 dev_dbg(&client
->dev
, "\n");
248 ret
= fe
->callback(client
->adapter
,
249 DVB_FRONTEND_COMPONENT_TUNER
,
258 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
262 static const struct i2c_device_id tua9001_id_table
[] = {
266 MODULE_DEVICE_TABLE(i2c
, tua9001_id_table
);
268 static struct i2c_driver tua9001_driver
= {
270 .owner
= THIS_MODULE
,
272 .suppress_bind_attrs
= true,
274 .probe
= tua9001_probe
,
275 .remove
= tua9001_remove
,
276 .id_table
= tua9001_id_table
,
279 module_i2c_driver(tua9001_driver
);
281 MODULE_DESCRIPTION("Infineon TUA9001 silicon tuner driver");
282 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
283 MODULE_LICENSE("GPL");