1 #include "si2157_priv.h"
3 /* execute firmware command */
4 static int si2157_cmd_execute(struct si2157 *s, struct si2157_cmd *cmd)
10 mutex_lock(&s->i2c_mutex);
13 /* write cmd and args for firmware */
14 ret = i2c_master_send(s->client, cmd->args, cmd->len);
16 goto err_mutex_unlock;
17 } else if (ret != cmd->len) {
19 goto err_mutex_unlock;
23 /* wait cmd execution terminate */
25 timeout = jiffies + msecs_to_jiffies(TIMEOUT);
26 while (!time_after(jiffies, timeout)) {
27 ret = i2c_master_recv(s->client, buf, 1);
29 goto err_mutex_unlock;
30 } else if (ret != 1) {
32 goto err_mutex_unlock;
36 if ((buf[0] >> 7) & 0x01)
40 dev_dbg(&s->client->dev, "%s: cmd execution took %d ms\n", __func__,
41 jiffies_to_msecs(jiffies) -
42 (jiffies_to_msecs(timeout) - TIMEOUT));
44 if (!(buf[0] >> 7) & 0x01) {
46 goto err_mutex_unlock;
52 mutex_unlock(&s->i2c_mutex);
58 dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret);
62 static int si2157_init(struct dvb_frontend *fe)
64 struct si2157 *s = fe->tuner_priv;
66 dev_dbg(&s->client->dev, "%s:\n", __func__);
73 static int si2157_sleep(struct dvb_frontend *fe)
75 struct si2157 *s = fe->tuner_priv;
77 dev_dbg(&s->client->dev, "%s:\n", __func__);
84 static int si2157_set_params(struct dvb_frontend *fe)
86 struct si2157 *s = fe->tuner_priv;
87 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
89 struct si2157_cmd cmd;
91 dev_dbg(&s->client->dev,
92 "%s: delivery_system=%d frequency=%u bandwidth_hz=%u\n",
93 __func__, c->delivery_system, c->frequency,
118 ret = si2157_cmd_execute(s, &cmd);
124 ret = si2157_cmd_execute(s, &cmd);
131 ret = si2157_cmd_execute(s, &cmd);
140 cmd.args[4] = (c->frequency >> 0) & 0xff;
141 cmd.args[5] = (c->frequency >> 8) & 0xff;
142 cmd.args[6] = (c->frequency >> 16) & 0xff;
143 cmd.args[7] = (c->frequency >> 24) & 0xff;
145 ret = si2157_cmd_execute(s, &cmd);
151 dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret);
155 static const struct dvb_tuner_ops si2157_tuner_ops = {
157 .name = "Silicon Labs Si2157",
158 .frequency_min = 174000000,
159 .frequency_max = 862000000,
163 .sleep = si2157_sleep,
164 .set_params = si2157_set_params,
167 static int si2157_probe(struct i2c_client *client,
168 const struct i2c_device_id *id)
170 struct si2157_config *cfg = client->dev.platform_data;
171 struct dvb_frontend *fe = cfg->fe;
173 struct si2157_cmd cmd;
176 s = kzalloc(sizeof(struct si2157), GFP_KERNEL);
179 dev_err(&client->dev, "%s: kzalloc() failed\n", KBUILD_MODNAME);
185 mutex_init(&s->i2c_mutex);
187 /* check if the tuner is there */
189 ret = si2157_cmd_execute(s, &cmd);
194 memcpy(&fe->ops.tuner_ops, &si2157_tuner_ops,
195 sizeof(struct dvb_tuner_ops));
197 i2c_set_clientdata(client, s);
199 dev_info(&s->client->dev,
200 "%s: Silicon Labs Si2157 successfully attached\n",
204 dev_dbg(&client->dev, "%s: failed=%d\n", __func__, ret);
210 static int si2157_remove(struct i2c_client *client)
212 struct si2157 *s = i2c_get_clientdata(client);
213 struct dvb_frontend *fe = s->fe;
215 dev_dbg(&client->dev, "%s:\n", __func__);
217 memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops));
218 fe->tuner_priv = NULL;
224 static const struct i2c_device_id si2157_id[] = {
228 MODULE_DEVICE_TABLE(i2c, si2157_id);
230 static struct i2c_driver si2157_driver = {
232 .owner = THIS_MODULE,
235 .probe = si2157_probe,
236 .remove = si2157_remove,
237 .id_table = si2157_id,
240 module_i2c_driver(si2157_driver);
242 MODULE_DESCRIPTION("Silicon Labs Si2157 silicon tuner driver");
243 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
244 MODULE_LICENSE("GPL");