Uri Shkolnik | e527579 | 2009-04-27 09:09:47 -0300 | [diff] [blame] | 1 | /**************************************************************** |
| 2 | |
| 3 | Siano Mobile Silicon, Inc. |
| 4 | MDTV receiver kernel modules. |
| 5 | Copyright (C) 2006-2008, Uri Shkolnik |
| 6 | |
| 7 | This program is free software: you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation, either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | ****************************************************************/ |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 21 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 22 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 24 | #include <linux/init.h> |
Mauro Carvalho Chehab | f35d09d | 2013-03-22 06:22:45 -0300 | [diff] [blame] | 25 | #include <asm/div64.h> |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 26 | |
Uri Shkolnik | c9679e3 | 2009-05-14 16:28:17 -0300 | [diff] [blame] | 27 | #include "dmxdev.h" |
| 28 | #include "dvbdev.h" |
| 29 | #include "dvb_demux.h" |
| 30 | #include "dvb_frontend.h" |
| 31 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 32 | #include "smscoreapi.h" |
Michael Krufky | 1c11d54 | 2008-06-18 22:09:55 -0300 | [diff] [blame] | 33 | #include "sms-cards.h" |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 34 | |
Mauro Carvalho Chehab | 503efe5 | 2013-03-10 09:04:44 -0300 | [diff] [blame] | 35 | #include "smsdvb.h" |
| 36 | |
Michael Krufky | 9c59f968 | 2008-05-19 18:57:12 -0300 | [diff] [blame] | 37 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 38 | |
Adrian Bunk | c5e0bd1 | 2008-07-21 23:17:36 -0300 | [diff] [blame] | 39 | static struct list_head g_smsdvb_clients; |
| 40 | static struct mutex g_smsdvb_clientslock; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 41 | |
Michael Krufky | 0d02efe | 2009-02-27 02:42:16 -0300 | [diff] [blame] | 42 | static int sms_dbg; |
| 43 | module_param_named(debug, sms_dbg, int, 0644); |
| 44 | MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))"); |
| 45 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 46 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 47 | u32 sms_to_guard_interval_table[] = { |
| 48 | [0] = GUARD_INTERVAL_1_32, |
| 49 | [1] = GUARD_INTERVAL_1_16, |
| 50 | [2] = GUARD_INTERVAL_1_8, |
| 51 | [3] = GUARD_INTERVAL_1_4, |
| 52 | }; |
| 53 | |
| 54 | u32 sms_to_code_rate_table[] = { |
| 55 | [0] = FEC_1_2, |
| 56 | [1] = FEC_2_3, |
| 57 | [2] = FEC_3_4, |
| 58 | [3] = FEC_5_6, |
| 59 | [4] = FEC_7_8, |
| 60 | }; |
| 61 | |
| 62 | |
| 63 | u32 sms_to_hierarchy_table[] = { |
| 64 | [0] = HIERARCHY_NONE, |
| 65 | [1] = HIERARCHY_1, |
| 66 | [2] = HIERARCHY_2, |
| 67 | [3] = HIERARCHY_4, |
| 68 | }; |
| 69 | |
| 70 | u32 sms_to_modulation_table[] = { |
| 71 | [0] = QPSK, |
| 72 | [1] = QAM_16, |
| 73 | [2] = QAM_64, |
| 74 | [3] = DQPSK, |
| 75 | }; |
| 76 | |
Mauro Carvalho Chehab | ff702eb | 2013-03-09 15:54:46 -0300 | [diff] [blame] | 77 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 78 | /* Events that may come from DVB v3 adapter */ |
| 79 | static void sms_board_dvb3_event(struct smsdvb_client_t *client, |
| 80 | enum SMS_DVB3_EVENTS event) { |
Uri Shkolnik | 4db989f | 2009-05-19 12:28:02 -0300 | [diff] [blame] | 81 | |
| 82 | struct smscore_device_t *coredev = client->coredev; |
| 83 | switch (event) { |
| 84 | case DVB3_EVENT_INIT: |
| 85 | sms_debug("DVB3_EVENT_INIT"); |
| 86 | sms_board_event(coredev, BOARD_EVENT_BIND); |
| 87 | break; |
| 88 | case DVB3_EVENT_SLEEP: |
| 89 | sms_debug("DVB3_EVENT_SLEEP"); |
| 90 | sms_board_event(coredev, BOARD_EVENT_POWER_SUSPEND); |
| 91 | break; |
| 92 | case DVB3_EVENT_HOTPLUG: |
| 93 | sms_debug("DVB3_EVENT_HOTPLUG"); |
| 94 | sms_board_event(coredev, BOARD_EVENT_POWER_INIT); |
| 95 | break; |
| 96 | case DVB3_EVENT_FE_LOCK: |
| 97 | if (client->event_fe_state != DVB3_EVENT_FE_LOCK) { |
| 98 | client->event_fe_state = DVB3_EVENT_FE_LOCK; |
| 99 | sms_debug("DVB3_EVENT_FE_LOCK"); |
| 100 | sms_board_event(coredev, BOARD_EVENT_FE_LOCK); |
| 101 | } |
| 102 | break; |
| 103 | case DVB3_EVENT_FE_UNLOCK: |
| 104 | if (client->event_fe_state != DVB3_EVENT_FE_UNLOCK) { |
| 105 | client->event_fe_state = DVB3_EVENT_FE_UNLOCK; |
| 106 | sms_debug("DVB3_EVENT_FE_UNLOCK"); |
| 107 | sms_board_event(coredev, BOARD_EVENT_FE_UNLOCK); |
| 108 | } |
| 109 | break; |
| 110 | case DVB3_EVENT_UNC_OK: |
| 111 | if (client->event_unc_state != DVB3_EVENT_UNC_OK) { |
| 112 | client->event_unc_state = DVB3_EVENT_UNC_OK; |
| 113 | sms_debug("DVB3_EVENT_UNC_OK"); |
| 114 | sms_board_event(coredev, BOARD_EVENT_MULTIPLEX_OK); |
| 115 | } |
| 116 | break; |
| 117 | case DVB3_EVENT_UNC_ERR: |
| 118 | if (client->event_unc_state != DVB3_EVENT_UNC_ERR) { |
| 119 | client->event_unc_state = DVB3_EVENT_UNC_ERR; |
| 120 | sms_debug("DVB3_EVENT_UNC_ERR"); |
| 121 | sms_board_event(coredev, BOARD_EVENT_MULTIPLEX_ERRORS); |
| 122 | } |
| 123 | break; |
| 124 | |
| 125 | default: |
| 126 | sms_err("Unknown dvb3 api event"); |
| 127 | break; |
| 128 | } |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 129 | } |
| 130 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 131 | static void smsdvb_stats_not_ready(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | 5eb2397 | 2009-12-25 11:29:42 -0300 | [diff] [blame] | 132 | { |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 133 | struct smsdvb_client_t *client = |
| 134 | container_of(fe, struct smsdvb_client_t, frontend); |
| 135 | struct smscore_device_t *coredev = client->coredev; |
| 136 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 137 | int i, n_layers; |
Mauro Carvalho Chehab | 5eb2397 | 2009-12-25 11:29:42 -0300 | [diff] [blame] | 138 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 139 | switch (smscore_get_device_mode(coredev)) { |
| 140 | case DEVICE_MODE_ISDBT: |
| 141 | case DEVICE_MODE_ISDBT_BDA: |
| 142 | n_layers = 4; |
Jakob Normark | 250a51c | 2013-05-19 09:30:23 -0300 | [diff] [blame] | 143 | break; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 144 | default: |
| 145 | n_layers = 1; |
| 146 | } |
Mauro Carvalho Chehab | 5eb2397 | 2009-12-25 11:29:42 -0300 | [diff] [blame] | 147 | |
Mauro Carvalho Chehab | f5de95e | 2013-03-10 12:06:30 -0300 | [diff] [blame] | 148 | /* Global stats */ |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 149 | c->strength.len = 1; |
| 150 | c->cnr.len = 1; |
Mauro Carvalho Chehab | f5de95e | 2013-03-10 12:06:30 -0300 | [diff] [blame] | 151 | c->strength.stat[0].scale = FE_SCALE_DECIBEL; |
| 152 | c->cnr.stat[0].scale = FE_SCALE_DECIBEL; |
Mauro Carvalho Chehab | 5eb2397 | 2009-12-25 11:29:42 -0300 | [diff] [blame] | 153 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 154 | /* Per-layer stats */ |
| 155 | c->post_bit_error.len = n_layers; |
| 156 | c->post_bit_count.len = n_layers; |
| 157 | c->block_error.len = n_layers; |
| 158 | c->block_count.len = n_layers; |
Mauro Carvalho Chehab | b405909 | 2013-03-07 21:58:47 -0300 | [diff] [blame] | 159 | |
Mauro Carvalho Chehab | f5de95e | 2013-03-10 12:06:30 -0300 | [diff] [blame] | 160 | /* |
| 161 | * Put all of them at FE_SCALE_NOT_AVAILABLE. They're dynamically |
| 162 | * changed when the stats become available. |
| 163 | */ |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 164 | for (i = 0; i < n_layers; i++) { |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 165 | c->post_bit_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE; |
| 166 | c->post_bit_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE; |
| 167 | c->block_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE; |
| 168 | c->block_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | b405909 | 2013-03-07 21:58:47 -0300 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 172 | static inline int sms_to_mode(u32 mode) |
Mauro Carvalho Chehab | b405909 | 2013-03-07 21:58:47 -0300 | [diff] [blame] | 173 | { |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 174 | switch (mode) { |
| 175 | case 2: |
| 176 | return TRANSMISSION_MODE_2K; |
| 177 | case 4: |
| 178 | return TRANSMISSION_MODE_4K; |
| 179 | case 8: |
| 180 | return TRANSMISSION_MODE_8K; |
| 181 | } |
| 182 | return TRANSMISSION_MODE_AUTO; |
| 183 | } |
Mauro Carvalho Chehab | b405909 | 2013-03-07 21:58:47 -0300 | [diff] [blame] | 184 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 185 | static inline int sms_to_status(u32 is_demod_locked, u32 is_rf_locked) |
| 186 | { |
| 187 | if (is_demod_locked) |
| 188 | return FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | |
| 189 | FE_HAS_SYNC | FE_HAS_LOCK; |
Mauro Carvalho Chehab | b405909 | 2013-03-07 21:58:47 -0300 | [diff] [blame] | 190 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 191 | if (is_rf_locked) |
| 192 | return FE_HAS_SIGNAL | FE_HAS_CARRIER; |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
Mauro Carvalho Chehab | 5c3b874 | 2013-03-10 19:21:13 -0300 | [diff] [blame] | 197 | static inline u32 sms_to_bw(u32 value) |
| 198 | { |
| 199 | return value * 1000000; |
| 200 | } |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 201 | |
| 202 | #define convert_from_table(value, table, defval) ({ \ |
| 203 | u32 __ret; \ |
| 204 | if (value < ARRAY_SIZE(table)) \ |
| 205 | __ret = table[value]; \ |
| 206 | else \ |
| 207 | __ret = defval; \ |
| 208 | __ret; \ |
| 209 | }) |
| 210 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 211 | #define sms_to_guard_interval(value) \ |
| 212 | convert_from_table(value, sms_to_guard_interval_table, \ |
| 213 | GUARD_INTERVAL_AUTO); |
| 214 | |
| 215 | #define sms_to_code_rate(value) \ |
| 216 | convert_from_table(value, sms_to_code_rate_table, \ |
| 217 | FEC_NONE); |
| 218 | |
| 219 | #define sms_to_hierarchy(value) \ |
| 220 | convert_from_table(value, sms_to_hierarchy_table, \ |
| 221 | FEC_NONE); |
| 222 | |
| 223 | #define sms_to_modulation(value) \ |
| 224 | convert_from_table(value, sms_to_modulation_table, \ |
| 225 | FEC_NONE); |
| 226 | |
| 227 | static void smsdvb_update_tx_params(struct smsdvb_client_t *client, |
Mauro Carvalho Chehab | cf0e9cf | 2013-03-21 09:06:03 -0300 | [diff] [blame] | 228 | struct sms_tx_stats *p) |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 229 | { |
| 230 | struct dvb_frontend *fe = &client->frontend; |
| 231 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 232 | |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 233 | c->frequency = p->frequency; |
| 234 | client->fe_status = sms_to_status(p->is_demod_locked, 0); |
| 235 | c->bandwidth_hz = sms_to_bw(p->bandwidth); |
| 236 | c->transmission_mode = sms_to_mode(p->transmission_mode); |
| 237 | c->guard_interval = sms_to_guard_interval(p->guard_interval); |
| 238 | c->code_rate_HP = sms_to_code_rate(p->code_rate); |
| 239 | c->code_rate_LP = sms_to_code_rate(p->lp_code_rate); |
| 240 | c->hierarchy = sms_to_hierarchy(p->hierarchy); |
| 241 | c->modulation = sms_to_modulation(p->constellation); |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | static void smsdvb_update_per_slices(struct smsdvb_client_t *client, |
| 245 | struct RECEPTION_STATISTICS_PER_SLICES_S *p) |
| 246 | { |
| 247 | struct dvb_frontend *fe = &client->frontend; |
| 248 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | f35d09d | 2013-03-22 06:22:45 -0300 | [diff] [blame] | 249 | u64 tmp; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 250 | |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 251 | client->fe_status = sms_to_status(p->is_demod_locked, p->is_rf_locked); |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 252 | c->modulation = sms_to_modulation(p->constellation); |
Mauro Carvalho Chehab | b405909 | 2013-03-07 21:58:47 -0300 | [diff] [blame] | 253 | |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 254 | /* signal Strength, in DBm */ |
| 255 | c->strength.stat[0].uvalue = p->in_band_power * 1000; |
Mauro Carvalho Chehab | f5de95e | 2013-03-10 12:06:30 -0300 | [diff] [blame] | 256 | |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 257 | /* Carrier to noise ratio, in DB */ |
Mauro Carvalho Chehab | f5de95e | 2013-03-10 12:06:30 -0300 | [diff] [blame] | 258 | c->cnr.stat[0].svalue = p->snr * 1000; |
| 259 | |
| 260 | /* PER/BER requires demod lock */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 261 | if (!p->is_demod_locked) |
Mauro Carvalho Chehab | f5de95e | 2013-03-10 12:06:30 -0300 | [diff] [blame] | 262 | return; |
| 263 | |
Mauro Carvalho Chehab | b405909 | 2013-03-07 21:58:47 -0300 | [diff] [blame] | 264 | /* TS PER */ |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 265 | client->last_per = c->block_error.stat[0].uvalue; |
| 266 | c->block_error.stat[0].scale = FE_SCALE_COUNTER; |
| 267 | c->block_count.stat[0].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 268 | c->block_error.stat[0].uvalue += p->ets_packets; |
| 269 | c->block_count.stat[0].uvalue += p->ets_packets + p->ts_packets; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 270 | |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 271 | /* ber */ |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 272 | c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; |
| 273 | c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 274 | c->post_bit_error.stat[0].uvalue += p->ber_error_count; |
| 275 | c->post_bit_count.stat[0].uvalue += p->ber_bit_count; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 276 | |
| 277 | /* Legacy PER/BER */ |
Mauro Carvalho Chehab | f35d09d | 2013-03-22 06:22:45 -0300 | [diff] [blame] | 278 | tmp = p->ets_packets * 65535; |
Bjørn Mork | ec53250 | 2013-08-14 05:24:39 -0300 | [diff] [blame] | 279 | if (p->ts_packets + p->ets_packets) |
| 280 | do_div(tmp, p->ts_packets + p->ets_packets); |
Mauro Carvalho Chehab | f35d09d | 2013-03-22 06:22:45 -0300 | [diff] [blame] | 281 | client->legacy_per = tmp; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | static void smsdvb_update_dvb_stats(struct smsdvb_client_t *client, |
Mauro Carvalho Chehab | cf0e9cf | 2013-03-21 09:06:03 -0300 | [diff] [blame] | 285 | struct sms_stats *p) |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 286 | { |
| 287 | struct dvb_frontend *fe = &client->frontend; |
| 288 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 289 | |
Mauro Carvalho Chehab | 503efe5 | 2013-03-10 09:04:44 -0300 | [diff] [blame] | 290 | if (client->prt_dvb_stats) |
| 291 | client->prt_dvb_stats(client->debug_data, p); |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 292 | |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 293 | client->fe_status = sms_to_status(p->is_demod_locked, p->is_rf_locked); |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 294 | |
| 295 | /* Update DVB modulation parameters */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 296 | c->frequency = p->frequency; |
| 297 | client->fe_status = sms_to_status(p->is_demod_locked, 0); |
| 298 | c->bandwidth_hz = sms_to_bw(p->bandwidth); |
| 299 | c->transmission_mode = sms_to_mode(p->transmission_mode); |
| 300 | c->guard_interval = sms_to_guard_interval(p->guard_interval); |
| 301 | c->code_rate_HP = sms_to_code_rate(p->code_rate); |
| 302 | c->code_rate_LP = sms_to_code_rate(p->lp_code_rate); |
| 303 | c->hierarchy = sms_to_hierarchy(p->hierarchy); |
| 304 | c->modulation = sms_to_modulation(p->constellation); |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 305 | |
| 306 | /* update reception data */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 307 | c->lna = p->is_external_lna_on ? 1 : 0; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 308 | |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 309 | /* Carrier to noise ratio, in DB */ |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 310 | c->cnr.stat[0].svalue = p->SNR * 1000; |
| 311 | |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 312 | /* signal Strength, in DBm */ |
| 313 | c->strength.stat[0].uvalue = p->in_band_pwr * 1000; |
Mauro Carvalho Chehab | f5de95e | 2013-03-10 12:06:30 -0300 | [diff] [blame] | 314 | |
| 315 | /* PER/BER requires demod lock */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 316 | if (!p->is_demod_locked) |
Mauro Carvalho Chehab | f5de95e | 2013-03-10 12:06:30 -0300 | [diff] [blame] | 317 | return; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 318 | |
| 319 | /* TS PER */ |
| 320 | client->last_per = c->block_error.stat[0].uvalue; |
| 321 | c->block_error.stat[0].scale = FE_SCALE_COUNTER; |
| 322 | c->block_count.stat[0].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 323 | c->block_error.stat[0].uvalue += p->error_ts_packets; |
| 324 | c->block_count.stat[0].uvalue += p->total_ts_packets; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 325 | |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 326 | /* ber */ |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 327 | c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; |
| 328 | c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 329 | c->post_bit_error.stat[0].uvalue += p->ber_error_count; |
| 330 | c->post_bit_count.stat[0].uvalue += p->ber_bit_count; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 331 | |
| 332 | /* Legacy PER/BER */ |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 333 | client->legacy_ber = p->ber; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 334 | }; |
| 335 | |
| 336 | static void smsdvb_update_isdbt_stats(struct smsdvb_client_t *client, |
Mauro Carvalho Chehab | cf0e9cf | 2013-03-21 09:06:03 -0300 | [diff] [blame] | 337 | struct sms_isdbt_stats *p) |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 338 | { |
| 339 | struct dvb_frontend *fe = &client->frontend; |
| 340 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | cf0e9cf | 2013-03-21 09:06:03 -0300 | [diff] [blame] | 341 | struct sms_isdbt_layer_stats *lr; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 342 | int i, n_layers; |
| 343 | |
Mauro Carvalho Chehab | 503efe5 | 2013-03-10 09:04:44 -0300 | [diff] [blame] | 344 | if (client->prt_isdb_stats) |
| 345 | client->prt_isdb_stats(client->debug_data, p); |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 346 | |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 347 | client->fe_status = sms_to_status(p->is_demod_locked, p->is_rf_locked); |
Mauro Carvalho Chehab | 773adad | 2013-03-16 21:05:30 -0300 | [diff] [blame] | 348 | |
| 349 | /* |
| 350 | * Firmware 2.1 seems to report only lock status and |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 351 | * signal strength. The signal strength indicator is at the |
Mauro Carvalho Chehab | 773adad | 2013-03-16 21:05:30 -0300 | [diff] [blame] | 352 | * wrong field. |
| 353 | */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 354 | if (p->statistics_type == 0) { |
| 355 | c->strength.stat[0].uvalue = ((s32)p->transmission_mode) * 1000; |
Mauro Carvalho Chehab | 773adad | 2013-03-16 21:05:30 -0300 | [diff] [blame] | 356 | c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 357 | return; |
| 358 | } |
| 359 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 360 | /* Update ISDB-T transmission parameters */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 361 | c->frequency = p->frequency; |
| 362 | c->bandwidth_hz = sms_to_bw(p->bandwidth); |
| 363 | c->transmission_mode = sms_to_mode(p->transmission_mode); |
| 364 | c->guard_interval = sms_to_guard_interval(p->guard_interval); |
| 365 | c->isdbt_partial_reception = p->partial_reception ? 1 : 0; |
| 366 | n_layers = p->num_of_layers; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 367 | if (n_layers < 1) |
| 368 | n_layers = 1; |
| 369 | if (n_layers > 3) |
| 370 | n_layers = 3; |
| 371 | c->isdbt_layer_enabled = 0; |
| 372 | |
| 373 | /* update reception data */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 374 | c->lna = p->is_external_lna_on ? 1 : 0; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 375 | |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 376 | /* Carrier to noise ratio, in DB */ |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 377 | c->cnr.stat[0].svalue = p->SNR * 1000; |
| 378 | |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 379 | /* signal Strength, in DBm */ |
| 380 | c->strength.stat[0].uvalue = p->in_band_pwr * 1000; |
Mauro Carvalho Chehab | f5de95e | 2013-03-10 12:06:30 -0300 | [diff] [blame] | 381 | |
| 382 | /* PER/BER and per-layer stats require demod lock */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 383 | if (!p->is_demod_locked) |
Mauro Carvalho Chehab | f5de95e | 2013-03-10 12:06:30 -0300 | [diff] [blame] | 384 | return; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 385 | |
| 386 | client->last_per = c->block_error.stat[0].uvalue; |
| 387 | |
| 388 | /* Clears global counters, as the code below will sum it again */ |
| 389 | c->block_error.stat[0].uvalue = 0; |
| 390 | c->block_count.stat[0].uvalue = 0; |
Mauro Carvalho Chehab | 9671045 | 2013-03-10 13:38:41 -0300 | [diff] [blame] | 391 | c->block_error.stat[0].scale = FE_SCALE_COUNTER; |
| 392 | c->block_count.stat[0].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 393 | c->post_bit_error.stat[0].uvalue = 0; |
| 394 | c->post_bit_count.stat[0].uvalue = 0; |
Mauro Carvalho Chehab | 9671045 | 2013-03-10 13:38:41 -0300 | [diff] [blame] | 395 | c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; |
| 396 | c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 397 | |
| 398 | for (i = 0; i < n_layers; i++) { |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 399 | lr = &p->layer_info[i]; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 400 | |
| 401 | /* Update per-layer transmission parameters */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 402 | if (lr->number_of_segments > 0 && lr->number_of_segments < 13) { |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 403 | c->isdbt_layer_enabled |= 1 << i; |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 404 | c->layer[i].segment_count = lr->number_of_segments; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 405 | } else { |
| 406 | continue; |
| 407 | } |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 408 | c->layer[i].modulation = sms_to_modulation(lr->constellation); |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 409 | |
| 410 | /* TS PER */ |
Mauro Carvalho Chehab | 9671045 | 2013-03-10 13:38:41 -0300 | [diff] [blame] | 411 | c->block_error.stat[i + 1].scale = FE_SCALE_COUNTER; |
| 412 | c->block_count.stat[i + 1].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 413 | c->block_error.stat[i + 1].uvalue += lr->error_ts_packets; |
| 414 | c->block_count.stat[i + 1].uvalue += lr->total_ts_packets; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 415 | |
| 416 | /* Update global PER counter */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 417 | c->block_error.stat[0].uvalue += lr->error_ts_packets; |
| 418 | c->block_count.stat[0].uvalue += lr->total_ts_packets; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 419 | |
| 420 | /* BER */ |
Mauro Carvalho Chehab | 9671045 | 2013-03-10 13:38:41 -0300 | [diff] [blame] | 421 | c->post_bit_error.stat[i + 1].scale = FE_SCALE_COUNTER; |
| 422 | c->post_bit_count.stat[i + 1].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 423 | c->post_bit_error.stat[i + 1].uvalue += lr->ber_error_count; |
| 424 | c->post_bit_count.stat[i + 1].uvalue += lr->ber_bit_count; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 425 | |
| 426 | /* Update global BER counter */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 427 | c->post_bit_error.stat[0].uvalue += lr->ber_error_count; |
| 428 | c->post_bit_count.stat[0].uvalue += lr->ber_bit_count; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | |
| 432 | static void smsdvb_update_isdbt_stats_ex(struct smsdvb_client_t *client, |
Mauro Carvalho Chehab | cf0e9cf | 2013-03-21 09:06:03 -0300 | [diff] [blame] | 433 | struct sms_isdbt_stats_ex *p) |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 434 | { |
| 435 | struct dvb_frontend *fe = &client->frontend; |
| 436 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | cf0e9cf | 2013-03-21 09:06:03 -0300 | [diff] [blame] | 437 | struct sms_isdbt_layer_stats *lr; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 438 | int i, n_layers; |
| 439 | |
Mauro Carvalho Chehab | 503efe5 | 2013-03-10 09:04:44 -0300 | [diff] [blame] | 440 | if (client->prt_isdb_stats_ex) |
| 441 | client->prt_isdb_stats_ex(client->debug_data, p); |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 442 | |
| 443 | /* Update ISDB-T transmission parameters */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 444 | c->frequency = p->frequency; |
| 445 | client->fe_status = sms_to_status(p->is_demod_locked, 0); |
| 446 | c->bandwidth_hz = sms_to_bw(p->bandwidth); |
| 447 | c->transmission_mode = sms_to_mode(p->transmission_mode); |
| 448 | c->guard_interval = sms_to_guard_interval(p->guard_interval); |
| 449 | c->isdbt_partial_reception = p->partial_reception ? 1 : 0; |
| 450 | n_layers = p->num_of_layers; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 451 | if (n_layers < 1) |
| 452 | n_layers = 1; |
| 453 | if (n_layers > 3) |
| 454 | n_layers = 3; |
| 455 | c->isdbt_layer_enabled = 0; |
| 456 | |
| 457 | /* update reception data */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 458 | c->lna = p->is_external_lna_on ? 1 : 0; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 459 | |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 460 | /* Carrier to noise ratio, in DB */ |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 461 | c->cnr.stat[0].svalue = p->SNR * 1000; |
| 462 | |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 463 | /* signal Strength, in DBm */ |
| 464 | c->strength.stat[0].uvalue = p->in_band_pwr * 1000; |
Mauro Carvalho Chehab | f5de95e | 2013-03-10 12:06:30 -0300 | [diff] [blame] | 465 | |
| 466 | /* PER/BER and per-layer stats require demod lock */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 467 | if (!p->is_demod_locked) |
Mauro Carvalho Chehab | f5de95e | 2013-03-10 12:06:30 -0300 | [diff] [blame] | 468 | return; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 469 | |
| 470 | client->last_per = c->block_error.stat[0].uvalue; |
| 471 | |
| 472 | /* Clears global counters, as the code below will sum it again */ |
| 473 | c->block_error.stat[0].uvalue = 0; |
| 474 | c->block_count.stat[0].uvalue = 0; |
Mauro Carvalho Chehab | 9671045 | 2013-03-10 13:38:41 -0300 | [diff] [blame] | 475 | c->block_error.stat[0].scale = FE_SCALE_COUNTER; |
| 476 | c->block_count.stat[0].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 477 | c->post_bit_error.stat[0].uvalue = 0; |
| 478 | c->post_bit_count.stat[0].uvalue = 0; |
Mauro Carvalho Chehab | 9671045 | 2013-03-10 13:38:41 -0300 | [diff] [blame] | 479 | c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; |
| 480 | c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 481 | |
Mauro Carvalho Chehab | 9671045 | 2013-03-10 13:38:41 -0300 | [diff] [blame] | 482 | c->post_bit_error.len = n_layers + 1; |
| 483 | c->post_bit_count.len = n_layers + 1; |
| 484 | c->block_error.len = n_layers + 1; |
| 485 | c->block_count.len = n_layers + 1; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 486 | for (i = 0; i < n_layers; i++) { |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 487 | lr = &p->layer_info[i]; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 488 | |
| 489 | /* Update per-layer transmission parameters */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 490 | if (lr->number_of_segments > 0 && lr->number_of_segments < 13) { |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 491 | c->isdbt_layer_enabled |= 1 << i; |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 492 | c->layer[i].segment_count = lr->number_of_segments; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 493 | } else { |
| 494 | continue; |
| 495 | } |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 496 | c->layer[i].modulation = sms_to_modulation(lr->constellation); |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 497 | |
| 498 | /* TS PER */ |
Mauro Carvalho Chehab | 9671045 | 2013-03-10 13:38:41 -0300 | [diff] [blame] | 499 | c->block_error.stat[i + 1].scale = FE_SCALE_COUNTER; |
| 500 | c->block_count.stat[i + 1].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 501 | c->block_error.stat[i + 1].uvalue += lr->error_ts_packets; |
| 502 | c->block_count.stat[i + 1].uvalue += lr->total_ts_packets; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 503 | |
| 504 | /* Update global PER counter */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 505 | c->block_error.stat[0].uvalue += lr->error_ts_packets; |
| 506 | c->block_count.stat[0].uvalue += lr->total_ts_packets; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 507 | |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 508 | /* ber */ |
Mauro Carvalho Chehab | 9671045 | 2013-03-10 13:38:41 -0300 | [diff] [blame] | 509 | c->post_bit_error.stat[i + 1].scale = FE_SCALE_COUNTER; |
| 510 | c->post_bit_count.stat[i + 1].scale = FE_SCALE_COUNTER; |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 511 | c->post_bit_error.stat[i + 1].uvalue += lr->ber_error_count; |
| 512 | c->post_bit_count.stat[i + 1].uvalue += lr->ber_bit_count; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 513 | |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 514 | /* Update global ber counter */ |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 515 | c->post_bit_error.stat[0].uvalue += lr->ber_error_count; |
| 516 | c->post_bit_count.stat[0].uvalue += lr->ber_bit_count; |
Mauro Carvalho Chehab | 5eb2397 | 2009-12-25 11:29:42 -0300 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 520 | static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 521 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 522 | struct smsdvb_client_t *client = (struct smsdvb_client_t *) context; |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 523 | struct sms_msg_hdr *phdr = (struct sms_msg_hdr *) (((u8 *) cb->p) |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 524 | + cb->offset); |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 525 | void *p = phdr + 1; |
| 526 | struct dvb_frontend *fe = &client->frontend; |
| 527 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 528 | bool is_status_update = false; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 529 | |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 530 | switch (phdr->msg_type) { |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 531 | case MSG_SMS_DVBT_BDA_DATA: |
Mauro Carvalho Chehab | e1b2ac4 | 2013-03-15 07:22:08 -0300 | [diff] [blame] | 532 | /* |
| 533 | * Only feed data to dvb demux if are there any feed listening |
| 534 | * to it and if the device has tuned |
| 535 | */ |
| 536 | if (client->feed_users && client->has_tuned) |
| 537 | dvb_dmx_swfilter(&client->demux, p, |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 538 | cb->size - sizeof(struct sms_msg_hdr)); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 539 | break; |
| 540 | |
| 541 | case MSG_SMS_RF_TUNE_RES: |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 542 | case MSG_SMS_ISDBT_TUNE_RES: |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 543 | complete(&client->tune_done); |
| 544 | break; |
| 545 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 546 | case MSG_SMS_SIGNAL_DETECTED_IND: |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 547 | client->fe_status = FE_HAS_SIGNAL | FE_HAS_CARRIER | |
| 548 | FE_HAS_VITERBI | FE_HAS_SYNC | |
| 549 | FE_HAS_LOCK; |
| 550 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 551 | is_status_update = true; |
| 552 | break; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 553 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 554 | case MSG_SMS_NO_SIGNAL_IND: |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 555 | client->fe_status = 0; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 556 | |
| 557 | is_status_update = true; |
| 558 | break; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 559 | |
| 560 | case MSG_SMS_TRANSMISSION_IND: |
| 561 | smsdvb_update_tx_params(client, p); |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 562 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 563 | is_status_update = true; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 564 | break; |
Mauro Carvalho Chehab | 5eb2397 | 2009-12-25 11:29:42 -0300 | [diff] [blame] | 565 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 566 | case MSG_SMS_HO_PER_SLICES_IND: |
| 567 | smsdvb_update_per_slices(client, p); |
| 568 | |
| 569 | is_status_update = true; |
| 570 | break; |
| 571 | |
| 572 | case MSG_SMS_GET_STATISTICS_RES: |
Mauro Carvalho Chehab | 5eb2397 | 2009-12-25 11:29:42 -0300 | [diff] [blame] | 573 | switch (smscore_get_device_mode(client->coredev)) { |
| 574 | case DEVICE_MODE_ISDBT: |
| 575 | case DEVICE_MODE_ISDBT_BDA: |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 576 | smsdvb_update_isdbt_stats(client, p); |
Mauro Carvalho Chehab | 5eb2397 | 2009-12-25 11:29:42 -0300 | [diff] [blame] | 577 | break; |
| 578 | default: |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 579 | /* Skip sms_msg_statistics_info:request_result field */ |
Mauro Carvalho Chehab | c02272f | 2013-03-09 23:01:48 -0300 | [diff] [blame] | 580 | smsdvb_update_dvb_stats(client, p + sizeof(u32)); |
Mauro Carvalho Chehab | 5eb2397 | 2009-12-25 11:29:42 -0300 | [diff] [blame] | 581 | } |
Mauro Carvalho Chehab | b405909 | 2013-03-07 21:58:47 -0300 | [diff] [blame] | 582 | |
| 583 | is_status_update = true; |
Mauro Carvalho Chehab | b405909 | 2013-03-07 21:58:47 -0300 | [diff] [blame] | 584 | break; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 585 | |
| 586 | /* Only for ISDB-T */ |
| 587 | case MSG_SMS_GET_STATISTICS_EX_RES: |
Mauro Carvalho Chehab | dfef84f | 2013-03-21 08:49:43 -0300 | [diff] [blame] | 588 | /* Skip sms_msg_statistics_info:request_result field? */ |
Mauro Carvalho Chehab | c02272f | 2013-03-09 23:01:48 -0300 | [diff] [blame] | 589 | smsdvb_update_isdbt_stats_ex(client, p + sizeof(u32)); |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 590 | is_status_update = true; |
| 591 | break; |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 592 | default: |
Mauro Carvalho Chehab | 4c3bdb5 | 2013-03-09 09:27:39 -0300 | [diff] [blame] | 593 | sms_info("message not handled"); |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 594 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 595 | smscore_putbuffer(client->coredev, cb); |
| 596 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 597 | if (is_status_update) { |
Mauro Carvalho Chehab | 9671045 | 2013-03-10 13:38:41 -0300 | [diff] [blame] | 598 | if (client->fe_status & FE_HAS_LOCK) { |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 599 | sms_board_dvb3_event(client, DVB3_EVENT_FE_LOCK); |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 600 | if (client->last_per == c->block_error.stat[0].uvalue) |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 601 | sms_board_dvb3_event(client, DVB3_EVENT_UNC_OK); |
| 602 | else |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 603 | sms_board_dvb3_event(client, DVB3_EVENT_UNC_ERR); |
Mauro Carvalho Chehab | e1b2ac4 | 2013-03-15 07:22:08 -0300 | [diff] [blame] | 604 | client->has_tuned = true; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 605 | } else { |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 606 | smsdvb_stats_not_ready(fe); |
Mauro Carvalho Chehab | e1b2ac4 | 2013-03-15 07:22:08 -0300 | [diff] [blame] | 607 | client->has_tuned = false; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 608 | sms_board_dvb3_event(client, DVB3_EVENT_FE_UNLOCK); |
| 609 | } |
Mauro Carvalho Chehab | 76e41a6 | 2013-03-07 16:32:33 -0300 | [diff] [blame] | 610 | complete(&client->stats_done); |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 611 | } |
| 612 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 613 | return 0; |
| 614 | } |
| 615 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 616 | static void smsdvb_unregister_client(struct smsdvb_client_t *client) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 617 | { |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 618 | /* must be called under clientslock */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 619 | |
| 620 | list_del(&client->entry); |
| 621 | |
Mauro Carvalho Chehab | 503efe5 | 2013-03-10 09:04:44 -0300 | [diff] [blame] | 622 | smsdvb_debugfs_release(client); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 623 | smscore_unregister_client(client->smsclient); |
| 624 | dvb_unregister_frontend(&client->frontend); |
| 625 | dvb_dmxdev_release(&client->dmxdev); |
| 626 | dvb_dmx_release(&client->demux); |
| 627 | dvb_unregister_adapter(&client->adapter); |
| 628 | kfree(client); |
| 629 | } |
| 630 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 631 | static void smsdvb_onremove(void *context) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 632 | { |
| 633 | kmutex_lock(&g_smsdvb_clientslock); |
| 634 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 635 | smsdvb_unregister_client((struct smsdvb_client_t *) context); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 636 | |
| 637 | kmutex_unlock(&g_smsdvb_clientslock); |
| 638 | } |
| 639 | |
| 640 | static int smsdvb_start_feed(struct dvb_demux_feed *feed) |
| 641 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 642 | struct smsdvb_client_t *client = |
| 643 | container_of(feed->demux, struct smsdvb_client_t, demux); |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 644 | struct sms_msg_data pid_msg; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 645 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 646 | sms_debug("add pid %d(%x)", |
Michael Krufky | 068d6c0 | 2008-06-19 01:15:46 -0300 | [diff] [blame] | 647 | feed->pid, feed->pid); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 648 | |
Mauro Carvalho Chehab | e1b2ac4 | 2013-03-15 07:22:08 -0300 | [diff] [blame] | 649 | client->feed_users++; |
| 650 | |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 651 | pid_msg.x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID; |
| 652 | pid_msg.x_msg_header.msg_dst_id = HIF_TASK; |
| 653 | pid_msg.x_msg_header.msg_flags = 0; |
| 654 | pid_msg.x_msg_header.msg_type = MSG_SMS_ADD_PID_FILTER_REQ; |
| 655 | pid_msg.x_msg_header.msg_length = sizeof(pid_msg); |
| 656 | pid_msg.msg_data[0] = feed->pid; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 657 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 658 | return smsclient_sendrequest(client->smsclient, |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 659 | &pid_msg, sizeof(pid_msg)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static int smsdvb_stop_feed(struct dvb_demux_feed *feed) |
| 663 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 664 | struct smsdvb_client_t *client = |
| 665 | container_of(feed->demux, struct smsdvb_client_t, demux); |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 666 | struct sms_msg_data pid_msg; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 667 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 668 | sms_debug("remove pid %d(%x)", |
Michael Krufky | 068d6c0 | 2008-06-19 01:15:46 -0300 | [diff] [blame] | 669 | feed->pid, feed->pid); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 670 | |
Mauro Carvalho Chehab | e1b2ac4 | 2013-03-15 07:22:08 -0300 | [diff] [blame] | 671 | client->feed_users--; |
| 672 | |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 673 | pid_msg.x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID; |
| 674 | pid_msg.x_msg_header.msg_dst_id = HIF_TASK; |
| 675 | pid_msg.x_msg_header.msg_flags = 0; |
| 676 | pid_msg.x_msg_header.msg_type = MSG_SMS_REMOVE_PID_FILTER_REQ; |
| 677 | pid_msg.x_msg_header.msg_length = sizeof(pid_msg); |
| 678 | pid_msg.msg_data[0] = feed->pid; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 679 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 680 | return smsclient_sendrequest(client->smsclient, |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 681 | &pid_msg, sizeof(pid_msg)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 682 | } |
| 683 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 684 | static int smsdvb_sendrequest_and_wait(struct smsdvb_client_t *client, |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 685 | void *buffer, size_t size, |
| 686 | struct completion *completion) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 687 | { |
Uri Shkolnik | ba79bb2 | 2009-05-12 11:37:09 -0300 | [diff] [blame] | 688 | int rc; |
| 689 | |
Uri Shkolnik | ba79bb2 | 2009-05-12 11:37:09 -0300 | [diff] [blame] | 690 | rc = smsclient_sendrequest(client->smsclient, buffer, size); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 691 | if (rc < 0) |
| 692 | return rc; |
| 693 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 694 | return wait_for_completion_timeout(completion, |
| 695 | msecs_to_jiffies(2000)) ? |
| 696 | 0 : -ETIME; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 697 | } |
| 698 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 699 | static int smsdvb_send_statistics_request(struct smsdvb_client_t *client) |
| 700 | { |
| 701 | int rc; |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 702 | struct sms_msg_hdr msg; |
Mauro Carvalho Chehab | b405909 | 2013-03-07 21:58:47 -0300 | [diff] [blame] | 703 | |
Mauro Carvalho Chehab | a9b9fbd | 2013-03-10 10:51:25 -0300 | [diff] [blame] | 704 | /* Don't request stats too fast */ |
| 705 | if (client->get_stats_jiffies && |
| 706 | (!time_after(jiffies, client->get_stats_jiffies))) |
| 707 | return 0; |
| 708 | client->get_stats_jiffies = jiffies + msecs_to_jiffies(100); |
Mauro Carvalho Chehab | b405909 | 2013-03-07 21:58:47 -0300 | [diff] [blame] | 709 | |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 710 | msg.msg_src_id = DVBT_BDA_CONTROL_MSG_ID; |
| 711 | msg.msg_dst_id = HIF_TASK; |
| 712 | msg.msg_flags = 0; |
| 713 | msg.msg_length = sizeof(msg); |
Mauro Carvalho Chehab | b405909 | 2013-03-07 21:58:47 -0300 | [diff] [blame] | 714 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 715 | switch (smscore_get_device_mode(client->coredev)) { |
| 716 | case DEVICE_MODE_ISDBT: |
| 717 | case DEVICE_MODE_ISDBT_BDA: |
| 718 | /* |
| 719 | * Check for firmware version, to avoid breaking for old cards |
| 720 | */ |
| 721 | if (client->coredev->fw_version >= 0x800) |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 722 | msg.msg_type = MSG_SMS_GET_STATISTICS_EX_REQ; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 723 | else |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 724 | msg.msg_type = MSG_SMS_GET_STATISTICS_REQ; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 725 | break; |
| 726 | default: |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 727 | msg.msg_type = MSG_SMS_GET_STATISTICS_REQ; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 728 | } |
Mauro Carvalho Chehab | b405909 | 2013-03-07 21:58:47 -0300 | [diff] [blame] | 729 | |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 730 | rc = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg), |
Mauro Carvalho Chehab | 76e41a6 | 2013-03-07 16:32:33 -0300 | [diff] [blame] | 731 | &client->stats_done); |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 732 | |
| 733 | return rc; |
| 734 | } |
| 735 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 736 | static inline int led_feedback(struct smsdvb_client_t *client) |
| 737 | { |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 738 | if (!(client->fe_status & FE_HAS_LOCK)) |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 739 | return sms_board_led_feedback(client->coredev, SMS_LED_OFF); |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 740 | |
| 741 | return sms_board_led_feedback(client->coredev, |
| 742 | (client->legacy_ber == 0) ? |
| 743 | SMS_LED_HI : SMS_LED_LO); |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 744 | } |
| 745 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 746 | static int smsdvb_read_status(struct dvb_frontend *fe, fe_status_t *stat) |
| 747 | { |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 748 | int rc; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 749 | struct smsdvb_client_t *client; |
| 750 | client = container_of(fe, struct smsdvb_client_t, frontend); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 751 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 752 | rc = smsdvb_send_statistics_request(client); |
| 753 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 754 | *stat = client->fe_status; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 755 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 756 | led_feedback(client); |
| 757 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 758 | return rc; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | static int smsdvb_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 762 | { |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 763 | int rc; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 764 | struct smsdvb_client_t *client; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 765 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 766 | client = container_of(fe, struct smsdvb_client_t, frontend); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 767 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 768 | rc = smsdvb_send_statistics_request(client); |
| 769 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 770 | *ber = client->legacy_ber; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 771 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 772 | led_feedback(client); |
| 773 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 774 | return rc; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | static int smsdvb_read_signal_strength(struct dvb_frontend *fe, u16 *strength) |
| 778 | { |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 779 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 780 | int rc; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 781 | s32 power = (s32) c->strength.stat[0].uvalue; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 782 | struct smsdvb_client_t *client; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 783 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 784 | client = container_of(fe, struct smsdvb_client_t, frontend); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 785 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 786 | rc = smsdvb_send_statistics_request(client); |
| 787 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 788 | if (power < -95) |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 789 | *strength = 0; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 790 | else if (power > -29) |
| 791 | *strength = 65535; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 792 | else |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 793 | *strength = (power + 95) * 65535 / 66; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 794 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 795 | led_feedback(client); |
| 796 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 797 | return rc; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | static int smsdvb_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 801 | { |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 802 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 803 | int rc; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 804 | struct smsdvb_client_t *client; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 805 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 806 | client = container_of(fe, struct smsdvb_client_t, frontend); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 807 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 808 | rc = smsdvb_send_statistics_request(client); |
| 809 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 810 | /* Preferred scale for SNR with legacy API: 0.1 dB */ |
Mauro Carvalho Chehab | f35d09d | 2013-03-22 06:22:45 -0300 | [diff] [blame] | 811 | *snr = ((u32)c->cnr.stat[0].svalue) / 100; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 812 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 813 | led_feedback(client); |
| 814 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 815 | return rc; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 816 | } |
| 817 | |
Michael Krufky | 851a909 | 2008-11-22 14:56:37 -0300 | [diff] [blame] | 818 | static int smsdvb_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
| 819 | { |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 820 | int rc; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 821 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 822 | struct smsdvb_client_t *client; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 823 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 824 | client = container_of(fe, struct smsdvb_client_t, frontend); |
Michael Krufky | 851a909 | 2008-11-22 14:56:37 -0300 | [diff] [blame] | 825 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 826 | rc = smsdvb_send_statistics_request(client); |
| 827 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 828 | *ucblocks = c->block_error.stat[0].uvalue; |
Michael Krufky | 851a909 | 2008-11-22 14:56:37 -0300 | [diff] [blame] | 829 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 830 | led_feedback(client); |
| 831 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 832 | return rc; |
Michael Krufky | 851a909 | 2008-11-22 14:56:37 -0300 | [diff] [blame] | 833 | } |
| 834 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 835 | static int smsdvb_get_tune_settings(struct dvb_frontend *fe, |
| 836 | struct dvb_frontend_tune_settings *tune) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 837 | { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 838 | sms_debug(""); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 839 | |
| 840 | tune->min_delay_ms = 400; |
| 841 | tune->step_size = 250000; |
| 842 | tune->max_drift = 0; |
| 843 | return 0; |
| 844 | } |
| 845 | |
Mauro Carvalho Chehab | 15115c1 | 2011-12-26 16:31:29 -0300 | [diff] [blame] | 846 | static int smsdvb_dvbt_set_frontend(struct dvb_frontend *fe) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 847 | { |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 848 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 849 | struct smsdvb_client_t *client = |
| 850 | container_of(fe, struct smsdvb_client_t, frontend); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 851 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 852 | struct { |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 853 | struct sms_msg_hdr msg; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 854 | u32 Data[3]; |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 855 | } msg; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 856 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 857 | int ret; |
| 858 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 859 | client->fe_status = 0; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 860 | client->event_fe_state = -1; |
| 861 | client->event_unc_state = -1; |
Mauro Carvalho Chehab | e85c97a | 2009-12-25 07:17:03 -0300 | [diff] [blame] | 862 | fe->dtv_property_cache.delivery_system = SYS_DVBT; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 863 | |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 864 | msg.msg.msg_src_id = DVBT_BDA_CONTROL_MSG_ID; |
| 865 | msg.msg.msg_dst_id = HIF_TASK; |
| 866 | msg.msg.msg_flags = 0; |
| 867 | msg.msg.msg_type = MSG_SMS_RF_TUNE_REQ; |
| 868 | msg.msg.msg_length = sizeof(msg); |
| 869 | msg.Data[0] = c->frequency; |
| 870 | msg.Data[2] = 12000000; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 871 | |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 872 | sms_info("%s: freq %d band %d", __func__, c->frequency, |
| 873 | c->bandwidth_hz); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 874 | |
Mauro Carvalho Chehab | 643e15a | 2009-12-25 07:29:06 -0300 | [diff] [blame] | 875 | switch (c->bandwidth_hz / 1000000) { |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 876 | case 8: |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 877 | msg.Data[1] = BW_8_MHZ; |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 878 | break; |
| 879 | case 7: |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 880 | msg.Data[1] = BW_7_MHZ; |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 881 | break; |
| 882 | case 6: |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 883 | msg.Data[1] = BW_6_MHZ; |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 884 | break; |
| 885 | case 0: |
| 886 | return -EOPNOTSUPP; |
| 887 | default: |
| 888 | return -EINVAL; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 889 | } |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 890 | /* Disable LNA, if any. An error is returned if no LNA is present */ |
| 891 | ret = sms_board_lna_control(client->coredev, 0); |
| 892 | if (ret == 0) { |
| 893 | fe_status_t status; |
| 894 | |
| 895 | /* tune with LNA off at first */ |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 896 | ret = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg), |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 897 | &client->tune_done); |
| 898 | |
| 899 | smsdvb_read_status(fe, &status); |
| 900 | |
| 901 | if (status & FE_HAS_LOCK) |
| 902 | return ret; |
| 903 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 904 | /* previous tune didn't lock - enable LNA and tune again */ |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 905 | sms_board_lna_control(client->coredev, 1); |
| 906 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 907 | |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 908 | return smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg), |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 909 | &client->tune_done); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 910 | } |
| 911 | |
Mauro Carvalho Chehab | 15115c1 | 2011-12-26 16:31:29 -0300 | [diff] [blame] | 912 | static int smsdvb_isdbt_set_frontend(struct dvb_frontend *fe) |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 913 | { |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 914 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 915 | struct smsdvb_client_t *client = |
| 916 | container_of(fe, struct smsdvb_client_t, frontend); |
Mauro Carvalho Chehab | a51fea4 | 2013-03-07 16:34:06 -0300 | [diff] [blame] | 917 | int board_id = smscore_get_board_id(client->coredev); |
| 918 | struct sms_board *board = sms_get_board(board_id); |
| 919 | enum sms_device_type_st type = board->type; |
Mauro Carvalho Chehab | 0c189fa | 2013-03-07 16:34:53 -0300 | [diff] [blame] | 920 | int ret; |
Mauro Carvalho Chehab | 503efe5 | 2013-03-10 09:04:44 -0300 | [diff] [blame] | 921 | |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 922 | struct { |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 923 | struct sms_msg_hdr msg; |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 924 | u32 Data[4]; |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 925 | } msg; |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 926 | |
Mauro Carvalho Chehab | e85c97a | 2009-12-25 07:17:03 -0300 | [diff] [blame] | 927 | fe->dtv_property_cache.delivery_system = SYS_ISDBT; |
| 928 | |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 929 | msg.msg.msg_src_id = DVBT_BDA_CONTROL_MSG_ID; |
| 930 | msg.msg.msg_dst_id = HIF_TASK; |
| 931 | msg.msg.msg_flags = 0; |
| 932 | msg.msg.msg_type = MSG_SMS_ISDBT_TUNE_REQ; |
| 933 | msg.msg.msg_length = sizeof(msg); |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 934 | |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 935 | if (c->isdbt_sb_segment_idx == -1) |
| 936 | c->isdbt_sb_segment_idx = 0; |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 937 | |
Mauro Carvalho Chehab | a51fea4 | 2013-03-07 16:34:06 -0300 | [diff] [blame] | 938 | if (!c->isdbt_layer_enabled) |
| 939 | c->isdbt_layer_enabled = 7; |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 940 | |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 941 | msg.Data[0] = c->frequency; |
| 942 | msg.Data[1] = BW_ISDBT_1SEG; |
| 943 | msg.Data[2] = 12000000; |
| 944 | msg.Data[3] = c->isdbt_sb_segment_idx; |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 945 | |
Mauro Carvalho Chehab | a51fea4 | 2013-03-07 16:34:06 -0300 | [diff] [blame] | 946 | if (c->isdbt_partial_reception) { |
| 947 | if ((type == SMS_PELE || type == SMS_RIO) && |
| 948 | c->isdbt_sb_segment_count > 3) |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 949 | msg.Data[1] = BW_ISDBT_13SEG; |
Mauro Carvalho Chehab | a51fea4 | 2013-03-07 16:34:06 -0300 | [diff] [blame] | 950 | else if (c->isdbt_sb_segment_count > 1) |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 951 | msg.Data[1] = BW_ISDBT_3SEG; |
Mauro Carvalho Chehab | a51fea4 | 2013-03-07 16:34:06 -0300 | [diff] [blame] | 952 | } else if (type == SMS_PELE || type == SMS_RIO) |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 953 | msg.Data[1] = BW_ISDBT_13SEG; |
Mauro Carvalho Chehab | a51fea4 | 2013-03-07 16:34:06 -0300 | [diff] [blame] | 954 | |
| 955 | c->bandwidth_hz = 6000000; |
| 956 | |
Mauro Carvalho Chehab | 98c3f94 | 2013-03-19 13:06:28 -0300 | [diff] [blame] | 957 | sms_info("%s: freq %d segwidth %d segindex %d", __func__, |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 958 | c->frequency, c->isdbt_sb_segment_count, |
| 959 | c->isdbt_sb_segment_idx); |
| 960 | |
Mauro Carvalho Chehab | 0c189fa | 2013-03-07 16:34:53 -0300 | [diff] [blame] | 961 | /* Disable LNA, if any. An error is returned if no LNA is present */ |
| 962 | ret = sms_board_lna_control(client->coredev, 0); |
| 963 | if (ret == 0) { |
| 964 | fe_status_t status; |
| 965 | |
| 966 | /* tune with LNA off at first */ |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 967 | ret = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg), |
Mauro Carvalho Chehab | 0c189fa | 2013-03-07 16:34:53 -0300 | [diff] [blame] | 968 | &client->tune_done); |
| 969 | |
| 970 | smsdvb_read_status(fe, &status); |
| 971 | |
| 972 | if (status & FE_HAS_LOCK) |
| 973 | return ret; |
| 974 | |
| 975 | /* previous tune didn't lock - enable LNA and tune again */ |
| 976 | sms_board_lna_control(client->coredev, 1); |
| 977 | } |
Mauro Carvalho Chehab | 28a59df | 2013-03-21 09:27:37 -0300 | [diff] [blame] | 978 | return smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg), |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 979 | &client->tune_done); |
| 980 | } |
| 981 | |
Mauro Carvalho Chehab | 15115c1 | 2011-12-26 16:31:29 -0300 | [diff] [blame] | 982 | static int smsdvb_set_frontend(struct dvb_frontend *fe) |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 983 | { |
Mauro Carvalho Chehab | f5de95e | 2013-03-10 12:06:30 -0300 | [diff] [blame] | 984 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 985 | struct smsdvb_client_t *client = |
| 986 | container_of(fe, struct smsdvb_client_t, frontend); |
| 987 | struct smscore_device_t *coredev = client->coredev; |
| 988 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 989 | smsdvb_stats_not_ready(fe); |
Mauro Carvalho Chehab | f5de95e | 2013-03-10 12:06:30 -0300 | [diff] [blame] | 990 | c->strength.stat[0].uvalue = 0; |
| 991 | c->cnr.stat[0].uvalue = 0; |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 992 | |
Mauro Carvalho Chehab | e1b2ac4 | 2013-03-15 07:22:08 -0300 | [diff] [blame] | 993 | client->has_tuned = false; |
| 994 | |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 995 | switch (smscore_get_device_mode(coredev)) { |
| 996 | case DEVICE_MODE_DVBT: |
| 997 | case DEVICE_MODE_DVBT_BDA: |
Mauro Carvalho Chehab | 15115c1 | 2011-12-26 16:31:29 -0300 | [diff] [blame] | 998 | return smsdvb_dvbt_set_frontend(fe); |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 999 | case DEVICE_MODE_ISDBT: |
| 1000 | case DEVICE_MODE_ISDBT_BDA: |
Mauro Carvalho Chehab | 15115c1 | 2011-12-26 16:31:29 -0300 | [diff] [blame] | 1001 | return smsdvb_isdbt_set_frontend(fe); |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 1002 | default: |
| 1003 | return -EINVAL; |
| 1004 | } |
| 1005 | } |
| 1006 | |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 1007 | /* Nothing to do here, as stats are automatically updated */ |
Mauro Carvalho Chehab | eab0fa0 | 2013-03-09 12:05:58 -0300 | [diff] [blame] | 1008 | static int smsdvb_get_frontend(struct dvb_frontend *fe) |
| 1009 | { |
Mauro Carvalho Chehab | d42f1cb | 2013-03-09 19:26:28 -0300 | [diff] [blame] | 1010 | return 0; |
Michael Krufky | 7a6fbed | 2008-11-22 14:26:37 -0300 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | static int smsdvb_init(struct dvb_frontend *fe) |
| 1014 | { |
| 1015 | struct smsdvb_client_t *client = |
| 1016 | container_of(fe, struct smsdvb_client_t, frontend); |
| 1017 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 1018 | sms_board_power(client->coredev, 1); |
| 1019 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 1020 | sms_board_dvb3_event(client, DVB3_EVENT_INIT); |
Michael Krufky | 7a6fbed | 2008-11-22 14:26:37 -0300 | [diff] [blame] | 1021 | return 0; |
| 1022 | } |
| 1023 | |
| 1024 | static int smsdvb_sleep(struct dvb_frontend *fe) |
| 1025 | { |
| 1026 | struct smsdvb_client_t *client = |
| 1027 | container_of(fe, struct smsdvb_client_t, frontend); |
| 1028 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 1029 | sms_board_led_feedback(client->coredev, SMS_LED_OFF); |
| 1030 | sms_board_power(client->coredev, 0); |
| 1031 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 1032 | sms_board_dvb3_event(client, DVB3_EVENT_SLEEP); |
Michael Krufky | 7a6fbed | 2008-11-22 14:26:37 -0300 | [diff] [blame] | 1033 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1034 | return 0; |
| 1035 | } |
| 1036 | |
| 1037 | static void smsdvb_release(struct dvb_frontend *fe) |
| 1038 | { |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 1039 | /* do nothing */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | static struct dvb_frontend_ops smsdvb_fe_ops = { |
| 1043 | .info = { |
Uri Shkolnik | e0f14c2 | 2008-08-31 00:44:04 -0300 | [diff] [blame] | 1044 | .name = "Siano Mobile Digital MDTV Receiver", |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1045 | .frequency_min = 44250000, |
| 1046 | .frequency_max = 867250000, |
| 1047 | .frequency_stepsize = 250000, |
| 1048 | .caps = FE_CAN_INVERSION_AUTO | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1049 | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | |
| 1050 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | |
| 1051 | FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | |
| 1052 | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | |
| 1053 | FE_CAN_GUARD_INTERVAL_AUTO | |
| 1054 | FE_CAN_RECOVER | |
| 1055 | FE_CAN_HIERARCHY_AUTO, |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1056 | }, |
| 1057 | |
| 1058 | .release = smsdvb_release, |
| 1059 | |
Mauro Carvalho Chehab | 15115c1 | 2011-12-26 16:31:29 -0300 | [diff] [blame] | 1060 | .set_frontend = smsdvb_set_frontend, |
| 1061 | .get_frontend = smsdvb_get_frontend, |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1062 | .get_tune_settings = smsdvb_get_tune_settings, |
| 1063 | |
| 1064 | .read_status = smsdvb_read_status, |
| 1065 | .read_ber = smsdvb_read_ber, |
| 1066 | .read_signal_strength = smsdvb_read_signal_strength, |
| 1067 | .read_snr = smsdvb_read_snr, |
Michael Krufky | 851a909 | 2008-11-22 14:56:37 -0300 | [diff] [blame] | 1068 | .read_ucblocks = smsdvb_read_ucblocks, |
Michael Krufky | 7a6fbed | 2008-11-22 14:26:37 -0300 | [diff] [blame] | 1069 | |
| 1070 | .init = smsdvb_init, |
| 1071 | .sleep = smsdvb_sleep, |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1072 | }; |
| 1073 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 1074 | static int smsdvb_hotplug(struct smscore_device_t *coredev, |
| 1075 | struct device *device, int arrival) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1076 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1077 | struct smsclient_params_t params; |
| 1078 | struct smsdvb_client_t *client; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1079 | int rc; |
| 1080 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 1081 | /* device removal handled by onremove callback */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1082 | if (!arrival) |
| 1083 | return 0; |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1084 | client = kzalloc(sizeof(struct smsdvb_client_t), GFP_KERNEL); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1085 | if (!client) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 1086 | sms_err("kmalloc() failed"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1087 | return -ENOMEM; |
| 1088 | } |
| 1089 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 1090 | /* register dvb adapter */ |
Michael Krufky | 1c11d54 | 2008-06-18 22:09:55 -0300 | [diff] [blame] | 1091 | rc = dvb_register_adapter(&client->adapter, |
| 1092 | sms_get_board( |
| 1093 | smscore_get_board_id(coredev))->name, |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1094 | THIS_MODULE, device, adapter_nr); |
| 1095 | if (rc < 0) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 1096 | sms_err("dvb_register_adapter() failed %d", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1097 | goto adapter_error; |
| 1098 | } |
| 1099 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 1100 | /* init dvb demux */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1101 | client->demux.dmx.capabilities = DMX_TS_FILTERING; |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 1102 | client->demux.filternum = 32; /* todo: nova ??? */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1103 | client->demux.feednum = 32; |
| 1104 | client->demux.start_feed = smsdvb_start_feed; |
| 1105 | client->demux.stop_feed = smsdvb_stop_feed; |
| 1106 | |
| 1107 | rc = dvb_dmx_init(&client->demux); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1108 | if (rc < 0) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 1109 | sms_err("dvb_dmx_init failed %d", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1110 | goto dvbdmx_error; |
| 1111 | } |
| 1112 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 1113 | /* init dmxdev */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1114 | client->dmxdev.filternum = 32; |
| 1115 | client->dmxdev.demux = &client->demux.dmx; |
| 1116 | client->dmxdev.capabilities = 0; |
| 1117 | |
| 1118 | rc = dvb_dmxdev_init(&client->dmxdev, &client->adapter); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1119 | if (rc < 0) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 1120 | sms_err("dvb_dmxdev_init failed %d", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1121 | goto dmxdev_error; |
| 1122 | } |
| 1123 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 1124 | /* init and register frontend */ |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1125 | memcpy(&client->frontend.ops, &smsdvb_fe_ops, |
| 1126 | sizeof(struct dvb_frontend_ops)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1127 | |
Mauro Carvalho Chehab | 15115c1 | 2011-12-26 16:31:29 -0300 | [diff] [blame] | 1128 | switch (smscore_get_device_mode(coredev)) { |
| 1129 | case DEVICE_MODE_DVBT: |
| 1130 | case DEVICE_MODE_DVBT_BDA: |
Mauro Carvalho Chehab | 9bd58e7 | 2012-03-01 07:25:39 -0300 | [diff] [blame] | 1131 | client->frontend.ops.delsys[0] = SYS_DVBT; |
Mauro Carvalho Chehab | 15115c1 | 2011-12-26 16:31:29 -0300 | [diff] [blame] | 1132 | break; |
| 1133 | case DEVICE_MODE_ISDBT: |
| 1134 | case DEVICE_MODE_ISDBT_BDA: |
Mauro Carvalho Chehab | 9bd58e7 | 2012-03-01 07:25:39 -0300 | [diff] [blame] | 1135 | client->frontend.ops.delsys[0] = SYS_ISDBT; |
Mauro Carvalho Chehab | 15115c1 | 2011-12-26 16:31:29 -0300 | [diff] [blame] | 1136 | break; |
| 1137 | } |
| 1138 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1139 | rc = dvb_register_frontend(&client->adapter, &client->frontend); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1140 | if (rc < 0) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 1141 | sms_err("frontend registration failed %d", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1142 | goto frontend_error; |
| 1143 | } |
| 1144 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 1145 | params.initial_id = 1; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1146 | params.data_type = MSG_SMS_DVBT_BDA_DATA; |
| 1147 | params.onresponse_handler = smsdvb_onresponse; |
| 1148 | params.onremove_handler = smsdvb_onremove; |
| 1149 | params.context = client; |
| 1150 | |
| 1151 | rc = smscore_register_client(coredev, ¶ms, &client->smsclient); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1152 | if (rc < 0) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 1153 | sms_err("smscore_register_client() failed %d", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1154 | goto client_error; |
| 1155 | } |
| 1156 | |
| 1157 | client->coredev = coredev; |
| 1158 | |
| 1159 | init_completion(&client->tune_done); |
Mauro Carvalho Chehab | 76e41a6 | 2013-03-07 16:32:33 -0300 | [diff] [blame] | 1160 | init_completion(&client->stats_done); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1161 | |
| 1162 | kmutex_lock(&g_smsdvb_clientslock); |
| 1163 | |
| 1164 | list_add(&client->entry, &g_smsdvb_clients); |
| 1165 | |
| 1166 | kmutex_unlock(&g_smsdvb_clientslock); |
| 1167 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 1168 | client->event_fe_state = -1; |
| 1169 | client->event_unc_state = -1; |
| 1170 | sms_board_dvb3_event(client, DVB3_EVENT_HOTPLUG); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1171 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 1172 | sms_info("success"); |
Michael Krufky | 250fa67 | 2008-11-16 22:45:42 -0300 | [diff] [blame] | 1173 | sms_board_setup(coredev); |
| 1174 | |
Mauro Carvalho Chehab | 503efe5 | 2013-03-10 09:04:44 -0300 | [diff] [blame] | 1175 | if (smsdvb_debugfs_create(client) < 0) |
Mauro Carvalho Chehab | 3f6b87c | 2013-03-09 22:33:06 -0300 | [diff] [blame] | 1176 | sms_info("failed to create debugfs node"); |
| 1177 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1178 | return 0; |
| 1179 | |
| 1180 | client_error: |
| 1181 | dvb_unregister_frontend(&client->frontend); |
| 1182 | |
| 1183 | frontend_error: |
| 1184 | dvb_dmxdev_release(&client->dmxdev); |
| 1185 | |
| 1186 | dmxdev_error: |
| 1187 | dvb_dmx_release(&client->demux); |
| 1188 | |
| 1189 | dvbdmx_error: |
| 1190 | dvb_unregister_adapter(&client->adapter); |
| 1191 | |
| 1192 | adapter_error: |
| 1193 | kfree(client); |
| 1194 | return rc; |
| 1195 | } |
| 1196 | |
Márton Németh | 2184dda | 2009-12-11 20:05:10 -0300 | [diff] [blame] | 1197 | static int __init smsdvb_module_init(void) |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 1198 | { |
| 1199 | int rc; |
| 1200 | |
| 1201 | INIT_LIST_HEAD(&g_smsdvb_clients); |
| 1202 | kmutex_init(&g_smsdvb_clientslock); |
| 1203 | |
Mauro Carvalho Chehab | 503efe5 | 2013-03-10 09:04:44 -0300 | [diff] [blame] | 1204 | smsdvb_debugfs_register(); |
Mauro Carvalho Chehab | 3f6b87c | 2013-03-09 22:33:06 -0300 | [diff] [blame] | 1205 | |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 1206 | rc = smscore_register_hotplug(smsdvb_hotplug); |
| 1207 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 1208 | sms_debug(""); |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 1209 | |
| 1210 | return rc; |
| 1211 | } |
| 1212 | |
Márton Németh | 2184dda | 2009-12-11 20:05:10 -0300 | [diff] [blame] | 1213 | static void __exit smsdvb_module_exit(void) |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 1214 | { |
| 1215 | smscore_unregister_hotplug(smsdvb_hotplug); |
| 1216 | |
| 1217 | kmutex_lock(&g_smsdvb_clientslock); |
| 1218 | |
| 1219 | while (!list_empty(&g_smsdvb_clients)) |
Mauro Carvalho Chehab | 503efe5 | 2013-03-10 09:04:44 -0300 | [diff] [blame] | 1220 | smsdvb_unregister_client((struct smsdvb_client_t *)g_smsdvb_clients.next); |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 1221 | |
Mauro Carvalho Chehab | 503efe5 | 2013-03-10 09:04:44 -0300 | [diff] [blame] | 1222 | smsdvb_debugfs_unregister(); |
Mauro Carvalho Chehab | 3f6b87c | 2013-03-09 22:33:06 -0300 | [diff] [blame] | 1223 | |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 1224 | kmutex_unlock(&g_smsdvb_clientslock); |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 1225 | } |
Uri Shkolnik | e0f14c2 | 2008-08-31 00:44:04 -0300 | [diff] [blame] | 1226 | |
| 1227 | module_init(smsdvb_module_init); |
| 1228 | module_exit(smsdvb_module_exit); |
| 1229 | |
| 1230 | MODULE_DESCRIPTION("SMS DVB subsystem adaptation module"); |
Uri Shkolnik | 843d060 | 2009-05-12 13:13:13 -0300 | [diff] [blame] | 1231 | MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)"); |
Uri Shkolnik | e0f14c2 | 2008-08-31 00:44:04 -0300 | [diff] [blame] | 1232 | MODULE_LICENSE("GPL"); |