blob: 5e3625e75620653e80612888c7dc8156b0cda9e9 [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Antti Palosaarif9263742012-03-30 06:37:26 -03002/*
Antti Palosaari465433f2015-04-15 20:26:06 -03003 * Infineon TUA9001 silicon tuner driver
Antti Palosaarif9263742012-03-30 06:37:26 -03004 *
5 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
Antti Palosaarif9263742012-03-30 06:37:26 -03006 */
7
Antti Palosaarif9263742012-03-30 06:37:26 -03008#include "tua9001_priv.h"
9
Antti Palosaarif9263742012-03-30 06:37:26 -030010static int tua9001_init(struct dvb_frontend *fe)
11{
Antti Palosaari465433f2015-04-15 20:26:06 -030012 struct tua9001_dev *dev = fe->tuner_priv;
13 struct i2c_client *client = dev->client;
14 int ret, i;
15 static const struct tua9001_reg_val data[] = {
16 {0x1e, 0x6512},
17 {0x25, 0xb888},
18 {0x39, 0x5460},
19 {0x3b, 0x00c0},
20 {0x3a, 0xf000},
21 {0x08, 0x0000},
22 {0x32, 0x0030},
23 {0x41, 0x703a},
24 {0x40, 0x1c78},
25 {0x2c, 0x1c00},
26 {0x36, 0xc013},
27 {0x37, 0x6f18},
28 {0x27, 0x0008},
29 {0x2a, 0x0001},
30 {0x34, 0x0a40},
Antti Palosaarif9263742012-03-30 06:37:26 -030031 };
32
Antti Palosaari465433f2015-04-15 20:26:06 -030033 dev_dbg(&client->dev, "\n");
Antti Palosaarie6211c72012-09-11 22:27:10 -030034
Antti Palosaari89054e32012-09-11 22:27:07 -030035 if (fe->callback) {
Antti Palosaari465433f2015-04-15 20:26:06 -030036 ret = fe->callback(client->adapter,
37 DVB_FRONTEND_COMPONENT_TUNER,
38 TUA9001_CMD_RESETN, 0);
39 if (ret)
Antti Palosaari89054e32012-09-11 22:27:07 -030040 goto err;
41 }
42
Antti Palosaarif9263742012-03-30 06:37:26 -030043 for (i = 0; i < ARRAY_SIZE(data); i++) {
Antti Palosaaridd219a82015-04-15 20:38:43 -030044 ret = regmap_write(dev->regmap, data[i].reg, data[i].val);
Antti Palosaari465433f2015-04-15 20:26:06 -030045 if (ret)
Antti Palosaari96676232015-04-15 19:33:13 -030046 goto err;
Antti Palosaarif9263742012-03-30 06:37:26 -030047 }
Antti Palosaari465433f2015-04-15 20:26:06 -030048 return 0;
Antti Palosaari89054e32012-09-11 22:27:07 -030049err:
Antti Palosaari465433f2015-04-15 20:26:06 -030050 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaari89054e32012-09-11 22:27:07 -030051 return ret;
52}
53
54static int tua9001_sleep(struct dvb_frontend *fe)
55{
Antti Palosaari465433f2015-04-15 20:26:06 -030056 struct tua9001_dev *dev = fe->tuner_priv;
57 struct i2c_client *client = dev->client;
58 int ret;
Antti Palosaari89054e32012-09-11 22:27:07 -030059
Antti Palosaari465433f2015-04-15 20:26:06 -030060 dev_dbg(&client->dev, "\n");
Antti Palosaarie6211c72012-09-11 22:27:10 -030061
Antti Palosaari465433f2015-04-15 20:26:06 -030062 if (fe->callback) {
63 ret = fe->callback(client->adapter,
64 DVB_FRONTEND_COMPONENT_TUNER,
65 TUA9001_CMD_RESETN, 1);
66 if (ret)
67 goto err;
68 }
69 return 0;
70err:
71 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaarif9263742012-03-30 06:37:26 -030072 return ret;
73}
74
75static int tua9001_set_params(struct dvb_frontend *fe)
76{
Antti Palosaari465433f2015-04-15 20:26:06 -030077 struct tua9001_dev *dev = fe->tuner_priv;
78 struct i2c_client *client = dev->client;
Antti Palosaarif9263742012-03-30 06:37:26 -030079 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
Antti Palosaari465433f2015-04-15 20:26:06 -030080 int ret, i;
Antti Palosaarif9263742012-03-30 06:37:26 -030081 u16 val;
Antti Palosaari465433f2015-04-15 20:26:06 -030082 struct tua9001_reg_val data[2];
Antti Palosaarif9263742012-03-30 06:37:26 -030083
Antti Palosaari465433f2015-04-15 20:26:06 -030084 dev_dbg(&client->dev,
85 "delivery_system=%u frequency=%u bandwidth_hz=%u\n",
86 c->delivery_system, c->frequency, c->bandwidth_hz);
Antti Palosaarif9263742012-03-30 06:37:26 -030087
88 switch (c->delivery_system) {
89 case SYS_DVBT:
90 switch (c->bandwidth_hz) {
91 case 8000000:
92 val = 0x0000;
93 break;
94 case 7000000:
95 val = 0x1000;
96 break;
97 case 6000000:
98 val = 0x2000;
99 break;
100 case 5000000:
101 val = 0x3000;
102 break;
103 default:
104 ret = -EINVAL;
105 goto err;
106 }
107 break;
108 default:
109 ret = -EINVAL;
110 goto err;
111 }
112
113 data[0].reg = 0x04;
114 data[0].val = val;
Antti Palosaarif9263742012-03-30 06:37:26 -0300115 data[1].reg = 0x1f;
Antti Palosaari47f95db2015-04-16 07:36:51 -0300116 data[1].val = div_u64((u64) (c->frequency - 150000000) * 48, 1000000);
Antti Palosaarif9263742012-03-30 06:37:26 -0300117
Antti Palosaari89054e32012-09-11 22:27:07 -0300118 if (fe->callback) {
Antti Palosaari465433f2015-04-15 20:26:06 -0300119 ret = fe->callback(client->adapter,
120 DVB_FRONTEND_COMPONENT_TUNER,
121 TUA9001_CMD_RXEN, 0);
122 if (ret)
Antti Palosaari96676232015-04-15 19:33:13 -0300123 goto err;
Antti Palosaari89054e32012-09-11 22:27:07 -0300124 }
125
Antti Palosaarif9263742012-03-30 06:37:26 -0300126 for (i = 0; i < ARRAY_SIZE(data); i++) {
Antti Palosaaridd219a82015-04-15 20:38:43 -0300127 ret = regmap_write(dev->regmap, data[i].reg, data[i].val);
Antti Palosaari465433f2015-04-15 20:26:06 -0300128 if (ret)
Antti Palosaari96676232015-04-15 19:33:13 -0300129 goto err;
Antti Palosaarif9263742012-03-30 06:37:26 -0300130 }
131
Antti Palosaari89054e32012-09-11 22:27:07 -0300132 if (fe->callback) {
Antti Palosaari465433f2015-04-15 20:26:06 -0300133 ret = fe->callback(client->adapter,
134 DVB_FRONTEND_COMPONENT_TUNER,
135 TUA9001_CMD_RXEN, 1);
136 if (ret)
Antti Palosaari96676232015-04-15 19:33:13 -0300137 goto err;
Antti Palosaari89054e32012-09-11 22:27:07 -0300138 }
Antti Palosaari465433f2015-04-15 20:26:06 -0300139 return 0;
Antti Palosaarif9263742012-03-30 06:37:26 -0300140err:
Antti Palosaari465433f2015-04-15 20:26:06 -0300141 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaarif9263742012-03-30 06:37:26 -0300142 return ret;
143}
144
145static int tua9001_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
146{
Antti Palosaari465433f2015-04-15 20:26:06 -0300147 struct tua9001_dev *dev = fe->tuner_priv;
148 struct i2c_client *client = dev->client;
Antti Palosaarie6211c72012-09-11 22:27:10 -0300149
Antti Palosaari465433f2015-04-15 20:26:06 -0300150 dev_dbg(&client->dev, "\n");
Antti Palosaarie6211c72012-09-11 22:27:10 -0300151
Antti Palosaarif9263742012-03-30 06:37:26 -0300152 *frequency = 0; /* Zero-IF */
Antti Palosaarif9263742012-03-30 06:37:26 -0300153 return 0;
154}
155
156static const struct dvb_tuner_ops tua9001_tuner_ops = {
157 .info = {
Mauro Carvalho Chehaba3f90c72018-07-05 18:59:35 -0400158 .name = "Infineon TUA9001",
159 .frequency_min_hz = 170 * MHz,
160 .frequency_max_hz = 862 * MHz,
Antti Palosaarif9263742012-03-30 06:37:26 -0300161 },
162
Antti Palosaarif9263742012-03-30 06:37:26 -0300163 .init = tua9001_init,
Antti Palosaari89054e32012-09-11 22:27:07 -0300164 .sleep = tua9001_sleep,
Antti Palosaarif9263742012-03-30 06:37:26 -0300165 .set_params = tua9001_set_params,
166
167 .get_if_frequency = tua9001_get_if_frequency,
168};
169
Antti Palosaarifc851c62015-04-15 19:12:34 -0300170static int tua9001_probe(struct i2c_client *client,
171 const struct i2c_device_id *id)
172{
Antti Palosaari465433f2015-04-15 20:26:06 -0300173 struct tua9001_dev *dev;
Antti Palosaarifc851c62015-04-15 19:12:34 -0300174 struct tua9001_platform_data *pdata = client->dev.platform_data;
175 struct dvb_frontend *fe = pdata->dvb_frontend;
176 int ret;
Antti Palosaaridd219a82015-04-15 20:38:43 -0300177 static const struct regmap_config regmap_config = {
178 .reg_bits = 8,
179 .val_bits = 16,
180 };
Antti Palosaarifc851c62015-04-15 19:12:34 -0300181
182 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
183 if (!dev) {
184 ret = -ENOMEM;
185 goto err;
186 }
187
Antti Palosaarifc851c62015-04-15 19:12:34 -0300188 dev->fe = pdata->dvb_frontend;
Antti Palosaaridd219a82015-04-15 20:38:43 -0300189 dev->client = client;
190 dev->regmap = devm_regmap_init_i2c(client, &regmap_config);
191 if (IS_ERR(dev->regmap)) {
192 ret = PTR_ERR(dev->regmap);
193 goto err_kfree;
194 }
Antti Palosaarifc851c62015-04-15 19:12:34 -0300195
196 if (fe->callback) {
197 ret = fe->callback(client->adapter,
198 DVB_FRONTEND_COMPONENT_TUNER,
199 TUA9001_CMD_CEN, 1);
200 if (ret)
201 goto err_kfree;
202
203 ret = fe->callback(client->adapter,
204 DVB_FRONTEND_COMPONENT_TUNER,
205 TUA9001_CMD_RXEN, 0);
206 if (ret)
207 goto err_kfree;
208
209 ret = fe->callback(client->adapter,
210 DVB_FRONTEND_COMPONENT_TUNER,
211 TUA9001_CMD_RESETN, 1);
212 if (ret)
213 goto err_kfree;
214 }
215
216 fe->tuner_priv = dev;
217 memcpy(&fe->ops.tuner_ops, &tua9001_tuner_ops,
218 sizeof(struct dvb_tuner_ops));
Antti Palosaarifc851c62015-04-15 19:12:34 -0300219 i2c_set_clientdata(client, dev);
220
Antti Palosaari465433f2015-04-15 20:26:06 -0300221 dev_info(&client->dev, "Infineon TUA9001 successfully attached\n");
Antti Palosaarifc851c62015-04-15 19:12:34 -0300222 return 0;
223err_kfree:
224 kfree(dev);
225err:
226 dev_dbg(&client->dev, "failed=%d\n", ret);
227 return ret;
228}
229
230static int tua9001_remove(struct i2c_client *client)
231{
Antti Palosaari465433f2015-04-15 20:26:06 -0300232 struct tua9001_dev *dev = i2c_get_clientdata(client);
Antti Palosaarifc851c62015-04-15 19:12:34 -0300233 struct dvb_frontend *fe = dev->fe;
234 int ret;
235
236 dev_dbg(&client->dev, "\n");
237
238 if (fe->callback) {
239 ret = fe->callback(client->adapter,
240 DVB_FRONTEND_COMPONENT_TUNER,
241 TUA9001_CMD_CEN, 0);
242 if (ret)
243 goto err_kfree;
244 }
245 kfree(dev);
246 return 0;
247err_kfree:
248 kfree(dev);
249 dev_dbg(&client->dev, "failed=%d\n", ret);
250 return ret;
251}
252
253static const struct i2c_device_id tua9001_id_table[] = {
254 {"tua9001", 0},
255 {}
256};
257MODULE_DEVICE_TABLE(i2c, tua9001_id_table);
258
259static struct i2c_driver tua9001_driver = {
260 .driver = {
Antti Palosaarifc851c62015-04-15 19:12:34 -0300261 .name = "tua9001",
262 .suppress_bind_attrs = true,
263 },
264 .probe = tua9001_probe,
265 .remove = tua9001_remove,
266 .id_table = tua9001_id_table,
267};
268
269module_i2c_driver(tua9001_driver);
270
Antti Palosaari465433f2015-04-15 20:26:06 -0300271MODULE_DESCRIPTION("Infineon TUA9001 silicon tuner driver");
Antti Palosaarif9263742012-03-30 06:37:26 -0300272MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
273MODULE_LICENSE("GPL");