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