Lines Matching +full:preemphasis +full:- +full:level
1 // SPDX-License-Identifier: GPL-2.0-only
12 #include <linux/mfd/wl1273-core.h>
15 #include <media/v4l2-common.h>
16 #include <media/v4l2-ctrls.h>
17 #include <media/v4l2-device.h>
18 #include <media/v4l2-ioctl.h>
35 * static int radio_nr - The number of the radio device
47 unsigned int preemphasis; member
87 * static unsigned int rds_buf - the number of RDS buffer blocks used.
98 struct i2c_client *client = core->client; in wl1273_fm_write_fw()
102 msg.addr = client->addr; in wl1273_fm_write_fw()
110 dev_dbg(&client->dev, "%s:len[%d]: %d\n", __func__, i, msg.len); in wl1273_fm_write_fw()
112 r = i2c_transfer(client->adapter, &msg, 1); in wl1273_fm_write_fw()
117 dev_dbg(&client->dev, "%s: i: %d\n", __func__, i); in wl1273_fm_write_fw()
118 dev_dbg(&client->dev, "%s: len + 1: %d\n", __func__, len + 1); in wl1273_fm_write_fw()
133 struct wl1273_core *core = radio->core; in wl1273_fm_rds()
134 struct i2c_client *client = core->client; in wl1273_fm_rds()
140 .addr = client->addr, in wl1273_fm_rds()
146 .addr = client->addr, in wl1273_fm_rds()
154 if (core->mode != WL1273_MODE_RX) in wl1273_fm_rds()
157 r = core->read(core, WL1273_RDS_SYNC_GET, &val); in wl1273_fm_rds()
163 return -EAGAIN; in wl1273_fm_rds()
168 r = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); in wl1273_fm_rds()
170 dev_err(radio->dev, WL1273_FM_DRIVER_NAME in wl1273_fm_rds()
180 /* copy bits 0-2 (the block ID) to bits 3-5 */ in wl1273_fm_rds()
194 memcpy(&radio->buffer[radio->wr_index], &rds, RDS_BLOCK_SIZE); in wl1273_fm_rds()
195 radio->wr_index += 3; in wl1273_fm_rds()
198 if (radio->wr_index >= radio->buf_size) in wl1273_fm_rds()
199 radio->wr_index = 0; in wl1273_fm_rds()
202 if (radio->wr_index == radio->rd_index) { in wl1273_fm_rds()
203 dev_dbg(radio->dev, "RDS OVERFLOW"); in wl1273_fm_rds()
205 radio->rd_index = 0; in wl1273_fm_rds()
206 radio->wr_index = 0; in wl1273_fm_rds()
212 if (radio->wr_index != radio->rd_index) in wl1273_fm_rds()
213 wake_up_interruptible(&radio->read_queue); in wl1273_fm_rds()
221 struct wl1273_core *core = radio->core; in wl1273_fm_irq_thread_handler()
225 r = core->read(core, WL1273_FLAG_GET, &flags); in wl1273_fm_irq_thread_handler()
230 radio->irq_received = flags; in wl1273_fm_irq_thread_handler()
231 dev_dbg(radio->dev, "IRQ: BL\n"); in wl1273_fm_irq_thread_handler()
241 dev_dbg(radio->dev, "IRQ: BBLK\n"); in wl1273_fm_irq_thread_handler()
244 dev_dbg(radio->dev, "IRQ: LSYNC\n"); in wl1273_fm_irq_thread_handler()
247 u16 level; in wl1273_fm_irq_thread_handler() local
249 r = core->read(core, WL1273_RSSI_LVL_GET, &level); in wl1273_fm_irq_thread_handler()
253 if (level > 14) in wl1273_fm_irq_thread_handler()
254 dev_dbg(radio->dev, "IRQ: LEV: 0x%x04\n", level); in wl1273_fm_irq_thread_handler()
258 dev_dbg(radio->dev, "IRQ: IFFR\n"); in wl1273_fm_irq_thread_handler()
261 dev_dbg(radio->dev, "IRQ: PI\n"); in wl1273_fm_irq_thread_handler()
264 dev_dbg(radio->dev, "IRQ: PD\n"); in wl1273_fm_irq_thread_handler()
267 dev_dbg(radio->dev, "IRQ: STIC\n"); in wl1273_fm_irq_thread_handler()
270 dev_dbg(radio->dev, "IRQ: MAL\n"); in wl1273_fm_irq_thread_handler()
273 complete(&radio->busy); in wl1273_fm_irq_thread_handler()
274 dev_dbg(radio->dev, "NOT BUSY\n"); in wl1273_fm_irq_thread_handler()
275 dev_dbg(radio->dev, "IRQ: POW_ENB\n"); in wl1273_fm_irq_thread_handler()
279 dev_dbg(radio->dev, "IRQ: SCAN_OVER\n"); in wl1273_fm_irq_thread_handler()
282 dev_dbg(radio->dev, "IRQ: ERROR\n"); in wl1273_fm_irq_thread_handler()
287 dev_dbg(radio->dev, "IRQ: FR:\n"); in wl1273_fm_irq_thread_handler()
289 if (core->mode == WL1273_MODE_RX) { in wl1273_fm_irq_thread_handler()
290 r = core->write(core, WL1273_TUNER_MODE_SET, in wl1273_fm_irq_thread_handler()
293 dev_err(radio->dev, in wl1273_fm_irq_thread_handler()
299 r = core->read(core, WL1273_FREQ_SET, &freq); in wl1273_fm_irq_thread_handler()
303 if (radio->band == WL1273_BAND_JAPAN) in wl1273_fm_irq_thread_handler()
304 radio->rx_frequency = WL1273_BAND_JAPAN_LOW + in wl1273_fm_irq_thread_handler()
307 radio->rx_frequency = WL1273_BAND_OTHER_LOW + in wl1273_fm_irq_thread_handler()
315 dev_dbg(radio->dev, "%dkHz\n", radio->rx_frequency); in wl1273_fm_irq_thread_handler()
318 r = core->read(core, WL1273_CHANL_SET, &freq); in wl1273_fm_irq_thread_handler()
322 dev_dbg(radio->dev, "%dkHz\n", freq); in wl1273_fm_irq_thread_handler()
324 dev_dbg(radio->dev, "%s: NOT BUSY\n", __func__); in wl1273_fm_irq_thread_handler()
328 core->write(core, WL1273_INT_MASK_SET, radio->irq_flags); in wl1273_fm_irq_thread_handler()
329 complete(&radio->busy); in wl1273_fm_irq_thread_handler()
336 struct wl1273_core *core = radio->core; in wl1273_fm_set_tx_freq()
341 dev_err(radio->dev, in wl1273_fm_set_tx_freq()
344 return -ERANGE; in wl1273_fm_set_tx_freq()
348 dev_err(radio->dev, in wl1273_fm_set_tx_freq()
351 return -ERANGE; in wl1273_fm_set_tx_freq()
360 dev_dbg(radio->dev, "%s: freq: %d kHz\n", __func__, freq); in wl1273_fm_set_tx_freq()
363 r = core->write(core, WL1273_CHANL_SET, freq / 10); in wl1273_fm_set_tx_freq()
367 reinit_completion(&radio->busy); in wl1273_fm_set_tx_freq()
370 t = wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(2000)); in wl1273_fm_set_tx_freq()
372 return -ETIMEDOUT; in wl1273_fm_set_tx_freq()
374 dev_dbg(radio->dev, "WL1273_CHANL_SET: %lu\n", t); in wl1273_fm_set_tx_freq()
377 r = core->write(core, WL1273_POWER_ENB_SET, 1); in wl1273_fm_set_tx_freq()
381 reinit_completion(&radio->busy); in wl1273_fm_set_tx_freq()
384 t = wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(1000)); in wl1273_fm_set_tx_freq()
386 return -ETIMEDOUT; in wl1273_fm_set_tx_freq()
388 radio->tx_frequency = freq; in wl1273_fm_set_tx_freq()
389 dev_dbg(radio->dev, "WL1273_POWER_ENB_SET: %lu\n", t); in wl1273_fm_set_tx_freq()
396 struct wl1273_core *core = radio->core; in wl1273_fm_set_rx_freq()
400 if (freq < radio->rangelow) { in wl1273_fm_set_rx_freq()
401 dev_err(radio->dev, in wl1273_fm_set_rx_freq()
403 radio->rangelow); in wl1273_fm_set_rx_freq()
404 r = -ERANGE; in wl1273_fm_set_rx_freq()
408 if (freq > radio->rangehigh) { in wl1273_fm_set_rx_freq()
409 dev_err(radio->dev, in wl1273_fm_set_rx_freq()
411 radio->rangehigh); in wl1273_fm_set_rx_freq()
412 r = -ERANGE; in wl1273_fm_set_rx_freq()
416 dev_dbg(radio->dev, "%s: %dkHz\n", __func__, freq); in wl1273_fm_set_rx_freq()
418 core->write(core, WL1273_INT_MASK_SET, radio->irq_flags); in wl1273_fm_set_rx_freq()
420 if (radio->band == WL1273_BAND_JAPAN) in wl1273_fm_set_rx_freq()
421 f = (freq - WL1273_BAND_JAPAN_LOW) / 50; in wl1273_fm_set_rx_freq()
423 f = (freq - WL1273_BAND_OTHER_LOW) / 50; in wl1273_fm_set_rx_freq()
425 r = core->write(core, WL1273_FREQ_SET, f); in wl1273_fm_set_rx_freq()
427 dev_err(radio->dev, "FREQ_SET fails\n"); in wl1273_fm_set_rx_freq()
431 r = core->write(core, WL1273_TUNER_MODE_SET, TUNER_MODE_PRESET); in wl1273_fm_set_rx_freq()
433 dev_err(radio->dev, "TUNER_MODE_SET fails\n"); in wl1273_fm_set_rx_freq()
437 reinit_completion(&radio->busy); in wl1273_fm_set_rx_freq()
439 t = wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(2000)); in wl1273_fm_set_rx_freq()
441 dev_err(radio->dev, "%s: TIMEOUT\n", __func__); in wl1273_fm_set_rx_freq()
442 return -ETIMEDOUT; in wl1273_fm_set_rx_freq()
445 radio->rd_index = 0; in wl1273_fm_set_rx_freq()
446 radio->wr_index = 0; in wl1273_fm_set_rx_freq()
447 radio->rx_frequency = freq; in wl1273_fm_set_rx_freq()
455 struct wl1273_core *core = radio->core; in wl1273_fm_get_freq()
460 if (core->mode == WL1273_MODE_RX) { in wl1273_fm_get_freq()
461 r = core->read(core, WL1273_FREQ_SET, &f); in wl1273_fm_get_freq()
465 dev_dbg(radio->dev, "Freq get: 0x%04x\n", f); in wl1273_fm_get_freq()
466 if (radio->band == WL1273_BAND_JAPAN) in wl1273_fm_get_freq()
471 r = core->read(core, WL1273_CHANL_SET, &f); in wl1273_fm_get_freq()
482 * wl1273_fm_upload_firmware_patch() - Upload the firmware.
491 struct wl1273_core *core = radio->core; in wl1273_fm_upload_firmware_patch()
494 const char *fw_name = "radio-wl1273-fw.bin"; in wl1273_fm_upload_firmware_patch()
495 struct device *dev = radio->dev; in wl1273_fm_upload_firmware_patch()
506 dev_info(dev, "%s - %s not found\n", __func__, fw_name); in wl1273_fm_upload_firmware_patch()
511 ptr = (__u8 *) fw_p->data; in wl1273_fm_upload_firmware_patch()
522 core->write(core, WL1273_RESET, 0); in wl1273_fm_upload_firmware_patch()
524 dev_dbg(dev, "%s - download OK, r: %d\n", __func__, r); in wl1273_fm_upload_firmware_patch()
532 struct wl1273_core *core = radio->core; in wl1273_fm_stop()
534 if (core->mode == WL1273_MODE_RX) { in wl1273_fm_stop()
535 int r = core->write(core, WL1273_POWER_SET, in wl1273_fm_stop()
538 dev_err(radio->dev, "%s: POWER_SET fails: %d\n", in wl1273_fm_stop()
540 } else if (core->mode == WL1273_MODE_TX) { in wl1273_fm_stop()
541 int r = core->write(core, WL1273_PUPD_SET, in wl1273_fm_stop()
544 dev_err(radio->dev, in wl1273_fm_stop()
548 if (core->pdata->disable) { in wl1273_fm_stop()
549 core->pdata->disable(); in wl1273_fm_stop()
550 dev_dbg(radio->dev, "Back to reset\n"); in wl1273_fm_stop()
558 struct wl1273_core *core = radio->core; in wl1273_fm_start()
559 struct wl1273_fm_platform_data *pdata = core->pdata; in wl1273_fm_start()
560 struct device *dev = radio->dev; in wl1273_fm_start()
561 int r = -EINVAL; in wl1273_fm_start()
563 if (pdata->enable && core->mode == WL1273_MODE_OFF) { in wl1273_fm_start()
564 dev_dbg(radio->dev, "Out of reset\n"); in wl1273_fm_start()
566 pdata->enable(); in wl1273_fm_start()
573 if (radio->rds_on) in wl1273_fm_start()
577 r = core->write(core, WL1273_POWER_SET, val); in wl1273_fm_start()
581 r = core->write(core, WL1273_POWER_SET, val); in wl1273_fm_start()
589 radio->wr_index = 0; in wl1273_fm_start()
590 radio->rd_index = 0; in wl1273_fm_start()
594 r = core->write(core, WL1273_PUPD_SET, WL1273_PUPD_SET_ON); in wl1273_fm_start()
597 r = core->write(core, WL1273_PUPD_SET, in wl1273_fm_start()
605 if (radio->rds_on) { in wl1273_fm_start()
606 r = core->write(core, WL1273_RDS_DATA_ENB, 1); in wl1273_fm_start()
613 r = core->write(core, WL1273_RDS_DATA_ENB, 0); in wl1273_fm_start()
624 if (core->mode == WL1273_MODE_OFF) { in wl1273_fm_start()
636 if (radio->rds_on) in wl1273_fm_start()
639 r = core->write(core, WL1273_POWER_SET, val); in wl1273_fm_start()
645 r = core->write(core, WL1273_PUPD_SET, in wl1273_fm_start()
656 if (pdata->disable) in wl1273_fm_start()
657 pdata->disable(); in wl1273_fm_start()
665 struct wl1273_core *core = radio->core; in wl1273_fm_suspend()
669 if (core->mode == WL1273_MODE_RX) in wl1273_fm_suspend()
670 r = core->write(core, WL1273_POWER_SET, in wl1273_fm_suspend()
672 else if (core->mode == WL1273_MODE_TX) in wl1273_fm_suspend()
673 r = core->write(core, WL1273_PUPD_SET, in wl1273_fm_suspend()
676 r = -EINVAL; in wl1273_fm_suspend()
679 dev_err(radio->dev, "%s: POWER_SET fails: %d\n", __func__, r); in wl1273_fm_suspend()
689 struct wl1273_core *core = radio->core; in wl1273_fm_set_mode()
690 struct device *dev = radio->dev; in wl1273_fm_set_mode()
695 dev_dbg(dev, "Forbidden modes: 0x%02x\n", radio->forbidden); in wl1273_fm_set_mode()
697 old_mode = core->mode; in wl1273_fm_set_mode()
698 if (mode & radio->forbidden) { in wl1273_fm_set_mode()
699 r = -EPERM; in wl1273_fm_set_mode()
713 core->mode = mode; in wl1273_fm_set_mode()
714 r = core->write(core, WL1273_INT_MASK_SET, radio->irq_flags); in wl1273_fm_set_mode()
722 r = wl1273_fm_set_rx_freq(radio, radio->rx_frequency); in wl1273_fm_set_mode()
728 r = core->set_volume(core, core->volume); in wl1273_fm_set_mode()
735 core->volume); in wl1273_fm_set_mode()
737 r = wl1273_fm_set_tx_freq(radio, radio->tx_frequency); in wl1273_fm_set_mode()
744 dev_dbg(radio->dev, "%s: Set audio mode.\n", __func__); in wl1273_fm_set_mode()
746 r = core->set_audio(core, core->audio_mode); in wl1273_fm_set_mode()
756 core->mode = WL1273_MODE_OFF; in wl1273_fm_set_mode()
765 core->mode = WL1273_MODE_SUSPENDED; in wl1273_fm_set_mode()
771 r = -EINVAL; in wl1273_fm_set_mode()
776 core->mode = old_mode; in wl1273_fm_set_mode()
784 int level) in wl1273_fm_set_seek() argument
786 struct wl1273_core *core = radio->core; in wl1273_fm_set_seek()
791 f = radio->rx_frequency; in wl1273_fm_set_seek()
792 dev_dbg(radio->dev, "rx_frequency: %d\n", f); in wl1273_fm_set_seek()
794 if (dir && f + radio->spacing <= radio->rangehigh) in wl1273_fm_set_seek()
795 r = wl1273_fm_set_rx_freq(radio, f + radio->spacing); in wl1273_fm_set_seek()
797 r = wl1273_fm_set_rx_freq(radio, radio->rangelow); in wl1273_fm_set_seek()
798 else if (f - radio->spacing >= radio->rangelow) in wl1273_fm_set_seek()
799 r = wl1273_fm_set_rx_freq(radio, f - radio->spacing); in wl1273_fm_set_seek()
801 r = wl1273_fm_set_rx_freq(radio, radio->rangehigh); in wl1273_fm_set_seek()
806 if (level < SCHAR_MIN || level > SCHAR_MAX) in wl1273_fm_set_seek()
807 return -EINVAL; in wl1273_fm_set_seek()
809 reinit_completion(&radio->busy); in wl1273_fm_set_seek()
810 dev_dbg(radio->dev, "%s: BUSY\n", __func__); in wl1273_fm_set_seek()
812 r = core->write(core, WL1273_INT_MASK_SET, radio->irq_flags); in wl1273_fm_set_seek()
816 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_set_seek()
818 r = core->write(core, WL1273_SEARCH_LVL_SET, level); in wl1273_fm_set_seek()
822 r = core->write(core, WL1273_SEARCH_DIR_SET, dir); in wl1273_fm_set_seek()
826 r = core->write(core, WL1273_TUNER_MODE_SET, TUNER_MODE_AUTO_SEEK); in wl1273_fm_set_seek()
831 wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(1000)); in wl1273_fm_set_seek()
832 if (!(radio->irq_received & WL1273_BL_EVENT)) { in wl1273_fm_set_seek()
833 r = -ETIMEDOUT; in wl1273_fm_set_seek()
837 radio->irq_received &= ~WL1273_BL_EVENT; in wl1273_fm_set_seek()
843 dev_dbg(radio->dev, "Wrap around in HW seek.\n"); in wl1273_fm_set_seek()
846 f = radio->rangelow; in wl1273_fm_set_seek()
848 f = radio->rangehigh; in wl1273_fm_set_seek()
854 reinit_completion(&radio->busy); in wl1273_fm_set_seek()
855 dev_dbg(radio->dev, "%s: BUSY\n", __func__); in wl1273_fm_set_seek()
857 r = core->write(core, WL1273_TUNER_MODE_SET, TUNER_MODE_AUTO_SEEK); in wl1273_fm_set_seek()
862 if (!wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(1000))) in wl1273_fm_set_seek()
863 r = -ETIMEDOUT; in wl1273_fm_set_seek()
865 dev_dbg(radio->dev, "%s: Err: %d\n", __func__, r); in wl1273_fm_set_seek()
870 * wl1273_fm_get_tx_ctune() - Get the TX tuning capacitor value.
875 struct wl1273_core *core = radio->core; in wl1273_fm_get_tx_ctune()
876 struct device *dev = radio->dev; in wl1273_fm_get_tx_ctune()
880 if (core->mode == WL1273_MODE_OFF || in wl1273_fm_get_tx_ctune()
881 core->mode == WL1273_MODE_SUSPENDED) in wl1273_fm_get_tx_ctune()
882 return -EPERM; in wl1273_fm_get_tx_ctune()
884 r = core->read(core, WL1273_READ_FMANT_TUNE_VALUE, &val); in wl1273_fm_get_tx_ctune()
895 * wl1273_fm_set_preemphasis() - Set the TX pre-emphasis value.
897 * @preemphasis: The new pre-amphasis value.
899 * Possible pre-emphasis values are: V4L2_PREEMPHASIS_DISABLED,
903 unsigned int preemphasis) in wl1273_fm_set_preemphasis() argument
905 struct wl1273_core *core = radio->core; in wl1273_fm_set_preemphasis()
909 if (core->mode == WL1273_MODE_OFF || in wl1273_fm_set_preemphasis()
910 core->mode == WL1273_MODE_SUSPENDED) in wl1273_fm_set_preemphasis()
911 return -EPERM; in wl1273_fm_set_preemphasis()
913 mutex_lock(&core->lock); in wl1273_fm_set_preemphasis()
915 switch (preemphasis) { in wl1273_fm_set_preemphasis()
926 r = -EINVAL; in wl1273_fm_set_preemphasis()
930 r = core->write(core, WL1273_PREMPH_SET, em); in wl1273_fm_set_preemphasis()
934 radio->preemphasis = preemphasis; in wl1273_fm_set_preemphasis()
937 mutex_unlock(&core->lock); in wl1273_fm_set_preemphasis()
943 struct wl1273_core *core = radio->core; in wl1273_fm_rds_on()
946 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_rds_on()
947 if (radio->rds_on) in wl1273_fm_rds_on()
950 r = core->write(core, WL1273_POWER_SET, in wl1273_fm_rds_on()
955 r = wl1273_fm_set_rx_freq(radio, radio->rx_frequency); in wl1273_fm_rds_on()
957 dev_err(radio->dev, "set freq fails: %d.\n", r); in wl1273_fm_rds_on()
964 struct wl1273_core *core = radio->core; in wl1273_fm_rds_off()
967 if (!radio->rds_on) in wl1273_fm_rds_off()
970 radio->irq_flags &= ~WL1273_RDS_EVENT; in wl1273_fm_rds_off()
972 r = core->write(core, WL1273_INT_MASK_SET, radio->irq_flags); in wl1273_fm_rds_off()
977 wake_up_interruptible(&radio->read_queue); in wl1273_fm_rds_off()
979 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_rds_off()
981 r = core->write(core, WL1273_POWER_SET, WL1273_POWER_SET_FM); in wl1273_fm_rds_off()
985 r = wl1273_fm_set_rx_freq(radio, radio->rx_frequency); in wl1273_fm_rds_off()
987 dev_err(radio->dev, "set freq fails: %d.\n", r); in wl1273_fm_rds_off()
989 dev_dbg(radio->dev, "%s: exiting...\n", __func__); in wl1273_fm_rds_off()
997 struct wl1273_core *core = radio->core; in wl1273_fm_set_rds()
999 if (core->mode == WL1273_MODE_OFF || in wl1273_fm_set_rds()
1000 core->mode == WL1273_MODE_SUSPENDED) in wl1273_fm_set_rds()
1001 return -EPERM; in wl1273_fm_set_rds()
1004 r = core->write(core, WL1273_RDS_CNTRL_SET, 1); in wl1273_fm_set_rds()
1008 if (core->mode == WL1273_MODE_TX && new_mode == WL1273_RDS_OFF) { in wl1273_fm_set_rds()
1009 r = core->write(core, WL1273_RDS_DATA_ENB, 0); in wl1273_fm_set_rds()
1010 } else if (core->mode == WL1273_MODE_TX && new_mode == WL1273_RDS_ON) { in wl1273_fm_set_rds()
1011 r = core->write(core, WL1273_RDS_DATA_ENB, 1); in wl1273_fm_set_rds()
1012 } else if (core->mode == WL1273_MODE_RX && new_mode == WL1273_RDS_OFF) { in wl1273_fm_set_rds()
1014 } else if (core->mode == WL1273_MODE_RX && new_mode == WL1273_RDS_ON) { in wl1273_fm_set_rds()
1017 dev_err(radio->dev, "%s: Unknown mode: %d\n", in wl1273_fm_set_rds()
1019 r = -EINVAL; in wl1273_fm_set_rds()
1023 radio->rds_on = new_mode == WL1273_RDS_ON; in wl1273_fm_set_rds()
1032 struct wl1273_core *core = radio->core; in wl1273_fm_fops_write()
1036 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_fops_write()
1038 if (core->mode != WL1273_MODE_TX) in wl1273_fm_fops_write()
1041 if (radio->rds_users == 0) { in wl1273_fm_fops_write()
1042 dev_warn(radio->dev, "%s: RDS not on.\n", __func__); in wl1273_fm_fops_write()
1046 if (mutex_lock_interruptible(&core->lock)) in wl1273_fm_fops_write()
1047 return -EINTR; in wl1273_fm_fops_write()
1052 if (radio->owner && radio->owner != file) { in wl1273_fm_fops_write()
1053 r = -EBUSY; in wl1273_fm_fops_write()
1056 radio->owner = file; in wl1273_fm_fops_write()
1064 core->write(core, WL1273_RDS_CONFIG_DATA_SET, val); in wl1273_fm_fops_write()
1066 if (copy_from_user(radio->write_buf + 1, buf, val)) { in wl1273_fm_fops_write()
1067 r = -EFAULT; in wl1273_fm_fops_write()
1071 dev_dbg(radio->dev, "Count: %d\n", val); in wl1273_fm_fops_write()
1072 dev_dbg(radio->dev, "From user: \"%s\"\n", radio->write_buf); in wl1273_fm_fops_write()
1074 radio->write_buf[0] = WL1273_RDS_DATA_SET; in wl1273_fm_fops_write()
1075 core->write_data(core, radio->write_buf, val + 1); in wl1273_fm_fops_write()
1079 mutex_unlock(&core->lock); in wl1273_fm_fops_write()
1088 struct wl1273_core *core = radio->core; in wl1273_fm_fops_poll()
1090 if (radio->owner && radio->owner != file) in wl1273_fm_fops_poll()
1093 radio->owner = file; in wl1273_fm_fops_poll()
1095 if (core->mode == WL1273_MODE_RX) { in wl1273_fm_fops_poll()
1096 poll_wait(file, &radio->read_queue, pts); in wl1273_fm_fops_poll()
1098 if (radio->rd_index != radio->wr_index) in wl1273_fm_fops_poll()
1101 } else if (core->mode == WL1273_MODE_TX) { in wl1273_fm_fops_poll()
1111 struct wl1273_core *core = radio->core; in wl1273_fm_fops_open()
1114 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_fops_open()
1116 if (core->mode == WL1273_MODE_RX && radio->rds_on && in wl1273_fm_fops_open()
1117 !radio->rds_users) { in wl1273_fm_fops_open()
1118 dev_dbg(radio->dev, "%s: Mode: %d\n", __func__, core->mode); in wl1273_fm_fops_open()
1120 if (mutex_lock_interruptible(&core->lock)) in wl1273_fm_fops_open()
1121 return -EINTR; in wl1273_fm_fops_open()
1123 radio->irq_flags |= WL1273_RDS_EVENT; in wl1273_fm_fops_open()
1125 r = core->write(core, WL1273_INT_MASK_SET, in wl1273_fm_fops_open()
1126 radio->irq_flags); in wl1273_fm_fops_open()
1128 mutex_unlock(&core->lock); in wl1273_fm_fops_open()
1132 radio->rds_users++; in wl1273_fm_fops_open()
1134 mutex_unlock(&core->lock); in wl1273_fm_fops_open()
1143 struct wl1273_core *core = radio->core; in wl1273_fm_fops_release()
1146 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_fops_release()
1148 if (radio->rds_users > 0) { in wl1273_fm_fops_release()
1149 radio->rds_users--; in wl1273_fm_fops_release()
1150 if (radio->rds_users == 0) { in wl1273_fm_fops_release()
1151 mutex_lock(&core->lock); in wl1273_fm_fops_release()
1153 radio->irq_flags &= ~WL1273_RDS_EVENT; in wl1273_fm_fops_release()
1155 if (core->mode == WL1273_MODE_RX) { in wl1273_fm_fops_release()
1156 r = core->write(core, in wl1273_fm_fops_release()
1158 radio->irq_flags); in wl1273_fm_fops_release()
1160 mutex_unlock(&core->lock); in wl1273_fm_fops_release()
1164 mutex_unlock(&core->lock); in wl1273_fm_fops_release()
1168 if (file == radio->owner) in wl1273_fm_fops_release()
1169 radio->owner = NULL; in wl1273_fm_fops_release()
1179 struct wl1273_core *core = radio->core; in wl1273_fm_fops_read()
1183 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_fops_read()
1185 if (core->mode != WL1273_MODE_RX) in wl1273_fm_fops_read()
1188 if (radio->rds_users == 0) { in wl1273_fm_fops_read()
1189 dev_warn(radio->dev, "%s: RDS not on.\n", __func__); in wl1273_fm_fops_read()
1193 if (mutex_lock_interruptible(&core->lock)) in wl1273_fm_fops_read()
1194 return -EINTR; in wl1273_fm_fops_read()
1200 if (radio->owner && radio->owner != file) { in wl1273_fm_fops_read()
1201 r = -EBUSY; in wl1273_fm_fops_read()
1204 radio->owner = file; in wl1273_fm_fops_read()
1206 r = core->read(core, WL1273_RDS_SYNC_GET, &val); in wl1273_fm_fops_read()
1208 dev_err(radio->dev, "%s: Get RDS_SYNC fails.\n", __func__); in wl1273_fm_fops_read()
1211 dev_info(radio->dev, "RDS_SYNC: Not synchronized\n"); in wl1273_fm_fops_read()
1212 r = -ENODATA; in wl1273_fm_fops_read()
1217 while (radio->wr_index == radio->rd_index) { in wl1273_fm_fops_read()
1218 if (file->f_flags & O_NONBLOCK) { in wl1273_fm_fops_read()
1219 r = -EWOULDBLOCK; in wl1273_fm_fops_read()
1223 dev_dbg(radio->dev, "%s: Wait for RDS data.\n", __func__); in wl1273_fm_fops_read()
1224 if (wait_event_interruptible(radio->read_queue, in wl1273_fm_fops_read()
1225 radio->wr_index != in wl1273_fm_fops_read()
1226 radio->rd_index) < 0) { in wl1273_fm_fops_read()
1227 r = -EINTR; in wl1273_fm_fops_read()
1237 if (radio->rd_index == radio->wr_index) in wl1273_fm_fops_read()
1241 if (copy_to_user(buf, &radio->buffer[radio->rd_index], in wl1273_fm_fops_read()
1246 radio->rd_index += RDS_BLOCK_SIZE; in wl1273_fm_fops_read()
1247 if (radio->rd_index >= radio->buf_size) in wl1273_fm_fops_read()
1248 radio->rd_index = 0; in wl1273_fm_fops_read()
1257 dev_dbg(radio->dev, "%s: exit\n", __func__); in wl1273_fm_fops_read()
1258 mutex_unlock(&core->lock); in wl1273_fm_fops_read()
1278 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_vidioc_querycap()
1280 strscpy(capability->driver, WL1273_FM_DRIVER_NAME, in wl1273_fm_vidioc_querycap()
1281 sizeof(capability->driver)); in wl1273_fm_vidioc_querycap()
1282 strscpy(capability->card, "TI Wl1273 FM Radio", in wl1273_fm_vidioc_querycap()
1283 sizeof(capability->card)); in wl1273_fm_vidioc_querycap()
1284 strscpy(capability->bus_info, radio->bus_type, in wl1273_fm_vidioc_querycap()
1285 sizeof(capability->bus_info)); in wl1273_fm_vidioc_querycap()
1294 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_vidioc_g_input()
1306 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_vidioc_s_input()
1309 return -EINVAL; in wl1273_fm_vidioc_s_input()
1315 * wl1273_fm_set_tx_power() - Set the transmission power value.
1321 struct wl1273_core *core = radio->core; in wl1273_fm_set_tx_power()
1324 if (core->mode == WL1273_MODE_OFF || in wl1273_fm_set_tx_power()
1325 core->mode == WL1273_MODE_SUSPENDED) in wl1273_fm_set_tx_power()
1326 return -EPERM; in wl1273_fm_set_tx_power()
1328 mutex_lock(&core->lock); in wl1273_fm_set_tx_power()
1331 r = core->write(core, WL1273_POWER_LEV_SET, 122 - power); in wl1273_fm_set_tx_power()
1335 radio->tx_power = power; in wl1273_fm_set_tx_power()
1338 mutex_unlock(&core->lock); in wl1273_fm_set_tx_power()
1349 struct wl1273_core *core = radio->core; in wl1273_fm_tx_set_spacing()
1353 r = core->write(core, WL1273_SCAN_SPACING_SET, in wl1273_fm_tx_set_spacing()
1355 radio->spacing = 100; in wl1273_fm_tx_set_spacing()
1356 } else if (spacing - 50000 < 25000) { in wl1273_fm_tx_set_spacing()
1357 r = core->write(core, WL1273_SCAN_SPACING_SET, in wl1273_fm_tx_set_spacing()
1359 radio->spacing = 50; in wl1273_fm_tx_set_spacing()
1360 } else if (spacing - 100000 < 50000) { in wl1273_fm_tx_set_spacing()
1361 r = core->write(core, WL1273_SCAN_SPACING_SET, in wl1273_fm_tx_set_spacing()
1363 radio->spacing = 100; in wl1273_fm_tx_set_spacing()
1365 r = core->write(core, WL1273_SCAN_SPACING_SET, in wl1273_fm_tx_set_spacing()
1367 radio->spacing = 200; in wl1273_fm_tx_set_spacing()
1375 struct wl1273_device *radio = ctrl->priv; in wl1273_fm_g_volatile_ctrl()
1376 struct wl1273_core *core = radio->core; in wl1273_fm_g_volatile_ctrl()
1378 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_g_volatile_ctrl()
1380 if (mutex_lock_interruptible(&core->lock)) in wl1273_fm_g_volatile_ctrl()
1381 return -EINTR; in wl1273_fm_g_volatile_ctrl()
1383 switch (ctrl->id) { in wl1273_fm_g_volatile_ctrl()
1385 ctrl->val = wl1273_fm_get_tx_ctune(radio); in wl1273_fm_g_volatile_ctrl()
1389 dev_warn(radio->dev, "%s: Unknown IOCTL: %d\n", in wl1273_fm_g_volatile_ctrl()
1390 __func__, ctrl->id); in wl1273_fm_g_volatile_ctrl()
1394 mutex_unlock(&core->lock); in wl1273_fm_g_volatile_ctrl()
1407 return container_of(ctrl->handler, struct wl1273_device, ctrl_handler); in to_radio()
1413 struct wl1273_core *core = radio->core; in wl1273_fm_vidioc_s_ctrl()
1416 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_vidioc_s_ctrl()
1418 switch (ctrl->id) { in wl1273_fm_vidioc_s_ctrl()
1420 if (mutex_lock_interruptible(&core->lock)) in wl1273_fm_vidioc_s_ctrl()
1421 return -EINTR; in wl1273_fm_vidioc_s_ctrl()
1423 if (core->mode == WL1273_MODE_RX && ctrl->val) in wl1273_fm_vidioc_s_ctrl()
1424 r = core->write(core, in wl1273_fm_vidioc_s_ctrl()
1428 else if (core->mode == WL1273_MODE_RX) in wl1273_fm_vidioc_s_ctrl()
1429 r = core->write(core, in wl1273_fm_vidioc_s_ctrl()
1431 else if (core->mode == WL1273_MODE_TX && ctrl->val) in wl1273_fm_vidioc_s_ctrl()
1432 r = core->write(core, WL1273_MUTE, 1); in wl1273_fm_vidioc_s_ctrl()
1433 else if (core->mode == WL1273_MODE_TX) in wl1273_fm_vidioc_s_ctrl()
1434 r = core->write(core, WL1273_MUTE, 0); in wl1273_fm_vidioc_s_ctrl()
1436 mutex_unlock(&core->lock); in wl1273_fm_vidioc_s_ctrl()
1440 if (ctrl->val == 0) in wl1273_fm_vidioc_s_ctrl()
1443 r = core->set_volume(core, core->volume); in wl1273_fm_vidioc_s_ctrl()
1447 r = wl1273_fm_set_preemphasis(radio, ctrl->val); in wl1273_fm_vidioc_s_ctrl()
1451 r = wl1273_fm_set_tx_power(radio, ctrl->val); in wl1273_fm_vidioc_s_ctrl()
1455 dev_warn(radio->dev, "%s: Unknown IOCTL: %d\n", in wl1273_fm_vidioc_s_ctrl()
1456 __func__, ctrl->id); in wl1273_fm_vidioc_s_ctrl()
1460 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_vidioc_s_ctrl()
1469 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_vidioc_g_audio()
1471 if (audio->index > 1) in wl1273_fm_vidioc_g_audio()
1472 return -EINVAL; in wl1273_fm_vidioc_g_audio()
1474 strscpy(audio->name, "Radio", sizeof(audio->name)); in wl1273_fm_vidioc_g_audio()
1475 audio->capability = V4L2_AUDCAP_STEREO; in wl1273_fm_vidioc_g_audio()
1485 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_vidioc_s_audio()
1487 if (audio->index != 0) in wl1273_fm_vidioc_s_audio()
1488 return -EINVAL; in wl1273_fm_vidioc_s_audio()
1500 struct wl1273_core *core = radio->core; in wl1273_fm_vidioc_g_tuner()
1504 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_vidioc_g_tuner()
1506 if (tuner->index > 0) in wl1273_fm_vidioc_g_tuner()
1507 return -EINVAL; in wl1273_fm_vidioc_g_tuner()
1509 strscpy(tuner->name, WL1273_FM_DRIVER_NAME, sizeof(tuner->name)); in wl1273_fm_vidioc_g_tuner()
1510 tuner->type = V4L2_TUNER_RADIO; in wl1273_fm_vidioc_g_tuner()
1512 tuner->rangelow = WL1273_FREQ(WL1273_BAND_JAPAN_LOW); in wl1273_fm_vidioc_g_tuner()
1513 tuner->rangehigh = WL1273_FREQ(WL1273_BAND_OTHER_HIGH); in wl1273_fm_vidioc_g_tuner()
1515 tuner->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_RDS | in wl1273_fm_vidioc_g_tuner()
1519 if (radio->stereo) in wl1273_fm_vidioc_g_tuner()
1520 tuner->audmode = V4L2_TUNER_MODE_STEREO; in wl1273_fm_vidioc_g_tuner()
1522 tuner->audmode = V4L2_TUNER_MODE_MONO; in wl1273_fm_vidioc_g_tuner()
1524 if (core->mode != WL1273_MODE_RX) in wl1273_fm_vidioc_g_tuner()
1527 if (mutex_lock_interruptible(&core->lock)) in wl1273_fm_vidioc_g_tuner()
1528 return -EINTR; in wl1273_fm_vidioc_g_tuner()
1530 r = core->read(core, WL1273_STEREO_GET, &val); in wl1273_fm_vidioc_g_tuner()
1535 tuner->rxsubchans = V4L2_TUNER_SUB_STEREO; in wl1273_fm_vidioc_g_tuner()
1537 tuner->rxsubchans = V4L2_TUNER_SUB_MONO; in wl1273_fm_vidioc_g_tuner()
1539 r = core->read(core, WL1273_RSSI_LVL_GET, &val); in wl1273_fm_vidioc_g_tuner()
1543 tuner->signal = (s16) val; in wl1273_fm_vidioc_g_tuner()
1544 dev_dbg(radio->dev, "Signal: %d\n", tuner->signal); in wl1273_fm_vidioc_g_tuner()
1546 tuner->afc = 0; in wl1273_fm_vidioc_g_tuner()
1548 r = core->read(core, WL1273_RDS_SYNC_GET, &val); in wl1273_fm_vidioc_g_tuner()
1553 tuner->rxsubchans |= V4L2_TUNER_SUB_RDS; in wl1273_fm_vidioc_g_tuner()
1555 mutex_unlock(&core->lock); in wl1273_fm_vidioc_g_tuner()
1564 struct wl1273_core *core = radio->core; in wl1273_fm_vidioc_s_tuner()
1567 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_vidioc_s_tuner()
1568 dev_dbg(radio->dev, "tuner->index: %d\n", tuner->index); in wl1273_fm_vidioc_s_tuner()
1569 dev_dbg(radio->dev, "tuner->name: %s\n", tuner->name); in wl1273_fm_vidioc_s_tuner()
1570 dev_dbg(radio->dev, "tuner->capability: 0x%04x\n", tuner->capability); in wl1273_fm_vidioc_s_tuner()
1571 dev_dbg(radio->dev, "tuner->rxsubchans: 0x%04x\n", tuner->rxsubchans); in wl1273_fm_vidioc_s_tuner()
1572 dev_dbg(radio->dev, "tuner->rangelow: %d\n", tuner->rangelow); in wl1273_fm_vidioc_s_tuner()
1573 dev_dbg(radio->dev, "tuner->rangehigh: %d\n", tuner->rangehigh); in wl1273_fm_vidioc_s_tuner()
1575 if (tuner->index > 0) in wl1273_fm_vidioc_s_tuner()
1576 return -EINVAL; in wl1273_fm_vidioc_s_tuner()
1578 if (mutex_lock_interruptible(&core->lock)) in wl1273_fm_vidioc_s_tuner()
1579 return -EINTR; in wl1273_fm_vidioc_s_tuner()
1585 if (tuner->rxsubchans & V4L2_TUNER_SUB_RDS) in wl1273_fm_vidioc_s_tuner()
1591 dev_warn(radio->dev, "%s: RDS fails: %d\n", __func__, r); in wl1273_fm_vidioc_s_tuner()
1593 if (tuner->audmode == V4L2_TUNER_MODE_MONO) { in wl1273_fm_vidioc_s_tuner()
1594 r = core->write(core, WL1273_MOST_MODE_SET, WL1273_RX_MONO); in wl1273_fm_vidioc_s_tuner()
1596 dev_warn(radio->dev, "%s: MOST_MODE fails: %d\n", in wl1273_fm_vidioc_s_tuner()
1600 radio->stereo = false; in wl1273_fm_vidioc_s_tuner()
1601 } else if (tuner->audmode == V4L2_TUNER_MODE_STEREO) { in wl1273_fm_vidioc_s_tuner()
1602 r = core->write(core, WL1273_MOST_MODE_SET, WL1273_RX_STEREO); in wl1273_fm_vidioc_s_tuner()
1604 dev_warn(radio->dev, "%s: MOST_MODE fails: %d\n", in wl1273_fm_vidioc_s_tuner()
1608 radio->stereo = true; in wl1273_fm_vidioc_s_tuner()
1610 dev_err(radio->dev, "%s: tuner->audmode: %d\n", in wl1273_fm_vidioc_s_tuner()
1611 __func__, tuner->audmode); in wl1273_fm_vidioc_s_tuner()
1612 r = -EINVAL; in wl1273_fm_vidioc_s_tuner()
1617 mutex_unlock(&core->lock); in wl1273_fm_vidioc_s_tuner()
1626 struct wl1273_core *core = radio->core; in wl1273_fm_vidioc_g_frequency()
1628 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_vidioc_g_frequency()
1630 if (mutex_lock_interruptible(&core->lock)) in wl1273_fm_vidioc_g_frequency()
1631 return -EINTR; in wl1273_fm_vidioc_g_frequency()
1633 freq->type = V4L2_TUNER_RADIO; in wl1273_fm_vidioc_g_frequency()
1634 freq->frequency = WL1273_FREQ(wl1273_fm_get_freq(radio)); in wl1273_fm_vidioc_g_frequency()
1636 mutex_unlock(&core->lock); in wl1273_fm_vidioc_g_frequency()
1645 struct wl1273_core *core = radio->core; in wl1273_fm_vidioc_s_frequency()
1648 dev_dbg(radio->dev, "%s: %d\n", __func__, freq->frequency); in wl1273_fm_vidioc_s_frequency()
1650 if (freq->type != V4L2_TUNER_RADIO) { in wl1273_fm_vidioc_s_frequency()
1651 dev_dbg(radio->dev, in wl1273_fm_vidioc_s_frequency()
1652 "freq->type != V4L2_TUNER_RADIO: %d\n", freq->type); in wl1273_fm_vidioc_s_frequency()
1653 return -EINVAL; in wl1273_fm_vidioc_s_frequency()
1656 if (mutex_lock_interruptible(&core->lock)) in wl1273_fm_vidioc_s_frequency()
1657 return -EINTR; in wl1273_fm_vidioc_s_frequency()
1659 if (core->mode == WL1273_MODE_RX) { in wl1273_fm_vidioc_s_frequency()
1660 dev_dbg(radio->dev, "freq: %d\n", freq->frequency); in wl1273_fm_vidioc_s_frequency()
1663 WL1273_INV_FREQ(freq->frequency)); in wl1273_fm_vidioc_s_frequency()
1665 dev_warn(radio->dev, WL1273_FM_DRIVER_NAME in wl1273_fm_vidioc_s_frequency()
1669 WL1273_INV_FREQ(freq->frequency)); in wl1273_fm_vidioc_s_frequency()
1671 dev_warn(radio->dev, WL1273_FM_DRIVER_NAME in wl1273_fm_vidioc_s_frequency()
1675 mutex_unlock(&core->lock); in wl1273_fm_vidioc_s_frequency()
1677 dev_dbg(radio->dev, "wl1273_vidioc_s_frequency: DONE\n"); in wl1273_fm_vidioc_s_frequency()
1687 struct wl1273_core *core = radio->core; in wl1273_fm_vidioc_s_hw_freq_seek()
1690 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_vidioc_s_hw_freq_seek()
1692 if (seek->tuner != 0 || seek->type != V4L2_TUNER_RADIO) in wl1273_fm_vidioc_s_hw_freq_seek()
1693 return -EINVAL; in wl1273_fm_vidioc_s_hw_freq_seek()
1695 if (file->f_flags & O_NONBLOCK) in wl1273_fm_vidioc_s_hw_freq_seek()
1696 return -EWOULDBLOCK; in wl1273_fm_vidioc_s_hw_freq_seek()
1698 if (mutex_lock_interruptible(&core->lock)) in wl1273_fm_vidioc_s_hw_freq_seek()
1699 return -EINTR; in wl1273_fm_vidioc_s_hw_freq_seek()
1705 r = wl1273_fm_tx_set_spacing(radio, seek->spacing); in wl1273_fm_vidioc_s_hw_freq_seek()
1707 dev_warn(radio->dev, "HW seek failed: %d\n", r); in wl1273_fm_vidioc_s_hw_freq_seek()
1709 r = wl1273_fm_set_seek(radio, seek->wrap_around, seek->seek_upward, in wl1273_fm_vidioc_s_hw_freq_seek()
1712 dev_warn(radio->dev, "HW seek failed: %d\n", r); in wl1273_fm_vidioc_s_hw_freq_seek()
1715 mutex_unlock(&core->lock); in wl1273_fm_vidioc_s_hw_freq_seek()
1723 struct wl1273_core *core = radio->core; in wl1273_fm_vidioc_s_modulator()
1726 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_vidioc_s_modulator()
1728 if (modulator->index > 0) in wl1273_fm_vidioc_s_modulator()
1729 return -EINVAL; in wl1273_fm_vidioc_s_modulator()
1731 if (mutex_lock_interruptible(&core->lock)) in wl1273_fm_vidioc_s_modulator()
1732 return -EINTR; in wl1273_fm_vidioc_s_modulator()
1738 if (modulator->txsubchans & V4L2_TUNER_SUB_RDS) in wl1273_fm_vidioc_s_modulator()
1743 if (modulator->txsubchans & V4L2_TUNER_SUB_MONO) in wl1273_fm_vidioc_s_modulator()
1744 r = core->write(core, WL1273_MONO_SET, WL1273_TX_MONO); in wl1273_fm_vidioc_s_modulator()
1746 r = core->write(core, WL1273_MONO_SET, in wl1273_fm_vidioc_s_modulator()
1749 dev_warn(radio->dev, WL1273_FM_DRIVER_NAME in wl1273_fm_vidioc_s_modulator()
1752 mutex_unlock(&core->lock); in wl1273_fm_vidioc_s_modulator()
1761 struct wl1273_core *core = radio->core; in wl1273_fm_vidioc_g_modulator()
1765 dev_dbg(radio->dev, "%s\n", __func__); in wl1273_fm_vidioc_g_modulator()
1767 strscpy(modulator->name, WL1273_FM_DRIVER_NAME, in wl1273_fm_vidioc_g_modulator()
1768 sizeof(modulator->name)); in wl1273_fm_vidioc_g_modulator()
1770 modulator->rangelow = WL1273_FREQ(WL1273_BAND_JAPAN_LOW); in wl1273_fm_vidioc_g_modulator()
1771 modulator->rangehigh = WL1273_FREQ(WL1273_BAND_OTHER_HIGH); in wl1273_fm_vidioc_g_modulator()
1773 modulator->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_RDS | in wl1273_fm_vidioc_g_modulator()
1776 if (core->mode != WL1273_MODE_TX) in wl1273_fm_vidioc_g_modulator()
1779 if (mutex_lock_interruptible(&core->lock)) in wl1273_fm_vidioc_g_modulator()
1780 return -EINTR; in wl1273_fm_vidioc_g_modulator()
1782 r = core->read(core, WL1273_MONO_SET, &val); in wl1273_fm_vidioc_g_modulator()
1787 modulator->txsubchans = V4L2_TUNER_SUB_STEREO; in wl1273_fm_vidioc_g_modulator()
1789 modulator->txsubchans = V4L2_TUNER_SUB_MONO; in wl1273_fm_vidioc_g_modulator()
1791 if (radio->rds_on) in wl1273_fm_vidioc_g_modulator()
1792 modulator->txsubchans |= V4L2_TUNER_SUB_RDS; in wl1273_fm_vidioc_g_modulator()
1794 mutex_unlock(&core->lock); in wl1273_fm_vidioc_g_modulator()
1802 struct wl1273_core *core = radio->core; in wl1273_fm_vidioc_log_status()
1803 struct device *dev = radio->dev; in wl1273_fm_vidioc_log_status()
1809 if (core->mode == WL1273_MODE_OFF) { in wl1273_fm_vidioc_log_status()
1814 if (core->mode == WL1273_MODE_SUSPENDED) { in wl1273_fm_vidioc_log_status()
1819 r = core->read(core, WL1273_ASIC_ID_GET, &val); in wl1273_fm_vidioc_log_status()
1825 r = core->read(core, WL1273_ASIC_VER_GET, &val); in wl1273_fm_vidioc_log_status()
1831 r = core->read(core, WL1273_FIRM_VER_GET, &val); in wl1273_fm_vidioc_log_status()
1837 r = core->read(core, WL1273_BAND_SET, &val); in wl1273_fm_vidioc_log_status()
1843 if (core->mode == WL1273_MODE_TX) { in wl1273_fm_vidioc_log_status()
1844 r = core->read(core, WL1273_PUPD_SET, &val); in wl1273_fm_vidioc_log_status()
1850 r = core->read(core, WL1273_CHANL_SET, &val); in wl1273_fm_vidioc_log_status()
1855 } else if (core->mode == WL1273_MODE_RX) { in wl1273_fm_vidioc_log_status()
1856 int bf = radio->rangelow; in wl1273_fm_vidioc_log_status()
1858 r = core->read(core, WL1273_FREQ_SET, &val); in wl1273_fm_vidioc_log_status()
1864 r = core->read(core, WL1273_MOST_MODE_SET, &val); in wl1273_fm_vidioc_log_status()
1875 r = core->read(core, WL1273_MOST_BLEND_SET, &val); in wl1273_fm_vidioc_log_status()
1886 r = core->read(core, WL1273_STEREO_GET, &val); in wl1273_fm_vidioc_log_status()
1896 r = core->read(core, WL1273_RSSI_LVL_GET, &val); in wl1273_fm_vidioc_log_status()
1902 r = core->read(core, WL1273_POWER_SET, &val); in wl1273_fm_vidioc_log_status()
1908 r = core->read(core, WL1273_INT_MASK_SET, &val); in wl1273_fm_vidioc_log_status()
1914 r = core->read(core, WL1273_RDS_SYNC_GET, &val); in wl1273_fm_vidioc_log_status()
1926 r = core->read(core, WL1273_I2S_MODE_CONFIG_SET, &val); in wl1273_fm_vidioc_log_status()
1933 r = core->read(core, WL1273_VOLUME_SET, &val); in wl1273_fm_vidioc_log_status()
1983 struct wl1273_core *core = radio->core; in wl1273_fm_radio_remove()
1985 dev_info(&pdev->dev, "%s.\n", __func__); in wl1273_fm_radio_remove()
1987 free_irq(core->client->irq, radio); in wl1273_fm_radio_remove()
1988 core->pdata->free_resources(); in wl1273_fm_radio_remove()
1990 v4l2_ctrl_handler_free(&radio->ctrl_handler); in wl1273_fm_radio_remove()
1991 video_unregister_device(&radio->videodev); in wl1273_fm_radio_remove()
1992 v4l2_device_unregister(&radio->v4l2dev); in wl1273_fm_radio_remove()
1997 struct wl1273_core **core = pdev->dev.platform_data; in wl1273_fm_radio_probe()
2005 dev_err(&pdev->dev, "No platform data.\n"); in wl1273_fm_radio_probe()
2006 r = -EINVAL; in wl1273_fm_radio_probe()
2010 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL); in wl1273_fm_radio_probe()
2012 r = -ENOMEM; in wl1273_fm_radio_probe()
2017 radio->buf_size = rds_buf * RDS_BLOCK_SIZE; in wl1273_fm_radio_probe()
2018 radio->buffer = devm_kzalloc(&pdev->dev, radio->buf_size, GFP_KERNEL); in wl1273_fm_radio_probe()
2019 if (!radio->buffer) { in wl1273_fm_radio_probe()
2021 r = -ENOMEM; in wl1273_fm_radio_probe()
2025 radio->core = *core; in wl1273_fm_radio_probe()
2026 radio->irq_flags = WL1273_IRQ_MASK; in wl1273_fm_radio_probe()
2027 radio->dev = &radio->core->client->dev; in wl1273_fm_radio_probe()
2028 radio->rds_on = false; in wl1273_fm_radio_probe()
2029 radio->core->mode = WL1273_MODE_OFF; in wl1273_fm_radio_probe()
2030 radio->tx_power = 118; in wl1273_fm_radio_probe()
2031 radio->core->audio_mode = WL1273_AUDIO_ANALOG; in wl1273_fm_radio_probe()
2032 radio->band = WL1273_BAND_OTHER; in wl1273_fm_radio_probe()
2033 radio->core->i2s_mode = WL1273_I2S_DEF_MODE; in wl1273_fm_radio_probe()
2034 radio->core->channel_number = 2; in wl1273_fm_radio_probe()
2035 radio->core->volume = WL1273_DEFAULT_VOLUME; in wl1273_fm_radio_probe()
2036 radio->rx_frequency = WL1273_BAND_OTHER_LOW; in wl1273_fm_radio_probe()
2037 radio->tx_frequency = WL1273_BAND_OTHER_HIGH; in wl1273_fm_radio_probe()
2038 radio->rangelow = WL1273_BAND_OTHER_LOW; in wl1273_fm_radio_probe()
2039 radio->rangehigh = WL1273_BAND_OTHER_HIGH; in wl1273_fm_radio_probe()
2040 radio->stereo = true; in wl1273_fm_radio_probe()
2041 radio->bus_type = "I2C"; in wl1273_fm_radio_probe()
2043 if (radio->core->pdata->request_resources) { in wl1273_fm_radio_probe()
2044 r = radio->core->pdata->request_resources(radio->core->client); in wl1273_fm_radio_probe()
2046 dev_err(radio->dev, WL1273_FM_DRIVER_NAME in wl1273_fm_radio_probe()
2051 dev_dbg(radio->dev, "irq: %d\n", radio->core->client->irq); in wl1273_fm_radio_probe()
2053 r = request_threaded_irq(radio->core->client->irq, NULL, in wl1273_fm_radio_probe()
2056 "wl1273-fm", radio); in wl1273_fm_radio_probe()
2058 dev_err(radio->dev, WL1273_FM_DRIVER_NAME in wl1273_fm_radio_probe()
2063 dev_err(radio->dev, WL1273_FM_DRIVER_NAME ": Core WL1273 IRQ not configured"); in wl1273_fm_radio_probe()
2064 r = -EINVAL; in wl1273_fm_radio_probe()
2068 init_completion(&radio->busy); in wl1273_fm_radio_probe()
2069 init_waitqueue_head(&radio->read_queue); in wl1273_fm_radio_probe()
2071 radio->write_buf = devm_kzalloc(&pdev->dev, 256, GFP_KERNEL); in wl1273_fm_radio_probe()
2072 if (!radio->write_buf) { in wl1273_fm_radio_probe()
2073 r = -ENOMEM; in wl1273_fm_radio_probe()
2077 radio->dev = &pdev->dev; in wl1273_fm_radio_probe()
2078 radio->v4l2dev.ctrl_handler = &radio->ctrl_handler; in wl1273_fm_radio_probe()
2079 radio->rds_users = 0; in wl1273_fm_radio_probe()
2081 r = v4l2_device_register(&pdev->dev, &radio->v4l2dev); in wl1273_fm_radio_probe()
2083 dev_err(&pdev->dev, "Cannot register v4l2_device.\n"); in wl1273_fm_radio_probe()
2088 radio->videodev = wl1273_viddev_template; in wl1273_fm_radio_probe()
2090 radio->videodev.v4l2_dev = &radio->v4l2dev; in wl1273_fm_radio_probe()
2092 v4l2_ctrl_handler_init(&radio->ctrl_handler, 6); in wl1273_fm_radio_probe()
2095 v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops, in wl1273_fm_radio_probe()
2099 v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops, in wl1273_fm_radio_probe()
2102 v4l2_ctrl_new_std_menu(&radio->ctrl_handler, &wl1273_ctrl_ops, in wl1273_fm_radio_probe()
2107 v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops, in wl1273_fm_radio_probe()
2110 ctrl = v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops, in wl1273_fm_radio_probe()
2114 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE; in wl1273_fm_radio_probe()
2116 if (radio->ctrl_handler.error) { in wl1273_fm_radio_probe()
2117 r = radio->ctrl_handler.error; in wl1273_fm_radio_probe()
2118 dev_err(&pdev->dev, "Ctrl handler error: %d\n", r); in wl1273_fm_radio_probe()
2122 video_set_drvdata(&radio->videodev, radio); in wl1273_fm_radio_probe()
2126 r = video_register_device(&radio->videodev, VFL_TYPE_RADIO, radio_nr); in wl1273_fm_radio_probe()
2128 dev_err(&pdev->dev, WL1273_FM_DRIVER_NAME in wl1273_fm_radio_probe()
2136 v4l2_ctrl_handler_free(&radio->ctrl_handler); in wl1273_fm_radio_probe()
2137 v4l2_device_unregister(&radio->v4l2dev); in wl1273_fm_radio_probe()
2139 free_irq(radio->core->client->irq, radio); in wl1273_fm_radio_probe()
2141 radio->core->pdata->free_resources(); in wl1273_fm_radio_probe()