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