Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Afatech AF9033 demodulator driver |
| 3 | * |
| 4 | * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> |
| 5 | * Copyright (C) 2012 Antti Palosaari <crope@iki.fi> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include "af9033_priv.h" |
| 19 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 20 | struct af9033_dev { |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 21 | struct i2c_client *client; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 22 | struct regmap *regmap; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 23 | struct dvb_frontend fe; |
| 24 | struct af9033_config cfg; |
Antti Palosaari | 83f1161 | 2014-09-02 03:55:21 -0300 | [diff] [blame] | 25 | bool is_af9035; |
| 26 | bool is_it9135; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 27 | |
| 28 | u32 bandwidth_hz; |
| 29 | bool ts_mode_parallel; |
| 30 | bool ts_mode_serial; |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 31 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 32 | enum fe_status fe_status; |
Antti Palosaari | e53c474 | 2014-09-03 23:22:53 -0300 | [diff] [blame] | 33 | u64 post_bit_error_prev; /* for old read_ber we return (curr - prev) */ |
Antti Palosaari | 6bb096c | 2014-09-02 08:29:46 -0300 | [diff] [blame] | 34 | u64 post_bit_error; |
| 35 | u64 post_bit_count; |
Antti Palosaari | 204f431 | 2014-09-02 08:01:10 -0300 | [diff] [blame] | 36 | u64 error_block_count; |
| 37 | u64 total_block_count; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 38 | }; |
| 39 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 40 | /* Write reg val table using reg addr auto increment */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 41 | static int af9033_wr_reg_val_tab(struct af9033_dev *dev, |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 42 | const struct reg_val *tab, int tab_len) |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 43 | { |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 44 | struct i2c_client *client = dev->client; |
Antti Palosaari | d18a88b | 2013-11-27 17:17:43 -0300 | [diff] [blame] | 45 | #define MAX_TAB_LEN 212 |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 46 | int ret, i, j; |
Antti Palosaari | d18a88b | 2013-11-27 17:17:43 -0300 | [diff] [blame] | 47 | u8 buf[1 + MAX_TAB_LEN]; |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 48 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 49 | dev_dbg(&client->dev, "tab_len=%d\n", tab_len); |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 50 | |
Antti Palosaari | d18a88b | 2013-11-27 17:17:43 -0300 | [diff] [blame] | 51 | if (tab_len > sizeof(buf)) { |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 52 | dev_warn(&client->dev, "tab len %d is too big\n", tab_len); |
Antti Palosaari | d18a88b | 2013-11-27 17:17:43 -0300 | [diff] [blame] | 53 | return -EINVAL; |
| 54 | } |
| 55 | |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 56 | for (i = 0, j = 0; i < tab_len; i++) { |
| 57 | buf[j] = tab[i].val; |
| 58 | |
| 59 | if (i == tab_len - 1 || tab[i].reg != tab[i + 1].reg - 1) { |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 60 | ret = regmap_bulk_write(dev->regmap, tab[i].reg - j, |
| 61 | buf, j + 1); |
| 62 | if (ret) |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 63 | goto err; |
| 64 | |
| 65 | j = 0; |
| 66 | } else { |
| 67 | j++; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return 0; |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 72 | err: |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 73 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 74 | return ret; |
| 75 | } |
| 76 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 77 | static int af9033_init(struct dvb_frontend *fe) |
| 78 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 79 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 80 | struct i2c_client *client = dev->client; |
Antti Palosaari | 2db4d17 | 2014-09-06 11:24:14 -0300 | [diff] [blame] | 81 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 82 | int ret, i, len; |
Antti Palosaari | c2feb9f | 2016-11-06 15:27:16 -0200 | [diff] [blame] | 83 | unsigned int utmp; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 84 | const struct reg_val *init; |
| 85 | u8 buf[4]; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 86 | struct reg_val_mask tab[] = { |
| 87 | { 0x80fb24, 0x00, 0x08 }, |
| 88 | { 0x80004c, 0x00, 0xff }, |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 89 | { 0x00f641, dev->cfg.tuner, 0xff }, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 90 | { 0x80f5ca, 0x01, 0x01 }, |
| 91 | { 0x80f715, 0x01, 0x01 }, |
| 92 | { 0x00f41f, 0x04, 0x04 }, |
| 93 | { 0x00f41a, 0x01, 0x01 }, |
| 94 | { 0x80f731, 0x00, 0x01 }, |
| 95 | { 0x00d91e, 0x00, 0x01 }, |
| 96 | { 0x00d919, 0x00, 0x01 }, |
| 97 | { 0x80f732, 0x00, 0x01 }, |
| 98 | { 0x00d91f, 0x00, 0x01 }, |
| 99 | { 0x00d91a, 0x00, 0x01 }, |
| 100 | { 0x80f730, 0x00, 0x01 }, |
| 101 | { 0x80f778, 0x00, 0xff }, |
| 102 | { 0x80f73c, 0x01, 0x01 }, |
| 103 | { 0x80f776, 0x00, 0x01 }, |
| 104 | { 0x00d8fd, 0x01, 0xff }, |
| 105 | { 0x00d830, 0x01, 0xff }, |
| 106 | { 0x00d831, 0x00, 0xff }, |
| 107 | { 0x00d832, 0x00, 0xff }, |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 108 | { 0x80f985, dev->ts_mode_serial, 0x01 }, |
| 109 | { 0x80f986, dev->ts_mode_parallel, 0x01 }, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 110 | { 0x00d827, 0x00, 0xff }, |
| 111 | { 0x00d829, 0x00, 0xff }, |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 112 | { 0x800045, dev->cfg.adc_multiplier, 0xff }, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 113 | }; |
| 114 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 115 | dev_dbg(&client->dev, "\n"); |
| 116 | |
| 117 | /* Main clk control */ |
Antti Palosaari | c2feb9f | 2016-11-06 15:27:16 -0200 | [diff] [blame] | 118 | utmp = div_u64((u64)dev->cfg.clock * 0x80000, 1000000); |
| 119 | buf[0] = (utmp >> 0) & 0xff; |
| 120 | buf[1] = (utmp >> 8) & 0xff; |
| 121 | buf[2] = (utmp >> 16) & 0xff; |
| 122 | buf[3] = (utmp >> 24) & 0xff; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 123 | ret = regmap_bulk_write(dev->regmap, 0x800025, buf, 4); |
| 124 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 125 | goto err; |
| 126 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 127 | dev_dbg(&client->dev, "clk=%u clk_cw=%08x\n", dev->cfg.clock, utmp); |
Antti Palosaari | c2feb9f | 2016-11-06 15:27:16 -0200 | [diff] [blame] | 128 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 129 | /* ADC clk control */ |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 130 | for (i = 0; i < ARRAY_SIZE(clock_adc_lut); i++) { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 131 | if (clock_adc_lut[i].clock == dev->cfg.clock) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 132 | break; |
| 133 | } |
Mauro Carvalho Chehab | 060f79d | 2014-11-04 17:35:07 -0300 | [diff] [blame] | 134 | if (i == ARRAY_SIZE(clock_adc_lut)) { |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 135 | dev_err(&client->dev, "Couldn't find ADC config for clock %d\n", |
Mauro Carvalho Chehab | 060f79d | 2014-11-04 17:35:07 -0300 | [diff] [blame] | 136 | dev->cfg.clock); |
| 137 | goto err; |
| 138 | } |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 139 | |
Antti Palosaari | c2feb9f | 2016-11-06 15:27:16 -0200 | [diff] [blame] | 140 | utmp = div_u64((u64)clock_adc_lut[i].adc * 0x80000, 1000000); |
| 141 | buf[0] = (utmp >> 0) & 0xff; |
| 142 | buf[1] = (utmp >> 8) & 0xff; |
| 143 | buf[2] = (utmp >> 16) & 0xff; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 144 | ret = regmap_bulk_write(dev->regmap, 0x80f1cd, buf, 3); |
| 145 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 146 | goto err; |
| 147 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 148 | dev_dbg(&client->dev, "adc=%u adc_cw=%06x\n", |
Antti Palosaari | c2feb9f | 2016-11-06 15:27:16 -0200 | [diff] [blame] | 149 | clock_adc_lut[i].adc, utmp); |
| 150 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 151 | /* Config register table */ |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 152 | for (i = 0; i < ARRAY_SIZE(tab); i++) { |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 153 | ret = regmap_update_bits(dev->regmap, tab[i].reg, tab[i].mask, |
| 154 | tab[i].val); |
| 155 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 156 | goto err; |
| 157 | } |
| 158 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 159 | /* Demod clk output */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 160 | if (dev->cfg.dyn0_clk) { |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 161 | ret = regmap_write(dev->regmap, 0x80fba8, 0x00); |
| 162 | if (ret) |
Antti Palosaari | 9dc0f3f | 2014-08-09 01:03:14 -0300 | [diff] [blame] | 163 | goto err; |
| 164 | } |
| 165 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 166 | /* TS interface */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 167 | if (dev->cfg.ts_mode == AF9033_TS_MODE_USB) { |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 168 | ret = regmap_update_bits(dev->regmap, 0x80f9a5, 0x01, 0x00); |
| 169 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 170 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 171 | ret = regmap_update_bits(dev->regmap, 0x80f9b5, 0x01, 0x01); |
| 172 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 173 | goto err; |
| 174 | } else { |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 175 | ret = regmap_update_bits(dev->regmap, 0x80f990, 0x01, 0x00); |
| 176 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 177 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 178 | ret = regmap_update_bits(dev->regmap, 0x80f9b5, 0x01, 0x00); |
| 179 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 180 | goto err; |
| 181 | } |
| 182 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 183 | /* Demod core settings */ |
| 184 | dev_dbg(&client->dev, "load ofsm settings\n"); |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 185 | switch (dev->cfg.tuner) { |
Antti Palosaari | fe8eece | 2013-02-03 13:39:55 -0300 | [diff] [blame] | 186 | case AF9033_TUNER_IT9135_38: |
| 187 | case AF9033_TUNER_IT9135_51: |
| 188 | case AF9033_TUNER_IT9135_52: |
Antti Palosaari | 463c399 | 2013-03-07 00:03:06 -0300 | [diff] [blame] | 189 | len = ARRAY_SIZE(ofsm_init_it9135_v1); |
| 190 | init = ofsm_init_it9135_v1; |
| 191 | break; |
Antti Palosaari | fe8eece | 2013-02-03 13:39:55 -0300 | [diff] [blame] | 192 | case AF9033_TUNER_IT9135_60: |
| 193 | case AF9033_TUNER_IT9135_61: |
| 194 | case AF9033_TUNER_IT9135_62: |
Antti Palosaari | 463c399 | 2013-03-07 00:03:06 -0300 | [diff] [blame] | 195 | len = ARRAY_SIZE(ofsm_init_it9135_v2); |
| 196 | init = ofsm_init_it9135_v2; |
Antti Palosaari | fe8eece | 2013-02-03 13:39:55 -0300 | [diff] [blame] | 197 | break; |
| 198 | default: |
| 199 | len = ARRAY_SIZE(ofsm_init); |
| 200 | init = ofsm_init; |
| 201 | break; |
| 202 | } |
| 203 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 204 | ret = af9033_wr_reg_val_tab(dev, init, len); |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 205 | if (ret) |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 206 | goto err; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 207 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 208 | /* Demod tuner specific settings */ |
| 209 | dev_dbg(&client->dev, "load tuner specific settings\n"); |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 210 | switch (dev->cfg.tuner) { |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 211 | case AF9033_TUNER_TUA9001: |
| 212 | len = ARRAY_SIZE(tuner_init_tua9001); |
| 213 | init = tuner_init_tua9001; |
| 214 | break; |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 215 | case AF9033_TUNER_FC0011: |
| 216 | len = ARRAY_SIZE(tuner_init_fc0011); |
| 217 | init = tuner_init_fc0011; |
| 218 | break; |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 219 | case AF9033_TUNER_MXL5007T: |
| 220 | len = ARRAY_SIZE(tuner_init_mxl5007t); |
| 221 | init = tuner_init_mxl5007t; |
| 222 | break; |
Gianluca Gennari | ce1fe37 | 2012-04-02 17:25:14 -0300 | [diff] [blame] | 223 | case AF9033_TUNER_TDA18218: |
| 224 | len = ARRAY_SIZE(tuner_init_tda18218); |
| 225 | init = tuner_init_tda18218; |
| 226 | break; |
Oliver Schinagl | d67ceb3 | 2012-09-20 14:57:17 -0300 | [diff] [blame] | 227 | case AF9033_TUNER_FC2580: |
| 228 | len = ARRAY_SIZE(tuner_init_fc2580); |
| 229 | init = tuner_init_fc2580; |
| 230 | break; |
Antti Palosaari | e713ad1 | 2012-12-02 18:47:00 -0300 | [diff] [blame] | 231 | case AF9033_TUNER_FC0012: |
| 232 | len = ARRAY_SIZE(tuner_init_fc0012); |
| 233 | init = tuner_init_fc0012; |
| 234 | break; |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 235 | case AF9033_TUNER_IT9135_38: |
Antti Palosaari | a72cbb7 | 2013-03-07 21:17:55 -0300 | [diff] [blame] | 236 | len = ARRAY_SIZE(tuner_init_it9135_38); |
| 237 | init = tuner_init_it9135_38; |
| 238 | break; |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 239 | case AF9033_TUNER_IT9135_51: |
Antti Palosaari | bb2e12a | 2013-03-07 21:25:16 -0300 | [diff] [blame] | 240 | len = ARRAY_SIZE(tuner_init_it9135_51); |
| 241 | init = tuner_init_it9135_51; |
| 242 | break; |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 243 | case AF9033_TUNER_IT9135_52: |
Antti Palosaari | 22d729f | 2013-03-07 21:29:05 -0300 | [diff] [blame] | 244 | len = ARRAY_SIZE(tuner_init_it9135_52); |
| 245 | init = tuner_init_it9135_52; |
| 246 | break; |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 247 | case AF9033_TUNER_IT9135_60: |
Antti Palosaari | a49f53a | 2013-03-07 21:38:00 -0300 | [diff] [blame] | 248 | len = ARRAY_SIZE(tuner_init_it9135_60); |
| 249 | init = tuner_init_it9135_60; |
| 250 | break; |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 251 | case AF9033_TUNER_IT9135_61: |
Antti Palosaari | 8521132 | 2013-03-07 21:44:30 -0300 | [diff] [blame] | 252 | len = ARRAY_SIZE(tuner_init_it9135_61); |
| 253 | init = tuner_init_it9135_61; |
| 254 | break; |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 255 | case AF9033_TUNER_IT9135_62: |
Antti Palosaari | dc4a2c4 | 2013-03-07 21:47:20 -0300 | [diff] [blame] | 256 | len = ARRAY_SIZE(tuner_init_it9135_62); |
| 257 | init = tuner_init_it9135_62; |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 258 | break; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 259 | default: |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 260 | dev_dbg(&client->dev, "unsupported tuner ID=%d\n", |
| 261 | dev->cfg.tuner); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 262 | ret = -ENODEV; |
| 263 | goto err; |
| 264 | } |
| 265 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 266 | ret = af9033_wr_reg_val_tab(dev, init, len); |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 267 | if (ret) |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 268 | goto err; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 269 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 270 | if (dev->cfg.ts_mode == AF9033_TS_MODE_SERIAL) { |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 271 | ret = regmap_update_bits(dev->regmap, 0x00d91c, 0x01, 0x01); |
| 272 | if (ret) |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 273 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 274 | ret = regmap_update_bits(dev->regmap, 0x00d917, 0x01, 0x00); |
| 275 | if (ret) |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 276 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 277 | ret = regmap_update_bits(dev->regmap, 0x00d916, 0x01, 0x00); |
| 278 | if (ret) |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 279 | goto err; |
| 280 | } |
| 281 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 282 | switch (dev->cfg.tuner) { |
Antti Palosaari | 086991d | 2013-03-07 22:18:56 -0300 | [diff] [blame] | 283 | case AF9033_TUNER_IT9135_60: |
| 284 | case AF9033_TUNER_IT9135_61: |
| 285 | case AF9033_TUNER_IT9135_62: |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 286 | ret = regmap_write(dev->regmap, 0x800000, 0x01); |
| 287 | if (ret) |
Antti Palosaari | 086991d | 2013-03-07 22:18:56 -0300 | [diff] [blame] | 288 | goto err; |
| 289 | } |
| 290 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 291 | dev->bandwidth_hz = 0; /* Force to program all parameters */ |
| 292 | /* Init stats here in order signal app which stats are supported */ |
Antti Palosaari | 2db4d17 | 2014-09-06 11:24:14 -0300 | [diff] [blame] | 293 | c->strength.len = 1; |
| 294 | c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 295 | c->cnr.len = 1; |
| 296 | c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 297 | c->block_count.len = 1; |
| 298 | c->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 299 | c->block_error.len = 1; |
| 300 | c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 301 | c->post_bit_count.len = 1; |
| 302 | c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 303 | c->post_bit_error.len = 1; |
| 304 | c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 305 | |
| 306 | return 0; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 307 | err: |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 308 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 309 | return ret; |
| 310 | } |
| 311 | |
| 312 | static int af9033_sleep(struct dvb_frontend *fe) |
| 313 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 314 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 315 | struct i2c_client *client = dev->client; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 316 | int ret; |
| 317 | unsigned int utmp; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 318 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 319 | dev_dbg(&client->dev, "\n"); |
| 320 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 321 | ret = regmap_write(dev->regmap, 0x80004c, 0x01); |
| 322 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 323 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 324 | ret = regmap_write(dev->regmap, 0x800000, 0x00); |
| 325 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 326 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 327 | ret = regmap_read_poll_timeout(dev->regmap, 0x80004c, utmp, utmp == 0, |
| 328 | 5000, 1000000); |
| 329 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 330 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 331 | ret = regmap_update_bits(dev->regmap, 0x80fb24, 0x08, 0x08); |
| 332 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 333 | goto err; |
| 334 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 335 | /* Prevent current leak by setting TS interface to parallel mode */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 336 | if (dev->cfg.ts_mode == AF9033_TS_MODE_SERIAL) { |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 337 | /* Enable parallel TS */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 338 | ret = regmap_update_bits(dev->regmap, 0x00d917, 0x01, 0x00); |
| 339 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 340 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 341 | ret = regmap_update_bits(dev->regmap, 0x00d916, 0x01, 0x01); |
| 342 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 343 | goto err; |
| 344 | } |
| 345 | |
| 346 | return 0; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 347 | err: |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 348 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 349 | return ret; |
| 350 | } |
| 351 | |
| 352 | static int af9033_get_tune_settings(struct dvb_frontend *fe, |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 353 | struct dvb_frontend_tune_settings *fesettings) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 354 | { |
Antti Palosaari | fe8eece | 2013-02-03 13:39:55 -0300 | [diff] [blame] | 355 | /* 800 => 2000 because IT9135 v2 is slow to gain lock */ |
| 356 | fesettings->min_delay_ms = 2000; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 357 | fesettings->step_size = 0; |
| 358 | fesettings->max_drift = 0; |
| 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | static int af9033_set_frontend(struct dvb_frontend *fe) |
| 364 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 365 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 366 | struct i2c_client *client = dev->client; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 367 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Antti Palosaari | c2feb9f | 2016-11-06 15:27:16 -0200 | [diff] [blame] | 368 | int ret, i; |
| 369 | unsigned int utmp, adc_freq; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 370 | u8 tmp, buf[3], bandwidth_reg_val; |
Antti Palosaari | c2feb9f | 2016-11-06 15:27:16 -0200 | [diff] [blame] | 371 | u32 if_frequency; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 372 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 373 | dev_dbg(&client->dev, "frequency=%u bandwidth_hz=%u\n", |
| 374 | c->frequency, c->bandwidth_hz); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 375 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 376 | /* Check bandwidth */ |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 377 | switch (c->bandwidth_hz) { |
| 378 | case 6000000: |
| 379 | bandwidth_reg_val = 0x00; |
| 380 | break; |
| 381 | case 7000000: |
| 382 | bandwidth_reg_val = 0x01; |
| 383 | break; |
| 384 | case 8000000: |
| 385 | bandwidth_reg_val = 0x02; |
| 386 | break; |
| 387 | default: |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 388 | dev_dbg(&client->dev, "invalid bandwidth_hz\n"); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 389 | ret = -EINVAL; |
| 390 | goto err; |
| 391 | } |
| 392 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 393 | /* Program tuner */ |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 394 | if (fe->ops.tuner_ops.set_params) |
| 395 | fe->ops.tuner_ops.set_params(fe); |
| 396 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 397 | /* Coefficients */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 398 | if (c->bandwidth_hz != dev->bandwidth_hz) { |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 399 | for (i = 0; i < ARRAY_SIZE(coeff_lut); i++) { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 400 | if (coeff_lut[i].clock == dev->cfg.clock && |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 401 | coeff_lut[i].bandwidth_hz == c->bandwidth_hz) { |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 402 | break; |
| 403 | } |
| 404 | } |
Mauro Carvalho Chehab | 060f79d | 2014-11-04 17:35:07 -0300 | [diff] [blame] | 405 | if (i == ARRAY_SIZE(coeff_lut)) { |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 406 | dev_err(&client->dev, |
| 407 | "Couldn't find config for clock %u\n", |
Mauro Carvalho Chehab | 060f79d | 2014-11-04 17:35:07 -0300 | [diff] [blame] | 408 | dev->cfg.clock); |
| 409 | ret = -EINVAL; |
| 410 | goto err; |
| 411 | } |
| 412 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 413 | ret = regmap_bulk_write(dev->regmap, 0x800001, coeff_lut[i].val, |
| 414 | sizeof(coeff_lut[i].val)); |
| 415 | if (ret) |
| 416 | goto err; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 417 | } |
| 418 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 419 | /* IF frequency control */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 420 | if (c->bandwidth_hz != dev->bandwidth_hz) { |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 421 | for (i = 0; i < ARRAY_SIZE(clock_adc_lut); i++) { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 422 | if (clock_adc_lut[i].clock == dev->cfg.clock) |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 423 | break; |
| 424 | } |
Mauro Carvalho Chehab | 060f79d | 2014-11-04 17:35:07 -0300 | [diff] [blame] | 425 | if (i == ARRAY_SIZE(clock_adc_lut)) { |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 426 | dev_err(&client->dev, |
| 427 | "Couldn't find ADC clock for clock %u\n", |
Mauro Carvalho Chehab | 060f79d | 2014-11-04 17:35:07 -0300 | [diff] [blame] | 428 | dev->cfg.clock); |
| 429 | ret = -EINVAL; |
| 430 | goto err; |
| 431 | } |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 432 | adc_freq = clock_adc_lut[i].adc; |
| 433 | |
Antti Palosaari | c2feb9f | 2016-11-06 15:27:16 -0200 | [diff] [blame] | 434 | if (dev->cfg.adc_multiplier == AF9033_ADC_MULTIPLIER_2X) |
| 435 | adc_freq = 2 * adc_freq; |
| 436 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 437 | /* Get used IF frequency */ |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 438 | if (fe->ops.tuner_ops.get_if_frequency) |
| 439 | fe->ops.tuner_ops.get_if_frequency(fe, &if_frequency); |
| 440 | else |
| 441 | if_frequency = 0; |
| 442 | |
Antti Palosaari | c2feb9f | 2016-11-06 15:27:16 -0200 | [diff] [blame] | 443 | utmp = DIV_ROUND_CLOSEST_ULL((u64)if_frequency * 0x800000, |
| 444 | adc_freq); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 445 | |
Antti Palosaari | c2feb9f | 2016-11-06 15:27:16 -0200 | [diff] [blame] | 446 | if (!dev->cfg.spec_inv && if_frequency) |
| 447 | utmp = 0x800000 - utmp; |
Hans-Frieder Vogt | 182b967 | 2012-10-03 05:25:40 -0300 | [diff] [blame] | 448 | |
Antti Palosaari | c2feb9f | 2016-11-06 15:27:16 -0200 | [diff] [blame] | 449 | buf[0] = (utmp >> 0) & 0xff; |
| 450 | buf[1] = (utmp >> 8) & 0xff; |
| 451 | buf[2] = (utmp >> 16) & 0xff; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 452 | ret = regmap_bulk_write(dev->regmap, 0x800029, buf, 3); |
| 453 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 454 | goto err; |
| 455 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 456 | dev_dbg(&client->dev, "if_frequency_cw=%06x\n", utmp); |
Antti Palosaari | c2feb9f | 2016-11-06 15:27:16 -0200 | [diff] [blame] | 457 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 458 | dev->bandwidth_hz = c->bandwidth_hz; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 459 | } |
| 460 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 461 | ret = regmap_update_bits(dev->regmap, 0x80f904, 0x03, |
| 462 | bandwidth_reg_val); |
| 463 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 464 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 465 | ret = regmap_write(dev->regmap, 0x800040, 0x00); |
| 466 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 467 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 468 | ret = regmap_write(dev->regmap, 0x800047, 0x00); |
| 469 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 470 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 471 | ret = regmap_update_bits(dev->regmap, 0x80f999, 0x01, 0x00); |
| 472 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 473 | goto err; |
| 474 | |
| 475 | if (c->frequency <= 230000000) |
| 476 | tmp = 0x00; /* VHF */ |
| 477 | else |
| 478 | tmp = 0x01; /* UHF */ |
| 479 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 480 | ret = regmap_write(dev->regmap, 0x80004b, tmp); |
| 481 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 482 | goto err; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 483 | /* Reset FSM */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 484 | ret = regmap_write(dev->regmap, 0x800000, 0x00); |
| 485 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 486 | goto err; |
| 487 | |
| 488 | return 0; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 489 | err: |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 490 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 491 | return ret; |
| 492 | } |
| 493 | |
Mauro Carvalho Chehab | 7e3e68b | 2016-02-04 12:58:30 -0200 | [diff] [blame] | 494 | static int af9033_get_frontend(struct dvb_frontend *fe, |
| 495 | struct dtv_frontend_properties *c) |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 496 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 497 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 498 | struct i2c_client *client = dev->client; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 499 | int ret; |
| 500 | u8 buf[8]; |
| 501 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 502 | dev_dbg(&client->dev, "\n"); |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 503 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 504 | /* Read all needed TPS registers */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 505 | ret = regmap_bulk_read(dev->regmap, 0x80f900, buf, 8); |
| 506 | if (ret) |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 507 | goto err; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 508 | |
| 509 | switch ((buf[0] >> 0) & 3) { |
| 510 | case 0: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 511 | c->transmission_mode = TRANSMISSION_MODE_2K; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 512 | break; |
| 513 | case 1: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 514 | c->transmission_mode = TRANSMISSION_MODE_8K; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 515 | break; |
| 516 | } |
| 517 | |
| 518 | switch ((buf[1] >> 0) & 3) { |
| 519 | case 0: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 520 | c->guard_interval = GUARD_INTERVAL_1_32; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 521 | break; |
| 522 | case 1: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 523 | c->guard_interval = GUARD_INTERVAL_1_16; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 524 | break; |
| 525 | case 2: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 526 | c->guard_interval = GUARD_INTERVAL_1_8; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 527 | break; |
| 528 | case 3: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 529 | c->guard_interval = GUARD_INTERVAL_1_4; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 530 | break; |
| 531 | } |
| 532 | |
| 533 | switch ((buf[2] >> 0) & 7) { |
| 534 | case 0: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 535 | c->hierarchy = HIERARCHY_NONE; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 536 | break; |
| 537 | case 1: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 538 | c->hierarchy = HIERARCHY_1; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 539 | break; |
| 540 | case 2: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 541 | c->hierarchy = HIERARCHY_2; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 542 | break; |
| 543 | case 3: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 544 | c->hierarchy = HIERARCHY_4; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 545 | break; |
| 546 | } |
| 547 | |
| 548 | switch ((buf[3] >> 0) & 3) { |
| 549 | case 0: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 550 | c->modulation = QPSK; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 551 | break; |
| 552 | case 1: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 553 | c->modulation = QAM_16; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 554 | break; |
| 555 | case 2: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 556 | c->modulation = QAM_64; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 557 | break; |
| 558 | } |
| 559 | |
| 560 | switch ((buf[4] >> 0) & 3) { |
| 561 | case 0: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 562 | c->bandwidth_hz = 6000000; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 563 | break; |
| 564 | case 1: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 565 | c->bandwidth_hz = 7000000; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 566 | break; |
| 567 | case 2: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 568 | c->bandwidth_hz = 8000000; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 569 | break; |
| 570 | } |
| 571 | |
| 572 | switch ((buf[6] >> 0) & 7) { |
| 573 | case 0: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 574 | c->code_rate_HP = FEC_1_2; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 575 | break; |
| 576 | case 1: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 577 | c->code_rate_HP = FEC_2_3; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 578 | break; |
| 579 | case 2: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 580 | c->code_rate_HP = FEC_3_4; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 581 | break; |
| 582 | case 3: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 583 | c->code_rate_HP = FEC_5_6; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 584 | break; |
| 585 | case 4: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 586 | c->code_rate_HP = FEC_7_8; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 587 | break; |
| 588 | case 5: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 589 | c->code_rate_HP = FEC_NONE; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 590 | break; |
| 591 | } |
| 592 | |
| 593 | switch ((buf[7] >> 0) & 7) { |
| 594 | case 0: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 595 | c->code_rate_LP = FEC_1_2; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 596 | break; |
| 597 | case 1: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 598 | c->code_rate_LP = FEC_2_3; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 599 | break; |
| 600 | case 2: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 601 | c->code_rate_LP = FEC_3_4; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 602 | break; |
| 603 | case 3: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 604 | c->code_rate_LP = FEC_5_6; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 605 | break; |
| 606 | case 4: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 607 | c->code_rate_LP = FEC_7_8; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 608 | break; |
| 609 | case 5: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 610 | c->code_rate_LP = FEC_NONE; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 611 | break; |
| 612 | } |
| 613 | |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 614 | return 0; |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 615 | err: |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 616 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 617 | return ret; |
| 618 | } |
| 619 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 620 | static int af9033_read_status(struct dvb_frontend *fe, enum fe_status *status) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 621 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 622 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 623 | struct i2c_client *client = dev->client; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 624 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Antti Palosaari | 239dd61 | 2016-12-19 01:42:37 -0200 | [diff] [blame] | 625 | int ret, tmp = 0; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 626 | u8 buf[7]; |
Antti Palosaari | 239dd61 | 2016-12-19 01:42:37 -0200 | [diff] [blame] | 627 | unsigned int utmp, utmp1; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 628 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 629 | dev_dbg(&client->dev, "\n"); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 630 | |
| 631 | *status = 0; |
| 632 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 633 | /* Radio channel status: 0=no result, 1=has signal, 2=no signal */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 634 | ret = regmap_read(dev->regmap, 0x800047, &utmp); |
| 635 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 636 | goto err; |
| 637 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 638 | /* Has signal */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 639 | if (utmp == 0x01) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 640 | *status |= FE_HAS_SIGNAL; |
| 641 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 642 | if (utmp != 0x02) { |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 643 | /* TPS lock */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 644 | ret = regmap_read(dev->regmap, 0x80f5a9, &utmp); |
| 645 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 646 | goto err; |
| 647 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 648 | if ((utmp >> 0) & 0x01) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 649 | *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER | |
| 650 | FE_HAS_VITERBI; |
| 651 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 652 | /* Full lock */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 653 | ret = regmap_read(dev->regmap, 0x80f999, &utmp); |
| 654 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 655 | goto err; |
| 656 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 657 | if ((utmp >> 0) & 0x01) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 658 | *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER | |
| 659 | FE_HAS_VITERBI | FE_HAS_SYNC | |
| 660 | FE_HAS_LOCK; |
| 661 | } |
| 662 | |
Antti Palosaari | 83f1161 | 2014-09-02 03:55:21 -0300 | [diff] [blame] | 663 | dev->fe_status = *status; |
| 664 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 665 | /* Signal strength */ |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 666 | if (dev->fe_status & FE_HAS_SIGNAL) { |
| 667 | if (dev->is_af9035) { |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 668 | ret = regmap_read(dev->regmap, 0x80004a, &utmp); |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 669 | if (ret) |
| 670 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 671 | tmp = -utmp * 1000; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 672 | } else { |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 673 | ret = regmap_read(dev->regmap, 0x8000f7, &utmp); |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 674 | if (ret) |
| 675 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 676 | tmp = (utmp - 100) * 1000; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | c->strength.len = 1; |
| 680 | c->strength.stat[0].scale = FE_SCALE_DECIBEL; |
| 681 | c->strength.stat[0].svalue = tmp; |
| 682 | } else { |
| 683 | c->strength.len = 1; |
| 684 | c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 685 | } |
| 686 | |
| 687 | /* CNR */ |
| 688 | if (dev->fe_status & FE_HAS_VITERBI) { |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 689 | /* Read raw SNR value */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 690 | ret = regmap_bulk_read(dev->regmap, 0x80002c, buf, 3); |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 691 | if (ret) |
| 692 | goto err; |
| 693 | |
Antti Palosaari | 239dd61 | 2016-12-19 01:42:37 -0200 | [diff] [blame] | 694 | utmp1 = buf[2] << 16 | buf[1] << 8 | buf[0] << 0; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 695 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 696 | /* Read superframe number */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 697 | ret = regmap_read(dev->regmap, 0x80f78b, &utmp); |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 698 | if (ret) |
| 699 | goto err; |
| 700 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 701 | if (utmp) |
Antti Palosaari | 239dd61 | 2016-12-19 01:42:37 -0200 | [diff] [blame] | 702 | utmp1 /= utmp; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 703 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 704 | /* Read current transmission mode */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 705 | ret = regmap_read(dev->regmap, 0x80f900, &utmp); |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 706 | if (ret) |
| 707 | goto err; |
| 708 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 709 | switch ((utmp >> 0) & 3) { |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 710 | case 0: |
Antti Palosaari | 239dd61 | 2016-12-19 01:42:37 -0200 | [diff] [blame] | 711 | /* 2k */ |
| 712 | utmp1 *= 4; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 713 | break; |
| 714 | case 1: |
Antti Palosaari | 239dd61 | 2016-12-19 01:42:37 -0200 | [diff] [blame] | 715 | /* 8k */ |
| 716 | utmp1 *= 1; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 717 | break; |
| 718 | case 2: |
Antti Palosaari | 239dd61 | 2016-12-19 01:42:37 -0200 | [diff] [blame] | 719 | /* 4k */ |
| 720 | utmp1 *= 2; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 721 | break; |
| 722 | default: |
Antti Palosaari | 239dd61 | 2016-12-19 01:42:37 -0200 | [diff] [blame] | 723 | utmp1 *= 0; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 724 | break; |
| 725 | } |
| 726 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 727 | /* Read current modulation */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 728 | ret = regmap_read(dev->regmap, 0x80f903, &utmp); |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 729 | if (ret) |
| 730 | goto err; |
| 731 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 732 | switch ((utmp >> 0) & 3) { |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 733 | case 0: |
Antti Palosaari | 239dd61 | 2016-12-19 01:42:37 -0200 | [diff] [blame] | 734 | /* |
| 735 | * QPSK |
| 736 | * CNR[dB] 13 * -log10((1690000 - value) / value) + 2.6 |
| 737 | * value [653799, 1689999], 2.6 / 13 = 3355443 |
| 738 | */ |
| 739 | utmp1 = clamp(utmp1, 653799U, 1689999U); |
| 740 | utmp1 = ((u64)(intlog10(utmp1) |
| 741 | - intlog10(1690000 - utmp1) |
| 742 | + 3355443) * 13 * 1000) >> 24; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 743 | break; |
| 744 | case 1: |
Antti Palosaari | 239dd61 | 2016-12-19 01:42:37 -0200 | [diff] [blame] | 745 | /* |
| 746 | * QAM-16 |
| 747 | * CNR[dB] 6 * log10((value - 370000) / (828000 - value)) + 15.7 |
| 748 | * value [371105, 827999], 15.7 / 6 = 43900382 |
| 749 | */ |
| 750 | utmp1 = clamp(utmp1, 371105U, 827999U); |
| 751 | utmp1 = ((u64)(intlog10(utmp1 - 370000) |
| 752 | - intlog10(828000 - utmp1) |
| 753 | + 43900382) * 6 * 1000) >> 24; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 754 | break; |
| 755 | case 2: |
Antti Palosaari | 239dd61 | 2016-12-19 01:42:37 -0200 | [diff] [blame] | 756 | /* |
| 757 | * QAM-64 |
| 758 | * CNR[dB] 8 * log10((value - 193000) / (425000 - value)) + 23.8 |
| 759 | * value [193246, 424999], 23.8 / 8 = 49912218 |
| 760 | */ |
| 761 | utmp1 = clamp(utmp1, 193246U, 424999U); |
| 762 | utmp1 = ((u64)(intlog10(utmp1 - 193000) |
| 763 | - intlog10(425000 - utmp1) |
| 764 | + 49912218) * 8 * 1000) >> 24; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 765 | break; |
| 766 | default: |
Antti Palosaari | 239dd61 | 2016-12-19 01:42:37 -0200 | [diff] [blame] | 767 | utmp1 = 0; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 768 | break; |
| 769 | } |
| 770 | |
Antti Palosaari | 239dd61 | 2016-12-19 01:42:37 -0200 | [diff] [blame] | 771 | dev_dbg(&client->dev, "cnr=%u\n", utmp1); |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 772 | |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 773 | c->cnr.stat[0].scale = FE_SCALE_DECIBEL; |
Antti Palosaari | 239dd61 | 2016-12-19 01:42:37 -0200 | [diff] [blame] | 774 | c->cnr.stat[0].svalue = utmp1; |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 775 | } else { |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 776 | c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 777 | } |
| 778 | |
| 779 | /* UCB/PER/BER */ |
| 780 | if (dev->fe_status & FE_HAS_LOCK) { |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 781 | /* Outer FEC, 204 byte packets */ |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 782 | u16 abort_packet_count, rsd_packet_count; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 783 | /* Inner FEC, bits */ |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 784 | u32 rsd_bit_err_count; |
| 785 | |
| 786 | /* |
| 787 | * Packet count used for measurement is 10000 |
| 788 | * (rsd_packet_count). Maybe it should be increased? |
| 789 | */ |
| 790 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 791 | ret = regmap_bulk_read(dev->regmap, 0x800032, buf, 7); |
Antti Palosaari | 659a099 | 2016-06-29 20:40:21 -0300 | [diff] [blame] | 792 | if (ret) |
| 793 | goto err; |
| 794 | |
| 795 | abort_packet_count = (buf[1] << 8) | (buf[0] << 0); |
| 796 | rsd_bit_err_count = (buf[4] << 16) | (buf[3] << 8) | buf[2]; |
| 797 | rsd_packet_count = (buf[6] << 8) | (buf[5] << 0); |
| 798 | |
| 799 | dev->error_block_count += abort_packet_count; |
| 800 | dev->total_block_count += rsd_packet_count; |
| 801 | dev->post_bit_error += rsd_bit_err_count; |
| 802 | dev->post_bit_count += rsd_packet_count * 204 * 8; |
| 803 | |
| 804 | c->block_count.len = 1; |
| 805 | c->block_count.stat[0].scale = FE_SCALE_COUNTER; |
| 806 | c->block_count.stat[0].uvalue = dev->total_block_count; |
| 807 | |
| 808 | c->block_error.len = 1; |
| 809 | c->block_error.stat[0].scale = FE_SCALE_COUNTER; |
| 810 | c->block_error.stat[0].uvalue = dev->error_block_count; |
| 811 | |
| 812 | c->post_bit_count.len = 1; |
| 813 | c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; |
| 814 | c->post_bit_count.stat[0].uvalue = dev->post_bit_count; |
| 815 | |
| 816 | c->post_bit_error.len = 1; |
| 817 | c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; |
| 818 | c->post_bit_error.stat[0].uvalue = dev->post_bit_error; |
| 819 | } |
| 820 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 821 | return 0; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 822 | err: |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 823 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 824 | return ret; |
| 825 | } |
| 826 | |
| 827 | static int af9033_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 828 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 829 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 830 | struct i2c_client *client = dev->client; |
Antti Palosaari | 6b45778 | 2014-09-02 05:03:21 -0300 | [diff] [blame] | 831 | struct dtv_frontend_properties *c = &dev->fe.dtv_property_cache; |
Bimow Chen | 6d03f6a | 2014-10-01 23:37:13 -0300 | [diff] [blame] | 832 | int ret; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 833 | unsigned int utmp; |
Antti Palosaari | e898ef6 | 2012-04-01 12:50:02 -0300 | [diff] [blame] | 834 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 835 | dev_dbg(&client->dev, "\n"); |
| 836 | |
| 837 | /* Use DVBv5 CNR */ |
Bimow Chen | 6d03f6a | 2014-10-01 23:37:13 -0300 | [diff] [blame] | 838 | if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL) { |
Antti Palosaari | c3a80cd | 2014-11-03 21:53:05 -0300 | [diff] [blame] | 839 | /* Return 0.1 dB for AF9030 and 0-0xffff for IT9130. */ |
| 840 | if (dev->is_af9035) { |
| 841 | /* 1000x => 10x (0.1 dB) */ |
| 842 | *snr = div_s64(c->cnr.stat[0].svalue, 100); |
| 843 | } else { |
| 844 | /* 1000x => 1x (1 dB) */ |
| 845 | *snr = div_s64(c->cnr.stat[0].svalue, 1000); |
Bimow Chen | 6d03f6a | 2014-10-01 23:37:13 -0300 | [diff] [blame] | 846 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 847 | /* Read current modulation */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 848 | ret = regmap_read(dev->regmap, 0x80f903, &utmp); |
Antti Palosaari | c3a80cd | 2014-11-03 21:53:05 -0300 | [diff] [blame] | 849 | if (ret) |
| 850 | goto err; |
Bimow Chen | 6d03f6a | 2014-10-01 23:37:13 -0300 | [diff] [blame] | 851 | |
Antti Palosaari | c3a80cd | 2014-11-03 21:53:05 -0300 | [diff] [blame] | 852 | /* scale value to 0x0000-0xffff */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 853 | switch ((utmp >> 0) & 3) { |
Antti Palosaari | c3a80cd | 2014-11-03 21:53:05 -0300 | [diff] [blame] | 854 | case 0: |
| 855 | *snr = *snr * 0xffff / 23; |
| 856 | break; |
| 857 | case 1: |
| 858 | *snr = *snr * 0xffff / 26; |
| 859 | break; |
| 860 | case 2: |
| 861 | *snr = *snr * 0xffff / 32; |
| 862 | break; |
| 863 | default: |
| 864 | goto err; |
| 865 | } |
Bimow Chen | 6d03f6a | 2014-10-01 23:37:13 -0300 | [diff] [blame] | 866 | } |
| 867 | } else { |
Antti Palosaari | 6b45778 | 2014-09-02 05:03:21 -0300 | [diff] [blame] | 868 | *snr = 0; |
Bimow Chen | 6d03f6a | 2014-10-01 23:37:13 -0300 | [diff] [blame] | 869 | } |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 870 | |
| 871 | return 0; |
Bimow Chen | 6d03f6a | 2014-10-01 23:37:13 -0300 | [diff] [blame] | 872 | err: |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 873 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Bimow Chen | 6d03f6a | 2014-10-01 23:37:13 -0300 | [diff] [blame] | 874 | return ret; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | static int af9033_read_signal_strength(struct dvb_frontend *fe, u16 *strength) |
| 878 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 879 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 880 | struct i2c_client *client = dev->client; |
Bimow Chen | 3adec27 | 2014-10-01 07:28:54 -0300 | [diff] [blame] | 881 | struct dtv_frontend_properties *c = &dev->fe.dtv_property_cache; |
| 882 | int ret, tmp, power_real; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 883 | unsigned int utmp; |
| 884 | u8 gain_offset, buf[7]; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 885 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 886 | dev_dbg(&client->dev, "\n"); |
| 887 | |
Bimow Chen | 3adec27 | 2014-10-01 07:28:54 -0300 | [diff] [blame] | 888 | if (dev->is_af9035) { |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 889 | /* Read signal strength of 0-100 scale */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 890 | ret = regmap_read(dev->regmap, 0x800048, &utmp); |
| 891 | if (ret) |
Antti Palosaari | 0b0d962 | 2014-11-03 20:24:13 -0300 | [diff] [blame] | 892 | goto err; |
| 893 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 894 | /* Scale value to 0x0000-0xffff */ |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 895 | *strength = utmp * 0xffff / 100; |
Bimow Chen | 3adec27 | 2014-10-01 07:28:54 -0300 | [diff] [blame] | 896 | } else { |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 897 | ret = regmap_read(dev->regmap, 0x8000f7, &utmp); |
| 898 | if (ret) |
Antti Palosaari | 1620d22 | 2014-11-03 21:23:26 -0300 | [diff] [blame] | 899 | goto err; |
| 900 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 901 | ret = regmap_bulk_read(dev->regmap, 0x80f900, buf, 7); |
| 902 | if (ret) |
Antti Palosaari | 1620d22 | 2014-11-03 21:23:26 -0300 | [diff] [blame] | 903 | goto err; |
Bimow Chen | 3adec27 | 2014-10-01 07:28:54 -0300 | [diff] [blame] | 904 | |
| 905 | if (c->frequency <= 300000000) |
| 906 | gain_offset = 7; /* VHF */ |
| 907 | else |
| 908 | gain_offset = 4; /* UHF */ |
| 909 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 910 | power_real = (utmp - 100 - gain_offset) - |
Bimow Chen | 3adec27 | 2014-10-01 07:28:54 -0300 | [diff] [blame] | 911 | power_reference[((buf[3] >> 0) & 3)][((buf[6] >> 0) & 7)]; |
| 912 | |
| 913 | if (power_real < -15) |
| 914 | tmp = 0; |
| 915 | else if ((power_real >= -15) && (power_real < 0)) |
| 916 | tmp = (2 * (power_real + 15)) / 3; |
| 917 | else if ((power_real >= 0) && (power_real < 20)) |
| 918 | tmp = 4 * power_real + 10; |
| 919 | else if ((power_real >= 20) && (power_real < 35)) |
| 920 | tmp = (2 * (power_real - 20)) / 3 + 90; |
| 921 | else |
| 922 | tmp = 100; |
| 923 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 924 | /* Scale value to 0x0000-0xffff */ |
Bimow Chen | 3adec27 | 2014-10-01 07:28:54 -0300 | [diff] [blame] | 925 | *strength = tmp * 0xffff / 100; |
| 926 | } |
| 927 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 928 | return 0; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 929 | err: |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 930 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 931 | return ret; |
| 932 | } |
| 933 | |
| 934 | static int af9033_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 935 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 936 | struct af9033_dev *dev = fe->demodulator_priv; |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 937 | |
Antti Palosaari | e53c474 | 2014-09-03 23:22:53 -0300 | [diff] [blame] | 938 | *ber = (dev->post_bit_error - dev->post_bit_error_prev); |
| 939 | dev->post_bit_error_prev = dev->post_bit_error; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 940 | |
| 941 | return 0; |
| 942 | } |
| 943 | |
| 944 | static int af9033_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
| 945 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 946 | struct af9033_dev *dev = fe->demodulator_priv; |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 947 | |
Antti Palosaari | 1d0ceae | 2014-09-03 23:07:39 -0300 | [diff] [blame] | 948 | *ucblocks = dev->error_block_count; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 949 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 950 | return 0; |
| 951 | } |
| 952 | |
| 953 | static int af9033_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
| 954 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 955 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 956 | struct i2c_client *client = dev->client; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 957 | int ret; |
| 958 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 959 | dev_dbg(&client->dev, "enable=%d\n", enable); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 960 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 961 | ret = regmap_update_bits(dev->regmap, 0x00fa04, 0x01, enable); |
| 962 | if (ret) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 963 | goto err; |
| 964 | |
| 965 | return 0; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 966 | err: |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 967 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 968 | return ret; |
| 969 | } |
| 970 | |
Mauro Carvalho Chehab | ed97a6f | 2014-03-14 14:29:06 -0300 | [diff] [blame] | 971 | static int af9033_pid_filter_ctrl(struct dvb_frontend *fe, int onoff) |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 972 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 973 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 974 | struct i2c_client *client = dev->client; |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 975 | int ret; |
| 976 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 977 | dev_dbg(&client->dev, "onoff=%d\n", onoff); |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 978 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 979 | ret = regmap_update_bits(dev->regmap, 0x80f993, 0x01, onoff); |
| 980 | if (ret) |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 981 | goto err; |
| 982 | |
| 983 | return 0; |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 984 | err: |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 985 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 986 | return ret; |
| 987 | } |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 988 | |
Antti Palosaari | 24e419a | 2014-08-09 14:59:53 -0300 | [diff] [blame] | 989 | static int af9033_pid_filter(struct dvb_frontend *fe, int index, u16 pid, |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 990 | int onoff) |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 991 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame] | 992 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 993 | struct i2c_client *client = dev->client; |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 994 | int ret; |
| 995 | u8 wbuf[2] = {(pid >> 0) & 0xff, (pid >> 8) & 0xff}; |
| 996 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 997 | dev_dbg(&client->dev, "index=%d pid=%04x onoff=%d\n", |
| 998 | index, pid, onoff); |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 999 | |
| 1000 | if (pid > 0x1fff) |
| 1001 | return 0; |
| 1002 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 1003 | ret = regmap_bulk_write(dev->regmap, 0x80f996, wbuf, 2); |
| 1004 | if (ret) |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1005 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 1006 | ret = regmap_write(dev->regmap, 0x80f994, onoff); |
| 1007 | if (ret) |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1008 | goto err; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 1009 | ret = regmap_write(dev->regmap, 0x80f995, index); |
| 1010 | if (ret) |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1011 | goto err; |
| 1012 | |
| 1013 | return 0; |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1014 | err: |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 1015 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1016 | return ret; |
| 1017 | } |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1018 | |
Max Kellermann | bd336e6 | 2016-08-09 18:32:21 -0300 | [diff] [blame] | 1019 | static const struct dvb_frontend_ops af9033_ops = { |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 1020 | .delsys = {SYS_DVBT}, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1021 | .info = { |
| 1022 | .name = "Afatech AF9033 (DVB-T)", |
Mauro Carvalho Chehab | f1b1eab | 2018-07-05 18:59:36 -0400 | [diff] [blame^] | 1023 | .frequency_min_hz = 174 * MHz, |
| 1024 | .frequency_max_hz = 862 * MHz, |
| 1025 | .frequency_stepsize_hz = 250 * kHz, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1026 | .caps = FE_CAN_FEC_1_2 | |
| 1027 | FE_CAN_FEC_2_3 | |
| 1028 | FE_CAN_FEC_3_4 | |
| 1029 | FE_CAN_FEC_5_6 | |
| 1030 | FE_CAN_FEC_7_8 | |
| 1031 | FE_CAN_FEC_AUTO | |
| 1032 | FE_CAN_QPSK | |
| 1033 | FE_CAN_QAM_16 | |
| 1034 | FE_CAN_QAM_64 | |
| 1035 | FE_CAN_QAM_AUTO | |
| 1036 | FE_CAN_TRANSMISSION_MODE_AUTO | |
| 1037 | FE_CAN_GUARD_INTERVAL_AUTO | |
| 1038 | FE_CAN_HIERARCHY_AUTO | |
| 1039 | FE_CAN_RECOVER | |
| 1040 | FE_CAN_MUTE_TS |
| 1041 | }, |
| 1042 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1043 | .init = af9033_init, |
| 1044 | .sleep = af9033_sleep, |
| 1045 | |
| 1046 | .get_tune_settings = af9033_get_tune_settings, |
| 1047 | .set_frontend = af9033_set_frontend, |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 1048 | .get_frontend = af9033_get_frontend, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1049 | |
| 1050 | .read_status = af9033_read_status, |
| 1051 | .read_snr = af9033_read_snr, |
| 1052 | .read_signal_strength = af9033_read_signal_strength, |
| 1053 | .read_ber = af9033_read_ber, |
| 1054 | .read_ucblocks = af9033_read_ucblocks, |
| 1055 | |
| 1056 | .i2c_gate_ctrl = af9033_i2c_gate_ctrl, |
| 1057 | }; |
| 1058 | |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1059 | static int af9033_probe(struct i2c_client *client, |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 1060 | const struct i2c_device_id *id) |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1061 | { |
| 1062 | struct af9033_config *cfg = client->dev.platform_data; |
| 1063 | struct af9033_dev *dev; |
| 1064 | int ret; |
| 1065 | u8 buf[8]; |
| 1066 | u32 reg; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 1067 | static const struct regmap_config regmap_config = { |
| 1068 | .reg_bits = 24, |
| 1069 | .val_bits = 8, |
| 1070 | }; |
| 1071 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 1072 | /* Allocate memory for the internal state */ |
| 1073 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 1074 | if (!dev) { |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1075 | ret = -ENOMEM; |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1076 | goto err; |
| 1077 | } |
| 1078 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 1079 | /* Setup the state */ |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1080 | dev->client = client; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 1081 | memcpy(&dev->cfg, cfg, sizeof(dev->cfg)); |
| 1082 | switch (dev->cfg.ts_mode) { |
| 1083 | case AF9033_TS_MODE_PARALLEL: |
| 1084 | dev->ts_mode_parallel = true; |
| 1085 | break; |
| 1086 | case AF9033_TS_MODE_SERIAL: |
| 1087 | dev->ts_mode_serial = true; |
| 1088 | break; |
| 1089 | case AF9033_TS_MODE_USB: |
| 1090 | /* USB mode for AF9035 */ |
| 1091 | default: |
| 1092 | break; |
| 1093 | } |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1094 | |
| 1095 | if (dev->cfg.clock != 12000000) { |
| 1096 | ret = -ENODEV; |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 1097 | dev_err(&client->dev, |
| 1098 | "Unsupported clock %u Hz. Only 12000000 Hz is supported currently\n", |
| 1099 | dev->cfg.clock); |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1100 | goto err_kfree; |
| 1101 | } |
| 1102 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 1103 | /* Create regmap */ |
| 1104 | dev->regmap = regmap_init_i2c(client, ®map_config); |
| 1105 | if (IS_ERR(dev->regmap)) { |
| 1106 | ret = PTR_ERR(dev->regmap); |
| 1107 | goto err_kfree; |
| 1108 | } |
| 1109 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 1110 | /* Firmware version */ |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1111 | switch (dev->cfg.tuner) { |
| 1112 | case AF9033_TUNER_IT9135_38: |
| 1113 | case AF9033_TUNER_IT9135_51: |
| 1114 | case AF9033_TUNER_IT9135_52: |
| 1115 | case AF9033_TUNER_IT9135_60: |
| 1116 | case AF9033_TUNER_IT9135_61: |
| 1117 | case AF9033_TUNER_IT9135_62: |
Antti Palosaari | 83f1161 | 2014-09-02 03:55:21 -0300 | [diff] [blame] | 1118 | dev->is_it9135 = true; |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1119 | reg = 0x004bfc; |
| 1120 | break; |
| 1121 | default: |
Antti Palosaari | 83f1161 | 2014-09-02 03:55:21 -0300 | [diff] [blame] | 1122 | dev->is_af9035 = true; |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1123 | reg = 0x0083e9; |
| 1124 | break; |
| 1125 | } |
| 1126 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 1127 | ret = regmap_bulk_read(dev->regmap, reg, &buf[0], 4); |
| 1128 | if (ret) |
| 1129 | goto err_regmap_exit; |
| 1130 | ret = regmap_bulk_read(dev->regmap, 0x804191, &buf[4], 4); |
| 1131 | if (ret) |
| 1132 | goto err_regmap_exit; |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1133 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 1134 | dev_info(&client->dev, |
| 1135 | "firmware version: LINK %d.%d.%d.%d - OFDM %d.%d.%d.%d\n", |
| 1136 | buf[0], buf[1], buf[2], buf[3], |
| 1137 | buf[4], buf[5], buf[6], buf[7]); |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1138 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 1139 | /* Sleep as chip seems to be partly active by default */ |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1140 | switch (dev->cfg.tuner) { |
| 1141 | case AF9033_TUNER_IT9135_38: |
| 1142 | case AF9033_TUNER_IT9135_51: |
| 1143 | case AF9033_TUNER_IT9135_52: |
| 1144 | case AF9033_TUNER_IT9135_60: |
| 1145 | case AF9033_TUNER_IT9135_61: |
| 1146 | case AF9033_TUNER_IT9135_62: |
| 1147 | /* IT9135 did not like to sleep at that early */ |
| 1148 | break; |
| 1149 | default: |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 1150 | ret = regmap_write(dev->regmap, 0x80004c, 0x01); |
| 1151 | if (ret) |
| 1152 | goto err_regmap_exit; |
| 1153 | ret = regmap_write(dev->regmap, 0x800000, 0x00); |
| 1154 | if (ret) |
| 1155 | goto err_regmap_exit; |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1156 | } |
| 1157 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 1158 | /* Create dvb frontend */ |
| 1159 | memcpy(&dev->fe.ops, &af9033_ops, sizeof(dev->fe.ops)); |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1160 | dev->fe.demodulator_priv = dev; |
| 1161 | *cfg->fe = &dev->fe; |
| 1162 | if (cfg->ops) { |
| 1163 | cfg->ops->pid_filter = af9033_pid_filter; |
| 1164 | cfg->ops->pid_filter_ctrl = af9033_pid_filter_ctrl; |
| 1165 | } |
Antti Palosaari | 3461831 | 2016-11-06 22:14:18 -0200 | [diff] [blame] | 1166 | cfg->regmap = dev->regmap; |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1167 | i2c_set_clientdata(client, dev); |
| 1168 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 1169 | dev_info(&client->dev, "Afatech AF9033 successfully attached\n"); |
| 1170 | |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1171 | return 0; |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 1172 | err_regmap_exit: |
| 1173 | regmap_exit(dev->regmap); |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1174 | err_kfree: |
| 1175 | kfree(dev); |
| 1176 | err: |
Antti Palosaari | 6a087f1 | 2014-08-31 21:08:09 -0300 | [diff] [blame] | 1177 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1178 | return ret; |
| 1179 | } |
| 1180 | |
| 1181 | static int af9033_remove(struct i2c_client *client) |
| 1182 | { |
| 1183 | struct af9033_dev *dev = i2c_get_clientdata(client); |
| 1184 | |
Antti Palosaari | 81e1991 | 2016-11-06 18:55:36 -0200 | [diff] [blame] | 1185 | dev_dbg(&client->dev, "\n"); |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1186 | |
Antti Palosaari | bc85d5e | 2016-11-06 02:20:29 -0200 | [diff] [blame] | 1187 | regmap_exit(dev->regmap); |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1188 | kfree(dev); |
| 1189 | |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
| 1193 | static const struct i2c_device_id af9033_id_table[] = { |
| 1194 | {"af9033", 0}, |
| 1195 | {} |
| 1196 | }; |
| 1197 | MODULE_DEVICE_TABLE(i2c, af9033_id_table); |
| 1198 | |
| 1199 | static struct i2c_driver af9033_driver = { |
| 1200 | .driver = { |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1201 | .name = "af9033", |
Antti Palosaari | 7281217 | 2016-06-29 20:40:22 -0300 | [diff] [blame] | 1202 | .suppress_bind_attrs = true, |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1203 | }, |
| 1204 | .probe = af9033_probe, |
| 1205 | .remove = af9033_remove, |
| 1206 | .id_table = af9033_id_table, |
| 1207 | }; |
| 1208 | |
| 1209 | module_i2c_driver(af9033_driver); |
| 1210 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1211 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 1212 | MODULE_DESCRIPTION("Afatech AF9033 DVB-T demodulator driver"); |
| 1213 | MODULE_LICENSE("GPL"); |