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