2 * Silicon Labs Si2157 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 /* execute firmware command */
20 static int si2157_cmd_execute(struct si2157
*s
, struct si2157_cmd
*cmd
)
24 unsigned long timeout
;
26 mutex_lock(&s
->i2c_mutex
);
29 /* write cmd and args for firmware */
30 ret
= i2c_master_send(s
->client
, cmd
->args
, cmd
->len
);
32 goto err_mutex_unlock
;
33 } else if (ret
!= cmd
->len
) {
35 goto err_mutex_unlock
;
39 /* wait cmd execution terminate */
41 timeout
= jiffies
+ msecs_to_jiffies(TIMEOUT
);
42 while (!time_after(jiffies
, timeout
)) {
43 ret
= i2c_master_recv(s
->client
, buf
, 1);
45 goto err_mutex_unlock
;
46 } else if (ret
!= 1) {
48 goto err_mutex_unlock
;
52 if ((buf
[0] >> 7) & 0x01)
56 dev_dbg(&s
->client
->dev
, "%s: cmd execution took %d ms\n", __func__
,
57 jiffies_to_msecs(jiffies
) -
58 (jiffies_to_msecs(timeout
) - TIMEOUT
));
60 if (!((buf
[0] >> 7) & 0x01)) {
62 goto err_mutex_unlock
;
68 mutex_unlock(&s
->i2c_mutex
);
74 dev_dbg(&s
->client
->dev
, "%s: failed=%d\n", __func__
, ret
);
78 static int si2157_init(struct dvb_frontend
*fe
)
80 struct si2157
*s
= fe
->tuner_priv
;
82 dev_dbg(&s
->client
->dev
, "%s:\n", __func__
);
89 static int si2157_sleep(struct dvb_frontend
*fe
)
91 struct si2157
*s
= fe
->tuner_priv
;
93 dev_dbg(&s
->client
->dev
, "%s:\n", __func__
);
100 static int si2157_set_params(struct dvb_frontend
*fe
)
102 struct si2157
*s
= fe
->tuner_priv
;
103 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
105 struct si2157_cmd cmd
;
107 dev_dbg(&s
->client
->dev
,
108 "%s: delivery_system=%d frequency=%u bandwidth_hz=%u\n",
109 __func__
, c
->delivery_system
, c
->frequency
,
134 ret
= si2157_cmd_execute(s
, &cmd
);
140 ret
= si2157_cmd_execute(s
, &cmd
);
147 ret
= si2157_cmd_execute(s
, &cmd
);
156 cmd
.args
[4] = (c
->frequency
>> 0) & 0xff;
157 cmd
.args
[5] = (c
->frequency
>> 8) & 0xff;
158 cmd
.args
[6] = (c
->frequency
>> 16) & 0xff;
159 cmd
.args
[7] = (c
->frequency
>> 24) & 0xff;
161 ret
= si2157_cmd_execute(s
, &cmd
);
167 dev_dbg(&s
->client
->dev
, "%s: failed=%d\n", __func__
, ret
);
171 static const struct dvb_tuner_ops si2157_tuner_ops
= {
173 .name
= "Silicon Labs Si2157",
174 .frequency_min
= 110000000,
175 .frequency_max
= 862000000,
179 .sleep
= si2157_sleep
,
180 .set_params
= si2157_set_params
,
183 static int si2157_probe(struct i2c_client
*client
,
184 const struct i2c_device_id
*id
)
186 struct si2157_config
*cfg
= client
->dev
.platform_data
;
187 struct dvb_frontend
*fe
= cfg
->fe
;
189 struct si2157_cmd cmd
;
192 s
= kzalloc(sizeof(struct si2157
), GFP_KERNEL
);
195 dev_err(&client
->dev
, "%s: kzalloc() failed\n", KBUILD_MODNAME
);
201 mutex_init(&s
->i2c_mutex
);
203 /* check if the tuner is there */
205 ret
= si2157_cmd_execute(s
, &cmd
);
210 memcpy(&fe
->ops
.tuner_ops
, &si2157_tuner_ops
,
211 sizeof(struct dvb_tuner_ops
));
213 i2c_set_clientdata(client
, s
);
215 dev_info(&s
->client
->dev
,
216 "%s: Silicon Labs Si2157 successfully attached\n",
220 dev_dbg(&client
->dev
, "%s: failed=%d\n", __func__
, ret
);
226 static int si2157_remove(struct i2c_client
*client
)
228 struct si2157
*s
= i2c_get_clientdata(client
);
229 struct dvb_frontend
*fe
= s
->fe
;
231 dev_dbg(&client
->dev
, "%s:\n", __func__
);
233 memset(&fe
->ops
.tuner_ops
, 0, sizeof(struct dvb_tuner_ops
));
234 fe
->tuner_priv
= NULL
;
240 static const struct i2c_device_id si2157_id
[] = {
244 MODULE_DEVICE_TABLE(i2c
, si2157_id
);
246 static struct i2c_driver si2157_driver
= {
248 .owner
= THIS_MODULE
,
251 .probe
= si2157_probe
,
252 .remove
= si2157_remove
,
253 .id_table
= si2157_id
,
256 module_i2c_driver(si2157_driver
);
258 MODULE_DESCRIPTION("Silicon Labs Si2157 silicon tuner driver");
259 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
260 MODULE_LICENSE("GPL");