blob: 539399dac55149e0554960f430b081881065f545 [file] [log] [blame]
Antti Palosaari711615d2014-04-14 21:55:12 -03001/*
2 * Silicon Labs Si2168 DVB-T/T2/C demodulator driver
3 *
4 * Copyright (C) 2014 Antti Palosaari <crope@iki.fi>
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 * GNU General Public License for more details.
15 */
16
Ron Economos380a6c82017-12-11 19:51:53 -050017#include <linux/delay.h>
18
Antti Palosaari845f3502014-04-10 22:00:50 -030019#include "si2168_priv.h"
20
21static const struct dvb_frontend_ops si2168_ops;
22
Antti Palosaarid2b72f62015-05-29 16:42:33 -030023/* execute firmware command */
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +020024static int si2168_cmd_execute(struct i2c_client *client, struct si2168_cmd *cmd)
Antti Palosaarid2b72f62015-05-29 16:42:33 -030025{
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +020026 struct si2168_dev *dev = i2c_get_clientdata(client);
Antti Palosaari845f3502014-04-10 22:00:50 -030027 int ret;
28 unsigned long timeout;
29
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +020030 mutex_lock(&dev->i2c_mutex);
31
Antti Palosaari845f3502014-04-10 22:00:50 -030032 if (cmd->wlen) {
33 /* write cmd and args for firmware */
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +020034 ret = i2c_master_send(client, cmd->args, cmd->wlen);
Antti Palosaari845f3502014-04-10 22:00:50 -030035 if (ret < 0) {
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +020036 goto err_mutex_unlock;
Antti Palosaari845f3502014-04-10 22:00:50 -030037 } else if (ret != cmd->wlen) {
38 ret = -EREMOTEIO;
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +020039 goto err_mutex_unlock;
Antti Palosaari845f3502014-04-10 22:00:50 -030040 }
41 }
42
43 if (cmd->rlen) {
44 /* wait cmd execution terminate */
Jurgen Kramer551c33e2014-12-08 05:30:44 -030045 #define TIMEOUT 70
Antti Palosaari845f3502014-04-10 22:00:50 -030046 timeout = jiffies + msecs_to_jiffies(TIMEOUT);
47 while (!time_after(jiffies, timeout)) {
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +020048 ret = i2c_master_recv(client, cmd->args, cmd->rlen);
Antti Palosaari845f3502014-04-10 22:00:50 -030049 if (ret < 0) {
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +020050 goto err_mutex_unlock;
Antti Palosaari845f3502014-04-10 22:00:50 -030051 } else if (ret != cmd->rlen) {
52 ret = -EREMOTEIO;
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +020053 goto err_mutex_unlock;
Antti Palosaari845f3502014-04-10 22:00:50 -030054 }
55
56 /* firmware ready? */
57 if ((cmd->args[0] >> 7) & 0x01)
58 break;
59 }
60
Antti Palosaari3de35832014-11-25 17:53:21 -030061 dev_dbg(&client->dev, "cmd execution took %d ms\n",
Antti Palosaari845f3502014-04-10 22:00:50 -030062 jiffies_to_msecs(jiffies) -
63 (jiffies_to_msecs(timeout) - TIMEOUT));
64
Olli Salonen7adf99d2015-05-05 13:54:16 -030065 /* error bit set? */
66 if ((cmd->args[0] >> 6) & 0x01) {
67 ret = -EREMOTEIO;
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +020068 goto err_mutex_unlock;
Olli Salonen7adf99d2015-05-05 13:54:16 -030069 }
70
Antti Palosaarieefae302014-06-13 11:08:25 -030071 if (!((cmd->args[0] >> 7) & 0x01)) {
Antti Palosaari845f3502014-04-10 22:00:50 -030072 ret = -ETIMEDOUT;
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +020073 goto err_mutex_unlock;
Antti Palosaari845f3502014-04-10 22:00:50 -030074 }
75 }
76
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +020077 mutex_unlock(&dev->i2c_mutex);
Antti Palosaari4affbe12014-12-05 14:30:44 -030078 return 0;
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +020079err_mutex_unlock:
80 mutex_unlock(&dev->i2c_mutex);
Antti Palosaari3de35832014-11-25 17:53:21 -030081 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaari845f3502014-04-10 22:00:50 -030082 return ret;
83}
84
Mauro Carvalho Chehab0df289a2015-06-07 14:53:52 -030085static int si2168_read_status(struct dvb_frontend *fe, enum fe_status *status)
Antti Palosaari845f3502014-04-10 22:00:50 -030086{
Antti Palosaari6307b562014-11-25 17:31:43 -030087 struct i2c_client *client = fe->demodulator_priv;
88 struct si2168_dev *dev = i2c_get_clientdata(client);
Antti Palosaaribffab932014-04-11 20:35:27 -030089 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
Antti Palosaari8393c002016-12-08 22:19:19 -020090 int ret, i;
91 unsigned int utmp, utmp1, utmp2;
Antti Palosaari845f3502014-04-10 22:00:50 -030092 struct si2168_cmd cmd;
93
94 *status = 0;
95
Antti Palosaaribd01c762014-11-25 16:46:16 -030096 if (!dev->active) {
Antti Palosaari845f3502014-04-10 22:00:50 -030097 ret = -EAGAIN;
98 goto err;
99 }
100
Antti Palosaaribffab932014-04-11 20:35:27 -0300101 switch (c->delivery_system) {
102 case SYS_DVBT:
Antti Palosaari888680f2014-07-09 19:36:58 -0300103 memcpy(cmd.args, "\xa0\x01", 2);
Antti Palosaaribffab932014-04-11 20:35:27 -0300104 cmd.wlen = 2;
105 cmd.rlen = 13;
106 break;
Antti Palosaaric7908852014-04-12 01:58:32 -0300107 case SYS_DVBC_ANNEX_A:
Antti Palosaari888680f2014-07-09 19:36:58 -0300108 memcpy(cmd.args, "\x90\x01", 2);
Antti Palosaaric7908852014-04-12 01:58:32 -0300109 cmd.wlen = 2;
110 cmd.rlen = 9;
111 break;
Antti Palosaaribffab932014-04-11 20:35:27 -0300112 case SYS_DVBT2:
Antti Palosaari888680f2014-07-09 19:36:58 -0300113 memcpy(cmd.args, "\x50\x01", 2);
Antti Palosaaribffab932014-04-11 20:35:27 -0300114 cmd.wlen = 2;
115 cmd.rlen = 14;
116 break;
117 default:
118 ret = -EINVAL;
119 goto err;
120 }
121
Antti Palosaari6307b562014-11-25 17:31:43 -0300122 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300123 if (ret)
124 goto err;
125
Antti Palosaari722a0422014-04-22 21:36:32 -0300126 switch ((cmd.args[2] >> 1) & 0x03) {
127 case 0x01:
Antti Palosaari845f3502014-04-10 22:00:50 -0300128 *status = FE_HAS_SIGNAL | FE_HAS_CARRIER;
129 break;
Antti Palosaari722a0422014-04-22 21:36:32 -0300130 case 0x03:
Antti Palosaari845f3502014-04-10 22:00:50 -0300131 *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI |
132 FE_HAS_SYNC | FE_HAS_LOCK;
133 break;
134 }
135
Antti Palosaaribd01c762014-11-25 16:46:16 -0300136 dev->fe_status = *status;
Antti Palosaari845f3502014-04-10 22:00:50 -0300137
Antti Palosaari88ac8f82014-07-09 20:22:27 -0300138 if (*status & FE_HAS_LOCK) {
139 c->cnr.len = 1;
140 c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
141 c->cnr.stat[0].svalue = cmd.args[3] * 1000 / 4;
142 } else {
143 c->cnr.len = 1;
144 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
145 }
146
Antti Palosaari3de35832014-11-25 17:53:21 -0300147 dev_dbg(&client->dev, "status=%02x args=%*ph\n",
Olli Salonen37b4e432014-08-05 08:54:08 -0300148 *status, cmd.rlen, cmd.args);
Antti Palosaari845f3502014-04-10 22:00:50 -0300149
Antti Palosaari8393c002016-12-08 22:19:19 -0200150 /* BER */
151 if (*status & FE_HAS_VITERBI) {
152 memcpy(cmd.args, "\x82\x00", 2);
153 cmd.wlen = 2;
154 cmd.rlen = 3;
155 ret = si2168_cmd_execute(client, &cmd);
156 if (ret)
157 goto err;
158
159 /*
160 * Firmware returns [0, 255] mantissa and [0, 8] exponent.
161 * Convert to DVB API: mantissa * 10^(8 - exponent) / 10^8
162 */
163 utmp = clamp(8 - cmd.args[1], 0, 8);
164 for (i = 0, utmp1 = 1; i < utmp; i++)
165 utmp1 = utmp1 * 10;
166
167 utmp1 = cmd.args[2] * utmp1;
168 utmp2 = 100000000; /* 10^8 */
169
170 dev_dbg(&client->dev,
171 "post_bit_error=%u post_bit_count=%u ber=%u*10^-%u\n",
172 utmp1, utmp2, cmd.args[2], cmd.args[1]);
173
174 c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
175 c->post_bit_error.stat[0].uvalue += utmp1;
176 c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
177 c->post_bit_count.stat[0].uvalue += utmp2;
178 } else {
179 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
180 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
181 }
182
Antti Palosaaric62d29c2016-12-09 11:11:32 -0200183 /* UCB */
184 if (*status & FE_HAS_SYNC) {
185 memcpy(cmd.args, "\x84\x01", 2);
186 cmd.wlen = 2;
187 cmd.rlen = 3;
188 ret = si2168_cmd_execute(client, &cmd);
189 if (ret)
190 goto err;
191
192 utmp1 = cmd.args[2] << 8 | cmd.args[1] << 0;
193 dev_dbg(&client->dev, "block_error=%u\n", utmp1);
194
195 /* Sometimes firmware returns bogus value */
196 if (utmp1 == 0xffff)
197 utmp1 = 0;
198
199 c->block_error.stat[0].scale = FE_SCALE_COUNTER;
200 c->block_error.stat[0].uvalue += utmp1;
201 } else {
202 c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
203 }
204
Antti Palosaari845f3502014-04-10 22:00:50 -0300205 return 0;
206err:
Antti Palosaari3de35832014-11-25 17:53:21 -0300207 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaari845f3502014-04-10 22:00:50 -0300208 return ret;
209}
210
211static int si2168_set_frontend(struct dvb_frontend *fe)
212{
Antti Palosaari6307b562014-11-25 17:31:43 -0300213 struct i2c_client *client = fe->demodulator_priv;
214 struct si2168_dev *dev = i2c_get_clientdata(client);
Antti Palosaari845f3502014-04-10 22:00:50 -0300215 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
216 int ret;
217 struct si2168_cmd cmd;
Antti Palosaaribffab932014-04-11 20:35:27 -0300218 u8 bandwidth, delivery_system;
Antti Palosaari845f3502014-04-10 22:00:50 -0300219
Antti Palosaari3de35832014-11-25 17:53:21 -0300220 dev_dbg(&client->dev,
Antti Palosaarie5dd1102014-12-05 15:57:03 -0300221 "delivery_system=%u modulation=%u frequency=%u bandwidth_hz=%u symbol_rate=%u inversion=%u stream_id=%u\n",
222 c->delivery_system, c->modulation, c->frequency,
223 c->bandwidth_hz, c->symbol_rate, c->inversion,
224 c->stream_id);
Antti Palosaari845f3502014-04-10 22:00:50 -0300225
Antti Palosaaribd01c762014-11-25 16:46:16 -0300226 if (!dev->active) {
Antti Palosaari845f3502014-04-10 22:00:50 -0300227 ret = -EAGAIN;
228 goto err;
229 }
230
Antti Palosaaribffab932014-04-11 20:35:27 -0300231 switch (c->delivery_system) {
232 case SYS_DVBT:
233 delivery_system = 0x20;
234 break;
Antti Palosaaric7908852014-04-12 01:58:32 -0300235 case SYS_DVBC_ANNEX_A:
236 delivery_system = 0x30;
237 break;
Antti Palosaaribffab932014-04-11 20:35:27 -0300238 case SYS_DVBT2:
239 delivery_system = 0x70;
240 break;
241 default:
242 ret = -EINVAL;
243 goto err;
244 }
245
Olli Salonen683e98b2015-01-16 09:35:19 -0300246 if (c->bandwidth_hz == 0) {
247 ret = -EINVAL;
248 goto err;
Olli Salonen17d4d6a2015-01-16 09:35:20 -0300249 } else if (c->bandwidth_hz <= 2000000)
250 bandwidth = 0x02;
251 else if (c->bandwidth_hz <= 5000000)
Antti Palosaaribffab932014-04-11 20:35:27 -0300252 bandwidth = 0x05;
Antti Palosaaric7908852014-04-12 01:58:32 -0300253 else if (c->bandwidth_hz <= 6000000)
Antti Palosaaribffab932014-04-11 20:35:27 -0300254 bandwidth = 0x06;
Antti Palosaaric7908852014-04-12 01:58:32 -0300255 else if (c->bandwidth_hz <= 7000000)
Antti Palosaaribffab932014-04-11 20:35:27 -0300256 bandwidth = 0x07;
Antti Palosaaric7908852014-04-12 01:58:32 -0300257 else if (c->bandwidth_hz <= 8000000)
Antti Palosaaribffab932014-04-11 20:35:27 -0300258 bandwidth = 0x08;
Antti Palosaaric7908852014-04-12 01:58:32 -0300259 else if (c->bandwidth_hz <= 9000000)
260 bandwidth = 0x09;
261 else if (c->bandwidth_hz <= 10000000)
262 bandwidth = 0x0a;
263 else
264 bandwidth = 0x0f;
Antti Palosaari845f3502014-04-10 22:00:50 -0300265
266 /* program tuner */
267 if (fe->ops.tuner_ops.set_params) {
268 ret = fe->ops.tuner_ops.set_params(fe);
269 if (ret)
270 goto err;
271 }
272
273 memcpy(cmd.args, "\x88\x02\x02\x02\x02", 5);
274 cmd.wlen = 5;
275 cmd.rlen = 5;
Antti Palosaari6307b562014-11-25 17:31:43 -0300276 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300277 if (ret)
278 goto err;
279
Antti Palosaaribffab932014-04-11 20:35:27 -0300280 /* that has no big effect */
281 if (c->delivery_system == SYS_DVBT)
282 memcpy(cmd.args, "\x89\x21\x06\x11\xff\x98", 6);
Antti Palosaaric7908852014-04-12 01:58:32 -0300283 else if (c->delivery_system == SYS_DVBC_ANNEX_A)
284 memcpy(cmd.args, "\x89\x21\x06\x11\x89\xf0", 6);
Antti Palosaaribffab932014-04-11 20:35:27 -0300285 else if (c->delivery_system == SYS_DVBT2)
286 memcpy(cmd.args, "\x89\x21\x06\x11\x89\x20", 6);
Antti Palosaari845f3502014-04-10 22:00:50 -0300287 cmd.wlen = 6;
288 cmd.rlen = 3;
Antti Palosaari6307b562014-11-25 17:31:43 -0300289 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300290 if (ret)
291 goto err;
292
CrazyCate395e572014-08-16 18:33:14 -0300293 if (c->delivery_system == SYS_DVBT2) {
294 /* select PLP */
295 cmd.args[0] = 0x52;
296 cmd.args[1] = c->stream_id & 0xff;
297 cmd.args[2] = c->stream_id == NO_STREAM_ID_FILTER ? 0 : 1;
298 cmd.wlen = 3;
299 cmd.rlen = 1;
Antti Palosaari6307b562014-11-25 17:31:43 -0300300 ret = si2168_cmd_execute(client, &cmd);
CrazyCate395e572014-08-16 18:33:14 -0300301 if (ret)
302 goto err;
303 }
304
Antti Palosaari845f3502014-04-10 22:00:50 -0300305 memcpy(cmd.args, "\x51\x03", 2);
306 cmd.wlen = 2;
307 cmd.rlen = 12;
Antti Palosaari6307b562014-11-25 17:31:43 -0300308 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300309 if (ret)
310 goto err;
311
312 memcpy(cmd.args, "\x12\x08\x04", 3);
313 cmd.wlen = 3;
314 cmd.rlen = 3;
Antti Palosaari6307b562014-11-25 17:31:43 -0300315 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300316 if (ret)
317 goto err;
318
Antti Palosaari845f3502014-04-10 22:00:50 -0300319 memcpy(cmd.args, "\x14\x00\x0c\x10\x12\x00", 6);
320 cmd.wlen = 6;
Antti Palosaari1d518c22014-07-11 10:40:29 -0300321 cmd.rlen = 4;
Antti Palosaari6307b562014-11-25 17:31:43 -0300322 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300323 if (ret)
324 goto err;
325
326 memcpy(cmd.args, "\x14\x00\x06\x10\x24\x00", 6);
327 cmd.wlen = 6;
Antti Palosaari1d518c22014-07-11 10:40:29 -0300328 cmd.rlen = 4;
Antti Palosaari6307b562014-11-25 17:31:43 -0300329 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300330 if (ret)
331 goto err;
332
Antti Palosaari845f3502014-04-10 22:00:50 -0300333 memcpy(cmd.args, "\x14\x00\x07\x10\x00\x24", 6);
334 cmd.wlen = 6;
Antti Palosaari1d518c22014-07-11 10:40:29 -0300335 cmd.rlen = 4;
Antti Palosaari6307b562014-11-25 17:31:43 -0300336 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300337 if (ret)
338 goto err;
339
340 memcpy(cmd.args, "\x14\x00\x0a\x10\x00\x00", 6);
Antti Palosaaribffab932014-04-11 20:35:27 -0300341 cmd.args[4] = delivery_system | bandwidth;
Antti Palosaari845f3502014-04-10 22:00:50 -0300342 cmd.wlen = 6;
Antti Palosaari1d518c22014-07-11 10:40:29 -0300343 cmd.rlen = 4;
Antti Palosaari6307b562014-11-25 17:31:43 -0300344 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300345 if (ret)
346 goto err;
347
Luis Alves32bf8812014-07-17 14:31:28 -0300348 /* set DVB-C symbol rate */
349 if (c->delivery_system == SYS_DVBC_ANNEX_A) {
350 memcpy(cmd.args, "\x14\x00\x02\x11", 4);
Antti Palosaari346d4902014-12-05 14:54:14 -0300351 cmd.args[4] = ((c->symbol_rate / 1000) >> 0) & 0xff;
Luis Alves32bf8812014-07-17 14:31:28 -0300352 cmd.args[5] = ((c->symbol_rate / 1000) >> 8) & 0xff;
353 cmd.wlen = 6;
354 cmd.rlen = 4;
Antti Palosaari6307b562014-11-25 17:31:43 -0300355 ret = si2168_cmd_execute(client, &cmd);
Luis Alves32bf8812014-07-17 14:31:28 -0300356 if (ret)
357 goto err;
358 }
359
Antti Palosaari845f3502014-04-10 22:00:50 -0300360 memcpy(cmd.args, "\x14\x00\x0f\x10\x10\x00", 6);
361 cmd.wlen = 6;
Antti Palosaari1d518c22014-07-11 10:40:29 -0300362 cmd.rlen = 4;
Antti Palosaari6307b562014-11-25 17:31:43 -0300363 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300364 if (ret)
365 goto err;
366
CrazyCat52791972014-11-14 18:22:10 -0300367 memcpy(cmd.args, "\x14\x00\x09\x10\xe3\x08", 6);
Antti Palosaaribd01c762014-11-25 16:46:16 -0300368 cmd.args[5] |= dev->ts_clock_inv ? 0x00 : 0x10;
Antti Palosaari845f3502014-04-10 22:00:50 -0300369 cmd.wlen = 6;
Antti Palosaari1d518c22014-07-11 10:40:29 -0300370 cmd.rlen = 4;
Antti Palosaari6307b562014-11-25 17:31:43 -0300371 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300372 if (ret)
373 goto err;
374
CrazyCat52791972014-11-14 18:22:10 -0300375 memcpy(cmd.args, "\x14\x00\x08\x10\xd7\x05", 6);
Antti Palosaaribd01c762014-11-25 16:46:16 -0300376 cmd.args[5] |= dev->ts_clock_inv ? 0x00 : 0x10;
Antti Palosaari845f3502014-04-10 22:00:50 -0300377 cmd.wlen = 6;
Antti Palosaari1d518c22014-07-11 10:40:29 -0300378 cmd.rlen = 4;
Antti Palosaari6307b562014-11-25 17:31:43 -0300379 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300380 if (ret)
381 goto err;
382
Antti Palosaari845f3502014-04-10 22:00:50 -0300383 memcpy(cmd.args, "\x14\x00\x01\x12\x00\x00", 6);
384 cmd.wlen = 6;
Antti Palosaari1d518c22014-07-11 10:40:29 -0300385 cmd.rlen = 4;
Antti Palosaari6307b562014-11-25 17:31:43 -0300386 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300387 if (ret)
388 goto err;
389
Olli Salonen43911772014-07-17 15:43:27 -0300390 memcpy(cmd.args, "\x14\x00\x01\x03\x0c\x00", 6);
391 cmd.wlen = 6;
392 cmd.rlen = 4;
Antti Palosaari6307b562014-11-25 17:31:43 -0300393 ret = si2168_cmd_execute(client, &cmd);
Olli Salonen43911772014-07-17 15:43:27 -0300394 if (ret)
395 goto err;
396
Antti Palosaari888680f2014-07-09 19:36:58 -0300397 memcpy(cmd.args, "\x85", 1);
Antti Palosaari845f3502014-04-10 22:00:50 -0300398 cmd.wlen = 1;
399 cmd.rlen = 1;
Antti Palosaari6307b562014-11-25 17:31:43 -0300400 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300401 if (ret)
402 goto err;
403
Antti Palosaaribd01c762014-11-25 16:46:16 -0300404 dev->delivery_system = c->delivery_system;
Antti Palosaari845f3502014-04-10 22:00:50 -0300405
406 return 0;
407err:
Antti Palosaari3de35832014-11-25 17:53:21 -0300408 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaari845f3502014-04-10 22:00:50 -0300409 return ret;
410}
411
412static int si2168_init(struct dvb_frontend *fe)
413{
Antti Palosaari6307b562014-11-25 17:31:43 -0300414 struct i2c_client *client = fe->demodulator_priv;
415 struct si2168_dev *dev = i2c_get_clientdata(client);
Antti Palosaari8393c002016-12-08 22:19:19 -0200416 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
Antti Palosaari845f3502014-04-10 22:00:50 -0300417 int ret, len, remaining;
Antti Palosaari58f66932014-12-05 17:22:42 -0300418 const struct firmware *fw;
Antti Palosaari845f3502014-04-10 22:00:50 -0300419 struct si2168_cmd cmd;
420
Antti Palosaari3de35832014-11-25 17:53:21 -0300421 dev_dbg(&client->dev, "\n");
Antti Palosaari845f3502014-04-10 22:00:50 -0300422
Olli Salonen8e417222014-08-25 15:07:04 -0300423 /* initialize */
Antti Palosaari888680f2014-07-09 19:36:58 -0300424 memcpy(cmd.args, "\xc0\x12\x00\x0c\x00\x0d\x16\x00\x00\x00\x00\x00\x00", 13);
Antti Palosaari845f3502014-04-10 22:00:50 -0300425 cmd.wlen = 13;
426 cmd.rlen = 0;
Antti Palosaari6307b562014-11-25 17:31:43 -0300427 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300428 if (ret)
429 goto err;
430
Antti Palosaari6ab1e942016-06-29 20:38:17 -0300431 if (dev->warm) {
Olli Salonen8e417222014-08-25 15:07:04 -0300432 /* resume */
433 memcpy(cmd.args, "\xc0\x06\x08\x0f\x00\x20\x21\x01", 8);
434 cmd.wlen = 8;
435 cmd.rlen = 1;
Antti Palosaari6307b562014-11-25 17:31:43 -0300436 ret = si2168_cmd_execute(client, &cmd);
Olli Salonen8e417222014-08-25 15:07:04 -0300437 if (ret)
438 goto err;
439
Ron Economos380a6c82017-12-11 19:51:53 -0500440 udelay(100);
Olli Salonen8e417222014-08-25 15:07:04 -0300441 memcpy(cmd.args, "\x85", 1);
442 cmd.wlen = 1;
443 cmd.rlen = 1;
Antti Palosaari6307b562014-11-25 17:31:43 -0300444 ret = si2168_cmd_execute(client, &cmd);
Olli Salonen8e417222014-08-25 15:07:04 -0300445 if (ret)
446 goto err;
447
448 goto warm;
449 }
450
451 /* power up */
Antti Palosaari888680f2014-07-09 19:36:58 -0300452 memcpy(cmd.args, "\xc0\x06\x01\x0f\x00\x20\x20\x01", 8);
Antti Palosaari845f3502014-04-10 22:00:50 -0300453 cmd.wlen = 8;
454 cmd.rlen = 1;
Antti Palosaari6307b562014-11-25 17:31:43 -0300455 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300456 if (ret)
457 goto err;
458
Antti Palosaari845f3502014-04-10 22:00:50 -0300459 /* request the firmware, this will block and timeout */
Antti Palosaari6ab1e942016-06-29 20:38:17 -0300460 ret = request_firmware(&fw, dev->firmware_name, &client->dev);
Antti Palosaari845f3502014-04-10 22:00:50 -0300461 if (ret) {
Antti Palosaarib6b6fd62014-07-13 19:22:19 -0300462 /* fallback mechanism to handle old name for Si2168 B40 fw */
Antti Palosaari6ab1e942016-06-29 20:38:17 -0300463 if (dev->chip_id == SI2168_CHIP_ID_B40) {
464 dev->firmware_name = SI2168_B40_FIRMWARE_FALLBACK;
465 ret = request_firmware(&fw, dev->firmware_name,
466 &client->dev);
Olli Salonenc9cb0822014-07-13 10:52:18 -0300467 }
Antti Palosaarib6b6fd62014-07-13 19:22:19 -0300468
469 if (ret == 0) {
Antti Palosaari3de35832014-11-25 17:53:21 -0300470 dev_notice(&client->dev,
Olli Salonen37b4e432014-08-05 08:54:08 -0300471 "please install firmware file '%s'\n",
472 SI2168_B40_FIRMWARE);
Antti Palosaarib6b6fd62014-07-13 19:22:19 -0300473 } else {
Antti Palosaari3de35832014-11-25 17:53:21 -0300474 dev_err(&client->dev,
Olli Salonen37b4e432014-08-05 08:54:08 -0300475 "firmware file '%s' not found\n",
Antti Palosaari6ab1e942016-06-29 20:38:17 -0300476 dev->firmware_name);
Antti Palosaari346d4902014-12-05 14:54:14 -0300477 goto err_release_firmware;
Olli Salonenc9cb0822014-07-13 10:52:18 -0300478 }
Antti Palosaari845f3502014-04-10 22:00:50 -0300479 }
480
Antti Palosaari3de35832014-11-25 17:53:21 -0300481 dev_info(&client->dev, "downloading firmware from file '%s'\n",
Antti Palosaari6ab1e942016-06-29 20:38:17 -0300482 dev->firmware_name);
Antti Palosaari845f3502014-04-10 22:00:50 -0300483
Olli Salonen1b97dc92014-11-27 16:42:23 -0300484 if ((fw->size % 17 == 0) && (fw->data[0] > 5)) {
485 /* firmware is in the new format */
486 for (remaining = fw->size; remaining > 0; remaining -= 17) {
487 len = fw->data[fw->size - remaining];
Laura Abbott47810b42015-09-29 21:10:09 -0300488 if (len > SI2168_ARGLEN) {
489 ret = -EINVAL;
490 break;
491 }
Olli Salonen1b97dc92014-11-27 16:42:23 -0300492 memcpy(cmd.args, &fw->data[(fw->size - remaining) + 1], len);
493 cmd.wlen = len;
494 cmd.rlen = 1;
Antti Palosaari6307b562014-11-25 17:31:43 -0300495 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari68c16a72014-12-05 17:08:22 -0300496 if (ret)
497 break;
Olli Salonen1b97dc92014-11-27 16:42:23 -0300498 }
Antti Palosaari68c16a72014-12-05 17:08:22 -0300499 } else if (fw->size % 8 == 0) {
Olli Salonen1b97dc92014-11-27 16:42:23 -0300500 /* firmware is in the old format */
Antti Palosaari68c16a72014-12-05 17:08:22 -0300501 for (remaining = fw->size; remaining > 0; remaining -= 8) {
502 len = 8;
Olli Salonen1b97dc92014-11-27 16:42:23 -0300503 memcpy(cmd.args, &fw->data[fw->size - remaining], len);
504 cmd.wlen = len;
505 cmd.rlen = 1;
Antti Palosaari6307b562014-11-25 17:31:43 -0300506 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari68c16a72014-12-05 17:08:22 -0300507 if (ret)
508 break;
Antti Palosaari845f3502014-04-10 22:00:50 -0300509 }
Antti Palosaari68c16a72014-12-05 17:08:22 -0300510 } else {
511 /* bad or unknown firmware format */
512 ret = -EINVAL;
513 }
514
515 if (ret) {
516 dev_err(&client->dev, "firmware download failed %d\n", ret);
517 goto err_release_firmware;
Antti Palosaari845f3502014-04-10 22:00:50 -0300518 }
519
520 release_firmware(fw);
Antti Palosaari845f3502014-04-10 22:00:50 -0300521
Antti Palosaari888680f2014-07-09 19:36:58 -0300522 memcpy(cmd.args, "\x01\x01", 2);
Antti Palosaari845f3502014-04-10 22:00:50 -0300523 cmd.wlen = 2;
524 cmd.rlen = 1;
Antti Palosaari6307b562014-11-25 17:31:43 -0300525 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari845f3502014-04-10 22:00:50 -0300526 if (ret)
527 goto err;
528
Olli Salonena594cf22014-11-27 16:42:22 -0300529 /* query firmware version */
530 memcpy(cmd.args, "\x11", 1);
531 cmd.wlen = 1;
532 cmd.rlen = 10;
Antti Palosaari6307b562014-11-25 17:31:43 -0300533 ret = si2168_cmd_execute(client, &cmd);
Olli Salonena594cf22014-11-27 16:42:22 -0300534 if (ret)
535 goto err;
536
Antti Palosaari6ab1e942016-06-29 20:38:17 -0300537 dev->version = (cmd.args[9] + '@') << 24 | (cmd.args[6] - '0') << 16 |
538 (cmd.args[7] - '0') << 8 | (cmd.args[8]) << 0;
539 dev_info(&client->dev, "firmware version: %c %d.%d.%d\n",
540 dev->version >> 24 & 0xff, dev->version >> 16 & 0xff,
541 dev->version >> 8 & 0xff, dev->version >> 0 & 0xff);
Olli Salonena594cf22014-11-27 16:42:22 -0300542
Olli Salonen389ce392014-08-11 16:58:10 -0300543 /* set ts mode */
544 memcpy(cmd.args, "\x14\x00\x01\x10\x10\x00", 6);
Antti Palosaaribd01c762014-11-25 16:46:16 -0300545 cmd.args[4] |= dev->ts_mode;
Olli Salonen8117a312015-05-05 13:54:14 -0300546 if (dev->ts_clock_gapped)
547 cmd.args[4] |= 0x40;
Olli Salonen389ce392014-08-11 16:58:10 -0300548 cmd.wlen = 6;
549 cmd.rlen = 4;
Antti Palosaari6307b562014-11-25 17:31:43 -0300550 ret = si2168_cmd_execute(client, &cmd);
Olli Salonen389ce392014-08-11 16:58:10 -0300551 if (ret)
552 goto err;
553
Antti Palosaari6ab1e942016-06-29 20:38:17 -0300554 dev->warm = true;
Antti Palosaari45c3cbb2014-11-03 18:28:39 -0300555warm:
Antti Palosaari8393c002016-12-08 22:19:19 -0200556 /* Init stats here to indicate which stats are supported */
557 c->cnr.len = 1;
558 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
559 c->post_bit_error.len = 1;
560 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
561 c->post_bit_count.len = 1;
562 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
Antti Palosaaric62d29c2016-12-09 11:11:32 -0200563 c->block_error.len = 1;
564 c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
Antti Palosaari8393c002016-12-08 22:19:19 -0200565
Antti Palosaaribd01c762014-11-25 16:46:16 -0300566 dev->active = true;
Antti Palosaari845f3502014-04-10 22:00:50 -0300567
568 return 0;
Antti Palosaari346d4902014-12-05 14:54:14 -0300569err_release_firmware:
Markus Elfring034e1ec2014-11-19 19:23:15 -0300570 release_firmware(fw);
571err:
Antti Palosaari3de35832014-11-25 17:53:21 -0300572 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaari845f3502014-04-10 22:00:50 -0300573 return ret;
574}
575
576static int si2168_sleep(struct dvb_frontend *fe)
577{
Antti Palosaari6307b562014-11-25 17:31:43 -0300578 struct i2c_client *client = fe->demodulator_priv;
579 struct si2168_dev *dev = i2c_get_clientdata(client);
Antti Palosaari4de0ed72014-07-09 18:45:31 -0300580 int ret;
581 struct si2168_cmd cmd;
Antti Palosaari845f3502014-04-10 22:00:50 -0300582
Antti Palosaari3de35832014-11-25 17:53:21 -0300583 dev_dbg(&client->dev, "\n");
Antti Palosaari845f3502014-04-10 22:00:50 -0300584
Antti Palosaaribd01c762014-11-25 16:46:16 -0300585 dev->active = false;
Antti Palosaari845f3502014-04-10 22:00:50 -0300586
Antti Palosaari6ab1e942016-06-29 20:38:17 -0300587 /* Firmware B 4.0-11 or later loses warm state during sleep */
588 if (dev->version > ('B' << 24 | 4 << 16 | 0 << 8 | 11 << 0))
589 dev->warm = false;
590
Antti Palosaari4de0ed72014-07-09 18:45:31 -0300591 memcpy(cmd.args, "\x13", 1);
592 cmd.wlen = 1;
593 cmd.rlen = 0;
Antti Palosaari6307b562014-11-25 17:31:43 -0300594 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaari4de0ed72014-07-09 18:45:31 -0300595 if (ret)
596 goto err;
597
Antti Palosaari845f3502014-04-10 22:00:50 -0300598 return 0;
Antti Palosaari4de0ed72014-07-09 18:45:31 -0300599err:
Antti Palosaari3de35832014-11-25 17:53:21 -0300600 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaari4de0ed72014-07-09 18:45:31 -0300601 return ret;
Antti Palosaari845f3502014-04-10 22:00:50 -0300602}
603
604static int si2168_get_tune_settings(struct dvb_frontend *fe,
605 struct dvb_frontend_tune_settings *s)
606{
607 s->min_delay_ms = 900;
608
609 return 0;
610}
611
Peter Rosin58d7b542016-04-20 08:41:36 +0200612static int si2168_select(struct i2c_mux_core *muxc, u32 chan)
Antti Palosaari845f3502014-04-10 22:00:50 -0300613{
Peter Rosin58d7b542016-04-20 08:41:36 +0200614 struct i2c_client *client = i2c_mux_priv(muxc);
Antti Palosaari845f3502014-04-10 22:00:50 -0300615 int ret;
Antti Palosaarid2b72f62015-05-29 16:42:33 -0300616 struct si2168_cmd cmd;
Antti Palosaari845f3502014-04-10 22:00:50 -0300617
Antti Palosaarid2b72f62015-05-29 16:42:33 -0300618 /* open I2C gate */
619 memcpy(cmd.args, "\xc0\x0d\x01", 3);
620 cmd.wlen = 3;
621 cmd.rlen = 0;
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +0200622 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaarid2b72f62015-05-29 16:42:33 -0300623 if (ret)
624 goto err;
Antti Palosaari845f3502014-04-10 22:00:50 -0300625
Antti Palosaarid2b72f62015-05-29 16:42:33 -0300626 return 0;
627err:
628 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaari845f3502014-04-10 22:00:50 -0300629 return ret;
630}
631
Peter Rosin58d7b542016-04-20 08:41:36 +0200632static int si2168_deselect(struct i2c_mux_core *muxc, u32 chan)
Antti Palosaari845f3502014-04-10 22:00:50 -0300633{
Peter Rosin58d7b542016-04-20 08:41:36 +0200634 struct i2c_client *client = i2c_mux_priv(muxc);
Antti Palosaari845f3502014-04-10 22:00:50 -0300635 int ret;
Antti Palosaarid2b72f62015-05-29 16:42:33 -0300636 struct si2168_cmd cmd;
Antti Palosaari845f3502014-04-10 22:00:50 -0300637
Antti Palosaarid2b72f62015-05-29 16:42:33 -0300638 /* close I2C gate */
639 memcpy(cmd.args, "\xc0\x0d\x00", 3);
640 cmd.wlen = 3;
641 cmd.rlen = 0;
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +0200642 ret = si2168_cmd_execute(client, &cmd);
Antti Palosaarid2b72f62015-05-29 16:42:33 -0300643 if (ret)
644 goto err;
Antti Palosaari845f3502014-04-10 22:00:50 -0300645
Antti Palosaarid2b72f62015-05-29 16:42:33 -0300646 return 0;
647err:
648 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaari845f3502014-04-10 22:00:50 -0300649 return ret;
650}
651
652static const struct dvb_frontend_ops si2168_ops = {
Antti Palosaaric7908852014-04-12 01:58:32 -0300653 .delsys = {SYS_DVBT, SYS_DVBT2, SYS_DVBC_ANNEX_A},
Antti Palosaari845f3502014-04-10 22:00:50 -0300654 .info = {
655 .name = "Silicon Labs Si2168",
Antti Palosaarif1ecc5d2014-11-25 16:26:49 -0300656 .symbol_rate_min = 1000000,
657 .symbol_rate_max = 7200000,
Antti Palosaari845f3502014-04-10 22:00:50 -0300658 .caps = FE_CAN_FEC_1_2 |
659 FE_CAN_FEC_2_3 |
660 FE_CAN_FEC_3_4 |
661 FE_CAN_FEC_5_6 |
662 FE_CAN_FEC_7_8 |
663 FE_CAN_FEC_AUTO |
664 FE_CAN_QPSK |
665 FE_CAN_QAM_16 |
666 FE_CAN_QAM_32 |
667 FE_CAN_QAM_64 |
668 FE_CAN_QAM_128 |
669 FE_CAN_QAM_256 |
670 FE_CAN_QAM_AUTO |
671 FE_CAN_TRANSMISSION_MODE_AUTO |
672 FE_CAN_GUARD_INTERVAL_AUTO |
673 FE_CAN_HIERARCHY_AUTO |
674 FE_CAN_MUTE_TS |
Olli Salonen327eeb32014-09-23 13:53:09 -0300675 FE_CAN_2G_MODULATION |
676 FE_CAN_MULTISTREAM
Antti Palosaari845f3502014-04-10 22:00:50 -0300677 },
678
679 .get_tune_settings = si2168_get_tune_settings,
680
681 .init = si2168_init,
682 .sleep = si2168_sleep,
683
684 .set_frontend = si2168_set_frontend,
685
686 .read_status = si2168_read_status,
687};
688
689static int si2168_probe(struct i2c_client *client,
690 const struct i2c_device_id *id)
691{
692 struct si2168_config *config = client->dev.platform_data;
Antti Palosaaribd01c762014-11-25 16:46:16 -0300693 struct si2168_dev *dev;
Antti Palosaari845f3502014-04-10 22:00:50 -0300694 int ret;
Antti Palosaari6ab1e942016-06-29 20:38:17 -0300695 struct si2168_cmd cmd;
Antti Palosaari845f3502014-04-10 22:00:50 -0300696
Olli Salonen37b4e432014-08-05 08:54:08 -0300697 dev_dbg(&client->dev, "\n");
Antti Palosaari845f3502014-04-10 22:00:50 -0300698
Antti Palosaaribd01c762014-11-25 16:46:16 -0300699 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
700 if (!dev) {
Antti Palosaari845f3502014-04-10 22:00:50 -0300701 ret = -ENOMEM;
Antti Palosaari1ee5e7d2014-12-05 16:02:42 -0300702 goto err;
Antti Palosaari845f3502014-04-10 22:00:50 -0300703 }
704
Antti Palosaari6ab1e942016-06-29 20:38:17 -0300705 i2c_set_clientdata(client, dev);
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +0200706 mutex_init(&dev->i2c_mutex);
707
Antti Palosaari6ab1e942016-06-29 20:38:17 -0300708 /* Initialize */
709 memcpy(cmd.args, "\xc0\x12\x00\x0c\x00\x0d\x16\x00\x00\x00\x00\x00\x00", 13);
710 cmd.wlen = 13;
711 cmd.rlen = 0;
712 ret = si2168_cmd_execute(client, &cmd);
713 if (ret)
714 goto err_kfree;
715
716 /* Power up */
717 memcpy(cmd.args, "\xc0\x06\x01\x0f\x00\x20\x20\x01", 8);
718 cmd.wlen = 8;
719 cmd.rlen = 1;
720 ret = si2168_cmd_execute(client, &cmd);
721 if (ret)
722 goto err_kfree;
723
724 /* Query chip revision */
725 memcpy(cmd.args, "\x02", 1);
726 cmd.wlen = 1;
727 cmd.rlen = 13;
728 ret = si2168_cmd_execute(client, &cmd);
729 if (ret)
730 goto err_kfree;
731
732 dev->chip_id = cmd.args[1] << 24 | cmd.args[2] << 16 |
733 cmd.args[3] << 8 | cmd.args[4] << 0;
734
735 switch (dev->chip_id) {
736 case SI2168_CHIP_ID_A20:
737 dev->firmware_name = SI2168_A20_FIRMWARE;
738 break;
739 case SI2168_CHIP_ID_A30:
740 dev->firmware_name = SI2168_A30_FIRMWARE;
741 break;
742 case SI2168_CHIP_ID_B40:
743 dev->firmware_name = SI2168_B40_FIRMWARE;
744 break;
Evgeny Plehov50d64462017-02-07 19:33:47 -0200745 case SI2168_CHIP_ID_D60:
746 dev->firmware_name = SI2168_D60_FIRMWARE;
747 break;
Antti Palosaari6ab1e942016-06-29 20:38:17 -0300748 default:
749 dev_dbg(&client->dev, "unknown chip version Si21%d-%c%c%c\n",
750 cmd.args[2], cmd.args[1], cmd.args[3], cmd.args[4]);
751 ret = -ENODEV;
752 goto err_kfree;
753 }
754
755 dev->version = (cmd.args[1]) << 24 | (cmd.args[3] - '0') << 16 |
756 (cmd.args[4] - '0') << 8 | (cmd.args[5]) << 0;
757
Antti Palosaari845f3502014-04-10 22:00:50 -0300758 /* create mux i2c adapter for tuner */
Peter Rosin58d7b542016-04-20 08:41:36 +0200759 dev->muxc = i2c_mux_alloc(client->adapter, &client->dev,
Antti Palosaarie6d7ffc2016-05-04 22:15:32 +0200760 1, 0, I2C_MUX_LOCKED,
Peter Rosin58d7b542016-04-20 08:41:36 +0200761 si2168_select, si2168_deselect);
762 if (!dev->muxc) {
763 ret = -ENOMEM;
Antti Palosaari346d4902014-12-05 14:54:14 -0300764 goto err_kfree;
Luis Alves4d6efc72014-07-17 16:38:08 -0300765 }
Peter Rosin58d7b542016-04-20 08:41:36 +0200766 dev->muxc->priv = client;
767 ret = i2c_mux_add_adapter(dev->muxc, 0, 0, 0);
768 if (ret)
769 goto err_kfree;
Antti Palosaari845f3502014-04-10 22:00:50 -0300770
771 /* create dvb_frontend */
Antti Palosaaribd01c762014-11-25 16:46:16 -0300772 memcpy(&dev->fe.ops, &si2168_ops, sizeof(struct dvb_frontend_ops));
Antti Palosaari6307b562014-11-25 17:31:43 -0300773 dev->fe.demodulator_priv = client;
Peter Rosin58d7b542016-04-20 08:41:36 +0200774 *config->i2c_adapter = dev->muxc->adapter[0];
Antti Palosaaribd01c762014-11-25 16:46:16 -0300775 *config->fe = &dev->fe;
776 dev->ts_mode = config->ts_mode;
777 dev->ts_clock_inv = config->ts_clock_inv;
Olli Salonen8117a312015-05-05 13:54:14 -0300778 dev->ts_clock_gapped = config->ts_clock_gapped;
Antti Palosaari845f3502014-04-10 22:00:50 -0300779
Antti Palosaari6ab1e942016-06-29 20:38:17 -0300780 dev_info(&client->dev, "Silicon Labs Si2168-%c%d%d successfully identified\n",
781 dev->version >> 24 & 0xff, dev->version >> 16 & 0xff,
782 dev->version >> 8 & 0xff);
783 dev_info(&client->dev, "firmware version: %c %d.%d.%d\n",
784 dev->version >> 24 & 0xff, dev->version >> 16 & 0xff,
785 dev->version >> 8 & 0xff, dev->version >> 0 & 0xff);
Antti Palosaari845f3502014-04-10 22:00:50 -0300786
Antti Palosaari845f3502014-04-10 22:00:50 -0300787 return 0;
Antti Palosaari346d4902014-12-05 14:54:14 -0300788err_kfree:
Antti Palosaaribd01c762014-11-25 16:46:16 -0300789 kfree(dev);
Antti Palosaari1ee5e7d2014-12-05 16:02:42 -0300790err:
Olli Salonen37b4e432014-08-05 08:54:08 -0300791 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaari845f3502014-04-10 22:00:50 -0300792 return ret;
793}
794
795static int si2168_remove(struct i2c_client *client)
796{
Antti Palosaaribd01c762014-11-25 16:46:16 -0300797 struct si2168_dev *dev = i2c_get_clientdata(client);
Antti Palosaari845f3502014-04-10 22:00:50 -0300798
Olli Salonen37b4e432014-08-05 08:54:08 -0300799 dev_dbg(&client->dev, "\n");
Antti Palosaari845f3502014-04-10 22:00:50 -0300800
Peter Rosin58d7b542016-04-20 08:41:36 +0200801 i2c_mux_del_adapters(dev->muxc);
Antti Palosaari845f3502014-04-10 22:00:50 -0300802
Antti Palosaaribd01c762014-11-25 16:46:16 -0300803 dev->fe.ops.release = NULL;
804 dev->fe.demodulator_priv = NULL;
Antti Palosaari845f3502014-04-10 22:00:50 -0300805
Antti Palosaaribd01c762014-11-25 16:46:16 -0300806 kfree(dev);
Antti Palosaari845f3502014-04-10 22:00:50 -0300807
808 return 0;
809}
810
Antti Palosaari346d4902014-12-05 14:54:14 -0300811static const struct i2c_device_id si2168_id_table[] = {
Antti Palosaari845f3502014-04-10 22:00:50 -0300812 {"si2168", 0},
813 {}
814};
Antti Palosaari346d4902014-12-05 14:54:14 -0300815MODULE_DEVICE_TABLE(i2c, si2168_id_table);
Antti Palosaari845f3502014-04-10 22:00:50 -0300816
817static struct i2c_driver si2168_driver = {
818 .driver = {
Antti Palosaarie06be1d2016-06-29 20:38:18 -0300819 .name = "si2168",
820 .suppress_bind_attrs = true,
Antti Palosaari845f3502014-04-10 22:00:50 -0300821 },
822 .probe = si2168_probe,
823 .remove = si2168_remove,
Antti Palosaari346d4902014-12-05 14:54:14 -0300824 .id_table = si2168_id_table,
Antti Palosaari845f3502014-04-10 22:00:50 -0300825};
826
827module_i2c_driver(si2168_driver);
828
829MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
830MODULE_DESCRIPTION("Silicon Labs Si2168 DVB-T/T2/C demodulator driver");
831MODULE_LICENSE("GPL");
Luis Alves635a90c2014-07-17 19:43:37 -0300832MODULE_FIRMWARE(SI2168_A20_FIRMWARE);
Antti Palosaari668aa632014-07-13 16:09:03 -0300833MODULE_FIRMWARE(SI2168_A30_FIRMWARE);
Olli Salonenc9cb0822014-07-13 10:52:18 -0300834MODULE_FIRMWARE(SI2168_B40_FIRMWARE);
Evgeny Plehov50d64462017-02-07 19:33:47 -0200835MODULE_FIRMWARE(SI2168_D60_FIRMWARE);