Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Abilis Systems Single DVB-T Receiver |
| 3 | * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com> |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 4 | * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com> |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2, or (at your option) |
| 9 | * any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 15 | */ |
Mauro Carvalho Chehab | 47f7912 | 2014-08-12 18:50:22 -0300 | [diff] [blame] | 16 | |
| 17 | #include <dvb_frontend.h> |
| 18 | |
| 19 | #include "as102_fe.h" |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 20 | |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 21 | struct as102_state { |
| 22 | struct dvb_frontend frontend; |
| 23 | struct as10x_demod_stats demod_stats; |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 24 | |
Mauro Carvalho Chehab | 47f7912 | 2014-08-12 18:50:22 -0300 | [diff] [blame] | 25 | const struct as102_fe_ops *ops; |
| 26 | void *priv; |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 27 | uint8_t elna_cfg; |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 28 | |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 29 | /* signal strength */ |
| 30 | uint16_t signal_strength; |
| 31 | /* bit error rate */ |
| 32 | uint32_t ber; |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 33 | }; |
| 34 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 35 | static uint8_t as102_fe_get_code_rate(enum fe_code_rate arg) |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 36 | { |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 37 | uint8_t c; |
| 38 | |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 39 | switch (arg) { |
| 40 | case FEC_1_2: |
| 41 | c = CODE_RATE_1_2; |
| 42 | break; |
| 43 | case FEC_2_3: |
| 44 | c = CODE_RATE_2_3; |
| 45 | break; |
| 46 | case FEC_3_4: |
| 47 | c = CODE_RATE_3_4; |
| 48 | break; |
| 49 | case FEC_5_6: |
| 50 | c = CODE_RATE_5_6; |
| 51 | break; |
| 52 | case FEC_7_8: |
| 53 | c = CODE_RATE_7_8; |
| 54 | break; |
| 55 | default: |
| 56 | c = CODE_RATE_UNKNOWN; |
| 57 | break; |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | return c; |
| 61 | } |
| 62 | |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 63 | static int as102_fe_set_frontend(struct dvb_frontend *fe) |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 64 | { |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 65 | struct as102_state *state = fe->demodulator_priv; |
| 66 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 67 | struct as10x_tune_args tune_args = { 0 }; |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 68 | |
| 69 | /* set frequency */ |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 70 | tune_args.freq = c->frequency / 1000; |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 71 | |
| 72 | /* fix interleaving_mode */ |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 73 | tune_args.interleaving_mode = INTLV_NATIVE; |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 74 | |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 75 | switch (c->bandwidth_hz) { |
Mauro Carvalho Chehab | dfc6438 | 2011-12-26 15:20:03 -0300 | [diff] [blame] | 76 | case 8000000: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 77 | tune_args.bandwidth = BW_8_MHZ; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 78 | break; |
Mauro Carvalho Chehab | dfc6438 | 2011-12-26 15:20:03 -0300 | [diff] [blame] | 79 | case 7000000: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 80 | tune_args.bandwidth = BW_7_MHZ; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 81 | break; |
Mauro Carvalho Chehab | dfc6438 | 2011-12-26 15:20:03 -0300 | [diff] [blame] | 82 | case 6000000: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 83 | tune_args.bandwidth = BW_6_MHZ; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 84 | break; |
| 85 | default: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 86 | tune_args.bandwidth = BW_8_MHZ; |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 87 | } |
| 88 | |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 89 | switch (c->guard_interval) { |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 90 | case GUARD_INTERVAL_1_32: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 91 | tune_args.guard_interval = GUARD_INT_1_32; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 92 | break; |
| 93 | case GUARD_INTERVAL_1_16: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 94 | tune_args.guard_interval = GUARD_INT_1_16; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 95 | break; |
| 96 | case GUARD_INTERVAL_1_8: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 97 | tune_args.guard_interval = GUARD_INT_1_8; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 98 | break; |
| 99 | case GUARD_INTERVAL_1_4: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 100 | tune_args.guard_interval = GUARD_INT_1_4; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 101 | break; |
| 102 | case GUARD_INTERVAL_AUTO: |
| 103 | default: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 104 | tune_args.guard_interval = GUARD_UNKNOWN; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 105 | break; |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 106 | } |
| 107 | |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 108 | switch (c->modulation) { |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 109 | case QPSK: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 110 | tune_args.modulation = CONST_QPSK; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 111 | break; |
| 112 | case QAM_16: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 113 | tune_args.modulation = CONST_QAM16; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 114 | break; |
| 115 | case QAM_64: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 116 | tune_args.modulation = CONST_QAM64; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 117 | break; |
| 118 | default: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 119 | tune_args.modulation = CONST_UNKNOWN; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 120 | break; |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 121 | } |
| 122 | |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 123 | switch (c->transmission_mode) { |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 124 | case TRANSMISSION_MODE_2K: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 125 | tune_args.transmission_mode = TRANS_MODE_2K; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 126 | break; |
| 127 | case TRANSMISSION_MODE_8K: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 128 | tune_args.transmission_mode = TRANS_MODE_8K; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 129 | break; |
| 130 | default: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 131 | tune_args.transmission_mode = TRANS_MODE_UNKNOWN; |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 132 | } |
| 133 | |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 134 | switch (c->hierarchy) { |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 135 | case HIERARCHY_NONE: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 136 | tune_args.hierarchy = HIER_NONE; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 137 | break; |
| 138 | case HIERARCHY_1: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 139 | tune_args.hierarchy = HIER_ALPHA_1; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 140 | break; |
| 141 | case HIERARCHY_2: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 142 | tune_args.hierarchy = HIER_ALPHA_2; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 143 | break; |
| 144 | case HIERARCHY_4: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 145 | tune_args.hierarchy = HIER_ALPHA_4; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 146 | break; |
| 147 | case HIERARCHY_AUTO: |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 148 | tune_args.hierarchy = HIER_UNKNOWN; |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 149 | break; |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 150 | } |
| 151 | |
Martin Kepplinger | 2179de6 | 2014-08-04 08:13:16 -0300 | [diff] [blame] | 152 | pr_debug("as102: tuner parameters: freq: %d bw: 0x%02x gi: 0x%02x\n", |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 153 | c->frequency, |
| 154 | tune_args.bandwidth, |
| 155 | tune_args.guard_interval); |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 156 | |
| 157 | /* |
| 158 | * Detect a hierarchy selection |
| 159 | * if HP/LP are both set to FEC_NONE, HP will be selected. |
| 160 | */ |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 161 | if ((tune_args.hierarchy != HIER_NONE) && |
| 162 | ((c->code_rate_LP == FEC_NONE) || |
| 163 | (c->code_rate_HP == FEC_NONE))) { |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 164 | |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 165 | if (c->code_rate_LP == FEC_NONE) { |
| 166 | tune_args.hier_select = HIER_HIGH_PRIORITY; |
| 167 | tune_args.code_rate = |
| 168 | as102_fe_get_code_rate(c->code_rate_HP); |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 169 | } |
| 170 | |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 171 | if (c->code_rate_HP == FEC_NONE) { |
| 172 | tune_args.hier_select = HIER_LOW_PRIORITY; |
| 173 | tune_args.code_rate = |
| 174 | as102_fe_get_code_rate(c->code_rate_LP); |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 175 | } |
| 176 | |
Martin Kepplinger | 2179de6 | 2014-08-04 08:13:16 -0300 | [diff] [blame] | 177 | pr_debug("as102: \thierarchy: 0x%02x selected: %s code_rate_%s: 0x%02x\n", |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 178 | tune_args.hierarchy, |
| 179 | tune_args.hier_select == HIER_HIGH_PRIORITY ? |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 180 | "HP" : "LP", |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 181 | tune_args.hier_select == HIER_HIGH_PRIORITY ? |
Devin Heitmueller | 87ad567e | 2011-10-31 12:24:44 -0300 | [diff] [blame] | 182 | "HP" : "LP", |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 183 | tune_args.code_rate); |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 184 | } else { |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 185 | tune_args.code_rate = |
| 186 | as102_fe_get_code_rate(c->code_rate_HP); |
Pierrick Hascoet | 41b44e0 | 2011-10-31 12:24:39 -0300 | [diff] [blame] | 187 | } |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 188 | |
Mauro Carvalho Chehab | 1d6207f | 2014-08-12 18:50:20 -0300 | [diff] [blame] | 189 | /* Set frontend arguments */ |
Mauro Carvalho Chehab | 47f7912 | 2014-08-12 18:50:22 -0300 | [diff] [blame] | 190 | return state->ops->set_tune(state->priv, &tune_args); |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 191 | } |
| 192 | |
Mauro Carvalho Chehab | 7e3e68b | 2016-02-04 12:58:30 -0200 | [diff] [blame] | 193 | static int as102_fe_get_frontend(struct dvb_frontend *fe, |
| 194 | struct dtv_frontend_properties *c) |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 195 | { |
| 196 | struct as102_state *state = fe->demodulator_priv; |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 197 | int ret = 0; |
| 198 | struct as10x_tps tps = { 0 }; |
| 199 | |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 200 | /* send abilis command: GET_TPS */ |
Mauro Carvalho Chehab | 47f7912 | 2014-08-12 18:50:22 -0300 | [diff] [blame] | 201 | ret = state->ops->get_tps(state->priv, &tps); |
Mauro Carvalho Chehab | c098c219 | 2014-08-12 18:50:21 -0300 | [diff] [blame] | 202 | if (ret < 0) |
| 203 | return ret; |
| 204 | |
| 205 | /* extract constellation */ |
| 206 | switch (tps.modulation) { |
| 207 | case CONST_QPSK: |
| 208 | c->modulation = QPSK; |
| 209 | break; |
| 210 | case CONST_QAM16: |
| 211 | c->modulation = QAM_16; |
| 212 | break; |
| 213 | case CONST_QAM64: |
| 214 | c->modulation = QAM_64; |
| 215 | break; |
| 216 | } |
| 217 | |
| 218 | /* extract hierarchy */ |
| 219 | switch (tps.hierarchy) { |
| 220 | case HIER_NONE: |
| 221 | c->hierarchy = HIERARCHY_NONE; |
| 222 | break; |
| 223 | case HIER_ALPHA_1: |
| 224 | c->hierarchy = HIERARCHY_1; |
| 225 | break; |
| 226 | case HIER_ALPHA_2: |
| 227 | c->hierarchy = HIERARCHY_2; |
| 228 | break; |
| 229 | case HIER_ALPHA_4: |
| 230 | c->hierarchy = HIERARCHY_4; |
| 231 | break; |
| 232 | } |
| 233 | |
| 234 | /* extract code rate HP */ |
| 235 | switch (tps.code_rate_HP) { |
| 236 | case CODE_RATE_1_2: |
| 237 | c->code_rate_HP = FEC_1_2; |
| 238 | break; |
| 239 | case CODE_RATE_2_3: |
| 240 | c->code_rate_HP = FEC_2_3; |
| 241 | break; |
| 242 | case CODE_RATE_3_4: |
| 243 | c->code_rate_HP = FEC_3_4; |
| 244 | break; |
| 245 | case CODE_RATE_5_6: |
| 246 | c->code_rate_HP = FEC_5_6; |
| 247 | break; |
| 248 | case CODE_RATE_7_8: |
| 249 | c->code_rate_HP = FEC_7_8; |
| 250 | break; |
| 251 | } |
| 252 | |
| 253 | /* extract code rate LP */ |
| 254 | switch (tps.code_rate_LP) { |
| 255 | case CODE_RATE_1_2: |
| 256 | c->code_rate_LP = FEC_1_2; |
| 257 | break; |
| 258 | case CODE_RATE_2_3: |
| 259 | c->code_rate_LP = FEC_2_3; |
| 260 | break; |
| 261 | case CODE_RATE_3_4: |
| 262 | c->code_rate_LP = FEC_3_4; |
| 263 | break; |
| 264 | case CODE_RATE_5_6: |
| 265 | c->code_rate_LP = FEC_5_6; |
| 266 | break; |
| 267 | case CODE_RATE_7_8: |
| 268 | c->code_rate_LP = FEC_7_8; |
| 269 | break; |
| 270 | } |
| 271 | |
| 272 | /* extract guard interval */ |
| 273 | switch (tps.guard_interval) { |
| 274 | case GUARD_INT_1_32: |
| 275 | c->guard_interval = GUARD_INTERVAL_1_32; |
| 276 | break; |
| 277 | case GUARD_INT_1_16: |
| 278 | c->guard_interval = GUARD_INTERVAL_1_16; |
| 279 | break; |
| 280 | case GUARD_INT_1_8: |
| 281 | c->guard_interval = GUARD_INTERVAL_1_8; |
| 282 | break; |
| 283 | case GUARD_INT_1_4: |
| 284 | c->guard_interval = GUARD_INTERVAL_1_4; |
| 285 | break; |
| 286 | } |
| 287 | |
| 288 | /* extract transmission mode */ |
| 289 | switch (tps.transmission_mode) { |
| 290 | case TRANS_MODE_2K: |
| 291 | c->transmission_mode = TRANSMISSION_MODE_2K; |
| 292 | break; |
| 293 | case TRANS_MODE_8K: |
| 294 | c->transmission_mode = TRANSMISSION_MODE_8K; |
| 295 | break; |
| 296 | } |
| 297 | |
| 298 | return 0; |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | static int as102_fe_get_tune_settings(struct dvb_frontend *fe, |
| 302 | struct dvb_frontend_tune_settings *settings) { |
| 303 | |
| 304 | settings->min_delay_ms = 1000; |
| 305 | |
| 306 | return 0; |
| 307 | } |
| 308 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 309 | static int as102_fe_read_status(struct dvb_frontend *fe, enum fe_status *status) |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 310 | { |
| 311 | int ret = 0; |
| 312 | struct as102_state *state = fe->demodulator_priv; |
| 313 | struct as10x_tune_status tstate = { 0 }; |
| 314 | |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 315 | /* send abilis command: GET_TUNE_STATUS */ |
Mauro Carvalho Chehab | 47f7912 | 2014-08-12 18:50:22 -0300 | [diff] [blame] | 316 | ret = state->ops->get_status(state->priv, &tstate); |
| 317 | if (ret < 0) |
| 318 | return ret; |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 319 | |
| 320 | state->signal_strength = tstate.signal_strength; |
| 321 | state->ber = tstate.BER; |
| 322 | |
| 323 | switch (tstate.tune_state) { |
| 324 | case TUNE_STATUS_SIGNAL_DVB_OK: |
| 325 | *status = FE_HAS_SIGNAL | FE_HAS_CARRIER; |
| 326 | break; |
| 327 | case TUNE_STATUS_STREAM_DETECTED: |
Mauro Carvalho Chehab | 4628f99 | 2014-08-12 18:50:24 -0300 | [diff] [blame] | 328 | *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | |
| 329 | FE_HAS_VITERBI; |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 330 | break; |
| 331 | case TUNE_STATUS_STREAM_TUNED: |
| 332 | *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | |
Mauro Carvalho Chehab | 4628f99 | 2014-08-12 18:50:24 -0300 | [diff] [blame] | 333 | FE_HAS_LOCK | FE_HAS_VITERBI; |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 334 | break; |
| 335 | default: |
| 336 | *status = TUNE_STATUS_NOT_TUNED; |
| 337 | } |
| 338 | |
Mauro Carvalho Chehab | 47f7912 | 2014-08-12 18:50:22 -0300 | [diff] [blame] | 339 | pr_debug("as102: tuner status: 0x%02x, strength %d, per: %d, ber: %d\n", |
| 340 | tstate.tune_state, tstate.signal_strength, |
| 341 | tstate.PER, tstate.BER); |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 342 | |
Mauro Carvalho Chehab | 47f7912 | 2014-08-12 18:50:22 -0300 | [diff] [blame] | 343 | if (!(*status & FE_HAS_LOCK)) { |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 344 | memset(&state->demod_stats, 0, sizeof(state->demod_stats)); |
Mauro Carvalho Chehab | 47f7912 | 2014-08-12 18:50:22 -0300 | [diff] [blame] | 345 | return 0; |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 346 | } |
| 347 | |
Mauro Carvalho Chehab | 47f7912 | 2014-08-12 18:50:22 -0300 | [diff] [blame] | 348 | ret = state->ops->get_stats(state->priv, &state->demod_stats); |
| 349 | if (ret < 0) |
| 350 | memset(&state->demod_stats, 0, sizeof(state->demod_stats)); |
| 351 | |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 352 | return ret; |
| 353 | } |
| 354 | |
| 355 | /* |
| 356 | * Note: |
| 357 | * - in AS102 SNR=MER |
| 358 | * - the SNR will be returned in linear terms, i.e. not in dB |
| 359 | * - the accuracy equals ±2dB for a SNR range from 4dB to 30dB |
| 360 | * - the accuracy is >2dB for SNR values outside this range |
| 361 | */ |
| 362 | static int as102_fe_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 363 | { |
| 364 | struct as102_state *state = fe->demodulator_priv; |
| 365 | |
| 366 | *snr = state->demod_stats.mer; |
| 367 | |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | static int as102_fe_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 372 | { |
| 373 | struct as102_state *state = fe->demodulator_priv; |
| 374 | |
| 375 | *ber = state->ber; |
| 376 | |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | static int as102_fe_read_signal_strength(struct dvb_frontend *fe, |
| 381 | u16 *strength) |
| 382 | { |
| 383 | struct as102_state *state = fe->demodulator_priv; |
| 384 | |
| 385 | *strength = (((0xffff * 400) * state->signal_strength + 41000) * 2); |
| 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | static int as102_fe_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
| 391 | { |
| 392 | struct as102_state *state = fe->demodulator_priv; |
| 393 | |
| 394 | if (state->demod_stats.has_started) |
| 395 | *ucblocks = state->demod_stats.bad_frame_count; |
| 396 | else |
| 397 | *ucblocks = 0; |
| 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | static int as102_fe_ts_bus_ctrl(struct dvb_frontend *fe, int acquire) |
| 403 | { |
| 404 | struct as102_state *state = fe->demodulator_priv; |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 405 | |
Mauro Carvalho Chehab | 47f7912 | 2014-08-12 18:50:22 -0300 | [diff] [blame] | 406 | return state->ops->stream_ctrl(state->priv, acquire, |
| 407 | state->elna_cfg); |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 408 | } |
| 409 | |
Mauro Carvalho Chehab | 5b6aa19 | 2014-08-12 21:35:44 -0300 | [diff] [blame] | 410 | static void as102_fe_release(struct dvb_frontend *fe) |
| 411 | { |
| 412 | struct as102_state *state = fe->demodulator_priv; |
| 413 | |
| 414 | kfree(state); |
| 415 | } |
| 416 | |
| 417 | |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 418 | static struct dvb_frontend_ops as102_fe_ops = { |
| 419 | .delsys = { SYS_DVBT }, |
| 420 | .info = { |
| 421 | .name = "Abilis AS102 DVB-T", |
| 422 | .frequency_min = 174000000, |
| 423 | .frequency_max = 862000000, |
| 424 | .frequency_stepsize = 166667, |
| 425 | .caps = FE_CAN_INVERSION_AUTO |
| 426 | | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
| 427 | | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
| 428 | | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QPSK |
| 429 | | FE_CAN_QAM_AUTO |
| 430 | | FE_CAN_TRANSMISSION_MODE_AUTO |
| 431 | | FE_CAN_GUARD_INTERVAL_AUTO |
| 432 | | FE_CAN_HIERARCHY_AUTO |
| 433 | | FE_CAN_RECOVER |
| 434 | | FE_CAN_MUTE_TS |
| 435 | }, |
| 436 | |
| 437 | .set_frontend = as102_fe_set_frontend, |
| 438 | .get_frontend = as102_fe_get_frontend, |
| 439 | .get_tune_settings = as102_fe_get_tune_settings, |
| 440 | |
| 441 | .read_status = as102_fe_read_status, |
| 442 | .read_snr = as102_fe_read_snr, |
| 443 | .read_ber = as102_fe_read_ber, |
| 444 | .read_signal_strength = as102_fe_read_signal_strength, |
| 445 | .read_ucblocks = as102_fe_read_ucblocks, |
| 446 | .ts_bus_ctrl = as102_fe_ts_bus_ctrl, |
Mauro Carvalho Chehab | 5b6aa19 | 2014-08-12 21:35:44 -0300 | [diff] [blame] | 447 | .release = as102_fe_release, |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 448 | }; |
| 449 | |
| 450 | struct dvb_frontend *as102_attach(const char *name, |
Mauro Carvalho Chehab | 47f7912 | 2014-08-12 18:50:22 -0300 | [diff] [blame] | 451 | const struct as102_fe_ops *ops, |
| 452 | void *priv, |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 453 | uint8_t elna_cfg) |
| 454 | { |
| 455 | struct as102_state *state; |
| 456 | struct dvb_frontend *fe; |
| 457 | |
| 458 | state = kzalloc(sizeof(struct as102_state), GFP_KERNEL); |
| 459 | if (state == NULL) { |
Mauro Carvalho Chehab | 47f7912 | 2014-08-12 18:50:22 -0300 | [diff] [blame] | 460 | pr_err("%s: unable to allocate memory for state\n", __func__); |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 461 | return NULL; |
| 462 | } |
| 463 | fe = &state->frontend; |
| 464 | fe->demodulator_priv = state; |
Mauro Carvalho Chehab | 47f7912 | 2014-08-12 18:50:22 -0300 | [diff] [blame] | 465 | state->ops = ops; |
| 466 | state->priv = priv; |
Mauro Carvalho Chehab | b601d9a | 2014-08-12 18:50:19 -0300 | [diff] [blame] | 467 | state->elna_cfg = elna_cfg; |
| 468 | |
| 469 | /* init frontend callback ops */ |
| 470 | memcpy(&fe->ops, &as102_fe_ops, sizeof(struct dvb_frontend_ops)); |
| 471 | strncpy(fe->ops.info.name, name, sizeof(fe->ops.info.name)); |
| 472 | |
| 473 | return fe; |
| 474 | |
| 475 | } |
| 476 | EXPORT_SYMBOL_GPL(as102_attach); |
Mauro Carvalho Chehab | dcae778 | 2014-08-12 18:50:23 -0300 | [diff] [blame] | 477 | |
| 478 | MODULE_DESCRIPTION("as102-fe"); |
| 479 | MODULE_LICENSE("GPL"); |
| 480 | MODULE_AUTHOR("Pierrick Hascoet <pierrick.hascoet@abilis.com>"); |