Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011, Code Aurora Forum. All rights reserved |
| 2 | * |
| 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 | |
| 40 | static unsigned int rds_buf = 100; |
| 41 | module_param(rds_buf, uint, 0); |
| 42 | MODULE_PARM_DESC(rds_buf, "RDS buffer entries: *100*"); |
| 43 | |
| 44 | static void radio_hci_cmd_task(unsigned long arg); |
| 45 | static void radio_hci_rx_task(unsigned long arg); |
| 46 | static struct video_device *video_get_dev(void); |
| 47 | static DEFINE_RWLOCK(hci_task_lock); |
| 48 | |
| 49 | struct 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 Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 58 | unsigned int mode; |
| 59 | |
| 60 | __u16 pi; |
| 61 | __u8 pty; |
| 62 | __u8 ps_repeatcount; |
Ankur Nandwani | 8f972e5 | 2011-08-24 11:48:32 -0700 | [diff] [blame] | 63 | __u8 prev_trans_rds; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 64 | |
| 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 Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 84 | struct hci_fm_trans_conf_req_struct trans_conf; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 85 | struct hci_fm_rds_grp_req rds_grp; |
| 86 | unsigned char g_search_mode; |
Srinivasa Rao Uppala | f856ae6 | 2011-10-17 18:43:26 +0530 | [diff] [blame] | 87 | unsigned char power_mode; |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 88 | int search_on; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 89 | unsigned int tone_freq; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 90 | unsigned char g_scan_time; |
| 91 | unsigned int g_antenna; |
| 92 | unsigned int g_rds_grp_proc_ps; |
Srinivasa Rao Uppala | f856ae6 | 2011-10-17 18:43:26 +0530 | [diff] [blame] | 93 | unsigned char event_mask; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 94 | 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 Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 97 | 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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | static struct video_device *priv_videodev; |
Srinivasa Rao Uppala | cb48ee6 | 2011-10-25 09:57:06 +0530 | [diff] [blame] | 103 | static int iris_do_calibration(struct iris_device *radio); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 104 | |
| 105 | static 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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 300 | { |
| 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 Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 321 | { |
| 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 Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 332 | .minimum = 0x3180000, |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 333 | .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 Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 353 | .minimum = 0x3180000, |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 354 | .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 Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 360 | .minimum = 0x280, |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 361 | .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 Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 384 | { |
| 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 Domakonda | 787af69 | 2011-10-14 21:23:03 +0530 | [diff] [blame] | 398 | { |
| 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 Uppala | cb48ee6 | 2011-10-25 09:57:06 +0530 | [diff] [blame] | 408 | { |
| 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 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 422 | }; |
| 423 | |
| 424 | static void iris_q_event(struct iris_device *radio, |
| 425 | enum iris_evt_t event) |
| 426 | { |
| 427 | struct kfifo *data_b = &radio->data_buf[IRIS_BUF_EVENTS]; |
| 428 | unsigned char evt = event; |
| 429 | if (kfifo_in_locked(data_b, &evt, 1, &radio->buf_lock[IRIS_BUF_EVENTS])) |
| 430 | wake_up_interruptible(&radio->event_queue); |
| 431 | } |
| 432 | |
| 433 | static int hci_send_frame(struct sk_buff *skb) |
| 434 | { |
| 435 | struct radio_hci_dev *hdev = (struct radio_hci_dev *) skb->dev; |
| 436 | |
| 437 | if (!hdev) { |
| 438 | kfree_skb(skb); |
| 439 | return -ENODEV; |
| 440 | } |
| 441 | |
| 442 | __net_timestamp(skb); |
| 443 | |
| 444 | skb_orphan(skb); |
| 445 | return hdev->send(skb); |
| 446 | } |
| 447 | |
| 448 | static void radio_hci_cmd_task(unsigned long arg) |
| 449 | { |
| 450 | struct radio_hci_dev *hdev = (struct radio_hci_dev *) arg; |
| 451 | struct sk_buff *skb; |
| 452 | if (!(atomic_read(&hdev->cmd_cnt)) |
| 453 | && time_after(jiffies, hdev->cmd_last_tx + HZ)) { |
| 454 | FMDERR("%s command tx timeout", hdev->name); |
| 455 | atomic_set(&hdev->cmd_cnt, 1); |
| 456 | } |
| 457 | |
| 458 | skb = skb_dequeue(&hdev->cmd_q); |
| 459 | if (atomic_read(&hdev->cmd_cnt) && skb) { |
| 460 | kfree_skb(hdev->sent_cmd); |
| 461 | hdev->sent_cmd = skb_clone(skb, GFP_ATOMIC); |
| 462 | if (hdev->sent_cmd) { |
| 463 | atomic_dec(&hdev->cmd_cnt); |
| 464 | hci_send_frame(skb); |
| 465 | hdev->cmd_last_tx = jiffies; |
| 466 | } else { |
| 467 | skb_queue_head(&hdev->cmd_q, skb); |
| 468 | tasklet_schedule(&hdev->cmd_task); |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | } |
| 473 | |
| 474 | static void radio_hci_rx_task(unsigned long arg) |
| 475 | { |
| 476 | struct radio_hci_dev *hdev = (struct radio_hci_dev *) arg; |
| 477 | struct sk_buff *skb; |
| 478 | |
| 479 | read_lock(&hci_task_lock); |
| 480 | |
| 481 | skb = skb_dequeue(&hdev->rx_q); |
| 482 | radio_hci_event_packet(hdev, skb); |
| 483 | |
| 484 | read_unlock(&hci_task_lock); |
| 485 | } |
| 486 | |
| 487 | int radio_hci_register_dev(struct radio_hci_dev *hdev) |
| 488 | { |
| 489 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 490 | if (!radio) { |
| 491 | FMDERR(":radio is null"); |
| 492 | return -EINVAL; |
| 493 | } |
| 494 | |
| 495 | if (!hdev) { |
| 496 | FMDERR("hdev is null"); |
| 497 | return -EINVAL; |
| 498 | } |
| 499 | |
| 500 | hdev->flags = 0; |
| 501 | |
| 502 | tasklet_init(&hdev->cmd_task, radio_hci_cmd_task, (unsigned long) |
| 503 | hdev); |
| 504 | tasklet_init(&hdev->rx_task, radio_hci_rx_task, (unsigned long) |
| 505 | hdev); |
| 506 | |
| 507 | init_waitqueue_head(&hdev->req_wait_q); |
| 508 | |
| 509 | skb_queue_head_init(&hdev->rx_q); |
| 510 | skb_queue_head_init(&hdev->cmd_q); |
| 511 | skb_queue_head_init(&hdev->raw_q); |
| 512 | |
| 513 | if (!radio) |
| 514 | FMDERR(":radio is null"); |
| 515 | |
| 516 | radio->fm_hdev = hdev; |
| 517 | |
| 518 | return 0; |
| 519 | } |
| 520 | EXPORT_SYMBOL(radio_hci_register_dev); |
| 521 | |
| 522 | int radio_hci_unregister_dev(struct radio_hci_dev *hdev) |
| 523 | { |
| 524 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 525 | if (!radio) { |
| 526 | FMDERR(":radio is null"); |
| 527 | return -EINVAL; |
| 528 | } |
| 529 | |
| 530 | tasklet_kill(&hdev->rx_task); |
| 531 | tasklet_kill(&hdev->cmd_task); |
| 532 | skb_queue_purge(&hdev->rx_q); |
| 533 | skb_queue_purge(&hdev->cmd_q); |
| 534 | skb_queue_purge(&hdev->raw_q); |
| 535 | kfree(radio->fm_hdev); |
| 536 | kfree(radio->videodev); |
| 537 | |
| 538 | return 0; |
| 539 | } |
| 540 | EXPORT_SYMBOL(radio_hci_unregister_dev); |
| 541 | |
| 542 | int radio_hci_recv_frame(struct sk_buff *skb) |
| 543 | { |
| 544 | struct radio_hci_dev *hdev = (struct radio_hci_dev *) skb->dev; |
| 545 | if (!hdev) { |
| 546 | FMDERR("%s hdev is null while receiving frame", hdev->name); |
| 547 | kfree_skb(skb); |
| 548 | return -ENXIO; |
| 549 | } |
| 550 | |
| 551 | __net_timestamp(skb); |
| 552 | |
| 553 | radio_hci_event_packet(hdev, skb); |
Srinivasa Rao Uppala | cf3a811 | 2011-09-22 21:02:02 +0530 | [diff] [blame] | 554 | kfree_skb(skb); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 555 | return 0; |
| 556 | } |
| 557 | EXPORT_SYMBOL(radio_hci_recv_frame); |
| 558 | |
| 559 | int radio_hci_send_cmd(struct radio_hci_dev *hdev, __u16 opcode, __u32 plen, |
| 560 | void *param) |
| 561 | { |
| 562 | int len = RADIO_HCI_COMMAND_HDR_SIZE + plen; |
| 563 | struct radio_hci_command_hdr *hdr; |
| 564 | struct sk_buff *skb; |
| 565 | int ret = 0; |
| 566 | |
| 567 | skb = alloc_skb(len, GFP_ATOMIC); |
| 568 | if (!skb) { |
| 569 | FMDERR("%s no memory for command", hdev->name); |
| 570 | return -ENOMEM; |
| 571 | } |
| 572 | |
| 573 | hdr = (struct radio_hci_command_hdr *) skb_put(skb, |
| 574 | RADIO_HCI_COMMAND_HDR_SIZE); |
| 575 | hdr->opcode = cpu_to_le16(opcode); |
| 576 | hdr->plen = plen; |
| 577 | |
| 578 | if (plen) |
| 579 | memcpy(skb_put(skb, plen), param, plen); |
| 580 | |
| 581 | skb->dev = (void *) hdev; |
| 582 | |
| 583 | ret = hci_send_frame(skb); |
| 584 | |
| 585 | return ret; |
| 586 | } |
| 587 | EXPORT_SYMBOL(radio_hci_send_cmd); |
| 588 | |
| 589 | static int hci_fm_enable_recv_req(struct radio_hci_dev *hdev, |
| 590 | unsigned long param) |
| 591 | { |
| 592 | __u16 opcode = 0; |
| 593 | |
| 594 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 595 | HCI_OCF_FM_ENABLE_RECV_REQ); |
| 596 | return radio_hci_send_cmd(hdev, opcode, 0, NULL); |
| 597 | } |
| 598 | |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 599 | static int hci_fm_tone_generator(struct radio_hci_dev *hdev, |
| 600 | unsigned long param) |
| 601 | { |
| 602 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 603 | __u16 opcode = 0; |
| 604 | |
| 605 | opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ, |
| 606 | HCI_FM_SET_INTERNAL_TONE_GENRATOR); |
| 607 | return radio_hci_send_cmd(hdev, opcode, |
| 608 | sizeof(radio->tone_freq), &radio->tone_freq); |
| 609 | } |
| 610 | |
| 611 | static int hci_fm_enable_trans_req(struct radio_hci_dev *hdev, |
| 612 | unsigned long param) |
| 613 | { |
| 614 | __u16 opcode = 0; |
| 615 | |
| 616 | opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ, |
| 617 | HCI_OCF_FM_ENABLE_TRANS_REQ); |
| 618 | return radio_hci_send_cmd(hdev, opcode, 0, NULL); |
| 619 | } |
| 620 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 621 | static int hci_fm_disable_recv_req(struct radio_hci_dev *hdev, |
| 622 | unsigned long param) |
| 623 | { |
| 624 | __u16 opcode = 0; |
| 625 | |
| 626 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 627 | HCI_OCF_FM_DISABLE_RECV_REQ); |
| 628 | return radio_hci_send_cmd(hdev, opcode, 0, NULL); |
| 629 | } |
| 630 | |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 631 | static int hci_fm_disable_trans_req(struct radio_hci_dev *hdev, |
| 632 | unsigned long param) |
| 633 | { |
| 634 | __u16 opcode = 0; |
| 635 | |
| 636 | opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ, |
| 637 | HCI_OCF_FM_DISABLE_TRANS_REQ); |
| 638 | return radio_hci_send_cmd(hdev, opcode, 0, NULL); |
| 639 | } |
| 640 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 641 | static int hci_get_fm_recv_conf_req(struct radio_hci_dev *hdev, |
| 642 | unsigned long param) |
| 643 | { |
| 644 | __u16 opcode = 0; |
| 645 | |
| 646 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 647 | HCI_OCF_FM_GET_RECV_CONF_REQ); |
| 648 | return radio_hci_send_cmd(hdev, opcode, 0, NULL); |
| 649 | } |
| 650 | |
| 651 | static int hci_set_fm_recv_conf_req(struct radio_hci_dev *hdev, |
| 652 | unsigned long param) |
| 653 | { |
| 654 | __u16 opcode = 0; |
| 655 | |
| 656 | struct hci_fm_recv_conf_req *recv_conf_req = |
| 657 | (struct hci_fm_recv_conf_req *) param; |
| 658 | |
| 659 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 660 | HCI_OCF_FM_SET_RECV_CONF_REQ); |
| 661 | return radio_hci_send_cmd(hdev, opcode, sizeof((*recv_conf_req)), |
| 662 | recv_conf_req); |
| 663 | } |
| 664 | |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 665 | static int hci_set_fm_trans_conf_req(struct radio_hci_dev *hdev, |
| 666 | unsigned long param) |
| 667 | { |
| 668 | __u16 opcode = 0; |
| 669 | |
| 670 | struct hci_fm_trans_conf_req_struct *trans_conf_req = |
| 671 | (struct hci_fm_trans_conf_req_struct *) param; |
| 672 | |
| 673 | opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ, |
| 674 | HCI_OCF_FM_SET_TRANS_CONF_REQ); |
| 675 | return radio_hci_send_cmd(hdev, opcode, sizeof((*trans_conf_req)), |
| 676 | trans_conf_req); |
| 677 | } |
| 678 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 679 | static int hci_fm_get_station_param_req(struct radio_hci_dev *hdev, |
| 680 | unsigned long param) |
| 681 | { |
| 682 | __u16 opcode = 0; |
| 683 | |
| 684 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 685 | HCI_OCF_FM_GET_STATION_PARAM_REQ); |
| 686 | return radio_hci_send_cmd(hdev, opcode, 0, NULL); |
| 687 | } |
| 688 | |
| 689 | static int hci_set_fm_mute_mode_req(struct radio_hci_dev *hdev, |
| 690 | unsigned long param) |
| 691 | { |
| 692 | __u16 opcode = 0; |
| 693 | struct hci_fm_mute_mode_req *mute_mode_req = |
| 694 | (struct hci_fm_mute_mode_req *) param; |
| 695 | |
| 696 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 697 | HCI_OCF_FM_SET_MUTE_MODE_REQ); |
| 698 | return radio_hci_send_cmd(hdev, opcode, sizeof((*mute_mode_req)), |
| 699 | mute_mode_req); |
| 700 | } |
| 701 | |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 702 | |
| 703 | static int hci_trans_ps_req(struct radio_hci_dev *hdev, |
| 704 | unsigned long param) |
| 705 | { |
| 706 | __u16 opcode = 0; |
| 707 | struct hci_fm_tx_ps *tx_ps_req = |
| 708 | (struct hci_fm_tx_ps *) param; |
| 709 | |
| 710 | opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ, |
| 711 | HCI_OCF_FM_RDS_PS_REQ); |
| 712 | |
| 713 | return radio_hci_send_cmd(hdev, opcode, sizeof((*tx_ps_req)), |
| 714 | tx_ps_req); |
| 715 | } |
| 716 | |
| 717 | static int hci_trans_rt_req(struct radio_hci_dev *hdev, |
| 718 | unsigned long param) |
| 719 | { |
| 720 | __u16 opcode = 0; |
| 721 | struct hci_fm_tx_rt *tx_rt_req = |
| 722 | (struct hci_fm_tx_rt *) param; |
| 723 | |
| 724 | opcode = hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ, |
| 725 | HCI_OCF_FM_RDS_RT_REQ); |
| 726 | |
| 727 | return radio_hci_send_cmd(hdev, opcode, sizeof((*tx_rt_req)), |
| 728 | tx_rt_req); |
| 729 | } |
| 730 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 731 | static int hci_set_fm_stereo_mode_req(struct radio_hci_dev *hdev, |
| 732 | unsigned long param) |
| 733 | { |
| 734 | __u16 opcode = 0; |
| 735 | struct hci_fm_stereo_mode_req *stereo_mode_req = |
| 736 | (struct hci_fm_stereo_mode_req *) param; |
| 737 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 738 | HCI_OCF_FM_SET_STEREO_MODE_REQ); |
| 739 | return radio_hci_send_cmd(hdev, opcode, sizeof((*stereo_mode_req)), |
| 740 | stereo_mode_req); |
| 741 | } |
| 742 | |
| 743 | static int hci_fm_set_antenna_req(struct radio_hci_dev *hdev, |
| 744 | unsigned long param) |
| 745 | { |
| 746 | __u16 opcode = 0; |
| 747 | |
| 748 | __u8 antenna = param; |
| 749 | |
| 750 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 751 | HCI_OCF_FM_SET_ANTENNA); |
| 752 | return radio_hci_send_cmd(hdev, opcode, sizeof(antenna), &antenna); |
| 753 | } |
| 754 | |
| 755 | static int hci_fm_set_sig_threshold_req(struct radio_hci_dev *hdev, |
| 756 | unsigned long param) |
| 757 | { |
| 758 | __u16 opcode = 0; |
| 759 | |
| 760 | __u8 sig_threshold = param; |
| 761 | |
Venkateshwarlu Domakonda | 1c67b75 | 2011-10-17 13:05:48 +0530 | [diff] [blame] | 762 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 763 | HCI_OCF_FM_SET_SIGNAL_THRESHOLD); |
| 764 | return radio_hci_send_cmd(hdev, opcode, sizeof(sig_threshold), |
| 765 | &sig_threshold); |
| 766 | } |
| 767 | |
Srinivasa Rao Uppala | f856ae6 | 2011-10-17 18:43:26 +0530 | [diff] [blame] | 768 | static int hci_fm_set_event_mask(struct radio_hci_dev *hdev, |
| 769 | unsigned long param) |
| 770 | { |
| 771 | u16 opcode = 0; |
| 772 | u8 event_mask = param; |
| 773 | |
| 774 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 775 | HCI_OCF_FM_SET_EVENT_MASK); |
| 776 | return radio_hci_send_cmd(hdev, opcode, sizeof(event_mask), |
| 777 | &event_mask); |
| 778 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 779 | static int hci_fm_get_sig_threshold_req(struct radio_hci_dev *hdev, |
| 780 | unsigned long param) |
| 781 | { |
| 782 | __u16 opcode = 0; |
| 783 | |
Venkateshwarlu Domakonda | 1c67b75 | 2011-10-17 13:05:48 +0530 | [diff] [blame] | 784 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 785 | HCI_OCF_FM_GET_SIGNAL_THRESHOLD); |
| 786 | return radio_hci_send_cmd(hdev, opcode, 0, NULL); |
| 787 | } |
| 788 | |
| 789 | static int hci_fm_get_program_service_req(struct radio_hci_dev *hdev, |
| 790 | unsigned long param) |
| 791 | { |
| 792 | __u16 opcode = 0; |
| 793 | |
Venkateshwarlu Domakonda | 1c67b75 | 2011-10-17 13:05:48 +0530 | [diff] [blame] | 794 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 795 | HCI_OCF_FM_GET_PROGRAM_SERVICE_REQ); |
| 796 | return radio_hci_send_cmd(hdev, opcode, 0, NULL); |
| 797 | } |
| 798 | |
| 799 | static int hci_fm_get_radio_text_req(struct radio_hci_dev *hdev, |
| 800 | unsigned long param) |
| 801 | { |
| 802 | __u16 opcode = 0; |
| 803 | |
Venkateshwarlu Domakonda | 1c67b75 | 2011-10-17 13:05:48 +0530 | [diff] [blame] | 804 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 805 | HCI_OCF_FM_GET_RADIO_TEXT_REQ); |
| 806 | return radio_hci_send_cmd(hdev, opcode, 0, NULL); |
| 807 | } |
| 808 | |
| 809 | static int hci_fm_get_af_list_req(struct radio_hci_dev *hdev, |
| 810 | unsigned long param) |
| 811 | { |
| 812 | __u16 opcode = 0; |
| 813 | |
Venkateshwarlu Domakonda | 1c67b75 | 2011-10-17 13:05:48 +0530 | [diff] [blame] | 814 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 815 | HCI_OCF_FM_GET_AF_LIST_REQ); |
| 816 | return radio_hci_send_cmd(hdev, opcode, 0, NULL); |
| 817 | } |
| 818 | |
| 819 | static int hci_fm_search_stations_req(struct radio_hci_dev *hdev, |
| 820 | unsigned long param) |
| 821 | { |
| 822 | __u16 opcode = 0; |
| 823 | struct hci_fm_search_station_req *srch_stations = |
| 824 | (struct hci_fm_search_station_req *) param; |
| 825 | |
| 826 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 827 | HCI_OCF_FM_SEARCH_STATIONS); |
| 828 | return radio_hci_send_cmd(hdev, opcode, sizeof((*srch_stations)), |
| 829 | srch_stations); |
| 830 | } |
| 831 | |
| 832 | static int hci_fm_srch_rds_stations_req(struct radio_hci_dev *hdev, |
| 833 | unsigned long param) |
| 834 | { |
| 835 | __u16 opcode = 0; |
| 836 | struct hci_fm_search_rds_station_req *srch_stations = |
| 837 | (struct hci_fm_search_rds_station_req *) param; |
| 838 | |
| 839 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 840 | HCI_OCF_FM_SEARCH_RDS_STATIONS); |
| 841 | return radio_hci_send_cmd(hdev, opcode, sizeof((*srch_stations)), |
| 842 | srch_stations); |
| 843 | } |
| 844 | |
| 845 | static int hci_fm_srch_station_list_req(struct radio_hci_dev *hdev, |
| 846 | unsigned long param) |
| 847 | { |
| 848 | __u16 opcode = 0; |
| 849 | struct hci_fm_search_station_list_req *srch_list = |
| 850 | (struct hci_fm_search_station_list_req *) param; |
| 851 | |
| 852 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 853 | HCI_OCF_FM_SEARCH_STATIONS_LIST); |
| 854 | return radio_hci_send_cmd(hdev, opcode, sizeof((*srch_list)), |
| 855 | srch_list); |
| 856 | } |
| 857 | |
| 858 | static int hci_fm_cancel_search_req(struct radio_hci_dev *hdev, |
| 859 | unsigned long param) |
| 860 | { |
| 861 | __u16 opcode = 0; |
| 862 | |
| 863 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 864 | HCI_OCF_FM_CANCEL_SEARCH); |
| 865 | return radio_hci_send_cmd(hdev, opcode, 0, NULL); |
| 866 | } |
| 867 | |
| 868 | static int hci_fm_rds_grp_process_req(struct radio_hci_dev *hdev, |
| 869 | unsigned long param) |
| 870 | { |
| 871 | __u16 opcode = 0; |
| 872 | |
| 873 | __u32 fm_grps_process = param; |
| 874 | |
| 875 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 876 | HCI_OCF_FM_RDS_GRP_PROCESS); |
| 877 | return radio_hci_send_cmd(hdev, opcode, sizeof(fm_grps_process), |
| 878 | &fm_grps_process); |
| 879 | } |
| 880 | |
| 881 | static int hci_fm_tune_station_req(struct radio_hci_dev *hdev, |
| 882 | unsigned long param) |
| 883 | { |
| 884 | __u16 opcode = 0; |
| 885 | |
| 886 | __u32 tune_freq = param; |
| 887 | |
| 888 | opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ, |
| 889 | HCI_OCF_FM_TUNE_STATION_REQ); |
| 890 | return radio_hci_send_cmd(hdev, opcode, sizeof(tune_freq), &tune_freq); |
| 891 | } |
| 892 | |
| 893 | static int hci_def_data_read_req(struct radio_hci_dev *hdev, |
| 894 | unsigned long param) |
| 895 | { |
| 896 | __u16 opcode = 0; |
| 897 | struct hci_fm_def_data_rd_req *def_data_rd = |
| 898 | (struct hci_fm_def_data_rd_req *) param; |
| 899 | |
Venkateshwarlu Domakonda | 787af69 | 2011-10-14 21:23:03 +0530 | [diff] [blame] | 900 | opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 901 | HCI_OCF_FM_DEFAULT_DATA_READ); |
| 902 | return radio_hci_send_cmd(hdev, opcode, sizeof((*def_data_rd)), |
| 903 | def_data_rd); |
| 904 | } |
| 905 | |
| 906 | static int hci_def_data_write_req(struct radio_hci_dev *hdev, |
| 907 | unsigned long param) |
| 908 | { |
| 909 | __u16 opcode = 0; |
| 910 | struct hci_fm_def_data_wr_req *def_data_wr = |
| 911 | (struct hci_fm_def_data_wr_req *) param; |
| 912 | |
Venkateshwarlu Domakonda | 787af69 | 2011-10-14 21:23:03 +0530 | [diff] [blame] | 913 | opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 914 | HCI_OCF_FM_DEFAULT_DATA_WRITE); |
| 915 | return radio_hci_send_cmd(hdev, opcode, sizeof((*def_data_wr)), |
| 916 | def_data_wr); |
| 917 | } |
| 918 | |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 919 | static int hci_set_notch_filter_req(struct radio_hci_dev *hdev, |
| 920 | unsigned long param) |
| 921 | { |
| 922 | __u16 opcode = 0; |
| 923 | __u8 notch_filter_val = param; |
| 924 | |
| 925 | opcode = hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, |
| 926 | HCI_OCF_FM_EN_NOTCH_CTRL); |
| 927 | return radio_hci_send_cmd(hdev, opcode, sizeof(notch_filter_val), |
| 928 | ¬ch_filter_val); |
| 929 | } |
| 930 | |
| 931 | |
| 932 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 933 | static int hci_fm_reset_req(struct radio_hci_dev *hdev, unsigned long param) |
| 934 | { |
| 935 | __u16 opcode = 0; |
| 936 | |
| 937 | opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ, |
| 938 | HCI_OCF_FM_RESET); |
| 939 | return radio_hci_send_cmd(hdev, opcode, 0, NULL); |
| 940 | } |
| 941 | |
| 942 | static int hci_fm_get_feature_lists_req(struct radio_hci_dev *hdev, |
| 943 | unsigned long param) |
| 944 | { |
| 945 | __u16 opcode = 0; |
| 946 | |
| 947 | opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ, |
| 948 | HCI_OCF_FM_GET_FEATURE_LIST); |
| 949 | return radio_hci_send_cmd(hdev, opcode, 0, NULL); |
| 950 | } |
| 951 | |
| 952 | static int hci_fm_do_calibration_req(struct radio_hci_dev *hdev, |
| 953 | unsigned long param) |
| 954 | { |
| 955 | __u16 opcode = 0; |
| 956 | |
| 957 | __u8 mode = param; |
| 958 | |
| 959 | opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ, |
| 960 | HCI_OCF_FM_DO_CALIBRATION); |
| 961 | return radio_hci_send_cmd(hdev, opcode, sizeof(mode), &mode); |
| 962 | } |
| 963 | |
| 964 | static int hci_read_grp_counters_req(struct radio_hci_dev *hdev, |
| 965 | unsigned long param) |
| 966 | { |
| 967 | __u16 opcode = 0; |
| 968 | |
| 969 | __u8 reset_counters = param; |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 970 | opcode = hci_opcode_pack(HCI_OGF_FM_STATUS_PARAMETERS_CMD_REQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 971 | HCI_OCF_FM_READ_GRP_COUNTERS); |
| 972 | return radio_hci_send_cmd(hdev, opcode, sizeof(reset_counters), |
| 973 | &reset_counters); |
| 974 | } |
| 975 | |
| 976 | static int hci_peek_data_req(struct radio_hci_dev *hdev, unsigned long param) |
| 977 | { |
| 978 | __u16 opcode = 0; |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 979 | struct hci_fm_riva_data *peek_data = (struct hci_fm_riva_data *)param; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 980 | |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 981 | opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 982 | HCI_OCF_FM_PEEK_DATA); |
| 983 | return radio_hci_send_cmd(hdev, opcode, sizeof((*peek_data)), |
| 984 | peek_data); |
| 985 | } |
| 986 | |
| 987 | static int hci_poke_data_req(struct radio_hci_dev *hdev, unsigned long param) |
| 988 | { |
| 989 | __u16 opcode = 0; |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 990 | struct hci_fm_riva_poke *poke_data = (struct hci_fm_riva_poke *) param; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 991 | |
Srinivasa Rao Uppala | 6cc0e32 | 2011-08-12 10:54:48 -0700 | [diff] [blame] | 992 | opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 993 | HCI_OCF_FM_POKE_DATA); |
| 994 | return radio_hci_send_cmd(hdev, opcode, sizeof((*poke_data)), |
| 995 | poke_data); |
| 996 | } |
| 997 | |
| 998 | static int hci_ssbi_peek_reg_req(struct radio_hci_dev *hdev, |
| 999 | unsigned long param) |
| 1000 | { |
| 1001 | __u16 opcode = 0; |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1002 | struct hci_fm_ssbi_peek *ssbi_peek = (struct hci_fm_ssbi_peek *) param; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1003 | |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1004 | opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1005 | HCI_OCF_FM_SSBI_PEEK_REG); |
| 1006 | return radio_hci_send_cmd(hdev, opcode, sizeof((*ssbi_peek)), |
| 1007 | ssbi_peek); |
| 1008 | } |
| 1009 | |
| 1010 | static int hci_ssbi_poke_reg_req(struct radio_hci_dev *hdev, |
| 1011 | unsigned long param) |
| 1012 | { |
| 1013 | __u16 opcode = 0; |
| 1014 | struct hci_fm_ssbi_req *ssbi_poke = (struct hci_fm_ssbi_req *) param; |
| 1015 | |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1016 | opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1017 | HCI_OCF_FM_SSBI_POKE_REG); |
| 1018 | return radio_hci_send_cmd(hdev, opcode, sizeof((*ssbi_poke)), |
| 1019 | ssbi_poke); |
| 1020 | } |
| 1021 | |
| 1022 | static int hci_fm_get_station_dbg_param_req(struct radio_hci_dev *hdev, |
| 1023 | unsigned long param) |
| 1024 | { |
| 1025 | __u16 opcode = 0; |
| 1026 | |
Venkateshwarlu Domakonda | 1c67b75 | 2011-10-17 13:05:48 +0530 | [diff] [blame] | 1027 | opcode = hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1028 | HCI_OCF_FM_STATION_DBG_PARAM); |
| 1029 | return radio_hci_send_cmd(hdev, opcode, 0, NULL); |
| 1030 | } |
| 1031 | |
| 1032 | static int radio_hci_err(__u16 code) |
| 1033 | { |
| 1034 | switch (code) { |
| 1035 | case 0: |
| 1036 | return 0; |
| 1037 | case 0x01: |
| 1038 | return -EBADRQC; |
| 1039 | case 0x02: |
| 1040 | return -ENOTCONN; |
| 1041 | case 0x03: |
| 1042 | return -EIO; |
| 1043 | case 0x07: |
| 1044 | return -ENOMEM; |
| 1045 | case 0x0c: |
| 1046 | return -EBUSY; |
| 1047 | case 0x11: |
| 1048 | return -EOPNOTSUPP; |
| 1049 | case 0x12: |
| 1050 | return -EINVAL; |
| 1051 | default: |
| 1052 | return -ENOSYS; |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | static int __radio_hci_request(struct radio_hci_dev *hdev, |
| 1057 | int (*req)(struct radio_hci_dev *hdev, |
| 1058 | unsigned long param), |
| 1059 | unsigned long param, __u32 timeout) |
| 1060 | { |
| 1061 | int err = 0; |
| 1062 | |
| 1063 | DECLARE_WAITQUEUE(wait, current); |
| 1064 | |
| 1065 | hdev->req_status = HCI_REQ_PEND; |
| 1066 | |
| 1067 | add_wait_queue(&hdev->req_wait_q, &wait); |
| 1068 | set_current_state(TASK_INTERRUPTIBLE); |
| 1069 | |
| 1070 | err = req(hdev, param); |
| 1071 | |
| 1072 | schedule_timeout(timeout); |
| 1073 | |
| 1074 | remove_wait_queue(&hdev->req_wait_q, &wait); |
| 1075 | |
| 1076 | if (signal_pending(current)) |
| 1077 | return -EINTR; |
| 1078 | |
| 1079 | switch (hdev->req_status) { |
| 1080 | case HCI_REQ_DONE: |
| 1081 | case HCI_REQ_STATUS: |
| 1082 | err = radio_hci_err(hdev->req_result); |
| 1083 | break; |
| 1084 | |
| 1085 | case HCI_REQ_CANCELED: |
| 1086 | err = -hdev->req_result; |
| 1087 | break; |
| 1088 | |
| 1089 | default: |
| 1090 | err = -ETIMEDOUT; |
| 1091 | break; |
| 1092 | } |
| 1093 | |
| 1094 | hdev->req_status = hdev->req_result = 0; |
| 1095 | |
| 1096 | return err; |
| 1097 | } |
| 1098 | |
| 1099 | static inline int radio_hci_request(struct radio_hci_dev *hdev, |
| 1100 | int (*req)(struct |
| 1101 | radio_hci_dev * hdev, unsigned long param), |
| 1102 | unsigned long param, __u32 timeout) |
| 1103 | { |
| 1104 | int ret = 0; |
| 1105 | |
| 1106 | ret = __radio_hci_request(hdev, req, param, timeout); |
| 1107 | |
| 1108 | return ret; |
| 1109 | } |
| 1110 | |
Srinivasa Rao Uppala | f856ae6 | 2011-10-17 18:43:26 +0530 | [diff] [blame] | 1111 | static inline int hci_conf_event_mask(__u8 *arg, |
| 1112 | struct radio_hci_dev *hdev) |
| 1113 | { |
| 1114 | u8 event_mask = *arg; |
| 1115 | return radio_hci_request(hdev, hci_fm_set_event_mask, |
| 1116 | event_mask, RADIO_HCI_TIMEOUT); |
| 1117 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1118 | static int hci_set_fm_recv_conf(struct hci_fm_recv_conf_req *arg, |
| 1119 | struct radio_hci_dev *hdev) |
| 1120 | { |
| 1121 | int ret = 0; |
| 1122 | struct hci_fm_recv_conf_req *set_recv_conf = arg; |
| 1123 | |
| 1124 | ret = radio_hci_request(hdev, hci_set_fm_recv_conf_req, (unsigned |
| 1125 | long)set_recv_conf, RADIO_HCI_TIMEOUT); |
| 1126 | |
| 1127 | return ret; |
| 1128 | } |
| 1129 | |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 1130 | static int hci_set_fm_trans_conf(struct hci_fm_trans_conf_req_struct *arg, |
| 1131 | struct radio_hci_dev *hdev) |
| 1132 | { |
| 1133 | int ret = 0; |
| 1134 | struct hci_fm_trans_conf_req_struct *set_trans_conf = arg; |
| 1135 | |
| 1136 | ret = radio_hci_request(hdev, hci_set_fm_trans_conf_req, (unsigned |
| 1137 | long)set_trans_conf, RADIO_HCI_TIMEOUT); |
| 1138 | |
| 1139 | return ret; |
| 1140 | } |
| 1141 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1142 | static int hci_fm_tune_station(__u32 *arg, struct radio_hci_dev *hdev) |
| 1143 | { |
| 1144 | int ret = 0; |
| 1145 | __u32 tune_freq = *arg; |
| 1146 | |
| 1147 | ret = radio_hci_request(hdev, hci_fm_tune_station_req, tune_freq, |
| 1148 | RADIO_HCI_TIMEOUT); |
| 1149 | |
| 1150 | return ret; |
| 1151 | } |
| 1152 | |
| 1153 | static int hci_set_fm_mute_mode(struct hci_fm_mute_mode_req *arg, |
| 1154 | struct radio_hci_dev *hdev) |
| 1155 | { |
| 1156 | int ret = 0; |
| 1157 | struct hci_fm_mute_mode_req *set_mute_conf = arg; |
| 1158 | |
| 1159 | ret = radio_hci_request(hdev, hci_set_fm_mute_mode_req, (unsigned |
| 1160 | long)set_mute_conf, RADIO_HCI_TIMEOUT); |
| 1161 | |
| 1162 | return ret; |
| 1163 | } |
| 1164 | |
| 1165 | static int hci_set_fm_stereo_mode(struct hci_fm_stereo_mode_req *arg, |
| 1166 | struct radio_hci_dev *hdev) |
| 1167 | { |
| 1168 | int ret = 0; |
| 1169 | struct hci_fm_stereo_mode_req *set_stereo_conf = arg; |
| 1170 | |
| 1171 | ret = radio_hci_request(hdev, hci_set_fm_stereo_mode_req, (unsigned |
| 1172 | long)set_stereo_conf, RADIO_HCI_TIMEOUT); |
| 1173 | |
| 1174 | return ret; |
| 1175 | } |
| 1176 | |
| 1177 | static int hci_fm_set_antenna(__u8 *arg, struct radio_hci_dev *hdev) |
| 1178 | { |
| 1179 | int ret = 0; |
| 1180 | __u8 antenna = *arg; |
| 1181 | |
| 1182 | ret = radio_hci_request(hdev, hci_fm_set_antenna_req, antenna, |
| 1183 | RADIO_HCI_TIMEOUT); |
| 1184 | |
| 1185 | return ret; |
| 1186 | } |
| 1187 | |
| 1188 | static int hci_fm_set_signal_threshold(__u8 *arg, |
| 1189 | struct radio_hci_dev *hdev) |
| 1190 | { |
| 1191 | int ret = 0; |
| 1192 | __u8 sig_threshold = *arg; |
| 1193 | |
| 1194 | ret = radio_hci_request(hdev, hci_fm_set_sig_threshold_req, |
| 1195 | sig_threshold, RADIO_HCI_TIMEOUT); |
| 1196 | |
| 1197 | return ret; |
| 1198 | } |
| 1199 | |
| 1200 | static int hci_fm_search_stations(struct hci_fm_search_station_req *arg, |
| 1201 | struct radio_hci_dev *hdev) |
| 1202 | { |
| 1203 | int ret = 0; |
| 1204 | struct hci_fm_search_station_req *srch_stations = arg; |
| 1205 | |
| 1206 | ret = radio_hci_request(hdev, hci_fm_search_stations_req, (unsigned |
| 1207 | long)srch_stations, RADIO_HCI_TIMEOUT); |
| 1208 | |
| 1209 | return ret; |
| 1210 | } |
| 1211 | |
| 1212 | static int hci_fm_search_rds_stations(struct hci_fm_search_rds_station_req *arg, |
| 1213 | struct radio_hci_dev *hdev) |
| 1214 | { |
| 1215 | int ret = 0; |
| 1216 | struct hci_fm_search_rds_station_req *srch_stations = arg; |
| 1217 | |
| 1218 | ret = radio_hci_request(hdev, hci_fm_srch_rds_stations_req, (unsigned |
| 1219 | long)srch_stations, RADIO_HCI_TIMEOUT); |
| 1220 | |
| 1221 | return ret; |
| 1222 | } |
| 1223 | |
| 1224 | static int hci_fm_search_station_list |
| 1225 | (struct hci_fm_search_station_list_req *arg, |
| 1226 | struct radio_hci_dev *hdev) |
| 1227 | { |
| 1228 | int ret = 0; |
| 1229 | struct hci_fm_search_station_list_req *srch_list = arg; |
| 1230 | |
| 1231 | ret = radio_hci_request(hdev, hci_fm_srch_station_list_req, (unsigned |
| 1232 | long)srch_list, RADIO_HCI_TIMEOUT); |
| 1233 | |
| 1234 | return ret; |
| 1235 | } |
| 1236 | |
| 1237 | static int hci_fm_rds_grp(struct hci_fm_rds_grp_req *arg, |
| 1238 | struct radio_hci_dev *hdev) |
| 1239 | { |
| 1240 | return 0; |
| 1241 | } |
| 1242 | |
| 1243 | static int hci_fm_rds_grps_process(__u32 *arg, struct radio_hci_dev *hdev) |
| 1244 | { |
| 1245 | int ret = 0; |
| 1246 | __u32 fm_grps_process = *arg; |
| 1247 | |
| 1248 | ret = radio_hci_request(hdev, hci_fm_rds_grp_process_req, |
| 1249 | fm_grps_process, RADIO_HCI_TIMEOUT); |
| 1250 | |
| 1251 | return ret; |
| 1252 | } |
| 1253 | |
| 1254 | int hci_def_data_read(struct hci_fm_def_data_rd_req *arg, |
| 1255 | struct radio_hci_dev *hdev) |
| 1256 | { |
| 1257 | int ret = 0; |
| 1258 | struct hci_fm_def_data_rd_req *def_data_rd = arg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1259 | ret = radio_hci_request(hdev, hci_def_data_read_req, (unsigned |
| 1260 | long)def_data_rd, RADIO_HCI_TIMEOUT); |
| 1261 | |
| 1262 | return ret; |
| 1263 | } |
| 1264 | |
| 1265 | int hci_def_data_write(struct hci_fm_def_data_wr_req *arg, |
| 1266 | struct radio_hci_dev *hdev) |
| 1267 | { |
| 1268 | int ret = 0; |
| 1269 | struct hci_fm_def_data_wr_req *def_data_wr = arg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1270 | ret = radio_hci_request(hdev, hci_def_data_write_req, (unsigned |
| 1271 | long)def_data_wr, RADIO_HCI_TIMEOUT); |
| 1272 | |
| 1273 | return ret; |
| 1274 | } |
| 1275 | |
| 1276 | int hci_fm_do_calibration(__u8 *arg, struct radio_hci_dev *hdev) |
| 1277 | { |
| 1278 | int ret = 0; |
| 1279 | __u8 mode = *arg; |
| 1280 | |
| 1281 | ret = radio_hci_request(hdev, hci_fm_do_calibration_req, mode, |
| 1282 | RADIO_HCI_TIMEOUT); |
| 1283 | |
| 1284 | return ret; |
| 1285 | } |
| 1286 | |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 1287 | static int hci_read_grp_counters(__u8 *arg, struct radio_hci_dev *hdev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1288 | { |
| 1289 | int ret = 0; |
| 1290 | __u8 reset_counters = *arg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1291 | ret = radio_hci_request(hdev, hci_read_grp_counters_req, |
| 1292 | reset_counters, RADIO_HCI_TIMEOUT); |
| 1293 | |
| 1294 | return ret; |
| 1295 | } |
| 1296 | |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 1297 | static int hci_set_notch_filter(__u8 *arg, struct radio_hci_dev *hdev) |
| 1298 | { |
| 1299 | int ret = 0; |
| 1300 | __u8 notch_filter = *arg; |
| 1301 | ret = radio_hci_request(hdev, hci_set_notch_filter_req, |
| 1302 | notch_filter, RADIO_HCI_TIMEOUT); |
| 1303 | |
| 1304 | return ret; |
| 1305 | } |
| 1306 | |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1307 | static int hci_peek_data(struct hci_fm_riva_data *arg, |
| 1308 | struct radio_hci_dev *hdev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1309 | { |
| 1310 | int ret = 0; |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1311 | struct hci_fm_riva_data *peek_data = arg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1312 | |
| 1313 | ret = radio_hci_request(hdev, hci_peek_data_req, (unsigned |
| 1314 | long)peek_data, RADIO_HCI_TIMEOUT); |
| 1315 | |
| 1316 | return ret; |
| 1317 | } |
| 1318 | |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1319 | static int hci_poke_data(struct hci_fm_riva_poke *arg, |
| 1320 | struct radio_hci_dev *hdev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1321 | { |
| 1322 | int ret = 0; |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1323 | struct hci_fm_riva_poke *poke_data = arg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1324 | |
| 1325 | ret = radio_hci_request(hdev, hci_poke_data_req, (unsigned |
| 1326 | long)poke_data, RADIO_HCI_TIMEOUT); |
| 1327 | |
| 1328 | return ret; |
| 1329 | } |
| 1330 | |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1331 | static int hci_ssbi_peek_reg(struct hci_fm_ssbi_peek *arg, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1332 | struct radio_hci_dev *hdev) |
| 1333 | { |
| 1334 | int ret = 0; |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1335 | struct hci_fm_ssbi_peek *ssbi_peek_reg = arg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1336 | |
| 1337 | ret = radio_hci_request(hdev, hci_ssbi_peek_reg_req, (unsigned |
| 1338 | long)ssbi_peek_reg, RADIO_HCI_TIMEOUT); |
| 1339 | |
| 1340 | return ret; |
| 1341 | } |
| 1342 | |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1343 | static int hci_ssbi_poke_reg(struct hci_fm_ssbi_req *arg, |
| 1344 | struct radio_hci_dev *hdev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1345 | { |
| 1346 | int ret = 0; |
| 1347 | struct hci_fm_ssbi_req *ssbi_poke_reg = arg; |
| 1348 | |
| 1349 | ret = radio_hci_request(hdev, hci_ssbi_poke_reg_req, (unsigned |
| 1350 | long)ssbi_poke_reg, RADIO_HCI_TIMEOUT); |
| 1351 | |
| 1352 | return ret; |
| 1353 | } |
| 1354 | |
Srinivasa Rao Uppala | cb48ee6 | 2011-10-25 09:57:06 +0530 | [diff] [blame] | 1355 | static int hci_fm_set_cal_req(struct radio_hci_dev *hdev, |
| 1356 | unsigned long param) |
| 1357 | { |
| 1358 | u16 opcode = 0; |
| 1359 | struct hci_fm_set_cal_req *cal_req = |
| 1360 | (struct hci_fm_set_cal_req *)param; |
| 1361 | |
| 1362 | opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ, |
| 1363 | HCI_OCF_FM_SET_CALIBRATION); |
| 1364 | return radio_hci_send_cmd(hdev, opcode, sizeof((*hci_fm_set_cal_req)), |
| 1365 | cal_req); |
| 1366 | |
| 1367 | } |
| 1368 | |
| 1369 | static int hci_fm_do_cal_req(struct radio_hci_dev *hdev, |
| 1370 | unsigned long param) |
| 1371 | { |
| 1372 | u16 opcode = 0; |
| 1373 | u8 cal_mode = param; |
| 1374 | |
| 1375 | opcode = hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ, |
| 1376 | HCI_OCF_FM_DO_CALIBRATION); |
| 1377 | return radio_hci_send_cmd(hdev, opcode, sizeof(cal_mode), |
| 1378 | &cal_mode); |
| 1379 | |
| 1380 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1381 | static int hci_cmd(unsigned int cmd, struct radio_hci_dev *hdev) |
| 1382 | { |
| 1383 | int ret = 0; |
| 1384 | unsigned long arg = 0; |
| 1385 | |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 1386 | if (!hdev) |
| 1387 | return -ENODEV; |
| 1388 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1389 | switch (cmd) { |
| 1390 | case HCI_FM_ENABLE_RECV_CMD: |
| 1391 | ret = radio_hci_request(hdev, hci_fm_enable_recv_req, arg, |
| 1392 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 1393 | break; |
| 1394 | |
| 1395 | case HCI_FM_DISABLE_RECV_CMD: |
| 1396 | ret = radio_hci_request(hdev, hci_fm_disable_recv_req, arg, |
| 1397 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 1398 | break; |
| 1399 | |
| 1400 | case HCI_FM_GET_RECV_CONF_CMD: |
| 1401 | ret = radio_hci_request(hdev, hci_get_fm_recv_conf_req, arg, |
| 1402 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 1403 | break; |
| 1404 | |
| 1405 | case HCI_FM_GET_STATION_PARAM_CMD: |
| 1406 | ret = radio_hci_request(hdev, |
| 1407 | hci_fm_get_station_param_req, arg, |
| 1408 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 1409 | break; |
| 1410 | |
| 1411 | case HCI_FM_GET_SIGNAL_TH_CMD: |
| 1412 | ret = radio_hci_request(hdev, |
| 1413 | hci_fm_get_sig_threshold_req, arg, |
| 1414 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 1415 | break; |
| 1416 | |
| 1417 | case HCI_FM_GET_PROGRAM_SERVICE_CMD: |
| 1418 | ret = radio_hci_request(hdev, |
| 1419 | hci_fm_get_program_service_req, arg, |
| 1420 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 1421 | break; |
| 1422 | |
| 1423 | case HCI_FM_GET_RADIO_TEXT_CMD: |
| 1424 | ret = radio_hci_request(hdev, hci_fm_get_radio_text_req, arg, |
| 1425 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 1426 | break; |
| 1427 | |
| 1428 | case HCI_FM_GET_AF_LIST_CMD: |
| 1429 | ret = radio_hci_request(hdev, hci_fm_get_af_list_req, arg, |
| 1430 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 1431 | break; |
| 1432 | |
| 1433 | case HCI_FM_CANCEL_SEARCH_CMD: |
| 1434 | ret = radio_hci_request(hdev, hci_fm_cancel_search_req, arg, |
| 1435 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 1436 | break; |
| 1437 | |
| 1438 | case HCI_FM_RESET_CMD: |
| 1439 | ret = radio_hci_request(hdev, hci_fm_reset_req, arg, |
| 1440 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 1441 | break; |
| 1442 | |
| 1443 | case HCI_FM_GET_FEATURES_CMD: |
| 1444 | ret = radio_hci_request(hdev, |
| 1445 | hci_fm_get_feature_lists_req, arg, |
| 1446 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 1447 | break; |
| 1448 | |
| 1449 | case HCI_FM_STATION_DBG_PARAM_CMD: |
| 1450 | ret = radio_hci_request(hdev, |
| 1451 | hci_fm_get_station_dbg_param_req, arg, |
| 1452 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 1453 | break; |
| 1454 | |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 1455 | case HCI_FM_ENABLE_TRANS_CMD: |
| 1456 | ret = radio_hci_request(hdev, hci_fm_enable_trans_req, arg, |
| 1457 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 1458 | break; |
| 1459 | |
| 1460 | case HCI_FM_DISABLE_TRANS_CMD: |
| 1461 | ret = radio_hci_request(hdev, hci_fm_disable_trans_req, arg, |
| 1462 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 1463 | break; |
| 1464 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1465 | default: |
| 1466 | ret = -EINVAL; |
| 1467 | break; |
| 1468 | } |
| 1469 | |
| 1470 | return ret; |
| 1471 | } |
| 1472 | |
| 1473 | static void radio_hci_req_complete(struct radio_hci_dev *hdev, int result) |
| 1474 | { |
| 1475 | hdev->req_result = result; |
| 1476 | hdev->req_status = HCI_REQ_DONE; |
| 1477 | wake_up_interruptible(&hdev->req_wait_q); |
| 1478 | } |
| 1479 | |
| 1480 | static void radio_hci_status_complete(struct radio_hci_dev *hdev, int result) |
| 1481 | { |
| 1482 | hdev->req_result = result; |
| 1483 | hdev->req_status = HCI_REQ_STATUS; |
| 1484 | wake_up_interruptible(&hdev->req_wait_q); |
| 1485 | } |
| 1486 | |
| 1487 | static void hci_cc_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb) |
| 1488 | { |
| 1489 | __u8 status = *((__u8 *) skb->data); |
| 1490 | |
| 1491 | if (status) |
| 1492 | return; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1493 | radio_hci_req_complete(hdev, status); |
| 1494 | } |
| 1495 | |
| 1496 | static void hci_cc_fm_disable_rsp(struct radio_hci_dev *hdev, |
| 1497 | struct sk_buff *skb) |
| 1498 | { |
| 1499 | __u8 status = *((__u8 *) skb->data); |
| 1500 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1501 | |
| 1502 | if (status) |
| 1503 | return; |
| 1504 | |
| 1505 | iris_q_event(radio, IRIS_EVT_RADIO_READY); |
| 1506 | |
| 1507 | radio_hci_req_complete(hdev, status); |
| 1508 | } |
| 1509 | |
| 1510 | static void hci_cc_conf_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb) |
| 1511 | { |
| 1512 | struct hci_fm_conf_rsp *rsp = (void *)skb->data; |
| 1513 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1514 | |
| 1515 | if (rsp->status) |
| 1516 | return; |
| 1517 | |
| 1518 | radio->recv_conf = rsp->recv_conf_rsp; |
| 1519 | radio_hci_req_complete(hdev, rsp->status); |
| 1520 | } |
| 1521 | |
| 1522 | static void hci_cc_fm_enable_rsp(struct radio_hci_dev *hdev, |
| 1523 | struct sk_buff *skb) |
| 1524 | { |
| 1525 | struct hci_fm_conf_rsp *rsp = (void *)skb->data; |
| 1526 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1527 | |
| 1528 | if (rsp->status) |
| 1529 | return; |
| 1530 | |
| 1531 | iris_q_event(radio, IRIS_EVT_RADIO_READY); |
| 1532 | |
| 1533 | radio_hci_req_complete(hdev, rsp->status); |
| 1534 | } |
| 1535 | |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 1536 | |
| 1537 | static void hci_cc_fm_trans_set_conf_rsp(struct radio_hci_dev *hdev, |
| 1538 | struct sk_buff *skb) |
| 1539 | { |
| 1540 | struct hci_fm_conf_rsp *rsp = (void *)skb->data; |
| 1541 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1542 | |
| 1543 | if (rsp->status) |
| 1544 | return; |
| 1545 | |
| 1546 | iris_q_event(radio, HCI_EV_CMD_COMPLETE); |
| 1547 | |
| 1548 | radio_hci_req_complete(hdev, rsp->status); |
| 1549 | } |
| 1550 | |
| 1551 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1552 | static void hci_cc_sig_threshold_rsp(struct radio_hci_dev *hdev, |
| 1553 | struct sk_buff *skb) |
| 1554 | { |
| 1555 | struct hci_fm_sig_threshold_rsp *rsp = (void *)skb->data; |
| 1556 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1557 | struct v4l2_control *v4l_ctl = radio->g_ctl; |
| 1558 | |
| 1559 | if (rsp->status) |
| 1560 | return; |
| 1561 | |
| 1562 | v4l_ctl->value = rsp->sig_threshold; |
| 1563 | |
| 1564 | radio_hci_req_complete(hdev, rsp->status); |
| 1565 | } |
| 1566 | |
| 1567 | static void hci_cc_station_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb) |
| 1568 | { |
| 1569 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1570 | struct hci_fm_station_rsp *rsp = (void *)skb->data; |
| 1571 | radio->fm_st_rsp = *(rsp); |
| 1572 | |
| 1573 | /* Tune is always succesful */ |
| 1574 | radio_hci_req_complete(hdev, 0); |
| 1575 | } |
| 1576 | |
| 1577 | static void hci_cc_prg_srv_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb) |
| 1578 | { |
| 1579 | struct hci_fm_prgm_srv_rsp *rsp = (void *)skb->data; |
| 1580 | |
| 1581 | if (rsp->status) |
| 1582 | return; |
| 1583 | |
| 1584 | radio_hci_req_complete(hdev, rsp->status); |
| 1585 | } |
| 1586 | |
| 1587 | static void hci_cc_rd_txt_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb) |
| 1588 | { |
| 1589 | struct hci_fm_radio_txt_rsp *rsp = (void *)skb->data; |
| 1590 | |
| 1591 | if (rsp->status) |
| 1592 | return; |
| 1593 | |
| 1594 | radio_hci_req_complete(hdev, rsp->status); |
| 1595 | } |
| 1596 | |
| 1597 | static void hci_cc_af_list_rsp(struct radio_hci_dev *hdev, struct sk_buff *skb) |
| 1598 | { |
| 1599 | struct hci_fm_af_list_rsp *rsp = (void *)skb->data; |
| 1600 | |
| 1601 | if (rsp->status) |
| 1602 | return; |
| 1603 | |
| 1604 | radio_hci_req_complete(hdev, rsp->status); |
| 1605 | } |
| 1606 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1607 | static void hci_cc_feature_list_rsp(struct radio_hci_dev *hdev, |
| 1608 | struct sk_buff *skb) |
| 1609 | { |
| 1610 | struct hci_fm_feature_list_rsp *rsp = (void *)skb->data; |
| 1611 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1612 | struct v4l2_capability *v4l_cap = radio->g_cap; |
| 1613 | |
| 1614 | if (rsp->status) |
| 1615 | return; |
| 1616 | v4l_cap->capabilities = (rsp->feature_mask & 0x000002) | |
| 1617 | (rsp->feature_mask & 0x000001); |
| 1618 | |
| 1619 | radio_hci_req_complete(hdev, rsp->status); |
| 1620 | } |
| 1621 | |
| 1622 | static void hci_cc_dbg_param_rsp(struct radio_hci_dev *hdev, |
| 1623 | struct sk_buff *skb) |
| 1624 | { |
| 1625 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1626 | struct hci_fm_dbg_param_rsp *rsp = (void *)skb->data; |
| 1627 | radio->st_dbg_param = *(rsp); |
| 1628 | |
| 1629 | if (radio->st_dbg_param.status) |
| 1630 | return; |
| 1631 | |
| 1632 | radio_hci_req_complete(hdev, radio->st_dbg_param.status); |
| 1633 | } |
| 1634 | |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1635 | static void iris_q_evt_data(struct iris_device *radio, |
| 1636 | char *data, int len, int event) |
| 1637 | { |
| 1638 | struct kfifo *data_b = &radio->data_buf[event]; |
| 1639 | if (kfifo_in_locked(data_b, data, len, &radio->buf_lock[event])) |
| 1640 | wake_up_interruptible(&radio->event_queue); |
| 1641 | } |
| 1642 | |
| 1643 | static void hci_cc_riva_peek_rsp(struct radio_hci_dev *hdev, |
| 1644 | struct sk_buff *skb) |
| 1645 | { |
| 1646 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 1647 | __u8 status = *((__u8 *) skb->data); |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1648 | int len; |
| 1649 | char *data; |
| 1650 | |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 1651 | if (status) |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1652 | return; |
| 1653 | len = skb->data[RIVA_PEEK_LEN_OFSET] + RIVA_PEEK_PARAM; |
| 1654 | data = kmalloc(len, GFP_ATOMIC); |
| 1655 | |
| 1656 | if (!data) { |
| 1657 | FMDERR("Memory allocation failed"); |
| 1658 | return; |
| 1659 | } |
| 1660 | |
| 1661 | memcpy(data, &skb->data[PEEK_DATA_OFSET], len); |
| 1662 | iris_q_evt_data(radio, data, len, IRIS_BUF_PEEK); |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 1663 | radio_hci_req_complete(hdev, status); |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1664 | |
| 1665 | |
| 1666 | } |
Venkateshwarlu Domakonda | 787af69 | 2011-10-14 21:23:03 +0530 | [diff] [blame] | 1667 | |
| 1668 | static void hci_cc_riva_read_default_rsp(struct radio_hci_dev *hdev, |
| 1669 | struct sk_buff *skb) |
| 1670 | { |
| 1671 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1672 | __u8 status = *((__u8 *) skb->data); |
| 1673 | __u8 len; |
| 1674 | char *data; |
| 1675 | |
| 1676 | if (status) |
| 1677 | return; |
| 1678 | len = skb->data[1]; |
| 1679 | data = kmalloc(len+2, GFP_ATOMIC); |
| 1680 | if (!data) { |
| 1681 | FMDERR("Memory allocation failed"); |
| 1682 | return; |
| 1683 | } |
| 1684 | |
| 1685 | data[0] = status; |
| 1686 | data[1] = len; |
| 1687 | memcpy(&data[2], &skb->data[DEFAULT_DATA_OFFSET], len); |
| 1688 | iris_q_evt_data(radio, data, len+2, IRIS_BUF_RD_DEFAULT); |
| 1689 | radio_hci_req_complete(hdev, status); |
| 1690 | kfree(data); |
| 1691 | } |
| 1692 | |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1693 | static void hci_cc_ssbi_peek_rsp(struct radio_hci_dev *hdev, |
| 1694 | struct sk_buff *skb) |
| 1695 | { |
| 1696 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 1697 | __u8 status = *((__u8 *) skb->data); |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1698 | char *data; |
| 1699 | |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 1700 | if (status) |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1701 | return; |
| 1702 | data = kmalloc(SSBI_PEEK_LEN, GFP_ATOMIC); |
| 1703 | if (!data) { |
| 1704 | FMDERR("Memory allocation failed"); |
| 1705 | return; |
| 1706 | } |
| 1707 | |
| 1708 | data[0] = skb->data[PEEK_DATA_OFSET]; |
| 1709 | iris_q_evt_data(radio, data, SSBI_PEEK_LEN, IRIS_BUF_SSBI_PEEK); |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 1710 | radio_hci_req_complete(hdev, status); |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1711 | kfree(data); |
| 1712 | } |
| 1713 | |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 1714 | static void hci_cc_rds_grp_cntrs_rsp(struct radio_hci_dev *hdev, |
| 1715 | struct sk_buff *skb) |
| 1716 | { |
| 1717 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1718 | __u8 status = *((__u8 *) skb->data); |
| 1719 | char *data; |
| 1720 | if (status) |
| 1721 | return; |
| 1722 | data = kmalloc(RDS_GRP_CNTR_LEN, GFP_ATOMIC); |
| 1723 | if (!data) { |
| 1724 | FMDERR("memory allocation failed"); |
| 1725 | return; |
| 1726 | } |
| 1727 | memcpy(data, &skb->data[1], RDS_GRP_CNTR_LEN); |
| 1728 | iris_q_evt_data(radio, data, RDS_GRP_CNTR_LEN, IRIS_BUF_RDS_CNTRS); |
| 1729 | radio_hci_req_complete(hdev, status); |
| 1730 | kfree(data); |
| 1731 | |
| 1732 | } |
| 1733 | |
Srinivasa Rao Uppala | cb48ee6 | 2011-10-25 09:57:06 +0530 | [diff] [blame] | 1734 | static void hci_cc_do_calibration_rsp(struct radio_hci_dev *hdev, |
| 1735 | struct sk_buff *skb) |
| 1736 | { |
| 1737 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1738 | static struct hci_cc_do_calibration_rsp rsp ; |
| 1739 | rsp.status = skb->data[0]; |
| 1740 | rsp.mode = skb->data[CALIB_MODE_OFSET]; |
| 1741 | |
| 1742 | if (rsp.status) { |
| 1743 | FMDERR("status = %d", rsp.status); |
| 1744 | return; |
| 1745 | } |
| 1746 | if (rsp.mode == PROCS_CALIB_MODE) { |
| 1747 | memcpy(&rsp.data[0], &skb->data[CALIB_DATA_OFSET], |
| 1748 | PROCS_CALIB_SIZE); |
| 1749 | } else if (rsp.mode == DC_CALIB_MODE) { |
| 1750 | memcpy(&rsp.data[PROCS_CALIB_SIZE], |
| 1751 | &skb->data[CALIB_DATA_OFSET], DC_CALIB_SIZE); |
| 1752 | iris_q_evt_data(radio, rsp.data, (PROCS_CALIB_SIZE + |
| 1753 | DC_CALIB_SIZE), IRIS_BUF_CAL_DATA); |
| 1754 | } |
| 1755 | radio_hci_req_complete(hdev, rsp.status); |
| 1756 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1757 | static inline void hci_cmd_complete_event(struct radio_hci_dev *hdev, |
| 1758 | struct sk_buff *skb) |
| 1759 | { |
| 1760 | struct hci_ev_cmd_complete *cmd_compl_ev = (void *) skb->data; |
| 1761 | __u16 opcode; |
| 1762 | |
| 1763 | skb_pull(skb, sizeof(*cmd_compl_ev)); |
| 1764 | |
| 1765 | opcode = __le16_to_cpu(cmd_compl_ev->cmd_opcode); |
| 1766 | |
| 1767 | switch (opcode) { |
| 1768 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_ENABLE_RECV_REQ): |
| 1769 | hci_cc_fm_enable_rsp(hdev, skb); |
| 1770 | break; |
| 1771 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_RECV_CONF_REQ): |
| 1772 | hci_cc_conf_rsp(hdev, skb); |
| 1773 | break; |
| 1774 | |
| 1775 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_DISABLE_RECV_REQ): |
| 1776 | hci_cc_fm_disable_rsp(hdev, skb); |
| 1777 | break; |
| 1778 | |
| 1779 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_RECV_CONF_REQ): |
| 1780 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_MUTE_MODE_REQ): |
| 1781 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_STEREO_MODE_REQ): |
| 1782 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_ANTENNA): |
| 1783 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_SIGNAL_THRESHOLD): |
| 1784 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_CANCEL_SEARCH): |
| 1785 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_RDS_GRP): |
| 1786 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_RDS_GRP_PROCESS): |
| 1787 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_EN_WAN_AVD_CTRL): |
| 1788 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_EN_NOTCH_CTRL): |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 1789 | case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_ENABLE_TRANS_REQ): |
| 1790 | case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_DISABLE_TRANS_REQ): |
| 1791 | case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_RDS_RT_REQ): |
| 1792 | case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_RDS_PS_REQ): |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1793 | case hci_common_cmd_op_pack(HCI_OCF_FM_DEFAULT_DATA_WRITE): |
Venkateshwarlu Domakonda | 787af69 | 2011-10-14 21:23:03 +0530 | [diff] [blame] | 1794 | hci_cc_rsp(hdev, skb); |
| 1795 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1796 | case hci_common_cmd_op_pack(HCI_OCF_FM_RESET): |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1797 | case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_SSBI_POKE_REG): |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1798 | case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_POKE_DATA): |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 1799 | case hci_diagnostic_cmd_op_pack(HCI_FM_SET_INTERNAL_TONE_GENRATOR): |
Srinivasa Rao Uppala | cb48ee6 | 2011-10-25 09:57:06 +0530 | [diff] [blame] | 1800 | case hci_common_cmd_op_pack(HCI_OCF_FM_SET_CALIBRATION): |
Srinivasa Rao Uppala | f856ae6 | 2011-10-17 18:43:26 +0530 | [diff] [blame] | 1801 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_SET_EVENT_MASK): |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1802 | hci_cc_rsp(hdev, skb); |
| 1803 | break; |
Srinivasa Rao Uppala | f856ae6 | 2011-10-17 18:43:26 +0530 | [diff] [blame] | 1804 | |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1805 | case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_SSBI_PEEK_REG): |
| 1806 | hci_cc_ssbi_peek_rsp(hdev, skb); |
| 1807 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1808 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_SIGNAL_THRESHOLD): |
| 1809 | hci_cc_sig_threshold_rsp(hdev, skb); |
| 1810 | break; |
| 1811 | |
| 1812 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_STATION_PARAM_REQ): |
| 1813 | hci_cc_station_rsp(hdev, skb); |
| 1814 | break; |
| 1815 | |
| 1816 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_PROGRAM_SERVICE_REQ): |
| 1817 | hci_cc_prg_srv_rsp(hdev, skb); |
| 1818 | break; |
| 1819 | |
| 1820 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_RADIO_TEXT_REQ): |
| 1821 | hci_cc_rd_txt_rsp(hdev, skb); |
| 1822 | break; |
| 1823 | |
| 1824 | case hci_recv_ctrl_cmd_op_pack(HCI_OCF_FM_GET_AF_LIST_REQ): |
| 1825 | hci_cc_af_list_rsp(hdev, skb); |
| 1826 | break; |
| 1827 | |
| 1828 | case hci_common_cmd_op_pack(HCI_OCF_FM_DEFAULT_DATA_READ): |
Venkateshwarlu Domakonda | 787af69 | 2011-10-14 21:23:03 +0530 | [diff] [blame] | 1829 | hci_cc_riva_read_default_rsp(hdev, skb); |
| 1830 | break; |
| 1831 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1832 | case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_PEEK_DATA): |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 1833 | hci_cc_riva_peek_rsp(hdev, skb); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1834 | break; |
| 1835 | |
| 1836 | case hci_common_cmd_op_pack(HCI_OCF_FM_GET_FEATURE_LIST): |
| 1837 | hci_cc_feature_list_rsp(hdev, skb); |
| 1838 | break; |
| 1839 | |
| 1840 | case hci_diagnostic_cmd_op_pack(HCI_OCF_FM_STATION_DBG_PARAM): |
| 1841 | hci_cc_dbg_param_rsp(hdev, skb); |
| 1842 | break; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 1843 | case hci_trans_ctrl_cmd_op_pack(HCI_OCF_FM_SET_TRANS_CONF_REQ): |
| 1844 | hci_cc_fm_trans_set_conf_rsp(hdev, skb); |
| 1845 | break; |
| 1846 | |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 1847 | case hci_status_param_op_pack(HCI_OCF_FM_READ_GRP_COUNTERS): |
| 1848 | hci_cc_rds_grp_cntrs_rsp(hdev, skb); |
| 1849 | break; |
Srinivasa Rao Uppala | cb48ee6 | 2011-10-25 09:57:06 +0530 | [diff] [blame] | 1850 | case hci_common_cmd_op_pack(HCI_OCF_FM_DO_CALIBRATION): |
| 1851 | hci_cc_do_calibration_rsp(hdev, skb); |
| 1852 | break; |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 1853 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1854 | default: |
| 1855 | FMDERR("%s opcode 0x%x", hdev->name, opcode); |
| 1856 | break; |
| 1857 | } |
| 1858 | |
| 1859 | } |
| 1860 | |
| 1861 | static inline void hci_cmd_status_event(struct radio_hci_dev *hdev, |
| 1862 | struct sk_buff *skb) |
| 1863 | { |
| 1864 | struct hci_ev_cmd_status *ev = (void *) skb->data; |
| 1865 | radio_hci_status_complete(hdev, ev->status); |
| 1866 | } |
| 1867 | |
| 1868 | static inline void hci_ev_tune_status(struct radio_hci_dev *hdev, |
| 1869 | struct sk_buff *skb) |
| 1870 | { |
| 1871 | int i; |
| 1872 | int len; |
| 1873 | |
| 1874 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1875 | |
| 1876 | len = sizeof(struct hci_fm_station_rsp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1877 | memcpy(&radio->fm_st_rsp.station_rsp, skb_pull(skb, len), len); |
| 1878 | |
| 1879 | iris_q_event(radio, IRIS_EVT_TUNE_SUCC); |
| 1880 | |
| 1881 | for (i = 0; i < IRIS_BUF_MAX; i++) { |
| 1882 | if (i >= IRIS_BUF_RT_RDS) |
| 1883 | kfifo_reset(&radio->data_buf[i]); |
| 1884 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1885 | if (radio->fm_st_rsp.station_rsp.rssi) |
| 1886 | iris_q_event(radio, IRIS_EVT_ABOVE_TH); |
| 1887 | else |
| 1888 | iris_q_event(radio, IRIS_EVT_BELOW_TH); |
| 1889 | |
| 1890 | if (radio->fm_st_rsp.station_rsp.stereo_prg) |
| 1891 | iris_q_event(radio, IRIS_EVT_STEREO); |
| 1892 | |
| 1893 | if (radio->fm_st_rsp.station_rsp.mute_mode) |
| 1894 | iris_q_event(radio, IRIS_EVT_MONO); |
| 1895 | |
| 1896 | if (radio->fm_st_rsp.station_rsp.rds_sync_status) |
| 1897 | iris_q_event(radio, IRIS_EVT_RDS_AVAIL); |
| 1898 | else |
| 1899 | iris_q_event(radio, IRIS_EVT_RDS_NOT_AVAIL); |
| 1900 | } |
| 1901 | |
| 1902 | static inline void hci_ev_search_compl(struct radio_hci_dev *hdev, |
| 1903 | struct sk_buff *skb) |
| 1904 | { |
| 1905 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1906 | iris_q_event(radio, IRIS_EVT_SEEK_COMPLETE); |
| 1907 | } |
| 1908 | |
| 1909 | static inline void hci_ev_srch_st_list_compl(struct radio_hci_dev *hdev, |
| 1910 | struct sk_buff *skb) |
| 1911 | { |
| 1912 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
Srinivasa Rao Uppala | 18fb80e | 2011-07-17 17:33:00 -0700 | [diff] [blame] | 1913 | struct hci_ev_srch_list_compl *ev ; |
| 1914 | int cnt; |
| 1915 | int stn_num; |
| 1916 | int rel_freq; |
| 1917 | int abs_freq; |
| 1918 | int len; |
| 1919 | |
| 1920 | ev = kmalloc(sizeof(*ev), GFP_ATOMIC); |
| 1921 | if (!ev) { |
| 1922 | FMDERR("Memory allocation failed"); |
| 1923 | return ; |
| 1924 | } |
| 1925 | |
| 1926 | ev->num_stations_found = skb->data[STN_NUM_OFFSET]; |
| 1927 | len = ev->num_stations_found * PARAMS_PER_STATION + STN_FREQ_OFFSET; |
| 1928 | |
| 1929 | for (cnt = STN_FREQ_OFFSET, stn_num = 0; |
| 1930 | (cnt < len) && (stn_num < ev->num_stations_found); |
| 1931 | cnt += PARAMS_PER_STATION, stn_num++) { |
| 1932 | abs_freq = *((int *)&skb->data[cnt]); |
| 1933 | rel_freq = abs_freq - radio->recv_conf.band_low_limit; |
| 1934 | rel_freq = (rel_freq * 20) / KHZ_TO_MHZ; |
| 1935 | |
| 1936 | ev->rel_freq[stn_num].rel_freq_lsb = GET_LSB(rel_freq); |
| 1937 | ev->rel_freq[stn_num].rel_freq_msb = GET_MSB(rel_freq); |
| 1938 | } |
| 1939 | |
| 1940 | len = ev->num_stations_found * 2 + sizeof(ev->num_stations_found); |
| 1941 | iris_q_event(radio, IRIS_EVT_NEW_SRCH_LIST); |
| 1942 | iris_q_evt_data(radio, (char *)ev, len, IRIS_BUF_SRCH_LIST); |
| 1943 | kfree(ev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | static inline void hci_ev_search_next(struct radio_hci_dev *hdev, |
| 1947 | struct sk_buff *skb) |
| 1948 | { |
| 1949 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1950 | iris_q_event(radio, IRIS_EVT_SCAN_NEXT); |
| 1951 | } |
| 1952 | |
| 1953 | static inline void hci_ev_stereo_status(struct radio_hci_dev *hdev, |
| 1954 | struct sk_buff *skb) |
| 1955 | { |
| 1956 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1957 | __u8 st_status = *((__u8 *) skb->data); |
| 1958 | if (st_status) |
| 1959 | iris_q_event(radio, IRIS_EVT_STEREO); |
| 1960 | else |
| 1961 | iris_q_event(radio, IRIS_EVT_MONO); |
| 1962 | } |
| 1963 | |
Ankur Nandwani | 78a782b | 2011-07-07 21:11:21 -0700 | [diff] [blame] | 1964 | |
Ankur Nandwani | 78a782b | 2011-07-07 21:11:21 -0700 | [diff] [blame] | 1965 | static inline void hci_ev_program_service(struct radio_hci_dev *hdev, |
| 1966 | struct sk_buff *skb) |
| 1967 | { |
| 1968 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1969 | int len; |
| 1970 | char *data; |
| 1971 | |
| 1972 | len = (skb->data[RDS_PS_LENGTH_OFFSET] * RDS_STRING) + RDS_OFFSET; |
| 1973 | iris_q_event(radio, IRIS_EVT_NEW_PS_RDS); |
| 1974 | data = kmalloc(len, GFP_ATOMIC); |
| 1975 | if (!data) { |
| 1976 | FMDERR("Failed to allocate memory"); |
| 1977 | return; |
| 1978 | } |
| 1979 | |
| 1980 | data[0] = skb->data[RDS_PS_LENGTH_OFFSET]; |
| 1981 | data[1] = skb->data[RDS_PTYPE]; |
| 1982 | data[2] = skb->data[RDS_PID_LOWER]; |
| 1983 | data[3] = skb->data[RDS_PID_HIGHER]; |
| 1984 | data[4] = 0; |
| 1985 | |
| 1986 | memcpy(data+RDS_OFFSET, &skb->data[RDS_PS_DATA_OFFSET], len-RDS_OFFSET); |
| 1987 | |
Srinivasa Rao Uppala | 18fb80e | 2011-07-17 17:33:00 -0700 | [diff] [blame] | 1988 | iris_q_evt_data(radio, data, len, IRIS_BUF_PS_RDS); |
Ankur Nandwani | 78a782b | 2011-07-07 21:11:21 -0700 | [diff] [blame] | 1989 | |
| 1990 | kfree(data); |
| 1991 | } |
| 1992 | |
| 1993 | |
| 1994 | static inline void hci_ev_radio_text(struct radio_hci_dev *hdev, |
| 1995 | struct sk_buff *skb) |
| 1996 | { |
| 1997 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 1998 | int len = 0; |
| 1999 | char *data; |
| 2000 | |
| 2001 | iris_q_event(radio, IRIS_EVT_NEW_RT_RDS); |
| 2002 | |
| 2003 | while (skb->data[len+RDS_OFFSET] != 0x0d) |
| 2004 | len++; |
| 2005 | len++; |
| 2006 | |
| 2007 | data = kmalloc(len+RDS_OFFSET, GFP_ATOMIC); |
| 2008 | if (!data) { |
| 2009 | FMDERR("Failed to allocate memory"); |
| 2010 | return; |
| 2011 | } |
| 2012 | |
| 2013 | data[0] = len; |
| 2014 | data[1] = skb->data[RDS_PTYPE]; |
| 2015 | data[2] = skb->data[RDS_PID_LOWER]; |
| 2016 | data[3] = skb->data[RDS_PID_HIGHER]; |
| 2017 | data[4] = 0; |
| 2018 | |
| 2019 | memcpy(data+RDS_OFFSET, &skb->data[RDS_OFFSET], len); |
| 2020 | data[len+RDS_OFFSET] = 0x00; |
| 2021 | |
Srinivasa Rao Uppala | 18fb80e | 2011-07-17 17:33:00 -0700 | [diff] [blame] | 2022 | iris_q_evt_data(radio, data, len+RDS_OFFSET, IRIS_BUF_RT_RDS); |
Ankur Nandwani | 78a782b | 2011-07-07 21:11:21 -0700 | [diff] [blame] | 2023 | |
| 2024 | kfree(data); |
| 2025 | } |
| 2026 | |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2027 | static void hci_ev_af_list(struct radio_hci_dev *hdev, |
| 2028 | struct sk_buff *skb) |
| 2029 | { |
| 2030 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 2031 | struct hci_ev_af_list ev; |
| 2032 | |
| 2033 | ev.tune_freq = *((int *) &skb->data[0]); |
| 2034 | ev.pi_code = *((__le16 *) &skb->data[PI_CODE_OFFSET]); |
| 2035 | ev.af_size = skb->data[AF_SIZE_OFFSET]; |
| 2036 | memcpy(&ev.af_list[0], &skb->data[AF_LIST_OFFSET], ev.af_size); |
| 2037 | iris_q_event(radio, IRIS_EVT_NEW_AF_LIST); |
| 2038 | iris_q_evt_data(radio, (char *)&ev, sizeof(ev), IRIS_BUF_AF_LIST); |
| 2039 | } |
| 2040 | |
| 2041 | static void hci_ev_rds_lock_status(struct radio_hci_dev *hdev, |
| 2042 | struct sk_buff *skb) |
| 2043 | { |
| 2044 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 2045 | __u8 rds_status = skb->data[0]; |
| 2046 | |
| 2047 | if (rds_status) |
| 2048 | iris_q_event(radio, IRIS_EVT_RDS_AVAIL); |
| 2049 | else |
| 2050 | iris_q_event(radio, IRIS_EVT_RDS_NOT_AVAIL); |
| 2051 | } |
| 2052 | |
| 2053 | static void hci_ev_service_available(struct radio_hci_dev *hdev, |
| 2054 | struct sk_buff *skb) |
| 2055 | { |
| 2056 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 2057 | if (radio->fm_st_rsp.station_rsp.serv_avble) |
| 2058 | iris_q_event(radio, IRIS_EVT_ABOVE_TH); |
| 2059 | else |
| 2060 | iris_q_event(radio, IRIS_EVT_BELOW_TH); |
| 2061 | } |
| 2062 | |
| 2063 | static void hci_ev_rds_grp_complete(struct radio_hci_dev *hdev, |
| 2064 | struct sk_buff *skb) |
| 2065 | { |
| 2066 | struct iris_device *radio = video_get_drvdata(video_get_dev()); |
| 2067 | iris_q_event(radio, IRIS_EVT_TXRDSDONE); |
| 2068 | } |
Ankur Nandwani | 78a782b | 2011-07-07 21:11:21 -0700 | [diff] [blame] | 2069 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2070 | void radio_hci_event_packet(struct radio_hci_dev *hdev, struct sk_buff *skb) |
| 2071 | { |
| 2072 | struct radio_hci_event_hdr *hdr = (void *) skb->data; |
| 2073 | __u8 event = hdr->evt; |
| 2074 | |
| 2075 | skb_pull(skb, RADIO_HCI_EVENT_HDR_SIZE); |
| 2076 | |
| 2077 | switch (event) { |
| 2078 | case HCI_EV_TUNE_STATUS: |
| 2079 | hci_ev_tune_status(hdev, skb); |
| 2080 | break; |
| 2081 | case HCI_EV_SEARCH_PROGRESS: |
| 2082 | case HCI_EV_SEARCH_RDS_PROGRESS: |
| 2083 | case HCI_EV_SEARCH_LIST_PROGRESS: |
| 2084 | hci_ev_search_next(hdev, skb); |
| 2085 | break; |
| 2086 | case HCI_EV_STEREO_STATUS: |
| 2087 | hci_ev_stereo_status(hdev, skb); |
| 2088 | break; |
| 2089 | case HCI_EV_RDS_LOCK_STATUS: |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2090 | hci_ev_rds_lock_status(hdev, skb); |
| 2091 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2092 | case HCI_EV_SERVICE_AVAILABLE: |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2093 | hci_ev_service_available(hdev, skb); |
| 2094 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2095 | case HCI_EV_RDS_RX_DATA: |
Ankur Nandwani | 78a782b | 2011-07-07 21:11:21 -0700 | [diff] [blame] | 2096 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2097 | case HCI_EV_PROGRAM_SERVICE: |
Ankur Nandwani | 78a782b | 2011-07-07 21:11:21 -0700 | [diff] [blame] | 2098 | hci_ev_program_service(hdev, skb); |
| 2099 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2100 | case HCI_EV_RADIO_TEXT: |
Ankur Nandwani | 78a782b | 2011-07-07 21:11:21 -0700 | [diff] [blame] | 2101 | hci_ev_radio_text(hdev, skb); |
| 2102 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2103 | case HCI_EV_FM_AF_LIST: |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2104 | hci_ev_af_list(hdev, skb); |
| 2105 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2106 | case HCI_EV_TX_RDS_GRP_COMPL: |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2107 | hci_ev_rds_grp_complete(hdev, skb); |
| 2108 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2109 | case HCI_EV_TX_RDS_CONT_GRP_COMPL: |
| 2110 | break; |
| 2111 | |
| 2112 | case HCI_EV_CMD_COMPLETE: |
| 2113 | hci_cmd_complete_event(hdev, skb); |
| 2114 | break; |
| 2115 | |
| 2116 | case HCI_EV_CMD_STATUS: |
| 2117 | hci_cmd_status_event(hdev, skb); |
| 2118 | break; |
| 2119 | |
| 2120 | case HCI_EV_SEARCH_COMPLETE: |
| 2121 | case HCI_EV_SEARCH_RDS_COMPLETE: |
| 2122 | hci_ev_search_compl(hdev, skb); |
| 2123 | break; |
| 2124 | |
| 2125 | case HCI_EV_SEARCH_LIST_COMPLETE: |
Srinivasa Rao Uppala | 18fb80e | 2011-07-17 17:33:00 -0700 | [diff] [blame] | 2126 | hci_ev_srch_st_list_compl(hdev, skb); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2127 | break; |
| 2128 | |
| 2129 | default: |
| 2130 | break; |
| 2131 | } |
| 2132 | } |
| 2133 | |
| 2134 | /* |
| 2135 | * fops/IOCTL helper functions |
| 2136 | */ |
| 2137 | |
| 2138 | static int iris_search(struct iris_device *radio, int on, int dir) |
| 2139 | { |
| 2140 | int retval = 0; |
| 2141 | enum search_t srch = radio->g_search_mode & SRCH_MODE; |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2142 | radio->search_on = on; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2143 | |
| 2144 | if (on) { |
| 2145 | switch (srch) { |
| 2146 | case SCAN_FOR_STRONG: |
| 2147 | case SCAN_FOR_WEAK: |
| 2148 | radio->srch_st_list.srch_list_dir = dir; |
| 2149 | radio->srch_st_list.srch_list_mode = srch; |
| 2150 | radio->srch_st_list.srch_list_max = 0; |
| 2151 | retval = hci_fm_search_station_list( |
| 2152 | &radio->srch_st_list, radio->fm_hdev); |
| 2153 | break; |
| 2154 | case RDS_SEEK_PTY: |
| 2155 | case RDS_SCAN_PTY: |
| 2156 | case RDS_SEEK_PI: |
Srinivasa Rao Uppala | 7bb2210 | 2011-07-14 11:27:30 -0700 | [diff] [blame] | 2157 | srch = srch - SEARCH_RDS_STNS_MODE_OFFSET; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2158 | radio->srch_rds.srch_station.srch_mode = srch; |
| 2159 | radio->srch_rds.srch_station.srch_dir = dir; |
| 2160 | radio->srch_rds.srch_station.scan_time = |
| 2161 | radio->g_scan_time; |
| 2162 | retval = hci_fm_search_rds_stations(&radio->srch_rds, |
| 2163 | radio->fm_hdev); |
| 2164 | break; |
| 2165 | default: |
| 2166 | radio->srch_st.srch_mode = srch; |
| 2167 | radio->srch_st.scan_time = radio->g_scan_time; |
| 2168 | radio->srch_st.srch_dir = dir; |
| 2169 | retval = hci_fm_search_stations( |
| 2170 | &radio->srch_st, radio->fm_hdev); |
| 2171 | break; |
| 2172 | } |
| 2173 | |
| 2174 | } else { |
| 2175 | retval = hci_cmd(HCI_FM_CANCEL_SEARCH_CMD, radio->fm_hdev); |
| 2176 | } |
| 2177 | |
| 2178 | return retval; |
| 2179 | } |
| 2180 | |
Srinivasa Rao Uppala | f856ae6 | 2011-10-17 18:43:26 +0530 | [diff] [blame] | 2181 | static int set_low_power_mode(struct iris_device *radio, int power_mode) |
| 2182 | { |
| 2183 | |
| 2184 | int rds_grps_proc = 0x00; |
| 2185 | int retval = 0; |
| 2186 | if (radio->power_mode != power_mode) { |
| 2187 | |
| 2188 | if (power_mode) { |
| 2189 | radio->event_mask = 0x00; |
| 2190 | rds_grps_proc = 0x00 | AF_JUMP_ENABLE ; |
| 2191 | retval = hci_fm_rds_grps_process( |
| 2192 | &rds_grps_proc, |
| 2193 | radio->fm_hdev); |
| 2194 | if (retval < 0) { |
| 2195 | FMDERR("Disable RDS failed"); |
| 2196 | return retval; |
| 2197 | } |
| 2198 | retval = hci_conf_event_mask(&radio->event_mask, |
| 2199 | radio->fm_hdev); |
| 2200 | } else { |
| 2201 | |
| 2202 | radio->event_mask = SIG_LEVEL_INTR | |
| 2203 | RDS_SYNC_INTR | AUDIO_CTRL_INTR; |
| 2204 | retval = hci_conf_event_mask(&radio->event_mask, |
| 2205 | radio->fm_hdev); |
| 2206 | if (retval < 0) { |
| 2207 | FMDERR("Enable Async events failed"); |
| 2208 | return retval; |
| 2209 | } |
| 2210 | retval = hci_fm_rds_grps_process( |
| 2211 | &radio->g_rds_grp_proc_ps, |
| 2212 | radio->fm_hdev); |
| 2213 | } |
| 2214 | radio->power_mode = power_mode; |
| 2215 | } |
| 2216 | return retval; |
| 2217 | } |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2218 | static int iris_recv_set_region(struct iris_device *radio, int req_region) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2219 | { |
| 2220 | int retval; |
| 2221 | radio->region = req_region; |
| 2222 | |
| 2223 | switch (radio->region) { |
| 2224 | case IRIS_REGION_US: |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2225 | radio->recv_conf.band_low_limit = |
| 2226 | REGION_US_EU_BAND_LOW; |
| 2227 | radio->recv_conf.band_high_limit = |
| 2228 | REGION_US_EU_BAND_HIGH; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2229 | break; |
| 2230 | case IRIS_REGION_EU: |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2231 | radio->recv_conf.band_low_limit = |
| 2232 | REGION_US_EU_BAND_LOW; |
| 2233 | radio->recv_conf.band_high_limit = |
| 2234 | REGION_US_EU_BAND_HIGH; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2235 | break; |
| 2236 | case IRIS_REGION_JAPAN: |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2237 | radio->recv_conf.band_low_limit = |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2238 | REGION_JAPAN_STANDARD_BAND_LOW; |
Srinivasa Rao Uppala | cc62b1c | 2011-08-22 19:15:29 +0530 | [diff] [blame] | 2239 | radio->recv_conf.band_high_limit = |
| 2240 | REGION_JAPAN_STANDARD_BAND_HIGH; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2241 | break; |
| 2242 | case IRIS_REGION_JAPAN_WIDE: |
| 2243 | radio->recv_conf.band_low_limit = |
| 2244 | REGION_JAPAN_WIDE_BAND_LOW; |
| 2245 | radio->recv_conf.band_high_limit = |
| 2246 | REGION_JAPAN_WIDE_BAND_HIGH; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2247 | break; |
| 2248 | default: |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2249 | /* The user specifies the value. |
| 2250 | So nothing needs to be done */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2251 | break; |
| 2252 | } |
| 2253 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2254 | retval = hci_set_fm_recv_conf( |
| 2255 | &radio->recv_conf, |
| 2256 | radio->fm_hdev); |
| 2257 | |
| 2258 | return retval; |
| 2259 | } |
| 2260 | |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2261 | |
| 2262 | static int iris_trans_set_region(struct iris_device *radio, int req_region) |
| 2263 | { |
| 2264 | int retval; |
| 2265 | radio->region = req_region; |
| 2266 | |
| 2267 | switch (radio->region) { |
| 2268 | case IRIS_REGION_US: |
| 2269 | radio->trans_conf.band_low_limit = |
| 2270 | REGION_US_EU_BAND_LOW; |
| 2271 | radio->trans_conf.band_high_limit = |
| 2272 | REGION_US_EU_BAND_HIGH; |
| 2273 | break; |
| 2274 | case IRIS_REGION_EU: |
| 2275 | radio->trans_conf.band_low_limit = |
| 2276 | REGION_US_EU_BAND_LOW; |
| 2277 | radio->trans_conf.band_high_limit = |
| 2278 | REGION_US_EU_BAND_HIGH; |
| 2279 | break; |
| 2280 | case IRIS_REGION_JAPAN: |
| 2281 | radio->trans_conf.band_low_limit = |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2282 | REGION_JAPAN_STANDARD_BAND_LOW; |
Srinivasa Rao Uppala | cc62b1c | 2011-08-22 19:15:29 +0530 | [diff] [blame] | 2283 | radio->trans_conf.band_high_limit = |
| 2284 | REGION_JAPAN_STANDARD_BAND_HIGH; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2285 | break; |
| 2286 | case IRIS_REGION_JAPAN_WIDE: |
| 2287 | radio->recv_conf.band_low_limit = |
| 2288 | REGION_JAPAN_WIDE_BAND_LOW; |
| 2289 | radio->recv_conf.band_high_limit = |
| 2290 | REGION_JAPAN_WIDE_BAND_HIGH; |
| 2291 | default: |
| 2292 | break; |
| 2293 | } |
| 2294 | |
| 2295 | retval = hci_set_fm_trans_conf( |
| 2296 | &radio->trans_conf, |
| 2297 | radio->fm_hdev); |
| 2298 | return retval; |
| 2299 | } |
| 2300 | |
| 2301 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2302 | static int iris_set_freq(struct iris_device *radio, unsigned int freq) |
| 2303 | { |
| 2304 | |
| 2305 | int retval; |
| 2306 | retval = hci_fm_tune_station(&freq, radio->fm_hdev); |
| 2307 | if (retval < 0) |
| 2308 | FMDERR("Error while setting the frequency : %d\n", retval); |
| 2309 | return retval; |
| 2310 | } |
| 2311 | |
| 2312 | |
| 2313 | static int iris_vidioc_queryctrl(struct file *file, void *priv, |
| 2314 | struct v4l2_queryctrl *qc) |
| 2315 | { |
| 2316 | unsigned char i; |
| 2317 | int retval = -EINVAL; |
| 2318 | |
| 2319 | for (i = 0; i < ARRAY_SIZE(iris_v4l2_queryctrl); i++) { |
| 2320 | if (qc->id && qc->id == iris_v4l2_queryctrl[i].id) { |
| 2321 | memcpy(qc, &(iris_v4l2_queryctrl[i]), sizeof(*qc)); |
| 2322 | retval = 0; |
| 2323 | break; |
| 2324 | } |
| 2325 | } |
| 2326 | |
| 2327 | return retval; |
| 2328 | } |
| 2329 | |
Srinivasa Rao Uppala | cb48ee6 | 2011-10-25 09:57:06 +0530 | [diff] [blame] | 2330 | static int iris_do_calibration(struct iris_device *radio) |
| 2331 | { |
| 2332 | char cal_mode = 0x00; |
| 2333 | int retval = 0x00; |
| 2334 | |
| 2335 | cal_mode = PROCS_CALIB_MODE; |
| 2336 | retval = hci_cmd(HCI_FM_ENABLE_RECV_CMD, |
| 2337 | radio->fm_hdev); |
| 2338 | if (retval < 0) { |
| 2339 | FMDERR("Enable failed before calibration %x", retval); |
| 2340 | return retval; |
| 2341 | } |
| 2342 | retval = radio_hci_request(radio->fm_hdev, hci_fm_do_cal_req, |
| 2343 | (unsigned long)cal_mode, RADIO_HCI_TIMEOUT); |
| 2344 | if (retval < 0) { |
| 2345 | FMDERR("Do Process calibration failed %x", retval); |
| 2346 | return retval; |
| 2347 | } |
| 2348 | cal_mode = DC_CALIB_MODE; |
| 2349 | retval = radio_hci_request(radio->fm_hdev, hci_fm_do_cal_req, |
| 2350 | (unsigned long)cal_mode, RADIO_HCI_TIMEOUT); |
| 2351 | if (retval < 0) { |
| 2352 | FMDERR("Do DC calibration failed %x", retval); |
| 2353 | return retval; |
| 2354 | } |
| 2355 | retval = hci_cmd(HCI_FM_DISABLE_RECV_CMD, |
| 2356 | radio->fm_hdev); |
| 2357 | if (retval < 0) |
| 2358 | FMDERR("Disable Failed after calibration %d", retval); |
| 2359 | return retval; |
| 2360 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2361 | static int iris_vidioc_g_ctrl(struct file *file, void *priv, |
| 2362 | struct v4l2_control *ctrl) |
| 2363 | { |
| 2364 | struct iris_device *radio = video_get_drvdata(video_devdata(file)); |
| 2365 | int retval = 0; |
| 2366 | |
| 2367 | switch (ctrl->id) { |
| 2368 | case V4L2_CID_AUDIO_VOLUME: |
| 2369 | break; |
| 2370 | case V4L2_CID_AUDIO_MUTE: |
| 2371 | ctrl->value = radio->mute_mode.hard_mute; |
| 2372 | break; |
| 2373 | case V4L2_CID_PRIVATE_IRIS_SRCHMODE: |
| 2374 | ctrl->value = radio->g_search_mode; |
| 2375 | break; |
| 2376 | case V4L2_CID_PRIVATE_IRIS_SCANDWELL: |
| 2377 | ctrl->value = radio->g_scan_time; |
| 2378 | break; |
| 2379 | case V4L2_CID_PRIVATE_IRIS_SRCHON: |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2380 | ctrl->value = radio->search_on; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2381 | break; |
| 2382 | case V4L2_CID_PRIVATE_IRIS_STATE: |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2383 | ctrl->value = radio->mode; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2384 | break; |
| 2385 | case V4L2_CID_PRIVATE_IRIS_IOVERC: |
| 2386 | retval = hci_cmd(HCI_FM_STATION_DBG_PARAM_CMD, radio->fm_hdev); |
| 2387 | if (retval < 0) |
| 2388 | return retval; |
| 2389 | ctrl->value = radio->st_dbg_param.io_verc; |
| 2390 | break; |
| 2391 | case V4L2_CID_PRIVATE_IRIS_INTDET: |
| 2392 | retval = hci_cmd(HCI_FM_STATION_DBG_PARAM_CMD, radio->fm_hdev); |
| 2393 | if (retval < 0) |
| 2394 | return retval; |
| 2395 | ctrl->value = radio->st_dbg_param.in_det_out; |
| 2396 | break; |
| 2397 | case V4L2_CID_PRIVATE_IRIS_REGION: |
| 2398 | ctrl->value = radio->region; |
| 2399 | break; |
| 2400 | case V4L2_CID_PRIVATE_IRIS_SIGNAL_TH: |
| 2401 | retval = hci_cmd(HCI_FM_GET_SIGNAL_TH_CMD, radio->fm_hdev); |
| 2402 | break; |
| 2403 | case V4L2_CID_PRIVATE_IRIS_SRCH_PTY: |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2404 | ctrl->value = radio->srch_rds.srch_pty; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2405 | break; |
| 2406 | case V4L2_CID_PRIVATE_IRIS_SRCH_PI: |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2407 | ctrl->value = radio->srch_rds.srch_pi; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2408 | break; |
| 2409 | case V4L2_CID_PRIVATE_IRIS_SRCH_CNT: |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2410 | ctrl->value = radio->srch_st_result.num_stations_found; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2411 | break; |
| 2412 | case V4L2_CID_PRIVATE_IRIS_EMPHASIS: |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2413 | if (radio->mode == FM_RECV) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2414 | ctrl->value = radio->recv_conf.emphasis; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2415 | } else if (radio->mode == FM_TRANS) { |
| 2416 | ctrl->value = radio->trans_conf.emphasis; |
| 2417 | } else { |
| 2418 | FMDERR("Error in radio mode" |
| 2419 | " %d\n", retval); |
| 2420 | return -EINVAL; |
| 2421 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2422 | break; |
| 2423 | case V4L2_CID_PRIVATE_IRIS_RDS_STD: |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2424 | if (radio->mode == FM_RECV) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2425 | ctrl->value = radio->recv_conf.rds_std; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2426 | } else if (radio->mode == FM_TRANS) { |
| 2427 | ctrl->value = radio->trans_conf.rds_std; |
| 2428 | } else { |
| 2429 | FMDERR("Error in radio mode" |
| 2430 | " %d\n", retval); |
| 2431 | return -EINVAL; |
| 2432 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2433 | break; |
| 2434 | case V4L2_CID_PRIVATE_IRIS_SPACING: |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2435 | if (radio->mode == FM_RECV) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2436 | ctrl->value = radio->recv_conf.ch_spacing; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2437 | } else { |
| 2438 | FMDERR("Error in radio mode" |
| 2439 | " %d\n", retval); |
| 2440 | return -EINVAL; |
| 2441 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2442 | break; |
| 2443 | case V4L2_CID_PRIVATE_IRIS_RDSON: |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2444 | if (radio->mode == FM_RECV) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2445 | ctrl->value = radio->recv_conf.rds_std; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2446 | } else { |
| 2447 | FMDERR("Error in radio mode" |
| 2448 | " %d\n", retval); |
| 2449 | return -EINVAL; |
| 2450 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2451 | break; |
| 2452 | case V4L2_CID_PRIVATE_IRIS_RDSGROUP_MASK: |
| 2453 | ctrl->value = radio->rds_grp.rds_grp_enable_mask; |
| 2454 | break; |
| 2455 | case V4L2_CID_PRIVATE_IRIS_RDSGROUP_PROC: |
Srinivasa Rao Uppala | 58273f8 | 2011-08-10 19:07:45 -0700 | [diff] [blame] | 2456 | case V4L2_CID_PRIVATE_IRIS_PSALL: |
| 2457 | ctrl->value = (radio->g_rds_grp_proc_ps << RDS_CONFIG_OFFSET); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2458 | break; |
| 2459 | case V4L2_CID_PRIVATE_IRIS_RDSD_BUF: |
| 2460 | ctrl->value = radio->rds_grp.rds_buf_size; |
| 2461 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2462 | case V4L2_CID_PRIVATE_IRIS_LP_MODE: |
Srinivasa Rao Uppala | f856ae6 | 2011-10-17 18:43:26 +0530 | [diff] [blame] | 2463 | ctrl->value = radio->power_mode; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2464 | break; |
| 2465 | case V4L2_CID_PRIVATE_IRIS_ANTENNA: |
| 2466 | ctrl->value = radio->g_antenna; |
| 2467 | break; |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 2468 | case V4L2_CID_PRIVATE_IRIS_SOFT_MUTE: |
| 2469 | ctrl->value = radio->mute_mode.soft_mute; |
| 2470 | break; |
Srinivasa Rao Uppala | cb48ee6 | 2011-10-25 09:57:06 +0530 | [diff] [blame] | 2471 | case V4L2_CID_PRIVATE_IRIS_DO_CALIBRATION: |
| 2472 | retval = iris_do_calibration(radio); |
| 2473 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2474 | default: |
| 2475 | retval = -EINVAL; |
| 2476 | } |
| 2477 | if (retval < 0) |
| 2478 | FMDERR("get control failed with %d, id: %d\n", |
| 2479 | retval, ctrl->id); |
| 2480 | return retval; |
| 2481 | } |
| 2482 | |
Venkateshwarlu Domakonda | 787af69 | 2011-10-14 21:23:03 +0530 | [diff] [blame] | 2483 | static int iris_vidioc_g_ext_ctrls(struct file *file, void *priv, |
| 2484 | struct v4l2_ext_controls *ctrl) |
| 2485 | { |
| 2486 | int retval = 0; |
| 2487 | char *data = NULL; |
| 2488 | struct iris_device *radio = video_get_drvdata(video_devdata(file)); |
| 2489 | struct hci_fm_def_data_rd_req default_data_rd; |
| 2490 | |
| 2491 | switch ((ctrl->controls[0]).id) { |
| 2492 | case V4L2_CID_PRIVATE_IRIS_READ_DEFAULT: |
| 2493 | data = (ctrl->controls[0]).string; |
| 2494 | memset(&default_data_rd, 0, sizeof(default_data_rd)); |
| 2495 | if (copy_from_user(&default_data_rd.mode, data, |
| 2496 | sizeof(default_data_rd))) |
| 2497 | return -EFAULT; |
| 2498 | retval = hci_def_data_read(&default_data_rd, radio->fm_hdev); |
| 2499 | break; |
| 2500 | default: |
| 2501 | retval = -EINVAL; |
| 2502 | } |
| 2503 | |
| 2504 | return retval; |
| 2505 | } |
| 2506 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2507 | static int iris_vidioc_s_ext_ctrls(struct file *file, void *priv, |
| 2508 | struct v4l2_ext_controls *ctrl) |
| 2509 | { |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2510 | int retval = 0; |
| 2511 | int bytes_to_copy; |
| 2512 | struct hci_fm_tx_ps tx_ps; |
| 2513 | struct hci_fm_tx_rt tx_rt; |
Venkateshwarlu Domakonda | 787af69 | 2011-10-14 21:23:03 +0530 | [diff] [blame] | 2514 | struct hci_fm_def_data_wr_req default_data; |
Srinivasa Rao Uppala | cb48ee6 | 2011-10-25 09:57:06 +0530 | [diff] [blame] | 2515 | struct hci_fm_set_cal_req cal_req; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2516 | |
| 2517 | struct iris_device *radio = video_get_drvdata(video_devdata(file)); |
| 2518 | char *data = NULL; |
| 2519 | |
| 2520 | switch ((ctrl->controls[0]).id) { |
| 2521 | case V4L2_CID_RDS_TX_PS_NAME: |
| 2522 | FMDBG("In V4L2_CID_RDS_TX_PS_NAME\n"); |
| 2523 | /*Pass a sample PS string */ |
| 2524 | |
| 2525 | memset(tx_ps.ps_data, 0, MAX_PS_LENGTH); |
| 2526 | bytes_to_copy = min((int)(ctrl->controls[0]).size, |
| 2527 | MAX_PS_LENGTH); |
| 2528 | data = (ctrl->controls[0]).string; |
| 2529 | |
| 2530 | if (copy_from_user(tx_ps.ps_data, |
| 2531 | data, bytes_to_copy)) |
| 2532 | return -EFAULT; |
| 2533 | tx_ps.ps_control = 0x01; |
| 2534 | tx_ps.pi = radio->pi; |
| 2535 | tx_ps.pty = radio->pty; |
| 2536 | tx_ps.ps_repeatcount = radio->ps_repeatcount; |
| 2537 | tx_ps.ps_len = bytes_to_copy; |
| 2538 | |
| 2539 | retval = radio_hci_request(radio->fm_hdev, hci_trans_ps_req, |
| 2540 | (unsigned long)&tx_ps, RADIO_HCI_TIMEOUT); |
| 2541 | break; |
| 2542 | case V4L2_CID_RDS_TX_RADIO_TEXT: |
| 2543 | bytes_to_copy = |
| 2544 | min((int)(ctrl->controls[0]).size, MAX_RT_LENGTH); |
| 2545 | data = (ctrl->controls[0]).string; |
| 2546 | |
| 2547 | memset(tx_rt.rt_data, 0, MAX_RT_LENGTH); |
| 2548 | |
| 2549 | if (copy_from_user(tx_rt.rt_data, |
| 2550 | data, bytes_to_copy)) |
| 2551 | return -EFAULT; |
| 2552 | |
| 2553 | tx_rt.rt_control = 0x01; |
| 2554 | tx_rt.pi = radio->pi; |
| 2555 | tx_rt.pty = radio->pty; |
| 2556 | tx_rt.ps_len = bytes_to_copy; |
| 2557 | |
| 2558 | retval = radio_hci_request(radio->fm_hdev, hci_trans_rt_req, |
| 2559 | (unsigned long)&tx_rt, RADIO_HCI_TIMEOUT); |
| 2560 | break; |
Venkateshwarlu Domakonda | 787af69 | 2011-10-14 21:23:03 +0530 | [diff] [blame] | 2561 | case V4L2_CID_PRIVATE_IRIS_WRITE_DEFAULT: |
| 2562 | data = (ctrl->controls[0]).string; |
| 2563 | memset(&default_data, 0, sizeof(default_data)); |
| 2564 | if (copy_from_user(&default_data, data, sizeof(default_data))) |
| 2565 | return -EFAULT; |
| 2566 | retval = hci_def_data_write(&default_data, radio->fm_hdev); |
Srinivasa Rao Uppala | cb48ee6 | 2011-10-25 09:57:06 +0530 | [diff] [blame] | 2567 | break; |
| 2568 | case V4L2_CID_PRIVATE_IRIS_SET_CALIBRATION: |
| 2569 | FMDERR("In Set Calibration"); |
| 2570 | data = (ctrl->controls[0]).string; |
| 2571 | bytes_to_copy = (ctrl->controls[0]).size; |
| 2572 | memset(cal_req.data, 0, MAX_CALIB_SIZE); |
| 2573 | cal_req.mode = PROCS_CALIB_MODE; |
| 2574 | if (copy_from_user(&cal_req.data[0], |
| 2575 | data, PROCS_CALIB_SIZE)) |
| 2576 | return -EFAULT; |
| 2577 | retval = radio_hci_request(radio->fm_hdev, hci_fm_set_cal_req, |
| 2578 | (unsigned long)&cal_req, RADIO_HCI_TIMEOUT); |
| 2579 | if (retval < 0) |
| 2580 | FMDERR("Set Process calibration failed %d", retval); |
| 2581 | if (copy_from_user(&cal_req.data[PROCS_CALIB_SIZE], |
| 2582 | data, DC_CALIB_SIZE)) |
| 2583 | return -EFAULT; |
| 2584 | cal_req.mode = DC_CALIB_MODE; |
| 2585 | retval = radio_hci_request(radio->fm_hdev, hci_fm_set_cal_req, |
| 2586 | (unsigned long)&cal_req, RADIO_HCI_TIMEOUT); |
| 2587 | if (retval < 0) |
| 2588 | FMDERR("Set DC calibration failed %d", retval); |
Venkateshwarlu Domakonda | 787af69 | 2011-10-14 21:23:03 +0530 | [diff] [blame] | 2589 | break; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2590 | default: |
| 2591 | FMDBG("Shouldn't reach here\n"); |
| 2592 | retval = -1; |
| 2593 | } |
| 2594 | return retval; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2595 | } |
| 2596 | |
| 2597 | static int iris_vidioc_s_ctrl(struct file *file, void *priv, |
| 2598 | struct v4l2_control *ctrl) |
| 2599 | { |
| 2600 | struct iris_device *radio = video_get_drvdata(video_devdata(file)); |
| 2601 | int retval = 0; |
| 2602 | unsigned int rds_grps_proc = 0; |
| 2603 | __u8 temp_val = 0; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2604 | unsigned long arg = 0; |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2605 | struct hci_fm_tx_ps tx_ps = {0}; |
| 2606 | struct hci_fm_tx_rt tx_rt = {0}; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2607 | |
| 2608 | switch (ctrl->id) { |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 2609 | case V4L2_CID_PRIVATE_IRIS_TX_TONE: |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2610 | radio->tone_freq = ctrl->value; |
| 2611 | retval = radio_hci_request(radio->fm_hdev, |
| 2612 | hci_fm_tone_generator, arg, |
| 2613 | msecs_to_jiffies(RADIO_HCI_TIMEOUT)); |
| 2614 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2615 | case V4L2_CID_AUDIO_VOLUME: |
| 2616 | break; |
| 2617 | case V4L2_CID_AUDIO_MUTE: |
| 2618 | radio->mute_mode.hard_mute = ctrl->value; |
| 2619 | radio->mute_mode.soft_mute = IOC_SFT_MUTE; |
| 2620 | retval = hci_set_fm_mute_mode( |
| 2621 | &radio->mute_mode, |
| 2622 | radio->fm_hdev); |
| 2623 | if (retval < 0) |
| 2624 | FMDERR("Error while set FM hard mute"" %d\n", |
| 2625 | retval); |
| 2626 | break; |
| 2627 | case V4L2_CID_PRIVATE_IRIS_SRCHMODE: |
| 2628 | radio->g_search_mode = ctrl->value; |
| 2629 | break; |
| 2630 | case V4L2_CID_PRIVATE_IRIS_SCANDWELL: |
| 2631 | radio->g_scan_time = ctrl->value; |
| 2632 | break; |
| 2633 | case V4L2_CID_PRIVATE_IRIS_SRCHON: |
| 2634 | iris_search(radio, ctrl->value, SRCH_DIR_UP); |
| 2635 | break; |
| 2636 | case V4L2_CID_PRIVATE_IRIS_STATE: |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2637 | switch (ctrl->value) { |
| 2638 | case FM_RECV: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2639 | retval = hci_cmd(HCI_FM_ENABLE_RECV_CMD, |
| 2640 | radio->fm_hdev); |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2641 | |
| 2642 | radio->mode = FM_RECV; |
| 2643 | |
| 2644 | if (retval < 0) |
| 2645 | FMDERR("Error while enabling RECV FM" |
Srinivasa Rao Uppala | 0ffb5d6 | 2011-08-02 17:54:13 -0700 | [diff] [blame] | 2646 | " %d\n", retval); |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2647 | radio->mute_mode.soft_mute = CTRL_ON; |
| 2648 | retval = hci_set_fm_mute_mode( |
| 2649 | &radio->mute_mode, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2650 | radio->fm_hdev); |
Srinivasa Rao Uppala | cb48ee6 | 2011-10-25 09:57:06 +0530 | [diff] [blame] | 2651 | if (retval < 0) { |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2652 | FMDERR("Failed to enable Smute\n"); |
Srinivasa Rao Uppala | cb48ee6 | 2011-10-25 09:57:06 +0530 | [diff] [blame] | 2653 | return retval; |
| 2654 | } |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2655 | radio->stereo_mode.stereo_mode = CTRL_OFF; |
| 2656 | radio->stereo_mode.sig_blend = CTRL_ON; |
| 2657 | radio->stereo_mode.intf_blend = CTRL_ON; |
| 2658 | radio->stereo_mode.most_switch = CTRL_ON; |
| 2659 | retval = hci_set_fm_stereo_mode( |
| 2660 | &radio->stereo_mode, |
| 2661 | radio->fm_hdev); |
Srinivasa Rao Uppala | cb48ee6 | 2011-10-25 09:57:06 +0530 | [diff] [blame] | 2662 | if (retval < 0) { |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2663 | FMDERR("Failed to set stereo mode\n"); |
Srinivasa Rao Uppala | cb48ee6 | 2011-10-25 09:57:06 +0530 | [diff] [blame] | 2664 | return retval; |
| 2665 | } |
Srinivasa Rao Uppala | f0d1374 | 2011-09-08 10:13:13 +0530 | [diff] [blame] | 2666 | retval = hci_cmd(HCI_FM_GET_RECV_CONF_CMD, |
| 2667 | radio->fm_hdev); |
| 2668 | if (retval < 0) |
| 2669 | FMDERR("Failed to get the Recv Config\n"); |
Srinivasa Rao Uppala | 07522d9 | 2011-08-16 05:09:30 -0700 | [diff] [blame] | 2670 | break; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2671 | case FM_TRANS: |
| 2672 | retval = hci_cmd(HCI_FM_ENABLE_TRANS_CMD, |
| 2673 | radio->fm_hdev); |
| 2674 | radio->mode = FM_TRANS; |
| 2675 | |
| 2676 | if (retval < 0) |
| 2677 | FMDERR("Error while enabling TRANS FM" |
| 2678 | " %d\n", retval); |
Srinivasa Rao Uppala | 07522d9 | 2011-08-16 05:09:30 -0700 | [diff] [blame] | 2679 | break; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2680 | case FM_OFF: |
| 2681 | switch (radio->mode) { |
| 2682 | case FM_RECV: |
| 2683 | retval = hci_cmd(HCI_FM_DISABLE_RECV_CMD, |
| 2684 | radio->fm_hdev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2685 | if (retval < 0) |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2686 | FMDERR("Err on disable recv FM" |
| 2687 | " %d\n", retval); |
| 2688 | break; |
| 2689 | case FM_TRANS: |
| 2690 | retval = hci_cmd(HCI_FM_DISABLE_TRANS_CMD, |
| 2691 | radio->fm_hdev); |
| 2692 | |
Srinivasa Rao Uppala | 0ffb5d6 | 2011-08-02 17:54:13 -0700 | [diff] [blame] | 2693 | if (retval < 0) |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2694 | FMDERR("Err disabling trans FM" |
Srinivasa Rao Uppala | 0ffb5d6 | 2011-08-02 17:54:13 -0700 | [diff] [blame] | 2695 | " %d\n", retval); |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2696 | break; |
| 2697 | default: |
| 2698 | retval = -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2699 | } |
Srinivasa Rao Uppala | cc62b1c | 2011-08-22 19:15:29 +0530 | [diff] [blame] | 2700 | break; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2701 | default: |
| 2702 | retval = -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2703 | } |
| 2704 | break; |
| 2705 | case V4L2_CID_PRIVATE_IRIS_REGION: |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2706 | if (radio->mode == FM_RECV) { |
| 2707 | retval = iris_recv_set_region(radio, ctrl->value); |
| 2708 | } else { |
| 2709 | if (radio->mode == FM_TRANS) |
| 2710 | retval = iris_trans_set_region(radio, |
| 2711 | ctrl->value); |
| 2712 | else |
| 2713 | retval = -EINVAL; |
| 2714 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2715 | break; |
| 2716 | case V4L2_CID_PRIVATE_IRIS_SIGNAL_TH: |
| 2717 | temp_val = ctrl->value; |
| 2718 | retval = hci_fm_set_signal_threshold( |
| 2719 | &temp_val, |
| 2720 | radio->fm_hdev); |
| 2721 | if (retval < 0) { |
| 2722 | FMDERR("Error while setting signal threshold\n"); |
| 2723 | break; |
| 2724 | } |
| 2725 | break; |
| 2726 | case V4L2_CID_PRIVATE_IRIS_SRCH_PTY: |
| 2727 | radio->srch_rds.srch_pty = ctrl->value; |
| 2728 | radio->srch_st_list.srch_pty = ctrl->value; |
| 2729 | break; |
| 2730 | case V4L2_CID_PRIVATE_IRIS_SRCH_PI: |
| 2731 | radio->srch_rds.srch_pi = ctrl->value; |
| 2732 | break; |
| 2733 | case V4L2_CID_PRIVATE_IRIS_SRCH_CNT: |
| 2734 | break; |
| 2735 | case V4L2_CID_PRIVATE_IRIS_SPACING: |
| 2736 | radio->recv_conf.ch_spacing = ctrl->value; |
| 2737 | break; |
| 2738 | case V4L2_CID_PRIVATE_IRIS_EMPHASIS: |
Ankur Nandwani | 8f972e5 | 2011-08-24 11:48:32 -0700 | [diff] [blame] | 2739 | switch (radio->mode) { |
| 2740 | case FM_RECV: |
| 2741 | radio->recv_conf.emphasis = ctrl->value; |
| 2742 | retval = hci_set_fm_recv_conf( |
| 2743 | &radio->recv_conf, |
| 2744 | radio->fm_hdev); |
| 2745 | if (retval < 0) |
| 2746 | FMDERR("Error in setting emphasis"); |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2747 | break; |
Ankur Nandwani | 8f972e5 | 2011-08-24 11:48:32 -0700 | [diff] [blame] | 2748 | case FM_TRANS: |
| 2749 | radio->trans_conf.emphasis = ctrl->value; |
| 2750 | retval = hci_set_fm_trans_conf( |
| 2751 | &radio->trans_conf, |
| 2752 | radio->fm_hdev); |
| 2753 | if (retval < 0) |
| 2754 | FMDERR("Error in setting emphasis"); |
| 2755 | break; |
| 2756 | default: |
| 2757 | retval = -EINVAL; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2758 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2759 | break; |
| 2760 | case V4L2_CID_PRIVATE_IRIS_RDS_STD: |
Ankur Nandwani | 8f972e5 | 2011-08-24 11:48:32 -0700 | [diff] [blame] | 2761 | switch (radio->mode) { |
| 2762 | case FM_RECV: |
| 2763 | radio->recv_conf.rds_std = ctrl->value; |
| 2764 | retval = hci_set_fm_recv_conf( |
| 2765 | &radio->recv_conf, |
| 2766 | radio->fm_hdev); |
| 2767 | if (retval < 0) |
| 2768 | FMDERR("Error in rds_std"); |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2769 | break; |
Ankur Nandwani | 8f972e5 | 2011-08-24 11:48:32 -0700 | [diff] [blame] | 2770 | case FM_TRANS: |
| 2771 | radio->trans_conf.rds_std = ctrl->value; |
| 2772 | retval = hci_set_fm_trans_conf( |
| 2773 | &radio->trans_conf, |
| 2774 | radio->fm_hdev); |
| 2775 | if (retval < 0) |
| 2776 | FMDERR("Error in rds_Std"); |
| 2777 | break; |
| 2778 | default: |
| 2779 | retval = -EINVAL; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2780 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2781 | break; |
| 2782 | case V4L2_CID_PRIVATE_IRIS_RDSON: |
Ankur Nandwani | 8f972e5 | 2011-08-24 11:48:32 -0700 | [diff] [blame] | 2783 | switch (radio->mode) { |
| 2784 | case FM_RECV: |
| 2785 | radio->recv_conf.rds_std = ctrl->value; |
| 2786 | retval = hci_set_fm_recv_conf( |
| 2787 | &radio->recv_conf, |
| 2788 | radio->fm_hdev); |
| 2789 | if (retval < 0) |
| 2790 | FMDERR("Error in rds_std"); |
| 2791 | break; |
| 2792 | case FM_TRANS: |
| 2793 | radio->trans_conf.rds_std = ctrl->value; |
| 2794 | retval = hci_set_fm_trans_conf( |
| 2795 | &radio->trans_conf, |
| 2796 | radio->fm_hdev); |
| 2797 | if (retval < 0) |
| 2798 | FMDERR("Error in rds_Std"); |
| 2799 | break; |
| 2800 | default: |
| 2801 | retval = -EINVAL; |
| 2802 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2803 | break; |
| 2804 | case V4L2_CID_PRIVATE_IRIS_RDSGROUP_MASK: |
| 2805 | radio->rds_grp.rds_grp_enable_mask = ctrl->value; |
| 2806 | retval = hci_fm_rds_grp(&radio->rds_grp, radio->fm_hdev); |
| 2807 | break; |
| 2808 | case V4L2_CID_PRIVATE_IRIS_RDSGROUP_PROC: |
| 2809 | rds_grps_proc = radio->g_rds_grp_proc_ps | ctrl->value; |
Srinivasa Rao Uppala | 58273f8 | 2011-08-10 19:07:45 -0700 | [diff] [blame] | 2810 | radio->g_rds_grp_proc_ps = (rds_grps_proc >> RDS_CONFIG_OFFSET); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2811 | retval = hci_fm_rds_grps_process( |
Srinivasa Rao Uppala | 58273f8 | 2011-08-10 19:07:45 -0700 | [diff] [blame] | 2812 | &radio->g_rds_grp_proc_ps, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2813 | radio->fm_hdev); |
| 2814 | break; |
| 2815 | case V4L2_CID_PRIVATE_IRIS_RDSD_BUF: |
| 2816 | radio->rds_grp.rds_buf_size = ctrl->value; |
| 2817 | break; |
| 2818 | case V4L2_CID_PRIVATE_IRIS_PSALL: |
Srinivasa Rao Uppala | 58273f8 | 2011-08-10 19:07:45 -0700 | [diff] [blame] | 2819 | rds_grps_proc = (ctrl->value << RDS_CONFIG_OFFSET); |
| 2820 | radio->g_rds_grp_proc_ps |= rds_grps_proc; |
| 2821 | retval = hci_fm_rds_grps_process( |
| 2822 | &radio->g_rds_grp_proc_ps, |
| 2823 | radio->fm_hdev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2824 | break; |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2825 | case V4L2_CID_PRIVATE_IRIS_AF_JUMP: |
| 2826 | rds_grps_proc = (ctrl->value << RDS_AF_JUMP_OFFSET); |
| 2827 | radio->g_rds_grp_proc_ps |= rds_grps_proc; |
| 2828 | retval = hci_fm_rds_grps_process( |
| 2829 | &radio->g_rds_grp_proc_ps, |
| 2830 | radio->fm_hdev); |
| 2831 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2832 | case V4L2_CID_PRIVATE_IRIS_LP_MODE: |
Srinivasa Rao Uppala | f856ae6 | 2011-10-17 18:43:26 +0530 | [diff] [blame] | 2833 | set_low_power_mode(radio, ctrl->value); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2834 | break; |
| 2835 | case V4L2_CID_PRIVATE_IRIS_ANTENNA: |
| 2836 | temp_val = ctrl->value; |
| 2837 | retval = hci_fm_set_antenna(&temp_val, radio->fm_hdev); |
| 2838 | break; |
| 2839 | case V4L2_CID_RDS_TX_PTY: |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2840 | radio->pty = ctrl->value; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2841 | break; |
| 2842 | case V4L2_CID_RDS_TX_PI: |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2843 | radio->pi = ctrl->value; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2844 | break; |
| 2845 | case V4L2_CID_PRIVATE_IRIS_STOP_RDS_TX_PS_NAME: |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2846 | tx_ps.ps_control = 0x00; |
| 2847 | retval = radio_hci_request(radio->fm_hdev, hci_trans_ps_req, |
| 2848 | (unsigned long)&tx_ps, RADIO_HCI_TIMEOUT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2849 | break; |
| 2850 | case V4L2_CID_PRIVATE_IRIS_STOP_RDS_TX_RT: |
Srinivasa Rao Uppala | 3c7a8eb | 2011-09-18 09:10:21 +0530 | [diff] [blame] | 2851 | tx_rt.rt_control = 0x00; |
| 2852 | retval = radio_hci_request(radio->fm_hdev, hci_trans_rt_req, |
| 2853 | (unsigned long)&tx_rt, RADIO_HCI_TIMEOUT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2854 | break; |
| 2855 | case V4L2_CID_PRIVATE_IRIS_TX_SETPSREPEATCOUNT: |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2856 | radio->ps_repeatcount = ctrl->value; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2857 | break; |
| 2858 | case V4L2_CID_TUNE_POWER_LEVEL: |
| 2859 | break; |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 2860 | case V4L2_CID_PRIVATE_IRIS_SOFT_MUTE: |
| 2861 | radio->mute_mode.soft_mute = ctrl->value; |
| 2862 | retval = hci_set_fm_mute_mode( |
| 2863 | &radio->mute_mode, |
| 2864 | radio->fm_hdev); |
| 2865 | if (retval < 0) |
| 2866 | FMDERR("Error while setting FM soft mute"" %d\n", |
| 2867 | retval); |
| 2868 | break; |
| 2869 | case V4L2_CID_PRIVATE_IRIS_RIVA_ACCS_ADDR: |
| 2870 | radio->riva_data_req.cmd_params.start_addr = ctrl->value; |
| 2871 | break; |
| 2872 | case V4L2_CID_PRIVATE_IRIS_RIVA_ACCS_LEN: |
| 2873 | radio->riva_data_req.cmd_params.length = ctrl->value; |
| 2874 | break; |
| 2875 | case V4L2_CID_PRIVATE_IRIS_RIVA_POKE: |
| 2876 | memcpy(radio->riva_data_req.data, (void *)ctrl->value, |
| 2877 | radio->riva_data_req.cmd_params.length); |
| 2878 | radio->riva_data_req.cmd_params.subopcode = RIVA_POKE_OPCODE; |
| 2879 | retval = hci_poke_data(&radio->riva_data_req , radio->fm_hdev); |
| 2880 | break; |
| 2881 | case V4L2_CID_PRIVATE_IRIS_SSBI_ACCS_ADDR: |
| 2882 | radio->ssbi_data_accs.start_addr = ctrl->value; |
| 2883 | break; |
| 2884 | case V4L2_CID_PRIVATE_IRIS_SSBI_POKE: |
| 2885 | radio->ssbi_data_accs.data = ctrl->value; |
| 2886 | retval = hci_ssbi_poke_reg(&radio->ssbi_data_accs , |
| 2887 | radio->fm_hdev); |
| 2888 | break; |
| 2889 | case V4L2_CID_PRIVATE_IRIS_RIVA_PEEK: |
| 2890 | radio->riva_data_req.cmd_params.subopcode = RIVA_PEEK_OPCODE; |
| 2891 | ctrl->value = hci_peek_data(&radio->riva_data_req.cmd_params , |
| 2892 | radio->fm_hdev); |
| 2893 | break; |
| 2894 | case V4L2_CID_PRIVATE_IRIS_SSBI_PEEK: |
| 2895 | radio->ssbi_peek_reg.start_address = ctrl->value; |
| 2896 | hci_ssbi_peek_reg(&radio->ssbi_peek_reg, radio->fm_hdev); |
| 2897 | break; |
Srinivasa Rao Uppala | 0f4098f | 2011-09-06 16:46:28 +0530 | [diff] [blame] | 2898 | case V4L2_CID_PRIVATE_IRIS_RDS_GRP_COUNTERS: |
| 2899 | temp_val = ctrl->value; |
| 2900 | hci_read_grp_counters(&temp_val, radio->fm_hdev); |
| 2901 | break; |
| 2902 | case V4L2_CID_PRIVATE_IRIS_HLSI: |
| 2903 | retval = hci_cmd(HCI_FM_GET_RECV_CONF_CMD, |
| 2904 | radio->fm_hdev); |
| 2905 | if (retval) |
| 2906 | break; |
| 2907 | radio->recv_conf.hlsi = ctrl->value; |
| 2908 | retval = hci_set_fm_recv_conf( |
| 2909 | &radio->recv_conf, |
| 2910 | radio->fm_hdev); |
| 2911 | break; |
| 2912 | case V4L2_CID_PRIVATE_IRIS_SET_NOTCH_FILTER: |
| 2913 | temp_val = ctrl->value; |
| 2914 | retval = hci_set_notch_filter(&temp_val, radio->fm_hdev); |
| 2915 | break; |
Srinivasa Rao Uppala | abc8efa | 2011-08-02 14:31:30 -0700 | [diff] [blame] | 2916 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2917 | default: |
| 2918 | retval = -EINVAL; |
| 2919 | } |
| 2920 | return retval; |
| 2921 | } |
| 2922 | |
| 2923 | static int iris_vidioc_g_tuner(struct file *file, void *priv, |
| 2924 | struct v4l2_tuner *tuner) |
| 2925 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2926 | int retval; |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2927 | struct iris_device *radio = video_get_drvdata(video_devdata(file)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2928 | if (tuner->index > 0) |
| 2929 | return -EINVAL; |
| 2930 | |
| 2931 | retval = hci_cmd(HCI_FM_GET_STATION_PARAM_CMD, radio->fm_hdev); |
| 2932 | if (retval < 0) |
| 2933 | return retval; |
| 2934 | |
| 2935 | tuner->type = V4L2_TUNER_RADIO; |
| 2936 | tuner->rangelow = radio->recv_conf.band_low_limit * TUNE_PARAM; |
| 2937 | tuner->rangehigh = radio->recv_conf.band_high_limit * TUNE_PARAM; |
| 2938 | tuner->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; |
| 2939 | tuner->capability = V4L2_TUNER_CAP_LOW; |
| 2940 | tuner->signal = radio->fm_st_rsp.station_rsp.rssi; |
| 2941 | tuner->audmode = radio->fm_st_rsp.station_rsp.stereo_prg; |
| 2942 | tuner->afc = 0; |
| 2943 | |
| 2944 | return 0; |
| 2945 | } |
| 2946 | |
| 2947 | static int iris_vidioc_s_tuner(struct file *file, void *priv, |
| 2948 | struct v4l2_tuner *tuner) |
| 2949 | { |
| 2950 | struct iris_device *radio = video_get_drvdata(video_devdata(file)); |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2951 | int retval = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2952 | if (tuner->index > 0) |
| 2953 | return -EINVAL; |
| 2954 | |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2955 | if (radio->mode == FM_RECV) { |
| 2956 | radio->recv_conf.band_low_limit = tuner->rangelow / TUNE_PARAM; |
| 2957 | radio->recv_conf.band_high_limit = |
| 2958 | tuner->rangehigh / TUNE_PARAM; |
| 2959 | if (tuner->audmode == V4L2_TUNER_MODE_MONO) { |
| 2960 | radio->stereo_mode.stereo_mode = 0x01; |
| 2961 | retval = hci_set_fm_stereo_mode( |
| 2962 | &radio->stereo_mode, |
| 2963 | radio->fm_hdev); |
| 2964 | } else { |
| 2965 | radio->stereo_mode.stereo_mode = 0x00; |
| 2966 | retval = hci_set_fm_stereo_mode( |
| 2967 | &radio->stereo_mode, |
| 2968 | radio->fm_hdev); |
| 2969 | } |
| 2970 | if (retval < 0) |
| 2971 | FMDERR(": set tuner failed with %d\n", retval); |
| 2972 | return retval; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2973 | } else { |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2974 | if (radio->mode == FM_TRANS) { |
| 2975 | radio->trans_conf.band_low_limit = |
| 2976 | tuner->rangelow / TUNE_PARAM; |
| 2977 | radio->trans_conf.band_high_limit = |
| 2978 | tuner->rangehigh / TUNE_PARAM; |
| 2979 | } else { |
| 2980 | return -EINVAL; |
| 2981 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2982 | } |
Ankur Nandwani | d928d54 | 2011-08-11 13:15:41 -0700 | [diff] [blame] | 2983 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2984 | return retval; |
| 2985 | } |
| 2986 | |
| 2987 | static int iris_vidioc_g_frequency(struct file *file, void *priv, |
| 2988 | struct v4l2_frequency *freq) |
| 2989 | { |
| 2990 | struct iris_device *radio = video_get_drvdata(video_devdata(file)); |
| 2991 | int retval; |
| 2992 | |
| 2993 | freq->type = V4L2_TUNER_RADIO; |
| 2994 | retval = hci_cmd(HCI_FM_GET_STATION_PARAM_CMD, radio->fm_hdev); |
| 2995 | if (retval < 0) |
| 2996 | FMDERR("get frequency failed %d\n", retval); |
| 2997 | else |
| 2998 | freq->frequency = |
| 2999 | radio->fm_st_rsp.station_rsp.station_freq * TUNE_PARAM; |
| 3000 | return retval; |
| 3001 | } |
| 3002 | |
| 3003 | static int iris_vidioc_s_frequency(struct file *file, void *priv, |
| 3004 | struct v4l2_frequency *freq) |
| 3005 | { |
| 3006 | struct iris_device *radio = video_get_drvdata(video_devdata(file)); |
| 3007 | int retval = -1; |
| 3008 | freq->frequency = freq->frequency / TUNE_PARAM; |
| 3009 | |
| 3010 | if (freq->type != V4L2_TUNER_RADIO) |
| 3011 | return -EINVAL; |
| 3012 | |
Ankur Nandwani | 8f972e5 | 2011-08-24 11:48:32 -0700 | [diff] [blame] | 3013 | /* We turn off RDS prior to tuning to a new station. |
| 3014 | because of a bug in SoC which prevents tuning |
| 3015 | during RDS transmission. |
| 3016 | */ |
| 3017 | if (radio->mode == FM_TRANS |
| 3018 | && (radio->trans_conf.rds_std == 0 || |
| 3019 | radio->trans_conf.rds_std == 1)) { |
| 3020 | radio->prev_trans_rds = radio->trans_conf.rds_std; |
| 3021 | radio->trans_conf.rds_std = 2; |
| 3022 | hci_set_fm_trans_conf(&radio->trans_conf, |
| 3023 | radio->fm_hdev); |
| 3024 | } |
| 3025 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3026 | retval = iris_set_freq(radio, freq->frequency); |
Ankur Nandwani | 8f972e5 | 2011-08-24 11:48:32 -0700 | [diff] [blame] | 3027 | |
| 3028 | if (radio->mode == FM_TRANS |
| 3029 | && radio->trans_conf.rds_std == 2 |
| 3030 | && (radio->prev_trans_rds == 1 |
| 3031 | || radio->prev_trans_rds == 0)) { |
| 3032 | radio->trans_conf.rds_std = radio->prev_trans_rds; |
| 3033 | hci_set_fm_trans_conf(&radio->trans_conf, |
| 3034 | radio->fm_hdev); |
| 3035 | } |
| 3036 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3037 | if (retval < 0) |
| 3038 | FMDERR(" set frequency failed with %d\n", retval); |
| 3039 | return retval; |
| 3040 | } |
| 3041 | |
| 3042 | static int iris_vidioc_dqbuf(struct file *file, void *priv, |
| 3043 | struct v4l2_buffer *buffer) |
| 3044 | { |
| 3045 | struct iris_device *radio = video_get_drvdata(video_devdata(file)); |
| 3046 | enum iris_buf_t buf_type = buffer->index; |
| 3047 | struct kfifo *data_fifo; |
| 3048 | unsigned char *buf = (unsigned char *)buffer->m.userptr; |
| 3049 | unsigned int len = buffer->length; |
| 3050 | if (!access_ok(VERIFY_WRITE, buf, len)) |
| 3051 | return -EFAULT; |
| 3052 | if ((buf_type < IRIS_BUF_MAX) && (buf_type >= 0)) { |
| 3053 | data_fifo = &radio->data_buf[buf_type]; |
| 3054 | if (buf_type == IRIS_BUF_EVENTS) |
| 3055 | if (wait_event_interruptible(radio->event_queue, |
| 3056 | kfifo_len(data_fifo)) < 0) |
| 3057 | return -EINTR; |
| 3058 | } else { |
| 3059 | FMDERR("invalid buffer type\n"); |
| 3060 | return -EINVAL; |
| 3061 | } |
| 3062 | buffer->bytesused = kfifo_out_locked(data_fifo, buf, len, |
| 3063 | &radio->buf_lock[buf_type]); |
| 3064 | |
| 3065 | return 0; |
| 3066 | } |
| 3067 | |
| 3068 | static int iris_vidioc_g_fmt_type_private(struct file *file, void *priv, |
| 3069 | struct v4l2_format *f) |
| 3070 | { |
| 3071 | return 0; |
| 3072 | |
| 3073 | } |
| 3074 | |
| 3075 | static int iris_vidioc_s_hw_freq_seek(struct file *file, void *priv, |
| 3076 | struct v4l2_hw_freq_seek *seek) |
| 3077 | { |
| 3078 | struct iris_device *radio = video_get_drvdata(video_devdata(file)); |
| 3079 | int dir; |
| 3080 | if (seek->seek_upward) |
| 3081 | dir = SRCH_DIR_UP; |
| 3082 | else |
| 3083 | dir = SRCH_DIR_DOWN; |
| 3084 | return iris_search(radio, CTRL_ON, dir); |
| 3085 | } |
| 3086 | |
| 3087 | static int iris_vidioc_querycap(struct file *file, void *priv, |
| 3088 | struct v4l2_capability *capability) |
| 3089 | { |
| 3090 | struct iris_device *radio; |
| 3091 | radio = video_get_drvdata(video_devdata(file)); |
| 3092 | strlcpy(capability->driver, DRIVER_NAME, sizeof(capability->driver)); |
| 3093 | strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card)); |
| 3094 | radio->g_cap = capability; |
| 3095 | return 0; |
| 3096 | } |
| 3097 | |
| 3098 | |
| 3099 | static const struct v4l2_ioctl_ops iris_ioctl_ops = { |
| 3100 | .vidioc_querycap = iris_vidioc_querycap, |
| 3101 | .vidioc_queryctrl = iris_vidioc_queryctrl, |
| 3102 | .vidioc_g_ctrl = iris_vidioc_g_ctrl, |
| 3103 | .vidioc_s_ctrl = iris_vidioc_s_ctrl, |
| 3104 | .vidioc_g_tuner = iris_vidioc_g_tuner, |
| 3105 | .vidioc_s_tuner = iris_vidioc_s_tuner, |
| 3106 | .vidioc_g_frequency = iris_vidioc_g_frequency, |
| 3107 | .vidioc_s_frequency = iris_vidioc_s_frequency, |
| 3108 | .vidioc_s_hw_freq_seek = iris_vidioc_s_hw_freq_seek, |
| 3109 | .vidioc_dqbuf = iris_vidioc_dqbuf, |
| 3110 | .vidioc_g_fmt_type_private = iris_vidioc_g_fmt_type_private, |
| 3111 | .vidioc_s_ext_ctrls = iris_vidioc_s_ext_ctrls, |
Venkateshwarlu Domakonda | 787af69 | 2011-10-14 21:23:03 +0530 | [diff] [blame] | 3112 | .vidioc_g_ext_ctrls = iris_vidioc_g_ext_ctrls, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3113 | }; |
| 3114 | |
| 3115 | static const struct v4l2_file_operations iris_fops = { |
| 3116 | .owner = THIS_MODULE, |
| 3117 | .unlocked_ioctl = video_ioctl2, |
| 3118 | }; |
| 3119 | |
| 3120 | static struct video_device iris_viddev_template = { |
| 3121 | .fops = &iris_fops, |
| 3122 | .ioctl_ops = &iris_ioctl_ops, |
| 3123 | .name = DRIVER_NAME, |
| 3124 | .release = video_device_release, |
| 3125 | }; |
| 3126 | |
| 3127 | static struct video_device *video_get_dev(void) |
| 3128 | { |
| 3129 | return priv_videodev; |
| 3130 | } |
| 3131 | |
| 3132 | static int __init iris_probe(struct platform_device *pdev) |
| 3133 | { |
| 3134 | struct iris_device *radio; |
| 3135 | int retval; |
| 3136 | int radio_nr = -1; |
| 3137 | int i; |
| 3138 | |
| 3139 | if (!pdev) { |
| 3140 | FMDERR(": pdev is null\n"); |
| 3141 | return -ENOMEM; |
| 3142 | } |
| 3143 | |
| 3144 | radio = kzalloc(sizeof(struct iris_device), GFP_KERNEL); |
| 3145 | if (!radio) { |
| 3146 | FMDERR(": Could not allocate radio device\n"); |
| 3147 | return -ENOMEM; |
| 3148 | } |
| 3149 | |
| 3150 | radio->dev = &pdev->dev; |
| 3151 | platform_set_drvdata(pdev, radio); |
| 3152 | |
| 3153 | radio->videodev = video_device_alloc(); |
| 3154 | if (!radio->videodev) { |
| 3155 | FMDERR(": Could not allocate V4L device\n"); |
| 3156 | kfree(radio); |
| 3157 | return -ENOMEM; |
| 3158 | } |
| 3159 | |
| 3160 | memcpy(radio->videodev, &iris_viddev_template, |
| 3161 | sizeof(iris_viddev_template)); |
| 3162 | |
| 3163 | for (i = 0; i < IRIS_BUF_MAX; i++) { |
| 3164 | int kfifo_alloc_rc = 0; |
| 3165 | spin_lock_init(&radio->buf_lock[i]); |
| 3166 | |
Srinivasa Rao Uppala | 6cc0e32 | 2011-08-12 10:54:48 -0700 | [diff] [blame] | 3167 | if ((i == IRIS_BUF_RAW_RDS) || (i == IRIS_BUF_PEEK)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3168 | kfifo_alloc_rc = kfifo_alloc(&radio->data_buf[i], |
| 3169 | rds_buf*3, GFP_KERNEL); |
| 3170 | else |
| 3171 | kfifo_alloc_rc = kfifo_alloc(&radio->data_buf[i], |
| 3172 | STD_BUF_SIZE, GFP_KERNEL); |
| 3173 | |
| 3174 | if (kfifo_alloc_rc != 0) { |
| 3175 | FMDERR("failed allocating buffers %d\n", |
| 3176 | kfifo_alloc_rc); |
| 3177 | for (; i > -1; i--) { |
| 3178 | kfifo_free(&radio->data_buf[i]); |
| 3179 | kfree(radio); |
| 3180 | return -ENOMEM; |
| 3181 | } |
| 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | mutex_init(&radio->lock); |
| 3186 | init_completion(&radio->sync_xfr_start); |
| 3187 | radio->tune_req = 0; |
Ankur Nandwani | 8f972e5 | 2011-08-24 11:48:32 -0700 | [diff] [blame] | 3188 | radio->prev_trans_rds = 2; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3189 | init_waitqueue_head(&radio->event_queue); |
| 3190 | init_waitqueue_head(&radio->read_queue); |
| 3191 | |
| 3192 | video_set_drvdata(radio->videodev, radio); |
| 3193 | |
| 3194 | if (NULL == video_get_drvdata(radio->videodev)) |
| 3195 | FMDERR(": video_get_drvdata failed\n"); |
| 3196 | |
| 3197 | retval = video_register_device(radio->videodev, VFL_TYPE_RADIO, |
| 3198 | radio_nr); |
| 3199 | if (retval) { |
| 3200 | FMDERR(": Could not register video device\n"); |
| 3201 | video_device_release(radio->videodev); |
| 3202 | for (; i > -1; i--) |
| 3203 | kfifo_free(&radio->data_buf[i]); |
| 3204 | kfree(radio); |
| 3205 | return retval; |
| 3206 | } else { |
| 3207 | priv_videodev = kzalloc(sizeof(struct video_device), |
| 3208 | GFP_KERNEL); |
| 3209 | memcpy(priv_videodev, radio->videodev, |
| 3210 | sizeof(struct video_device)); |
| 3211 | } |
| 3212 | return 0; |
| 3213 | } |
| 3214 | |
| 3215 | |
| 3216 | static int __devexit iris_remove(struct platform_device *pdev) |
| 3217 | { |
| 3218 | int i; |
| 3219 | struct iris_device *radio = platform_get_drvdata(pdev); |
| 3220 | |
| 3221 | video_unregister_device(radio->videodev); |
| 3222 | |
| 3223 | for (i = 0; i < IRIS_BUF_MAX; i++) |
| 3224 | kfifo_free(&radio->data_buf[i]); |
| 3225 | |
| 3226 | kfree(radio); |
| 3227 | |
| 3228 | platform_set_drvdata(pdev, NULL); |
| 3229 | |
| 3230 | return 0; |
| 3231 | } |
| 3232 | |
| 3233 | static struct platform_driver iris_driver = { |
| 3234 | .driver = { |
| 3235 | .owner = THIS_MODULE, |
| 3236 | .name = "iris_fm", |
| 3237 | }, |
| 3238 | .remove = __devexit_p(iris_remove), |
| 3239 | }; |
| 3240 | |
| 3241 | static int __init iris_radio_init(void) |
| 3242 | { |
| 3243 | return platform_driver_probe(&iris_driver, iris_probe); |
| 3244 | } |
| 3245 | module_init(iris_radio_init); |
| 3246 | |
| 3247 | static void __exit iris_radio_exit(void) |
| 3248 | { |
| 3249 | platform_driver_unregister(&iris_driver); |
| 3250 | } |
| 3251 | module_exit(iris_radio_exit); |
| 3252 | |
| 3253 | MODULE_LICENSE("GPL v2"); |
| 3254 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 3255 | MODULE_DESCRIPTION(DRIVER_DESC); |