aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/tuners
diff options
context:
space:
mode:
authorAntti Palosaari <crope@iki.fi>2014-07-10 05:02:53 -0400
committerMauro Carvalho Chehab <m.chehab@samsung.com>2014-07-14 20:07:02 -0400
commite6b4380f3ef89601b1a77c327fe3aa7b5500b3f4 (patch)
tree533a456cffbf421c414d4a78c2df5131843fed6d /drivers/media/tuners
parent88ac8f860640f28ae6fae43ca690adc3f7294b90 (diff)
[media] si2157: add read data support for fw cmd func
We want also read data from firmware. Add support for it. Copied from si2168 driver. Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media/tuners')
-rw-r--r--drivers/media/tuners/si2157.c74
-rw-r--r--drivers/media/tuners/si2157_priv.h3
2 files changed, 43 insertions, 34 deletions
diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c
index 3f88e5365850..a4908ee81ab9 100644
--- a/drivers/media/tuners/si2157.c
+++ b/drivers/media/tuners/si2157.c
@@ -20,50 +20,52 @@
20static int si2157_cmd_execute(struct si2157 *s, struct si2157_cmd *cmd) 20static int si2157_cmd_execute(struct si2157 *s, struct si2157_cmd *cmd)
21{ 21{
22 int ret; 22 int ret;
23 u8 buf[1];
24 unsigned long timeout; 23 unsigned long timeout;
25 24
26 mutex_lock(&s->i2c_mutex); 25 mutex_lock(&s->i2c_mutex);
27 26
28 if (cmd->len) { 27 if (cmd->wlen) {
29 /* write cmd and args for firmware */ 28 /* write cmd and args for firmware */
30 ret = i2c_master_send(s->client, cmd->args, cmd->len); 29 ret = i2c_master_send(s->client, cmd->args, cmd->wlen);
31 if (ret < 0) { 30 if (ret < 0) {
32 goto err_mutex_unlock; 31 goto err_mutex_unlock;
33 } else if (ret != cmd->len) { 32 } else if (ret != cmd->wlen) {
34 ret = -EREMOTEIO; 33 ret = -EREMOTEIO;
35 goto err_mutex_unlock; 34 goto err_mutex_unlock;
36 } 35 }
37 } 36 }
38 37
39 /* wait cmd execution terminate */ 38 if (cmd->rlen) {
40 #define TIMEOUT 80 39 /* wait cmd execution terminate */
41 timeout = jiffies + msecs_to_jiffies(TIMEOUT); 40 #define TIMEOUT 80
42 while (!time_after(jiffies, timeout)) { 41 timeout = jiffies + msecs_to_jiffies(TIMEOUT);
43 ret = i2c_master_recv(s->client, buf, 1); 42 while (!time_after(jiffies, timeout)) {
44 if (ret < 0) { 43 ret = i2c_master_recv(s->client, cmd->args, cmd->rlen);
45 goto err_mutex_unlock; 44 if (ret < 0) {
46 } else if (ret != 1) { 45 goto err_mutex_unlock;
47 ret = -EREMOTEIO; 46 } else if (ret != cmd->rlen) {
48 goto err_mutex_unlock; 47 ret = -EREMOTEIO;
48 goto err_mutex_unlock;
49 }
50
51 /* firmware ready? */
52 if ((cmd->args[0] >> 7) & 0x01)
53 break;
49 } 54 }
50 55
51 /* firmware ready? */ 56 dev_dbg(&s->client->dev, "%s: cmd execution took %d ms\n",
52 if ((buf[0] >> 7) & 0x01) 57 __func__,
53 break; 58 jiffies_to_msecs(jiffies) -
54 } 59 (jiffies_to_msecs(timeout) - TIMEOUT));
55 60
56 dev_dbg(&s->client->dev, "%s: cmd execution took %d ms\n", __func__, 61 if (!((cmd->args[0] >> 7) & 0x01)) {
57 jiffies_to_msecs(jiffies) - 62 ret = -ETIMEDOUT;
58 (jiffies_to_msecs(timeout) - TIMEOUT)); 63 goto err_mutex_unlock;
59 64 }
60 if (!(buf[0] >> 7) & 0x01) {
61 ret = -ETIMEDOUT;
62 goto err_mutex_unlock;
63 } else {
64 ret = 0;
65 } 65 }
66 66
67 ret = 0;
68
67err_mutex_unlock: 69err_mutex_unlock:
68 mutex_unlock(&s->i2c_mutex); 70 mutex_unlock(&s->i2c_mutex);
69 if (ret) 71 if (ret)
@@ -97,7 +99,8 @@ static int si2157_sleep(struct dvb_frontend *fe)
97 s->active = false; 99 s->active = false;
98 100
99 memcpy(cmd.args, "\x13", 1); 101 memcpy(cmd.args, "\x13", 1);
100 cmd.len = 1; 102 cmd.wlen = 1;
103 cmd.rlen = 0;
101 ret = si2157_cmd_execute(s, &cmd); 104 ret = si2157_cmd_execute(s, &cmd);
102 if (ret) 105 if (ret)
103 goto err; 106 goto err;
@@ -141,20 +144,23 @@ static int si2157_set_params(struct dvb_frontend *fe)
141 cmd.args[12] = 0x00; 144 cmd.args[12] = 0x00;
142 cmd.args[13] = 0x00; 145 cmd.args[13] = 0x00;
143 cmd.args[14] = 0x01; 146 cmd.args[14] = 0x01;
144 cmd.len = 15; 147 cmd.wlen = 15;
148 cmd.rlen = 1;
145 ret = si2157_cmd_execute(s, &cmd); 149 ret = si2157_cmd_execute(s, &cmd);
146 if (ret) 150 if (ret)
147 goto err; 151 goto err;
148 152
149 cmd.args[0] = 0x02; 153 cmd.args[0] = 0x02;
150 cmd.len = 1; 154 cmd.wlen = 1;
155 cmd.rlen = 13;
151 ret = si2157_cmd_execute(s, &cmd); 156 ret = si2157_cmd_execute(s, &cmd);
152 if (ret) 157 if (ret)
153 goto err; 158 goto err;
154 159
155 cmd.args[0] = 0x01; 160 cmd.args[0] = 0x01;
156 cmd.args[1] = 0x01; 161 cmd.args[1] = 0x01;
157 cmd.len = 2; 162 cmd.wlen = 2;
163 cmd.rlen = 1;
158 ret = si2157_cmd_execute(s, &cmd); 164 ret = si2157_cmd_execute(s, &cmd);
159 if (ret) 165 if (ret)
160 goto err; 166 goto err;
@@ -168,7 +174,8 @@ static int si2157_set_params(struct dvb_frontend *fe)
168 cmd.args[5] = (c->frequency >> 8) & 0xff; 174 cmd.args[5] = (c->frequency >> 8) & 0xff;
169 cmd.args[6] = (c->frequency >> 16) & 0xff; 175 cmd.args[6] = (c->frequency >> 16) & 0xff;
170 cmd.args[7] = (c->frequency >> 24) & 0xff; 176 cmd.args[7] = (c->frequency >> 24) & 0xff;
171 cmd.len = 8; 177 cmd.wlen = 8;
178 cmd.rlen = 1;
172 ret = si2157_cmd_execute(s, &cmd); 179 ret = si2157_cmd_execute(s, &cmd);
173 if (ret) 180 if (ret)
174 goto err; 181 goto err;
@@ -212,7 +219,8 @@ static int si2157_probe(struct i2c_client *client,
212 mutex_init(&s->i2c_mutex); 219 mutex_init(&s->i2c_mutex);
213 220
214 /* check if the tuner is there */ 221 /* check if the tuner is there */
215 cmd.len = 0; 222 cmd.wlen = 0;
223 cmd.rlen = 1;
216 ret = si2157_cmd_execute(s, &cmd); 224 ret = si2157_cmd_execute(s, &cmd);
217 if (ret) 225 if (ret)
218 goto err; 226 goto err;
diff --git a/drivers/media/tuners/si2157_priv.h b/drivers/media/tuners/si2157_priv.h
index 6cc6c6fdab7a..6db4c97c26a7 100644
--- a/drivers/media/tuners/si2157_priv.h
+++ b/drivers/media/tuners/si2157_priv.h
@@ -31,7 +31,8 @@ struct si2157 {
31#define SI2157_ARGLEN 30 31#define SI2157_ARGLEN 30
32struct si2157_cmd { 32struct si2157_cmd {
33 u8 args[SI2157_ARGLEN]; 33 u8 args[SI2157_ARGLEN];
34 unsigned len; 34 unsigned wlen;
35 unsigned rlen;
35}; 36};
36 37
37#endif 38#endif