Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1 | /* |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 2 | * Montage Technology M88DS3103/M88RS6000 demodulator driver |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2013 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. |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include "m88ds3103_priv.h" |
| 18 | |
Max Kellermann | bd336e6 | 2016-08-09 18:32:21 -0300 | [diff] [blame^] | 19 | static const struct dvb_frontend_ops m88ds3103_ops; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 20 | |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 21 | /* write single register with mask */ |
| 22 | static int m88ds3103_update_bits(struct m88ds3103_dev *dev, |
| 23 | u8 reg, u8 mask, u8 val) |
| 24 | { |
| 25 | int ret; |
| 26 | u8 tmp; |
| 27 | |
| 28 | /* no need for read if whole reg is written */ |
| 29 | if (mask != 0xff) { |
| 30 | ret = regmap_bulk_read(dev->regmap, reg, &tmp, 1); |
| 31 | if (ret) |
| 32 | return ret; |
| 33 | |
| 34 | val &= mask; |
| 35 | tmp &= ~mask; |
| 36 | val |= tmp; |
| 37 | } |
| 38 | |
| 39 | return regmap_bulk_write(dev->regmap, reg, &val, 1); |
| 40 | } |
| 41 | |
Antti Palosaari | 06487de | 2013-12-02 14:08:53 -0300 | [diff] [blame] | 42 | /* write reg val table using reg addr auto increment */ |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 43 | static int m88ds3103_wr_reg_val_tab(struct m88ds3103_dev *dev, |
Antti Palosaari | 06487de | 2013-12-02 14:08:53 -0300 | [diff] [blame] | 44 | const struct m88ds3103_reg_val *tab, int tab_len) |
| 45 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 46 | struct i2c_client *client = dev->client; |
Antti Palosaari | 06487de | 2013-12-02 14:08:53 -0300 | [diff] [blame] | 47 | int ret, i, j; |
| 48 | u8 buf[83]; |
Antti Palosaari | 41b9aa0 | 2014-08-21 21:38:29 -0300 | [diff] [blame] | 49 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 50 | dev_dbg(&client->dev, "tab_len=%d\n", tab_len); |
Antti Palosaari | 06487de | 2013-12-02 14:08:53 -0300 | [diff] [blame] | 51 | |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 52 | if (tab_len > 86) { |
Antti Palosaari | 06487de | 2013-12-02 14:08:53 -0300 | [diff] [blame] | 53 | ret = -EINVAL; |
| 54 | goto err; |
| 55 | } |
| 56 | |
| 57 | for (i = 0, j = 0; i < tab_len; i++, j++) { |
| 58 | buf[j] = tab[i].val; |
| 59 | |
| 60 | if (i == tab_len - 1 || tab[i].reg != tab[i + 1].reg - 1 || |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 61 | !((j + 1) % (dev->cfg->i2c_wr_max - 1))) { |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 62 | ret = regmap_bulk_write(dev->regmap, tab[i].reg - j, buf, j + 1); |
Antti Palosaari | 06487de | 2013-12-02 14:08:53 -0300 | [diff] [blame] | 63 | if (ret) |
| 64 | goto err; |
| 65 | |
| 66 | j = -1; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return 0; |
| 71 | err: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 72 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 06487de | 2013-12-02 14:08:53 -0300 | [diff] [blame] | 73 | return ret; |
| 74 | } |
| 75 | |
David Howells | 0f91c9d | 2015-05-26 12:04:00 -0300 | [diff] [blame] | 76 | /* |
| 77 | * Get the demodulator AGC PWM voltage setting supplied to the tuner. |
| 78 | */ |
| 79 | int m88ds3103_get_agc_pwm(struct dvb_frontend *fe, u8 *_agc_pwm) |
| 80 | { |
| 81 | struct m88ds3103_dev *dev = fe->demodulator_priv; |
| 82 | unsigned tmp; |
| 83 | int ret; |
| 84 | |
| 85 | ret = regmap_read(dev->regmap, 0x3f, &tmp); |
| 86 | if (ret == 0) |
| 87 | *_agc_pwm = tmp; |
| 88 | return ret; |
| 89 | } |
| 90 | EXPORT_SYMBOL(m88ds3103_get_agc_pwm); |
| 91 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 92 | static int m88ds3103_read_status(struct dvb_frontend *fe, |
| 93 | enum fe_status *status) |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 94 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 95 | struct m88ds3103_dev *dev = fe->demodulator_priv; |
| 96 | struct i2c_client *client = dev->client; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 97 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Antti Palosaari | c1daf65 | 2015-04-13 20:56:13 -0300 | [diff] [blame] | 98 | int ret, i, itmp; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 99 | unsigned int utmp; |
Antti Palosaari | c1daf65 | 2015-04-13 20:56:13 -0300 | [diff] [blame] | 100 | u8 buf[3]; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 101 | |
| 102 | *status = 0; |
| 103 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 104 | if (!dev->warm) { |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 105 | ret = -EAGAIN; |
| 106 | goto err; |
| 107 | } |
| 108 | |
| 109 | switch (c->delivery_system) { |
| 110 | case SYS_DVBS: |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 111 | ret = regmap_read(dev->regmap, 0xd1, &utmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 112 | if (ret) |
| 113 | goto err; |
| 114 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 115 | if ((utmp & 0x07) == 0x07) |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 116 | *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | |
| 117 | FE_HAS_VITERBI | FE_HAS_SYNC | |
| 118 | FE_HAS_LOCK; |
| 119 | break; |
| 120 | case SYS_DVBS2: |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 121 | ret = regmap_read(dev->regmap, 0x0d, &utmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 122 | if (ret) |
| 123 | goto err; |
| 124 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 125 | if ((utmp & 0x8f) == 0x8f) |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 126 | *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | |
| 127 | FE_HAS_VITERBI | FE_HAS_SYNC | |
| 128 | FE_HAS_LOCK; |
| 129 | break; |
| 130 | default: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 131 | dev_dbg(&client->dev, "invalid delivery_system\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 132 | ret = -EINVAL; |
| 133 | goto err; |
| 134 | } |
| 135 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 136 | dev->fe_status = *status; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 137 | dev_dbg(&client->dev, "lock=%02x status=%02x\n", utmp, *status); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 138 | |
Antti Palosaari | c1daf65 | 2015-04-13 20:56:13 -0300 | [diff] [blame] | 139 | /* CNR */ |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 140 | if (dev->fe_status & FE_HAS_VITERBI) { |
Antti Palosaari | c1daf65 | 2015-04-13 20:56:13 -0300 | [diff] [blame] | 141 | unsigned int cnr, noise, signal, noise_tot, signal_tot; |
| 142 | |
| 143 | cnr = 0; |
| 144 | /* more iterations for more accurate estimation */ |
| 145 | #define M88DS3103_SNR_ITERATIONS 3 |
| 146 | |
| 147 | switch (c->delivery_system) { |
| 148 | case SYS_DVBS: |
| 149 | itmp = 0; |
| 150 | |
| 151 | for (i = 0; i < M88DS3103_SNR_ITERATIONS; i++) { |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 152 | ret = regmap_read(dev->regmap, 0xff, &utmp); |
Antti Palosaari | c1daf65 | 2015-04-13 20:56:13 -0300 | [diff] [blame] | 153 | if (ret) |
| 154 | goto err; |
| 155 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 156 | itmp += utmp; |
Antti Palosaari | c1daf65 | 2015-04-13 20:56:13 -0300 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /* use of single register limits max value to 15 dB */ |
| 160 | /* SNR(X) dB = 10 * ln(X) / ln(10) dB */ |
| 161 | itmp = DIV_ROUND_CLOSEST(itmp, 8 * M88DS3103_SNR_ITERATIONS); |
| 162 | if (itmp) |
| 163 | cnr = div_u64((u64) 10000 * intlog2(itmp), intlog2(10)); |
| 164 | break; |
| 165 | case SYS_DVBS2: |
| 166 | noise_tot = 0; |
| 167 | signal_tot = 0; |
| 168 | |
| 169 | for (i = 0; i < M88DS3103_SNR_ITERATIONS; i++) { |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 170 | ret = regmap_bulk_read(dev->regmap, 0x8c, buf, 3); |
Antti Palosaari | c1daf65 | 2015-04-13 20:56:13 -0300 | [diff] [blame] | 171 | if (ret) |
| 172 | goto err; |
| 173 | |
| 174 | noise = buf[1] << 6; /* [13:6] */ |
| 175 | noise |= buf[0] & 0x3f; /* [5:0] */ |
| 176 | noise >>= 2; |
| 177 | signal = buf[2] * buf[2]; |
| 178 | signal >>= 1; |
| 179 | |
| 180 | noise_tot += noise; |
| 181 | signal_tot += signal; |
| 182 | } |
| 183 | |
| 184 | noise = noise_tot / M88DS3103_SNR_ITERATIONS; |
| 185 | signal = signal_tot / M88DS3103_SNR_ITERATIONS; |
| 186 | |
| 187 | /* SNR(X) dB = 10 * log10(X) dB */ |
| 188 | if (signal > noise) { |
| 189 | itmp = signal / noise; |
| 190 | cnr = div_u64((u64) 10000 * intlog10(itmp), (1 << 24)); |
| 191 | } |
| 192 | break; |
| 193 | default: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 194 | dev_dbg(&client->dev, "invalid delivery_system\n"); |
Antti Palosaari | c1daf65 | 2015-04-13 20:56:13 -0300 | [diff] [blame] | 195 | ret = -EINVAL; |
| 196 | goto err; |
| 197 | } |
| 198 | |
| 199 | if (cnr) { |
| 200 | c->cnr.stat[0].scale = FE_SCALE_DECIBEL; |
| 201 | c->cnr.stat[0].svalue = cnr; |
| 202 | } else { |
| 203 | c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 204 | } |
| 205 | } else { |
| 206 | c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 207 | } |
| 208 | |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 209 | /* BER */ |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 210 | if (dev->fe_status & FE_HAS_LOCK) { |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 211 | unsigned int utmp, post_bit_error, post_bit_count; |
| 212 | |
| 213 | switch (c->delivery_system) { |
| 214 | case SYS_DVBS: |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 215 | ret = regmap_write(dev->regmap, 0xf9, 0x04); |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 216 | if (ret) |
| 217 | goto err; |
| 218 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 219 | ret = regmap_read(dev->regmap, 0xf8, &utmp); |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 220 | if (ret) |
| 221 | goto err; |
| 222 | |
| 223 | /* measurement ready? */ |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 224 | if (!(utmp & 0x10)) { |
| 225 | ret = regmap_bulk_read(dev->regmap, 0xf6, buf, 2); |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 226 | if (ret) |
| 227 | goto err; |
| 228 | |
| 229 | post_bit_error = buf[1] << 8 | buf[0] << 0; |
| 230 | post_bit_count = 0x800000; |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 231 | dev->post_bit_error += post_bit_error; |
| 232 | dev->post_bit_count += post_bit_count; |
| 233 | dev->dvbv3_ber = post_bit_error; |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 234 | |
| 235 | /* restart measurement */ |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 236 | utmp |= 0x10; |
| 237 | ret = regmap_write(dev->regmap, 0xf8, utmp); |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 238 | if (ret) |
| 239 | goto err; |
| 240 | } |
| 241 | break; |
| 242 | case SYS_DVBS2: |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 243 | ret = regmap_bulk_read(dev->regmap, 0xd5, buf, 3); |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 244 | if (ret) |
| 245 | goto err; |
| 246 | |
| 247 | utmp = buf[2] << 16 | buf[1] << 8 | buf[0] << 0; |
| 248 | |
| 249 | /* enough data? */ |
| 250 | if (utmp > 4000) { |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 251 | ret = regmap_bulk_read(dev->regmap, 0xf7, buf, 2); |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 252 | if (ret) |
| 253 | goto err; |
| 254 | |
| 255 | post_bit_error = buf[1] << 8 | buf[0] << 0; |
| 256 | post_bit_count = 32 * utmp; /* TODO: FEC */ |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 257 | dev->post_bit_error += post_bit_error; |
| 258 | dev->post_bit_count += post_bit_count; |
| 259 | dev->dvbv3_ber = post_bit_error; |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 260 | |
| 261 | /* restart measurement */ |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 262 | ret = regmap_write(dev->regmap, 0xd1, 0x01); |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 263 | if (ret) |
| 264 | goto err; |
| 265 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 266 | ret = regmap_write(dev->regmap, 0xf9, 0x01); |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 267 | if (ret) |
| 268 | goto err; |
| 269 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 270 | ret = regmap_write(dev->regmap, 0xf9, 0x00); |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 271 | if (ret) |
| 272 | goto err; |
| 273 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 274 | ret = regmap_write(dev->regmap, 0xd1, 0x00); |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 275 | if (ret) |
| 276 | goto err; |
| 277 | } |
| 278 | break; |
| 279 | default: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 280 | dev_dbg(&client->dev, "invalid delivery_system\n"); |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 281 | ret = -EINVAL; |
| 282 | goto err; |
| 283 | } |
| 284 | |
| 285 | c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 286 | c->post_bit_error.stat[0].uvalue = dev->post_bit_error; |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 287 | c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 288 | c->post_bit_count.stat[0].uvalue = dev->post_bit_count; |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 289 | } else { |
| 290 | c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 291 | c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 292 | } |
| 293 | |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 294 | return 0; |
| 295 | err: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 296 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 297 | return ret; |
| 298 | } |
| 299 | |
| 300 | static int m88ds3103_set_frontend(struct dvb_frontend *fe) |
| 301 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 302 | struct m88ds3103_dev *dev = fe->demodulator_priv; |
| 303 | struct i2c_client *client = dev->client; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 304 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Antti Palosaari | 06487de | 2013-12-02 14:08:53 -0300 | [diff] [blame] | 305 | int ret, len; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 306 | const struct m88ds3103_reg_val *init; |
nibble.max | b685141 | 2014-11-05 11:59:07 -0300 | [diff] [blame] | 307 | u8 u8tmp, u8tmp1 = 0, u8tmp2 = 0; /* silence compiler warning */ |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 308 | u8 buf[3]; |
Antti Palosaari | 334ef18 | 2016-06-29 20:39:46 -0300 | [diff] [blame] | 309 | u16 u16tmp; |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 310 | u32 tuner_frequency_khz, target_mclk; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 311 | s32 s32tmp; |
Antti Palosaari | 41b9aa0 | 2014-08-21 21:38:29 -0300 | [diff] [blame] | 312 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 313 | dev_dbg(&client->dev, |
| 314 | "delivery_system=%d modulation=%d frequency=%u symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n", |
| 315 | c->delivery_system, c->modulation, c->frequency, c->symbol_rate, |
| 316 | c->inversion, c->pilot, c->rolloff); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 317 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 318 | if (!dev->warm) { |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 319 | ret = -EAGAIN; |
| 320 | goto err; |
| 321 | } |
| 322 | |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 323 | /* reset */ |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 324 | ret = regmap_write(dev->regmap, 0x07, 0x80); |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 325 | if (ret) |
| 326 | goto err; |
| 327 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 328 | ret = regmap_write(dev->regmap, 0x07, 0x00); |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 329 | if (ret) |
| 330 | goto err; |
| 331 | |
| 332 | /* Disable demod clock path */ |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 333 | if (dev->chip_id == M88RS6000_CHIP_ID) { |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 334 | ret = regmap_write(dev->regmap, 0x06, 0xe0); |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 335 | if (ret) |
| 336 | goto err; |
| 337 | } |
| 338 | |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 339 | /* program tuner */ |
| 340 | if (fe->ops.tuner_ops.set_params) { |
| 341 | ret = fe->ops.tuner_ops.set_params(fe); |
| 342 | if (ret) |
| 343 | goto err; |
| 344 | } |
| 345 | |
| 346 | if (fe->ops.tuner_ops.get_frequency) { |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 347 | ret = fe->ops.tuner_ops.get_frequency(fe, &tuner_frequency_khz); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 348 | if (ret) |
| 349 | goto err; |
Antti Palosaari | 2f9dff3 | 2014-02-01 12:58:28 -0300 | [diff] [blame] | 350 | } else { |
| 351 | /* |
| 352 | * Use nominal target frequency as tuner driver does not provide |
| 353 | * actual frequency used. Carrier offset calculation is not |
| 354 | * valid. |
| 355 | */ |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 356 | tuner_frequency_khz = c->frequency; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 357 | } |
| 358 | |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 359 | /* select M88RS6000 demod main mclk and ts mclk from tuner die. */ |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 360 | if (dev->chip_id == M88RS6000_CHIP_ID) { |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 361 | if (c->symbol_rate > 45010000) |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 362 | dev->mclk = 110250000; |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 363 | else |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 364 | dev->mclk = 96000000; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 365 | |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 366 | if (c->delivery_system == SYS_DVBS) |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 367 | target_mclk = 96000000; |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 368 | else |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 369 | target_mclk = 144000000; |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 370 | |
| 371 | /* Enable demod clock path */ |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 372 | ret = regmap_write(dev->regmap, 0x06, 0x00); |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 373 | if (ret) |
| 374 | goto err; |
| 375 | usleep_range(10000, 20000); |
| 376 | } else { |
| 377 | /* set M88DS3103 mclk and ts mclk. */ |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 378 | dev->mclk = 96000000; |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 379 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 380 | switch (dev->cfg->ts_mode) { |
nibble.max | b685141 | 2014-11-05 11:59:07 -0300 | [diff] [blame] | 381 | case M88DS3103_TS_SERIAL: |
| 382 | case M88DS3103_TS_SERIAL_D7: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 383 | target_mclk = dev->cfg->ts_clk; |
nibble.max | b685141 | 2014-11-05 11:59:07 -0300 | [diff] [blame] | 384 | break; |
| 385 | case M88DS3103_TS_PARALLEL: |
| 386 | case M88DS3103_TS_CI: |
| 387 | if (c->delivery_system == SYS_DVBS) |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 388 | target_mclk = 96000000; |
nibble.max | b685141 | 2014-11-05 11:59:07 -0300 | [diff] [blame] | 389 | else { |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 390 | if (c->symbol_rate < 18000000) |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 391 | target_mclk = 96000000; |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 392 | else if (c->symbol_rate < 28000000) |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 393 | target_mclk = 144000000; |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 394 | else |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 395 | target_mclk = 192000000; |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 396 | } |
nibble.max | b685141 | 2014-11-05 11:59:07 -0300 | [diff] [blame] | 397 | break; |
| 398 | default: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 399 | dev_dbg(&client->dev, "invalid ts_mode\n"); |
nibble.max | b685141 | 2014-11-05 11:59:07 -0300 | [diff] [blame] | 400 | ret = -EINVAL; |
| 401 | goto err; |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | switch (target_mclk) { |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 405 | case 96000000: |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 406 | u8tmp1 = 0x02; /* 0b10 */ |
| 407 | u8tmp2 = 0x01; /* 0b01 */ |
| 408 | break; |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 409 | case 144000000: |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 410 | u8tmp1 = 0x00; /* 0b00 */ |
| 411 | u8tmp2 = 0x01; /* 0b01 */ |
| 412 | break; |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 413 | case 192000000: |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 414 | u8tmp1 = 0x03; /* 0b11 */ |
| 415 | u8tmp2 = 0x00; /* 0b00 */ |
| 416 | break; |
| 417 | } |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 418 | ret = m88ds3103_update_bits(dev, 0x22, 0xc0, u8tmp1 << 6); |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 419 | if (ret) |
| 420 | goto err; |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 421 | ret = m88ds3103_update_bits(dev, 0x24, 0xc0, u8tmp2 << 6); |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 422 | if (ret) |
| 423 | goto err; |
| 424 | } |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 425 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 426 | ret = regmap_write(dev->regmap, 0xb2, 0x01); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 427 | if (ret) |
| 428 | goto err; |
| 429 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 430 | ret = regmap_write(dev->regmap, 0x00, 0x01); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 431 | if (ret) |
| 432 | goto err; |
| 433 | |
| 434 | switch (c->delivery_system) { |
| 435 | case SYS_DVBS: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 436 | if (dev->chip_id == M88RS6000_CHIP_ID) { |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 437 | len = ARRAY_SIZE(m88rs6000_dvbs_init_reg_vals); |
| 438 | init = m88rs6000_dvbs_init_reg_vals; |
| 439 | } else { |
| 440 | len = ARRAY_SIZE(m88ds3103_dvbs_init_reg_vals); |
| 441 | init = m88ds3103_dvbs_init_reg_vals; |
| 442 | } |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 443 | break; |
| 444 | case SYS_DVBS2: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 445 | if (dev->chip_id == M88RS6000_CHIP_ID) { |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 446 | len = ARRAY_SIZE(m88rs6000_dvbs2_init_reg_vals); |
| 447 | init = m88rs6000_dvbs2_init_reg_vals; |
| 448 | } else { |
| 449 | len = ARRAY_SIZE(m88ds3103_dvbs2_init_reg_vals); |
| 450 | init = m88ds3103_dvbs2_init_reg_vals; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 451 | } |
| 452 | break; |
| 453 | default: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 454 | dev_dbg(&client->dev, "invalid delivery_system\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 455 | ret = -EINVAL; |
| 456 | goto err; |
| 457 | } |
| 458 | |
| 459 | /* program init table */ |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 460 | if (c->delivery_system != dev->delivery_system) { |
| 461 | ret = m88ds3103_wr_reg_val_tab(dev, init, len); |
Antti Palosaari | 06487de | 2013-12-02 14:08:53 -0300 | [diff] [blame] | 462 | if (ret) |
| 463 | goto err; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 464 | } |
| 465 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 466 | if (dev->chip_id == M88RS6000_CHIP_ID) { |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 467 | if (c->delivery_system == SYS_DVBS2 && |
| 468 | c->symbol_rate <= 5000000) { |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 469 | ret = regmap_write(dev->regmap, 0xc0, 0x04); |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 470 | if (ret) |
| 471 | goto err; |
| 472 | buf[0] = 0x09; |
| 473 | buf[1] = 0x22; |
| 474 | buf[2] = 0x88; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 475 | ret = regmap_bulk_write(dev->regmap, 0x8a, buf, 3); |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 476 | if (ret) |
| 477 | goto err; |
| 478 | } |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 479 | ret = m88ds3103_update_bits(dev, 0x9d, 0x08, 0x08); |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 480 | if (ret) |
| 481 | goto err; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 482 | ret = regmap_write(dev->regmap, 0xf1, 0x01); |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 483 | if (ret) |
| 484 | goto err; |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 485 | ret = m88ds3103_update_bits(dev, 0x30, 0x80, 0x80); |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 486 | if (ret) |
| 487 | goto err; |
| 488 | } |
| 489 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 490 | switch (dev->cfg->ts_mode) { |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 491 | case M88DS3103_TS_SERIAL: |
| 492 | u8tmp1 = 0x00; |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 493 | u8tmp = 0x06; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 494 | break; |
| 495 | case M88DS3103_TS_SERIAL_D7: |
| 496 | u8tmp1 = 0x20; |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 497 | u8tmp = 0x06; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 498 | break; |
| 499 | case M88DS3103_TS_PARALLEL: |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 500 | u8tmp = 0x02; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 501 | break; |
| 502 | case M88DS3103_TS_CI: |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 503 | u8tmp = 0x03; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 504 | break; |
| 505 | default: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 506 | dev_dbg(&client->dev, "invalid ts_mode\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 507 | ret = -EINVAL; |
| 508 | goto err; |
| 509 | } |
| 510 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 511 | if (dev->cfg->ts_clk_pol) |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 512 | u8tmp |= 0x40; |
| 513 | |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 514 | /* TS mode */ |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 515 | ret = regmap_write(dev->regmap, 0xfd, u8tmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 516 | if (ret) |
| 517 | goto err; |
| 518 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 519 | switch (dev->cfg->ts_mode) { |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 520 | case M88DS3103_TS_SERIAL: |
| 521 | case M88DS3103_TS_SERIAL_D7: |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 522 | ret = m88ds3103_update_bits(dev, 0x29, 0x20, u8tmp1); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 523 | if (ret) |
| 524 | goto err; |
Antti Palosaari | 334ef18 | 2016-06-29 20:39:46 -0300 | [diff] [blame] | 525 | u16tmp = 0; |
| 526 | u8tmp1 = 0x3f; |
| 527 | u8tmp2 = 0x3f; |
nibble.max | b685141 | 2014-11-05 11:59:07 -0300 | [diff] [blame] | 528 | break; |
| 529 | default: |
Antti Palosaari | 334ef18 | 2016-06-29 20:39:46 -0300 | [diff] [blame] | 530 | u16tmp = DIV_ROUND_UP(target_mclk, dev->cfg->ts_clk); |
| 531 | u8tmp1 = u16tmp / 2 - 1; |
| 532 | u8tmp2 = DIV_ROUND_UP(u16tmp, 2) - 1; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 533 | } |
| 534 | |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 535 | dev_dbg(&client->dev, "target_mclk=%u ts_clk=%u ts_clk_divide_ratio=%u\n", |
Antti Palosaari | 334ef18 | 2016-06-29 20:39:46 -0300 | [diff] [blame] | 536 | target_mclk, dev->cfg->ts_clk, u16tmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 537 | |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 538 | /* u8tmp1[5:2] => fe[3:0], u8tmp1[1:0] => ea[7:6] */ |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 539 | /* u8tmp2[5:0] => ea[5:0] */ |
Antti Palosaari | 334ef18 | 2016-06-29 20:39:46 -0300 | [diff] [blame] | 540 | u8tmp = (u8tmp1 >> 2) & 0x0f; |
| 541 | ret = regmap_update_bits(dev->regmap, 0xfe, 0x0f, u8tmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 542 | if (ret) |
| 543 | goto err; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 544 | u8tmp = ((u8tmp1 & 0x03) << 6) | u8tmp2 >> 0; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 545 | ret = regmap_write(dev->regmap, 0xea, u8tmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 546 | if (ret) |
| 547 | goto err; |
| 548 | |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 549 | if (c->symbol_rate <= 3000000) |
| 550 | u8tmp = 0x20; |
| 551 | else if (c->symbol_rate <= 10000000) |
| 552 | u8tmp = 0x10; |
| 553 | else |
| 554 | u8tmp = 0x06; |
| 555 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 556 | ret = regmap_write(dev->regmap, 0xc3, 0x08); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 557 | if (ret) |
| 558 | goto err; |
| 559 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 560 | ret = regmap_write(dev->regmap, 0xc8, u8tmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 561 | if (ret) |
| 562 | goto err; |
| 563 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 564 | ret = regmap_write(dev->regmap, 0xc4, 0x08); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 565 | if (ret) |
| 566 | goto err; |
| 567 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 568 | ret = regmap_write(dev->regmap, 0xc7, 0x00); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 569 | if (ret) |
| 570 | goto err; |
| 571 | |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 572 | u16tmp = DIV_ROUND_CLOSEST_ULL((u64)c->symbol_rate * 0x10000, dev->mclk); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 573 | buf[0] = (u16tmp >> 0) & 0xff; |
| 574 | buf[1] = (u16tmp >> 8) & 0xff; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 575 | ret = regmap_bulk_write(dev->regmap, 0x61, buf, 2); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 576 | if (ret) |
| 577 | goto err; |
| 578 | |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 579 | ret = m88ds3103_update_bits(dev, 0x4d, 0x02, dev->cfg->spec_inv << 1); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 580 | if (ret) |
| 581 | goto err; |
| 582 | |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 583 | ret = m88ds3103_update_bits(dev, 0x30, 0x10, dev->cfg->agc_inv << 4); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 584 | if (ret) |
| 585 | goto err; |
| 586 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 587 | ret = regmap_write(dev->regmap, 0x33, dev->cfg->agc); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 588 | if (ret) |
| 589 | goto err; |
| 590 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 591 | dev_dbg(&client->dev, "carrier offset=%d\n", |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 592 | (tuner_frequency_khz - c->frequency)); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 593 | |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 594 | /* Use 32-bit calc as there is no s64 version of DIV_ROUND_CLOSEST() */ |
| 595 | s32tmp = 0x10000 * (tuner_frequency_khz - c->frequency); |
| 596 | s32tmp = DIV_ROUND_CLOSEST(s32tmp, dev->mclk / 1000); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 597 | buf[0] = (s32tmp >> 0) & 0xff; |
| 598 | buf[1] = (s32tmp >> 8) & 0xff; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 599 | ret = regmap_bulk_write(dev->regmap, 0x5e, buf, 2); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 600 | if (ret) |
| 601 | goto err; |
| 602 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 603 | ret = regmap_write(dev->regmap, 0x00, 0x00); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 604 | if (ret) |
| 605 | goto err; |
| 606 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 607 | ret = regmap_write(dev->regmap, 0xb2, 0x00); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 608 | if (ret) |
| 609 | goto err; |
| 610 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 611 | dev->delivery_system = c->delivery_system; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 612 | |
| 613 | return 0; |
| 614 | err: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 615 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 616 | return ret; |
| 617 | } |
| 618 | |
| 619 | static int m88ds3103_init(struct dvb_frontend *fe) |
| 620 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 621 | struct m88ds3103_dev *dev = fe->demodulator_priv; |
| 622 | struct i2c_client *client = dev->client; |
Antti Palosaari | c1daf65 | 2015-04-13 20:56:13 -0300 | [diff] [blame] | 623 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 624 | int ret, len, rem; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 625 | unsigned int utmp; |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 626 | const struct firmware *firmware; |
| 627 | const char *name; |
Antti Palosaari | 41b9aa0 | 2014-08-21 21:38:29 -0300 | [diff] [blame] | 628 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 629 | dev_dbg(&client->dev, "\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 630 | |
| 631 | /* set cold state by default */ |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 632 | dev->warm = false; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 633 | |
| 634 | /* wake up device from sleep */ |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 635 | ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x01); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 636 | if (ret) |
| 637 | goto err; |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 638 | ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x00); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 639 | if (ret) |
| 640 | goto err; |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 641 | ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x00); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 642 | if (ret) |
| 643 | goto err; |
| 644 | |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 645 | /* firmware status */ |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 646 | ret = regmap_read(dev->regmap, 0xb9, &utmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 647 | if (ret) |
| 648 | goto err; |
| 649 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 650 | dev_dbg(&client->dev, "firmware=%02x\n", utmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 651 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 652 | if (utmp) |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 653 | goto warm; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 654 | |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 655 | /* global reset, global diseqc reset, golbal fec reset */ |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 656 | ret = regmap_write(dev->regmap, 0x07, 0xe0); |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 657 | if (ret) |
| 658 | goto err; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 659 | ret = regmap_write(dev->regmap, 0x07, 0x00); |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 660 | if (ret) |
| 661 | goto err; |
| 662 | |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 663 | /* cold state - try to download firmware */ |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 664 | dev_info(&client->dev, "found a '%s' in cold state\n", |
| 665 | m88ds3103_ops.info.name); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 666 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 667 | if (dev->chip_id == M88RS6000_CHIP_ID) |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 668 | name = M88RS6000_FIRMWARE; |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 669 | else |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 670 | name = M88DS3103_FIRMWARE; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 671 | /* request the firmware, this will block and timeout */ |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 672 | ret = request_firmware(&firmware, name, &client->dev); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 673 | if (ret) { |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 674 | dev_err(&client->dev, "firmware file '%s' not found\n", name); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 675 | goto err; |
| 676 | } |
| 677 | |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 678 | dev_info(&client->dev, "downloading firmware from file '%s'\n", name); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 679 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 680 | ret = regmap_write(dev->regmap, 0xb2, 0x01); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 681 | if (ret) |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 682 | goto err_release_firmware; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 683 | |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 684 | for (rem = firmware->size; rem > 0; rem -= (dev->cfg->i2c_wr_max - 1)) { |
| 685 | len = min(dev->cfg->i2c_wr_max - 1, rem); |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 686 | ret = regmap_bulk_write(dev->regmap, 0xb0, |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 687 | &firmware->data[firmware->size - rem], |
| 688 | len); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 689 | if (ret) { |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 690 | dev_err(&client->dev, "firmware download failed %d\n", |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 691 | ret); |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 692 | goto err_release_firmware; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 696 | ret = regmap_write(dev->regmap, 0xb2, 0x00); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 697 | if (ret) |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 698 | goto err_release_firmware; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 699 | |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 700 | release_firmware(firmware); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 701 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 702 | ret = regmap_read(dev->regmap, 0xb9, &utmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 703 | if (ret) |
| 704 | goto err; |
| 705 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 706 | if (!utmp) { |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 707 | ret = -EINVAL; |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 708 | dev_info(&client->dev, "firmware did not run\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 709 | goto err; |
| 710 | } |
| 711 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 712 | dev_info(&client->dev, "found a '%s' in warm state\n", |
| 713 | m88ds3103_ops.info.name); |
| 714 | dev_info(&client->dev, "firmware version: %X.%X\n", |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 715 | (utmp >> 4) & 0xf, (utmp >> 0 & 0xf)); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 716 | |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 717 | warm: |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 718 | /* warm state */ |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 719 | dev->warm = true; |
| 720 | |
Antti Palosaari | c1daf65 | 2015-04-13 20:56:13 -0300 | [diff] [blame] | 721 | /* init stats here in order signal app which stats are supported */ |
| 722 | c->cnr.len = 1; |
| 723 | c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Antti Palosaari | ce80d71 | 2015-04-14 09:44:20 -0300 | [diff] [blame] | 724 | c->post_bit_error.len = 1; |
| 725 | c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 726 | c->post_bit_count.len = 1; |
| 727 | c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 728 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 729 | return 0; |
Antti Palosaari | 60701d5 | 2016-06-29 20:39:48 -0300 | [diff] [blame] | 730 | err_release_firmware: |
| 731 | release_firmware(firmware); |
Markus Elfring | 5ed0cf8 | 2014-11-19 19:20:51 -0300 | [diff] [blame] | 732 | err: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 733 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 734 | return ret; |
| 735 | } |
| 736 | |
| 737 | static int m88ds3103_sleep(struct dvb_frontend *fe) |
| 738 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 739 | struct m88ds3103_dev *dev = fe->demodulator_priv; |
| 740 | struct i2c_client *client = dev->client; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 741 | int ret; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 742 | unsigned int utmp; |
Antti Palosaari | 41b9aa0 | 2014-08-21 21:38:29 -0300 | [diff] [blame] | 743 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 744 | dev_dbg(&client->dev, "\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 745 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 746 | dev->fe_status = 0; |
| 747 | dev->delivery_system = SYS_UNDEFINED; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 748 | |
| 749 | /* TS Hi-Z */ |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 750 | if (dev->chip_id == M88RS6000_CHIP_ID) |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 751 | utmp = 0x29; |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 752 | else |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 753 | utmp = 0x27; |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 754 | ret = m88ds3103_update_bits(dev, utmp, 0x01, 0x00); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 755 | if (ret) |
| 756 | goto err; |
| 757 | |
| 758 | /* sleep */ |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 759 | ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x00); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 760 | if (ret) |
| 761 | goto err; |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 762 | ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x01); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 763 | if (ret) |
| 764 | goto err; |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 765 | ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x10); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 766 | if (ret) |
| 767 | goto err; |
| 768 | |
| 769 | return 0; |
| 770 | err: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 771 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 772 | return ret; |
| 773 | } |
| 774 | |
Mauro Carvalho Chehab | 7e3e68b | 2016-02-04 12:58:30 -0200 | [diff] [blame] | 775 | static int m88ds3103_get_frontend(struct dvb_frontend *fe, |
| 776 | struct dtv_frontend_properties *c) |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 777 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 778 | struct m88ds3103_dev *dev = fe->demodulator_priv; |
| 779 | struct i2c_client *client = dev->client; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 780 | int ret; |
| 781 | u8 buf[3]; |
Antti Palosaari | 41b9aa0 | 2014-08-21 21:38:29 -0300 | [diff] [blame] | 782 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 783 | dev_dbg(&client->dev, "\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 784 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 785 | if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) { |
Antti Palosaari | 9240c38 | 2015-04-13 21:00:09 -0300 | [diff] [blame] | 786 | ret = 0; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 787 | goto err; |
| 788 | } |
| 789 | |
| 790 | switch (c->delivery_system) { |
| 791 | case SYS_DVBS: |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 792 | ret = regmap_bulk_read(dev->regmap, 0xe0, &buf[0], 1); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 793 | if (ret) |
| 794 | goto err; |
| 795 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 796 | ret = regmap_bulk_read(dev->regmap, 0xe6, &buf[1], 1); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 797 | if (ret) |
| 798 | goto err; |
| 799 | |
| 800 | switch ((buf[0] >> 2) & 0x01) { |
| 801 | case 0: |
| 802 | c->inversion = INVERSION_OFF; |
| 803 | break; |
| 804 | case 1: |
| 805 | c->inversion = INVERSION_ON; |
| 806 | break; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | switch ((buf[1] >> 5) & 0x07) { |
| 810 | case 0: |
| 811 | c->fec_inner = FEC_7_8; |
| 812 | break; |
| 813 | case 1: |
| 814 | c->fec_inner = FEC_5_6; |
| 815 | break; |
| 816 | case 2: |
| 817 | c->fec_inner = FEC_3_4; |
| 818 | break; |
| 819 | case 3: |
| 820 | c->fec_inner = FEC_2_3; |
| 821 | break; |
| 822 | case 4: |
| 823 | c->fec_inner = FEC_1_2; |
| 824 | break; |
| 825 | default: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 826 | dev_dbg(&client->dev, "invalid fec_inner\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | c->modulation = QPSK; |
| 830 | |
| 831 | break; |
| 832 | case SYS_DVBS2: |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 833 | ret = regmap_bulk_read(dev->regmap, 0x7e, &buf[0], 1); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 834 | if (ret) |
| 835 | goto err; |
| 836 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 837 | ret = regmap_bulk_read(dev->regmap, 0x89, &buf[1], 1); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 838 | if (ret) |
| 839 | goto err; |
| 840 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 841 | ret = regmap_bulk_read(dev->regmap, 0xf2, &buf[2], 1); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 842 | if (ret) |
| 843 | goto err; |
| 844 | |
| 845 | switch ((buf[0] >> 0) & 0x0f) { |
| 846 | case 2: |
| 847 | c->fec_inner = FEC_2_5; |
| 848 | break; |
| 849 | case 3: |
| 850 | c->fec_inner = FEC_1_2; |
| 851 | break; |
| 852 | case 4: |
| 853 | c->fec_inner = FEC_3_5; |
| 854 | break; |
| 855 | case 5: |
| 856 | c->fec_inner = FEC_2_3; |
| 857 | break; |
| 858 | case 6: |
| 859 | c->fec_inner = FEC_3_4; |
| 860 | break; |
| 861 | case 7: |
| 862 | c->fec_inner = FEC_4_5; |
| 863 | break; |
| 864 | case 8: |
| 865 | c->fec_inner = FEC_5_6; |
| 866 | break; |
| 867 | case 9: |
| 868 | c->fec_inner = FEC_8_9; |
| 869 | break; |
| 870 | case 10: |
| 871 | c->fec_inner = FEC_9_10; |
| 872 | break; |
| 873 | default: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 874 | dev_dbg(&client->dev, "invalid fec_inner\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | switch ((buf[0] >> 5) & 0x01) { |
| 878 | case 0: |
| 879 | c->pilot = PILOT_OFF; |
| 880 | break; |
| 881 | case 1: |
| 882 | c->pilot = PILOT_ON; |
| 883 | break; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | switch ((buf[0] >> 6) & 0x07) { |
| 887 | case 0: |
| 888 | c->modulation = QPSK; |
| 889 | break; |
| 890 | case 1: |
| 891 | c->modulation = PSK_8; |
| 892 | break; |
| 893 | case 2: |
| 894 | c->modulation = APSK_16; |
| 895 | break; |
| 896 | case 3: |
| 897 | c->modulation = APSK_32; |
| 898 | break; |
| 899 | default: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 900 | dev_dbg(&client->dev, "invalid modulation\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | switch ((buf[1] >> 7) & 0x01) { |
| 904 | case 0: |
| 905 | c->inversion = INVERSION_OFF; |
| 906 | break; |
| 907 | case 1: |
| 908 | c->inversion = INVERSION_ON; |
| 909 | break; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | switch ((buf[2] >> 0) & 0x03) { |
| 913 | case 0: |
| 914 | c->rolloff = ROLLOFF_35; |
| 915 | break; |
| 916 | case 1: |
| 917 | c->rolloff = ROLLOFF_25; |
| 918 | break; |
| 919 | case 2: |
| 920 | c->rolloff = ROLLOFF_20; |
| 921 | break; |
| 922 | default: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 923 | dev_dbg(&client->dev, "invalid rolloff\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 924 | } |
| 925 | break; |
| 926 | default: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 927 | dev_dbg(&client->dev, "invalid delivery_system\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 928 | ret = -EINVAL; |
| 929 | goto err; |
| 930 | } |
| 931 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 932 | ret = regmap_bulk_read(dev->regmap, 0x6d, buf, 2); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 933 | if (ret) |
| 934 | goto err; |
| 935 | |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 936 | c->symbol_rate = DIV_ROUND_CLOSEST_ULL((u64)(buf[1] << 8 | buf[0] << 0) * dev->mclk, 0x10000); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 937 | |
| 938 | return 0; |
| 939 | err: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 940 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 941 | return ret; |
| 942 | } |
| 943 | |
| 944 | static int m88ds3103_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 945 | { |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 946 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Antti Palosaari | 41b9aa0 | 2014-08-21 21:38:29 -0300 | [diff] [blame] | 947 | |
Antti Palosaari | c1daf65 | 2015-04-13 20:56:13 -0300 | [diff] [blame] | 948 | if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL) |
| 949 | *snr = div_s64(c->cnr.stat[0].svalue, 100); |
| 950 | else |
| 951 | *snr = 0; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 952 | |
| 953 | return 0; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 954 | } |
| 955 | |
Antti Palosaari | 4423a2b | 2014-07-10 08:17:59 -0300 | [diff] [blame] | 956 | static int m88ds3103_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 957 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 958 | struct m88ds3103_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 41b9aa0 | 2014-08-21 21:38:29 -0300 | [diff] [blame] | 959 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 960 | *ber = dev->dvbv3_ber; |
Antti Palosaari | 4423a2b | 2014-07-10 08:17:59 -0300 | [diff] [blame] | 961 | |
| 962 | return 0; |
Antti Palosaari | 4423a2b | 2014-07-10 08:17:59 -0300 | [diff] [blame] | 963 | } |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 964 | |
| 965 | static int m88ds3103_set_tone(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 966 | enum fe_sec_tone_mode fe_sec_tone_mode) |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 967 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 968 | struct m88ds3103_dev *dev = fe->demodulator_priv; |
| 969 | struct i2c_client *client = dev->client; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 970 | int ret; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 971 | unsigned int utmp, tone, reg_a1_mask; |
Antti Palosaari | 41b9aa0 | 2014-08-21 21:38:29 -0300 | [diff] [blame] | 972 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 973 | dev_dbg(&client->dev, "fe_sec_tone_mode=%d\n", fe_sec_tone_mode); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 974 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 975 | if (!dev->warm) { |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 976 | ret = -EAGAIN; |
| 977 | goto err; |
| 978 | } |
| 979 | |
| 980 | switch (fe_sec_tone_mode) { |
| 981 | case SEC_TONE_ON: |
| 982 | tone = 0; |
Antti Palosaari | 418a97c | 2014-02-01 17:28:21 -0300 | [diff] [blame] | 983 | reg_a1_mask = 0x47; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 984 | break; |
| 985 | case SEC_TONE_OFF: |
| 986 | tone = 1; |
| 987 | reg_a1_mask = 0x00; |
| 988 | break; |
| 989 | default: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 990 | dev_dbg(&client->dev, "invalid fe_sec_tone_mode\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 991 | ret = -EINVAL; |
| 992 | goto err; |
| 993 | } |
| 994 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 995 | utmp = tone << 7 | dev->cfg->envelope_mode << 5; |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 996 | ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 997 | if (ret) |
| 998 | goto err; |
| 999 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1000 | utmp = 1 << 2; |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 1001 | ret = m88ds3103_update_bits(dev, 0xa1, reg_a1_mask, utmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1002 | if (ret) |
| 1003 | goto err; |
| 1004 | |
| 1005 | return 0; |
| 1006 | err: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1007 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1008 | return ret; |
| 1009 | } |
| 1010 | |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 1011 | static int m88ds3103_set_voltage(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 1012 | enum fe_sec_voltage fe_sec_voltage) |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 1013 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1014 | struct m88ds3103_dev *dev = fe->demodulator_priv; |
| 1015 | struct i2c_client *client = dev->client; |
Antti Palosaari | d28677f | 2014-08-21 21:06:13 -0300 | [diff] [blame] | 1016 | int ret; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1017 | unsigned int utmp; |
Antti Palosaari | d28677f | 2014-08-21 21:06:13 -0300 | [diff] [blame] | 1018 | bool voltage_sel, voltage_dis; |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 1019 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1020 | dev_dbg(&client->dev, "fe_sec_voltage=%d\n", fe_sec_voltage); |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 1021 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1022 | if (!dev->warm) { |
Antti Palosaari | d28677f | 2014-08-21 21:06:13 -0300 | [diff] [blame] | 1023 | ret = -EAGAIN; |
| 1024 | goto err; |
| 1025 | } |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 1026 | |
Antti Palosaari | d28677f | 2014-08-21 21:06:13 -0300 | [diff] [blame] | 1027 | switch (fe_sec_voltage) { |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 1028 | case SEC_VOLTAGE_18: |
Mauro Carvalho Chehab | afbd6eb | 2014-09-03 15:24:29 -0300 | [diff] [blame] | 1029 | voltage_sel = true; |
| 1030 | voltage_dis = false; |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 1031 | break; |
| 1032 | case SEC_VOLTAGE_13: |
Mauro Carvalho Chehab | afbd6eb | 2014-09-03 15:24:29 -0300 | [diff] [blame] | 1033 | voltage_sel = false; |
| 1034 | voltage_dis = false; |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 1035 | break; |
| 1036 | case SEC_VOLTAGE_OFF: |
Mauro Carvalho Chehab | afbd6eb | 2014-09-03 15:24:29 -0300 | [diff] [blame] | 1037 | voltage_sel = false; |
| 1038 | voltage_dis = true; |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 1039 | break; |
Antti Palosaari | d28677f | 2014-08-21 21:06:13 -0300 | [diff] [blame] | 1040 | default: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1041 | dev_dbg(&client->dev, "invalid fe_sec_voltage\n"); |
Antti Palosaari | d28677f | 2014-08-21 21:06:13 -0300 | [diff] [blame] | 1042 | ret = -EINVAL; |
| 1043 | goto err; |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 1044 | } |
Antti Palosaari | d28677f | 2014-08-21 21:06:13 -0300 | [diff] [blame] | 1045 | |
| 1046 | /* output pin polarity */ |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1047 | voltage_sel ^= dev->cfg->lnb_hv_pol; |
| 1048 | voltage_dis ^= dev->cfg->lnb_en_pol; |
Antti Palosaari | d28677f | 2014-08-21 21:06:13 -0300 | [diff] [blame] | 1049 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1050 | utmp = voltage_dis << 1 | voltage_sel << 0; |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 1051 | ret = m88ds3103_update_bits(dev, 0xa2, 0x03, utmp); |
Antti Palosaari | d28677f | 2014-08-21 21:06:13 -0300 | [diff] [blame] | 1052 | if (ret) |
| 1053 | goto err; |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 1054 | |
| 1055 | return 0; |
Antti Palosaari | d28677f | 2014-08-21 21:06:13 -0300 | [diff] [blame] | 1056 | err: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1057 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | d28677f | 2014-08-21 21:06:13 -0300 | [diff] [blame] | 1058 | return ret; |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 1059 | } |
| 1060 | |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1061 | static int m88ds3103_diseqc_send_master_cmd(struct dvb_frontend *fe, |
| 1062 | struct dvb_diseqc_master_cmd *diseqc_cmd) |
| 1063 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1064 | struct m88ds3103_dev *dev = fe->demodulator_priv; |
| 1065 | struct i2c_client *client = dev->client; |
Antti Palosaari | befa0cc | 2015-04-14 12:56:24 -0300 | [diff] [blame] | 1066 | int ret; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1067 | unsigned int utmp; |
Antti Palosaari | befa0cc | 2015-04-14 12:56:24 -0300 | [diff] [blame] | 1068 | unsigned long timeout; |
Antti Palosaari | 41b9aa0 | 2014-08-21 21:38:29 -0300 | [diff] [blame] | 1069 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1070 | dev_dbg(&client->dev, "msg=%*ph\n", |
| 1071 | diseqc_cmd->msg_len, diseqc_cmd->msg); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1072 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1073 | if (!dev->warm) { |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1074 | ret = -EAGAIN; |
| 1075 | goto err; |
| 1076 | } |
| 1077 | |
| 1078 | if (diseqc_cmd->msg_len < 3 || diseqc_cmd->msg_len > 6) { |
| 1079 | ret = -EINVAL; |
| 1080 | goto err; |
| 1081 | } |
| 1082 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1083 | utmp = dev->cfg->envelope_mode << 5; |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 1084 | ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1085 | if (ret) |
| 1086 | goto err; |
| 1087 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1088 | ret = regmap_bulk_write(dev->regmap, 0xa3, diseqc_cmd->msg, |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1089 | diseqc_cmd->msg_len); |
| 1090 | if (ret) |
| 1091 | goto err; |
| 1092 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1093 | ret = regmap_write(dev->regmap, 0xa1, |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1094 | (diseqc_cmd->msg_len - 1) << 3 | 0x07); |
| 1095 | if (ret) |
| 1096 | goto err; |
| 1097 | |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1098 | /* wait DiSEqC TX ready */ |
Antti Palosaari | befa0cc | 2015-04-14 12:56:24 -0300 | [diff] [blame] | 1099 | #define SEND_MASTER_CMD_TIMEOUT 120 |
| 1100 | timeout = jiffies + msecs_to_jiffies(SEND_MASTER_CMD_TIMEOUT); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1101 | |
Antti Palosaari | 9ef3cdc | 2016-06-29 20:39:45 -0300 | [diff] [blame] | 1102 | /* DiSEqC message period is 13.5 ms per byte */ |
| 1103 | utmp = diseqc_cmd->msg_len * 13500; |
| 1104 | usleep_range(utmp - 4000, utmp); |
Antti Palosaari | befa0cc | 2015-04-14 12:56:24 -0300 | [diff] [blame] | 1105 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1106 | for (utmp = 1; !time_after(jiffies, timeout) && utmp;) { |
| 1107 | ret = regmap_read(dev->regmap, 0xa1, &utmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1108 | if (ret) |
| 1109 | goto err; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1110 | utmp = (utmp >> 6) & 0x1; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1111 | } |
| 1112 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1113 | if (utmp == 0) { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1114 | dev_dbg(&client->dev, "diseqc tx took %u ms\n", |
Antti Palosaari | befa0cc | 2015-04-14 12:56:24 -0300 | [diff] [blame] | 1115 | jiffies_to_msecs(jiffies) - |
| 1116 | (jiffies_to_msecs(timeout) - SEND_MASTER_CMD_TIMEOUT)); |
| 1117 | } else { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1118 | dev_dbg(&client->dev, "diseqc tx timeout\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1119 | |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 1120 | ret = m88ds3103_update_bits(dev, 0xa1, 0xc0, 0x40); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1121 | if (ret) |
| 1122 | goto err; |
| 1123 | } |
| 1124 | |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 1125 | ret = m88ds3103_update_bits(dev, 0xa2, 0xc0, 0x80); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1126 | if (ret) |
| 1127 | goto err; |
| 1128 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1129 | if (utmp == 1) { |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1130 | ret = -ETIMEDOUT; |
| 1131 | goto err; |
| 1132 | } |
| 1133 | |
| 1134 | return 0; |
| 1135 | err: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1136 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1137 | return ret; |
| 1138 | } |
| 1139 | |
| 1140 | static int m88ds3103_diseqc_send_burst(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 1141 | enum fe_sec_mini_cmd fe_sec_mini_cmd) |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1142 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1143 | struct m88ds3103_dev *dev = fe->demodulator_priv; |
| 1144 | struct i2c_client *client = dev->client; |
Antti Palosaari | befa0cc | 2015-04-14 12:56:24 -0300 | [diff] [blame] | 1145 | int ret; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1146 | unsigned int utmp, burst; |
Antti Palosaari | befa0cc | 2015-04-14 12:56:24 -0300 | [diff] [blame] | 1147 | unsigned long timeout; |
Antti Palosaari | 41b9aa0 | 2014-08-21 21:38:29 -0300 | [diff] [blame] | 1148 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1149 | dev_dbg(&client->dev, "fe_sec_mini_cmd=%d\n", fe_sec_mini_cmd); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1150 | |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1151 | if (!dev->warm) { |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1152 | ret = -EAGAIN; |
| 1153 | goto err; |
| 1154 | } |
| 1155 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1156 | utmp = dev->cfg->envelope_mode << 5; |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 1157 | ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1158 | if (ret) |
| 1159 | goto err; |
| 1160 | |
| 1161 | switch (fe_sec_mini_cmd) { |
| 1162 | case SEC_MINI_A: |
| 1163 | burst = 0x02; |
| 1164 | break; |
| 1165 | case SEC_MINI_B: |
| 1166 | burst = 0x01; |
| 1167 | break; |
| 1168 | default: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1169 | dev_dbg(&client->dev, "invalid fe_sec_mini_cmd\n"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1170 | ret = -EINVAL; |
| 1171 | goto err; |
| 1172 | } |
| 1173 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1174 | ret = regmap_write(dev->regmap, 0xa1, burst); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1175 | if (ret) |
| 1176 | goto err; |
| 1177 | |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1178 | /* wait DiSEqC TX ready */ |
Antti Palosaari | befa0cc | 2015-04-14 12:56:24 -0300 | [diff] [blame] | 1179 | #define SEND_BURST_TIMEOUT 40 |
| 1180 | timeout = jiffies + msecs_to_jiffies(SEND_BURST_TIMEOUT); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1181 | |
Antti Palosaari | befa0cc | 2015-04-14 12:56:24 -0300 | [diff] [blame] | 1182 | /* DiSEqC ToneBurst period is 12.5 ms */ |
| 1183 | usleep_range(8500, 12500); |
| 1184 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1185 | for (utmp = 1; !time_after(jiffies, timeout) && utmp;) { |
| 1186 | ret = regmap_read(dev->regmap, 0xa1, &utmp); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1187 | if (ret) |
| 1188 | goto err; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1189 | utmp = (utmp >> 6) & 0x1; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1190 | } |
| 1191 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1192 | if (utmp == 0) { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1193 | dev_dbg(&client->dev, "diseqc tx took %u ms\n", |
Antti Palosaari | befa0cc | 2015-04-14 12:56:24 -0300 | [diff] [blame] | 1194 | jiffies_to_msecs(jiffies) - |
| 1195 | (jiffies_to_msecs(timeout) - SEND_BURST_TIMEOUT)); |
| 1196 | } else { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1197 | dev_dbg(&client->dev, "diseqc tx timeout\n"); |
Antti Palosaari | befa0cc | 2015-04-14 12:56:24 -0300 | [diff] [blame] | 1198 | |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 1199 | ret = m88ds3103_update_bits(dev, 0xa1, 0xc0, 0x40); |
Antti Palosaari | befa0cc | 2015-04-14 12:56:24 -0300 | [diff] [blame] | 1200 | if (ret) |
| 1201 | goto err; |
| 1202 | } |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1203 | |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 1204 | ret = m88ds3103_update_bits(dev, 0xa2, 0xc0, 0x80); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1205 | if (ret) |
| 1206 | goto err; |
| 1207 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1208 | if (utmp == 1) { |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1209 | ret = -ETIMEDOUT; |
| 1210 | goto err; |
| 1211 | } |
| 1212 | |
| 1213 | return 0; |
| 1214 | err: |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1215 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1216 | return ret; |
| 1217 | } |
| 1218 | |
| 1219 | static int m88ds3103_get_tune_settings(struct dvb_frontend *fe, |
| 1220 | struct dvb_frontend_tune_settings *s) |
| 1221 | { |
| 1222 | s->min_delay_ms = 3000; |
| 1223 | |
| 1224 | return 0; |
| 1225 | } |
| 1226 | |
Antti Palosaari | 44b9055 | 2013-11-19 20:32:42 -0300 | [diff] [blame] | 1227 | static void m88ds3103_release(struct dvb_frontend *fe) |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1228 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1229 | struct m88ds3103_dev *dev = fe->demodulator_priv; |
| 1230 | struct i2c_client *client = dev->client; |
Antti Palosaari | 41b9aa0 | 2014-08-21 21:38:29 -0300 | [diff] [blame] | 1231 | |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1232 | i2c_unregister_device(client); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1233 | } |
| 1234 | |
Peter Rosin | e00fed4 | 2016-04-20 08:41:02 +0200 | [diff] [blame] | 1235 | static int m88ds3103_select(struct i2c_mux_core *muxc, u32 chan) |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1236 | { |
Peter Rosin | e00fed4 | 2016-04-20 08:41:02 +0200 | [diff] [blame] | 1237 | struct m88ds3103_dev *dev = i2c_mux_priv(muxc); |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1238 | struct i2c_client *client = dev->client; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1239 | int ret; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1240 | struct i2c_msg msg = { |
| 1241 | .addr = client->addr, |
| 1242 | .flags = 0, |
| 1243 | .len = 2, |
| 1244 | .buf = "\x03\x11", |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1245 | }; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1246 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1247 | /* Open tuner I2C repeater for 1 xfer, closes automatically */ |
| 1248 | ret = __i2c_transfer(client->adapter, &msg, 1); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1249 | if (ret != 1) { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1250 | dev_warn(&client->dev, "i2c wr failed=%d\n", ret); |
Antti Palosaari | 44b9055 | 2013-11-19 20:32:42 -0300 | [diff] [blame] | 1251 | if (ret >= 0) |
| 1252 | ret = -EREMOTEIO; |
Antti Palosaari | 44b9055 | 2013-11-19 20:32:42 -0300 | [diff] [blame] | 1253 | return ret; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1254 | } |
| 1255 | |
Antti Palosaari | 44b9055 | 2013-11-19 20:32:42 -0300 | [diff] [blame] | 1256 | return 0; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1257 | } |
| 1258 | |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1259 | /* |
| 1260 | * XXX: That is wrapper to m88ds3103_probe() via driver core in order to provide |
| 1261 | * proper I2C client for legacy media attach binding. |
| 1262 | * New users must use I2C client binding directly! |
| 1263 | */ |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1264 | struct dvb_frontend *m88ds3103_attach(const struct m88ds3103_config *cfg, |
| 1265 | struct i2c_adapter *i2c, struct i2c_adapter **tuner_i2c_adapter) |
| 1266 | { |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1267 | struct i2c_client *client; |
| 1268 | struct i2c_board_info board_info; |
| 1269 | struct m88ds3103_platform_data pdata; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1270 | |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1271 | pdata.clk = cfg->clock; |
| 1272 | pdata.i2c_wr_max = cfg->i2c_wr_max; |
| 1273 | pdata.ts_mode = cfg->ts_mode; |
| 1274 | pdata.ts_clk = cfg->ts_clk; |
| 1275 | pdata.ts_clk_pol = cfg->ts_clk_pol; |
| 1276 | pdata.spec_inv = cfg->spec_inv; |
| 1277 | pdata.agc = cfg->agc; |
| 1278 | pdata.agc_inv = cfg->agc_inv; |
| 1279 | pdata.clk_out = cfg->clock_out; |
| 1280 | pdata.envelope_mode = cfg->envelope_mode; |
| 1281 | pdata.lnb_hv_pol = cfg->lnb_hv_pol; |
| 1282 | pdata.lnb_en_pol = cfg->lnb_en_pol; |
| 1283 | pdata.attach_in_use = true; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1284 | |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1285 | memset(&board_info, 0, sizeof(board_info)); |
| 1286 | strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE); |
| 1287 | board_info.addr = cfg->i2c_addr; |
| 1288 | board_info.platform_data = &pdata; |
| 1289 | client = i2c_new_device(i2c, &board_info); |
| 1290 | if (!client || !client->dev.driver) |
| 1291 | return NULL; |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1292 | |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1293 | *tuner_i2c_adapter = pdata.get_i2c_adapter(client); |
| 1294 | return pdata.get_dvb_frontend(client); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1295 | } |
| 1296 | EXPORT_SYMBOL(m88ds3103_attach); |
| 1297 | |
Max Kellermann | bd336e6 | 2016-08-09 18:32:21 -0300 | [diff] [blame^] | 1298 | static const struct dvb_frontend_ops m88ds3103_ops = { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1299 | .delsys = {SYS_DVBS, SYS_DVBS2}, |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1300 | .info = { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1301 | .name = "Montage Technology M88DS3103", |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1302 | .frequency_min = 950000, |
| 1303 | .frequency_max = 2150000, |
| 1304 | .frequency_tolerance = 5000, |
| 1305 | .symbol_rate_min = 1000000, |
| 1306 | .symbol_rate_max = 45000000, |
| 1307 | .caps = FE_CAN_INVERSION_AUTO | |
| 1308 | FE_CAN_FEC_1_2 | |
| 1309 | FE_CAN_FEC_2_3 | |
| 1310 | FE_CAN_FEC_3_4 | |
| 1311 | FE_CAN_FEC_4_5 | |
| 1312 | FE_CAN_FEC_5_6 | |
| 1313 | FE_CAN_FEC_6_7 | |
| 1314 | FE_CAN_FEC_7_8 | |
| 1315 | FE_CAN_FEC_8_9 | |
| 1316 | FE_CAN_FEC_AUTO | |
| 1317 | FE_CAN_QPSK | |
| 1318 | FE_CAN_RECOVER | |
| 1319 | FE_CAN_2G_MODULATION |
| 1320 | }, |
| 1321 | |
| 1322 | .release = m88ds3103_release, |
| 1323 | |
| 1324 | .get_tune_settings = m88ds3103_get_tune_settings, |
| 1325 | |
| 1326 | .init = m88ds3103_init, |
| 1327 | .sleep = m88ds3103_sleep, |
| 1328 | |
| 1329 | .set_frontend = m88ds3103_set_frontend, |
| 1330 | .get_frontend = m88ds3103_get_frontend, |
| 1331 | |
| 1332 | .read_status = m88ds3103_read_status, |
| 1333 | .read_snr = m88ds3103_read_snr, |
Antti Palosaari | 4423a2b | 2014-07-10 08:17:59 -0300 | [diff] [blame] | 1334 | .read_ber = m88ds3103_read_ber, |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1335 | |
| 1336 | .diseqc_send_master_cmd = m88ds3103_diseqc_send_master_cmd, |
| 1337 | .diseqc_send_burst = m88ds3103_diseqc_send_burst, |
| 1338 | |
| 1339 | .set_tone = m88ds3103_set_tone, |
nibble.max | 79d0933 | 2014-08-11 01:22:45 -0300 | [diff] [blame] | 1340 | .set_voltage = m88ds3103_set_voltage, |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1341 | }; |
| 1342 | |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1343 | static struct dvb_frontend *m88ds3103_get_dvb_frontend(struct i2c_client *client) |
| 1344 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1345 | struct m88ds3103_dev *dev = i2c_get_clientdata(client); |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1346 | |
| 1347 | dev_dbg(&client->dev, "\n"); |
| 1348 | |
| 1349 | return &dev->fe; |
| 1350 | } |
| 1351 | |
| 1352 | static struct i2c_adapter *m88ds3103_get_i2c_adapter(struct i2c_client *client) |
| 1353 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1354 | struct m88ds3103_dev *dev = i2c_get_clientdata(client); |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1355 | |
| 1356 | dev_dbg(&client->dev, "\n"); |
| 1357 | |
Peter Rosin | e00fed4 | 2016-04-20 08:41:02 +0200 | [diff] [blame] | 1358 | return dev->muxc->adapter[0]; |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | static int m88ds3103_probe(struct i2c_client *client, |
| 1362 | const struct i2c_device_id *id) |
| 1363 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1364 | struct m88ds3103_dev *dev; |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1365 | struct m88ds3103_platform_data *pdata = client->dev.platform_data; |
| 1366 | int ret; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1367 | unsigned int utmp; |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1368 | |
| 1369 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 1370 | if (!dev) { |
| 1371 | ret = -ENOMEM; |
| 1372 | goto err; |
| 1373 | } |
| 1374 | |
| 1375 | dev->client = client; |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1376 | dev->config.clock = pdata->clk; |
| 1377 | dev->config.i2c_wr_max = pdata->i2c_wr_max; |
| 1378 | dev->config.ts_mode = pdata->ts_mode; |
Antti Palosaari | f5d9b88 | 2016-06-29 20:39:47 -0300 | [diff] [blame] | 1379 | dev->config.ts_clk = pdata->ts_clk * 1000; |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1380 | dev->config.ts_clk_pol = pdata->ts_clk_pol; |
| 1381 | dev->config.spec_inv = pdata->spec_inv; |
| 1382 | dev->config.agc_inv = pdata->agc_inv; |
| 1383 | dev->config.clock_out = pdata->clk_out; |
| 1384 | dev->config.envelope_mode = pdata->envelope_mode; |
| 1385 | dev->config.agc = pdata->agc; |
| 1386 | dev->config.lnb_hv_pol = pdata->lnb_hv_pol; |
| 1387 | dev->config.lnb_en_pol = pdata->lnb_en_pol; |
| 1388 | dev->cfg = &dev->config; |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1389 | /* create regmap */ |
| 1390 | dev->regmap_config.reg_bits = 8, |
| 1391 | dev->regmap_config.val_bits = 8, |
| 1392 | dev->regmap_config.lock_arg = dev, |
| 1393 | dev->regmap = devm_regmap_init_i2c(client, &dev->regmap_config); |
| 1394 | if (IS_ERR(dev->regmap)) { |
| 1395 | ret = PTR_ERR(dev->regmap); |
| 1396 | goto err_kfree; |
| 1397 | } |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1398 | |
| 1399 | /* 0x00: chip id[6:0], 0x01: chip ver[7:0], 0x02: chip ver[15:8] */ |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1400 | ret = regmap_read(dev->regmap, 0x00, &utmp); |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1401 | if (ret) |
| 1402 | goto err_kfree; |
| 1403 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1404 | dev->chip_id = utmp >> 1; |
| 1405 | dev_dbg(&client->dev, "chip_id=%02x\n", dev->chip_id); |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1406 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1407 | switch (dev->chip_id) { |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1408 | case M88RS6000_CHIP_ID: |
| 1409 | case M88DS3103_CHIP_ID: |
| 1410 | break; |
| 1411 | default: |
| 1412 | goto err_kfree; |
| 1413 | } |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1414 | |
| 1415 | switch (dev->cfg->clock_out) { |
| 1416 | case M88DS3103_CLOCK_OUT_DISABLED: |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1417 | utmp = 0x80; |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1418 | break; |
| 1419 | case M88DS3103_CLOCK_OUT_ENABLED: |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1420 | utmp = 0x00; |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1421 | break; |
| 1422 | case M88DS3103_CLOCK_OUT_ENABLED_DIV2: |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1423 | utmp = 0x10; |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1424 | break; |
| 1425 | default: |
Dan Carpenter | 4347df6 | 2015-06-02 07:20:00 -0300 | [diff] [blame] | 1426 | ret = -EINVAL; |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1427 | goto err_kfree; |
| 1428 | } |
| 1429 | |
Antti Palosaari | 334ef18 | 2016-06-29 20:39:46 -0300 | [diff] [blame] | 1430 | if (!pdata->ts_clk) { |
| 1431 | ret = -EINVAL; |
| 1432 | goto err_kfree; |
| 1433 | } |
| 1434 | |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1435 | /* 0x29 register is defined differently for m88rs6000. */ |
| 1436 | /* set internal tuner address to 0x21 */ |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1437 | if (dev->chip_id == M88RS6000_CHIP_ID) |
| 1438 | utmp = 0x00; |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1439 | |
Antti Palosaari | 478932b | 2015-04-16 22:43:52 -0300 | [diff] [blame] | 1440 | ret = regmap_write(dev->regmap, 0x29, utmp); |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1441 | if (ret) |
| 1442 | goto err_kfree; |
| 1443 | |
| 1444 | /* sleep */ |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 1445 | ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x00); |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1446 | if (ret) |
| 1447 | goto err_kfree; |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 1448 | ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x01); |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1449 | if (ret) |
| 1450 | goto err_kfree; |
Antti Palosaari | 56ea37d | 2015-10-03 18:35:14 -0300 | [diff] [blame] | 1451 | ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x10); |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1452 | if (ret) |
| 1453 | goto err_kfree; |
| 1454 | |
| 1455 | /* create mux i2c adapter for tuner */ |
Peter Rosin | e00fed4 | 2016-04-20 08:41:02 +0200 | [diff] [blame] | 1456 | dev->muxc = i2c_mux_alloc(client->adapter, &client->dev, 1, 0, 0, |
| 1457 | m88ds3103_select, NULL); |
| 1458 | if (!dev->muxc) { |
Dan Carpenter | 4347df6 | 2015-06-02 07:20:00 -0300 | [diff] [blame] | 1459 | ret = -ENOMEM; |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1460 | goto err_kfree; |
Dan Carpenter | 4347df6 | 2015-06-02 07:20:00 -0300 | [diff] [blame] | 1461 | } |
Peter Rosin | e00fed4 | 2016-04-20 08:41:02 +0200 | [diff] [blame] | 1462 | dev->muxc->priv = dev; |
| 1463 | ret = i2c_mux_add_adapter(dev->muxc, 0, 0, 0); |
| 1464 | if (ret) |
| 1465 | goto err_kfree; |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1466 | |
| 1467 | /* create dvb_frontend */ |
| 1468 | memcpy(&dev->fe.ops, &m88ds3103_ops, sizeof(struct dvb_frontend_ops)); |
| 1469 | if (dev->chip_id == M88RS6000_CHIP_ID) |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1470 | strncpy(dev->fe.ops.info.name, "Montage Technology M88RS6000", |
| 1471 | sizeof(dev->fe.ops.info.name)); |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1472 | if (!pdata->attach_in_use) |
| 1473 | dev->fe.ops.release = NULL; |
| 1474 | dev->fe.demodulator_priv = dev; |
| 1475 | i2c_set_clientdata(client, dev); |
| 1476 | |
| 1477 | /* setup callbacks */ |
| 1478 | pdata->get_dvb_frontend = m88ds3103_get_dvb_frontend; |
| 1479 | pdata->get_i2c_adapter = m88ds3103_get_i2c_adapter; |
| 1480 | return 0; |
| 1481 | err_kfree: |
| 1482 | kfree(dev); |
| 1483 | err: |
| 1484 | dev_dbg(&client->dev, "failed=%d\n", ret); |
| 1485 | return ret; |
| 1486 | } |
| 1487 | |
| 1488 | static int m88ds3103_remove(struct i2c_client *client) |
| 1489 | { |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1490 | struct m88ds3103_dev *dev = i2c_get_clientdata(client); |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1491 | |
| 1492 | dev_dbg(&client->dev, "\n"); |
| 1493 | |
Peter Rosin | e00fed4 | 2016-04-20 08:41:02 +0200 | [diff] [blame] | 1494 | i2c_mux_del_adapters(dev->muxc); |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1495 | |
| 1496 | kfree(dev); |
| 1497 | return 0; |
| 1498 | } |
| 1499 | |
| 1500 | static const struct i2c_device_id m88ds3103_id_table[] = { |
| 1501 | {"m88ds3103", 0}, |
| 1502 | {} |
| 1503 | }; |
| 1504 | MODULE_DEVICE_TABLE(i2c, m88ds3103_id_table); |
| 1505 | |
| 1506 | static struct i2c_driver m88ds3103_driver = { |
| 1507 | .driver = { |
Antti Palosaari | f01919e8 | 2015-04-16 20:04:55 -0300 | [diff] [blame] | 1508 | .name = "m88ds3103", |
| 1509 | .suppress_bind_attrs = true, |
| 1510 | }, |
| 1511 | .probe = m88ds3103_probe, |
| 1512 | .remove = m88ds3103_remove, |
| 1513 | .id_table = m88ds3103_id_table, |
| 1514 | }; |
| 1515 | |
| 1516 | module_i2c_driver(m88ds3103_driver); |
| 1517 | |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1518 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
Antti Palosaari | 7978b8a | 2015-04-16 21:36:00 -0300 | [diff] [blame] | 1519 | MODULE_DESCRIPTION("Montage Technology M88DS3103 DVB-S/S2 demodulator driver"); |
Antti Palosaari | 395d00d | 2013-02-25 08:39:16 -0300 | [diff] [blame] | 1520 | MODULE_LICENSE("GPL"); |
| 1521 | MODULE_FIRMWARE(M88DS3103_FIRMWARE); |
nibble.max | f4df95b | 2014-10-30 05:01:14 -0300 | [diff] [blame] | 1522 | MODULE_FIRMWARE(M88RS6000_FIRMWARE); |