1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Infineon TUA9001 silicon tuner driver
5 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
8 #include "tua9001_priv.h"
10 static int tua9001_init(struct dvb_frontend
*fe
)
12 struct tua9001_dev
*dev
= fe
->tuner_priv
;
13 struct i2c_client
*client
= dev
->client
;
15 static const struct tua9001_reg_val data
[] = {
33 dev_dbg(&client
->dev
, "\n");
36 ret
= fe
->callback(client
->adapter
,
37 DVB_FRONTEND_COMPONENT_TUNER
,
38 TUA9001_CMD_RESETN
, 0);
43 for (i
= 0; i
< ARRAY_SIZE(data
); i
++) {
44 ret
= regmap_write(dev
->regmap
, data
[i
].reg
, data
[i
].val
);
50 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
54 static int tua9001_sleep(struct dvb_frontend
*fe
)
56 struct tua9001_dev
*dev
= fe
->tuner_priv
;
57 struct i2c_client
*client
= dev
->client
;
60 dev_dbg(&client
->dev
, "\n");
63 ret
= fe
->callback(client
->adapter
,
64 DVB_FRONTEND_COMPONENT_TUNER
,
65 TUA9001_CMD_RESETN
, 1);
71 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
75 static int tua9001_set_params(struct dvb_frontend
*fe
)
77 struct tua9001_dev
*dev
= fe
->tuner_priv
;
78 struct i2c_client
*client
= dev
->client
;
79 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
82 struct tua9001_reg_val data
[2];
85 "delivery_system=%u frequency=%u bandwidth_hz=%u\n",
86 c
->delivery_system
, c
->frequency
, c
->bandwidth_hz
);
88 switch (c
->delivery_system
) {
90 switch (c
->bandwidth_hz
) {
116 data
[1].val
= div_u64((u64
) (c
->frequency
- 150000000) * 48, 1000000);
119 ret
= fe
->callback(client
->adapter
,
120 DVB_FRONTEND_COMPONENT_TUNER
,
121 TUA9001_CMD_RXEN
, 0);
126 for (i
= 0; i
< ARRAY_SIZE(data
); i
++) {
127 ret
= regmap_write(dev
->regmap
, data
[i
].reg
, data
[i
].val
);
133 ret
= fe
->callback(client
->adapter
,
134 DVB_FRONTEND_COMPONENT_TUNER
,
135 TUA9001_CMD_RXEN
, 1);
141 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
145 static int tua9001_get_if_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
147 struct tua9001_dev
*dev
= fe
->tuner_priv
;
148 struct i2c_client
*client
= dev
->client
;
150 dev_dbg(&client
->dev
, "\n");
152 *frequency
= 0; /* Zero-IF */
156 static const struct dvb_tuner_ops tua9001_tuner_ops
= {
158 .name
= "Infineon TUA9001",
159 .frequency_min_hz
= 170 * MHz
,
160 .frequency_max_hz
= 862 * MHz
,
163 .init
= tua9001_init
,
164 .sleep
= tua9001_sleep
,
165 .set_params
= tua9001_set_params
,
167 .get_if_frequency
= tua9001_get_if_frequency
,
170 static int tua9001_probe(struct i2c_client
*client
,
171 const struct i2c_device_id
*id
)
173 struct tua9001_dev
*dev
;
174 struct tua9001_platform_data
*pdata
= client
->dev
.platform_data
;
175 struct dvb_frontend
*fe
= pdata
->dvb_frontend
;
177 static const struct regmap_config regmap_config
= {
182 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
188 dev
->fe
= pdata
->dvb_frontend
;
189 dev
->client
= client
;
190 dev
->regmap
= devm_regmap_init_i2c(client
, ®map_config
);
191 if (IS_ERR(dev
->regmap
)) {
192 ret
= PTR_ERR(dev
->regmap
);
197 ret
= fe
->callback(client
->adapter
,
198 DVB_FRONTEND_COMPONENT_TUNER
,
203 ret
= fe
->callback(client
->adapter
,
204 DVB_FRONTEND_COMPONENT_TUNER
,
205 TUA9001_CMD_RXEN
, 0);
209 ret
= fe
->callback(client
->adapter
,
210 DVB_FRONTEND_COMPONENT_TUNER
,
211 TUA9001_CMD_RESETN
, 1);
216 fe
->tuner_priv
= dev
;
217 memcpy(&fe
->ops
.tuner_ops
, &tua9001_tuner_ops
,
218 sizeof(struct dvb_tuner_ops
));
219 i2c_set_clientdata(client
, dev
);
221 dev_info(&client
->dev
, "Infineon TUA9001 successfully attached\n");
226 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
230 static int tua9001_remove(struct i2c_client
*client
)
232 struct tua9001_dev
*dev
= i2c_get_clientdata(client
);
233 struct dvb_frontend
*fe
= dev
->fe
;
236 dev_dbg(&client
->dev
, "\n");
239 ret
= fe
->callback(client
->adapter
,
240 DVB_FRONTEND_COMPONENT_TUNER
,
249 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
253 static const struct i2c_device_id tua9001_id_table
[] = {
257 MODULE_DEVICE_TABLE(i2c
, tua9001_id_table
);
259 static struct i2c_driver tua9001_driver
= {
262 .suppress_bind_attrs
= true,
264 .probe
= tua9001_probe
,
265 .remove
= tua9001_remove
,
266 .id_table
= tua9001_id_table
,
269 module_i2c_driver(tua9001_driver
);
271 MODULE_DESCRIPTION("Infineon TUA9001 silicon tuner driver");
272 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
273 MODULE_LICENSE("GPL");