Antti Palosaari | ba92ae0 | 2014-04-14 21:51:32 -0300 | [diff] [blame] | 1 | /* |
Olli Salonen | 1b92373 | 2014-07-13 10:52:20 -0300 | [diff] [blame] | 2 | * Silicon Labs Si2157/2158 silicon tuner driver |
Antti Palosaari | ba92ae0 | 2014-04-14 21:51:32 -0300 | [diff] [blame] | 3 | * |
| 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 Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 17 | #include "si2157_priv.h" |
| 18 | |
Olli Salonen | 1b92373 | 2014-07-13 10:52:20 -0300 | [diff] [blame] | 19 | static const struct dvb_tuner_ops si2157_ops; |
| 20 | |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 21 | /* execute firmware command */ |
| 22 | static int si2157_cmd_execute(struct si2157 *s, struct si2157_cmd *cmd) |
| 23 | { |
| 24 | int ret; |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 25 | unsigned long timeout; |
| 26 | |
| 27 | mutex_lock(&s->i2c_mutex); |
| 28 | |
Antti Palosaari | e6b4380 | 2014-07-10 06:02:53 -0300 | [diff] [blame] | 29 | if (cmd->wlen) { |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 30 | /* write cmd and args for firmware */ |
Antti Palosaari | e6b4380 | 2014-07-10 06:02:53 -0300 | [diff] [blame] | 31 | ret = i2c_master_send(s->client, cmd->args, cmd->wlen); |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 32 | if (ret < 0) { |
| 33 | goto err_mutex_unlock; |
Antti Palosaari | e6b4380 | 2014-07-10 06:02:53 -0300 | [diff] [blame] | 34 | } else if (ret != cmd->wlen) { |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 35 | ret = -EREMOTEIO; |
| 36 | goto err_mutex_unlock; |
| 37 | } |
| 38 | } |
| 39 | |
Antti Palosaari | e6b4380 | 2014-07-10 06:02:53 -0300 | [diff] [blame] | 40 | if (cmd->rlen) { |
| 41 | /* wait cmd execution terminate */ |
| 42 | #define TIMEOUT 80 |
| 43 | timeout = jiffies + msecs_to_jiffies(TIMEOUT); |
| 44 | while (!time_after(jiffies, timeout)) { |
| 45 | ret = i2c_master_recv(s->client, cmd->args, cmd->rlen); |
| 46 | if (ret < 0) { |
| 47 | goto err_mutex_unlock; |
| 48 | } else if (ret != cmd->rlen) { |
| 49 | ret = -EREMOTEIO; |
| 50 | goto err_mutex_unlock; |
| 51 | } |
| 52 | |
| 53 | /* firmware ready? */ |
| 54 | if ((cmd->args[0] >> 7) & 0x01) |
| 55 | break; |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 56 | } |
| 57 | |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 58 | dev_dbg(&s->client->dev, "cmd execution took %d ms\n", |
Antti Palosaari | e6b4380 | 2014-07-10 06:02:53 -0300 | [diff] [blame] | 59 | jiffies_to_msecs(jiffies) - |
| 60 | (jiffies_to_msecs(timeout) - TIMEOUT)); |
| 61 | |
| 62 | if (!((cmd->args[0] >> 7) & 0x01)) { |
| 63 | ret = -ETIMEDOUT; |
| 64 | goto err_mutex_unlock; |
| 65 | } |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 66 | } |
| 67 | |
Antti Palosaari | e6b4380 | 2014-07-10 06:02:53 -0300 | [diff] [blame] | 68 | ret = 0; |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 69 | |
| 70 | err_mutex_unlock: |
| 71 | mutex_unlock(&s->i2c_mutex); |
| 72 | if (ret) |
| 73 | goto err; |
| 74 | |
| 75 | return 0; |
| 76 | err: |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 77 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 78 | return ret; |
| 79 | } |
| 80 | |
| 81 | static int si2157_init(struct dvb_frontend *fe) |
| 82 | { |
| 83 | struct si2157 *s = fe->tuner_priv; |
Antti Palosaari | 7d6bc60 | 2014-07-13 20:05:28 -0300 | [diff] [blame] | 84 | int ret, len, remaining; |
Olli Salonen | b154121 | 2014-07-13 10:52:19 -0300 | [diff] [blame] | 85 | struct si2157_cmd cmd; |
Olli Salonen | 1b92373 | 2014-07-13 10:52:20 -0300 | [diff] [blame] | 86 | const struct firmware *fw = NULL; |
| 87 | u8 *fw_file; |
Antti Palosaari | 7d6bc60 | 2014-07-13 20:05:28 -0300 | [diff] [blame] | 88 | unsigned int chip_id; |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 89 | |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 90 | dev_dbg(&s->client->dev, "\n"); |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 91 | |
Olli Salonen | b154121 | 2014-07-13 10:52:19 -0300 | [diff] [blame] | 92 | /* configure? */ |
| 93 | memcpy(cmd.args, "\xc0\x00\x0c\x00\x00\x01\x01\x01\x01\x01\x01\x02\x00\x00\x01", 15); |
| 94 | cmd.wlen = 15; |
| 95 | cmd.rlen = 1; |
| 96 | ret = si2157_cmd_execute(s, &cmd); |
| 97 | if (ret) |
| 98 | goto err; |
| 99 | |
| 100 | /* query chip revision */ |
| 101 | memcpy(cmd.args, "\x02", 1); |
| 102 | cmd.wlen = 1; |
| 103 | cmd.rlen = 13; |
| 104 | ret = si2157_cmd_execute(s, &cmd); |
| 105 | if (ret) |
| 106 | goto err; |
| 107 | |
Antti Palosaari | 7d6bc60 | 2014-07-13 20:05:28 -0300 | [diff] [blame] | 108 | chip_id = cmd.args[1] << 24 | cmd.args[2] << 16 | cmd.args[3] << 8 | |
| 109 | cmd.args[4] << 0; |
Olli Salonen | 1b92373 | 2014-07-13 10:52:20 -0300 | [diff] [blame] | 110 | |
Antti Palosaari | 7d6bc60 | 2014-07-13 20:05:28 -0300 | [diff] [blame] | 111 | #define SI2158_A20 ('A' << 24 | 58 << 16 | '2' << 8 | '0' << 0) |
| 112 | #define SI2157_A30 ('A' << 24 | 57 << 16 | '3' << 8 | '0' << 0) |
Olli Salonen | 1b92373 | 2014-07-13 10:52:20 -0300 | [diff] [blame] | 113 | |
Antti Palosaari | 7d6bc60 | 2014-07-13 20:05:28 -0300 | [diff] [blame] | 114 | switch (chip_id) { |
| 115 | case SI2158_A20: |
| 116 | fw_file = SI2158_A20_FIRMWARE; |
| 117 | break; |
| 118 | case SI2157_A30: |
| 119 | goto skip_fw_download; |
| 120 | break; |
| 121 | default: |
| 122 | dev_err(&s->client->dev, |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 123 | "unknown chip version Si21%d-%c%c%c\n", |
| 124 | cmd.args[2], cmd.args[1], |
Antti Palosaari | 7d6bc60 | 2014-07-13 20:05:28 -0300 | [diff] [blame] | 125 | cmd.args[3], cmd.args[4]); |
| 126 | ret = -EINVAL; |
| 127 | goto err; |
Olli Salonen | 1b92373 | 2014-07-13 10:52:20 -0300 | [diff] [blame] | 128 | } |
| 129 | |
Antti Palosaari | 7d6bc60 | 2014-07-13 20:05:28 -0300 | [diff] [blame] | 130 | /* cold state - try to download firmware */ |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 131 | dev_info(&s->client->dev, "found a '%s' in cold state\n", |
| 132 | si2157_ops.info.name); |
Antti Palosaari | 7d6bc60 | 2014-07-13 20:05:28 -0300 | [diff] [blame] | 133 | |
| 134 | /* request the firmware, this will block and timeout */ |
| 135 | ret = request_firmware(&fw, fw_file, &s->client->dev); |
| 136 | if (ret) { |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 137 | dev_err(&s->client->dev, "firmware file '%s' not found\n", |
| 138 | fw_file); |
Antti Palosaari | 7d6bc60 | 2014-07-13 20:05:28 -0300 | [diff] [blame] | 139 | goto err; |
| 140 | } |
| 141 | |
| 142 | /* firmware should be n chunks of 17 bytes */ |
| 143 | if (fw->size % 17 != 0) { |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 144 | dev_err(&s->client->dev, "firmware file '%s' is invalid\n", |
| 145 | fw_file); |
Antti Palosaari | 7d6bc60 | 2014-07-13 20:05:28 -0300 | [diff] [blame] | 146 | ret = -EINVAL; |
| 147 | goto err; |
| 148 | } |
| 149 | |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 150 | dev_info(&s->client->dev, "downloading firmware from file '%s'\n", |
| 151 | fw_file); |
Antti Palosaari | 7d6bc60 | 2014-07-13 20:05:28 -0300 | [diff] [blame] | 152 | |
| 153 | for (remaining = fw->size; remaining > 0; remaining -= 17) { |
| 154 | len = fw->data[fw->size - remaining]; |
| 155 | memcpy(cmd.args, &fw->data[(fw->size - remaining) + 1], len); |
| 156 | cmd.wlen = len; |
| 157 | cmd.rlen = 1; |
| 158 | ret = si2157_cmd_execute(s, &cmd); |
| 159 | if (ret) { |
| 160 | dev_err(&s->client->dev, |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 161 | "firmware download failed=%d\n", |
| 162 | ret); |
Antti Palosaari | 7d6bc60 | 2014-07-13 20:05:28 -0300 | [diff] [blame] | 163 | goto err; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | release_firmware(fw); |
| 168 | fw = NULL; |
| 169 | |
| 170 | skip_fw_download: |
Olli Salonen | b154121 | 2014-07-13 10:52:19 -0300 | [diff] [blame] | 171 | /* reboot the tuner with new firmware? */ |
| 172 | memcpy(cmd.args, "\x01\x01", 2); |
| 173 | cmd.wlen = 2; |
| 174 | cmd.rlen = 1; |
| 175 | ret = si2157_cmd_execute(s, &cmd); |
| 176 | if (ret) |
| 177 | goto err; |
| 178 | |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 179 | s->active = true; |
| 180 | |
| 181 | return 0; |
Olli Salonen | b154121 | 2014-07-13 10:52:19 -0300 | [diff] [blame] | 182 | err: |
Antti Palosaari | 7d6bc60 | 2014-07-13 20:05:28 -0300 | [diff] [blame] | 183 | if (fw) |
| 184 | release_firmware(fw); |
| 185 | |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 186 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
Olli Salonen | b154121 | 2014-07-13 10:52:19 -0300 | [diff] [blame] | 187 | return ret; |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static int si2157_sleep(struct dvb_frontend *fe) |
| 191 | { |
| 192 | struct si2157 *s = fe->tuner_priv; |
Antti Palosaari | a83d7d1 | 2014-07-09 18:37:30 -0300 | [diff] [blame] | 193 | int ret; |
| 194 | struct si2157_cmd cmd; |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 195 | |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 196 | dev_dbg(&s->client->dev, "\n"); |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 197 | |
| 198 | s->active = false; |
| 199 | |
Antti Palosaari | a83d7d1 | 2014-07-09 18:37:30 -0300 | [diff] [blame] | 200 | memcpy(cmd.args, "\x13", 1); |
Antti Palosaari | e6b4380 | 2014-07-10 06:02:53 -0300 | [diff] [blame] | 201 | cmd.wlen = 1; |
| 202 | cmd.rlen = 0; |
Antti Palosaari | a83d7d1 | 2014-07-09 18:37:30 -0300 | [diff] [blame] | 203 | ret = si2157_cmd_execute(s, &cmd); |
| 204 | if (ret) |
| 205 | goto err; |
| 206 | |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 207 | return 0; |
Antti Palosaari | a83d7d1 | 2014-07-09 18:37:30 -0300 | [diff] [blame] | 208 | err: |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 209 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
Antti Palosaari | a83d7d1 | 2014-07-09 18:37:30 -0300 | [diff] [blame] | 210 | return ret; |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | static int si2157_set_params(struct dvb_frontend *fe) |
| 214 | { |
| 215 | struct si2157 *s = fe->tuner_priv; |
| 216 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 217 | int ret; |
| 218 | struct si2157_cmd cmd; |
Olli Salonen | a1dad50 | 2014-07-13 10:52:21 -0300 | [diff] [blame] | 219 | u8 bandwidth, delivery_system; |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 220 | |
| 221 | dev_dbg(&s->client->dev, |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 222 | "delivery_system=%d frequency=%u bandwidth_hz=%u\n", |
| 223 | c->delivery_system, c->frequency, |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 224 | c->bandwidth_hz); |
| 225 | |
| 226 | if (!s->active) { |
| 227 | ret = -EAGAIN; |
| 228 | goto err; |
| 229 | } |
| 230 | |
Olli Salonen | a1dad50 | 2014-07-13 10:52:21 -0300 | [diff] [blame] | 231 | if (c->bandwidth_hz <= 6000000) |
| 232 | bandwidth = 0x06; |
| 233 | else if (c->bandwidth_hz <= 7000000) |
| 234 | bandwidth = 0x07; |
| 235 | else if (c->bandwidth_hz <= 8000000) |
| 236 | bandwidth = 0x08; |
| 237 | else |
| 238 | bandwidth = 0x0f; |
| 239 | |
| 240 | switch (c->delivery_system) { |
Olli Salonen | 5cd62db | 2014-08-17 02:24:49 -0300 | [diff] [blame^] | 241 | case SYS_ATSC: |
| 242 | delivery_system = 0x00; |
| 243 | break; |
Olli Salonen | a1dad50 | 2014-07-13 10:52:21 -0300 | [diff] [blame] | 244 | case SYS_DVBT: |
| 245 | case SYS_DVBT2: /* it seems DVB-T and DVB-T2 both are 0x20 here */ |
| 246 | delivery_system = 0x20; |
| 247 | break; |
| 248 | case SYS_DVBC_ANNEX_A: |
| 249 | delivery_system = 0x30; |
| 250 | break; |
| 251 | default: |
| 252 | ret = -EINVAL; |
| 253 | goto err; |
| 254 | } |
| 255 | |
| 256 | memcpy(cmd.args, "\x14\x00\x03\x07\x00\x00", 6); |
| 257 | cmd.args[4] = delivery_system | bandwidth; |
Matthias Schwarzott | 05024ef | 2014-07-15 16:34:36 -0300 | [diff] [blame] | 258 | if (s->inversion) |
| 259 | cmd.args[5] = 0x01; |
Olli Salonen | a1dad50 | 2014-07-13 10:52:21 -0300 | [diff] [blame] | 260 | cmd.wlen = 6; |
| 261 | cmd.rlen = 1; |
| 262 | ret = si2157_cmd_execute(s, &cmd); |
| 263 | if (ret) |
| 264 | goto err; |
| 265 | |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 266 | /* set frequency */ |
Olli Salonen | b154121 | 2014-07-13 10:52:19 -0300 | [diff] [blame] | 267 | memcpy(cmd.args, "\x41\x00\x00\x00\x00\x00\x00\x00", 8); |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 268 | cmd.args[4] = (c->frequency >> 0) & 0xff; |
| 269 | cmd.args[5] = (c->frequency >> 8) & 0xff; |
| 270 | cmd.args[6] = (c->frequency >> 16) & 0xff; |
| 271 | cmd.args[7] = (c->frequency >> 24) & 0xff; |
Antti Palosaari | e6b4380 | 2014-07-10 06:02:53 -0300 | [diff] [blame] | 272 | cmd.wlen = 8; |
| 273 | cmd.rlen = 1; |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 274 | ret = si2157_cmd_execute(s, &cmd); |
| 275 | if (ret) |
| 276 | goto err; |
| 277 | |
| 278 | return 0; |
| 279 | err: |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 280 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 281 | return ret; |
| 282 | } |
| 283 | |
Matthias Schwarzott | 1140540 | 2014-07-15 04:58:40 -0300 | [diff] [blame] | 284 | static int si2157_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) |
| 285 | { |
| 286 | *frequency = 5000000; /* default value of property 0x0706 */ |
| 287 | return 0; |
| 288 | } |
| 289 | |
Olli Salonen | 6cc8a35 | 2014-07-18 02:41:12 -0300 | [diff] [blame] | 290 | static const struct dvb_tuner_ops si2157_ops = { |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 291 | .info = { |
Olli Salonen | 1b92373 | 2014-07-13 10:52:20 -0300 | [diff] [blame] | 292 | .name = "Silicon Labs Si2157/Si2158", |
Antti Palosaari | ae4c891 | 2014-04-12 01:53:51 -0300 | [diff] [blame] | 293 | .frequency_min = 110000000, |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 294 | .frequency_max = 862000000, |
| 295 | }, |
| 296 | |
| 297 | .init = si2157_init, |
| 298 | .sleep = si2157_sleep, |
| 299 | .set_params = si2157_set_params, |
Matthias Schwarzott | 1140540 | 2014-07-15 04:58:40 -0300 | [diff] [blame] | 300 | .get_if_frequency = si2157_get_if_frequency, |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 301 | }; |
| 302 | |
| 303 | static int si2157_probe(struct i2c_client *client, |
| 304 | const struct i2c_device_id *id) |
| 305 | { |
| 306 | struct si2157_config *cfg = client->dev.platform_data; |
| 307 | struct dvb_frontend *fe = cfg->fe; |
| 308 | struct si2157 *s; |
| 309 | struct si2157_cmd cmd; |
| 310 | int ret; |
| 311 | |
| 312 | s = kzalloc(sizeof(struct si2157), GFP_KERNEL); |
| 313 | if (!s) { |
| 314 | ret = -ENOMEM; |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 315 | dev_err(&client->dev, "kzalloc() failed\n"); |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 316 | goto err; |
| 317 | } |
| 318 | |
| 319 | s->client = client; |
| 320 | s->fe = cfg->fe; |
Matthias Schwarzott | 05024ef | 2014-07-15 16:34:36 -0300 | [diff] [blame] | 321 | s->inversion = cfg->inversion; |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 322 | mutex_init(&s->i2c_mutex); |
| 323 | |
| 324 | /* check if the tuner is there */ |
Antti Palosaari | e6b4380 | 2014-07-10 06:02:53 -0300 | [diff] [blame] | 325 | cmd.wlen = 0; |
| 326 | cmd.rlen = 1; |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 327 | ret = si2157_cmd_execute(s, &cmd); |
| 328 | if (ret) |
| 329 | goto err; |
| 330 | |
| 331 | fe->tuner_priv = s; |
Olli Salonen | 6cc8a35 | 2014-07-18 02:41:12 -0300 | [diff] [blame] | 332 | memcpy(&fe->ops.tuner_ops, &si2157_ops, |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 333 | sizeof(struct dvb_tuner_ops)); |
| 334 | |
| 335 | i2c_set_clientdata(client, s); |
| 336 | |
| 337 | dev_info(&s->client->dev, |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 338 | "Silicon Labs Si2157/Si2158 successfully attached\n"); |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 339 | return 0; |
| 340 | err: |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 341 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 342 | kfree(s); |
| 343 | |
| 344 | return ret; |
| 345 | } |
| 346 | |
| 347 | static int si2157_remove(struct i2c_client *client) |
| 348 | { |
| 349 | struct si2157 *s = i2c_get_clientdata(client); |
| 350 | struct dvb_frontend *fe = s->fe; |
| 351 | |
Olli Salonen | 67d0113 | 2014-08-05 09:03:54 -0300 | [diff] [blame] | 352 | dev_dbg(&client->dev, "\n"); |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 353 | |
| 354 | memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); |
| 355 | fe->tuner_priv = NULL; |
| 356 | kfree(s); |
| 357 | |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | static const struct i2c_device_id si2157_id[] = { |
| 362 | {"si2157", 0}, |
| 363 | {} |
| 364 | }; |
| 365 | MODULE_DEVICE_TABLE(i2c, si2157_id); |
| 366 | |
| 367 | static struct i2c_driver si2157_driver = { |
| 368 | .driver = { |
| 369 | .owner = THIS_MODULE, |
| 370 | .name = "si2157", |
| 371 | }, |
| 372 | .probe = si2157_probe, |
| 373 | .remove = si2157_remove, |
| 374 | .id_table = si2157_id, |
| 375 | }; |
| 376 | |
| 377 | module_i2c_driver(si2157_driver); |
| 378 | |
Olli Salonen | 1b92373 | 2014-07-13 10:52:20 -0300 | [diff] [blame] | 379 | MODULE_DESCRIPTION("Silicon Labs Si2157/Si2158 silicon tuner driver"); |
Antti Palosaari | 930a873 | 2014-04-10 21:58:10 -0300 | [diff] [blame] | 380 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 381 | MODULE_LICENSE("GPL"); |
Antti Palosaari | bac53a2 | 2014-07-13 16:13:49 -0300 | [diff] [blame] | 382 | MODULE_FIRMWARE(SI2158_A20_FIRMWARE); |