blob: 5499754c92f4546607e4bd35237247ccc65e1d75 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/*
2 *
3 * Copyright (c) 2011 Code Aurora Forum. All rights reserved.
4 *
5 * This file is based on include/net/bluetooth/hci_core.h
6 *
7 * Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation;
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
16 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
17 * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 *
22 * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
23 * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
24 * SOFTWARE IS DISCLAIMED.
25 */
26
27#ifndef __RADIO_HCI_CORE_H
28#define __RADIO_HCI_CORE_H
29
30#include <linux/skbuff.h>
31#include <linux/interrupt.h>
32#include <linux/mutex.h>
33#include <linux/atomic.h>
34
35/* ---- HCI Packet structures ---- */
36#define RADIO_HCI_COMMAND_HDR_SIZE sizeof(struct radio_hci_command_hdr)
37#define RADIO_HCI_EVENT_HDR_SIZE sizeof(struct radio_hci_event_hdr)
38
39/* HCI data types */
40#define RADIO_HCI_COMMAND_PKT 0x11
41#define RADIO_HCI_EVENT_PKT 0x14
42
43/* HCI timeouts */
44#define RADIO_HCI_TIMEOUT (10000) /* 10 seconds */
45
46#define TUNE_PARAM 16
47struct radio_hci_command_hdr {
48 __le16 opcode; /* OCF & OGF */
49 __u8 plen;
50} __packed;
51
52struct radio_hci_event_hdr {
53 __u8 evt;
54 __u8 plen;
55} __packed;
56
57struct radio_hci_dev {
58 char name[8];
59 unsigned long flags;
60 __u16 id;
61 __u8 bus;
62 __u8 dev_type;
63 __u8 dev_name[248];
64 __u8 dev_class[3];
65 __u8 features[8];
66 __u8 commands[64];
67
68 unsigned int data_block_len;
69 unsigned long cmd_last_tx;
70
71 struct sk_buff *sent_cmd;
72
73 __u32 req_status;
74 __u32 req_result;
75 atomic_t cmd_cnt;
76
77 struct tasklet_struct cmd_task;
78 struct tasklet_struct rx_task;
79 struct tasklet_struct tx_task;
80
81 struct sk_buff_head rx_q;
82 struct sk_buff_head raw_q;
83 struct sk_buff_head cmd_q;
84
85 struct mutex req_lock;
86 wait_queue_head_t req_wait_q;
87
88 int (*open)(struct radio_hci_dev *hdev);
89 int (*close)(struct radio_hci_dev *hdev);
90 int (*flush)(struct radio_hci_dev *hdev);
91 int (*send)(struct sk_buff *skb);
92 void (*destruct)(struct radio_hci_dev *hdev);
93 void (*notify)(struct radio_hci_dev *hdev, unsigned int evt);
94};
95
96int radio_hci_register_dev(struct radio_hci_dev *hdev);
97int radio_hci_unregister_dev(struct radio_hci_dev *hdev);
98int radio_hci_recv_frame(struct sk_buff *skb);
99int radio_hci_send_cmd(struct radio_hci_dev *hdev, __u16 opcode, __u32 plen,
100 void *param);
101void radio_hci_event_packet(struct radio_hci_dev *hdev, struct sk_buff *skb);
102
103/* Opcode OCF */
104/* HCI recv control commands opcode */
105#define HCI_OCF_FM_ENABLE_RECV_REQ 0x0001
106#define HCI_OCF_FM_DISABLE_RECV_REQ 0x0002
107#define HCI_OCF_FM_GET_RECV_CONF_REQ 0x0003
108#define HCI_OCF_FM_SET_RECV_CONF_REQ 0x0004
109#define HCI_OCF_FM_SET_MUTE_MODE_REQ 0x0005
110#define HCI_OCF_FM_SET_STEREO_MODE_REQ 0x0006
111#define HCI_OCF_FM_SET_ANTENNA 0x0007
112#define HCI_OCF_FM_SET_SIGNAL_THRESHOLD 0x0008
113#define HCI_OCF_FM_GET_SIGNAL_THRESHOLD 0x0009
114#define HCI_OCF_FM_GET_STATION_PARAM_REQ 0x000A
115#define HCI_OCF_FM_GET_PROGRAM_SERVICE_REQ 0x000B
116#define HCI_OCF_FM_GET_RADIO_TEXT_REQ 0x000C
117#define HCI_OCF_FM_GET_AF_LIST_REQ 0x000D
118#define HCI_OCF_FM_SEARCH_STATIONS 0x000E
119#define HCI_OCF_FM_SEARCH_RDS_STATIONS 0x000F
120#define HCI_OCF_FM_SEARCH_STATIONS_LIST 0x0010
121#define HCI_OCF_FM_CANCEL_SEARCH 0x0011
122#define HCI_OCF_FM_RDS_GRP 0x0012
123#define HCI_OCF_FM_RDS_GRP_PROCESS 0x0013
124#define HCI_OCF_FM_EN_WAN_AVD_CTRL 0x0014
125#define HCI_OCF_FM_EN_NOTCH_CTRL 0x0015
126
127/* HCI common control commands opcode */
128#define HCI_OCF_FM_TUNE_STATION_REQ 0x0001
129#define HCI_OCF_FM_DEFAULT_DATA_READ 0x0002
130#define HCI_OCF_FM_DEFAULT_DATA_WRITE 0x0003
131#define HCI_OCF_FM_RESET 0x0004
132#define HCI_OCF_FM_GET_FEATURE_LIST 0x0005
133#define HCI_OCF_FM_DO_CALIBRATION 0x0006
134
135/*HCI Status parameters commands*/
136#define HCI_OCF_FM_READ_GRP_COUNTERS 0x0001
137
138/*HCI Diagnostic commands*/
139#define HCI_OCF_FM_PEEK_DATA 0x0002
140#define HCI_OCF_FM_POKE_DATA 0x0003
141#define HCI_OCF_FM_SSBI_PEEK_REG 0x0004
142#define HCI_OCF_FM_SSBI_POKE_REG 0x0005
143#define HCI_OCF_FM_STATION_DBG_PARAM 0x0007
144
145/* Opcode OGF */
146#define HCI_OGF_FM_RECV_CTRL_CMD_REQ 0x0013
147#define HCI_OGF_FM_COMMON_CTRL_CMD_REQ 0x0015
148#define HCI_OGF_FM_STATUS_PARAMETERS_CMD_REQ 0x0016
149#define HCI_OGF_FM_TEST_CMD_REQ 0x0017
150#define HCI_OGF_FM_DIAGNOSTIC_CMD_REQ 0x003F
151
152/* Command opcode pack/unpack */
153#define hci_opcode_pack(ogf, ocf) (__u16) ((ocf & 0x03ff)|(ogf << 10))
154#define hci_opcode_ogf(op) (op >> 10)
155#define hci_opcode_ocf(op) (op & 0x03ff)
156#define hci_recv_ctrl_cmd_op_pack(ocf) \
157 (__u16) hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, ocf)
158#define hci_common_cmd_op_pack(ocf) \
159 (__u16) hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ, ocf)
160#define hci_status_param_op_pack(ocf) \
161 (__u16) hci_opcode_pack(HCI_OGF_FM_STATUS_PARAMETERS_CMD_REQ, ocf)
162#define hci_diagnostic_cmd_op_pack(ocf) \
163 (__u16) hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ, ocf)
164
165
166/* HCI commands with no arguments*/
167#define HCI_FM_ENABLE_RECV_CMD 1
168#define HCI_FM_DISABLE_RECV_CMD 2
169#define HCI_FM_GET_RECV_CONF_CMD 3
170#define HCI_FM_GET_STATION_PARAM_CMD 4
171#define HCI_FM_GET_SIGNAL_TH_CMD 5
172#define HCI_FM_GET_PROGRAM_SERVICE_CMD 6
173#define HCI_FM_GET_RADIO_TEXT_CMD 7
174#define HCI_FM_GET_AF_LIST_CMD 8
175#define HCI_FM_CANCEL_SEARCH_CMD 9
176#define HCI_FM_RESET_CMD 10
177#define HCI_FM_GET_FEATURES_CMD 11
178#define HCI_FM_STATION_DBG_PARAM_CMD 12
179
180/* ----- HCI Command request ----- */
181struct hci_fm_recv_conf_req {
182 __u8 emphasis;
183 __u8 ch_spacing;
184 __u8 rds_std;
185 __u8 hlsi;
186 __u32 band_low_limit;
187 __u32 band_high_limit;
188} __packed;
189
190struct hci_fm_mute_mode_req {
191 __u8 hard_mute;
192 __u8 soft_mute;
193} __packed;
194
195struct hci_fm_stereo_mode_req {
196 __u8 stereo_mode;
197 __u8 sig_blend;
198 __u8 intf_blend;
199 __u8 most_switch;
200} __packed;
201
202struct hci_fm_search_station_req {
203 __u8 srch_mode;
204 __u8 scan_time;
205 __u8 srch_dir;
206} __packed;
207
208struct hci_fm_search_rds_station_req {
209 struct hci_fm_search_station_req srch_station;
210 __u8 srch_pty;
211 __u16 srch_pi;
212} __packed;
213
214struct hci_fm_search_station_list_req {
215 __u8 srch_list_mode;
216 __u8 srch_list_dir;
217 __u32 srch_list_max;
218 __u8 srch_pty;
219} __packed;
220
221struct hci_fm_rds_grp_req {
222 __u32 rds_grp_enable_mask;
223 __u32 rds_buf_size;
224 __u8 en_rds_change_filter;
225} __packed;
226
227struct hci_fm_en_avd_ctrl_req {
228 __u8 no_freqs;
229 __u8 freq_index;
230 __u8 lo_shft;
231 __u16 freq_min;
232 __u16 freq_max;
233} __packed;
234
235struct hci_fm_def_data_rd_req {
236 __u8 mode;
237 __u8 length;
238} __packed;
239
240struct hci_fm_def_data_wr_req {
241 struct hci_fm_def_data_rd_req data_rd;
242 __u8 data[256];
243} __packed;
244
245struct hci_fm_peek_req {
246 __u32 start_addr;
247 __u8 length;
248} __packed;
249
250struct hci_fm_poke_req {
251 struct hci_fm_peek_req peek_req;
252 __u8 data[256];
253} __packed;
254
255struct hci_fm_ssbi_req {
256 __u16 start_addr;
257 __u8 data;
258} __packed;
259
260/*HCI events*/
261#define HCI_EV_TUNE_STATUS 0x01
262#define HCI_EV_RDS_LOCK_STATUS 0x02
263#define HCI_EV_STEREO_STATUS 0x03
264#define HCI_EV_SERVICE_AVAILABLE 0x04
265#define HCI_EV_SEARCH_PROGRESS 0x05
266#define HCI_EV_SEARCH_RDS_PROGRESS 0x06
267#define HCI_EV_SEARCH_LIST_PROGRESS 0x07
268#define HCI_EV_RDS_RX_DATA 0x08
269#define HCI_EV_PROGRAM_SERVICE 0x09
270#define HCI_EV_RADIO_TEXT 0x0A
271#define HCI_EV_FM_AF_LIST 0x0B
272#define HCI_EV_TX_RDS_GRP_AVBLE 0x0C
273#define HCI_EV_TX_RDS_GRP_COMPL 0x0D
274#define HCI_EV_TX_RDS_CONT_GRP_COMPL 0x0E
275#define HCI_EV_CMD_COMPLETE 0x0F
276#define HCI_EV_CMD_STATUS 0x10
277#define HCI_EV_TUNE_COMPLETE 0x11
278#define HCI_EV_SEARCH_COMPLETE 0x12
279#define HCI_EV_SEARCH_RDS_COMPLETE 0x13
280#define HCI_EV_SEARCH_LIST_COMPLETE 0x14
281
282#define HCI_REQ_DONE 0
283#define HCI_REQ_PEND 1
284#define HCI_REQ_CANCELED 2
285#define HCI_REQ_STATUS 3
286
287struct hci_ev_tune_status {
288 __u8 sub_event;
289 __le32 station_freq;
290 __u8 serv_avble;
291 __u8 rssi;
292 __u8 stereo_prg;
293 __u8 rds_sync_status;
294 __u8 mute_mode;
295} __packed;
296
297struct hci_ev_rds_rx_data {
298 __u8 num_rds_grps;
299 __u8 rds_grp_data[12];
300} __packed;
301
302struct hci_ev_prg_service {
303 __le16 pi_prg_id;
304 __u8 pty_prg_type;
305 __u8 ta_prg_code_type;
306 __u8 ta_ann_code_flag;
307 __u8 ms_switch_code_flag;
308 __u8 dec_id_ctrl_code_flag;
309 __u8 ps_num;
310 __u8 prg_service_name[119];
311} __packed;
312
313struct hci_ev_radio_text {
314 __le16 pi_prg_id;
315 __u8 pty_prg_type;
316 __u8 ta_prg_code_type;
317 __u8 txt_ab_flag;
318 __u8 radio_txt[64];
319} __packed;
320
321struct hci_ev_af_list {
322 __le32 tune_freq;
323 __le16 pi_code;
324 __u8 af_size;
325 __u8 af_list[25];
326} __packed;
327
328struct hci_ev_cmd_complete {
329 __u8 num_hci_cmd_pkts;
330 __le16 cmd_opcode;
331} __packed;
332
333struct hci_ev_cmd_status {
334 __u8 status;
335 __u8 num_hci_cmd_pkts;
336 __le16 status_opcode;
337} __packed;
338
339struct hci_ev_srch_st {
340 __le32 station_freq;
341 __u8 rds_cap;
342 __u8 pty;
343 __le16 status_opcode;
344} __packed;
345
346struct hci_ev_srch_list_compl {
347 __u8 status;
348 __u8 num_stations_found;
349 struct hci_ev_srch_st srch_st[20];
350} __packed;
351
352/* ----- HCI Event Response ----- */
353struct hci_fm_conf_rsp {
354 __u8 status;
355 struct hci_fm_recv_conf_req recv_conf_rsp;
356} __packed;
357
358struct hci_fm_sig_threshold_rsp {
359 __u8 status;
360 __u8 sig_threshold;
361} __packed;
362
363struct hci_fm_station_rsp {
364 struct hci_ev_tune_status station_rsp;
365} __packed;
366
367struct hci_fm_prgm_srv_rsp {
368 __u8 status;
369 struct hci_ev_prg_service prg_srv;
370} __packed;
371
372struct hci_fm_radio_txt_rsp {
373 __u8 status;
374 struct hci_ev_radio_text rd_txt;
375} __packed;
376
377struct hci_fm_af_list_rsp {
378 __u8 status;
379 struct hci_ev_af_list rd_txt;
380} __packed;
381
382struct hci_fm_data_rd_rsp {
383 __u8 status;
384 __u8 ret_data_len;
385 __u8 data[256];
386} __packed;
387
388struct hci_fm_feature_list_rsp {
389 __u8 status;
390 __u8 feature_mask;
391} __packed;
392
393struct hci_fm_dbg_param_rsp {
394 __u8 status;
395 __u8 blend;
396 __u8 soft_mute;
397 __u8 inf_blend;
398 __u8 inf_soft_mute;
399 __u8 pilot_pil;
400 __u8 io_verc;
401 __u8 in_det_out;
402} __packed;
403
404/* HCI dev events */
405#define RADIO_HCI_DEV_REG 1
406#define RADIO_HCI_DEV_WRITE 2
407
408#define hci_req_lock(d) mutex_lock(&d->req_lock)
409#define hci_req_unlock(d) mutex_unlock(&d->req_lock)
410
Ankur Nandwani78a782b2011-07-07 21:11:21 -0700411/* FM RDS */
412#define RDS_PTYPE 0
413#define RDS_PID_LOWER 2
414#define RDS_PID_HIGHER 3
415#define RDS_OFFSET 5
416#define RDS_PS_LENGTH_OFFSET 7
417#define RDS_STRING 8
418#define RDS_PS_DATA_OFFSET 8
419
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700420/*FM states*/
421
422enum radio_state_t {
423 FM_OFF,
424 FM_RECV,
425 FM_TRANS,
426 FM_RESET,
427};
428
429enum v4l2_cid_private_iris_t {
430 V4L2_CID_PRIVATE_IRIS_SRCHMODE = (0x08000000 + 1),
431 V4L2_CID_PRIVATE_IRIS_SCANDWELL,
432 V4L2_CID_PRIVATE_IRIS_SRCHON,
433 V4L2_CID_PRIVATE_IRIS_STATE,
434 V4L2_CID_PRIVATE_IRIS_TRANSMIT_MODE,
435 V4L2_CID_PRIVATE_IRIS_RDSGROUP_MASK,
436 V4L2_CID_PRIVATE_IRIS_REGION,
437 V4L2_CID_PRIVATE_IRIS_SIGNAL_TH,
438 V4L2_CID_PRIVATE_IRIS_SRCH_PTY,
439 V4L2_CID_PRIVATE_IRIS_SRCH_PI,
440 V4L2_CID_PRIVATE_IRIS_SRCH_CNT,
441 V4L2_CID_PRIVATE_IRIS_EMPHASIS,
442 V4L2_CID_PRIVATE_IRIS_RDS_STD,
443 V4L2_CID_PRIVATE_IRIS_SPACING,
444 V4L2_CID_PRIVATE_IRIS_RDSON,
445 V4L2_CID_PRIVATE_IRIS_RDSGROUP_PROC,
446 V4L2_CID_PRIVATE_IRIS_LP_MODE,
447 V4L2_CID_PRIVATE_IRIS_ANTENNA,
448 V4L2_CID_PRIVATE_IRIS_RDSD_BUF,
449 V4L2_CID_PRIVATE_IRIS_PSALL,
450 /*v4l2 Tx controls*/
451 V4L2_CID_PRIVATE_IRIS_TX_SETPSREPEATCOUNT,
452 V4L2_CID_PRIVATE_IRIS_STOP_RDS_TX_PS_NAME,
453 V4L2_CID_PRIVATE_IRIS_STOP_RDS_TX_RT,
454 V4L2_CID_PRIVATE_IRIS_IOVERC,
455 V4L2_CID_PRIVATE_IRIS_INTDET,
456};
457
458enum iris_evt_t {
459 IRIS_EVT_RADIO_READY,
460 IRIS_EVT_TUNE_SUCC,
461 IRIS_EVT_SEEK_COMPLETE,
462 IRIS_EVT_SCAN_NEXT,
463 IRIS_EVT_NEW_RAW_RDS,
464 IRIS_EVT_NEW_RT_RDS,
465 IRIS_EVT_NEW_PS_RDS,
466 IRIS_EVT_ERROR,
467 IRIS_EVT_BELOW_TH,
468 IRIS_EVT_ABOVE_TH,
469 IRIS_EVT_STEREO,
470 IRIS_EVT_MONO,
471 IRIS_EVT_RDS_AVAIL,
472 IRIS_EVT_RDS_NOT_AVAIL,
473 IRIS_EVT_NEW_SRCH_LIST,
474 IRIS_EVT_NEW_AF_LIST,
475 IRIS_EVT_TXRDSDAT,
476 IRIS_EVT_TXRDSDONE
477};
478
479enum iris_region_t {
480 IRIS_REGION_US,
481 IRIS_REGION_EU,
482 IRIS_REGION_JAPAN,
483 IRIS_REGION_JAPAN_WIDE,
484 IRIS_REGION_OTHER
485};
486
487#define STD_BUF_SIZE (64)
488
489enum iris_buf_t {
490 IRIS_BUF_SRCH_LIST,
491 IRIS_BUF_EVENTS,
492 IRIS_BUF_RT_RDS,
493 IRIS_BUF_PS_RDS,
494 IRIS_BUF_RAW_RDS,
495 IRIS_BUF_AF_LIST,
496 IRIS_BUF_MAX
497};
498
499enum iris_xfr_t {
500 IRIS_XFR_SYNC,
501 IRIS_XFR_ERROR,
502 IRIS_XFR_SRCH_LIST,
503 IRIS_XFR_RT_RDS,
504 IRIS_XFR_PS_RDS,
505 IRIS_XFR_AF_LIST,
506 IRIS_XFR_MAX
507};
508
509#undef FMDBG
510#ifdef FM_DEBUG
511#define FMDBG(fmt, args...) pr_info("iris_radio: " fmt, ##args)
512#else
513#define FMDBG(fmt, args...)
514#endif
515
516#undef FMDERR
517#define FMDERR(fmt, args...) pr_err("iris_radio: " fmt, ##args)
518
519/* Search options */
520enum search_t {
521 SEEK,
522 SCAN,
523 SCAN_FOR_STRONG,
524 SCAN_FOR_WEAK,
525 RDS_SEEK_PTY,
526 RDS_SCAN_PTY,
527 RDS_SEEK_PI,
528 RDS_AF_JUMP,
529};
530
531#define SRCH_MODE 0x07
532#define SRCH_DIR 0x08 /* 0-up 1-down */
533#define SCAN_DWELL 0x70
534#define SRCH_ON 0x80
535
536/* I/O Control */
537#define IOC_HRD_MUTE 0x03
538#define IOC_SFT_MUTE 0x01
539#define IOC_MON_STR 0x01
540#define IOC_SIG_BLND 0x01
541#define IOC_INTF_BLND 0x01
542#define IOC_ANTENNA 0x01
543
544/* RDS Control */
545#define RDS_ON 0x01
546#define RDS_BUF_SZ 100
547
548/* Search direction */
549#define SRCH_DIR_UP (0)
550#define SRCH_DIR_DOWN (1)
551
552/* control options */
553#define CTRL_ON (1)
554#define CTRL_OFF (0)
555
556int hci_def_data_read(struct hci_fm_def_data_rd_req *arg,
557 struct radio_hci_dev *hdev);
558int hci_def_data_write(struct hci_fm_def_data_wr_req *arg,
559 struct radio_hci_dev *hdev);
560int hci_fm_do_calibration(__u8 *arg, struct radio_hci_dev *hdev);
561int hci_fm_do_calibration(__u8 *arg, struct radio_hci_dev *hdev);
562int hci_peek_data(struct hci_fm_peek_req *arg, struct radio_hci_dev *hdev);
563int hci_poke_data(struct hci_fm_poke_req *arg, struct radio_hci_dev *hdev);
564int hci_poke_data(struct hci_fm_poke_req *arg, struct radio_hci_dev *hdev);
565int hci_poke_data(struct hci_fm_poke_req *arg, struct radio_hci_dev *hdev);
566
567#endif /* __RADIO_HCI_CORE_H */