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