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