blob: 7e72391cb13c8ec37051124a0fbd2400d7fa4160 [file] [log] [blame]
Srinivasa Rao Uppalaacdebcc2011-12-23 14:31:38 +05301/* Copyright (c) 2011-12, Code Aurora Forum. All rights reserved
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#define DRIVER_AUTHOR "Archana Ramchandran <archanar@codeaurora.org>"
14#define DRIVER_NAME "radio-iris"
15#define DRIVER_CARD "Qualcomm FM Radio Transceiver"
16#define DRIVER_DESC "Driver for Qualcomm FM Radio Transceiver "
17
18#include <linux/version.h>
19#include <linux/init.h>
20#include <linux/delay.h>
21#include <linux/uaccess.h>
22#include <linux/kfifo.h>
23#include <linux/param.h>
24#include <linux/interrupt.h>
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/version.h>
28#include <linux/videodev2.h>
29#include <linux/mutex.h>
30#include <linux/unistd.h>
31#include <linux/atomic.h>
32#include <linux/platform_device.h>
33#include <linux/workqueue.h>
34#include <linux/slab.h>
35#include <media/v4l2-common.h>
36#include <media/v4l2-ioctl.h>
37#include <media/radio-iris.h>
38#include <asm/unaligned.h>
39
40static unsigned int rds_buf = 100;
41module_param(rds_buf, uint, 0);
42MODULE_PARM_DESC(rds_buf, "RDS buffer entries: *100*");
43
44static void radio_hci_cmd_task(unsigned long arg);
45static void radio_hci_rx_task(unsigned long arg);
46static struct video_device *video_get_dev(void);
47static DEFINE_RWLOCK(hci_task_lock);
48
49struct iris_device {
50 struct device *dev;
51 struct kfifo data_buf[IRIS_BUF_MAX];
52
53 int pending_xfrs[IRIS_XFR_MAX];
54 int xfr_bytes_left;
55 int xfr_in_progress;
56 struct completion sync_xfr_start;
57 int tune_req;
Ankur Nandwanid928d542011-08-11 13:15:41 -070058 unsigned int mode;
59
60 __u16 pi;
61 __u8 pty;
62 __u8 ps_repeatcount;
Ankur Nandwani8f972e52011-08-24 11:48:32 -070063 __u8 prev_trans_rds;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070064
65 struct video_device *videodev;
66
67 struct mutex lock;
68 spinlock_t buf_lock[IRIS_BUF_MAX];
69 wait_queue_head_t event_queue;
70 wait_queue_head_t read_queue;
71
72 struct radio_hci_dev *fm_hdev;
73
74 struct v4l2_capability *g_cap;
75 struct v4l2_control *g_ctl;
76
77 struct hci_fm_mute_mode_req mute_mode;
78 struct hci_fm_stereo_mode_req stereo_mode;
79 struct hci_fm_station_rsp fm_st_rsp;
80 struct hci_fm_search_station_req srch_st;
81 struct hci_fm_search_rds_station_req srch_rds;
82 struct hci_fm_search_station_list_req srch_st_list;
83 struct hci_fm_recv_conf_req recv_conf;
Ankur Nandwanid928d542011-08-11 13:15:41 -070084 struct hci_fm_trans_conf_req_struct trans_conf;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070085 struct hci_fm_rds_grp_req rds_grp;
86 unsigned char g_search_mode;
Srinivasa Rao Uppalaf856ae62011-10-17 18:43:26 +053087 unsigned char power_mode;
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +053088 int search_on;
Ankur Nandwanid928d542011-08-11 13:15:41 -070089 unsigned int tone_freq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070090 unsigned char g_scan_time;
91 unsigned int g_antenna;
92 unsigned int g_rds_grp_proc_ps;
Srinivasa Rao Uppalaf856ae62011-10-17 18:43:26 +053093 unsigned char event_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070094 enum iris_region_t region;
95 struct hci_fm_dbg_param_rsp st_dbg_param;
96 struct hci_ev_srch_list_compl srch_st_result;
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -070097 struct hci_fm_riva_poke riva_data_req;
98 struct hci_fm_ssbi_req ssbi_data_accs;
99 struct hci_fm_ssbi_peek ssbi_peek_reg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700100};
101
102static struct video_device *priv_videodev;
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +0530103static int iris_do_calibration(struct iris_device *radio);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700104
105static struct v4l2_queryctrl iris_v4l2_queryctrl[] = {
106 {
107 .id = V4L2_CID_AUDIO_VOLUME,
108 .type = V4L2_CTRL_TYPE_INTEGER,
109 .name = "Volume",
110 .minimum = 0,
111 .maximum = 15,
112 .step = 1,
113 .default_value = 15,
114 },
115 {
116 .id = V4L2_CID_AUDIO_BALANCE,
117 .flags = V4L2_CTRL_FLAG_DISABLED,
118 },
119 {
120 .id = V4L2_CID_AUDIO_BASS,
121 .flags = V4L2_CTRL_FLAG_DISABLED,
122 },
123 {
124 .id = V4L2_CID_AUDIO_TREBLE,
125 .flags = V4L2_CTRL_FLAG_DISABLED,
126 },
127 {
128 .id = V4L2_CID_AUDIO_MUTE,
129 .type = V4L2_CTRL_TYPE_BOOLEAN,
130 .name = "Mute",
131 .minimum = 0,
132 .maximum = 1,
133 .step = 1,
134 .default_value = 1,
135 },
136 {
137 .id = V4L2_CID_AUDIO_LOUDNESS,
138 .flags = V4L2_CTRL_FLAG_DISABLED,
139 },
140 {
141 .id = V4L2_CID_PRIVATE_IRIS_SRCHMODE,
142 .type = V4L2_CTRL_TYPE_INTEGER,
143 .name = "Search mode",
144 .minimum = 0,
145 .maximum = 7,
146 .step = 1,
147 .default_value = 0,
148 },
149 {
150 .id = V4L2_CID_PRIVATE_IRIS_SCANDWELL,
151 .type = V4L2_CTRL_TYPE_INTEGER,
152 .name = "Search dwell time",
153 .minimum = 0,
154 .maximum = 7,
155 .step = 1,
156 .default_value = 0,
157 },
158 {
159 .id = V4L2_CID_PRIVATE_IRIS_SRCHON,
160 .type = V4L2_CTRL_TYPE_BOOLEAN,
161 .name = "Search on/off",
162 .minimum = 0,
163 .maximum = 1,
164 .step = 1,
165 .default_value = 1,
166
167 },
168 {
169 .id = V4L2_CID_PRIVATE_IRIS_STATE,
170 .type = V4L2_CTRL_TYPE_INTEGER,
171 .name = "radio 0ff/rx/tx/reset",
172 .minimum = 0,
173 .maximum = 3,
174 .step = 1,
175 .default_value = 1,
176
177 },
178 {
179 .id = V4L2_CID_PRIVATE_IRIS_REGION,
180 .type = V4L2_CTRL_TYPE_INTEGER,
181 .name = "radio standard",
182 .minimum = 0,
183 .maximum = 2,
184 .step = 1,
185 .default_value = 0,
186 },
187 {
188 .id = V4L2_CID_PRIVATE_IRIS_SIGNAL_TH,
189 .type = V4L2_CTRL_TYPE_INTEGER,
190 .name = "Signal Threshold",
191 .minimum = 0x80,
192 .maximum = 0x7F,
193 .step = 1,
194 .default_value = 0,
195 },
196 {
197 .id = V4L2_CID_PRIVATE_IRIS_SRCH_PTY,
198 .type = V4L2_CTRL_TYPE_INTEGER,
199 .name = "Search PTY",
200 .minimum = 0,
201 .maximum = 31,
202 .default_value = 0,
203 },
204 {
205 .id = V4L2_CID_PRIVATE_IRIS_SRCH_PI,
206 .type = V4L2_CTRL_TYPE_INTEGER,
207 .name = "Search PI",
208 .minimum = 0,
209 .maximum = 0xFF,
210 .default_value = 0,
211 },
212 {
213 .id = V4L2_CID_PRIVATE_IRIS_SRCH_CNT,
214 .type = V4L2_CTRL_TYPE_INTEGER,
215 .name = "Preset num",
216 .minimum = 0,
217 .maximum = 12,
218 .default_value = 0,
219 },
220 {
221 .id = V4L2_CID_PRIVATE_IRIS_EMPHASIS,
222 .type = V4L2_CTRL_TYPE_BOOLEAN,
223 .name = "Emphasis",
224 .minimum = 0,
225 .maximum = 1,
226 .default_value = 0,
227 },
228 {
229 .id = V4L2_CID_PRIVATE_IRIS_RDS_STD,
230 .type = V4L2_CTRL_TYPE_BOOLEAN,
231 .name = "RDS standard",
232 .minimum = 0,
233 .maximum = 1,
234 .default_value = 0,
235 },
236 {
237 .id = V4L2_CID_PRIVATE_IRIS_SPACING,
238 .type = V4L2_CTRL_TYPE_INTEGER,
239 .name = "Channel spacing",
240 .minimum = 0,
241 .maximum = 2,
242 .default_value = 0,
243 },
244 {
245 .id = V4L2_CID_PRIVATE_IRIS_RDSON,
246 .type = V4L2_CTRL_TYPE_BOOLEAN,
247 .name = "RDS on/off",
248 .minimum = 0,
249 .maximum = 1,
250 .default_value = 0,
251 },
252 {
253 .id = V4L2_CID_PRIVATE_IRIS_RDSGROUP_MASK,
254 .type = V4L2_CTRL_TYPE_INTEGER,
255 .name = "RDS group mask",
256 .minimum = 0,
257 .maximum = 0xFFFFFFFF,
258 .default_value = 0,
259 },
260 {
261 .id = V4L2_CID_PRIVATE_IRIS_RDSGROUP_PROC,
262 .type = V4L2_CTRL_TYPE_INTEGER,
263 .name = "RDS processing",
264 .minimum = 0,
265 .maximum = 0xFF,
266 .default_value = 0,
267 },
268 {
269 .id = V4L2_CID_PRIVATE_IRIS_RDSD_BUF,
270 .type = V4L2_CTRL_TYPE_INTEGER,
271 .name = "RDS data groups to buffer",
272 .minimum = 1,
273 .maximum = 21,
274 .default_value = 0,
275 },
276 {
277 .id = V4L2_CID_PRIVATE_IRIS_PSALL,
278 .type = V4L2_CTRL_TYPE_BOOLEAN,
279 .name = "pass all ps strings",
280 .minimum = 0,
281 .maximum = 1,
282 .default_value = 0,
283 },
284 {
285 .id = V4L2_CID_PRIVATE_IRIS_LP_MODE,
286 .type = V4L2_CTRL_TYPE_BOOLEAN,
287 .name = "Low power mode",
288 .minimum = 0,
289 .maximum = 1,
290 .default_value = 0,
291 },
292 {
293 .id = V4L2_CID_PRIVATE_IRIS_ANTENNA,
294 .type = V4L2_CTRL_TYPE_BOOLEAN,
295 .name = "headset/internal",
296 .minimum = 0,
297 .maximum = 1,
298 .default_value = 0,
299 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700300 {
301 .id = V4L2_CID_PRIVATE_IRIS_TX_SETPSREPEATCOUNT,
302 .type = V4L2_CTRL_TYPE_INTEGER,
303 .name = "Set PS REPEATCOUNT",
304 .minimum = 0,
305 .maximum = 15,
306 },
307 {
308 .id = V4L2_CID_PRIVATE_IRIS_STOP_RDS_TX_PS_NAME,
309 .type = V4L2_CTRL_TYPE_BOOLEAN,
310 .name = "Stop PS NAME",
311 .minimum = 0,
312 .maximum = 1,
313 },
314 {
315 .id = V4L2_CID_PRIVATE_IRIS_STOP_RDS_TX_RT,
316 .type = V4L2_CTRL_TYPE_BOOLEAN,
317 .name = "Stop RT",
318 .minimum = 0,
319 .maximum = 1,
320 },
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -0700321 {
322 .id = V4L2_CID_PRIVATE_IRIS_SOFT_MUTE,
323 .type = V4L2_CTRL_TYPE_BOOLEAN,
324 .name = "Soft Mute",
325 .minimum = 0,
326 .maximum = 1,
327 },
328 {
329 .id = V4L2_CID_PRIVATE_IRIS_RIVA_ACCS_ADDR,
330 .type = V4L2_CTRL_TYPE_BOOLEAN,
331 .name = "Riva addr",
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +0530332 .minimum = 0x3180000,
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -0700333 .maximum = 0x31E0004,
334 },
335 {
336 .id = V4L2_CID_PRIVATE_IRIS_RIVA_ACCS_LEN,
337 .type = V4L2_CTRL_TYPE_INTEGER,
338 .name = "Data len",
339 .minimum = 0,
340 .maximum = 0xFF,
341 },
342 {
343 .id = V4L2_CID_PRIVATE_IRIS_RIVA_PEEK,
344 .type = V4L2_CTRL_TYPE_BOOLEAN,
345 .name = "Riva peek",
346 .minimum = 0,
347 .maximum = 1,
348 },
349 {
350 .id = V4L2_CID_PRIVATE_IRIS_RIVA_POKE,
351 .type = V4L2_CTRL_TYPE_INTEGER,
352 .name = "Riva poke",
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +0530353 .minimum = 0x3180000,
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -0700354 .maximum = 0x31E0004,
355 },
356 {
357 .id = V4L2_CID_PRIVATE_IRIS_SSBI_ACCS_ADDR,
358 .type = V4L2_CTRL_TYPE_INTEGER,
359 .name = "Ssbi addr",
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +0530360 .minimum = 0x280,
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -0700361 .maximum = 0x37F,
362 },
363 {
364 .id = V4L2_CID_PRIVATE_IRIS_SSBI_PEEK,
365 .type = V4L2_CTRL_TYPE_INTEGER,
366 .name = "Ssbi peek",
367 .minimum = 0,
368 .maximum = 0x37F,
369 },
370 {
371 .id = V4L2_CID_PRIVATE_IRIS_SSBI_POKE,
372 .type = V4L2_CTRL_TYPE_INTEGER,
373 .name = "ssbi poke",
374 .minimum = 0x01,
375 .maximum = 0xFF,
376 },
377 {
378 .id = V4L2_CID_PRIVATE_IRIS_HLSI,
379 .type = V4L2_CTRL_TYPE_INTEGER,
380 .name = "set hlsi",
381 .minimum = 0,
382 .maximum = 2,
383 },
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +0530384 {
385 .id = V4L2_CID_PRIVATE_IRIS_RDS_GRP_COUNTERS,
386 .type = V4L2_CTRL_TYPE_BOOLEAN,
387 .name = "RDS grp",
388 .minimum = 0,
389 .maximum = 1,
390 },
391 {
392 .id = V4L2_CID_PRIVATE_IRIS_SET_NOTCH_FILTER,
393 .type = V4L2_CTRL_TYPE_INTEGER,
394 .name = "Notch filter",
395 .minimum = 0,
396 .maximum = 2,
397 },
Venkateshwarlu Domakonda787af692011-10-14 21:23:03 +0530398 {
399 .id = V4L2_CID_PRIVATE_IRIS_READ_DEFAULT,
400 .type = V4L2_CTRL_TYPE_INTEGER,
401 .name = "Read default",
402 },
403 {
404 .id = V4L2_CID_PRIVATE_IRIS_WRITE_DEFAULT,
405 .type = V4L2_CTRL_TYPE_INTEGER,
406 .name = "Write default",
407 },
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +0530408 {
409 .id = V4L2_CID_PRIVATE_IRIS_SET_CALIBRATION,
410 .type = V4L2_CTRL_TYPE_BOOLEAN,
411 .name = "SET Calibration",
412 .minimum = 0,
413 .maximum = 1,
414 },
415 {
416 .id = V4L2_CID_PRIVATE_IRIS_DO_CALIBRATION,
417 .type = V4L2_CTRL_TYPE_BOOLEAN,
418 .name = "SET Calibration",
419 .minimum = 0,
420 .maximum = 1,
421 },
Srinivasa Rao Uppalaacdebcc2011-12-23 14:31:38 +0530422 {
423 .id = V4L2_CID_PRIVATE_IRIS_GET_SINR,
424 .type = V4L2_CTRL_TYPE_INTEGER,
425 .name = "GET SINR",
426 .minimum = -128,
427 .maximum = 127,
428 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700429};
430
431static void iris_q_event(struct iris_device *radio,
432 enum iris_evt_t event)
433{
434 struct kfifo *data_b = &radio->data_buf[IRIS_BUF_EVENTS];
435 unsigned char evt = event;
436 if (kfifo_in_locked(data_b, &evt, 1, &radio->buf_lock[IRIS_BUF_EVENTS]))
437 wake_up_interruptible(&radio->event_queue);
438}
439
440static int hci_send_frame(struct sk_buff *skb)
441{
442 struct radio_hci_dev *hdev = (struct radio_hci_dev *) skb->dev;
443
444 if (!hdev) {
445 kfree_skb(skb);
446 return -ENODEV;
447 }
448
449 __net_timestamp(skb);
450
451 skb_orphan(skb);
452 return hdev->send(skb);
453}
454
455static void radio_hci_cmd_task(unsigned long arg)
456{
457 struct radio_hci_dev *hdev = (struct radio_hci_dev *) arg;
458 struct sk_buff *skb;
459 if (!(atomic_read(&hdev->cmd_cnt))
460 && time_after(jiffies, hdev->cmd_last_tx + HZ)) {
461 FMDERR("%s command tx timeout", hdev->name);
462 atomic_set(&hdev->cmd_cnt, 1);
463 }
464
465 skb = skb_dequeue(&hdev->cmd_q);
466 if (atomic_read(&hdev->cmd_cnt) && skb) {
467 kfree_skb(hdev->sent_cmd);
468 hdev->sent_cmd = skb_clone(skb, GFP_ATOMIC);
469 if (hdev->sent_cmd) {
470 atomic_dec(&hdev->cmd_cnt);
471 hci_send_frame(skb);
472 hdev->cmd_last_tx = jiffies;
473 } else {
474 skb_queue_head(&hdev->cmd_q, skb);
475 tasklet_schedule(&hdev->cmd_task);
476 }
477 }
478
479}
480
481static void radio_hci_rx_task(unsigned long arg)
482{
483 struct radio_hci_dev *hdev = (struct radio_hci_dev *) arg;
484 struct sk_buff *skb;
485
486 read_lock(&hci_task_lock);
487
488 skb = skb_dequeue(&hdev->rx_q);
489 radio_hci_event_packet(hdev, skb);
490
491 read_unlock(&hci_task_lock);
492}
493
494int radio_hci_register_dev(struct radio_hci_dev *hdev)
495{
496 struct iris_device *radio = video_get_drvdata(video_get_dev());
497 if (!radio) {
498 FMDERR(":radio is null");
499 return -EINVAL;
500 }
501
502 if (!hdev) {
503 FMDERR("hdev is null");
504 return -EINVAL;
505 }
506
507 hdev->flags = 0;
508
509 tasklet_init(&hdev->cmd_task, radio_hci_cmd_task, (unsigned long)
510 hdev);
511 tasklet_init(&hdev->rx_task, radio_hci_rx_task, (unsigned long)
512 hdev);
513
514 init_waitqueue_head(&hdev->req_wait_q);
515
516 skb_queue_head_init(&hdev->rx_q);
517 skb_queue_head_init(&hdev->cmd_q);
518 skb_queue_head_init(&hdev->raw_q);
519
520 if (!radio)
521 FMDERR(":radio is null");
522
523 radio->fm_hdev = hdev;
524
525 return 0;
526}
527EXPORT_SYMBOL(radio_hci_register_dev);
528
529int radio_hci_unregister_dev(struct radio_hci_dev *hdev)
530{
531 struct iris_device *radio = video_get_drvdata(video_get_dev());
532 if (!radio) {
533 FMDERR(":radio is null");
534 return -EINVAL;
535 }
536
537 tasklet_kill(&hdev->rx_task);
538 tasklet_kill(&hdev->cmd_task);
539 skb_queue_purge(&hdev->rx_q);
540 skb_queue_purge(&hdev->cmd_q);
541 skb_queue_purge(&hdev->raw_q);
542 kfree(radio->fm_hdev);
543 kfree(radio->videodev);
544
545 return 0;
546}
547EXPORT_SYMBOL(radio_hci_unregister_dev);
548
549int radio_hci_recv_frame(struct sk_buff *skb)
550{
551 struct radio_hci_dev *hdev = (struct radio_hci_dev *) skb->dev;
552 if (!hdev) {
553 FMDERR("%s hdev is null while receiving frame", hdev->name);
554 kfree_skb(skb);
555 return -ENXIO;
556 }
557
558 __net_timestamp(skb);
559
560 radio_hci_event_packet(hdev, skb);
Srinivasa Rao Uppalacf3a8112011-09-22 21:02:02 +0530561 kfree_skb(skb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700562 return 0;
563}
564EXPORT_SYMBOL(radio_hci_recv_frame);
565
566int radio_hci_send_cmd(struct radio_hci_dev *hdev, __u16 opcode, __u32 plen,
567 void *param)
568{
569 int len = RADIO_HCI_COMMAND_HDR_SIZE + plen;
570 struct radio_hci_command_hdr *hdr;
571 struct sk_buff *skb;
572 int ret = 0;
573
574 skb = alloc_skb(len, GFP_ATOMIC);
575 if (!skb) {
576 FMDERR("%s no memory for command", hdev->name);
577 return -ENOMEM;
578 }
579
580 hdr = (struct radio_hci_command_hdr *) skb_put(skb,
581 RADIO_HCI_COMMAND_HDR_SIZE);
582 hdr->opcode = cpu_to_le16(opcode);
583 hdr->plen = plen;
584
585 if (plen)
586 memcpy(skb_put(skb, plen), param, plen);
587
588 skb->dev = (void *) hdev;
589
590 ret = hci_send_frame(skb);
591
592 return ret;
593}
594EXPORT_SYMBOL(radio_hci_send_cmd);
595
596static int hci_fm_enable_recv_req(struct radio_hci_dev *hdev,
597 unsigned long param)
598{
599 __u16 opcode = 0;
600
601 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
602 HCI_OCF_FM_ENABLE_RECV_REQ);
603 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
604}
605
Ankur Nandwanid928d542011-08-11 13:15:41 -0700606static int hci_fm_tone_generator(struct radio_hci_dev *hdev,
607 unsigned long param)
608{
609 struct iris_device *radio = video_get_drvdata(video_get_dev());
610 __u16 opcode = 0;
611
612 opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ,
613 HCI_FM_SET_INTERNAL_TONE_GENRATOR);
614 return radio_hci_send_cmd(hdev, opcode,
615 sizeof(radio->tone_freq), &radio->tone_freq);
616}
617
618static int hci_fm_enable_trans_req(struct radio_hci_dev *hdev,
619 unsigned long param)
620{
621 __u16 opcode = 0;
622
623 opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ,
624 HCI_OCF_FM_ENABLE_TRANS_REQ);
625 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
626}
627
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700628static int hci_fm_disable_recv_req(struct radio_hci_dev *hdev,
629 unsigned long param)
630{
631 __u16 opcode = 0;
632
633 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
634 HCI_OCF_FM_DISABLE_RECV_REQ);
635 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
636}
637
Ankur Nandwanid928d542011-08-11 13:15:41 -0700638static int hci_fm_disable_trans_req(struct radio_hci_dev *hdev,
639 unsigned long param)
640{
641 __u16 opcode = 0;
642
643 opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ,
644 HCI_OCF_FM_DISABLE_TRANS_REQ);
645 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
646}
647
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700648static int hci_get_fm_recv_conf_req(struct radio_hci_dev *hdev,
649 unsigned long param)
650{
651 __u16 opcode = 0;
652
653 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
654 HCI_OCF_FM_GET_RECV_CONF_REQ);
655 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
656}
657
Srinivasa Rao Uppalac5320c22011-11-28 14:28:51 +0530658static int hci_get_fm_trans_conf_req(struct radio_hci_dev *hdev,
659 unsigned long param)
660{
661 u16 opcode = 0;
662
663 opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ,
664 HCI_OCF_FM_GET_TRANS_CONF_REQ);
665 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
666}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700667static int hci_set_fm_recv_conf_req(struct radio_hci_dev *hdev,
668 unsigned long param)
669{
670 __u16 opcode = 0;
671
672 struct hci_fm_recv_conf_req *recv_conf_req =
673 (struct hci_fm_recv_conf_req *) param;
674
675 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
676 HCI_OCF_FM_SET_RECV_CONF_REQ);
677 return radio_hci_send_cmd(hdev, opcode, sizeof((*recv_conf_req)),
678 recv_conf_req);
679}
680
Ankur Nandwanid928d542011-08-11 13:15:41 -0700681static int hci_set_fm_trans_conf_req(struct radio_hci_dev *hdev,
682 unsigned long param)
683{
684 __u16 opcode = 0;
685
686 struct hci_fm_trans_conf_req_struct *trans_conf_req =
687 (struct hci_fm_trans_conf_req_struct *) param;
688
689 opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ,
690 HCI_OCF_FM_SET_TRANS_CONF_REQ);
691 return radio_hci_send_cmd(hdev, opcode, sizeof((*trans_conf_req)),
692 trans_conf_req);
693}
694
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700695static int hci_fm_get_station_param_req(struct radio_hci_dev *hdev,
696 unsigned long param)
697{
698 __u16 opcode = 0;
699
700 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
701 HCI_OCF_FM_GET_STATION_PARAM_REQ);
702 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
703}
704
705static int hci_set_fm_mute_mode_req(struct radio_hci_dev *hdev,
706 unsigned long param)
707{
708 __u16 opcode = 0;
709 struct hci_fm_mute_mode_req *mute_mode_req =
710 (struct hci_fm_mute_mode_req *) param;
711
712 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
713 HCI_OCF_FM_SET_MUTE_MODE_REQ);
714 return radio_hci_send_cmd(hdev, opcode, sizeof((*mute_mode_req)),
715 mute_mode_req);
716}
717
Ankur Nandwanid928d542011-08-11 13:15:41 -0700718
719static int hci_trans_ps_req(struct radio_hci_dev *hdev,
720 unsigned long param)
721{
722 __u16 opcode = 0;
723 struct hci_fm_tx_ps *tx_ps_req =
724 (struct hci_fm_tx_ps *) param;
725
726 opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ,
727 HCI_OCF_FM_RDS_PS_REQ);
728
729 return radio_hci_send_cmd(hdev, opcode, sizeof((*tx_ps_req)),
730 tx_ps_req);
731}
732
733static int hci_trans_rt_req(struct radio_hci_dev *hdev,
734 unsigned long param)
735{
736 __u16 opcode = 0;
737 struct hci_fm_tx_rt *tx_rt_req =
738 (struct hci_fm_tx_rt *) param;
739
740 opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ,
741 HCI_OCF_FM_RDS_RT_REQ);
742
743 return radio_hci_send_cmd(hdev, opcode, sizeof((*tx_rt_req)),
744 tx_rt_req);
745}
746
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700747static int hci_set_fm_stereo_mode_req(struct radio_hci_dev *hdev,
748 unsigned long param)
749{
750 __u16 opcode = 0;
751 struct hci_fm_stereo_mode_req *stereo_mode_req =
752 (struct hci_fm_stereo_mode_req *) param;
753 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
754 HCI_OCF_FM_SET_STEREO_MODE_REQ);
755 return radio_hci_send_cmd(hdev, opcode, sizeof((*stereo_mode_req)),
756 stereo_mode_req);
757}
758
759static int hci_fm_set_antenna_req(struct radio_hci_dev *hdev,
760 unsigned long param)
761{
762 __u16 opcode = 0;
763
764 __u8 antenna = param;
765
766 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
767 HCI_OCF_FM_SET_ANTENNA);
768 return radio_hci_send_cmd(hdev, opcode, sizeof(antenna), &antenna);
769}
770
771static int hci_fm_set_sig_threshold_req(struct radio_hci_dev *hdev,
772 unsigned long param)
773{
774 __u16 opcode = 0;
775
776 __u8 sig_threshold = param;
777
Venkateshwarlu Domakonda1c67b752011-10-17 13:05:48 +0530778 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700779 HCI_OCF_FM_SET_SIGNAL_THRESHOLD);
780 return radio_hci_send_cmd(hdev, opcode, sizeof(sig_threshold),
781 &sig_threshold);
782}
783
Srinivasa Rao Uppalaf856ae62011-10-17 18:43:26 +0530784static int hci_fm_set_event_mask(struct radio_hci_dev *hdev,
785 unsigned long param)
786{
787 u16 opcode = 0;
788 u8 event_mask = param;
789
790 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
791 HCI_OCF_FM_SET_EVENT_MASK);
792 return radio_hci_send_cmd(hdev, opcode, sizeof(event_mask),
793 &event_mask);
794}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700795static int hci_fm_get_sig_threshold_req(struct radio_hci_dev *hdev,
796 unsigned long param)
797{
798 __u16 opcode = 0;
799
Venkateshwarlu Domakonda1c67b752011-10-17 13:05:48 +0530800 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700801 HCI_OCF_FM_GET_SIGNAL_THRESHOLD);
802 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
803}
804
805static int hci_fm_get_program_service_req(struct radio_hci_dev *hdev,
806 unsigned long param)
807{
808 __u16 opcode = 0;
809
Venkateshwarlu Domakonda1c67b752011-10-17 13:05:48 +0530810 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700811 HCI_OCF_FM_GET_PROGRAM_SERVICE_REQ);
812 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
813}
814
815static int hci_fm_get_radio_text_req(struct radio_hci_dev *hdev,
816 unsigned long param)
817{
818 __u16 opcode = 0;
819
Venkateshwarlu Domakonda1c67b752011-10-17 13:05:48 +0530820 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700821 HCI_OCF_FM_GET_RADIO_TEXT_REQ);
822 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
823}
824
825static int hci_fm_get_af_list_req(struct radio_hci_dev *hdev,
826 unsigned long param)
827{
828 __u16 opcode = 0;
829
Venkateshwarlu Domakonda1c67b752011-10-17 13:05:48 +0530830 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700831 HCI_OCF_FM_GET_AF_LIST_REQ);
832 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
833}
834
835static int hci_fm_search_stations_req(struct radio_hci_dev *hdev,
836 unsigned long param)
837{
838 __u16 opcode = 0;
839 struct hci_fm_search_station_req *srch_stations =
840 (struct hci_fm_search_station_req *) param;
841
842 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
843 HCI_OCF_FM_SEARCH_STATIONS);
844 return radio_hci_send_cmd(hdev, opcode, sizeof((*srch_stations)),
845 srch_stations);
846}
847
848static int hci_fm_srch_rds_stations_req(struct radio_hci_dev *hdev,
849 unsigned long param)
850{
851 __u16 opcode = 0;
852 struct hci_fm_search_rds_station_req *srch_stations =
853 (struct hci_fm_search_rds_station_req *) param;
854
855 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
856 HCI_OCF_FM_SEARCH_RDS_STATIONS);
857 return radio_hci_send_cmd(hdev, opcode, sizeof((*srch_stations)),
858 srch_stations);
859}
860
861static int hci_fm_srch_station_list_req(struct radio_hci_dev *hdev,
862 unsigned long param)
863{
864 __u16 opcode = 0;
865 struct hci_fm_search_station_list_req *srch_list =
866 (struct hci_fm_search_station_list_req *) param;
867
868 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
869 HCI_OCF_FM_SEARCH_STATIONS_LIST);
870 return radio_hci_send_cmd(hdev, opcode, sizeof((*srch_list)),
871 srch_list);
872}
873
874static int hci_fm_cancel_search_req(struct radio_hci_dev *hdev,
875 unsigned long param)
876{
877 __u16 opcode = 0;
878
879 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
880 HCI_OCF_FM_CANCEL_SEARCH);
881 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
882}
883
884static int hci_fm_rds_grp_process_req(struct radio_hci_dev *hdev,
885 unsigned long param)
886{
887 __u16 opcode = 0;
888
889 __u32 fm_grps_process = param;
890
891 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
892 HCI_OCF_FM_RDS_GRP_PROCESS);
893 return radio_hci_send_cmd(hdev, opcode, sizeof(fm_grps_process),
894 &fm_grps_process);
895}
896
897static int hci_fm_tune_station_req(struct radio_hci_dev *hdev,
898 unsigned long param)
899{
900 __u16 opcode = 0;
901
902 __u32 tune_freq = param;
903
904 opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
905 HCI_OCF_FM_TUNE_STATION_REQ);
906 return radio_hci_send_cmd(hdev, opcode, sizeof(tune_freq), &tune_freq);
907}
908
909static int hci_def_data_read_req(struct radio_hci_dev *hdev,
910 unsigned long param)
911{
912 __u16 opcode = 0;
913 struct hci_fm_def_data_rd_req *def_data_rd =
914 (struct hci_fm_def_data_rd_req *) param;
915
Venkateshwarlu Domakonda787af692011-10-14 21:23:03 +0530916 opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700917 HCI_OCF_FM_DEFAULT_DATA_READ);
918 return radio_hci_send_cmd(hdev, opcode, sizeof((*def_data_rd)),
919 def_data_rd);
920}
921
922static int hci_def_data_write_req(struct radio_hci_dev *hdev,
923 unsigned long param)
924{
925 __u16 opcode = 0;
926 struct hci_fm_def_data_wr_req *def_data_wr =
927 (struct hci_fm_def_data_wr_req *) param;
928
Venkateshwarlu Domakonda787af692011-10-14 21:23:03 +0530929 opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700930 HCI_OCF_FM_DEFAULT_DATA_WRITE);
931 return radio_hci_send_cmd(hdev, opcode, sizeof((*def_data_wr)),
932 def_data_wr);
933}
934
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +0530935static int hci_set_notch_filter_req(struct radio_hci_dev *hdev,
936 unsigned long param)
937{
938 __u16 opcode = 0;
939 __u8 notch_filter_val = param;
940
941 opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ,
942 HCI_OCF_FM_EN_NOTCH_CTRL);
943 return radio_hci_send_cmd(hdev, opcode, sizeof(notch_filter_val),
944 &notch_filter_val);
945}
946
947
948
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700949static int hci_fm_reset_req(struct radio_hci_dev *hdev, unsigned long param)
950{
951 __u16 opcode = 0;
952
953 opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
954 HCI_OCF_FM_RESET);
955 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
956}
957
958static int hci_fm_get_feature_lists_req(struct radio_hci_dev *hdev,
959 unsigned long param)
960{
961 __u16 opcode = 0;
962
963 opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
964 HCI_OCF_FM_GET_FEATURE_LIST);
965 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
966}
967
968static int hci_fm_do_calibration_req(struct radio_hci_dev *hdev,
969 unsigned long param)
970{
971 __u16 opcode = 0;
972
973 __u8 mode = param;
974
975 opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
976 HCI_OCF_FM_DO_CALIBRATION);
977 return radio_hci_send_cmd(hdev, opcode, sizeof(mode), &mode);
978}
979
980static int hci_read_grp_counters_req(struct radio_hci_dev *hdev,
981 unsigned long param)
982{
983 __u16 opcode = 0;
984
985 __u8 reset_counters = param;
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +0530986 opcode = hci_opcode_pack(HCI_OGF_FM_STATUS_PARAMETERS_CMD_REQ,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700987 HCI_OCF_FM_READ_GRP_COUNTERS);
988 return radio_hci_send_cmd(hdev, opcode, sizeof(reset_counters),
989 &reset_counters);
990}
991
992static int hci_peek_data_req(struct radio_hci_dev *hdev, unsigned long param)
993{
994 __u16 opcode = 0;
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -0700995 struct hci_fm_riva_data *peek_data = (struct hci_fm_riva_data *)param;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700996
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -0700997 opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700998 HCI_OCF_FM_PEEK_DATA);
999 return radio_hci_send_cmd(hdev, opcode, sizeof((*peek_data)),
1000 peek_data);
1001}
1002
1003static int hci_poke_data_req(struct radio_hci_dev *hdev, unsigned long param)
1004{
1005 __u16 opcode = 0;
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001006 struct hci_fm_riva_poke *poke_data = (struct hci_fm_riva_poke *) param;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001007
Srinivasa Rao Uppala6cc0e322011-08-12 10:54:48 -07001008 opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001009 HCI_OCF_FM_POKE_DATA);
1010 return radio_hci_send_cmd(hdev, opcode, sizeof((*poke_data)),
1011 poke_data);
1012}
1013
1014static int hci_ssbi_peek_reg_req(struct radio_hci_dev *hdev,
1015 unsigned long param)
1016{
1017 __u16 opcode = 0;
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001018 struct hci_fm_ssbi_peek *ssbi_peek = (struct hci_fm_ssbi_peek *) param;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001019
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001020 opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001021 HCI_OCF_FM_SSBI_PEEK_REG);
1022 return radio_hci_send_cmd(hdev, opcode, sizeof((*ssbi_peek)),
1023 ssbi_peek);
1024}
1025
1026static int hci_ssbi_poke_reg_req(struct radio_hci_dev *hdev,
1027 unsigned long param)
1028{
1029 __u16 opcode = 0;
1030 struct hci_fm_ssbi_req *ssbi_poke = (struct hci_fm_ssbi_req *) param;
1031
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001032 opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001033 HCI_OCF_FM_SSBI_POKE_REG);
1034 return radio_hci_send_cmd(hdev, opcode, sizeof((*ssbi_poke)),
1035 ssbi_poke);
1036}
1037
1038static int hci_fm_get_station_dbg_param_req(struct radio_hci_dev *hdev,
1039 unsigned long param)
1040{
1041 __u16 opcode = 0;
1042
Venkateshwarlu Domakonda1c67b752011-10-17 13:05:48 +05301043 opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001044 HCI_OCF_FM_STATION_DBG_PARAM);
1045 return radio_hci_send_cmd(hdev, opcode, 0, NULL);
1046}
1047
1048static int radio_hci_err(__u16 code)
1049{
1050 switch (code) {
1051 case 0:
1052 return 0;
1053 case 0x01:
1054 return -EBADRQC;
1055 case 0x02:
1056 return -ENOTCONN;
1057 case 0x03:
1058 return -EIO;
1059 case 0x07:
1060 return -ENOMEM;
1061 case 0x0c:
1062 return -EBUSY;
1063 case 0x11:
1064 return -EOPNOTSUPP;
1065 case 0x12:
1066 return -EINVAL;
1067 default:
1068 return -ENOSYS;
1069 }
1070}
1071
1072static int __radio_hci_request(struct radio_hci_dev *hdev,
1073 int (*req)(struct radio_hci_dev *hdev,
1074 unsigned long param),
1075 unsigned long param, __u32 timeout)
1076{
1077 int err = 0;
1078
1079 DECLARE_WAITQUEUE(wait, current);
1080
1081 hdev->req_status = HCI_REQ_PEND;
1082
1083 add_wait_queue(&hdev->req_wait_q, &wait);
1084 set_current_state(TASK_INTERRUPTIBLE);
1085
1086 err = req(hdev, param);
1087
1088 schedule_timeout(timeout);
1089
1090 remove_wait_queue(&hdev->req_wait_q, &wait);
1091
1092 if (signal_pending(current))
1093 return -EINTR;
1094
1095 switch (hdev->req_status) {
1096 case HCI_REQ_DONE:
1097 case HCI_REQ_STATUS:
1098 err = radio_hci_err(hdev->req_result);
1099 break;
1100
1101 case HCI_REQ_CANCELED:
1102 err = -hdev->req_result;
1103 break;
1104
1105 default:
1106 err = -ETIMEDOUT;
1107 break;
1108 }
1109
1110 hdev->req_status = hdev->req_result = 0;
1111
1112 return err;
1113}
1114
1115static inline int radio_hci_request(struct radio_hci_dev *hdev,
1116 int (*req)(struct
1117 radio_hci_dev * hdev, unsigned long param),
1118 unsigned long param, __u32 timeout)
1119{
1120 int ret = 0;
1121
1122 ret = __radio_hci_request(hdev, req, param, timeout);
1123
1124 return ret;
1125}
1126
Srinivasa Rao Uppalaf856ae62011-10-17 18:43:26 +05301127static inline int hci_conf_event_mask(__u8 *arg,
1128 struct radio_hci_dev *hdev)
1129{
1130 u8 event_mask = *arg;
1131 return radio_hci_request(hdev, hci_fm_set_event_mask,
1132 event_mask, RADIO_HCI_TIMEOUT);
1133}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001134static int hci_set_fm_recv_conf(struct hci_fm_recv_conf_req *arg,
1135 struct radio_hci_dev *hdev)
1136{
1137 int ret = 0;
1138 struct hci_fm_recv_conf_req *set_recv_conf = arg;
1139
1140 ret = radio_hci_request(hdev, hci_set_fm_recv_conf_req, (unsigned
1141 long)set_recv_conf, RADIO_HCI_TIMEOUT);
1142
1143 return ret;
1144}
1145
Ankur Nandwanid928d542011-08-11 13:15:41 -07001146static int hci_set_fm_trans_conf(struct hci_fm_trans_conf_req_struct *arg,
1147 struct radio_hci_dev *hdev)
1148{
1149 int ret = 0;
1150 struct hci_fm_trans_conf_req_struct *set_trans_conf = arg;
1151
1152 ret = radio_hci_request(hdev, hci_set_fm_trans_conf_req, (unsigned
1153 long)set_trans_conf, RADIO_HCI_TIMEOUT);
1154
1155 return ret;
1156}
1157
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001158static int hci_fm_tune_station(__u32 *arg, struct radio_hci_dev *hdev)
1159{
1160 int ret = 0;
1161 __u32 tune_freq = *arg;
1162
1163 ret = radio_hci_request(hdev, hci_fm_tune_station_req, tune_freq,
1164 RADIO_HCI_TIMEOUT);
1165
1166 return ret;
1167}
1168
1169static int hci_set_fm_mute_mode(struct hci_fm_mute_mode_req *arg,
1170 struct radio_hci_dev *hdev)
1171{
1172 int ret = 0;
1173 struct hci_fm_mute_mode_req *set_mute_conf = arg;
1174
1175 ret = radio_hci_request(hdev, hci_set_fm_mute_mode_req, (unsigned
1176 long)set_mute_conf, RADIO_HCI_TIMEOUT);
1177
1178 return ret;
1179}
1180
1181static int hci_set_fm_stereo_mode(struct hci_fm_stereo_mode_req *arg,
1182 struct radio_hci_dev *hdev)
1183{
1184 int ret = 0;
1185 struct hci_fm_stereo_mode_req *set_stereo_conf = arg;
1186
1187 ret = radio_hci_request(hdev, hci_set_fm_stereo_mode_req, (unsigned
1188 long)set_stereo_conf, RADIO_HCI_TIMEOUT);
1189
1190 return ret;
1191}
1192
1193static int hci_fm_set_antenna(__u8 *arg, struct radio_hci_dev *hdev)
1194{
1195 int ret = 0;
1196 __u8 antenna = *arg;
1197
1198 ret = radio_hci_request(hdev, hci_fm_set_antenna_req, antenna,
1199 RADIO_HCI_TIMEOUT);
1200
1201 return ret;
1202}
1203
1204static int hci_fm_set_signal_threshold(__u8 *arg,
1205 struct radio_hci_dev *hdev)
1206{
1207 int ret = 0;
1208 __u8 sig_threshold = *arg;
1209
1210 ret = radio_hci_request(hdev, hci_fm_set_sig_threshold_req,
1211 sig_threshold, RADIO_HCI_TIMEOUT);
1212
1213 return ret;
1214}
1215
1216static int hci_fm_search_stations(struct hci_fm_search_station_req *arg,
1217 struct radio_hci_dev *hdev)
1218{
1219 int ret = 0;
1220 struct hci_fm_search_station_req *srch_stations = arg;
1221
1222 ret = radio_hci_request(hdev, hci_fm_search_stations_req, (unsigned
1223 long)srch_stations, RADIO_HCI_TIMEOUT);
1224
1225 return ret;
1226}
1227
1228static int hci_fm_search_rds_stations(struct hci_fm_search_rds_station_req *arg,
1229 struct radio_hci_dev *hdev)
1230{
1231 int ret = 0;
1232 struct hci_fm_search_rds_station_req *srch_stations = arg;
1233
1234 ret = radio_hci_request(hdev, hci_fm_srch_rds_stations_req, (unsigned
1235 long)srch_stations, RADIO_HCI_TIMEOUT);
1236
1237 return ret;
1238}
1239
1240static int hci_fm_search_station_list
1241 (struct hci_fm_search_station_list_req *arg,
1242 struct radio_hci_dev *hdev)
1243{
1244 int ret = 0;
1245 struct hci_fm_search_station_list_req *srch_list = arg;
1246
1247 ret = radio_hci_request(hdev, hci_fm_srch_station_list_req, (unsigned
1248 long)srch_list, RADIO_HCI_TIMEOUT);
1249
1250 return ret;
1251}
1252
1253static int hci_fm_rds_grp(struct hci_fm_rds_grp_req *arg,
1254 struct radio_hci_dev *hdev)
1255{
1256 return 0;
1257}
1258
1259static int hci_fm_rds_grps_process(__u32 *arg, struct radio_hci_dev *hdev)
1260{
1261 int ret = 0;
1262 __u32 fm_grps_process = *arg;
1263
1264 ret = radio_hci_request(hdev, hci_fm_rds_grp_process_req,
1265 fm_grps_process, RADIO_HCI_TIMEOUT);
1266
1267 return ret;
1268}
1269
1270int hci_def_data_read(struct hci_fm_def_data_rd_req *arg,
1271 struct radio_hci_dev *hdev)
1272{
1273 int ret = 0;
1274 struct hci_fm_def_data_rd_req *def_data_rd = arg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001275 ret = radio_hci_request(hdev, hci_def_data_read_req, (unsigned
1276 long)def_data_rd, RADIO_HCI_TIMEOUT);
1277
1278 return ret;
1279}
1280
1281int hci_def_data_write(struct hci_fm_def_data_wr_req *arg,
1282 struct radio_hci_dev *hdev)
1283{
1284 int ret = 0;
1285 struct hci_fm_def_data_wr_req *def_data_wr = arg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001286 ret = radio_hci_request(hdev, hci_def_data_write_req, (unsigned
1287 long)def_data_wr, RADIO_HCI_TIMEOUT);
1288
1289 return ret;
1290}
1291
1292int hci_fm_do_calibration(__u8 *arg, struct radio_hci_dev *hdev)
1293{
1294 int ret = 0;
1295 __u8 mode = *arg;
1296
1297 ret = radio_hci_request(hdev, hci_fm_do_calibration_req, mode,
1298 RADIO_HCI_TIMEOUT);
1299
1300 return ret;
1301}
1302
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +05301303static int hci_read_grp_counters(__u8 *arg, struct radio_hci_dev *hdev)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001304{
1305 int ret = 0;
1306 __u8 reset_counters = *arg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001307 ret = radio_hci_request(hdev, hci_read_grp_counters_req,
1308 reset_counters, RADIO_HCI_TIMEOUT);
1309
1310 return ret;
1311}
1312
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +05301313static int hci_set_notch_filter(__u8 *arg, struct radio_hci_dev *hdev)
1314{
1315 int ret = 0;
1316 __u8 notch_filter = *arg;
1317 ret = radio_hci_request(hdev, hci_set_notch_filter_req,
1318 notch_filter, RADIO_HCI_TIMEOUT);
1319
1320 return ret;
1321}
1322
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001323static int hci_peek_data(struct hci_fm_riva_data *arg,
1324 struct radio_hci_dev *hdev)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001325{
1326 int ret = 0;
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001327 struct hci_fm_riva_data *peek_data = arg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001328
1329 ret = radio_hci_request(hdev, hci_peek_data_req, (unsigned
1330 long)peek_data, RADIO_HCI_TIMEOUT);
1331
1332 return ret;
1333}
1334
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001335static int hci_poke_data(struct hci_fm_riva_poke *arg,
1336 struct radio_hci_dev *hdev)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001337{
1338 int ret = 0;
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001339 struct hci_fm_riva_poke *poke_data = arg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001340
1341 ret = radio_hci_request(hdev, hci_poke_data_req, (unsigned
1342 long)poke_data, RADIO_HCI_TIMEOUT);
1343
1344 return ret;
1345}
1346
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001347static int hci_ssbi_peek_reg(struct hci_fm_ssbi_peek *arg,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001348 struct radio_hci_dev *hdev)
1349{
1350 int ret = 0;
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001351 struct hci_fm_ssbi_peek *ssbi_peek_reg = arg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001352
1353 ret = radio_hci_request(hdev, hci_ssbi_peek_reg_req, (unsigned
1354 long)ssbi_peek_reg, RADIO_HCI_TIMEOUT);
1355
1356 return ret;
1357}
1358
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001359static int hci_ssbi_poke_reg(struct hci_fm_ssbi_req *arg,
1360 struct radio_hci_dev *hdev)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001361{
1362 int ret = 0;
1363 struct hci_fm_ssbi_req *ssbi_poke_reg = arg;
1364
1365 ret = radio_hci_request(hdev, hci_ssbi_poke_reg_req, (unsigned
1366 long)ssbi_poke_reg, RADIO_HCI_TIMEOUT);
1367
1368 return ret;
1369}
1370
Venkateshwarlu Domakonda3a0b75d2011-11-23 17:03:27 +05301371static int hci_fm_set_cal_req_proc(struct radio_hci_dev *hdev,
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05301372 unsigned long param)
1373{
1374 u16 opcode = 0;
Venkateshwarlu Domakonda3a0b75d2011-11-23 17:03:27 +05301375 struct hci_fm_set_cal_req_proc *cal_req =
1376 (struct hci_fm_set_cal_req_proc *)param;
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05301377
1378 opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
1379 HCI_OCF_FM_SET_CALIBRATION);
Venkateshwarlu Domakonda3a0b75d2011-11-23 17:03:27 +05301380 return radio_hci_send_cmd(hdev, opcode, sizeof(*cal_req),
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05301381 cal_req);
Venkateshwarlu Domakonda3a0b75d2011-11-23 17:03:27 +05301382}
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05301383
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05301384static int hci_fm_do_cal_req(struct radio_hci_dev *hdev,
1385 unsigned long param)
1386{
1387 u16 opcode = 0;
1388 u8 cal_mode = param;
1389
1390 opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ,
1391 HCI_OCF_FM_DO_CALIBRATION);
1392 return radio_hci_send_cmd(hdev, opcode, sizeof(cal_mode),
1393 &cal_mode);
1394
1395}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001396static int hci_cmd(unsigned int cmd, struct radio_hci_dev *hdev)
1397{
1398 int ret = 0;
1399 unsigned long arg = 0;
1400
Ankur Nandwanid928d542011-08-11 13:15:41 -07001401 if (!hdev)
1402 return -ENODEV;
1403
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001404 switch (cmd) {
1405 case HCI_FM_ENABLE_RECV_CMD:
1406 ret = radio_hci_request(hdev, hci_fm_enable_recv_req, arg,
1407 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1408 break;
1409
1410 case HCI_FM_DISABLE_RECV_CMD:
1411 ret = radio_hci_request(hdev, hci_fm_disable_recv_req, arg,
1412 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1413 break;
1414
1415 case HCI_FM_GET_RECV_CONF_CMD:
1416 ret = radio_hci_request(hdev, hci_get_fm_recv_conf_req, arg,
1417 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1418 break;
1419
1420 case HCI_FM_GET_STATION_PARAM_CMD:
1421 ret = radio_hci_request(hdev,
1422 hci_fm_get_station_param_req, arg,
1423 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1424 break;
1425
1426 case HCI_FM_GET_SIGNAL_TH_CMD:
1427 ret = radio_hci_request(hdev,
1428 hci_fm_get_sig_threshold_req, arg,
1429 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1430 break;
1431
1432 case HCI_FM_GET_PROGRAM_SERVICE_CMD:
1433 ret = radio_hci_request(hdev,
1434 hci_fm_get_program_service_req, arg,
1435 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1436 break;
1437
1438 case HCI_FM_GET_RADIO_TEXT_CMD:
1439 ret = radio_hci_request(hdev, hci_fm_get_radio_text_req, arg,
1440 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1441 break;
1442
1443 case HCI_FM_GET_AF_LIST_CMD:
1444 ret = radio_hci_request(hdev, hci_fm_get_af_list_req, arg,
1445 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1446 break;
1447
1448 case HCI_FM_CANCEL_SEARCH_CMD:
1449 ret = radio_hci_request(hdev, hci_fm_cancel_search_req, arg,
1450 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1451 break;
1452
1453 case HCI_FM_RESET_CMD:
1454 ret = radio_hci_request(hdev, hci_fm_reset_req, arg,
1455 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1456 break;
1457
1458 case HCI_FM_GET_FEATURES_CMD:
1459 ret = radio_hci_request(hdev,
1460 hci_fm_get_feature_lists_req, arg,
1461 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1462 break;
1463
1464 case HCI_FM_STATION_DBG_PARAM_CMD:
1465 ret = radio_hci_request(hdev,
1466 hci_fm_get_station_dbg_param_req, arg,
1467 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1468 break;
1469
Ankur Nandwanid928d542011-08-11 13:15:41 -07001470 case HCI_FM_ENABLE_TRANS_CMD:
1471 ret = radio_hci_request(hdev, hci_fm_enable_trans_req, arg,
1472 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1473 break;
1474
1475 case HCI_FM_DISABLE_TRANS_CMD:
1476 ret = radio_hci_request(hdev, hci_fm_disable_trans_req, arg,
1477 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1478 break;
1479
Srinivasa Rao Uppalac5320c22011-11-28 14:28:51 +05301480 case HCI_FM_GET_TX_CONFIG:
1481 ret = radio_hci_request(hdev, hci_get_fm_trans_conf_req, arg,
1482 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
1483 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001484 default:
1485 ret = -EINVAL;
1486 break;
1487 }
1488
1489 return ret;
1490}
1491
1492static void radio_hci_req_complete(struct radio_hci_dev *hdev, int result)
1493{
1494 hdev->req_result = result;
1495 hdev->req_status = HCI_REQ_DONE;
1496 wake_up_interruptible(&hdev->req_wait_q);
1497}
1498
1499static void radio_hci_status_complete(struct radio_hci_dev *hdev, int result)
1500{
1501 hdev->req_result = result;
1502 hdev->req_status = HCI_REQ_STATUS;
1503 wake_up_interruptible(&hdev->req_wait_q);
1504}
1505
1506static void hci_cc_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb)
1507{
1508 __u8 status = *((__u8 *) skb->data);
1509
1510 if (status)
1511 return;
Srinivasa Rao Uppalac5320c22011-11-28 14:28:51 +05301512
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001513 radio_hci_req_complete(hdev, status);
1514}
1515
1516static void hci_cc_fm_disable_rsp(struct radio_hci_dev *hdev,
1517 struct sk_buff *skb)
1518{
1519 __u8 status = *((__u8 *) skb->data);
1520 struct iris_device *radio = video_get_drvdata(video_get_dev());
1521
1522 if (status)
1523 return;
1524
1525 iris_q_event(radio, IRIS_EVT_RADIO_READY);
1526
1527 radio_hci_req_complete(hdev, status);
1528}
1529
1530static void hci_cc_conf_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb)
1531{
1532 struct hci_fm_conf_rsp *rsp = (void *)skb->data;
1533 struct iris_device *radio = video_get_drvdata(video_get_dev());
1534
1535 if (rsp->status)
1536 return;
1537
1538 radio->recv_conf = rsp->recv_conf_rsp;
1539 radio_hci_req_complete(hdev, rsp->status);
1540}
1541
Srinivasa Rao Uppalac5320c22011-11-28 14:28:51 +05301542static void hci_cc_fm_trans_get_conf_rsp(struct radio_hci_dev *hdev,
1543 struct sk_buff *skb)
1544{
1545 struct hci_fm_get_trans_conf_rsp *rsp = (void *)skb->data;
1546 struct iris_device *radio = video_get_drvdata(video_get_dev());
1547
1548 if (rsp->status)
1549 return;
1550 memcpy((void *)&radio->trans_conf, (void*)&rsp->trans_conf_rsp,
1551 sizeof(rsp->trans_conf_rsp));
1552 radio_hci_req_complete(hdev, rsp->status);
1553}
1554
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001555static void hci_cc_fm_enable_rsp(struct radio_hci_dev *hdev,
1556 struct sk_buff *skb)
1557{
1558 struct hci_fm_conf_rsp *rsp = (void *)skb->data;
1559 struct iris_device *radio = video_get_drvdata(video_get_dev());
1560
1561 if (rsp->status)
1562 return;
1563
1564 iris_q_event(radio, IRIS_EVT_RADIO_READY);
1565
1566 radio_hci_req_complete(hdev, rsp->status);
1567}
1568
Ankur Nandwanid928d542011-08-11 13:15:41 -07001569
1570static void hci_cc_fm_trans_set_conf_rsp(struct radio_hci_dev *hdev,
1571 struct sk_buff *skb)
1572{
1573 struct hci_fm_conf_rsp *rsp = (void *)skb->data;
1574 struct iris_device *radio = video_get_drvdata(video_get_dev());
1575
1576 if (rsp->status)
1577 return;
1578
1579 iris_q_event(radio, HCI_EV_CMD_COMPLETE);
1580
1581 radio_hci_req_complete(hdev, rsp->status);
1582}
1583
1584
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001585static void hci_cc_sig_threshold_rsp(struct radio_hci_dev *hdev,
1586 struct sk_buff *skb)
1587{
1588 struct hci_fm_sig_threshold_rsp *rsp = (void *)skb->data;
1589 struct iris_device *radio = video_get_drvdata(video_get_dev());
1590 struct v4l2_control *v4l_ctl = radio->g_ctl;
1591
1592 if (rsp->status)
1593 return;
1594
1595 v4l_ctl->value = rsp->sig_threshold;
1596
1597 radio_hci_req_complete(hdev, rsp->status);
1598}
1599
1600static void hci_cc_station_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb)
1601{
1602 struct iris_device *radio = video_get_drvdata(video_get_dev());
1603 struct hci_fm_station_rsp *rsp = (void *)skb->data;
1604 radio->fm_st_rsp = *(rsp);
1605
1606 /* Tune is always succesful */
1607 radio_hci_req_complete(hdev, 0);
1608}
1609
1610static void hci_cc_prg_srv_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb)
1611{
1612 struct hci_fm_prgm_srv_rsp *rsp = (void *)skb->data;
1613
1614 if (rsp->status)
1615 return;
1616
1617 radio_hci_req_complete(hdev, rsp->status);
1618}
1619
1620static void hci_cc_rd_txt_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb)
1621{
1622 struct hci_fm_radio_txt_rsp *rsp = (void *)skb->data;
1623
1624 if (rsp->status)
1625 return;
1626
1627 radio_hci_req_complete(hdev, rsp->status);
1628}
1629
1630static void hci_cc_af_list_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb)
1631{
1632 struct hci_fm_af_list_rsp *rsp = (void *)skb->data;
1633
1634 if (rsp->status)
1635 return;
1636
1637 radio_hci_req_complete(hdev, rsp->status);
1638}
1639
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001640static void hci_cc_feature_list_rsp(struct radio_hci_dev *hdev,
1641 struct sk_buff *skb)
1642{
1643 struct hci_fm_feature_list_rsp *rsp = (void *)skb->data;
1644 struct iris_device *radio = video_get_drvdata(video_get_dev());
1645 struct v4l2_capability *v4l_cap = radio->g_cap;
1646
1647 if (rsp->status)
1648 return;
1649 v4l_cap->capabilities = (rsp->feature_mask & 0x000002) |
1650 (rsp->feature_mask & 0x000001);
1651
1652 radio_hci_req_complete(hdev, rsp->status);
1653}
1654
1655static void hci_cc_dbg_param_rsp(struct radio_hci_dev *hdev,
1656 struct sk_buff *skb)
1657{
1658 struct iris_device *radio = video_get_drvdata(video_get_dev());
1659 struct hci_fm_dbg_param_rsp *rsp = (void *)skb->data;
1660 radio->st_dbg_param = *(rsp);
1661
1662 if (radio->st_dbg_param.status)
1663 return;
1664
1665 radio_hci_req_complete(hdev, radio->st_dbg_param.status);
1666}
1667
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001668static void iris_q_evt_data(struct iris_device *radio,
1669 char *data, int len, int event)
1670{
1671 struct kfifo *data_b = &radio->data_buf[event];
1672 if (kfifo_in_locked(data_b, data, len, &radio->buf_lock[event]))
1673 wake_up_interruptible(&radio->event_queue);
1674}
1675
1676static void hci_cc_riva_peek_rsp(struct radio_hci_dev *hdev,
1677 struct sk_buff *skb)
1678{
1679 struct iris_device *radio = video_get_drvdata(video_get_dev());
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +05301680 __u8 status = *((__u8 *) skb->data);
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001681 int len;
1682 char *data;
1683
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +05301684 if (status)
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001685 return;
1686 len = skb->data[RIVA_PEEK_LEN_OFSET] + RIVA_PEEK_PARAM;
1687 data = kmalloc(len, GFP_ATOMIC);
1688
1689 if (!data) {
1690 FMDERR("Memory allocation failed");
1691 return;
1692 }
1693
1694 memcpy(data, &skb->data[PEEK_DATA_OFSET], len);
1695 iris_q_evt_data(radio, data, len, IRIS_BUF_PEEK);
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +05301696 radio_hci_req_complete(hdev, status);
Priyanka Vunnambab6b7e2011-11-01 15:41:54 +05301697 kfree(data);
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001698
1699}
Venkateshwarlu Domakonda787af692011-10-14 21:23:03 +05301700
1701static void hci_cc_riva_read_default_rsp(struct radio_hci_dev *hdev,
1702 struct sk_buff *skb)
1703{
1704 struct iris_device *radio = video_get_drvdata(video_get_dev());
1705 __u8 status = *((__u8 *) skb->data);
1706 __u8 len;
1707 char *data;
1708
1709 if (status)
1710 return;
1711 len = skb->data[1];
1712 data = kmalloc(len+2, GFP_ATOMIC);
1713 if (!data) {
1714 FMDERR("Memory allocation failed");
1715 return;
1716 }
1717
1718 data[0] = status;
1719 data[1] = len;
1720 memcpy(&data[2], &skb->data[DEFAULT_DATA_OFFSET], len);
1721 iris_q_evt_data(radio, data, len+2, IRIS_BUF_RD_DEFAULT);
1722 radio_hci_req_complete(hdev, status);
1723 kfree(data);
1724}
1725
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001726static void hci_cc_ssbi_peek_rsp(struct radio_hci_dev *hdev,
1727 struct sk_buff *skb)
1728{
1729 struct iris_device *radio = video_get_drvdata(video_get_dev());
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +05301730 __u8 status = *((__u8 *) skb->data);
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001731 char *data;
1732
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +05301733 if (status)
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001734 return;
1735 data = kmalloc(SSBI_PEEK_LEN, GFP_ATOMIC);
1736 if (!data) {
1737 FMDERR("Memory allocation failed");
1738 return;
1739 }
1740
1741 data[0] = skb->data[PEEK_DATA_OFSET];
1742 iris_q_evt_data(radio, data, SSBI_PEEK_LEN, IRIS_BUF_SSBI_PEEK);
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +05301743 radio_hci_req_complete(hdev, status);
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001744 kfree(data);
1745}
1746
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +05301747static void hci_cc_rds_grp_cntrs_rsp(struct radio_hci_dev *hdev,
1748 struct sk_buff *skb)
1749{
1750 struct iris_device *radio = video_get_drvdata(video_get_dev());
1751 __u8 status = *((__u8 *) skb->data);
1752 char *data;
1753 if (status)
1754 return;
1755 data = kmalloc(RDS_GRP_CNTR_LEN, GFP_ATOMIC);
1756 if (!data) {
1757 FMDERR("memory allocation failed");
1758 return;
1759 }
1760 memcpy(data, &skb->data[1], RDS_GRP_CNTR_LEN);
1761 iris_q_evt_data(radio, data, RDS_GRP_CNTR_LEN, IRIS_BUF_RDS_CNTRS);
1762 radio_hci_req_complete(hdev, status);
1763 kfree(data);
1764
1765}
1766
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05301767static void hci_cc_do_calibration_rsp(struct radio_hci_dev *hdev,
1768 struct sk_buff *skb)
1769{
1770 struct iris_device *radio = video_get_drvdata(video_get_dev());
1771 static struct hci_cc_do_calibration_rsp rsp ;
1772 rsp.status = skb->data[0];
1773 rsp.mode = skb->data[CALIB_MODE_OFSET];
1774
1775 if (rsp.status) {
1776 FMDERR("status = %d", rsp.status);
1777 return;
1778 }
1779 if (rsp.mode == PROCS_CALIB_MODE) {
1780 memcpy(&rsp.data[0], &skb->data[CALIB_DATA_OFSET],
1781 PROCS_CALIB_SIZE);
Venkateshwarlu Domakonda5e96e692011-12-05 17:36:06 +05301782 iris_q_evt_data(radio, rsp.data, PROCS_CALIB_SIZE,
1783 IRIS_BUF_CAL_DATA);
1784 } else {
1785 return;
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05301786 }
Venkateshwarlu Domakonda5e96e692011-12-05 17:36:06 +05301787
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05301788 radio_hci_req_complete(hdev, rsp.status);
1789}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001790static inline void hci_cmd_complete_event(struct radio_hci_dev *hdev,
1791 struct sk_buff *skb)
1792{
1793 struct hci_ev_cmd_complete *cmd_compl_ev = (void *) skb->data;
1794 __u16 opcode;
1795
1796 skb_pull(skb, sizeof(*cmd_compl_ev));
1797
1798 opcode = __le16_to_cpu(cmd_compl_ev->cmd_opcode);
1799
1800 switch (opcode) {
1801 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_ENABLE_RECV_REQ):
1802 hci_cc_fm_enable_rsp(hdev, skb);
1803 break;
1804 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_RECV_CONF_REQ):
1805 hci_cc_conf_rsp(hdev, skb);
1806 break;
1807
1808 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_DISABLE_RECV_REQ):
1809 hci_cc_fm_disable_rsp(hdev, skb);
1810 break;
1811
1812 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_RECV_CONF_REQ):
1813 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_MUTE_MODE_REQ):
1814 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_STEREO_MODE_REQ):
1815 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_ANTENNA):
1816 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_SIGNAL_THRESHOLD):
1817 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_CANCEL_SEARCH):
1818 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_RDS_GRP):
1819 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_RDS_GRP_PROCESS):
1820 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_EN_WAN_AVD_CTRL):
1821 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_EN_NOTCH_CTRL):
Ankur Nandwanid928d542011-08-11 13:15:41 -07001822 case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_ENABLE_TRANS_REQ):
1823 case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_DISABLE_TRANS_REQ):
1824 case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_RDS_RT_REQ):
1825 case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_RDS_PS_REQ):
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001826 case hci_common_cmd_op_pack(HCI_OCF_FM_DEFAULT_DATA_WRITE):
Venkateshwarlu Domakonda787af692011-10-14 21:23:03 +05301827 hci_cc_rsp(hdev, skb);
1828 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001829 case hci_common_cmd_op_pack(HCI_OCF_FM_RESET):
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001830 case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_SSBI_POKE_REG):
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001831 case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_POKE_DATA):
Ankur Nandwanid928d542011-08-11 13:15:41 -07001832 case hci_diagnostic_cmd_op_pack(HCI_FM_SET_INTERNAL_TONE_GENRATOR):
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05301833 case hci_common_cmd_op_pack(HCI_OCF_FM_SET_CALIBRATION):
Srinivasa Rao Uppalaf856ae62011-10-17 18:43:26 +05301834 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_EVENT_MASK):
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001835 hci_cc_rsp(hdev, skb);
1836 break;
Srinivasa Rao Uppalaf856ae62011-10-17 18:43:26 +05301837
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001838 case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_SSBI_PEEK_REG):
1839 hci_cc_ssbi_peek_rsp(hdev, skb);
1840 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001841 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_SIGNAL_THRESHOLD):
1842 hci_cc_sig_threshold_rsp(hdev, skb);
1843 break;
1844
1845 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_STATION_PARAM_REQ):
1846 hci_cc_station_rsp(hdev, skb);
1847 break;
1848
1849 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_PROGRAM_SERVICE_REQ):
1850 hci_cc_prg_srv_rsp(hdev, skb);
1851 break;
1852
1853 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_RADIO_TEXT_REQ):
1854 hci_cc_rd_txt_rsp(hdev, skb);
1855 break;
1856
1857 case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_AF_LIST_REQ):
1858 hci_cc_af_list_rsp(hdev, skb);
1859 break;
1860
1861 case hci_common_cmd_op_pack(HCI_OCF_FM_DEFAULT_DATA_READ):
Venkateshwarlu Domakonda787af692011-10-14 21:23:03 +05301862 hci_cc_riva_read_default_rsp(hdev, skb);
1863 break;
1864
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001865 case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_PEEK_DATA):
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07001866 hci_cc_riva_peek_rsp(hdev, skb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001867 break;
1868
1869 case hci_common_cmd_op_pack(HCI_OCF_FM_GET_FEATURE_LIST):
1870 hci_cc_feature_list_rsp(hdev, skb);
1871 break;
1872
1873 case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_STATION_DBG_PARAM):
1874 hci_cc_dbg_param_rsp(hdev, skb);
1875 break;
Ankur Nandwanid928d542011-08-11 13:15:41 -07001876 case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_SET_TRANS_CONF_REQ):
1877 hci_cc_fm_trans_set_conf_rsp(hdev, skb);
1878 break;
1879
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +05301880 case hci_status_param_op_pack(HCI_OCF_FM_READ_GRP_COUNTERS):
1881 hci_cc_rds_grp_cntrs_rsp(hdev, skb);
1882 break;
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05301883 case hci_common_cmd_op_pack(HCI_OCF_FM_DO_CALIBRATION):
1884 hci_cc_do_calibration_rsp(hdev, skb);
1885 break;
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +05301886
Srinivasa Rao Uppalac5320c22011-11-28 14:28:51 +05301887 case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_GET_TRANS_CONF_REQ):
1888 hci_cc_fm_trans_get_conf_rsp(hdev, skb);
1889 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001890 default:
1891 FMDERR("%s opcode 0x%x", hdev->name, opcode);
1892 break;
1893 }
1894
1895}
1896
1897static inline void hci_cmd_status_event(struct radio_hci_dev *hdev,
1898 struct sk_buff *skb)
1899{
1900 struct hci_ev_cmd_status *ev = (void *) skb->data;
1901 radio_hci_status_complete(hdev, ev->status);
1902}
1903
1904static inline void hci_ev_tune_status(struct radio_hci_dev *hdev,
1905 struct sk_buff *skb)
1906{
1907 int i;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001908 struct iris_device *radio = video_get_drvdata(video_get_dev());
1909
Venkateshwarlu Domakonda862492d2011-11-29 11:51:24 +05301910 memcpy(&radio->fm_st_rsp.station_rsp, &skb->data[0],
1911 sizeof(struct hci_ev_tune_status));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001912 iris_q_event(radio, IRIS_EVT_TUNE_SUCC);
1913
1914 for (i = 0; i < IRIS_BUF_MAX; i++) {
1915 if (i >= IRIS_BUF_RT_RDS)
1916 kfifo_reset(&radio->data_buf[i]);
1917 }
Srinivasa Rao Uppalaacdebcc2011-12-23 14:31:38 +05301918 if (radio->fm_st_rsp.station_rsp.serv_avble)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001919 iris_q_event(radio, IRIS_EVT_ABOVE_TH);
1920 else
1921 iris_q_event(radio, IRIS_EVT_BELOW_TH);
1922
1923 if (radio->fm_st_rsp.station_rsp.stereo_prg)
1924 iris_q_event(radio, IRIS_EVT_STEREO);
1925
1926 if (radio->fm_st_rsp.station_rsp.mute_mode)
1927 iris_q_event(radio, IRIS_EVT_MONO);
1928
1929 if (radio->fm_st_rsp.station_rsp.rds_sync_status)
1930 iris_q_event(radio, IRIS_EVT_RDS_AVAIL);
1931 else
1932 iris_q_event(radio, IRIS_EVT_RDS_NOT_AVAIL);
1933}
1934
1935static inline void hci_ev_search_compl(struct radio_hci_dev *hdev,
1936 struct sk_buff *skb)
1937{
1938 struct iris_device *radio = video_get_drvdata(video_get_dev());
1939 iris_q_event(radio, IRIS_EVT_SEEK_COMPLETE);
1940}
1941
1942static inline void hci_ev_srch_st_list_compl(struct radio_hci_dev *hdev,
1943 struct sk_buff *skb)
1944{
1945 struct iris_device *radio = video_get_drvdata(video_get_dev());
Srinivasa Rao Uppala18fb80e2011-07-17 17:33:00 -07001946 struct hci_ev_srch_list_compl *ev ;
1947 int cnt;
1948 int stn_num;
1949 int rel_freq;
1950 int abs_freq;
1951 int len;
1952
1953 ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
1954 if (!ev) {
1955 FMDERR("Memory allocation failed");
1956 return ;
1957 }
1958
1959 ev->num_stations_found = skb->data[STN_NUM_OFFSET];
1960 len = ev->num_stations_found * PARAMS_PER_STATION + STN_FREQ_OFFSET;
1961
1962 for (cnt = STN_FREQ_OFFSET, stn_num = 0;
Priyanka Vunnambab6b7e2011-11-01 15:41:54 +05301963 (cnt < len) && (stn_num < ev->num_stations_found)
1964 && (stn_num < ARRAY_SIZE(ev->rel_freq));
Srinivasa Rao Uppala18fb80e2011-07-17 17:33:00 -07001965 cnt += PARAMS_PER_STATION, stn_num++) {
1966 abs_freq = *((int *)&skb->data[cnt]);
1967 rel_freq = abs_freq - radio->recv_conf.band_low_limit;
1968 rel_freq = (rel_freq * 20) / KHZ_TO_MHZ;
1969
1970 ev->rel_freq[stn_num].rel_freq_lsb = GET_LSB(rel_freq);
1971 ev->rel_freq[stn_num].rel_freq_msb = GET_MSB(rel_freq);
1972 }
1973
1974 len = ev->num_stations_found * 2 + sizeof(ev->num_stations_found);
1975 iris_q_event(radio, IRIS_EVT_NEW_SRCH_LIST);
1976 iris_q_evt_data(radio, (char *)ev, len, IRIS_BUF_SRCH_LIST);
1977 kfree(ev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001978}
1979
1980static inline void hci_ev_search_next(struct radio_hci_dev *hdev,
1981 struct sk_buff *skb)
1982{
1983 struct iris_device *radio = video_get_drvdata(video_get_dev());
1984 iris_q_event(radio, IRIS_EVT_SCAN_NEXT);
1985}
1986
1987static inline void hci_ev_stereo_status(struct radio_hci_dev *hdev,
1988 struct sk_buff *skb)
1989{
1990 struct iris_device *radio = video_get_drvdata(video_get_dev());
1991 __u8 st_status = *((__u8 *) skb->data);
1992 if (st_status)
1993 iris_q_event(radio, IRIS_EVT_STEREO);
1994 else
1995 iris_q_event(radio, IRIS_EVT_MONO);
1996}
1997
Ankur Nandwani78a782b2011-07-07 21:11:21 -07001998
Ankur Nandwani78a782b2011-07-07 21:11:21 -07001999static inline void hci_ev_program_service(struct radio_hci_dev *hdev,
2000 struct sk_buff *skb)
2001{
2002 struct iris_device *radio = video_get_drvdata(video_get_dev());
2003 int len;
2004 char *data;
2005
2006 len = (skb->data[RDS_PS_LENGTH_OFFSET] * RDS_STRING) + RDS_OFFSET;
2007 iris_q_event(radio, IRIS_EVT_NEW_PS_RDS);
2008 data = kmalloc(len, GFP_ATOMIC);
2009 if (!data) {
2010 FMDERR("Failed to allocate memory");
2011 return;
2012 }
2013
2014 data[0] = skb->data[RDS_PS_LENGTH_OFFSET];
2015 data[1] = skb->data[RDS_PTYPE];
2016 data[2] = skb->data[RDS_PID_LOWER];
2017 data[3] = skb->data[RDS_PID_HIGHER];
2018 data[4] = 0;
2019
2020 memcpy(data+RDS_OFFSET, &skb->data[RDS_PS_DATA_OFFSET], len-RDS_OFFSET);
2021
Srinivasa Rao Uppala18fb80e2011-07-17 17:33:00 -07002022 iris_q_evt_data(radio, data, len, IRIS_BUF_PS_RDS);
Ankur Nandwani78a782b2011-07-07 21:11:21 -07002023
2024 kfree(data);
2025}
2026
2027
2028static inline void hci_ev_radio_text(struct radio_hci_dev *hdev,
2029 struct sk_buff *skb)
2030{
2031 struct iris_device *radio = video_get_drvdata(video_get_dev());
2032 int len = 0;
2033 char *data;
2034
2035 iris_q_event(radio, IRIS_EVT_NEW_RT_RDS);
2036
2037 while (skb->data[len+RDS_OFFSET] != 0x0d)
2038 len++;
2039 len++;
2040
2041 data = kmalloc(len+RDS_OFFSET, GFP_ATOMIC);
2042 if (!data) {
2043 FMDERR("Failed to allocate memory");
2044 return;
2045 }
2046
2047 data[0] = len;
2048 data[1] = skb->data[RDS_PTYPE];
2049 data[2] = skb->data[RDS_PID_LOWER];
2050 data[3] = skb->data[RDS_PID_HIGHER];
2051 data[4] = 0;
2052
2053 memcpy(data+RDS_OFFSET, &skb->data[RDS_OFFSET], len);
2054 data[len+RDS_OFFSET] = 0x00;
2055
Srinivasa Rao Uppala18fb80e2011-07-17 17:33:00 -07002056 iris_q_evt_data(radio, data, len+RDS_OFFSET, IRIS_BUF_RT_RDS);
Ankur Nandwani78a782b2011-07-07 21:11:21 -07002057
2058 kfree(data);
2059}
2060
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302061static void hci_ev_af_list(struct radio_hci_dev *hdev,
2062 struct sk_buff *skb)
2063{
2064 struct iris_device *radio = video_get_drvdata(video_get_dev());
2065 struct hci_ev_af_list ev;
2066
2067 ev.tune_freq = *((int *) &skb->data[0]);
2068 ev.pi_code = *((__le16 *) &skb->data[PI_CODE_OFFSET]);
2069 ev.af_size = skb->data[AF_SIZE_OFFSET];
2070 memcpy(&ev.af_list[0], &skb->data[AF_LIST_OFFSET], ev.af_size);
2071 iris_q_event(radio, IRIS_EVT_NEW_AF_LIST);
2072 iris_q_evt_data(radio, (char *)&ev, sizeof(ev), IRIS_BUF_AF_LIST);
2073}
2074
2075static void hci_ev_rds_lock_status(struct radio_hci_dev *hdev,
2076 struct sk_buff *skb)
2077{
2078 struct iris_device *radio = video_get_drvdata(video_get_dev());
2079 __u8 rds_status = skb->data[0];
2080
2081 if (rds_status)
2082 iris_q_event(radio, IRIS_EVT_RDS_AVAIL);
2083 else
2084 iris_q_event(radio, IRIS_EVT_RDS_NOT_AVAIL);
2085}
2086
2087static void hci_ev_service_available(struct radio_hci_dev *hdev,
2088 struct sk_buff *skb)
2089{
2090 struct iris_device *radio = video_get_drvdata(video_get_dev());
2091 if (radio->fm_st_rsp.station_rsp.serv_avble)
2092 iris_q_event(radio, IRIS_EVT_ABOVE_TH);
2093 else
2094 iris_q_event(radio, IRIS_EVT_BELOW_TH);
2095}
2096
2097static void hci_ev_rds_grp_complete(struct radio_hci_dev *hdev,
2098 struct sk_buff *skb)
2099{
2100 struct iris_device *radio = video_get_drvdata(video_get_dev());
2101 iris_q_event(radio, IRIS_EVT_TXRDSDONE);
2102}
Ankur Nandwani78a782b2011-07-07 21:11:21 -07002103
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002104void radio_hci_event_packet(struct radio_hci_dev *hdev, struct sk_buff *skb)
2105{
Priyanka Vunnambab6b7e2011-11-01 15:41:54 +05302106 struct radio_hci_event_hdr *hdr;
2107 u8 event;
2108
2109 if (skb == NULL) {
2110 FMDERR("Socket buffer is NULL");
2111 return;
2112 }
2113
2114 hdr = (void *) skb->data;
2115 event = hdr->evt;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002116
2117 skb_pull(skb, RADIO_HCI_EVENT_HDR_SIZE);
2118
2119 switch (event) {
2120 case HCI_EV_TUNE_STATUS:
2121 hci_ev_tune_status(hdev, skb);
2122 break;
2123 case HCI_EV_SEARCH_PROGRESS:
2124 case HCI_EV_SEARCH_RDS_PROGRESS:
2125 case HCI_EV_SEARCH_LIST_PROGRESS:
2126 hci_ev_search_next(hdev, skb);
2127 break;
2128 case HCI_EV_STEREO_STATUS:
2129 hci_ev_stereo_status(hdev, skb);
2130 break;
2131 case HCI_EV_RDS_LOCK_STATUS:
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302132 hci_ev_rds_lock_status(hdev, skb);
2133 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002134 case HCI_EV_SERVICE_AVAILABLE:
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302135 hci_ev_service_available(hdev, skb);
2136 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002137 case HCI_EV_RDS_RX_DATA:
Ankur Nandwani78a782b2011-07-07 21:11:21 -07002138 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002139 case HCI_EV_PROGRAM_SERVICE:
Ankur Nandwani78a782b2011-07-07 21:11:21 -07002140 hci_ev_program_service(hdev, skb);
2141 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002142 case HCI_EV_RADIO_TEXT:
Ankur Nandwani78a782b2011-07-07 21:11:21 -07002143 hci_ev_radio_text(hdev, skb);
2144 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002145 case HCI_EV_FM_AF_LIST:
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302146 hci_ev_af_list(hdev, skb);
2147 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002148 case HCI_EV_TX_RDS_GRP_COMPL:
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302149 hci_ev_rds_grp_complete(hdev, skb);
2150 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002151 case HCI_EV_TX_RDS_CONT_GRP_COMPL:
2152 break;
2153
2154 case HCI_EV_CMD_COMPLETE:
2155 hci_cmd_complete_event(hdev, skb);
2156 break;
2157
2158 case HCI_EV_CMD_STATUS:
2159 hci_cmd_status_event(hdev, skb);
2160 break;
2161
2162 case HCI_EV_SEARCH_COMPLETE:
2163 case HCI_EV_SEARCH_RDS_COMPLETE:
2164 hci_ev_search_compl(hdev, skb);
2165 break;
2166
2167 case HCI_EV_SEARCH_LIST_COMPLETE:
Srinivasa Rao Uppala18fb80e2011-07-17 17:33:00 -07002168 hci_ev_srch_st_list_compl(hdev, skb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002169 break;
2170
2171 default:
2172 break;
2173 }
2174}
2175
2176/*
2177 * fops/IOCTL helper functions
2178 */
2179
2180static int iris_search(struct iris_device *radio, int on, int dir)
2181{
2182 int retval = 0;
2183 enum search_t srch = radio->g_search_mode & SRCH_MODE;
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302184 radio->search_on = on;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002185
2186 if (on) {
2187 switch (srch) {
2188 case SCAN_FOR_STRONG:
2189 case SCAN_FOR_WEAK:
2190 radio->srch_st_list.srch_list_dir = dir;
2191 radio->srch_st_list.srch_list_mode = srch;
2192 radio->srch_st_list.srch_list_max = 0;
2193 retval = hci_fm_search_station_list(
2194 &radio->srch_st_list, radio->fm_hdev);
2195 break;
2196 case RDS_SEEK_PTY:
2197 case RDS_SCAN_PTY:
2198 case RDS_SEEK_PI:
Srinivasa Rao Uppala7bb22102011-07-14 11:27:30 -07002199 srch = srch - SEARCH_RDS_STNS_MODE_OFFSET;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002200 radio->srch_rds.srch_station.srch_mode = srch;
2201 radio->srch_rds.srch_station.srch_dir = dir;
2202 radio->srch_rds.srch_station.scan_time =
2203 radio->g_scan_time;
2204 retval = hci_fm_search_rds_stations(&radio->srch_rds,
2205 radio->fm_hdev);
2206 break;
2207 default:
2208 radio->srch_st.srch_mode = srch;
2209 radio->srch_st.scan_time = radio->g_scan_time;
2210 radio->srch_st.srch_dir = dir;
2211 retval = hci_fm_search_stations(
2212 &radio->srch_st, radio->fm_hdev);
2213 break;
2214 }
2215
2216 } else {
2217 retval = hci_cmd(HCI_FM_CANCEL_SEARCH_CMD, radio->fm_hdev);
2218 }
2219
2220 return retval;
2221}
2222
Srinivasa Rao Uppalaf856ae62011-10-17 18:43:26 +05302223static int set_low_power_mode(struct iris_device *radio, int power_mode)
2224{
2225
2226 int rds_grps_proc = 0x00;
2227 int retval = 0;
2228 if (radio->power_mode != power_mode) {
2229
2230 if (power_mode) {
2231 radio->event_mask = 0x00;
2232 rds_grps_proc = 0x00 | AF_JUMP_ENABLE ;
2233 retval = hci_fm_rds_grps_process(
2234 &rds_grps_proc,
2235 radio->fm_hdev);
2236 if (retval < 0) {
2237 FMDERR("Disable RDS failed");
2238 return retval;
2239 }
2240 retval = hci_conf_event_mask(&radio->event_mask,
2241 radio->fm_hdev);
2242 } else {
2243
2244 radio->event_mask = SIG_LEVEL_INTR |
2245 RDS_SYNC_INTR | AUDIO_CTRL_INTR;
2246 retval = hci_conf_event_mask(&radio->event_mask,
2247 radio->fm_hdev);
2248 if (retval < 0) {
2249 FMDERR("Enable Async events failed");
2250 return retval;
2251 }
2252 retval = hci_fm_rds_grps_process(
2253 &radio->g_rds_grp_proc_ps,
2254 radio->fm_hdev);
2255 }
2256 radio->power_mode = power_mode;
2257 }
2258 return retval;
2259}
Ankur Nandwanid928d542011-08-11 13:15:41 -07002260static int iris_recv_set_region(struct iris_device *radio, int req_region)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002261{
2262 int retval;
2263 radio->region = req_region;
2264
2265 switch (radio->region) {
2266 case IRIS_REGION_US:
Ankur Nandwanid928d542011-08-11 13:15:41 -07002267 radio->recv_conf.band_low_limit =
2268 REGION_US_EU_BAND_LOW;
2269 radio->recv_conf.band_high_limit =
2270 REGION_US_EU_BAND_HIGH;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002271 break;
2272 case IRIS_REGION_EU:
Ankur Nandwanid928d542011-08-11 13:15:41 -07002273 radio->recv_conf.band_low_limit =
2274 REGION_US_EU_BAND_LOW;
2275 radio->recv_conf.band_high_limit =
2276 REGION_US_EU_BAND_HIGH;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002277 break;
2278 case IRIS_REGION_JAPAN:
Ankur Nandwanid928d542011-08-11 13:15:41 -07002279 radio->recv_conf.band_low_limit =
Ankur Nandwanid928d542011-08-11 13:15:41 -07002280 REGION_JAPAN_STANDARD_BAND_LOW;
Srinivasa Rao Uppalacc62b1c2011-08-22 19:15:29 +05302281 radio->recv_conf.band_high_limit =
2282 REGION_JAPAN_STANDARD_BAND_HIGH;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002283 break;
2284 case IRIS_REGION_JAPAN_WIDE:
2285 radio->recv_conf.band_low_limit =
2286 REGION_JAPAN_WIDE_BAND_LOW;
2287 radio->recv_conf.band_high_limit =
2288 REGION_JAPAN_WIDE_BAND_HIGH;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002289 break;
2290 default:
Ankur Nandwanid928d542011-08-11 13:15:41 -07002291 /* The user specifies the value.
2292 So nothing needs to be done */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002293 break;
2294 }
2295
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002296 retval = hci_set_fm_recv_conf(
2297 &radio->recv_conf,
2298 radio->fm_hdev);
2299
2300 return retval;
2301}
2302
Ankur Nandwanid928d542011-08-11 13:15:41 -07002303
2304static int iris_trans_set_region(struct iris_device *radio, int req_region)
2305{
2306 int retval;
2307 radio->region = req_region;
2308
2309 switch (radio->region) {
2310 case IRIS_REGION_US:
2311 radio->trans_conf.band_low_limit =
2312 REGION_US_EU_BAND_LOW;
2313 radio->trans_conf.band_high_limit =
2314 REGION_US_EU_BAND_HIGH;
2315 break;
2316 case IRIS_REGION_EU:
2317 radio->trans_conf.band_low_limit =
2318 REGION_US_EU_BAND_LOW;
2319 radio->trans_conf.band_high_limit =
2320 REGION_US_EU_BAND_HIGH;
2321 break;
2322 case IRIS_REGION_JAPAN:
2323 radio->trans_conf.band_low_limit =
Ankur Nandwanid928d542011-08-11 13:15:41 -07002324 REGION_JAPAN_STANDARD_BAND_LOW;
Srinivasa Rao Uppalacc62b1c2011-08-22 19:15:29 +05302325 radio->trans_conf.band_high_limit =
2326 REGION_JAPAN_STANDARD_BAND_HIGH;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002327 break;
2328 case IRIS_REGION_JAPAN_WIDE:
2329 radio->recv_conf.band_low_limit =
2330 REGION_JAPAN_WIDE_BAND_LOW;
2331 radio->recv_conf.band_high_limit =
2332 REGION_JAPAN_WIDE_BAND_HIGH;
2333 default:
2334 break;
2335 }
2336
2337 retval = hci_set_fm_trans_conf(
2338 &radio->trans_conf,
2339 radio->fm_hdev);
2340 return retval;
2341}
2342
2343
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002344static int iris_set_freq(struct iris_device *radio, unsigned int freq)
2345{
2346
2347 int retval;
2348 retval = hci_fm_tune_station(&freq, radio->fm_hdev);
2349 if (retval < 0)
2350 FMDERR("Error while setting the frequency : %d\n", retval);
2351 return retval;
2352}
2353
2354
2355static int iris_vidioc_queryctrl(struct file *file, void *priv,
2356 struct v4l2_queryctrl *qc)
2357{
2358 unsigned char i;
2359 int retval = -EINVAL;
2360
2361 for (i = 0; i < ARRAY_SIZE(iris_v4l2_queryctrl); i++) {
2362 if (qc->id && qc->id == iris_v4l2_queryctrl[i].id) {
2363 memcpy(qc, &(iris_v4l2_queryctrl[i]), sizeof(*qc));
2364 retval = 0;
2365 break;
2366 }
2367 }
2368
2369 return retval;
2370}
2371
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05302372static int iris_do_calibration(struct iris_device *radio)
2373{
2374 char cal_mode = 0x00;
2375 int retval = 0x00;
2376
2377 cal_mode = PROCS_CALIB_MODE;
2378 retval = hci_cmd(HCI_FM_ENABLE_RECV_CMD,
2379 radio->fm_hdev);
2380 if (retval < 0) {
2381 FMDERR("Enable failed before calibration %x", retval);
2382 return retval;
2383 }
2384 retval = radio_hci_request(radio->fm_hdev, hci_fm_do_cal_req,
2385 (unsigned long)cal_mode, RADIO_HCI_TIMEOUT);
2386 if (retval < 0) {
2387 FMDERR("Do Process calibration failed %x", retval);
2388 return retval;
2389 }
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05302390 retval = hci_cmd(HCI_FM_DISABLE_RECV_CMD,
2391 radio->fm_hdev);
2392 if (retval < 0)
2393 FMDERR("Disable Failed after calibration %d", retval);
2394 return retval;
2395}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002396static int iris_vidioc_g_ctrl(struct file *file, void *priv,
2397 struct v4l2_control *ctrl)
2398{
2399 struct iris_device *radio = video_get_drvdata(video_devdata(file));
2400 int retval = 0;
2401
2402 switch (ctrl->id) {
2403 case V4L2_CID_AUDIO_VOLUME:
2404 break;
2405 case V4L2_CID_AUDIO_MUTE:
2406 ctrl->value = radio->mute_mode.hard_mute;
2407 break;
2408 case V4L2_CID_PRIVATE_IRIS_SRCHMODE:
2409 ctrl->value = radio->g_search_mode;
2410 break;
2411 case V4L2_CID_PRIVATE_IRIS_SCANDWELL:
2412 ctrl->value = radio->g_scan_time;
2413 break;
2414 case V4L2_CID_PRIVATE_IRIS_SRCHON:
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302415 ctrl->value = radio->search_on;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002416 break;
2417 case V4L2_CID_PRIVATE_IRIS_STATE:
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302418 ctrl->value = radio->mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002419 break;
2420 case V4L2_CID_PRIVATE_IRIS_IOVERC:
2421 retval = hci_cmd(HCI_FM_STATION_DBG_PARAM_CMD, radio->fm_hdev);
2422 if (retval < 0)
2423 return retval;
2424 ctrl->value = radio->st_dbg_param.io_verc;
2425 break;
2426 case V4L2_CID_PRIVATE_IRIS_INTDET:
2427 retval = hci_cmd(HCI_FM_STATION_DBG_PARAM_CMD, radio->fm_hdev);
2428 if (retval < 0)
2429 return retval;
2430 ctrl->value = radio->st_dbg_param.in_det_out;
2431 break;
2432 case V4L2_CID_PRIVATE_IRIS_REGION:
2433 ctrl->value = radio->region;
2434 break;
2435 case V4L2_CID_PRIVATE_IRIS_SIGNAL_TH:
2436 retval = hci_cmd(HCI_FM_GET_SIGNAL_TH_CMD, radio->fm_hdev);
2437 break;
2438 case V4L2_CID_PRIVATE_IRIS_SRCH_PTY:
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302439 ctrl->value = radio->srch_rds.srch_pty;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002440 break;
2441 case V4L2_CID_PRIVATE_IRIS_SRCH_PI:
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302442 ctrl->value = radio->srch_rds.srch_pi;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002443 break;
2444 case V4L2_CID_PRIVATE_IRIS_SRCH_CNT:
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302445 ctrl->value = radio->srch_st_result.num_stations_found;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002446 break;
2447 case V4L2_CID_PRIVATE_IRIS_EMPHASIS:
Ankur Nandwanid928d542011-08-11 13:15:41 -07002448 if (radio->mode == FM_RECV) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002449 ctrl->value = radio->recv_conf.emphasis;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002450 } else if (radio->mode == FM_TRANS) {
2451 ctrl->value = radio->trans_conf.emphasis;
2452 } else {
2453 FMDERR("Error in radio mode"
2454 " %d\n", retval);
2455 return -EINVAL;
2456 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002457 break;
2458 case V4L2_CID_PRIVATE_IRIS_RDS_STD:
Ankur Nandwanid928d542011-08-11 13:15:41 -07002459 if (radio->mode == FM_RECV) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002460 ctrl->value = radio->recv_conf.rds_std;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002461 } else if (radio->mode == FM_TRANS) {
2462 ctrl->value = radio->trans_conf.rds_std;
2463 } else {
2464 FMDERR("Error in radio mode"
2465 " %d\n", retval);
2466 return -EINVAL;
2467 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002468 break;
2469 case V4L2_CID_PRIVATE_IRIS_SPACING:
Ankur Nandwanid928d542011-08-11 13:15:41 -07002470 if (radio->mode == FM_RECV) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002471 ctrl->value = radio->recv_conf.ch_spacing;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002472 } else {
2473 FMDERR("Error in radio mode"
2474 " %d\n", retval);
2475 return -EINVAL;
2476 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002477 break;
2478 case V4L2_CID_PRIVATE_IRIS_RDSON:
Ankur Nandwanid928d542011-08-11 13:15:41 -07002479 if (radio->mode == FM_RECV) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002480 ctrl->value = radio->recv_conf.rds_std;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002481 } else {
2482 FMDERR("Error in radio mode"
2483 " %d\n", retval);
2484 return -EINVAL;
2485 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002486 break;
2487 case V4L2_CID_PRIVATE_IRIS_RDSGROUP_MASK:
2488 ctrl->value = radio->rds_grp.rds_grp_enable_mask;
2489 break;
2490 case V4L2_CID_PRIVATE_IRIS_RDSGROUP_PROC:
Srinivasa Rao Uppala58273f82011-08-10 19:07:45 -07002491 case V4L2_CID_PRIVATE_IRIS_PSALL:
2492 ctrl->value = (radio->g_rds_grp_proc_ps << RDS_CONFIG_OFFSET);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002493 break;
2494 case V4L2_CID_PRIVATE_IRIS_RDSD_BUF:
2495 ctrl->value = radio->rds_grp.rds_buf_size;
2496 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002497 case V4L2_CID_PRIVATE_IRIS_LP_MODE:
Srinivasa Rao Uppalaf856ae62011-10-17 18:43:26 +05302498 ctrl->value = radio->power_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002499 break;
2500 case V4L2_CID_PRIVATE_IRIS_ANTENNA:
2501 ctrl->value = radio->g_antenna;
2502 break;
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07002503 case V4L2_CID_PRIVATE_IRIS_SOFT_MUTE:
2504 ctrl->value = radio->mute_mode.soft_mute;
2505 break;
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05302506 case V4L2_CID_PRIVATE_IRIS_DO_CALIBRATION:
2507 retval = iris_do_calibration(radio);
2508 break;
Srinivasa Rao Uppalaacdebcc2011-12-23 14:31:38 +05302509 case V4L2_CID_PRIVATE_IRIS_GET_SINR:
2510 if (radio->mode == FM_RECV) {
2511 retval = hci_cmd(HCI_FM_GET_STATION_PARAM_CMD,
2512 radio->fm_hdev);
2513 if (retval < 0) {
2514 FMDERR("Get SINR Failed");
2515 return retval;
2516 }
2517 ctrl->value = radio->fm_st_rsp.station_rsp.sinr;
2518
2519 } else
2520 retval = -EINVAL;
2521
2522 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002523 default:
2524 retval = -EINVAL;
2525 }
2526 if (retval < 0)
2527 FMDERR("get control failed with %d, id: %d\n",
2528 retval, ctrl->id);
2529 return retval;
2530}
2531
Venkateshwarlu Domakonda787af692011-10-14 21:23:03 +05302532static int iris_vidioc_g_ext_ctrls(struct file *file, void *priv,
2533 struct v4l2_ext_controls *ctrl)
2534{
2535 int retval = 0;
2536 char *data = NULL;
2537 struct iris_device *radio = video_get_drvdata(video_devdata(file));
2538 struct hci_fm_def_data_rd_req default_data_rd;
2539
2540 switch ((ctrl->controls[0]).id) {
2541 case V4L2_CID_PRIVATE_IRIS_READ_DEFAULT:
2542 data = (ctrl->controls[0]).string;
2543 memset(&default_data_rd, 0, sizeof(default_data_rd));
2544 if (copy_from_user(&default_data_rd.mode, data,
2545 sizeof(default_data_rd)))
2546 return -EFAULT;
2547 retval = hci_def_data_read(&default_data_rd, radio->fm_hdev);
2548 break;
2549 default:
2550 retval = -EINVAL;
2551 }
2552
2553 return retval;
2554}
2555
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002556static int iris_vidioc_s_ext_ctrls(struct file *file, void *priv,
2557 struct v4l2_ext_controls *ctrl)
2558{
Ankur Nandwanid928d542011-08-11 13:15:41 -07002559 int retval = 0;
2560 int bytes_to_copy;
2561 struct hci_fm_tx_ps tx_ps;
2562 struct hci_fm_tx_rt tx_rt;
Venkateshwarlu Domakonda787af692011-10-14 21:23:03 +05302563 struct hci_fm_def_data_wr_req default_data;
Venkateshwarlu Domakonda3a0b75d2011-11-23 17:03:27 +05302564 struct hci_fm_set_cal_req_proc proc_cal_req;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002565
2566 struct iris_device *radio = video_get_drvdata(video_devdata(file));
2567 char *data = NULL;
2568
2569 switch ((ctrl->controls[0]).id) {
2570 case V4L2_CID_RDS_TX_PS_NAME:
2571 FMDBG("In V4L2_CID_RDS_TX_PS_NAME\n");
2572 /*Pass a sample PS string */
2573
2574 memset(tx_ps.ps_data, 0, MAX_PS_LENGTH);
2575 bytes_to_copy = min((int)(ctrl->controls[0]).size,
2576 MAX_PS_LENGTH);
2577 data = (ctrl->controls[0]).string;
2578
2579 if (copy_from_user(tx_ps.ps_data,
2580 data, bytes_to_copy))
2581 return -EFAULT;
2582 tx_ps.ps_control = 0x01;
2583 tx_ps.pi = radio->pi;
2584 tx_ps.pty = radio->pty;
2585 tx_ps.ps_repeatcount = radio->ps_repeatcount;
2586 tx_ps.ps_len = bytes_to_copy;
2587
2588 retval = radio_hci_request(radio->fm_hdev, hci_trans_ps_req,
2589 (unsigned long)&tx_ps, RADIO_HCI_TIMEOUT);
2590 break;
2591 case V4L2_CID_RDS_TX_RADIO_TEXT:
2592 bytes_to_copy =
2593 min((int)(ctrl->controls[0]).size, MAX_RT_LENGTH);
2594 data = (ctrl->controls[0]).string;
2595
2596 memset(tx_rt.rt_data, 0, MAX_RT_LENGTH);
2597
2598 if (copy_from_user(tx_rt.rt_data,
2599 data, bytes_to_copy))
2600 return -EFAULT;
2601
2602 tx_rt.rt_control = 0x01;
2603 tx_rt.pi = radio->pi;
2604 tx_rt.pty = radio->pty;
2605 tx_rt.ps_len = bytes_to_copy;
2606
2607 retval = radio_hci_request(radio->fm_hdev, hci_trans_rt_req,
2608 (unsigned long)&tx_rt, RADIO_HCI_TIMEOUT);
2609 break;
Venkateshwarlu Domakonda787af692011-10-14 21:23:03 +05302610 case V4L2_CID_PRIVATE_IRIS_WRITE_DEFAULT:
2611 data = (ctrl->controls[0]).string;
2612 memset(&default_data, 0, sizeof(default_data));
2613 if (copy_from_user(&default_data, data, sizeof(default_data)))
2614 return -EFAULT;
2615 retval = hci_def_data_write(&default_data, radio->fm_hdev);
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05302616 break;
2617 case V4L2_CID_PRIVATE_IRIS_SET_CALIBRATION:
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05302618 data = (ctrl->controls[0]).string;
2619 bytes_to_copy = (ctrl->controls[0]).size;
Venkateshwarlu Domakonda5e96e692011-12-05 17:36:06 +05302620 if (bytes_to_copy < PROCS_CALIB_SIZE) {
Venkateshwarlu Domakonda3a0b75d2011-11-23 17:03:27 +05302621 FMDERR("data is less than required size");
2622 return -EFAULT;
2623 }
2624 memset(proc_cal_req.data, 0, PROCS_CALIB_SIZE);
2625 proc_cal_req.mode = PROCS_CALIB_MODE;
2626 if (copy_from_user(&proc_cal_req.data[0],
2627 data, sizeof(proc_cal_req.data)))
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05302628 return -EFAULT;
Venkateshwarlu Domakonda3a0b75d2011-11-23 17:03:27 +05302629 retval = radio_hci_request(radio->fm_hdev,
2630 hci_fm_set_cal_req_proc,
2631 (unsigned long)&proc_cal_req,
2632 RADIO_HCI_TIMEOUT);
Srinivasa Rao Uppalaacdebcc2011-12-23 14:31:38 +05302633 if (retval < 0)
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05302634 FMDERR("Set Process calibration failed %d", retval);
Venkateshwarlu Domakonda787af692011-10-14 21:23:03 +05302635 break;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002636 default:
2637 FMDBG("Shouldn't reach here\n");
2638 retval = -1;
2639 }
2640 return retval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002641}
2642
2643static int iris_vidioc_s_ctrl(struct file *file, void *priv,
2644 struct v4l2_control *ctrl)
2645{
2646 struct iris_device *radio = video_get_drvdata(video_devdata(file));
2647 int retval = 0;
2648 unsigned int rds_grps_proc = 0;
2649 __u8 temp_val = 0;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002650 unsigned long arg = 0;
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302651 struct hci_fm_tx_ps tx_ps = {0};
2652 struct hci_fm_tx_rt tx_rt = {0};
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002653
2654 switch (ctrl->id) {
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +05302655 case V4L2_CID_PRIVATE_IRIS_TX_TONE:
Ankur Nandwanid928d542011-08-11 13:15:41 -07002656 radio->tone_freq = ctrl->value;
2657 retval = radio_hci_request(radio->fm_hdev,
2658 hci_fm_tone_generator, arg,
2659 msecs_to_jiffies(RADIO_HCI_TIMEOUT));
Srinivasa Rao Uppalac5320c22011-11-28 14:28:51 +05302660 if (retval < 0)
2661 FMDERR("Error while setting the tone %d", retval);
Ankur Nandwanid928d542011-08-11 13:15:41 -07002662 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002663 case V4L2_CID_AUDIO_VOLUME:
2664 break;
2665 case V4L2_CID_AUDIO_MUTE:
2666 radio->mute_mode.hard_mute = ctrl->value;
2667 radio->mute_mode.soft_mute = IOC_SFT_MUTE;
2668 retval = hci_set_fm_mute_mode(
2669 &radio->mute_mode,
2670 radio->fm_hdev);
2671 if (retval < 0)
2672 FMDERR("Error while set FM hard mute"" %d\n",
2673 retval);
2674 break;
2675 case V4L2_CID_PRIVATE_IRIS_SRCHMODE:
2676 radio->g_search_mode = ctrl->value;
2677 break;
2678 case V4L2_CID_PRIVATE_IRIS_SCANDWELL:
2679 radio->g_scan_time = ctrl->value;
2680 break;
2681 case V4L2_CID_PRIVATE_IRIS_SRCHON:
2682 iris_search(radio, ctrl->value, SRCH_DIR_UP);
2683 break;
2684 case V4L2_CID_PRIVATE_IRIS_STATE:
Ankur Nandwanid928d542011-08-11 13:15:41 -07002685 switch (ctrl->value) {
2686 case FM_RECV:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002687 retval = hci_cmd(HCI_FM_ENABLE_RECV_CMD,
2688 radio->fm_hdev);
Srinivasa Rao Uppalac5320c22011-11-28 14:28:51 +05302689 if (retval < 0) {
Ankur Nandwanid928d542011-08-11 13:15:41 -07002690 FMDERR("Error while enabling RECV FM"
Srinivasa Rao Uppala0ffb5d62011-08-02 17:54:13 -07002691 " %d\n", retval);
Srinivasa Rao Uppalac5320c22011-11-28 14:28:51 +05302692 return retval;
2693 }
2694 radio->mode = FM_RECV;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002695 radio->mute_mode.soft_mute = CTRL_ON;
2696 retval = hci_set_fm_mute_mode(
2697 &radio->mute_mode,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002698 radio->fm_hdev);
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05302699 if (retval < 0) {
Ankur Nandwanid928d542011-08-11 13:15:41 -07002700 FMDERR("Failed to enable Smute\n");
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05302701 return retval;
2702 }
Ankur Nandwanid928d542011-08-11 13:15:41 -07002703 radio->stereo_mode.stereo_mode = CTRL_OFF;
2704 radio->stereo_mode.sig_blend = CTRL_ON;
2705 radio->stereo_mode.intf_blend = CTRL_ON;
2706 radio->stereo_mode.most_switch = CTRL_ON;
2707 retval = hci_set_fm_stereo_mode(
2708 &radio->stereo_mode,
2709 radio->fm_hdev);
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05302710 if (retval < 0) {
Ankur Nandwanid928d542011-08-11 13:15:41 -07002711 FMDERR("Failed to set stereo mode\n");
Srinivasa Rao Uppalacb48ee62011-10-25 09:57:06 +05302712 return retval;
2713 }
Srinivasa Rao Uppalaf1febce2011-11-09 10:30:16 +05302714 radio->event_mask = SIG_LEVEL_INTR |
2715 RDS_SYNC_INTR | AUDIO_CTRL_INTR;
2716 retval = hci_conf_event_mask(&radio->event_mask,
2717 radio->fm_hdev);
2718 if (retval < 0) {
2719 FMDERR("Enable Async events failed");
2720 return retval;
2721 }
Srinivasa Rao Uppalaf0d13742011-09-08 10:13:13 +05302722 retval = hci_cmd(HCI_FM_GET_RECV_CONF_CMD,
2723 radio->fm_hdev);
2724 if (retval < 0)
2725 FMDERR("Failed to get the Recv Config\n");
Srinivasa Rao Uppala07522d92011-08-16 05:09:30 -07002726 break;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002727 case FM_TRANS:
2728 retval = hci_cmd(HCI_FM_ENABLE_TRANS_CMD,
2729 radio->fm_hdev);
2730 radio->mode = FM_TRANS;
Srinivasa Rao Uppalac5320c22011-11-28 14:28:51 +05302731 if (retval < 0) {
Ankur Nandwanid928d542011-08-11 13:15:41 -07002732 FMDERR("Error while enabling TRANS FM"
2733 " %d\n", retval);
Srinivasa Rao Uppalac5320c22011-11-28 14:28:51 +05302734 return retval;
2735 }
2736 retval = hci_cmd(HCI_FM_GET_TX_CONFIG, radio->fm_hdev);
2737 if (retval < 0)
2738 FMDERR("get frequency failed %d\n", retval);
Srinivasa Rao Uppala07522d92011-08-16 05:09:30 -07002739 break;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002740 case FM_OFF:
2741 switch (radio->mode) {
2742 case FM_RECV:
2743 retval = hci_cmd(HCI_FM_DISABLE_RECV_CMD,
2744 radio->fm_hdev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002745 if (retval < 0)
Ankur Nandwanid928d542011-08-11 13:15:41 -07002746 FMDERR("Err on disable recv FM"
2747 " %d\n", retval);
2748 break;
2749 case FM_TRANS:
2750 retval = hci_cmd(HCI_FM_DISABLE_TRANS_CMD,
2751 radio->fm_hdev);
2752
Srinivasa Rao Uppala0ffb5d62011-08-02 17:54:13 -07002753 if (retval < 0)
Ankur Nandwanid928d542011-08-11 13:15:41 -07002754 FMDERR("Err disabling trans FM"
Srinivasa Rao Uppala0ffb5d62011-08-02 17:54:13 -07002755 " %d\n", retval);
Ankur Nandwanid928d542011-08-11 13:15:41 -07002756 break;
2757 default:
2758 retval = -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002759 }
Srinivasa Rao Uppalacc62b1c2011-08-22 19:15:29 +05302760 break;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002761 default:
2762 retval = -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002763 }
2764 break;
2765 case V4L2_CID_PRIVATE_IRIS_REGION:
Ankur Nandwanid928d542011-08-11 13:15:41 -07002766 if (radio->mode == FM_RECV) {
2767 retval = iris_recv_set_region(radio, ctrl->value);
2768 } else {
2769 if (radio->mode == FM_TRANS)
2770 retval = iris_trans_set_region(radio,
2771 ctrl->value);
2772 else
2773 retval = -EINVAL;
2774 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002775 break;
2776 case V4L2_CID_PRIVATE_IRIS_SIGNAL_TH:
2777 temp_val = ctrl->value;
2778 retval = hci_fm_set_signal_threshold(
2779 &temp_val,
2780 radio->fm_hdev);
2781 if (retval < 0) {
2782 FMDERR("Error while setting signal threshold\n");
2783 break;
2784 }
2785 break;
2786 case V4L2_CID_PRIVATE_IRIS_SRCH_PTY:
2787 radio->srch_rds.srch_pty = ctrl->value;
2788 radio->srch_st_list.srch_pty = ctrl->value;
2789 break;
2790 case V4L2_CID_PRIVATE_IRIS_SRCH_PI:
2791 radio->srch_rds.srch_pi = ctrl->value;
2792 break;
2793 case V4L2_CID_PRIVATE_IRIS_SRCH_CNT:
2794 break;
2795 case V4L2_CID_PRIVATE_IRIS_SPACING:
Venkateshwarlu Domakonda45496f12011-11-23 12:51:13 +05302796 if (radio->mode == FM_RECV) {
2797 radio->recv_conf.ch_spacing = ctrl->value;
2798 retval = hci_set_fm_recv_conf(
2799 &radio->recv_conf,
2800 radio->fm_hdev);
2801 if (retval < 0)
2802 FMDERR("Error in setting channel spacing");
2803 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002804 break;
2805 case V4L2_CID_PRIVATE_IRIS_EMPHASIS:
Ankur Nandwani8f972e52011-08-24 11:48:32 -07002806 switch (radio->mode) {
2807 case FM_RECV:
2808 radio->recv_conf.emphasis = ctrl->value;
2809 retval = hci_set_fm_recv_conf(
2810 &radio->recv_conf,
2811 radio->fm_hdev);
2812 if (retval < 0)
2813 FMDERR("Error in setting emphasis");
Ankur Nandwanid928d542011-08-11 13:15:41 -07002814 break;
Ankur Nandwani8f972e52011-08-24 11:48:32 -07002815 case FM_TRANS:
2816 radio->trans_conf.emphasis = ctrl->value;
2817 retval = hci_set_fm_trans_conf(
2818 &radio->trans_conf,
2819 radio->fm_hdev);
2820 if (retval < 0)
2821 FMDERR("Error in setting emphasis");
2822 break;
2823 default:
2824 retval = -EINVAL;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002825 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002826 break;
2827 case V4L2_CID_PRIVATE_IRIS_RDS_STD:
Ankur Nandwani8f972e52011-08-24 11:48:32 -07002828 switch (radio->mode) {
2829 case FM_RECV:
2830 radio->recv_conf.rds_std = ctrl->value;
2831 retval = hci_set_fm_recv_conf(
2832 &radio->recv_conf,
2833 radio->fm_hdev);
2834 if (retval < 0)
2835 FMDERR("Error in rds_std");
Ankur Nandwanid928d542011-08-11 13:15:41 -07002836 break;
Ankur Nandwani8f972e52011-08-24 11:48:32 -07002837 case FM_TRANS:
2838 radio->trans_conf.rds_std = ctrl->value;
2839 retval = hci_set_fm_trans_conf(
2840 &radio->trans_conf,
2841 radio->fm_hdev);
2842 if (retval < 0)
2843 FMDERR("Error in rds_Std");
2844 break;
2845 default:
2846 retval = -EINVAL;
Ankur Nandwanid928d542011-08-11 13:15:41 -07002847 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002848 break;
2849 case V4L2_CID_PRIVATE_IRIS_RDSON:
Ankur Nandwani8f972e52011-08-24 11:48:32 -07002850 switch (radio->mode) {
2851 case FM_RECV:
2852 radio->recv_conf.rds_std = ctrl->value;
2853 retval = hci_set_fm_recv_conf(
2854 &radio->recv_conf,
2855 radio->fm_hdev);
2856 if (retval < 0)
2857 FMDERR("Error in rds_std");
2858 break;
2859 case FM_TRANS:
2860 radio->trans_conf.rds_std = ctrl->value;
2861 retval = hci_set_fm_trans_conf(
2862 &radio->trans_conf,
2863 radio->fm_hdev);
2864 if (retval < 0)
2865 FMDERR("Error in rds_Std");
2866 break;
2867 default:
2868 retval = -EINVAL;
2869 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002870 break;
2871 case V4L2_CID_PRIVATE_IRIS_RDSGROUP_MASK:
2872 radio->rds_grp.rds_grp_enable_mask = ctrl->value;
2873 retval = hci_fm_rds_grp(&radio->rds_grp, radio->fm_hdev);
2874 break;
2875 case V4L2_CID_PRIVATE_IRIS_RDSGROUP_PROC:
2876 rds_grps_proc = radio->g_rds_grp_proc_ps | ctrl->value;
Srinivasa Rao Uppala58273f82011-08-10 19:07:45 -07002877 radio->g_rds_grp_proc_ps = (rds_grps_proc >> RDS_CONFIG_OFFSET);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002878 retval = hci_fm_rds_grps_process(
Srinivasa Rao Uppala58273f82011-08-10 19:07:45 -07002879 &radio->g_rds_grp_proc_ps,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002880 radio->fm_hdev);
2881 break;
2882 case V4L2_CID_PRIVATE_IRIS_RDSD_BUF:
2883 radio->rds_grp.rds_buf_size = ctrl->value;
2884 break;
2885 case V4L2_CID_PRIVATE_IRIS_PSALL:
Srinivasa Rao Uppala58273f82011-08-10 19:07:45 -07002886 rds_grps_proc = (ctrl->value << RDS_CONFIG_OFFSET);
2887 radio->g_rds_grp_proc_ps |= rds_grps_proc;
2888 retval = hci_fm_rds_grps_process(
2889 &radio->g_rds_grp_proc_ps,
2890 radio->fm_hdev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002891 break;
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302892 case V4L2_CID_PRIVATE_IRIS_AF_JUMP:
2893 rds_grps_proc = (ctrl->value << RDS_AF_JUMP_OFFSET);
2894 radio->g_rds_grp_proc_ps |= rds_grps_proc;
2895 retval = hci_fm_rds_grps_process(
2896 &radio->g_rds_grp_proc_ps,
2897 radio->fm_hdev);
2898 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002899 case V4L2_CID_PRIVATE_IRIS_LP_MODE:
Srinivasa Rao Uppalaf856ae62011-10-17 18:43:26 +05302900 set_low_power_mode(radio, ctrl->value);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002901 break;
2902 case V4L2_CID_PRIVATE_IRIS_ANTENNA:
2903 temp_val = ctrl->value;
2904 retval = hci_fm_set_antenna(&temp_val, radio->fm_hdev);
2905 break;
2906 case V4L2_CID_RDS_TX_PTY:
Ankur Nandwanid928d542011-08-11 13:15:41 -07002907 radio->pty = ctrl->value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002908 break;
2909 case V4L2_CID_RDS_TX_PI:
Ankur Nandwanid928d542011-08-11 13:15:41 -07002910 radio->pi = ctrl->value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002911 break;
2912 case V4L2_CID_PRIVATE_IRIS_STOP_RDS_TX_PS_NAME:
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302913 tx_ps.ps_control = 0x00;
2914 retval = radio_hci_request(radio->fm_hdev, hci_trans_ps_req,
2915 (unsigned long)&tx_ps, RADIO_HCI_TIMEOUT);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002916 break;
2917 case V4L2_CID_PRIVATE_IRIS_STOP_RDS_TX_RT:
Srinivasa Rao Uppala3c7a8eb2011-09-18 09:10:21 +05302918 tx_rt.rt_control = 0x00;
2919 retval = radio_hci_request(radio->fm_hdev, hci_trans_rt_req,
2920 (unsigned long)&tx_rt, RADIO_HCI_TIMEOUT);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002921 break;
2922 case V4L2_CID_PRIVATE_IRIS_TX_SETPSREPEATCOUNT:
Ankur Nandwanid928d542011-08-11 13:15:41 -07002923 radio->ps_repeatcount = ctrl->value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002924 break;
2925 case V4L2_CID_TUNE_POWER_LEVEL:
2926 break;
Srinivasa Rao Uppalaabc8efa2011-08-02 14:31:30 -07002927 case V4L2_CID_PRIVATE_IRIS_SOFT_MUTE:
2928 radio->mute_mode.soft_mute = ctrl->value;
2929 retval = hci_set_fm_mute_mode(
2930 &radio->mute_mode,
2931 radio->fm_hdev);
2932 if (retval < 0)
2933 FMDERR("Error while setting FM soft mute"" %d\n",
2934 retval);
2935 break;
2936 case V4L2_CID_PRIVATE_IRIS_RIVA_ACCS_ADDR:
2937 radio->riva_data_req.cmd_params.start_addr = ctrl->value;
2938 break;
2939 case V4L2_CID_PRIVATE_IRIS_RIVA_ACCS_LEN:
2940 radio->riva_data_req.cmd_params.length = ctrl->value;
2941 break;
2942 case V4L2_CID_PRIVATE_IRIS_RIVA_POKE:
2943 memcpy(radio->riva_data_req.data, (void *)ctrl->value,
2944 radio->riva_data_req.cmd_params.length);
2945 radio->riva_data_req.cmd_params.subopcode = RIVA_POKE_OPCODE;
2946 retval = hci_poke_data(&radio->riva_data_req , radio->fm_hdev);
2947 break;
2948 case V4L2_CID_PRIVATE_IRIS_SSBI_ACCS_ADDR:
2949 radio->ssbi_data_accs.start_addr = ctrl->value;
2950 break;
2951 case V4L2_CID_PRIVATE_IRIS_SSBI_POKE:
2952 radio->ssbi_data_accs.data = ctrl->value;
2953 retval = hci_ssbi_poke_reg(&radio->ssbi_data_accs ,
2954 radio->fm_hdev);
2955 break;
2956 case V4L2_CID_PRIVATE_IRIS_RIVA_PEEK:
2957 radio->riva_data_req.cmd_params.subopcode = RIVA_PEEK_OPCODE;
2958 ctrl->value = hci_peek_data(&radio->riva_data_req.cmd_params ,
2959 radio->fm_hdev);
2960 break;
2961 case V4L2_CID_PRIVATE_IRIS_SSBI_PEEK:
2962 radio->ssbi_peek_reg.start_address = ctrl->value;
2963 hci_ssbi_peek_reg(&radio->ssbi_peek_reg, radio->fm_hdev);
2964 break;
Srinivasa Rao Uppala0f4098f2011-09-06 16:46:28 +05302965 case V4L2_CID_PRIVATE_IRIS_RDS_GRP_COUNTERS:
2966 temp_val = ctrl->value;
2967 hci_read_grp_counters(&temp_val, radio->fm_hdev);
2968 break;
2969 case V4L2_CID_PRIVATE_IRIS_HLSI:
2970 retval = hci_cmd(HCI_FM_GET_RECV_CONF_CMD,
2971 radio->fm_hdev);
2972 if (retval)
2973 break;
2974 radio->recv_conf.hlsi = ctrl->value;
2975 retval = hci_set_fm_recv_conf(
2976 &radio->recv_conf,
2977 radio->fm_hdev);
2978 break;
2979 case V4L2_CID_PRIVATE_IRIS_SET_NOTCH_FILTER:
2980 temp_val = ctrl->value;
2981 retval = hci_set_notch_filter(&temp_val, radio->fm_hdev);
2982 break;
Anantha Krishnan61dc15e2011-12-06 11:39:02 +05302983 case V4L2_CID_PRIVATE_IRIS_SRCH_ALGORITHM:
Srinivasa Rao Uppalade0b5d92011-12-27 18:09:10 +05302984 case V4L2_CID_PRIVATE_IRIS_SET_AUDIO_PATH:
Anantha Krishnan61dc15e2011-12-06 11:39:02 +05302985 /*
Srinivasa Rao Uppalade0b5d92011-12-27 18:09:10 +05302986 These private controls are place holders to keep the
Anantha Krishnan61dc15e2011-12-06 11:39:02 +05302987 driver compatible with changes done in the frameworks
2988 which are specific to TAVARUA.
2989 */
2990 retval = 0;
2991 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002992 default:
2993 retval = -EINVAL;
2994 }
2995 return retval;
2996}
2997
2998static int iris_vidioc_g_tuner(struct file *file, void *priv,
2999 struct v4l2_tuner *tuner)
3000{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003001 int retval;
Ankur Nandwanid928d542011-08-11 13:15:41 -07003002 struct iris_device *radio = video_get_drvdata(video_devdata(file));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003003
Srinivasa Rao Uppalad2ec4682011-12-12 14:02:15 +05303004 if (tuner->index > 0) {
3005 FMDERR("Invalid Tuner Index");
3006 return -EINVAL;
3007 }
Srinivasa Rao Uppalac5320c22011-11-28 14:28:51 +05303008 if (radio->mode == FM_RECV) {
3009 retval = hci_cmd(HCI_FM_GET_STATION_PARAM_CMD, radio->fm_hdev);
3010 if (retval < 0) {
3011 FMDERR("Failed to Get station params");
3012 return retval;
3013 }
3014 tuner->type = V4L2_TUNER_RADIO;
3015 tuner->rangelow =
3016 radio->recv_conf.band_low_limit * TUNE_PARAM;
3017 tuner->rangehigh =
3018 radio->recv_conf.band_high_limit * TUNE_PARAM;
3019 tuner->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
3020 tuner->capability = V4L2_TUNER_CAP_LOW;
3021 tuner->signal = radio->fm_st_rsp.station_rsp.rssi;
3022 tuner->audmode = radio->fm_st_rsp.station_rsp.stereo_prg;
3023 tuner->afc = 0;
3024 } else if (radio->mode == FM_TRANS) {
3025 retval = hci_cmd(HCI_FM_GET_TX_CONFIG, radio->fm_hdev);
3026 if (retval < 0) {
3027 FMDERR("get Tx config failed %d\n", retval);
3028 return retval;
3029 } else {
3030 tuner->type = V4L2_TUNER_RADIO;
3031 tuner->rangelow =
3032 radio->trans_conf.band_low_limit * TUNE_PARAM;
3033 tuner->rangehigh =
3034 radio->trans_conf.band_high_limit * TUNE_PARAM;
3035 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003036
Srinivasa Rao Uppalac5320c22011-11-28 14:28:51 +05303037 } else
3038 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003039 return 0;
3040}
3041
3042static int iris_vidioc_s_tuner(struct file *file, void *priv,
3043 struct v4l2_tuner *tuner)
3044{
3045 struct iris_device *radio = video_get_drvdata(video_devdata(file));
Ankur Nandwanid928d542011-08-11 13:15:41 -07003046 int retval = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003047 if (tuner->index > 0)
3048 return -EINVAL;
3049
Ankur Nandwanid928d542011-08-11 13:15:41 -07003050 if (radio->mode == FM_RECV) {
3051 radio->recv_conf.band_low_limit = tuner->rangelow / TUNE_PARAM;
3052 radio->recv_conf.band_high_limit =
3053 tuner->rangehigh / TUNE_PARAM;
3054 if (tuner->audmode == V4L2_TUNER_MODE_MONO) {
3055 radio->stereo_mode.stereo_mode = 0x01;
3056 retval = hci_set_fm_stereo_mode(
3057 &radio->stereo_mode,
3058 radio->fm_hdev);
3059 } else {
3060 radio->stereo_mode.stereo_mode = 0x00;
3061 retval = hci_set_fm_stereo_mode(
3062 &radio->stereo_mode,
3063 radio->fm_hdev);
3064 }
3065 if (retval < 0)
3066 FMDERR(": set tuner failed with %d\n", retval);
3067 return retval;
Srinivasa Rao Uppalac5320c22011-11-28 14:28:51 +05303068 } else if (radio->mode == FM_TRANS) {
Ankur Nandwanid928d542011-08-11 13:15:41 -07003069 radio->trans_conf.band_low_limit =
3070 tuner->rangelow / TUNE_PARAM;
3071 radio->trans_conf.band_high_limit =
3072 tuner->rangehigh / TUNE_PARAM;
Srinivasa Rao Uppalac5320c22011-11-28 14:28:51 +05303073 } else
3074 return -EINVAL;
Ankur Nandwanid928d542011-08-11 13:15:41 -07003075
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003076 return retval;
3077}
3078
3079static int iris_vidioc_g_frequency(struct file *file, void *priv,
3080 struct v4l2_frequency *freq)
3081{
3082 struct iris_device *radio = video_get_drvdata(video_devdata(file));
Srinivasa Rao Uppalad2ec4682011-12-12 14:02:15 +05303083 if ((freq != NULL) && (radio != NULL)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003084 freq->frequency =
3085 radio->fm_st_rsp.station_rsp.station_freq * TUNE_PARAM;
Srinivasa Rao Uppalad2ec4682011-12-12 14:02:15 +05303086 } else
3087 return -EINVAL;
3088 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003089}
3090
3091static int iris_vidioc_s_frequency(struct file *file, void *priv,
3092 struct v4l2_frequency *freq)
3093{
3094 struct iris_device *radio = video_get_drvdata(video_devdata(file));
3095 int retval = -1;
3096 freq->frequency = freq->frequency / TUNE_PARAM;
3097
3098 if (freq->type != V4L2_TUNER_RADIO)
3099 return -EINVAL;
3100
Ankur Nandwani8f972e52011-08-24 11:48:32 -07003101 /* We turn off RDS prior to tuning to a new station.
3102 because of a bug in SoC which prevents tuning
3103 during RDS transmission.
3104 */
3105 if (radio->mode == FM_TRANS
3106 && (radio->trans_conf.rds_std == 0 ||
3107 radio->trans_conf.rds_std == 1)) {
3108 radio->prev_trans_rds = radio->trans_conf.rds_std;
3109 radio->trans_conf.rds_std = 2;
3110 hci_set_fm_trans_conf(&radio->trans_conf,
3111 radio->fm_hdev);
3112 }
3113
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003114 retval = iris_set_freq(radio, freq->frequency);
Ankur Nandwani8f972e52011-08-24 11:48:32 -07003115
3116 if (radio->mode == FM_TRANS
3117 && radio->trans_conf.rds_std == 2
3118 && (radio->prev_trans_rds == 1
3119 || radio->prev_trans_rds == 0)) {
3120 radio->trans_conf.rds_std = radio->prev_trans_rds;
3121 hci_set_fm_trans_conf(&radio->trans_conf,
3122 radio->fm_hdev);
3123 }
3124
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003125 if (retval < 0)
3126 FMDERR(" set frequency failed with %d\n", retval);
3127 return retval;
3128}
3129
3130static int iris_vidioc_dqbuf(struct file *file, void *priv,
3131 struct v4l2_buffer *buffer)
3132{
3133 struct iris_device *radio = video_get_drvdata(video_devdata(file));
3134 enum iris_buf_t buf_type = buffer->index;
3135 struct kfifo *data_fifo;
3136 unsigned char *buf = (unsigned char *)buffer->m.userptr;
3137 unsigned int len = buffer->length;
3138 if (!access_ok(VERIFY_WRITE, buf, len))
3139 return -EFAULT;
3140 if ((buf_type < IRIS_BUF_MAX) && (buf_type >= 0)) {
3141 data_fifo = &radio->data_buf[buf_type];
3142 if (buf_type == IRIS_BUF_EVENTS)
3143 if (wait_event_interruptible(radio->event_queue,
3144 kfifo_len(data_fifo)) < 0)
3145 return -EINTR;
3146 } else {
3147 FMDERR("invalid buffer type\n");
3148 return -EINVAL;
3149 }
3150 buffer->bytesused = kfifo_out_locked(data_fifo, buf, len,
3151 &radio->buf_lock[buf_type]);
3152
3153 return 0;
3154}
3155
3156static int iris_vidioc_g_fmt_type_private(struct file *file, void *priv,
3157 struct v4l2_format *f)
3158{
3159 return 0;
3160
3161}
3162
3163static int iris_vidioc_s_hw_freq_seek(struct file *file, void *priv,
3164 struct v4l2_hw_freq_seek *seek)
3165{
3166 struct iris_device *radio = video_get_drvdata(video_devdata(file));
3167 int dir;
3168 if (seek->seek_upward)
3169 dir = SRCH_DIR_UP;
3170 else
3171 dir = SRCH_DIR_DOWN;
3172 return iris_search(radio, CTRL_ON, dir);
3173}
3174
3175static int iris_vidioc_querycap(struct file *file, void *priv,
3176 struct v4l2_capability *capability)
3177{
3178 struct iris_device *radio;
3179 radio = video_get_drvdata(video_devdata(file));
3180 strlcpy(capability->driver, DRIVER_NAME, sizeof(capability->driver));
3181 strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card));
3182 radio->g_cap = capability;
3183 return 0;
3184}
3185
3186
3187static const struct v4l2_ioctl_ops iris_ioctl_ops = {
3188 .vidioc_querycap = iris_vidioc_querycap,
3189 .vidioc_queryctrl = iris_vidioc_queryctrl,
3190 .vidioc_g_ctrl = iris_vidioc_g_ctrl,
3191 .vidioc_s_ctrl = iris_vidioc_s_ctrl,
3192 .vidioc_g_tuner = iris_vidioc_g_tuner,
3193 .vidioc_s_tuner = iris_vidioc_s_tuner,
3194 .vidioc_g_frequency = iris_vidioc_g_frequency,
3195 .vidioc_s_frequency = iris_vidioc_s_frequency,
3196 .vidioc_s_hw_freq_seek = iris_vidioc_s_hw_freq_seek,
3197 .vidioc_dqbuf = iris_vidioc_dqbuf,
3198 .vidioc_g_fmt_type_private = iris_vidioc_g_fmt_type_private,
3199 .vidioc_s_ext_ctrls = iris_vidioc_s_ext_ctrls,
Venkateshwarlu Domakonda787af692011-10-14 21:23:03 +05303200 .vidioc_g_ext_ctrls = iris_vidioc_g_ext_ctrls,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003201};
3202
3203static const struct v4l2_file_operations iris_fops = {
3204 .owner = THIS_MODULE,
3205 .unlocked_ioctl = video_ioctl2,
3206};
3207
3208static struct video_device iris_viddev_template = {
3209 .fops = &iris_fops,
3210 .ioctl_ops = &iris_ioctl_ops,
3211 .name = DRIVER_NAME,
3212 .release = video_device_release,
3213};
3214
3215static struct video_device *video_get_dev(void)
3216{
3217 return priv_videodev;
3218}
3219
3220static int __init iris_probe(struct platform_device *pdev)
3221{
3222 struct iris_device *radio;
3223 int retval;
3224 int radio_nr = -1;
3225 int i;
3226
3227 if (!pdev) {
3228 FMDERR(": pdev is null\n");
3229 return -ENOMEM;
3230 }
3231
3232 radio = kzalloc(sizeof(struct iris_device), GFP_KERNEL);
3233 if (!radio) {
3234 FMDERR(": Could not allocate radio device\n");
3235 return -ENOMEM;
3236 }
3237
3238 radio->dev = &pdev->dev;
3239 platform_set_drvdata(pdev, radio);
3240
3241 radio->videodev = video_device_alloc();
3242 if (!radio->videodev) {
3243 FMDERR(": Could not allocate V4L device\n");
3244 kfree(radio);
3245 return -ENOMEM;
3246 }
3247
3248 memcpy(radio->videodev, &iris_viddev_template,
3249 sizeof(iris_viddev_template));
3250
3251 for (i = 0; i < IRIS_BUF_MAX; i++) {
3252 int kfifo_alloc_rc = 0;
3253 spin_lock_init(&radio->buf_lock[i]);
3254
Srinivasa Rao Uppala6cc0e322011-08-12 10:54:48 -07003255 if ((i == IRIS_BUF_RAW_RDS) || (i == IRIS_BUF_PEEK))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003256 kfifo_alloc_rc = kfifo_alloc(&radio->data_buf[i],
3257 rds_buf*3, GFP_KERNEL);
Venkateshwarlu Domakonda3a0b75d2011-11-23 17:03:27 +05303258 else if (i == IRIS_BUF_CAL_DATA)
3259 kfifo_alloc_rc = kfifo_alloc(&radio->data_buf[i],
3260 STD_BUF_SIZE*2, GFP_KERNEL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003261 else
3262 kfifo_alloc_rc = kfifo_alloc(&radio->data_buf[i],
3263 STD_BUF_SIZE, GFP_KERNEL);
3264
3265 if (kfifo_alloc_rc != 0) {
3266 FMDERR("failed allocating buffers %d\n",
3267 kfifo_alloc_rc);
3268 for (; i > -1; i--) {
3269 kfifo_free(&radio->data_buf[i]);
3270 kfree(radio);
3271 return -ENOMEM;
3272 }
3273 }
3274 }
3275
3276 mutex_init(&radio->lock);
3277 init_completion(&radio->sync_xfr_start);
3278 radio->tune_req = 0;
Ankur Nandwani8f972e52011-08-24 11:48:32 -07003279 radio->prev_trans_rds = 2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003280 init_waitqueue_head(&radio->event_queue);
3281 init_waitqueue_head(&radio->read_queue);
3282
3283 video_set_drvdata(radio->videodev, radio);
3284
3285 if (NULL == video_get_drvdata(radio->videodev))
3286 FMDERR(": video_get_drvdata failed\n");
3287
3288 retval = video_register_device(radio->videodev, VFL_TYPE_RADIO,
3289 radio_nr);
3290 if (retval) {
3291 FMDERR(": Could not register video device\n");
3292 video_device_release(radio->videodev);
3293 for (; i > -1; i--)
3294 kfifo_free(&radio->data_buf[i]);
3295 kfree(radio);
3296 return retval;
3297 } else {
3298 priv_videodev = kzalloc(sizeof(struct video_device),
3299 GFP_KERNEL);
3300 memcpy(priv_videodev, radio->videodev,
3301 sizeof(struct video_device));
3302 }
3303 return 0;
3304}
3305
3306
3307static int __devexit iris_remove(struct platform_device *pdev)
3308{
3309 int i;
3310 struct iris_device *radio = platform_get_drvdata(pdev);
3311
3312 video_unregister_device(radio->videodev);
3313
3314 for (i = 0; i < IRIS_BUF_MAX; i++)
3315 kfifo_free(&radio->data_buf[i]);
3316
3317 kfree(radio);
3318
3319 platform_set_drvdata(pdev, NULL);
3320
3321 return 0;
3322}
3323
3324static struct platform_driver iris_driver = {
3325 .driver = {
3326 .owner = THIS_MODULE,
3327 .name = "iris_fm",
3328 },
3329 .remove = __devexit_p(iris_remove),
3330};
3331
3332static int __init iris_radio_init(void)
3333{
3334 return platform_driver_probe(&iris_driver, iris_probe);
3335}
3336module_init(iris_radio_init);
3337
3338static void __exit iris_radio_exit(void)
3339{
3340 platform_driver_unregister(&iris_driver);
3341}
3342module_exit(iris_radio_exit);
3343
3344MODULE_LICENSE("GPL v2");
3345MODULE_AUTHOR(DRIVER_AUTHOR);
3346MODULE_DESCRIPTION(DRIVER_DESC);