blob: fcf139dfdec6bc99daa3c67be783c0c66da14c09 [file] [log] [blame]
Antti Palosaariba92ae02014-04-14 21:51:32 -03001/*
CrazyCat17ad09f2014-11-14 18:19:37 -03002 * Silicon Labs Si2146/2147/2148/2157/2158 silicon tuner driver
Antti Palosaariba92ae02014-04-14 21:51:32 -03003 *
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
Antti Palosaari930a8732014-04-10 21:58:10 -030017#include "si2157_priv.h"
18
Olli Salonen1b923732014-07-13 10:52:20 -030019static const struct dvb_tuner_ops si2157_ops;
20
Antti Palosaari930a8732014-04-10 21:58:10 -030021/* execute firmware command */
Antti Palosaari8fe51722014-12-06 14:40:06 -030022static int si2157_cmd_execute(struct i2c_client *client, struct si2157_cmd *cmd)
Antti Palosaari930a8732014-04-10 21:58:10 -030023{
Antti Palosaari8fe51722014-12-06 14:40:06 -030024 struct si2157_dev *dev = i2c_get_clientdata(client);
Antti Palosaari930a8732014-04-10 21:58:10 -030025 int ret;
Antti Palosaari930a8732014-04-10 21:58:10 -030026 unsigned long timeout;
27
Antti Palosaari70f13ff2014-12-05 17:46:30 -030028 mutex_lock(&dev->i2c_mutex);
Antti Palosaari930a8732014-04-10 21:58:10 -030029
Antti Palosaarie6b43802014-07-10 06:02:53 -030030 if (cmd->wlen) {
Antti Palosaari930a8732014-04-10 21:58:10 -030031 /* write cmd and args for firmware */
Antti Palosaari8fe51722014-12-06 14:40:06 -030032 ret = i2c_master_send(client, cmd->args, cmd->wlen);
Antti Palosaari930a8732014-04-10 21:58:10 -030033 if (ret < 0) {
34 goto err_mutex_unlock;
Antti Palosaarie6b43802014-07-10 06:02:53 -030035 } else if (ret != cmd->wlen) {
Antti Palosaari930a8732014-04-10 21:58:10 -030036 ret = -EREMOTEIO;
37 goto err_mutex_unlock;
38 }
39 }
40
Antti Palosaarie6b43802014-07-10 06:02:53 -030041 if (cmd->rlen) {
42 /* wait cmd execution terminate */
43 #define TIMEOUT 80
44 timeout = jiffies + msecs_to_jiffies(TIMEOUT);
45 while (!time_after(jiffies, timeout)) {
Antti Palosaari8fe51722014-12-06 14:40:06 -030046 ret = i2c_master_recv(client, cmd->args, cmd->rlen);
Antti Palosaarie6b43802014-07-10 06:02:53 -030047 if (ret < 0) {
48 goto err_mutex_unlock;
49 } else if (ret != cmd->rlen) {
50 ret = -EREMOTEIO;
51 goto err_mutex_unlock;
52 }
53
54 /* firmware ready? */
55 if ((cmd->args[0] >> 7) & 0x01)
56 break;
Antti Palosaari930a8732014-04-10 21:58:10 -030057 }
58
Antti Palosaari8fe51722014-12-06 14:40:06 -030059 dev_dbg(&client->dev, "cmd execution took %d ms\n",
Antti Palosaarie6b43802014-07-10 06:02:53 -030060 jiffies_to_msecs(jiffies) -
61 (jiffies_to_msecs(timeout) - TIMEOUT));
62
63 if (!((cmd->args[0] >> 7) & 0x01)) {
64 ret = -ETIMEDOUT;
65 goto err_mutex_unlock;
66 }
Antti Palosaari930a8732014-04-10 21:58:10 -030067 }
68
Antti Palosaari7cbf5d72014-12-06 14:04:05 -030069 mutex_unlock(&dev->i2c_mutex);
70 return 0;
Antti Palosaari930a8732014-04-10 21:58:10 -030071
72err_mutex_unlock:
Antti Palosaari70f13ff2014-12-05 17:46:30 -030073 mutex_unlock(&dev->i2c_mutex);
Antti Palosaari8fe51722014-12-06 14:40:06 -030074 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaari930a8732014-04-10 21:58:10 -030075 return ret;
76}
77
78static int si2157_init(struct dvb_frontend *fe)
79{
Antti Palosaari8fe51722014-12-06 14:40:06 -030080 struct i2c_client *client = fe->tuner_priv;
81 struct si2157_dev *dev = i2c_get_clientdata(client);
Antti Palosaari7d6bc602014-07-13 20:05:28 -030082 int ret, len, remaining;
Olli Salonenb1541212014-07-13 10:52:19 -030083 struct si2157_cmd cmd;
Antti Palosaari78dab402014-12-06 14:51:17 -030084 const struct firmware *fw;
Antti Palosaari08272db2014-12-06 18:15:18 -030085 const char *fw_name;
Antti Palosaari7d6bc602014-07-13 20:05:28 -030086 unsigned int chip_id;
Antti Palosaari930a8732014-04-10 21:58:10 -030087
Antti Palosaari8fe51722014-12-06 14:40:06 -030088 dev_dbg(&client->dev, "\n");
Antti Palosaari930a8732014-04-10 21:58:10 -030089
Antti Palosaari70f13ff2014-12-05 17:46:30 -030090 if (dev->fw_loaded)
Olli Salonen4cbf6ed2014-08-25 15:07:03 -030091 goto warm;
92
93 /* power up */
Antti Palosaari70f13ff2014-12-05 17:46:30 -030094 if (dev->chiptype == SI2157_CHIPTYPE_SI2146) {
Olli Salonen073f3842014-11-24 03:57:33 -030095 memcpy(cmd.args, "\xc0\x05\x01\x00\x00\x0b\x00\x00\x01", 9);
96 cmd.wlen = 9;
97 } else {
98 memcpy(cmd.args, "\xc0\x00\x0c\x00\x00\x01\x01\x01\x01\x01\x01\x02\x00\x00\x01", 15);
99 cmd.wlen = 15;
100 }
Olli Salonenb1541212014-07-13 10:52:19 -0300101 cmd.rlen = 1;
Antti Palosaari8fe51722014-12-06 14:40:06 -0300102 ret = si2157_cmd_execute(client, &cmd);
Olli Salonenb1541212014-07-13 10:52:19 -0300103 if (ret)
104 goto err;
105
106 /* query chip revision */
107 memcpy(cmd.args, "\x02", 1);
108 cmd.wlen = 1;
109 cmd.rlen = 13;
Antti Palosaari8fe51722014-12-06 14:40:06 -0300110 ret = si2157_cmd_execute(client, &cmd);
Olli Salonenb1541212014-07-13 10:52:19 -0300111 if (ret)
112 goto err;
113
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300114 chip_id = cmd.args[1] << 24 | cmd.args[2] << 16 | cmd.args[3] << 8 |
115 cmd.args[4] << 0;
Olli Salonen1b923732014-07-13 10:52:20 -0300116
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300117 #define SI2158_A20 ('A' << 24 | 58 << 16 | '2' << 8 | '0' << 0)
CrazyCat17ad09f2014-11-14 18:19:37 -0300118 #define SI2148_A20 ('A' << 24 | 48 << 16 | '2' << 8 | '0' << 0)
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300119 #define SI2157_A30 ('A' << 24 | 57 << 16 | '3' << 8 | '0' << 0)
Olli Salonend87a5052014-09-11 17:01:38 -0300120 #define SI2147_A30 ('A' << 24 | 47 << 16 | '3' << 8 | '0' << 0)
Olli Salonen073f3842014-11-24 03:57:33 -0300121 #define SI2146_A10 ('A' << 24 | 46 << 16 | '1' << 8 | '0' << 0)
Olli Salonen1b923732014-07-13 10:52:20 -0300122
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300123 switch (chip_id) {
124 case SI2158_A20:
CrazyCat17ad09f2014-11-14 18:19:37 -0300125 case SI2148_A20:
Antti Palosaari08272db2014-12-06 18:15:18 -0300126 fw_name = SI2158_A20_FIRMWARE;
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300127 break;
128 case SI2157_A30:
Olli Salonend87a5052014-09-11 17:01:38 -0300129 case SI2147_A30:
Olli Salonen073f3842014-11-24 03:57:33 -0300130 case SI2146_A10:
Antti Palosaari08272db2014-12-06 18:15:18 -0300131 fw_name = NULL;
Antti Palosaari6c372532014-12-06 18:12:39 -0300132 break;
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300133 default:
Antti Palosaari8fe51722014-12-06 14:40:06 -0300134 dev_err(&client->dev, "unknown chip version Si21%d-%c%c%c\n",
Olli Salonen67d01132014-08-05 09:03:54 -0300135 cmd.args[2], cmd.args[1],
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300136 cmd.args[3], cmd.args[4]);
137 ret = -EINVAL;
138 goto err;
Olli Salonen1b923732014-07-13 10:52:20 -0300139 }
140
Antti Palosaari6c372532014-12-06 18:12:39 -0300141 dev_info(&client->dev, "found a 'Silicon Labs Si21%d-%c%c%c'\n",
142 cmd.args[2], cmd.args[1], cmd.args[3], cmd.args[4]);
143
Antti Palosaari08272db2014-12-06 18:15:18 -0300144 if (fw_name == NULL)
Antti Palosaari6c372532014-12-06 18:12:39 -0300145 goto skip_fw_download;
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300146
147 /* request the firmware, this will block and timeout */
Antti Palosaari08272db2014-12-06 18:15:18 -0300148 ret = request_firmware(&fw, fw_name, &client->dev);
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300149 if (ret) {
Antti Palosaari8fe51722014-12-06 14:40:06 -0300150 dev_err(&client->dev, "firmware file '%s' not found\n",
Antti Palosaari08272db2014-12-06 18:15:18 -0300151 fw_name);
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300152 goto err;
153 }
154
155 /* firmware should be n chunks of 17 bytes */
156 if (fw->size % 17 != 0) {
Antti Palosaari8fe51722014-12-06 14:40:06 -0300157 dev_err(&client->dev, "firmware file '%s' is invalid\n",
Antti Palosaari08272db2014-12-06 18:15:18 -0300158 fw_name);
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300159 ret = -EINVAL;
Antti Palosaari78dab402014-12-06 14:51:17 -0300160 goto err_release_firmware;
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300161 }
162
Antti Palosaari8fe51722014-12-06 14:40:06 -0300163 dev_info(&client->dev, "downloading firmware from file '%s'\n",
Antti Palosaari08272db2014-12-06 18:15:18 -0300164 fw_name);
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300165
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);
169 cmd.wlen = len;
170 cmd.rlen = 1;
Antti Palosaari8fe51722014-12-06 14:40:06 -0300171 ret = si2157_cmd_execute(client, &cmd);
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300172 if (ret) {
Antti Palosaari8fe51722014-12-06 14:40:06 -0300173 dev_err(&client->dev, "firmware download failed %d\n",
Olli Salonen67d01132014-08-05 09:03:54 -0300174 ret);
Antti Palosaari78dab402014-12-06 14:51:17 -0300175 goto err_release_firmware;
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300176 }
177 }
178
179 release_firmware(fw);
Antti Palosaari7d6bc602014-07-13 20:05:28 -0300180
181skip_fw_download:
Olli Salonenb1541212014-07-13 10:52:19 -0300182 /* reboot the tuner with new firmware? */
183 memcpy(cmd.args, "\x01\x01", 2);
184 cmd.wlen = 2;
185 cmd.rlen = 1;
Antti Palosaari8fe51722014-12-06 14:40:06 -0300186 ret = si2157_cmd_execute(client, &cmd);
Olli Salonenb1541212014-07-13 10:52:19 -0300187 if (ret)
188 goto err;
189
Antti Palosaaric7011842014-12-06 17:25:24 -0300190 /* query firmware version */
191 memcpy(cmd.args, "\x11", 1);
192 cmd.wlen = 1;
193 cmd.rlen = 10;
194 ret = si2157_cmd_execute(client, &cmd);
195 if (ret)
196 goto err;
197
198 dev_info(&client->dev, "firmware version: %c.%c.%d\n",
199 cmd.args[6], cmd.args[7], cmd.args[8]);
200
Antti Palosaari70f13ff2014-12-05 17:46:30 -0300201 dev->fw_loaded = true;
Antti Palosaari930a8732014-04-10 21:58:10 -0300202
Olli Salonen4cbf6ed2014-08-25 15:07:03 -0300203warm:
Antti Palosaari70f13ff2014-12-05 17:46:30 -0300204 dev->active = true;
Antti Palosaari930a8732014-04-10 21:58:10 -0300205 return 0;
Olli Salonen4cbf6ed2014-08-25 15:07:03 -0300206
Antti Palosaari78dab402014-12-06 14:51:17 -0300207err_release_firmware:
Markus Elfringdc89cfc2014-11-30 15:05:48 -0300208 release_firmware(fw);
Markus Elfringe358c8a2014-11-30 16:48:24 -0300209err:
Antti Palosaari8fe51722014-12-06 14:40:06 -0300210 dev_dbg(&client->dev, "failed=%d\n", ret);
Olli Salonenb1541212014-07-13 10:52:19 -0300211 return ret;
Antti Palosaari930a8732014-04-10 21:58:10 -0300212}
213
214static int si2157_sleep(struct dvb_frontend *fe)
215{
Antti Palosaari8fe51722014-12-06 14:40:06 -0300216 struct i2c_client *client = fe->tuner_priv;
217 struct si2157_dev *dev = i2c_get_clientdata(client);
Antti Palosaaria83d7d12014-07-09 18:37:30 -0300218 int ret;
219 struct si2157_cmd cmd;
Antti Palosaari930a8732014-04-10 21:58:10 -0300220
Antti Palosaari8fe51722014-12-06 14:40:06 -0300221 dev_dbg(&client->dev, "\n");
Antti Palosaari930a8732014-04-10 21:58:10 -0300222
Antti Palosaari70f13ff2014-12-05 17:46:30 -0300223 dev->active = false;
Antti Palosaari930a8732014-04-10 21:58:10 -0300224
Olli Salonen0e382332014-08-25 15:07:02 -0300225 /* standby */
226 memcpy(cmd.args, "\x16\x00", 2);
227 cmd.wlen = 2;
228 cmd.rlen = 1;
Antti Palosaari8fe51722014-12-06 14:40:06 -0300229 ret = si2157_cmd_execute(client, &cmd);
Antti Palosaaria83d7d12014-07-09 18:37:30 -0300230 if (ret)
231 goto err;
232
Antti Palosaari930a8732014-04-10 21:58:10 -0300233 return 0;
Antti Palosaaria83d7d12014-07-09 18:37:30 -0300234err:
Antti Palosaari8fe51722014-12-06 14:40:06 -0300235 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaaria83d7d12014-07-09 18:37:30 -0300236 return ret;
Antti Palosaari930a8732014-04-10 21:58:10 -0300237}
238
239static int si2157_set_params(struct dvb_frontend *fe)
240{
Antti Palosaari8fe51722014-12-06 14:40:06 -0300241 struct i2c_client *client = fe->tuner_priv;
242 struct si2157_dev *dev = i2c_get_clientdata(client);
Antti Palosaari930a8732014-04-10 21:58:10 -0300243 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
244 int ret;
245 struct si2157_cmd cmd;
Olli Salonena1dad502014-07-13 10:52:21 -0300246 u8 bandwidth, delivery_system;
Antti Palosaari930a8732014-04-10 21:58:10 -0300247
Antti Palosaari8fe51722014-12-06 14:40:06 -0300248 dev_dbg(&client->dev,
Olli Salonen67d01132014-08-05 09:03:54 -0300249 "delivery_system=%d frequency=%u bandwidth_hz=%u\n",
Antti Palosaari8fe51722014-12-06 14:40:06 -0300250 c->delivery_system, c->frequency, c->bandwidth_hz);
Antti Palosaari930a8732014-04-10 21:58:10 -0300251
Antti Palosaari70f13ff2014-12-05 17:46:30 -0300252 if (!dev->active) {
Antti Palosaari930a8732014-04-10 21:58:10 -0300253 ret = -EAGAIN;
254 goto err;
255 }
256
Olli Salonena1dad502014-07-13 10:52:21 -0300257 if (c->bandwidth_hz <= 6000000)
258 bandwidth = 0x06;
259 else if (c->bandwidth_hz <= 7000000)
260 bandwidth = 0x07;
261 else if (c->bandwidth_hz <= 8000000)
262 bandwidth = 0x08;
263 else
264 bandwidth = 0x0f;
265
266 switch (c->delivery_system) {
Olli Salonen5cd62db2014-08-17 02:24:49 -0300267 case SYS_ATSC:
268 delivery_system = 0x00;
269 break;
Olli Salonen0d1165f2014-10-30 07:43:16 -0300270 case SYS_DVBC_ANNEX_B:
271 delivery_system = 0x10;
272 break;
Olli Salonena1dad502014-07-13 10:52:21 -0300273 case SYS_DVBT:
274 case SYS_DVBT2: /* it seems DVB-T and DVB-T2 both are 0x20 here */
275 delivery_system = 0x20;
276 break;
277 case SYS_DVBC_ANNEX_A:
278 delivery_system = 0x30;
279 break;
280 default:
281 ret = -EINVAL;
282 goto err;
283 }
284
285 memcpy(cmd.args, "\x14\x00\x03\x07\x00\x00", 6);
286 cmd.args[4] = delivery_system | bandwidth;
Antti Palosaari70f13ff2014-12-05 17:46:30 -0300287 if (dev->inversion)
Matthias Schwarzott05024ef2014-07-15 16:34:36 -0300288 cmd.args[5] = 0x01;
Olli Salonena1dad502014-07-13 10:52:21 -0300289 cmd.wlen = 6;
Olli Salonend87a5052014-09-11 17:01:38 -0300290 cmd.rlen = 4;
Antti Palosaari8fe51722014-12-06 14:40:06 -0300291 ret = si2157_cmd_execute(client, &cmd);
Olli Salonend87a5052014-09-11 17:01:38 -0300292 if (ret)
293 goto err;
294
Antti Palosaari70f13ff2014-12-05 17:46:30 -0300295 if (dev->chiptype == SI2157_CHIPTYPE_SI2146)
Olli Salonen073f3842014-11-24 03:57:33 -0300296 memcpy(cmd.args, "\x14\x00\x02\x07\x00\x01", 6);
297 else
298 memcpy(cmd.args, "\x14\x00\x02\x07\x01\x00", 6);
Olli Salonend87a5052014-09-11 17:01:38 -0300299 cmd.wlen = 6;
300 cmd.rlen = 4;
Antti Palosaari8fe51722014-12-06 14:40:06 -0300301 ret = si2157_cmd_execute(client, &cmd);
Olli Salonena1dad502014-07-13 10:52:21 -0300302 if (ret)
303 goto err;
304
Antti Palosaari930a8732014-04-10 21:58:10 -0300305 /* set frequency */
Olli Salonenb1541212014-07-13 10:52:19 -0300306 memcpy(cmd.args, "\x41\x00\x00\x00\x00\x00\x00\x00", 8);
Antti Palosaari930a8732014-04-10 21:58:10 -0300307 cmd.args[4] = (c->frequency >> 0) & 0xff;
308 cmd.args[5] = (c->frequency >> 8) & 0xff;
309 cmd.args[6] = (c->frequency >> 16) & 0xff;
310 cmd.args[7] = (c->frequency >> 24) & 0xff;
Antti Palosaarie6b43802014-07-10 06:02:53 -0300311 cmd.wlen = 8;
312 cmd.rlen = 1;
Antti Palosaari8fe51722014-12-06 14:40:06 -0300313 ret = si2157_cmd_execute(client, &cmd);
Antti Palosaari930a8732014-04-10 21:58:10 -0300314 if (ret)
315 goto err;
316
317 return 0;
318err:
Antti Palosaari8fe51722014-12-06 14:40:06 -0300319 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaari930a8732014-04-10 21:58:10 -0300320 return ret;
321}
322
Matthias Schwarzott11405402014-07-15 04:58:40 -0300323static int si2157_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
324{
325 *frequency = 5000000; /* default value of property 0x0706 */
326 return 0;
327}
328
Olli Salonen6cc8a352014-07-18 02:41:12 -0300329static const struct dvb_tuner_ops si2157_ops = {
Antti Palosaari930a8732014-04-10 21:58:10 -0300330 .info = {
CrazyCat17ad09f2014-11-14 18:19:37 -0300331 .name = "Silicon Labs Si2146/2147/2148/2157/2158",
Antti Palosaariae4c8912014-04-12 01:53:51 -0300332 .frequency_min = 110000000,
Antti Palosaari930a8732014-04-10 21:58:10 -0300333 .frequency_max = 862000000,
334 },
335
336 .init = si2157_init,
337 .sleep = si2157_sleep,
338 .set_params = si2157_set_params,
Matthias Schwarzott11405402014-07-15 04:58:40 -0300339 .get_if_frequency = si2157_get_if_frequency,
Antti Palosaari930a8732014-04-10 21:58:10 -0300340};
341
342static int si2157_probe(struct i2c_client *client,
343 const struct i2c_device_id *id)
344{
345 struct si2157_config *cfg = client->dev.platform_data;
346 struct dvb_frontend *fe = cfg->fe;
Antti Palosaari70f13ff2014-12-05 17:46:30 -0300347 struct si2157_dev *dev;
Antti Palosaari930a8732014-04-10 21:58:10 -0300348 struct si2157_cmd cmd;
349 int ret;
350
Antti Palosaari70f13ff2014-12-05 17:46:30 -0300351 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
352 if (!dev) {
Antti Palosaari930a8732014-04-10 21:58:10 -0300353 ret = -ENOMEM;
Olli Salonen67d01132014-08-05 09:03:54 -0300354 dev_err(&client->dev, "kzalloc() failed\n");
Antti Palosaari930a8732014-04-10 21:58:10 -0300355 goto err;
356 }
357
Antti Palosaari8fe51722014-12-06 14:40:06 -0300358 i2c_set_clientdata(client, dev);
Antti Palosaari70f13ff2014-12-05 17:46:30 -0300359 dev->fe = cfg->fe;
360 dev->inversion = cfg->inversion;
361 dev->fw_loaded = false;
362 dev->chiptype = (u8)id->driver_data;
363 mutex_init(&dev->i2c_mutex);
Antti Palosaari930a8732014-04-10 21:58:10 -0300364
365 /* check if the tuner is there */
Antti Palosaarie6b43802014-07-10 06:02:53 -0300366 cmd.wlen = 0;
367 cmd.rlen = 1;
Antti Palosaari8fe51722014-12-06 14:40:06 -0300368 ret = si2157_cmd_execute(client, &cmd);
Antti Palosaari930a8732014-04-10 21:58:10 -0300369 if (ret)
Antti Palosaarie7f3f9f32014-12-06 15:13:31 -0300370 goto err_kfree;
Antti Palosaari930a8732014-04-10 21:58:10 -0300371
Antti Palosaari70f13ff2014-12-05 17:46:30 -0300372 memcpy(&fe->ops.tuner_ops, &si2157_ops, sizeof(struct dvb_tuner_ops));
Antti Palosaari8fe51722014-12-06 14:40:06 -0300373 fe->tuner_priv = client;
Antti Palosaari930a8732014-04-10 21:58:10 -0300374
Antti Palosaari8fe51722014-12-06 14:40:06 -0300375 dev_info(&client->dev, "Silicon Labs %s successfully attached\n",
Antti Palosaari70f13ff2014-12-05 17:46:30 -0300376 dev->chiptype == SI2157_CHIPTYPE_SI2146 ?
CrazyCat17ad09f2014-11-14 18:19:37 -0300377 "Si2146" : "Si2147/2148/2157/2158");
Olli Salonen073f3842014-11-24 03:57:33 -0300378
Antti Palosaari930a8732014-04-10 21:58:10 -0300379 return 0;
Antti Palosaarie7f3f9f32014-12-06 15:13:31 -0300380
381err_kfree:
382 kfree(dev);
Antti Palosaari930a8732014-04-10 21:58:10 -0300383err:
Olli Salonen67d01132014-08-05 09:03:54 -0300384 dev_dbg(&client->dev, "failed=%d\n", ret);
Antti Palosaari930a8732014-04-10 21:58:10 -0300385 return ret;
386}
387
388static int si2157_remove(struct i2c_client *client)
389{
Antti Palosaari70f13ff2014-12-05 17:46:30 -0300390 struct si2157_dev *dev = i2c_get_clientdata(client);
391 struct dvb_frontend *fe = dev->fe;
Antti Palosaari930a8732014-04-10 21:58:10 -0300392
Olli Salonen67d01132014-08-05 09:03:54 -0300393 dev_dbg(&client->dev, "\n");
Antti Palosaari930a8732014-04-10 21:58:10 -0300394
395 memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops));
396 fe->tuner_priv = NULL;
Antti Palosaari70f13ff2014-12-05 17:46:30 -0300397 kfree(dev);
Antti Palosaari930a8732014-04-10 21:58:10 -0300398
399 return 0;
400}
401
Antti Palosaaric1292232014-12-06 15:07:45 -0300402static const struct i2c_device_id si2157_id_table[] = {
403 {"si2157", SI2157_CHIPTYPE_SI2157},
404 {"si2146", SI2157_CHIPTYPE_SI2146},
Antti Palosaari930a8732014-04-10 21:58:10 -0300405 {}
406};
Antti Palosaaric1292232014-12-06 15:07:45 -0300407MODULE_DEVICE_TABLE(i2c, si2157_id_table);
Antti Palosaari930a8732014-04-10 21:58:10 -0300408
409static struct i2c_driver si2157_driver = {
410 .driver = {
411 .owner = THIS_MODULE,
412 .name = "si2157",
413 },
414 .probe = si2157_probe,
415 .remove = si2157_remove,
Antti Palosaaric1292232014-12-06 15:07:45 -0300416 .id_table = si2157_id_table,
Antti Palosaari930a8732014-04-10 21:58:10 -0300417};
418
419module_i2c_driver(si2157_driver);
420
CrazyCat17ad09f2014-11-14 18:19:37 -0300421MODULE_DESCRIPTION("Silicon Labs Si2146/2147/2148/2157/2158 silicon tuner driver");
Antti Palosaari930a8732014-04-10 21:58:10 -0300422MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
423MODULE_LICENSE("GPL");
Antti Palosaaribac53a22014-07-13 16:13:49 -0300424MODULE_FIRMWARE(SI2158_A20_FIRMWARE);