blob: 22888b0f2ca6df3aa8401f96afe9f00340b3cbfb [file] [log] [blame]
Jeremy Gebben1c143462015-10-29 13:04:12 -06001/*
2 *
3 * Copyright (c) 2011-2016 The Linux Foundation. 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_IRIS_H
28#define __RADIO_IRIS_H
29
30#include <uapi/media/radio-iris.h>
31
32#include <linux/skbuff.h>
33#include <linux/interrupt.h>
34#include <linux/mutex.h>
35#include <linux/atomic.h>
36
37struct radio_hci_dev {
38 char name[8];
39 unsigned long flags;
40 __u16 id;
41 __u8 bus;
42 __u8 dev_type;
43 __u8 dev_name[248];
44 __u8 dev_class[3];
45 __u8 features[8];
46 __u8 commands[64];
47
48 unsigned int data_block_len;
49 unsigned long cmd_last_tx;
50
51 struct sk_buff *sent_cmd;
52
53 __u32 req_status;
54 __u32 req_result;
55 atomic_t cmd_cnt;
56
57 struct tasklet_struct cmd_task;
58 struct tasklet_struct rx_task;
59 struct tasklet_struct tx_task;
60
61 struct sk_buff_head rx_q;
62 struct sk_buff_head raw_q;
63 struct sk_buff_head cmd_q;
64
65 struct mutex req_lock;
66 wait_queue_head_t req_wait_q;
67
68 int (*open)(struct radio_hci_dev *hdev);
69 int (*close)(struct radio_hci_dev *hdev);
70 int (*flush)(struct radio_hci_dev *hdev);
71 int (*send)(struct sk_buff *skb);
72 void (*destruct)(struct radio_hci_dev *hdev);
73 void (*notify)(struct radio_hci_dev *hdev, unsigned int evt);
74 void (*close_smd)(void);
75};
76
77int radio_hci_register_dev(struct radio_hci_dev *hdev);
78int radio_hci_unregister_dev(struct radio_hci_dev *hdev);
79int radio_hci_recv_frame(struct sk_buff *skb);
80int radio_hci_send_cmd(struct radio_hci_dev *hdev, __u16 opcode, __u32 plen,
81 void *param);
82void radio_hci_event_packet(struct radio_hci_dev *hdev, struct sk_buff *skb);
83
84#define hci_req_lock(d) mutex_lock(&d->req_lock)
85#define hci_req_unlock(d) mutex_unlock(&d->req_lock)
86
87#undef FMDBG
88#ifdef FM_DEBUG
89#define FMDBG(fmt, args...) pr_info("iris_radio: " fmt, ##args)
90#else
91#define FMDBG(fmt, args...)
92#endif
93
94#undef FMDERR
95#define FMDERR(fmt, args...) pr_err("iris_radio: " fmt, ##args)
96
97/* HCI timeouts */
98#define RADIO_HCI_TIMEOUT (10000) /* 10 seconds */
99
100int hci_def_data_read(struct hci_fm_def_data_rd_req *arg,
101 struct radio_hci_dev *hdev);
102int hci_def_data_write(struct hci_fm_def_data_wr_req *arg,
103 struct radio_hci_dev *hdev);
104int hci_fm_do_calibration(__u8 *arg, struct radio_hci_dev *hdev);
105int hci_fm_do_calibration(__u8 *arg, struct radio_hci_dev *hdev);
106
107static inline int is_valid_tone(int tone)
108{
109 if ((tone >= MIN_TX_TONE_VAL) &&
110 (tone <= MAX_TX_TONE_VAL))
111 return 1;
112 else
113 return 0;
114}
115
116static inline int is_valid_hard_mute(int hard_mute)
117{
118 if ((hard_mute >= MIN_HARD_MUTE_VAL) &&
119 (hard_mute <= MAX_HARD_MUTE_VAL))
120 return 1;
121 else
122 return 0;
123}
124
125static inline int is_valid_srch_mode(int srch_mode)
126{
127 if ((srch_mode >= MIN_SRCH_MODE) &&
128 (srch_mode <= MAX_SRCH_MODE))
129 return 1;
130 else
131 return 0;
132}
133
134static inline int is_valid_scan_dwell_prd(int scan_dwell_prd)
135{
136 if ((scan_dwell_prd >= MIN_SCAN_DWELL) &&
137 (scan_dwell_prd <= MAX_SCAN_DWELL))
138 return 1;
139 else
140 return 0;
141}
142
143static inline int is_valid_sig_th(int sig_th)
144{
145 if ((sig_th >= MIN_SIG_TH) &&
146 (sig_th <= MAX_SIG_TH))
147 return 1;
148 else
149 return 0;
150}
151
152static inline int is_valid_pty(int pty)
153{
154 if ((pty >= MIN_PTY) &&
155 (pty <= MAX_PTY))
156 return 1;
157 else
158 return 0;
159}
160
161static inline int is_valid_pi(int pi)
162{
163 if ((pi >= MIN_PI) &&
164 (pi <= MAX_PI))
165 return 1;
166 else
167 return 0;
168}
169
170static inline int is_valid_srch_station_cnt(int cnt)
171{
172 if ((cnt >= MIN_SRCH_STATIONS_CNT) &&
173 (cnt <= MAX_SRCH_STATIONS_CNT))
174 return 1;
175 else
176 return 0;
177}
178
179static inline int is_valid_chan_spacing(int spacing)
180{
181 if ((spacing >= MIN_CHAN_SPACING) &&
182 (spacing <= MAX_CHAN_SPACING))
183 return 1;
184 else
185 return 0;
186}
187
188static inline int is_valid_emphasis(int emphasis)
189{
190 if ((emphasis >= MIN_EMPHASIS) &&
191 (emphasis <= MAX_EMPHASIS))
192 return 1;
193 else
194 return 0;
195}
196
197static inline int is_valid_rds_std(int rds_std)
198{
199 if ((rds_std >= MIN_RDS_STD) &&
200 (rds_std <= MAX_RDS_STD))
201 return 1;
202 else
203 return 0;
204}
205
206static inline int is_valid_antenna(int antenna_type)
207{
208 if ((antenna_type >= MIN_ANTENNA_VAL) &&
209 (antenna_type <= MAX_ANTENNA_VAL))
210 return 1;
211 else
212 return 0;
213}
214
215static inline int is_valid_ps_repeat_cnt(int cnt)
216{
217 if ((cnt >= MIN_TX_PS_REPEAT_CNT) &&
218 (cnt <= MAX_TX_PS_REPEAT_CNT))
219 return 1;
220 else
221 return 0;
222}
223
224static inline int is_valid_soft_mute(int soft_mute)
225{
226 if ((soft_mute >= MIN_SOFT_MUTE) &&
227 (soft_mute <= MAX_SOFT_MUTE))
228 return 1;
229 else
230 return 0;
231}
232
233static inline int is_valid_peek_len(int len)
234{
235 if ((len >= MIN_PEEK_ACCESS_LEN) &&
236 (len <= MAX_PEEK_ACCESS_LEN))
237 return 1;
238 else
239 return 0;
240}
241
242static inline int is_valid_reset_cntr(int cntr)
243{
244 if ((cntr >= MIN_RESET_CNTR) &&
245 (cntr <= MAX_RESET_CNTR))
246 return 1;
247 else
248 return 0;
249}
250
251static inline int is_valid_hlsi(int hlsi)
252{
253 if ((hlsi >= MIN_HLSI) &&
254 (hlsi <= MAX_HLSI))
255 return 1;
256 else
257 return 0;
258}
259
260static inline int is_valid_notch_filter(int filter)
261{
262 if ((filter >= MIN_NOTCH_FILTER) &&
263 (filter <= MAX_NOTCH_FILTER))
264 return 1;
265 else
266 return 0;
267}
268
269static inline int is_valid_intf_det_low_th(int th)
270{
271 if ((th >= MIN_INTF_DET_OUT_LW_TH) &&
272 (th <= MAX_INTF_DET_OUT_LW_TH))
273 return 1;
274 else
275 return 0;
276}
277
278static inline int is_valid_intf_det_hgh_th(int th)
279{
280 if ((th >= MIN_INTF_DET_OUT_HG_TH) &&
281 (th <= MAX_INTF_DET_OUT_HG_TH))
282 return 1;
283 else
284 return 0;
285}
286
287static inline int is_valid_sinr_th(int th)
288{
289 if ((th >= MIN_SINR_TH) &&
290 (th <= MAX_SINR_TH))
291 return 1;
292 else
293 return 0;
294}
295
296static inline int is_valid_sinr_samples(int samples_cnt)
297{
298 if ((samples_cnt >= MIN_SINR_SAMPLES) &&
299 (samples_cnt <= MAX_SINR_SAMPLES))
300 return 1;
301 else
302 return 0;
303}
304
305static inline int is_valid_fm_state(int state)
306{
307 if ((state >= 0) && (state < FM_MAX_NO_STATES))
308 return 1;
309 else
310 return 0;
311}
312
313static inline int is_valid_blend_value(int val)
314{
315 if ((val >= MIN_BLEND_HI) && (val <= MAX_BLEND_HI))
316 return 1;
317 else
318 return 0;
319}
320
321#endif
322