Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Siano SMS10xx USB dongle |
| 3 | * |
Michael Krufky | 8544706 | 2008-05-22 18:29:20 -0300 | [diff] [blame] | 4 | * author: Anatoly Greenblat |
| 5 | * |
| 6 | * Copyright (c), 2005-2008 Siano Mobile Silicon, Inc. |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
Michael Krufky | 8544706 | 2008-05-22 18:29:20 -0300 | [diff] [blame] | 9 | * it under the terms of the GNU General Public License version 3 as |
| 10 | * published by the Free Software Foundation; |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 11 | * |
Michael Krufky | 8544706 | 2008-05-22 18:29:20 -0300 | [diff] [blame] | 12 | * Software distributed under the License is distributed on an "AS IS" |
| 13 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 14 | * |
Michael Krufky | 8544706 | 2008-05-22 18:29:20 -0300 | [diff] [blame] | 15 | * See the GNU General Public License for more details. |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 22 | #include <linux/module.h> |
| 23 | #include <linux/init.h> |
| 24 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 25 | #include "smscoreapi.h" |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 26 | |
Michael Krufky | 9c59f968 | 2008-05-19 18:57:12 -0300 | [diff] [blame] | 27 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 28 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 29 | struct list_head g_smsdvb_clients; |
| 30 | kmutex_t g_smsdvb_clientslock; |
| 31 | |
| 32 | int smsdvb_onresponse(void *context, smscore_buffer_t *cb) |
| 33 | { |
| 34 | smsdvb_client_t *client = (smsdvb_client_t *) context; |
Michael Krufky | 55ad310 | 2008-05-06 03:52:44 -0300 | [diff] [blame] | 35 | SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *)(((u8 *) cb->p) + cb->offset); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 36 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 37 | switch(phdr->msgType) { |
| 38 | case MSG_SMS_DVBT_BDA_DATA: |
| 39 | dvb_dmx_swfilter(&client->demux, (u8 *)(phdr + 1), |
| 40 | cb->size - sizeof(SmsMsgHdr_ST)); |
| 41 | break; |
| 42 | |
| 43 | case MSG_SMS_RF_TUNE_RES: |
| 44 | complete(&client->tune_done); |
| 45 | break; |
| 46 | |
| 47 | case MSG_SMS_GET_STATISTICS_RES: |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 48 | { |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 49 | SmsMsgStatisticsInfo_ST *p = |
| 50 | (SmsMsgStatisticsInfo_ST *)(phdr + 1); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 51 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 52 | if (p->Stat.IsDemodLocked) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 53 | { |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 54 | client->fe_status = FE_HAS_SIGNAL | |
| 55 | FE_HAS_CARRIER | |
| 56 | FE_HAS_VITERBI | |
| 57 | FE_HAS_SYNC | |
| 58 | FE_HAS_LOCK; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 59 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 60 | client->fe_snr = p->Stat.SNR; |
| 61 | client->fe_ber = p->Stat.BER; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 62 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 63 | if (p->Stat.InBandPwr < -95) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 64 | client->fe_signal_strength = 0; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 65 | else if (p->Stat.InBandPwr > -29) |
| 66 | client->fe_signal_strength = 100; |
| 67 | else |
| 68 | client->fe_signal_strength = |
| 69 | (p->Stat.InBandPwr + 95) * 3 / 2; |
| 70 | } else { |
| 71 | client->fe_status = 0; |
| 72 | client->fe_snr = |
| 73 | client->fe_ber = |
| 74 | client->fe_signal_strength = 0; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 75 | } |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 76 | |
| 77 | complete(&client->stat_done); |
| 78 | break; |
| 79 | } } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 80 | |
| 81 | smscore_putbuffer(client->coredev, cb); |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 86 | void smsdvb_unregister_client(smsdvb_client_t *client) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 87 | { |
| 88 | // must be called under clientslock |
| 89 | |
| 90 | list_del(&client->entry); |
| 91 | |
| 92 | smscore_unregister_client(client->smsclient); |
| 93 | dvb_unregister_frontend(&client->frontend); |
| 94 | dvb_dmxdev_release(&client->dmxdev); |
| 95 | dvb_dmx_release(&client->demux); |
| 96 | dvb_unregister_adapter(&client->adapter); |
| 97 | kfree(client); |
| 98 | } |
| 99 | |
| 100 | void smsdvb_onremove(void *context) |
| 101 | { |
| 102 | kmutex_lock(&g_smsdvb_clientslock); |
| 103 | |
Michael Krufky | 55ad310 | 2008-05-06 03:52:44 -0300 | [diff] [blame] | 104 | smsdvb_unregister_client((smsdvb_client_t *) context); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 105 | |
| 106 | kmutex_unlock(&g_smsdvb_clientslock); |
| 107 | } |
| 108 | |
| 109 | static int smsdvb_start_feed(struct dvb_demux_feed *feed) |
| 110 | { |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 111 | smsdvb_client_t *client = |
| 112 | container_of(feed->demux, smsdvb_client_t, demux); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 113 | SmsMsgData_ST PidMsg; |
| 114 | |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 115 | printk("%s add pid %d(%x)\n", __func__, feed->pid, feed->pid); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 116 | |
| 117 | PidMsg.xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; |
| 118 | PidMsg.xMsgHeader.msgDstId = HIF_TASK; |
| 119 | PidMsg.xMsgHeader.msgFlags = 0; |
| 120 | PidMsg.xMsgHeader.msgType = MSG_SMS_ADD_PID_FILTER_REQ; |
| 121 | PidMsg.xMsgHeader.msgLength = sizeof(PidMsg); |
| 122 | PidMsg.msgData[0] = feed->pid; |
| 123 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 124 | return smsclient_sendrequest(client->smsclient, |
| 125 | &PidMsg, sizeof(PidMsg)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static int smsdvb_stop_feed(struct dvb_demux_feed *feed) |
| 129 | { |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 130 | smsdvb_client_t *client = |
| 131 | container_of(feed->demux, smsdvb_client_t, demux); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 132 | SmsMsgData_ST PidMsg; |
| 133 | |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 134 | printk("%s remove pid %d(%x)\n", __func__, feed->pid, feed->pid); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 135 | |
| 136 | PidMsg.xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; |
| 137 | PidMsg.xMsgHeader.msgDstId = HIF_TASK; |
| 138 | PidMsg.xMsgHeader.msgFlags = 0; |
| 139 | PidMsg.xMsgHeader.msgType = MSG_SMS_REMOVE_PID_FILTER_REQ; |
| 140 | PidMsg.xMsgHeader.msgLength = sizeof(PidMsg); |
| 141 | PidMsg.msgData[0] = feed->pid; |
| 142 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 143 | return smsclient_sendrequest(client->smsclient, |
| 144 | &PidMsg, sizeof(PidMsg)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 145 | } |
| 146 | |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 147 | static int smsdvb_sendrequest_and_wait(smsdvb_client_t *client, |
| 148 | void *buffer, size_t size, |
| 149 | struct completion *completion) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 150 | { |
| 151 | int rc = smsclient_sendrequest(client->smsclient, buffer, size); |
| 152 | if (rc < 0) |
| 153 | return rc; |
| 154 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 155 | return wait_for_completion_timeout(completion, |
| 156 | msecs_to_jiffies(2000)) ? |
| 157 | 0 : -ETIME; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static int smsdvb_send_statistics_request(smsdvb_client_t *client) |
| 161 | { |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 162 | SmsMsgHdr_ST Msg = { MSG_SMS_GET_STATISTICS_REQ, |
| 163 | DVBT_BDA_CONTROL_MSG_ID, |
| 164 | HIF_TASK, sizeof(SmsMsgHdr_ST), 0 }; |
| 165 | return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg), |
| 166 | &client->stat_done); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | static int smsdvb_read_status(struct dvb_frontend *fe, fe_status_t *stat) |
| 170 | { |
| 171 | smsdvb_client_t *client = container_of(fe, smsdvb_client_t, frontend); |
| 172 | int rc = smsdvb_send_statistics_request(client); |
| 173 | |
| 174 | if (!rc) |
| 175 | *stat = client->fe_status; |
| 176 | |
| 177 | return rc; |
| 178 | } |
| 179 | |
| 180 | static int smsdvb_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 181 | { |
| 182 | smsdvb_client_t *client = container_of(fe, smsdvb_client_t, frontend); |
| 183 | int rc = smsdvb_send_statistics_request(client); |
| 184 | |
| 185 | if (!rc) |
| 186 | *ber = client->fe_ber; |
| 187 | |
| 188 | return rc; |
| 189 | } |
| 190 | |
| 191 | static int smsdvb_read_signal_strength(struct dvb_frontend *fe, u16 *strength) |
| 192 | { |
| 193 | smsdvb_client_t *client = container_of(fe, smsdvb_client_t, frontend); |
| 194 | int rc = smsdvb_send_statistics_request(client); |
| 195 | |
| 196 | if (!rc) |
| 197 | *strength = client->fe_signal_strength; |
| 198 | |
| 199 | return rc; |
| 200 | } |
| 201 | |
| 202 | static int smsdvb_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 203 | { |
| 204 | smsdvb_client_t *client = container_of(fe, smsdvb_client_t, frontend); |
| 205 | int rc = smsdvb_send_statistics_request(client); |
| 206 | |
| 207 | if (!rc) |
| 208 | *snr = client->fe_snr; |
| 209 | |
| 210 | return rc; |
| 211 | } |
| 212 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 213 | static int smsdvb_get_tune_settings(struct dvb_frontend *fe, |
| 214 | struct dvb_frontend_tune_settings *tune) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 215 | { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 216 | printk("%s\n", __func__); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 217 | |
| 218 | tune->min_delay_ms = 400; |
| 219 | tune->step_size = 250000; |
| 220 | tune->max_drift = 0; |
| 221 | return 0; |
| 222 | } |
| 223 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 224 | static int smsdvb_set_frontend(struct dvb_frontend *fe, |
| 225 | struct dvb_frontend_parameters *fep) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 226 | { |
| 227 | smsdvb_client_t *client = container_of(fe, smsdvb_client_t, frontend); |
| 228 | |
| 229 | struct |
| 230 | { |
| 231 | SmsMsgHdr_ST Msg; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 232 | u32 Data[3]; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 233 | } Msg; |
| 234 | |
| 235 | Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; |
| 236 | Msg.Msg.msgDstId = HIF_TASK; |
| 237 | Msg.Msg.msgFlags = 0; |
| 238 | Msg.Msg.msgType = MSG_SMS_RF_TUNE_REQ; |
| 239 | Msg.Msg.msgLength = sizeof(Msg); |
| 240 | Msg.Data[0] = fep->frequency; |
| 241 | Msg.Data[2] = 12000000; |
| 242 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 243 | printk("%s freq %d band %d\n", __func__, |
| 244 | fep->frequency, fep->u.ofdm.bandwidth); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 245 | |
| 246 | switch(fep->u.ofdm.bandwidth) |
| 247 | { |
| 248 | case BANDWIDTH_8_MHZ: Msg.Data[1] = BW_8_MHZ; break; |
| 249 | case BANDWIDTH_7_MHZ: Msg.Data[1] = BW_7_MHZ; break; |
| 250 | case BANDWIDTH_6_MHZ: Msg.Data[1] = BW_6_MHZ; break; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 251 | case BANDWIDTH_AUTO: return -EOPNOTSUPP; |
| 252 | default: return -EINVAL; |
| 253 | } |
| 254 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 255 | return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg), |
| 256 | &client->tune_done); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 257 | } |
| 258 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 259 | static int smsdvb_get_frontend(struct dvb_frontend *fe, |
| 260 | struct dvb_frontend_parameters *fep) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 261 | { |
| 262 | smsdvb_client_t *client = container_of(fe, smsdvb_client_t, frontend); |
| 263 | |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 264 | printk("%s\n", __func__); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 265 | |
| 266 | // todo: |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 267 | memcpy(fep, &client->fe_params, |
| 268 | sizeof(struct dvb_frontend_parameters)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | static void smsdvb_release(struct dvb_frontend *fe) |
| 273 | { |
| 274 | // do nothing |
| 275 | } |
| 276 | |
| 277 | static struct dvb_frontend_ops smsdvb_fe_ops = { |
| 278 | .info = { |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 279 | .name = "Siano Mobile Digital SMS10xx", |
| 280 | .type = FE_OFDM, |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 281 | .frequency_min = 44250000, |
| 282 | .frequency_max = 867250000, |
| 283 | .frequency_stepsize = 250000, |
| 284 | .caps = FE_CAN_INVERSION_AUTO | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 285 | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | |
| 286 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | |
| 287 | FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | |
| 288 | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | |
| 289 | FE_CAN_GUARD_INTERVAL_AUTO | |
| 290 | FE_CAN_RECOVER | |
| 291 | FE_CAN_HIERARCHY_AUTO, |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 292 | }, |
| 293 | |
| 294 | .release = smsdvb_release, |
| 295 | |
| 296 | .set_frontend = smsdvb_set_frontend, |
| 297 | .get_frontend = smsdvb_get_frontend, |
| 298 | .get_tune_settings = smsdvb_get_tune_settings, |
| 299 | |
| 300 | .read_status = smsdvb_read_status, |
| 301 | .read_ber = smsdvb_read_ber, |
| 302 | .read_signal_strength = smsdvb_read_signal_strength, |
| 303 | .read_snr = smsdvb_read_snr, |
| 304 | }; |
| 305 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 306 | int smsdvb_hotplug(smscore_device_t *coredev, |
| 307 | struct device *device, int arrival) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 308 | { |
| 309 | smsclient_params_t params; |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 310 | smsdvb_client_t *client; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 311 | int rc; |
| 312 | |
| 313 | // device removal handled by onremove callback |
| 314 | if (!arrival) |
| 315 | return 0; |
| 316 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 317 | if (smscore_get_device_mode(coredev) != 4) { |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 318 | printk(KERN_ERR "%sSMS Device mode is not set for DVB operation.\n", __func__); |
| 319 | return 0; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | client = kzalloc(sizeof(smsdvb_client_t), GFP_KERNEL); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 323 | if (!client) { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 324 | printk(KERN_INFO "%s kmalloc() failed\n", __func__); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 325 | return -ENOMEM; |
| 326 | } |
| 327 | |
| 328 | // register dvb adapter |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 329 | rc = dvb_register_adapter(&client->adapter, "Siano Digital Receiver", |
| 330 | THIS_MODULE, device, adapter_nr); |
| 331 | if (rc < 0) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 332 | printk("%s dvb_register_adapter() failed %d\n", __func__, rc); |
| 333 | goto adapter_error; |
| 334 | } |
| 335 | |
| 336 | // init dvb demux |
| 337 | client->demux.dmx.capabilities = DMX_TS_FILTERING; |
| 338 | client->demux.filternum = 32; // todo: nova ??? |
| 339 | client->demux.feednum = 32; |
| 340 | client->demux.start_feed = smsdvb_start_feed; |
| 341 | client->demux.stop_feed = smsdvb_stop_feed; |
| 342 | |
| 343 | rc = dvb_dmx_init(&client->demux); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 344 | if (rc < 0) { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 345 | printk("%s dvb_dmx_init failed %d\n\n", __func__, rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 346 | goto dvbdmx_error; |
| 347 | } |
| 348 | |
| 349 | // init dmxdev |
| 350 | client->dmxdev.filternum = 32; |
| 351 | client->dmxdev.demux = &client->demux.dmx; |
| 352 | client->dmxdev.capabilities = 0; |
| 353 | |
| 354 | rc = dvb_dmxdev_init(&client->dmxdev, &client->adapter); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 355 | if (rc < 0) { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 356 | printk("%s dvb_dmxdev_init failed %d\n", __func__, rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 357 | goto dmxdev_error; |
| 358 | } |
| 359 | |
| 360 | // init and register frontend |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 361 | memcpy(&client->frontend.ops, &smsdvb_fe_ops, |
| 362 | sizeof(struct dvb_frontend_ops)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 363 | |
| 364 | rc = dvb_register_frontend(&client->adapter, &client->frontend); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 365 | if (rc < 0) { |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 366 | printk("%s frontend registration failed %d\n", __func__, rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 367 | goto frontend_error; |
| 368 | } |
| 369 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 370 | params.initial_id = 1; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 371 | params.data_type = MSG_SMS_DVBT_BDA_DATA; |
| 372 | params.onresponse_handler = smsdvb_onresponse; |
| 373 | params.onremove_handler = smsdvb_onremove; |
| 374 | params.context = client; |
| 375 | |
| 376 | rc = smscore_register_client(coredev, ¶ms, &client->smsclient); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 377 | if (rc < 0) { |
| 378 | printk(KERN_INFO "%s smscore_register_client() failed %d\n", |
| 379 | __func__, rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 380 | goto client_error; |
| 381 | } |
| 382 | |
| 383 | client->coredev = coredev; |
| 384 | |
| 385 | init_completion(&client->tune_done); |
| 386 | init_completion(&client->stat_done); |
| 387 | |
| 388 | kmutex_lock(&g_smsdvb_clientslock); |
| 389 | |
| 390 | list_add(&client->entry, &g_smsdvb_clients); |
| 391 | |
| 392 | kmutex_unlock(&g_smsdvb_clientslock); |
| 393 | |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 394 | printk(KERN_INFO "%s success\n", __func__); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 395 | |
| 396 | return 0; |
| 397 | |
| 398 | client_error: |
| 399 | dvb_unregister_frontend(&client->frontend); |
| 400 | |
| 401 | frontend_error: |
| 402 | dvb_dmxdev_release(&client->dmxdev); |
| 403 | |
| 404 | dmxdev_error: |
| 405 | dvb_dmx_release(&client->demux); |
| 406 | |
| 407 | dvbdmx_error: |
| 408 | dvb_unregister_adapter(&client->adapter); |
| 409 | |
| 410 | adapter_error: |
| 411 | kfree(client); |
| 412 | return rc; |
| 413 | } |
| 414 | |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 415 | int smsdvb_register(void) |
| 416 | { |
| 417 | int rc; |
| 418 | |
| 419 | INIT_LIST_HEAD(&g_smsdvb_clients); |
| 420 | kmutex_init(&g_smsdvb_clientslock); |
| 421 | |
| 422 | rc = smscore_register_hotplug(smsdvb_hotplug); |
| 423 | |
Michael Krufky | 1865811 | 2008-05-22 18:30:17 -0300 | [diff] [blame] | 424 | printk(KERN_INFO "%s\n", __func__); |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 425 | |
| 426 | return rc; |
| 427 | } |
| 428 | |
| 429 | void smsdvb_unregister(void) |
| 430 | { |
| 431 | smscore_unregister_hotplug(smsdvb_hotplug); |
| 432 | |
| 433 | kmutex_lock(&g_smsdvb_clientslock); |
| 434 | |
| 435 | while (!list_empty(&g_smsdvb_clients)) |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame^] | 436 | smsdvb_unregister_client( |
| 437 | (smsdvb_client_t *) g_smsdvb_clients.next); |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 438 | |
| 439 | kmutex_unlock(&g_smsdvb_clientslock); |
Steven Toth | eae5566 | 2008-05-22 18:04:36 -0300 | [diff] [blame] | 440 | } |