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