2 * Silicon Labs Si2146/2147/2148/2157/2158 silicon tuner driver
4 * Copyright (C) 2014 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 "si2157_priv.h"
19 static const struct dvb_tuner_ops si2157_ops
;
21 /* execute firmware command */
22 static int si2157_cmd_execute(struct si2157_dev
*dev
, struct si2157_cmd
*cmd
)
25 unsigned long timeout
;
27 mutex_lock(&dev
->i2c_mutex
);
30 /* write cmd and args for firmware */
31 ret
= i2c_master_send(dev
->client
, cmd
->args
, cmd
->wlen
);
33 goto err_mutex_unlock
;
34 } else if (ret
!= cmd
->wlen
) {
36 goto err_mutex_unlock
;
41 /* wait cmd execution terminate */
43 timeout
= jiffies
+ msecs_to_jiffies(TIMEOUT
);
44 while (!time_after(jiffies
, timeout
)) {
45 ret
= i2c_master_recv(dev
->client
, cmd
->args
, cmd
->rlen
);
47 goto err_mutex_unlock
;
48 } else if (ret
!= cmd
->rlen
) {
50 goto err_mutex_unlock
;
54 if ((cmd
->args
[0] >> 7) & 0x01)
58 dev_dbg(&dev
->client
->dev
, "cmd execution took %d ms\n",
59 jiffies_to_msecs(jiffies
) -
60 (jiffies_to_msecs(timeout
) - TIMEOUT
));
62 if (!((cmd
->args
[0] >> 7) & 0x01)) {
64 goto err_mutex_unlock
;
71 mutex_unlock(&dev
->i2c_mutex
);
77 dev_dbg(&dev
->client
->dev
, "failed=%d\n", ret
);
81 static int si2157_init(struct dvb_frontend
*fe
)
83 struct si2157_dev
*dev
= fe
->tuner_priv
;
84 int ret
, len
, remaining
;
85 struct si2157_cmd cmd
;
86 const struct firmware
*fw
= NULL
;
90 dev_dbg(&dev
->client
->dev
, "\n");
96 if (dev
->chiptype
== SI2157_CHIPTYPE_SI2146
) {
97 memcpy(cmd
.args
, "\xc0\x05\x01\x00\x00\x0b\x00\x00\x01", 9);
100 memcpy(cmd
.args
, "\xc0\x00\x0c\x00\x00\x01\x01\x01\x01\x01\x01\x02\x00\x00\x01", 15);
104 ret
= si2157_cmd_execute(dev
, &cmd
);
108 /* query chip revision */
109 memcpy(cmd
.args
, "\x02", 1);
112 ret
= si2157_cmd_execute(dev
, &cmd
);
116 chip_id
= cmd
.args
[1] << 24 | cmd
.args
[2] << 16 | cmd
.args
[3] << 8 |
119 #define SI2158_A20 ('A' << 24 | 58 << 16 | '2' << 8 | '0' << 0)
120 #define SI2148_A20 ('A' << 24 | 48 << 16 | '2' << 8 | '0' << 0)
121 #define SI2157_A30 ('A' << 24 | 57 << 16 | '3' << 8 | '0' << 0)
122 #define SI2147_A30 ('A' << 24 | 47 << 16 | '3' << 8 | '0' << 0)
123 #define SI2146_A10 ('A' << 24 | 46 << 16 | '1' << 8 | '0' << 0)
128 fw_file
= SI2158_A20_FIRMWARE
;
133 goto skip_fw_download
;
135 dev_err(&dev
->client
->dev
,
136 "unknown chip version Si21%d-%c%c%c\n",
137 cmd
.args
[2], cmd
.args
[1],
138 cmd
.args
[3], cmd
.args
[4]);
143 /* cold state - try to download firmware */
144 dev_info(&dev
->client
->dev
, "found a '%s' in cold state\n",
145 si2157_ops
.info
.name
);
147 /* request the firmware, this will block and timeout */
148 ret
= request_firmware(&fw
, fw_file
, &dev
->client
->dev
);
150 dev_err(&dev
->client
->dev
, "firmware file '%s' not found\n",
155 /* firmware should be n chunks of 17 bytes */
156 if (fw
->size
% 17 != 0) {
157 dev_err(&dev
->client
->dev
, "firmware file '%s' is invalid\n",
160 goto fw_release_exit
;
163 dev_info(&dev
->client
->dev
, "downloading firmware from file '%s'\n",
166 for (remaining
= fw
->size
; remaining
> 0; remaining
-= 17) {
167 len
= fw
->data
[fw
->size
- remaining
];
168 memcpy(cmd
.args
, &fw
->data
[(fw
->size
- remaining
) + 1], len
);
171 ret
= si2157_cmd_execute(dev
, &cmd
);
173 dev_err(&dev
->client
->dev
,
174 "firmware download failed=%d\n",
176 goto fw_release_exit
;
180 release_firmware(fw
);
184 /* reboot the tuner with new firmware? */
185 memcpy(cmd
.args
, "\x01\x01", 2);
188 ret
= si2157_cmd_execute(dev
, &cmd
);
192 dev
->fw_loaded
= true;
199 release_firmware(fw
);
201 dev_dbg(&dev
->client
->dev
, "failed=%d\n", ret
);
205 static int si2157_sleep(struct dvb_frontend
*fe
)
207 struct si2157_dev
*dev
= fe
->tuner_priv
;
209 struct si2157_cmd cmd
;
211 dev_dbg(&dev
->client
->dev
, "\n");
216 memcpy(cmd
.args
, "\x16\x00", 2);
219 ret
= si2157_cmd_execute(dev
, &cmd
);
225 dev_dbg(&dev
->client
->dev
, "failed=%d\n", ret
);
229 static int si2157_set_params(struct dvb_frontend
*fe
)
231 struct si2157_dev
*dev
= fe
->tuner_priv
;
232 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
234 struct si2157_cmd cmd
;
235 u8 bandwidth
, delivery_system
;
237 dev_dbg(&dev
->client
->dev
,
238 "delivery_system=%d frequency=%u bandwidth_hz=%u\n",
239 c
->delivery_system
, c
->frequency
,
247 if (c
->bandwidth_hz
<= 6000000)
249 else if (c
->bandwidth_hz
<= 7000000)
251 else if (c
->bandwidth_hz
<= 8000000)
256 switch (c
->delivery_system
) {
258 delivery_system
= 0x00;
260 case SYS_DVBC_ANNEX_B
:
261 delivery_system
= 0x10;
264 case SYS_DVBT2
: /* it seems DVB-T and DVB-T2 both are 0x20 here */
265 delivery_system
= 0x20;
267 case SYS_DVBC_ANNEX_A
:
268 delivery_system
= 0x30;
275 memcpy(cmd
.args
, "\x14\x00\x03\x07\x00\x00", 6);
276 cmd
.args
[4] = delivery_system
| bandwidth
;
281 ret
= si2157_cmd_execute(dev
, &cmd
);
285 if (dev
->chiptype
== SI2157_CHIPTYPE_SI2146
)
286 memcpy(cmd
.args
, "\x14\x00\x02\x07\x00\x01", 6);
288 memcpy(cmd
.args
, "\x14\x00\x02\x07\x01\x00", 6);
291 ret
= si2157_cmd_execute(dev
, &cmd
);
296 memcpy(cmd
.args
, "\x41\x00\x00\x00\x00\x00\x00\x00", 8);
297 cmd
.args
[4] = (c
->frequency
>> 0) & 0xff;
298 cmd
.args
[5] = (c
->frequency
>> 8) & 0xff;
299 cmd
.args
[6] = (c
->frequency
>> 16) & 0xff;
300 cmd
.args
[7] = (c
->frequency
>> 24) & 0xff;
303 ret
= si2157_cmd_execute(dev
, &cmd
);
309 dev_dbg(&dev
->client
->dev
, "failed=%d\n", ret
);
313 static int si2157_get_if_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
315 *frequency
= 5000000; /* default value of property 0x0706 */
319 static const struct dvb_tuner_ops si2157_ops
= {
321 .name
= "Silicon Labs Si2146/2147/2148/2157/2158",
322 .frequency_min
= 110000000,
323 .frequency_max
= 862000000,
327 .sleep
= si2157_sleep
,
328 .set_params
= si2157_set_params
,
329 .get_if_frequency
= si2157_get_if_frequency
,
332 static int si2157_probe(struct i2c_client
*client
,
333 const struct i2c_device_id
*id
)
335 struct si2157_config
*cfg
= client
->dev
.platform_data
;
336 struct dvb_frontend
*fe
= cfg
->fe
;
337 struct si2157_dev
*dev
;
338 struct si2157_cmd cmd
;
341 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
344 dev_err(&client
->dev
, "kzalloc() failed\n");
348 dev
->client
= client
;
350 dev
->inversion
= cfg
->inversion
;
351 dev
->fw_loaded
= false;
352 dev
->chiptype
= (u8
)id
->driver_data
;
353 mutex_init(&dev
->i2c_mutex
);
355 /* check if the tuner is there */
358 ret
= si2157_cmd_execute(dev
, &cmd
);
362 fe
->tuner_priv
= dev
;
363 memcpy(&fe
->ops
.tuner_ops
, &si2157_ops
, sizeof(struct dvb_tuner_ops
));
365 i2c_set_clientdata(client
, dev
);
367 dev_info(&dev
->client
->dev
,
368 "Silicon Labs %s successfully attached\n",
369 dev
->chiptype
== SI2157_CHIPTYPE_SI2146
?
370 "Si2146" : "Si2147/2148/2157/2158");
374 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
379 static int si2157_remove(struct i2c_client
*client
)
381 struct si2157_dev
*dev
= i2c_get_clientdata(client
);
382 struct dvb_frontend
*fe
= dev
->fe
;
384 dev_dbg(&client
->dev
, "\n");
386 memset(&fe
->ops
.tuner_ops
, 0, sizeof(struct dvb_tuner_ops
));
387 fe
->tuner_priv
= NULL
;
393 static const struct i2c_device_id si2157_id
[] = {
398 MODULE_DEVICE_TABLE(i2c
, si2157_id
);
400 static struct i2c_driver si2157_driver
= {
402 .owner
= THIS_MODULE
,
405 .probe
= si2157_probe
,
406 .remove
= si2157_remove
,
407 .id_table
= si2157_id
,
410 module_i2c_driver(si2157_driver
);
412 MODULE_DESCRIPTION("Silicon Labs Si2146/2147/2148/2157/2158 silicon tuner driver");
413 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
414 MODULE_LICENSE("GPL");
415 MODULE_FIRMWARE(SI2158_A20_FIRMWARE
);
This page took 0.047301 seconds and 5 git commands to generate.