Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Elonics E4000 silicon tuner driver |
| 3 | * |
| 4 | * Copyright (C) 2012 Antti Palosaari <crope@iki.fi> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
| 21 | #include "e4000_priv.h" |
Antti Palosaari | 35c00c9 | 2013-09-02 13:06:13 -0300 | [diff] [blame] | 22 | #include <linux/math64.h> |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 23 | |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 24 | static int e4000_init(struct dvb_frontend *fe) |
| 25 | { |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 26 | struct e4000 *s = fe->tuner_priv; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 27 | int ret; |
| 28 | |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 29 | dev_dbg(&s->client->dev, "\n"); |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 30 | |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 31 | /* dummy I2C to ensure I2C wakes up */ |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 32 | ret = regmap_write(s->regmap, 0x02, 0x40); |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 33 | |
| 34 | /* reset */ |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 35 | ret = regmap_write(s->regmap, 0x00, 0x01); |
| 36 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 37 | goto err; |
| 38 | |
| 39 | /* disable output clock */ |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 40 | ret = regmap_write(s->regmap, 0x06, 0x00); |
| 41 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 42 | goto err; |
| 43 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 44 | ret = regmap_write(s->regmap, 0x7a, 0x96); |
| 45 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 46 | goto err; |
| 47 | |
| 48 | /* configure gains */ |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 49 | ret = regmap_bulk_write(s->regmap, 0x7e, "\x01\xfe", 2); |
| 50 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 51 | goto err; |
| 52 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 53 | ret = regmap_write(s->regmap, 0x82, 0x00); |
| 54 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 55 | goto err; |
| 56 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 57 | ret = regmap_write(s->regmap, 0x24, 0x05); |
| 58 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 59 | goto err; |
| 60 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 61 | ret = regmap_bulk_write(s->regmap, 0x87, "\x20\x01", 2); |
| 62 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 63 | goto err; |
| 64 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 65 | ret = regmap_bulk_write(s->regmap, 0x9f, "\x7f\x07", 2); |
| 66 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 67 | goto err; |
| 68 | |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 69 | /* DC offset control */ |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 70 | ret = regmap_write(s->regmap, 0x2d, 0x1f); |
| 71 | if (ret) |
Antti Palosaari | 8514611 | 2013-07-24 02:04:12 -0300 | [diff] [blame] | 72 | goto err; |
| 73 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 74 | ret = regmap_bulk_write(s->regmap, 0x70, "\x01\x01", 2); |
| 75 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 76 | goto err; |
| 77 | |
| 78 | /* gain control */ |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 79 | ret = regmap_write(s->regmap, 0x1a, 0x17); |
| 80 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 81 | goto err; |
| 82 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 83 | ret = regmap_write(s->regmap, 0x1f, 0x1a); |
| 84 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 85 | goto err; |
| 86 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 87 | s->active = true; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 88 | err: |
Antti Palosaari | 1c73fc6 | 2014-02-08 04:21:10 -0300 | [diff] [blame] | 89 | if (ret) |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 90 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 91 | |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 92 | return ret; |
| 93 | } |
| 94 | |
| 95 | static int e4000_sleep(struct dvb_frontend *fe) |
| 96 | { |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 97 | struct e4000 *s = fe->tuner_priv; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 98 | int ret; |
| 99 | |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 100 | dev_dbg(&s->client->dev, "\n"); |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 101 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 102 | s->active = false; |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 103 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 104 | ret = regmap_write(s->regmap, 0x00, 0x00); |
| 105 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 106 | goto err; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 107 | err: |
Antti Palosaari | 1c73fc6 | 2014-02-08 04:21:10 -0300 | [diff] [blame] | 108 | if (ret) |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 109 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 110 | |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 111 | return ret; |
| 112 | } |
| 113 | |
| 114 | static int e4000_set_params(struct dvb_frontend *fe) |
| 115 | { |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 116 | struct e4000 *s = fe->tuner_priv; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 117 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 118 | int ret, i, sigma_delta; |
Antti Palosaari | ac8f392 | 2014-03-14 15:22:24 -0300 | [diff] [blame] | 119 | unsigned int pll_n, pll_f; |
Antti Palosaari | 0ed0b22 | 2014-01-27 03:13:19 -0300 | [diff] [blame] | 120 | u64 f_vco; |
Antti Palosaari | 8514611 | 2013-07-24 02:04:12 -0300 | [diff] [blame] | 121 | u8 buf[5], i_data[4], q_data[4]; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 122 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 123 | dev_dbg(&s->client->dev, |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 124 | "delivery_system=%d frequency=%u bandwidth_hz=%u\n", |
| 125 | c->delivery_system, c->frequency, c->bandwidth_hz); |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 126 | |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 127 | /* gain control manual */ |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 128 | ret = regmap_write(s->regmap, 0x1a, 0x00); |
| 129 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 130 | goto err; |
| 131 | |
| 132 | /* PLL */ |
| 133 | for (i = 0; i < ARRAY_SIZE(e4000_pll_lut); i++) { |
| 134 | if (c->frequency <= e4000_pll_lut[i].freq) |
| 135 | break; |
| 136 | } |
| 137 | |
Julia Lawall | 58f087c | 2013-12-29 19:47:35 -0300 | [diff] [blame] | 138 | if (i == ARRAY_SIZE(e4000_pll_lut)) { |
| 139 | ret = -EINVAL; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 140 | goto err; |
Julia Lawall | 58f087c | 2013-12-29 19:47:35 -0300 | [diff] [blame] | 141 | } |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 142 | |
Antti Palosaari | 0ed0b22 | 2014-01-27 03:13:19 -0300 | [diff] [blame] | 143 | f_vco = 1ull * c->frequency * e4000_pll_lut[i].mul; |
Antti Palosaari | ac8f392 | 2014-03-14 15:22:24 -0300 | [diff] [blame] | 144 | pll_n = div_u64_rem(f_vco, s->clock, &pll_f); |
| 145 | sigma_delta = div_u64(0x10000ULL * pll_f, s->clock); |
| 146 | buf[0] = pll_n; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 147 | buf[1] = (sigma_delta >> 0) & 0xff; |
| 148 | buf[2] = (sigma_delta >> 8) & 0xff; |
| 149 | buf[3] = 0x00; |
| 150 | buf[4] = e4000_pll_lut[i].div; |
| 151 | |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 152 | dev_dbg(&s->client->dev, "f_vco=%llu pll div=%d sigma_delta=%04x\n", |
| 153 | f_vco, buf[0], sigma_delta); |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 154 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 155 | ret = regmap_bulk_write(s->regmap, 0x09, buf, 5); |
| 156 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 157 | goto err; |
| 158 | |
| 159 | /* LNA filter (RF filter) */ |
| 160 | for (i = 0; i < ARRAY_SIZE(e400_lna_filter_lut); i++) { |
| 161 | if (c->frequency <= e400_lna_filter_lut[i].freq) |
| 162 | break; |
| 163 | } |
| 164 | |
Julia Lawall | 58f087c | 2013-12-29 19:47:35 -0300 | [diff] [blame] | 165 | if (i == ARRAY_SIZE(e400_lna_filter_lut)) { |
| 166 | ret = -EINVAL; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 167 | goto err; |
Julia Lawall | 58f087c | 2013-12-29 19:47:35 -0300 | [diff] [blame] | 168 | } |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 169 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 170 | ret = regmap_write(s->regmap, 0x10, e400_lna_filter_lut[i].val); |
| 171 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 172 | goto err; |
| 173 | |
| 174 | /* IF filters */ |
| 175 | for (i = 0; i < ARRAY_SIZE(e4000_if_filter_lut); i++) { |
| 176 | if (c->bandwidth_hz <= e4000_if_filter_lut[i].freq) |
| 177 | break; |
| 178 | } |
| 179 | |
Julia Lawall | 58f087c | 2013-12-29 19:47:35 -0300 | [diff] [blame] | 180 | if (i == ARRAY_SIZE(e4000_if_filter_lut)) { |
| 181 | ret = -EINVAL; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 182 | goto err; |
Julia Lawall | 58f087c | 2013-12-29 19:47:35 -0300 | [diff] [blame] | 183 | } |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 184 | |
| 185 | buf[0] = e4000_if_filter_lut[i].reg11_val; |
| 186 | buf[1] = e4000_if_filter_lut[i].reg12_val; |
| 187 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 188 | ret = regmap_bulk_write(s->regmap, 0x11, buf, 2); |
| 189 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 190 | goto err; |
| 191 | |
| 192 | /* frequency band */ |
| 193 | for (i = 0; i < ARRAY_SIZE(e4000_band_lut); i++) { |
| 194 | if (c->frequency <= e4000_band_lut[i].freq) |
| 195 | break; |
| 196 | } |
| 197 | |
Julia Lawall | 58f087c | 2013-12-29 19:47:35 -0300 | [diff] [blame] | 198 | if (i == ARRAY_SIZE(e4000_band_lut)) { |
| 199 | ret = -EINVAL; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 200 | goto err; |
Julia Lawall | 58f087c | 2013-12-29 19:47:35 -0300 | [diff] [blame] | 201 | } |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 202 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 203 | ret = regmap_write(s->regmap, 0x07, e4000_band_lut[i].reg07_val); |
| 204 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 205 | goto err; |
| 206 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 207 | ret = regmap_write(s->regmap, 0x78, e4000_band_lut[i].reg78_val); |
| 208 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 209 | goto err; |
| 210 | |
Antti Palosaari | 8514611 | 2013-07-24 02:04:12 -0300 | [diff] [blame] | 211 | /* DC offset */ |
| 212 | for (i = 0; i < 4; i++) { |
| 213 | if (i == 0) |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 214 | ret = regmap_bulk_write(s->regmap, 0x15, "\x00\x7e\x24", 3); |
Antti Palosaari | 8514611 | 2013-07-24 02:04:12 -0300 | [diff] [blame] | 215 | else if (i == 1) |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 216 | ret = regmap_bulk_write(s->regmap, 0x15, "\x00\x7f", 2); |
Antti Palosaari | 8514611 | 2013-07-24 02:04:12 -0300 | [diff] [blame] | 217 | else if (i == 2) |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 218 | ret = regmap_bulk_write(s->regmap, 0x15, "\x01", 1); |
Antti Palosaari | 8514611 | 2013-07-24 02:04:12 -0300 | [diff] [blame] | 219 | else |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 220 | ret = regmap_bulk_write(s->regmap, 0x16, "\x7e", 1); |
Antti Palosaari | 8514611 | 2013-07-24 02:04:12 -0300 | [diff] [blame] | 221 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 222 | if (ret) |
Antti Palosaari | 8514611 | 2013-07-24 02:04:12 -0300 | [diff] [blame] | 223 | goto err; |
| 224 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 225 | ret = regmap_write(s->regmap, 0x29, 0x01); |
| 226 | if (ret) |
Antti Palosaari | 8514611 | 2013-07-24 02:04:12 -0300 | [diff] [blame] | 227 | goto err; |
| 228 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 229 | ret = regmap_bulk_read(s->regmap, 0x2a, buf, 3); |
| 230 | if (ret) |
Antti Palosaari | 8514611 | 2013-07-24 02:04:12 -0300 | [diff] [blame] | 231 | goto err; |
| 232 | |
| 233 | i_data[i] = (((buf[2] >> 0) & 0x3) << 6) | (buf[0] & 0x3f); |
| 234 | q_data[i] = (((buf[2] >> 4) & 0x3) << 6) | (buf[1] & 0x3f); |
| 235 | } |
| 236 | |
Antti Palosaari | d4992da | 2013-07-24 18:33:51 -0300 | [diff] [blame] | 237 | swap(q_data[2], q_data[3]); |
| 238 | swap(i_data[2], i_data[3]); |
| 239 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 240 | ret = regmap_bulk_write(s->regmap, 0x50, q_data, 4); |
| 241 | if (ret) |
Antti Palosaari | 8514611 | 2013-07-24 02:04:12 -0300 | [diff] [blame] | 242 | goto err; |
| 243 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 244 | ret = regmap_bulk_write(s->regmap, 0x60, i_data, 4); |
| 245 | if (ret) |
Antti Palosaari | 8514611 | 2013-07-24 02:04:12 -0300 | [diff] [blame] | 246 | goto err; |
| 247 | |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 248 | /* gain control auto */ |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 249 | ret = regmap_write(s->regmap, 0x1a, 0x17); |
| 250 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 251 | goto err; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 252 | err: |
Antti Palosaari | 1c73fc6 | 2014-02-08 04:21:10 -0300 | [diff] [blame] | 253 | if (ret) |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 254 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 255 | |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 256 | return ret; |
| 257 | } |
| 258 | |
| 259 | static int e4000_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) |
| 260 | { |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 261 | struct e4000 *s = fe->tuner_priv; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 262 | |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 263 | dev_dbg(&s->client->dev, "\n"); |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 264 | |
| 265 | *frequency = 0; /* Zero-IF */ |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
Antti Palosaari | 320c638 | 2014-03-16 18:13:05 -0300 | [diff] [blame] | 270 | #if IS_ENABLED(CONFIG_VIDEO_V4L2) |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 271 | static int e4000_set_lna_gain(struct dvb_frontend *fe) |
| 272 | { |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 273 | struct e4000 *s = fe->tuner_priv; |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 274 | int ret; |
| 275 | u8 u8tmp; |
Antti Palosaari | 1c73fc6 | 2014-02-08 04:21:10 -0300 | [diff] [blame] | 276 | |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 277 | dev_dbg(&s->client->dev, "lna auto=%d->%d val=%d->%d\n", |
| 278 | s->lna_gain_auto->cur.val, s->lna_gain_auto->val, |
| 279 | s->lna_gain->cur.val, s->lna_gain->val); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 280 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 281 | if (s->lna_gain_auto->val && s->if_gain_auto->cur.val) |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 282 | u8tmp = 0x17; |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 283 | else if (s->lna_gain_auto->val) |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 284 | u8tmp = 0x19; |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 285 | else if (s->if_gain_auto->cur.val) |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 286 | u8tmp = 0x16; |
| 287 | else |
| 288 | u8tmp = 0x10; |
| 289 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 290 | ret = regmap_write(s->regmap, 0x1a, u8tmp); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 291 | if (ret) |
| 292 | goto err; |
| 293 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 294 | if (s->lna_gain_auto->val == false) { |
| 295 | ret = regmap_write(s->regmap, 0x14, s->lna_gain->val); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 296 | if (ret) |
| 297 | goto err; |
| 298 | } |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 299 | err: |
Antti Palosaari | 1c73fc6 | 2014-02-08 04:21:10 -0300 | [diff] [blame] | 300 | if (ret) |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 301 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 302 | |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 303 | return ret; |
| 304 | } |
| 305 | |
| 306 | static int e4000_set_mixer_gain(struct dvb_frontend *fe) |
| 307 | { |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 308 | struct e4000 *s = fe->tuner_priv; |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 309 | int ret; |
| 310 | u8 u8tmp; |
Antti Palosaari | 1c73fc6 | 2014-02-08 04:21:10 -0300 | [diff] [blame] | 311 | |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 312 | dev_dbg(&s->client->dev, "mixer auto=%d->%d val=%d->%d\n", |
| 313 | s->mixer_gain_auto->cur.val, s->mixer_gain_auto->val, |
| 314 | s->mixer_gain->cur.val, s->mixer_gain->val); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 315 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 316 | if (s->mixer_gain_auto->val) |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 317 | u8tmp = 0x15; |
| 318 | else |
| 319 | u8tmp = 0x14; |
| 320 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 321 | ret = regmap_write(s->regmap, 0x20, u8tmp); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 322 | if (ret) |
| 323 | goto err; |
| 324 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 325 | if (s->mixer_gain_auto->val == false) { |
| 326 | ret = regmap_write(s->regmap, 0x15, s->mixer_gain->val); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 327 | if (ret) |
| 328 | goto err; |
| 329 | } |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 330 | err: |
Antti Palosaari | 1c73fc6 | 2014-02-08 04:21:10 -0300 | [diff] [blame] | 331 | if (ret) |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 332 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 333 | |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 334 | return ret; |
| 335 | } |
| 336 | |
| 337 | static int e4000_set_if_gain(struct dvb_frontend *fe) |
| 338 | { |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 339 | struct e4000 *s = fe->tuner_priv; |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 340 | int ret; |
| 341 | u8 buf[2]; |
| 342 | u8 u8tmp; |
Antti Palosaari | 1c73fc6 | 2014-02-08 04:21:10 -0300 | [diff] [blame] | 343 | |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 344 | dev_dbg(&s->client->dev, "if auto=%d->%d val=%d->%d\n", |
| 345 | s->if_gain_auto->cur.val, s->if_gain_auto->val, |
| 346 | s->if_gain->cur.val, s->if_gain->val); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 347 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 348 | if (s->if_gain_auto->val && s->lna_gain_auto->cur.val) |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 349 | u8tmp = 0x17; |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 350 | else if (s->lna_gain_auto->cur.val) |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 351 | u8tmp = 0x19; |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 352 | else if (s->if_gain_auto->val) |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 353 | u8tmp = 0x16; |
| 354 | else |
| 355 | u8tmp = 0x10; |
| 356 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 357 | ret = regmap_write(s->regmap, 0x1a, u8tmp); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 358 | if (ret) |
| 359 | goto err; |
| 360 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 361 | if (s->if_gain_auto->val == false) { |
| 362 | buf[0] = e4000_if_gain_lut[s->if_gain->val].reg16_val; |
| 363 | buf[1] = e4000_if_gain_lut[s->if_gain->val].reg17_val; |
| 364 | ret = regmap_bulk_write(s->regmap, 0x16, buf, 2); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 365 | if (ret) |
| 366 | goto err; |
| 367 | } |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 368 | err: |
Antti Palosaari | 1c73fc6 | 2014-02-08 04:21:10 -0300 | [diff] [blame] | 369 | if (ret) |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 370 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 371 | |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 372 | return ret; |
| 373 | } |
| 374 | |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 375 | static int e4000_pll_lock(struct dvb_frontend *fe) |
| 376 | { |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 377 | struct e4000 *s = fe->tuner_priv; |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 378 | int ret; |
Antti Palosaari | bd428bb | 2014-02-08 06:20:35 -0300 | [diff] [blame] | 379 | unsigned int utmp; |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 380 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 381 | ret = regmap_read(s->regmap, 0x07, &utmp); |
| 382 | if (ret) |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 383 | goto err; |
| 384 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 385 | s->pll_lock->val = (utmp & 0x01); |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 386 | err: |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 387 | if (ret) |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 388 | dev_dbg(&s->client->dev, "failed=%d\n", ret); |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 389 | |
| 390 | return ret; |
| 391 | } |
| 392 | |
| 393 | static int e4000_g_volatile_ctrl(struct v4l2_ctrl *ctrl) |
| 394 | { |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 395 | struct e4000 *s = container_of(ctrl->handler, struct e4000, hdl); |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 396 | int ret; |
| 397 | |
Mauro Carvalho Chehab | a04557a | 2014-09-03 16:04:59 -0300 | [diff] [blame] | 398 | if (!s->active) |
Antti Palosaari | bd428bb | 2014-02-08 06:20:35 -0300 | [diff] [blame] | 399 | return 0; |
| 400 | |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 401 | switch (ctrl->id) { |
| 402 | case V4L2_CID_RF_TUNER_PLL_LOCK: |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 403 | ret = e4000_pll_lock(s->fe); |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 404 | break; |
| 405 | default: |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 406 | dev_dbg(&s->client->dev, "unknown ctrl: id=%d name=%s\n", |
| 407 | ctrl->id, ctrl->name); |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 408 | ret = -EINVAL; |
| 409 | } |
| 410 | |
| 411 | return ret; |
| 412 | } |
| 413 | |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 414 | static int e4000_s_ctrl(struct v4l2_ctrl *ctrl) |
| 415 | { |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 416 | struct e4000 *s = container_of(ctrl->handler, struct e4000, hdl); |
| 417 | struct dvb_frontend *fe = s->fe; |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 418 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 419 | int ret; |
Antti Palosaari | 1c73fc6 | 2014-02-08 04:21:10 -0300 | [diff] [blame] | 420 | |
Mauro Carvalho Chehab | a04557a | 2014-09-03 16:04:59 -0300 | [diff] [blame] | 421 | if (!s->active) |
Antti Palosaari | bd428bb | 2014-02-08 06:20:35 -0300 | [diff] [blame] | 422 | return 0; |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 423 | |
| 424 | switch (ctrl->id) { |
| 425 | case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO: |
| 426 | case V4L2_CID_RF_TUNER_BANDWIDTH: |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 427 | c->bandwidth_hz = s->bandwidth->val; |
| 428 | ret = e4000_set_params(s->fe); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 429 | break; |
| 430 | case V4L2_CID_RF_TUNER_LNA_GAIN_AUTO: |
| 431 | case V4L2_CID_RF_TUNER_LNA_GAIN: |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 432 | ret = e4000_set_lna_gain(s->fe); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 433 | break; |
| 434 | case V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO: |
| 435 | case V4L2_CID_RF_TUNER_MIXER_GAIN: |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 436 | ret = e4000_set_mixer_gain(s->fe); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 437 | break; |
| 438 | case V4L2_CID_RF_TUNER_IF_GAIN_AUTO: |
| 439 | case V4L2_CID_RF_TUNER_IF_GAIN: |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 440 | ret = e4000_set_if_gain(s->fe); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 441 | break; |
| 442 | default: |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 443 | dev_dbg(&s->client->dev, "unknown ctrl: id=%d name=%s\n", |
| 444 | ctrl->id, ctrl->name); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 445 | ret = -EINVAL; |
| 446 | } |
| 447 | |
| 448 | return ret; |
| 449 | } |
| 450 | |
| 451 | static const struct v4l2_ctrl_ops e4000_ctrl_ops = { |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 452 | .g_volatile_ctrl = e4000_g_volatile_ctrl, |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 453 | .s_ctrl = e4000_s_ctrl, |
| 454 | }; |
Antti Palosaari | 320c638 | 2014-03-16 18:13:05 -0300 | [diff] [blame] | 455 | #endif |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 456 | |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 457 | static const struct dvb_tuner_ops e4000_tuner_ops = { |
| 458 | .info = { |
| 459 | .name = "Elonics E4000", |
| 460 | .frequency_min = 174000000, |
| 461 | .frequency_max = 862000000, |
| 462 | }, |
| 463 | |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 464 | .init = e4000_init, |
| 465 | .sleep = e4000_sleep, |
| 466 | .set_params = e4000_set_params, |
| 467 | |
| 468 | .get_if_frequency = e4000_get_if_frequency, |
| 469 | }; |
| 470 | |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 471 | /* |
| 472 | * Use V4L2 subdev to carry V4L2 control handler, even we don't implement |
| 473 | * subdev itself, just to avoid reinventing the wheel. |
| 474 | */ |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 475 | static int e4000_probe(struct i2c_client *client, |
| 476 | const struct i2c_device_id *id) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 477 | { |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 478 | struct e4000_config *cfg = client->dev.platform_data; |
| 479 | struct dvb_frontend *fe = cfg->fe; |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 480 | struct e4000 *s; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 481 | int ret; |
Antti Palosaari | bd428bb | 2014-02-08 06:20:35 -0300 | [diff] [blame] | 482 | unsigned int utmp; |
| 483 | static const struct regmap_config regmap_config = { |
| 484 | .reg_bits = 8, |
| 485 | .val_bits = 8, |
| 486 | .max_register = 0xff, |
| 487 | }; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 488 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 489 | s = kzalloc(sizeof(struct e4000), GFP_KERNEL); |
| 490 | if (!s) { |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 491 | ret = -ENOMEM; |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 492 | dev_err(&client->dev, "kzalloc() failed\n"); |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 493 | goto err; |
| 494 | } |
| 495 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 496 | s->clock = cfg->clock; |
| 497 | s->client = client; |
| 498 | s->fe = cfg->fe; |
| 499 | s->regmap = devm_regmap_init_i2c(client, ®map_config); |
| 500 | if (IS_ERR(s->regmap)) { |
| 501 | ret = PTR_ERR(s->regmap); |
Antti Palosaari | bd428bb | 2014-02-08 06:20:35 -0300 | [diff] [blame] | 502 | goto err; |
| 503 | } |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 504 | |
| 505 | /* check if the tuner is there */ |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 506 | ret = regmap_read(s->regmap, 0x02, &utmp); |
| 507 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 508 | goto err; |
| 509 | |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 510 | dev_dbg(&s->client->dev, "chip id=%02x\n", utmp); |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 511 | |
Antti Palosaari | bd428bb | 2014-02-08 06:20:35 -0300 | [diff] [blame] | 512 | if (utmp != 0x40) { |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 513 | ret = -ENODEV; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 514 | goto err; |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 515 | } |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 516 | |
| 517 | /* put sleep as chip seems to be in normal mode by default */ |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 518 | ret = regmap_write(s->regmap, 0x00, 0x00); |
| 519 | if (ret) |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 520 | goto err; |
| 521 | |
Antti Palosaari | 320c638 | 2014-03-16 18:13:05 -0300 | [diff] [blame] | 522 | #if IS_ENABLED(CONFIG_VIDEO_V4L2) |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 523 | /* Register controls */ |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 524 | v4l2_ctrl_handler_init(&s->hdl, 9); |
| 525 | s->bandwidth_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 526 | V4L2_CID_RF_TUNER_BANDWIDTH_AUTO, 0, 1, 1, 1); |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 527 | s->bandwidth = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 528 | V4L2_CID_RF_TUNER_BANDWIDTH, 4300000, 11000000, 100000, 4300000); |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 529 | v4l2_ctrl_auto_cluster(2, &s->bandwidth_auto, 0, false); |
| 530 | s->lna_gain_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 531 | V4L2_CID_RF_TUNER_LNA_GAIN_AUTO, 0, 1, 1, 1); |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 532 | s->lna_gain = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 533 | V4L2_CID_RF_TUNER_LNA_GAIN, 0, 15, 1, 10); |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 534 | v4l2_ctrl_auto_cluster(2, &s->lna_gain_auto, 0, false); |
| 535 | s->mixer_gain_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 536 | V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO, 0, 1, 1, 1); |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 537 | s->mixer_gain = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 538 | V4L2_CID_RF_TUNER_MIXER_GAIN, 0, 1, 1, 1); |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 539 | v4l2_ctrl_auto_cluster(2, &s->mixer_gain_auto, 0, false); |
| 540 | s->if_gain_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 541 | V4L2_CID_RF_TUNER_IF_GAIN_AUTO, 0, 1, 1, 1); |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 542 | s->if_gain = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 543 | V4L2_CID_RF_TUNER_IF_GAIN, 0, 54, 1, 0); |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 544 | v4l2_ctrl_auto_cluster(2, &s->if_gain_auto, 0, false); |
| 545 | s->pll_lock = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, |
Antti Palosaari | ecfb7ca | 2014-02-07 02:55:57 -0300 | [diff] [blame] | 546 | V4L2_CID_RF_TUNER_PLL_LOCK, 0, 1, 1, 0); |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 547 | if (s->hdl.error) { |
| 548 | ret = s->hdl.error; |
| 549 | dev_err(&s->client->dev, "Could not initialize controls\n"); |
| 550 | v4l2_ctrl_handler_free(&s->hdl); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 551 | goto err; |
| 552 | } |
| 553 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 554 | s->sd.ctrl_handler = &s->hdl; |
Antti Palosaari | 320c638 | 2014-03-16 18:13:05 -0300 | [diff] [blame] | 555 | #endif |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 556 | |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 557 | dev_info(&s->client->dev, "Elonics E4000 successfully identified\n"); |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 558 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 559 | fe->tuner_priv = s; |
Antti Palosaari | 36f647b | 2012-09-22 12:32:27 -0300 | [diff] [blame] | 560 | memcpy(&fe->ops.tuner_ops, &e4000_tuner_ops, |
| 561 | sizeof(struct dvb_tuner_ops)); |
| 562 | |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 563 | v4l2_set_subdevdata(&s->sd, client); |
| 564 | i2c_set_clientdata(client, &s->sd); |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 565 | |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 566 | return 0; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 567 | err: |
Antti Palosaari | 1c73fc6 | 2014-02-08 04:21:10 -0300 | [diff] [blame] | 568 | if (ret) { |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 569 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 570 | kfree(s); |
Antti Palosaari | 1c73fc6 | 2014-02-08 04:21:10 -0300 | [diff] [blame] | 571 | } |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 572 | |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 573 | return ret; |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 574 | } |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 575 | |
| 576 | static int e4000_remove(struct i2c_client *client) |
| 577 | { |
Antti Palosaari | adaa616 | 2014-01-26 21:02:53 -0300 | [diff] [blame] | 578 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 579 | struct e4000 *s = container_of(sd, struct e4000, sd); |
| 580 | struct dvb_frontend *fe = s->fe; |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 581 | |
Antti Palosaari | 13bd82d | 2014-08-24 23:35:48 -0300 | [diff] [blame] | 582 | dev_dbg(&client->dev, "\n"); |
Antti Palosaari | 1c73fc6 | 2014-02-08 04:21:10 -0300 | [diff] [blame] | 583 | |
Antti Palosaari | 320c638 | 2014-03-16 18:13:05 -0300 | [diff] [blame] | 584 | #if IS_ENABLED(CONFIG_VIDEO_V4L2) |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 585 | v4l2_ctrl_handler_free(&s->hdl); |
Antti Palosaari | 320c638 | 2014-03-16 18:13:05 -0300 | [diff] [blame] | 586 | #endif |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 587 | memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); |
| 588 | fe->tuner_priv = NULL; |
Antti Palosaari | c5f51b1 | 2014-02-10 22:52:51 -0300 | [diff] [blame] | 589 | kfree(s); |
Antti Palosaari | 28fd31f | 2013-10-15 19:22:45 -0300 | [diff] [blame] | 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | static const struct i2c_device_id e4000_id[] = { |
| 595 | {"e4000", 0}, |
| 596 | {} |
| 597 | }; |
| 598 | MODULE_DEVICE_TABLE(i2c, e4000_id); |
| 599 | |
| 600 | static struct i2c_driver e4000_driver = { |
| 601 | .driver = { |
| 602 | .owner = THIS_MODULE, |
| 603 | .name = "e4000", |
| 604 | }, |
| 605 | .probe = e4000_probe, |
| 606 | .remove = e4000_remove, |
| 607 | .id_table = e4000_id, |
| 608 | }; |
| 609 | |
| 610 | module_i2c_driver(e4000_driver); |
Antti Palosaari | ed85ada | 2012-09-01 21:09:21 -0300 | [diff] [blame] | 611 | |
| 612 | MODULE_DESCRIPTION("Elonics E4000 silicon tuner driver"); |
| 613 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 614 | MODULE_LICENSE("GPL"); |