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