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