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> |
| 23 | #include <linux/init.h> |
| 24 | |
Uri Shkolnik | c9679e3 | 2009-05-14 16:28:17 -0300 | [diff] [blame] | 25 | #include "dmxdev.h" |
| 26 | #include "dvbdev.h" |
| 27 | #include "dvb_demux.h" |
| 28 | #include "dvb_frontend.h" |
| 29 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 30 | #include "smscoreapi.h" |
Uri Shkolnik | ba79bb2 | 2009-05-12 11:37:09 -0300 | [diff] [blame] | 31 | #include "smsendian.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; |
Michael Krufky | 62c7167d | 2008-08-31 17:15:47 -0300 | [diff] [blame] | 50 | |
| 51 | /* todo: save freq/band instead whole struct */ |
| 52 | struct dvb_frontend_parameters fe_params; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 53 | |
| 54 | struct SMSHOSTLIB_STATISTICS_DVB_S sms_stat_dvb; |
| 55 | int event_fe_state; |
| 56 | int event_unc_state; |
Michael Krufky | 62c7167d | 2008-08-31 17:15:47 -0300 | [diff] [blame] | 57 | }; |
| 58 | |
Adrian Bunk | c5e0bd1 | 2008-07-21 23:17:36 -0300 | [diff] [blame] | 59 | static struct list_head g_smsdvb_clients; |
| 60 | static struct mutex g_smsdvb_clientslock; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 61 | |
Michael Krufky | 0d02efe | 2009-02-27 02:42:16 -0300 | [diff] [blame] | 62 | static int sms_dbg; |
| 63 | module_param_named(debug, sms_dbg, int, 0644); |
| 64 | MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))"); |
| 65 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 66 | /* Events that may come from DVB v3 adapter */ |
| 67 | static void sms_board_dvb3_event(struct smsdvb_client_t *client, |
| 68 | enum SMS_DVB3_EVENTS event) { |
Uri Shkolnik | 4db989f | 2009-05-19 12:28:02 -0300 | [diff] [blame] | 69 | |
| 70 | struct smscore_device_t *coredev = client->coredev; |
| 71 | switch (event) { |
| 72 | case DVB3_EVENT_INIT: |
| 73 | sms_debug("DVB3_EVENT_INIT"); |
| 74 | sms_board_event(coredev, BOARD_EVENT_BIND); |
| 75 | break; |
| 76 | case DVB3_EVENT_SLEEP: |
| 77 | sms_debug("DVB3_EVENT_SLEEP"); |
| 78 | sms_board_event(coredev, BOARD_EVENT_POWER_SUSPEND); |
| 79 | break; |
| 80 | case DVB3_EVENT_HOTPLUG: |
| 81 | sms_debug("DVB3_EVENT_HOTPLUG"); |
| 82 | sms_board_event(coredev, BOARD_EVENT_POWER_INIT); |
| 83 | break; |
| 84 | case DVB3_EVENT_FE_LOCK: |
| 85 | if (client->event_fe_state != DVB3_EVENT_FE_LOCK) { |
| 86 | client->event_fe_state = DVB3_EVENT_FE_LOCK; |
| 87 | sms_debug("DVB3_EVENT_FE_LOCK"); |
| 88 | sms_board_event(coredev, BOARD_EVENT_FE_LOCK); |
| 89 | } |
| 90 | break; |
| 91 | case DVB3_EVENT_FE_UNLOCK: |
| 92 | if (client->event_fe_state != DVB3_EVENT_FE_UNLOCK) { |
| 93 | client->event_fe_state = DVB3_EVENT_FE_UNLOCK; |
| 94 | sms_debug("DVB3_EVENT_FE_UNLOCK"); |
| 95 | sms_board_event(coredev, BOARD_EVENT_FE_UNLOCK); |
| 96 | } |
| 97 | break; |
| 98 | case DVB3_EVENT_UNC_OK: |
| 99 | if (client->event_unc_state != DVB3_EVENT_UNC_OK) { |
| 100 | client->event_unc_state = DVB3_EVENT_UNC_OK; |
| 101 | sms_debug("DVB3_EVENT_UNC_OK"); |
| 102 | sms_board_event(coredev, BOARD_EVENT_MULTIPLEX_OK); |
| 103 | } |
| 104 | break; |
| 105 | case DVB3_EVENT_UNC_ERR: |
| 106 | if (client->event_unc_state != DVB3_EVENT_UNC_ERR) { |
| 107 | client->event_unc_state = DVB3_EVENT_UNC_ERR; |
| 108 | sms_debug("DVB3_EVENT_UNC_ERR"); |
| 109 | sms_board_event(coredev, BOARD_EVENT_MULTIPLEX_ERRORS); |
| 110 | } |
| 111 | break; |
| 112 | |
| 113 | default: |
| 114 | sms_err("Unknown dvb3 api event"); |
| 115 | break; |
| 116 | } |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 117 | } |
| 118 | |
Mauro Carvalho Chehab | 5eb2397 | 2009-12-25 11:29:42 -0300 | [diff] [blame] | 119 | |
| 120 | static void smsdvb_update_dvb_stats(struct RECEPTION_STATISTICS_S *pReceptionData, |
| 121 | struct SMSHOSTLIB_STATISTICS_ST *p) |
| 122 | { |
| 123 | if (sms_dbg & 2) { |
| 124 | printk(KERN_DEBUG "Reserved = %d", p->Reserved); |
| 125 | printk(KERN_DEBUG "IsRfLocked = %d", p->IsRfLocked); |
| 126 | printk(KERN_DEBUG "IsDemodLocked = %d", p->IsDemodLocked); |
| 127 | printk(KERN_DEBUG "IsExternalLNAOn = %d", p->IsExternalLNAOn); |
| 128 | printk(KERN_DEBUG "SNR = %d", p->SNR); |
| 129 | printk(KERN_DEBUG "BER = %d", p->BER); |
| 130 | printk(KERN_DEBUG "FIB_CRC = %d", p->FIB_CRC); |
| 131 | printk(KERN_DEBUG "TS_PER = %d", p->TS_PER); |
| 132 | printk(KERN_DEBUG "MFER = %d", p->MFER); |
| 133 | printk(KERN_DEBUG "RSSI = %d", p->RSSI); |
| 134 | printk(KERN_DEBUG "InBandPwr = %d", p->InBandPwr); |
| 135 | printk(KERN_DEBUG "CarrierOffset = %d", p->CarrierOffset); |
| 136 | printk(KERN_DEBUG "Frequency = %d", p->Frequency); |
| 137 | printk(KERN_DEBUG "Bandwidth = %d", p->Bandwidth); |
| 138 | printk(KERN_DEBUG "TransmissionMode = %d", p->TransmissionMode); |
| 139 | printk(KERN_DEBUG "ModemState = %d", p->ModemState); |
| 140 | printk(KERN_DEBUG "GuardInterval = %d", p->GuardInterval); |
| 141 | printk(KERN_DEBUG "CodeRate = %d", p->CodeRate); |
| 142 | printk(KERN_DEBUG "LPCodeRate = %d", p->LPCodeRate); |
| 143 | printk(KERN_DEBUG "Hierarchy = %d", p->Hierarchy); |
| 144 | printk(KERN_DEBUG "Constellation = %d", p->Constellation); |
| 145 | printk(KERN_DEBUG "BurstSize = %d", p->BurstSize); |
| 146 | printk(KERN_DEBUG "BurstDuration = %d", p->BurstDuration); |
| 147 | printk(KERN_DEBUG "BurstCycleTime = %d", p->BurstCycleTime); |
| 148 | printk(KERN_DEBUG "CalculatedBurstCycleTime = %d", p->CalculatedBurstCycleTime); |
| 149 | printk(KERN_DEBUG "NumOfRows = %d", p->NumOfRows); |
| 150 | printk(KERN_DEBUG "NumOfPaddCols = %d", p->NumOfPaddCols); |
| 151 | printk(KERN_DEBUG "NumOfPunctCols = %d", p->NumOfPunctCols); |
| 152 | printk(KERN_DEBUG "ErrorTSPackets = %d", p->ErrorTSPackets); |
| 153 | printk(KERN_DEBUG "TotalTSPackets = %d", p->TotalTSPackets); |
| 154 | printk(KERN_DEBUG "NumOfValidMpeTlbs = %d", p->NumOfValidMpeTlbs); |
| 155 | printk(KERN_DEBUG "NumOfInvalidMpeTlbs = %d", p->NumOfInvalidMpeTlbs); |
| 156 | printk(KERN_DEBUG "NumOfCorrectedMpeTlbs = %d", p->NumOfCorrectedMpeTlbs); |
| 157 | printk(KERN_DEBUG "BERErrorCount = %d", p->BERErrorCount); |
| 158 | printk(KERN_DEBUG "BERBitCount = %d", p->BERBitCount); |
| 159 | printk(KERN_DEBUG "SmsToHostTxErrors = %d", p->SmsToHostTxErrors); |
| 160 | printk(KERN_DEBUG "PreBER = %d", p->PreBER); |
| 161 | printk(KERN_DEBUG "CellId = %d", p->CellId); |
| 162 | printk(KERN_DEBUG "DvbhSrvIndHP = %d", p->DvbhSrvIndHP); |
| 163 | printk(KERN_DEBUG "DvbhSrvIndLP = %d", p->DvbhSrvIndLP); |
| 164 | printk(KERN_DEBUG "NumMPEReceived = %d", p->NumMPEReceived); |
Mauro Carvalho Chehab | 5eb2397 | 2009-12-25 11:29:42 -0300 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | pReceptionData->IsDemodLocked = p->IsDemodLocked; |
| 168 | |
| 169 | pReceptionData->SNR = p->SNR; |
| 170 | pReceptionData->BER = p->BER; |
| 171 | pReceptionData->BERErrorCount = p->BERErrorCount; |
| 172 | pReceptionData->InBandPwr = p->InBandPwr; |
| 173 | pReceptionData->ErrorTSPackets = p->ErrorTSPackets; |
| 174 | }; |
| 175 | |
| 176 | |
| 177 | static void smsdvb_update_isdbt_stats(struct RECEPTION_STATISTICS_S *pReceptionData, |
| 178 | struct SMSHOSTLIB_STATISTICS_ISDBT_ST *p) |
| 179 | { |
| 180 | int i; |
| 181 | |
| 182 | if (sms_dbg & 2) { |
| 183 | printk(KERN_DEBUG "IsRfLocked = %d", p->IsRfLocked); |
| 184 | printk(KERN_DEBUG "IsDemodLocked = %d", p->IsDemodLocked); |
| 185 | printk(KERN_DEBUG "IsExternalLNAOn = %d", p->IsExternalLNAOn); |
| 186 | printk(KERN_DEBUG "SNR = %d", p->SNR); |
| 187 | printk(KERN_DEBUG "RSSI = %d", p->RSSI); |
| 188 | printk(KERN_DEBUG "InBandPwr = %d", p->InBandPwr); |
| 189 | printk(KERN_DEBUG "CarrierOffset = %d", p->CarrierOffset); |
| 190 | printk(KERN_DEBUG "Frequency = %d", p->Frequency); |
| 191 | printk(KERN_DEBUG "Bandwidth = %d", p->Bandwidth); |
| 192 | printk(KERN_DEBUG "TransmissionMode = %d", p->TransmissionMode); |
| 193 | printk(KERN_DEBUG "ModemState = %d", p->ModemState); |
| 194 | printk(KERN_DEBUG "GuardInterval = %d", p->GuardInterval); |
| 195 | printk(KERN_DEBUG "SystemType = %d", p->SystemType); |
| 196 | printk(KERN_DEBUG "PartialReception = %d", p->PartialReception); |
| 197 | printk(KERN_DEBUG "NumOfLayers = %d", p->NumOfLayers); |
| 198 | printk(KERN_DEBUG "SmsToHostTxErrors = %d", p->SmsToHostTxErrors); |
| 199 | |
| 200 | for (i = 0; i < 3; i++) { |
| 201 | printk(KERN_DEBUG "%d: CodeRate = %d", i, p->LayerInfo[i].CodeRate); |
| 202 | printk(KERN_DEBUG "%d: Constellation = %d", i, p->LayerInfo[i].Constellation); |
| 203 | printk(KERN_DEBUG "%d: BER = %d", i, p->LayerInfo[i].BER); |
| 204 | printk(KERN_DEBUG "%d: BERErrorCount = %d", i, p->LayerInfo[i].BERErrorCount); |
| 205 | printk(KERN_DEBUG "%d: BERBitCount = %d", i, p->LayerInfo[i].BERBitCount); |
| 206 | printk(KERN_DEBUG "%d: PreBER = %d", i, p->LayerInfo[i].PreBER); |
| 207 | printk(KERN_DEBUG "%d: TS_PER = %d", i, p->LayerInfo[i].TS_PER); |
| 208 | printk(KERN_DEBUG "%d: ErrorTSPackets = %d", i, p->LayerInfo[i].ErrorTSPackets); |
| 209 | printk(KERN_DEBUG "%d: TotalTSPackets = %d", i, p->LayerInfo[i].TotalTSPackets); |
| 210 | printk(KERN_DEBUG "%d: TILdepthI = %d", i, p->LayerInfo[i].TILdepthI); |
| 211 | printk(KERN_DEBUG "%d: NumberOfSegments = %d", i, p->LayerInfo[i].NumberOfSegments); |
| 212 | printk(KERN_DEBUG "%d: TMCCErrors = %d", i, p->LayerInfo[i].TMCCErrors); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | pReceptionData->IsDemodLocked = p->IsDemodLocked; |
| 217 | |
| 218 | pReceptionData->SNR = p->SNR; |
| 219 | pReceptionData->InBandPwr = p->InBandPwr; |
| 220 | |
| 221 | pReceptionData->ErrorTSPackets = 0; |
| 222 | pReceptionData->BER = 0; |
| 223 | pReceptionData->BERErrorCount = 0; |
| 224 | for (i = 0; i < 3; i++) { |
| 225 | pReceptionData->BER += p->LayerInfo[i].BER; |
| 226 | pReceptionData->BERErrorCount += p->LayerInfo[i].BERErrorCount; |
| 227 | pReceptionData->ErrorTSPackets += p->LayerInfo[i].ErrorTSPackets; |
| 228 | } |
| 229 | } |
| 230 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 231 | static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 232 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 233 | struct smsdvb_client_t *client = (struct smsdvb_client_t *) context; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 234 | struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) (((u8 *) cb->p) |
| 235 | + cb->offset); |
| 236 | u32 *pMsgData = (u32 *) phdr + 1; |
| 237 | /*u32 MsgDataLen = phdr->msgLength - sizeof(struct SmsMsgHdr_ST);*/ |
| 238 | bool is_status_update = false; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 239 | |
Uri Shkolnik | ba79bb2 | 2009-05-12 11:37:09 -0300 | [diff] [blame] | 240 | smsendian_handle_rx_message((struct SmsMsgData_ST *) phdr); |
| 241 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 242 | switch (phdr->msgType) { |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 243 | case MSG_SMS_DVBT_BDA_DATA: |
| 244 | dvb_dmx_swfilter(&client->demux, (u8 *)(phdr + 1), |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 245 | cb->size - sizeof(struct SmsMsgHdr_ST)); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 246 | break; |
| 247 | |
| 248 | case MSG_SMS_RF_TUNE_RES: |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 249 | case MSG_SMS_ISDBT_TUNE_RES: |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 250 | complete(&client->tune_done); |
| 251 | break; |
| 252 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 253 | case MSG_SMS_SIGNAL_DETECTED_IND: |
| 254 | sms_info("MSG_SMS_SIGNAL_DETECTED_IND"); |
| 255 | client->sms_stat_dvb.TransmissionData.IsDemodLocked = true; |
| 256 | is_status_update = true; |
| 257 | break; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 258 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 259 | case MSG_SMS_NO_SIGNAL_IND: |
| 260 | sms_info("MSG_SMS_NO_SIGNAL_IND"); |
| 261 | client->sms_stat_dvb.TransmissionData.IsDemodLocked = false; |
| 262 | is_status_update = true; |
| 263 | break; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 264 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 265 | case MSG_SMS_TRANSMISSION_IND: { |
| 266 | sms_info("MSG_SMS_TRANSMISSION_IND"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 267 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 268 | pMsgData++; |
| 269 | memcpy(&client->sms_stat_dvb.TransmissionData, pMsgData, |
| 270 | sizeof(struct TRANSMISSION_STATISTICS_S)); |
| 271 | |
| 272 | /* Mo need to correct guard interval |
| 273 | * (as opposed to old statistics message). |
| 274 | */ |
| 275 | CORRECT_STAT_BANDWIDTH(client->sms_stat_dvb.TransmissionData); |
| 276 | CORRECT_STAT_TRANSMISSON_MODE( |
| 277 | client->sms_stat_dvb.TransmissionData); |
| 278 | is_status_update = true; |
| 279 | break; |
| 280 | } |
| 281 | case MSG_SMS_HO_PER_SLICES_IND: { |
| 282 | struct RECEPTION_STATISTICS_S *pReceptionData = |
| 283 | &client->sms_stat_dvb.ReceptionData; |
| 284 | struct SRVM_SIGNAL_STATUS_S SignalStatusData; |
| 285 | |
| 286 | /*sms_info("MSG_SMS_HO_PER_SLICES_IND");*/ |
| 287 | pMsgData++; |
| 288 | SignalStatusData.result = pMsgData[0]; |
| 289 | SignalStatusData.snr = pMsgData[1]; |
| 290 | SignalStatusData.inBandPower = (s32) pMsgData[2]; |
| 291 | SignalStatusData.tsPackets = pMsgData[3]; |
| 292 | SignalStatusData.etsPackets = pMsgData[4]; |
| 293 | SignalStatusData.constellation = pMsgData[5]; |
| 294 | SignalStatusData.hpCode = pMsgData[6]; |
| 295 | SignalStatusData.tpsSrvIndLP = pMsgData[7] & 0x03; |
| 296 | SignalStatusData.tpsSrvIndHP = pMsgData[8] & 0x03; |
| 297 | SignalStatusData.cellId = pMsgData[9] & 0xFFFF; |
| 298 | SignalStatusData.reason = pMsgData[10]; |
| 299 | SignalStatusData.requestId = pMsgData[11]; |
| 300 | pReceptionData->IsRfLocked = pMsgData[16]; |
| 301 | pReceptionData->IsDemodLocked = pMsgData[17]; |
| 302 | pReceptionData->ModemState = pMsgData[12]; |
| 303 | pReceptionData->SNR = pMsgData[1]; |
| 304 | pReceptionData->BER = pMsgData[13]; |
| 305 | pReceptionData->RSSI = pMsgData[14]; |
| 306 | CORRECT_STAT_RSSI(client->sms_stat_dvb.ReceptionData); |
| 307 | |
| 308 | pReceptionData->InBandPwr = (s32) pMsgData[2]; |
| 309 | pReceptionData->CarrierOffset = (s32) pMsgData[15]; |
| 310 | pReceptionData->TotalTSPackets = pMsgData[3]; |
| 311 | pReceptionData->ErrorTSPackets = pMsgData[4]; |
| 312 | |
| 313 | /* TS PER */ |
| 314 | if ((SignalStatusData.tsPackets + SignalStatusData.etsPackets) |
| 315 | > 0) { |
| 316 | pReceptionData->TS_PER = (SignalStatusData.etsPackets |
| 317 | * 100) / (SignalStatusData.tsPackets |
| 318 | + SignalStatusData.etsPackets); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 319 | } else { |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 320 | pReceptionData->TS_PER = 0; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 321 | } |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 322 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 323 | pReceptionData->BERBitCount = pMsgData[18]; |
| 324 | pReceptionData->BERErrorCount = pMsgData[19]; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 325 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 326 | pReceptionData->MRC_SNR = pMsgData[20]; |
| 327 | pReceptionData->MRC_InBandPwr = pMsgData[21]; |
| 328 | pReceptionData->MRC_RSSI = pMsgData[22]; |
| 329 | |
| 330 | is_status_update = true; |
| 331 | break; |
| 332 | } |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 333 | case MSG_SMS_GET_STATISTICS_RES: { |
Mauro Carvalho Chehab | 5eb2397 | 2009-12-25 11:29:42 -0300 | [diff] [blame] | 334 | union { |
| 335 | struct SMSHOSTLIB_STATISTICS_ISDBT_ST isdbt; |
| 336 | struct SmsMsgStatisticsInfo_ST dvb; |
| 337 | } *p = (void *) (phdr + 1); |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 338 | struct RECEPTION_STATISTICS_S *pReceptionData = |
| 339 | &client->sms_stat_dvb.ReceptionData; |
| 340 | |
| 341 | sms_info("MSG_SMS_GET_STATISTICS_RES"); |
| 342 | |
| 343 | is_status_update = true; |
Mauro Carvalho Chehab | 5eb2397 | 2009-12-25 11:29:42 -0300 | [diff] [blame] | 344 | |
| 345 | switch (smscore_get_device_mode(client->coredev)) { |
| 346 | case DEVICE_MODE_ISDBT: |
| 347 | case DEVICE_MODE_ISDBT_BDA: |
| 348 | smsdvb_update_isdbt_stats(pReceptionData, &p->isdbt); |
| 349 | break; |
| 350 | default: |
| 351 | smsdvb_update_dvb_stats(pReceptionData, &p->dvb.Stat); |
| 352 | } |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 353 | if (!pReceptionData->IsDemodLocked) { |
| 354 | pReceptionData->SNR = 0; |
| 355 | pReceptionData->BER = 0; |
| 356 | pReceptionData->BERErrorCount = 0; |
| 357 | pReceptionData->InBandPwr = 0; |
| 358 | pReceptionData->ErrorTSPackets = 0; |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 359 | } |
| 360 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 361 | complete(&client->tune_done); |
| 362 | break; |
| 363 | } |
| 364 | default: |
| 365 | sms_info("Unhandled message %d", phdr->msgType); |
| 366 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 367 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 368 | smscore_putbuffer(client->coredev, cb); |
| 369 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 370 | if (is_status_update) { |
| 371 | if (client->sms_stat_dvb.ReceptionData.IsDemodLocked) { |
| 372 | client->fe_status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
| 373 | | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; |
| 374 | sms_board_dvb3_event(client, DVB3_EVENT_FE_LOCK); |
| 375 | if (client->sms_stat_dvb.ReceptionData.ErrorTSPackets |
| 376 | == 0) |
| 377 | sms_board_dvb3_event(client, DVB3_EVENT_UNC_OK); |
| 378 | else |
| 379 | sms_board_dvb3_event(client, |
| 380 | DVB3_EVENT_UNC_ERR); |
| 381 | |
| 382 | } else { |
Mauro Carvalho Chehab | b4622c1 | 2009-12-25 18:04:17 -0300 | [diff] [blame] | 383 | if (client->sms_stat_dvb.ReceptionData.IsRfLocked) |
| 384 | client->fe_status = FE_HAS_SIGNAL | FE_HAS_CARRIER; |
| 385 | else |
| 386 | client->fe_status = 0; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 387 | sms_board_dvb3_event(client, DVB3_EVENT_FE_UNLOCK); |
| 388 | } |
| 389 | } |
| 390 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 391 | return 0; |
| 392 | } |
| 393 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 394 | static void smsdvb_unregister_client(struct smsdvb_client_t *client) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 395 | { |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 396 | /* must be called under clientslock */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 397 | |
| 398 | list_del(&client->entry); |
| 399 | |
| 400 | smscore_unregister_client(client->smsclient); |
| 401 | dvb_unregister_frontend(&client->frontend); |
| 402 | dvb_dmxdev_release(&client->dmxdev); |
| 403 | dvb_dmx_release(&client->demux); |
| 404 | dvb_unregister_adapter(&client->adapter); |
| 405 | kfree(client); |
| 406 | } |
| 407 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 408 | static void smsdvb_onremove(void *context) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 409 | { |
| 410 | kmutex_lock(&g_smsdvb_clientslock); |
| 411 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 412 | smsdvb_unregister_client((struct smsdvb_client_t *) context); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 413 | |
| 414 | kmutex_unlock(&g_smsdvb_clientslock); |
| 415 | } |
| 416 | |
| 417 | static int smsdvb_start_feed(struct dvb_demux_feed *feed) |
| 418 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 419 | struct smsdvb_client_t *client = |
| 420 | container_of(feed->demux, struct smsdvb_client_t, demux); |
| 421 | struct SmsMsgData_ST PidMsg; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 422 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 423 | sms_debug("add pid %d(%x)", |
Michael Krufky | 068d6c0 | 2008-06-19 01:15:46 -0300 | [diff] [blame] | 424 | feed->pid, feed->pid); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 425 | |
| 426 | PidMsg.xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; |
| 427 | PidMsg.xMsgHeader.msgDstId = HIF_TASK; |
| 428 | PidMsg.xMsgHeader.msgFlags = 0; |
| 429 | PidMsg.xMsgHeader.msgType = MSG_SMS_ADD_PID_FILTER_REQ; |
| 430 | PidMsg.xMsgHeader.msgLength = sizeof(PidMsg); |
| 431 | PidMsg.msgData[0] = feed->pid; |
| 432 | |
Uri Shkolnik | ba79bb2 | 2009-05-12 11:37:09 -0300 | [diff] [blame] | 433 | smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&PidMsg); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 434 | return smsclient_sendrequest(client->smsclient, |
| 435 | &PidMsg, sizeof(PidMsg)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static int smsdvb_stop_feed(struct dvb_demux_feed *feed) |
| 439 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 440 | struct smsdvb_client_t *client = |
| 441 | container_of(feed->demux, struct smsdvb_client_t, demux); |
| 442 | struct SmsMsgData_ST PidMsg; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 443 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 444 | sms_debug("remove pid %d(%x)", |
Michael Krufky | 068d6c0 | 2008-06-19 01:15:46 -0300 | [diff] [blame] | 445 | feed->pid, feed->pid); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 446 | |
| 447 | PidMsg.xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; |
| 448 | PidMsg.xMsgHeader.msgDstId = HIF_TASK; |
| 449 | PidMsg.xMsgHeader.msgFlags = 0; |
| 450 | PidMsg.xMsgHeader.msgType = MSG_SMS_REMOVE_PID_FILTER_REQ; |
| 451 | PidMsg.xMsgHeader.msgLength = sizeof(PidMsg); |
| 452 | PidMsg.msgData[0] = feed->pid; |
| 453 | |
Uri Shkolnik | ba79bb2 | 2009-05-12 11:37:09 -0300 | [diff] [blame] | 454 | smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&PidMsg); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 455 | return smsclient_sendrequest(client->smsclient, |
| 456 | &PidMsg, sizeof(PidMsg)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 457 | } |
| 458 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 459 | static int smsdvb_sendrequest_and_wait(struct smsdvb_client_t *client, |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 460 | void *buffer, size_t size, |
| 461 | struct completion *completion) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 462 | { |
Uri Shkolnik | ba79bb2 | 2009-05-12 11:37:09 -0300 | [diff] [blame] | 463 | int rc; |
| 464 | |
| 465 | smsendian_handle_tx_message((struct SmsMsgHdr_ST *)buffer); |
| 466 | rc = smsclient_sendrequest(client->smsclient, buffer, size); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 467 | if (rc < 0) |
| 468 | return rc; |
| 469 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 470 | return wait_for_completion_timeout(completion, |
| 471 | msecs_to_jiffies(2000)) ? |
| 472 | 0 : -ETIME; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 473 | } |
| 474 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 475 | static int smsdvb_send_statistics_request(struct smsdvb_client_t *client) |
| 476 | { |
| 477 | int rc; |
| 478 | struct SmsMsgHdr_ST Msg = { MSG_SMS_GET_STATISTICS_REQ, |
| 479 | DVBT_BDA_CONTROL_MSG_ID, |
| 480 | HIF_TASK, |
| 481 | sizeof(struct SmsMsgHdr_ST), 0 }; |
| 482 | |
| 483 | rc = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg), |
| 484 | &client->tune_done); |
| 485 | |
| 486 | return rc; |
| 487 | } |
| 488 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 489 | static inline int led_feedback(struct smsdvb_client_t *client) |
| 490 | { |
| 491 | if (client->fe_status & FE_HAS_LOCK) |
| 492 | return sms_board_led_feedback(client->coredev, |
| 493 | (client->sms_stat_dvb.ReceptionData.BER |
| 494 | == 0) ? SMS_LED_HI : SMS_LED_LO); |
| 495 | else |
| 496 | return sms_board_led_feedback(client->coredev, SMS_LED_OFF); |
| 497 | } |
| 498 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 499 | static int smsdvb_read_status(struct dvb_frontend *fe, fe_status_t *stat) |
| 500 | { |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 501 | int rc; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 502 | struct smsdvb_client_t *client; |
| 503 | client = container_of(fe, struct smsdvb_client_t, frontend); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 504 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 505 | rc = smsdvb_send_statistics_request(client); |
| 506 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 507 | *stat = client->fe_status; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 508 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 509 | led_feedback(client); |
| 510 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 511 | return rc; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | static int smsdvb_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 515 | { |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 516 | int rc; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 517 | struct smsdvb_client_t *client; |
| 518 | client = container_of(fe, struct smsdvb_client_t, frontend); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 519 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 520 | rc = smsdvb_send_statistics_request(client); |
| 521 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 522 | *ber = client->sms_stat_dvb.ReceptionData.BER; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 523 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 524 | led_feedback(client); |
| 525 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 526 | return rc; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | static int smsdvb_read_signal_strength(struct dvb_frontend *fe, u16 *strength) |
| 530 | { |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 531 | int rc; |
| 532 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 533 | struct smsdvb_client_t *client; |
| 534 | client = container_of(fe, struct smsdvb_client_t, frontend); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 535 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 536 | rc = smsdvb_send_statistics_request(client); |
| 537 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 538 | if (client->sms_stat_dvb.ReceptionData.InBandPwr < -95) |
| 539 | *strength = 0; |
| 540 | else if (client->sms_stat_dvb.ReceptionData.InBandPwr > -29) |
| 541 | *strength = 100; |
| 542 | else |
| 543 | *strength = |
| 544 | (client->sms_stat_dvb.ReceptionData.InBandPwr |
| 545 | + 95) * 3 / 2; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 546 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 547 | led_feedback(client); |
| 548 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 549 | return rc; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | static int smsdvb_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 553 | { |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 554 | int rc; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 555 | struct smsdvb_client_t *client; |
| 556 | client = container_of(fe, struct smsdvb_client_t, frontend); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 557 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 558 | rc = smsdvb_send_statistics_request(client); |
| 559 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 560 | *snr = client->sms_stat_dvb.ReceptionData.SNR; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 561 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 562 | led_feedback(client); |
| 563 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 564 | return rc; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 565 | } |
| 566 | |
Michael Krufky | 851a909 | 2008-11-22 14:56:37 -0300 | [diff] [blame] | 567 | static int smsdvb_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
| 568 | { |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 569 | int rc; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 570 | struct smsdvb_client_t *client; |
| 571 | client = container_of(fe, struct smsdvb_client_t, frontend); |
Michael Krufky | 851a909 | 2008-11-22 14:56:37 -0300 | [diff] [blame] | 572 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 573 | rc = smsdvb_send_statistics_request(client); |
| 574 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 575 | *ucblocks = client->sms_stat_dvb.ReceptionData.ErrorTSPackets; |
Michael Krufky | 851a909 | 2008-11-22 14:56:37 -0300 | [diff] [blame] | 576 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 577 | led_feedback(client); |
| 578 | |
Mauro Carvalho Chehab | 67ae1d2 | 2009-12-23 10:07:16 -0300 | [diff] [blame] | 579 | return rc; |
Michael Krufky | 851a909 | 2008-11-22 14:56:37 -0300 | [diff] [blame] | 580 | } |
| 581 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 582 | static int smsdvb_get_tune_settings(struct dvb_frontend *fe, |
| 583 | struct dvb_frontend_tune_settings *tune) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 584 | { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 585 | sms_debug(""); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 586 | |
| 587 | tune->min_delay_ms = 400; |
| 588 | tune->step_size = 250000; |
| 589 | tune->max_drift = 0; |
| 590 | return 0; |
| 591 | } |
| 592 | |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 593 | static int smsdvb_dvbt_set_frontend(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 594 | struct dvb_frontend_parameters *p) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 595 | { |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 596 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 597 | struct smsdvb_client_t *client = |
| 598 | container_of(fe, struct smsdvb_client_t, frontend); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 599 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 600 | struct { |
| 601 | struct SmsMsgHdr_ST Msg; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 602 | u32 Data[3]; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 603 | } Msg; |
| 604 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 605 | int ret; |
| 606 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 607 | client->fe_status = FE_HAS_SIGNAL; |
| 608 | client->event_fe_state = -1; |
| 609 | client->event_unc_state = -1; |
Mauro Carvalho Chehab | e85c97a | 2009-12-25 07:17:03 -0300 | [diff] [blame] | 610 | fe->dtv_property_cache.delivery_system = SYS_DVBT; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 611 | |
| 612 | Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; |
| 613 | Msg.Msg.msgDstId = HIF_TASK; |
| 614 | Msg.Msg.msgFlags = 0; |
| 615 | Msg.Msg.msgType = MSG_SMS_RF_TUNE_REQ; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 616 | Msg.Msg.msgLength = sizeof(Msg); |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 617 | Msg.Data[0] = c->frequency; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 618 | Msg.Data[2] = 12000000; |
| 619 | |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 620 | sms_info("%s: freq %d band %d", __func__, c->frequency, |
| 621 | c->bandwidth_hz); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 622 | |
Mauro Carvalho Chehab | 643e15a | 2009-12-25 07:29:06 -0300 | [diff] [blame] | 623 | switch (c->bandwidth_hz / 1000000) { |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 624 | case 8: |
| 625 | Msg.Data[1] = BW_8_MHZ; |
| 626 | break; |
| 627 | case 7: |
| 628 | Msg.Data[1] = BW_7_MHZ; |
| 629 | break; |
| 630 | case 6: |
| 631 | Msg.Data[1] = BW_6_MHZ; |
| 632 | break; |
| 633 | case 0: |
| 634 | return -EOPNOTSUPP; |
| 635 | default: |
| 636 | return -EINVAL; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 637 | } |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 638 | /* Disable LNA, if any. An error is returned if no LNA is present */ |
| 639 | ret = sms_board_lna_control(client->coredev, 0); |
| 640 | if (ret == 0) { |
| 641 | fe_status_t status; |
| 642 | |
| 643 | /* tune with LNA off at first */ |
| 644 | ret = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg), |
| 645 | &client->tune_done); |
| 646 | |
| 647 | smsdvb_read_status(fe, &status); |
| 648 | |
| 649 | if (status & FE_HAS_LOCK) |
| 650 | return ret; |
| 651 | |
| 652 | /* previous tune didnt lock - enable LNA and tune again */ |
| 653 | sms_board_lna_control(client->coredev, 1); |
| 654 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 655 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 656 | return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg), |
| 657 | &client->tune_done); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 658 | } |
| 659 | |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 660 | static int smsdvb_isdbt_set_frontend(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 661 | struct dvb_frontend_parameters *p) |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 662 | { |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 663 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 664 | struct smsdvb_client_t *client = |
| 665 | container_of(fe, struct smsdvb_client_t, frontend); |
| 666 | |
| 667 | struct { |
| 668 | struct SmsMsgHdr_ST Msg; |
| 669 | u32 Data[4]; |
| 670 | } Msg; |
| 671 | |
Mauro Carvalho Chehab | e85c97a | 2009-12-25 07:17:03 -0300 | [diff] [blame] | 672 | fe->dtv_property_cache.delivery_system = SYS_ISDBT; |
| 673 | |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 674 | Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; |
| 675 | Msg.Msg.msgDstId = HIF_TASK; |
| 676 | Msg.Msg.msgFlags = 0; |
| 677 | Msg.Msg.msgType = MSG_SMS_ISDBT_TUNE_REQ; |
| 678 | Msg.Msg.msgLength = sizeof(Msg); |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 679 | |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 680 | if (c->isdbt_sb_segment_idx == -1) |
| 681 | c->isdbt_sb_segment_idx = 0; |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 682 | |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 683 | switch (c->isdbt_sb_segment_count) { |
| 684 | case 3: |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 685 | Msg.Data[1] = BW_ISDBT_3SEG; |
| 686 | break; |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 687 | case 1: |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 688 | Msg.Data[1] = BW_ISDBT_1SEG; |
| 689 | break; |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 690 | case 0: /* AUTO */ |
Mauro Carvalho Chehab | 643e15a | 2009-12-25 07:29:06 -0300 | [diff] [blame] | 691 | switch (c->bandwidth_hz / 1000000) { |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 692 | case 8: |
| 693 | case 7: |
| 694 | c->isdbt_sb_segment_count = 3; |
| 695 | Msg.Data[1] = BW_ISDBT_3SEG; |
| 696 | break; |
| 697 | case 6: |
| 698 | c->isdbt_sb_segment_count = 1; |
| 699 | Msg.Data[1] = BW_ISDBT_1SEG; |
| 700 | break; |
| 701 | default: /* Assumes 6 MHZ bw */ |
| 702 | c->isdbt_sb_segment_count = 1; |
| 703 | c->bandwidth_hz = 6000; |
| 704 | Msg.Data[1] = BW_ISDBT_1SEG; |
| 705 | break; |
| 706 | } |
| 707 | break; |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 708 | default: |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 709 | sms_info("Segment count %d not supported", c->isdbt_sb_segment_count); |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 710 | return -EINVAL; |
| 711 | } |
| 712 | |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 713 | Msg.Data[0] = c->frequency; |
| 714 | Msg.Data[2] = 12000000; |
| 715 | Msg.Data[3] = c->isdbt_sb_segment_idx; |
| 716 | |
| 717 | sms_info("%s: freq %d segwidth %d segindex %d\n", __func__, |
| 718 | c->frequency, c->isdbt_sb_segment_count, |
| 719 | c->isdbt_sb_segment_idx); |
| 720 | |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 721 | return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg), |
| 722 | &client->tune_done); |
| 723 | } |
| 724 | |
| 725 | static int smsdvb_set_frontend(struct dvb_frontend *fe, |
| 726 | struct dvb_frontend_parameters *fep) |
| 727 | { |
| 728 | struct smsdvb_client_t *client = |
| 729 | container_of(fe, struct smsdvb_client_t, frontend); |
| 730 | struct smscore_device_t *coredev = client->coredev; |
| 731 | |
| 732 | switch (smscore_get_device_mode(coredev)) { |
| 733 | case DEVICE_MODE_DVBT: |
| 734 | case DEVICE_MODE_DVBT_BDA: |
| 735 | return smsdvb_dvbt_set_frontend(fe, fep); |
| 736 | case DEVICE_MODE_ISDBT: |
| 737 | case DEVICE_MODE_ISDBT_BDA: |
Mauro Carvalho Chehab | cf4fab7 | 2009-12-23 11:28:46 -0300 | [diff] [blame] | 738 | return smsdvb_isdbt_set_frontend(fe, fep); |
Michael Krufky | 6b26fce | 2009-12-22 21:08:49 -0300 | [diff] [blame] | 739 | default: |
| 740 | return -EINVAL; |
| 741 | } |
| 742 | } |
| 743 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 744 | static int smsdvb_get_frontend(struct dvb_frontend *fe, |
| 745 | struct dvb_frontend_parameters *fep) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 746 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 747 | struct smsdvb_client_t *client = |
| 748 | container_of(fe, struct smsdvb_client_t, frontend); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 749 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 750 | sms_debug(""); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 751 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 752 | /* todo: */ |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 753 | memcpy(fep, &client->fe_params, |
| 754 | sizeof(struct dvb_frontend_parameters)); |
Michael Krufky | 7a6fbed | 2008-11-22 14:26:37 -0300 | [diff] [blame] | 755 | |
| 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | static int smsdvb_init(struct dvb_frontend *fe) |
| 760 | { |
| 761 | struct smsdvb_client_t *client = |
| 762 | container_of(fe, struct smsdvb_client_t, frontend); |
| 763 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 764 | sms_board_power(client->coredev, 1); |
| 765 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 766 | sms_board_dvb3_event(client, DVB3_EVENT_INIT); |
Michael Krufky | 7a6fbed | 2008-11-22 14:26:37 -0300 | [diff] [blame] | 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | static int smsdvb_sleep(struct dvb_frontend *fe) |
| 771 | { |
| 772 | struct smsdvb_client_t *client = |
| 773 | container_of(fe, struct smsdvb_client_t, frontend); |
| 774 | |
Michael Krufky | 3746b61 | 2009-07-12 23:30:14 -0300 | [diff] [blame] | 775 | sms_board_led_feedback(client->coredev, SMS_LED_OFF); |
| 776 | sms_board_power(client->coredev, 0); |
| 777 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 778 | sms_board_dvb3_event(client, DVB3_EVENT_SLEEP); |
Michael Krufky | 7a6fbed | 2008-11-22 14:26:37 -0300 | [diff] [blame] | 779 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 780 | return 0; |
| 781 | } |
| 782 | |
| 783 | static void smsdvb_release(struct dvb_frontend *fe) |
| 784 | { |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 785 | /* do nothing */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | static struct dvb_frontend_ops smsdvb_fe_ops = { |
| 789 | .info = { |
Uri Shkolnik | e0f14c2 | 2008-08-31 00:44:04 -0300 | [diff] [blame] | 790 | .name = "Siano Mobile Digital MDTV Receiver", |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 791 | .type = FE_OFDM, |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 792 | .frequency_min = 44250000, |
| 793 | .frequency_max = 867250000, |
| 794 | .frequency_stepsize = 250000, |
| 795 | .caps = FE_CAN_INVERSION_AUTO | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 796 | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | |
| 797 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | |
| 798 | FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | |
| 799 | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | |
| 800 | FE_CAN_GUARD_INTERVAL_AUTO | |
| 801 | FE_CAN_RECOVER | |
| 802 | FE_CAN_HIERARCHY_AUTO, |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 803 | }, |
| 804 | |
| 805 | .release = smsdvb_release, |
| 806 | |
| 807 | .set_frontend = smsdvb_set_frontend, |
| 808 | .get_frontend = smsdvb_get_frontend, |
| 809 | .get_tune_settings = smsdvb_get_tune_settings, |
| 810 | |
| 811 | .read_status = smsdvb_read_status, |
| 812 | .read_ber = smsdvb_read_ber, |
| 813 | .read_signal_strength = smsdvb_read_signal_strength, |
| 814 | .read_snr = smsdvb_read_snr, |
Michael Krufky | 851a909 | 2008-11-22 14:56:37 -0300 | [diff] [blame] | 815 | .read_ucblocks = smsdvb_read_ucblocks, |
Michael Krufky | 7a6fbed | 2008-11-22 14:26:37 -0300 | [diff] [blame] | 816 | |
| 817 | .init = smsdvb_init, |
| 818 | .sleep = smsdvb_sleep, |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 819 | }; |
| 820 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 821 | static int smsdvb_hotplug(struct smscore_device_t *coredev, |
| 822 | struct device *device, int arrival) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 823 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 824 | struct smsclient_params_t params; |
| 825 | struct smsdvb_client_t *client; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 826 | int rc; |
| 827 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 828 | /* device removal handled by onremove callback */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 829 | if (!arrival) |
| 830 | return 0; |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 831 | client = kzalloc(sizeof(struct smsdvb_client_t), GFP_KERNEL); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 832 | if (!client) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 833 | sms_err("kmalloc() failed"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 834 | return -ENOMEM; |
| 835 | } |
| 836 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 837 | /* register dvb adapter */ |
Michael Krufky | 1c11d54 | 2008-06-18 22:09:55 -0300 | [diff] [blame] | 838 | rc = dvb_register_adapter(&client->adapter, |
| 839 | sms_get_board( |
| 840 | smscore_get_board_id(coredev))->name, |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 841 | THIS_MODULE, device, adapter_nr); |
| 842 | if (rc < 0) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 843 | sms_err("dvb_register_adapter() failed %d", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 844 | goto adapter_error; |
| 845 | } |
| 846 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 847 | /* init dvb demux */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 848 | client->demux.dmx.capabilities = DMX_TS_FILTERING; |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 849 | client->demux.filternum = 32; /* todo: nova ??? */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 850 | client->demux.feednum = 32; |
| 851 | client->demux.start_feed = smsdvb_start_feed; |
| 852 | client->demux.stop_feed = smsdvb_stop_feed; |
| 853 | |
| 854 | rc = dvb_dmx_init(&client->demux); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 855 | if (rc < 0) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 856 | sms_err("dvb_dmx_init failed %d", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 857 | goto dvbdmx_error; |
| 858 | } |
| 859 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 860 | /* init dmxdev */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 861 | client->dmxdev.filternum = 32; |
| 862 | client->dmxdev.demux = &client->demux.dmx; |
| 863 | client->dmxdev.capabilities = 0; |
| 864 | |
| 865 | rc = dvb_dmxdev_init(&client->dmxdev, &client->adapter); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 866 | if (rc < 0) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 867 | sms_err("dvb_dmxdev_init failed %d", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 868 | goto dmxdev_error; |
| 869 | } |
| 870 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 871 | /* init and register frontend */ |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 872 | memcpy(&client->frontend.ops, &smsdvb_fe_ops, |
| 873 | sizeof(struct dvb_frontend_ops)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 874 | |
| 875 | rc = dvb_register_frontend(&client->adapter, &client->frontend); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 876 | if (rc < 0) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 877 | sms_err("frontend registration failed %d", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 878 | goto frontend_error; |
| 879 | } |
| 880 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 881 | params.initial_id = 1; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 882 | params.data_type = MSG_SMS_DVBT_BDA_DATA; |
| 883 | params.onresponse_handler = smsdvb_onresponse; |
| 884 | params.onremove_handler = smsdvb_onremove; |
| 885 | params.context = client; |
| 886 | |
| 887 | rc = smscore_register_client(coredev, ¶ms, &client->smsclient); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 888 | if (rc < 0) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 889 | sms_err("smscore_register_client() failed %d", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 890 | goto client_error; |
| 891 | } |
| 892 | |
| 893 | client->coredev = coredev; |
| 894 | |
| 895 | init_completion(&client->tune_done); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 896 | |
| 897 | kmutex_lock(&g_smsdvb_clientslock); |
| 898 | |
| 899 | list_add(&client->entry, &g_smsdvb_clients); |
| 900 | |
| 901 | kmutex_unlock(&g_smsdvb_clientslock); |
| 902 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 903 | client->event_fe_state = -1; |
| 904 | client->event_unc_state = -1; |
| 905 | sms_board_dvb3_event(client, DVB3_EVENT_HOTPLUG); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 906 | |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 907 | sms_info("success"); |
Michael Krufky | 250fa67 | 2008-11-16 22:45:42 -0300 | [diff] [blame] | 908 | sms_board_setup(coredev); |
| 909 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 910 | return 0; |
| 911 | |
| 912 | client_error: |
| 913 | dvb_unregister_frontend(&client->frontend); |
| 914 | |
| 915 | frontend_error: |
| 916 | dvb_dmxdev_release(&client->dmxdev); |
| 917 | |
| 918 | dmxdev_error: |
| 919 | dvb_dmx_release(&client->demux); |
| 920 | |
| 921 | dvbdmx_error: |
| 922 | dvb_unregister_adapter(&client->adapter); |
| 923 | |
| 924 | adapter_error: |
| 925 | kfree(client); |
| 926 | return rc; |
| 927 | } |
| 928 | |
Márton Németh | 2184dda | 2009-12-11 20:05:10 -0300 | [diff] [blame] | 929 | static int __init smsdvb_module_init(void) |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 930 | { |
| 931 | int rc; |
| 932 | |
| 933 | INIT_LIST_HEAD(&g_smsdvb_clients); |
| 934 | kmutex_init(&g_smsdvb_clientslock); |
| 935 | |
| 936 | rc = smscore_register_hotplug(smsdvb_hotplug); |
| 937 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 938 | sms_debug(""); |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 939 | |
| 940 | return rc; |
| 941 | } |
| 942 | |
Márton Németh | 2184dda | 2009-12-11 20:05:10 -0300 | [diff] [blame] | 943 | static void __exit smsdvb_module_exit(void) |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 944 | { |
| 945 | smscore_unregister_hotplug(smsdvb_hotplug); |
| 946 | |
| 947 | kmutex_lock(&g_smsdvb_clientslock); |
| 948 | |
| 949 | while (!list_empty(&g_smsdvb_clients)) |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 950 | smsdvb_unregister_client( |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 951 | (struct smsdvb_client_t *) g_smsdvb_clients.next); |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 952 | |
| 953 | kmutex_unlock(&g_smsdvb_clientslock); |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 954 | } |
Uri Shkolnik | e0f14c2 | 2008-08-31 00:44:04 -0300 | [diff] [blame] | 955 | |
| 956 | module_init(smsdvb_module_init); |
| 957 | module_exit(smsdvb_module_exit); |
| 958 | |
| 959 | MODULE_DESCRIPTION("SMS DVB subsystem adaptation module"); |
Uri Shkolnik | 843d060 | 2009-05-12 13:13:13 -0300 | [diff] [blame] | 960 | MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)"); |
Uri Shkolnik | e0f14c2 | 2008-08-31 00:44:04 -0300 | [diff] [blame] | 961 | MODULE_LICENSE("GPL"); |