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