Lines Matching refs:radio

3  * Driver for the Texas Instruments WL1273 FM radio.
35 * static int radio_nr - The number of the radio device
41 MODULE_PARM_DESC(radio_nr, "The number of the radio device. Default = 0");
61 struct mutex lock; /* for serializing fm radio operations */
131 static int wl1273_fm_rds(struct wl1273_device *radio)
133 struct wl1273_core *core = radio->core;
170 dev_err(radio->dev, WL1273_FM_DRIVER_NAME
194 memcpy(&radio->buffer[radio->wr_index], &rds, RDS_BLOCK_SIZE);
195 radio->wr_index += 3;
198 if (radio->wr_index >= radio->buf_size)
199 radio->wr_index = 0;
202 if (radio->wr_index == radio->rd_index) {
203 dev_dbg(radio->dev, "RDS OVERFLOW");
205 radio->rd_index = 0;
206 radio->wr_index = 0;
212 if (radio->wr_index != radio->rd_index)
213 wake_up_interruptible(&radio->read_queue);
220 struct wl1273_device *radio = dev_id;
221 struct wl1273_core *core = radio->core;
230 radio->irq_received = flags;
231 dev_dbg(radio->dev, "IRQ: BL\n");
237 wl1273_fm_rds(radio);
241 dev_dbg(radio->dev, "IRQ: BBLK\n");
244 dev_dbg(radio->dev, "IRQ: LSYNC\n");
254 dev_dbg(radio->dev, "IRQ: LEV: 0x%x04\n", level);
258 dev_dbg(radio->dev, "IRQ: IFFR\n");
261 dev_dbg(radio->dev, "IRQ: PI\n");
264 dev_dbg(radio->dev, "IRQ: PD\n");
267 dev_dbg(radio->dev, "IRQ: STIC\n");
270 dev_dbg(radio->dev, "IRQ: MAL\n");
273 complete(&radio->busy);
274 dev_dbg(radio->dev, "NOT BUSY\n");
275 dev_dbg(radio->dev, "IRQ: POW_ENB\n");
279 dev_dbg(radio->dev, "IRQ: SCAN_OVER\n");
282 dev_dbg(radio->dev, "IRQ: ERROR\n");
287 dev_dbg(radio->dev, "IRQ: FR:\n");
293 dev_err(radio->dev,
303 if (radio->band == WL1273_BAND_JAPAN)
304 radio->rx_frequency = WL1273_BAND_JAPAN_LOW +
307 radio->rx_frequency = WL1273_BAND_OTHER_LOW +
315 dev_dbg(radio->dev, "%dkHz\n", radio->rx_frequency);
322 dev_dbg(radio->dev, "%dkHz\n", freq);
324 dev_dbg(radio->dev, "%s: NOT BUSY\n", __func__);
328 core->write(core, WL1273_INT_MASK_SET, radio->irq_flags);
329 complete(&radio->busy);
334 static int wl1273_fm_set_tx_freq(struct wl1273_device *radio, unsigned int freq)
336 struct wl1273_core *core = radio->core;
341 dev_err(radio->dev,
348 dev_err(radio->dev,
360 dev_dbg(radio->dev, "%s: freq: %d kHz\n", __func__, freq);
367 reinit_completion(&radio->busy);
370 t = wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(2000));
374 dev_dbg(radio->dev, "WL1273_CHANL_SET: %lu\n", t);
381 reinit_completion(&radio->busy);
384 t = wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(1000));
388 radio->tx_frequency = freq;
389 dev_dbg(radio->dev, "WL1273_POWER_ENB_SET: %lu\n", t);
394 static int wl1273_fm_set_rx_freq(struct wl1273_device *radio, unsigned int freq)
396 struct wl1273_core *core = radio->core;
400 if (freq < radio->rangelow) {
401 dev_err(radio->dev,
403 radio->rangelow);
408 if (freq > radio->rangehigh) {
409 dev_err(radio->dev,
411 radio->rangehigh);
416 dev_dbg(radio->dev, "%s: %dkHz\n", __func__, freq);
418 core->write(core, WL1273_INT_MASK_SET, radio->irq_flags);
420 if (radio->band == WL1273_BAND_JAPAN)
427 dev_err(radio->dev, "FREQ_SET fails\n");
433 dev_err(radio->dev, "TUNER_MODE_SET fails\n");
437 reinit_completion(&radio->busy);
439 t = wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(2000));
441 dev_err(radio->dev, "%s: TIMEOUT\n", __func__);
445 radio->rd_index = 0;
446 radio->wr_index = 0;
447 radio->rx_frequency = freq;
453 static int wl1273_fm_get_freq(struct wl1273_device *radio)
455 struct wl1273_core *core = radio->core;
465 dev_dbg(radio->dev, "Freq get: 0x%04x\n", f);
466 if (radio->band == WL1273_BAND_JAPAN)
483 * @radio: A pointer to the device struct.
489 static int wl1273_fm_upload_firmware_patch(struct wl1273_device *radio)
491 struct wl1273_core *core = radio->core;
494 const char *fw_name = "radio-wl1273-fw.bin";
495 struct device *dev = radio->dev;
530 static int wl1273_fm_stop(struct wl1273_device *radio)
532 struct wl1273_core *core = radio->core;
538 dev_err(radio->dev, "%s: POWER_SET fails: %d\n",
544 dev_err(radio->dev,
550 dev_dbg(radio->dev, "Back to reset\n");
556 static int wl1273_fm_start(struct wl1273_device *radio, int new_mode)
558 struct wl1273_core *core = radio->core;
560 struct device *dev = radio->dev;
564 dev_dbg(radio->dev, "Out of reset\n");
573 if (radio->rds_on)
589 radio->wr_index = 0;
590 radio->rd_index = 0;
605 if (radio->rds_on) {
625 r = wl1273_fm_upload_firmware_patch(radio);
636 if (radio->rds_on)
663 static int wl1273_fm_suspend(struct wl1273_device *radio)
665 struct wl1273_core *core = radio->core;
679 dev_err(radio->dev, "%s: POWER_SET fails: %d\n", __func__, r);
687 static int wl1273_fm_set_mode(struct wl1273_device *radio, int mode)
689 struct wl1273_core *core = radio->core;
690 struct device *dev = radio->dev;
695 dev_dbg(dev, "Forbidden modes: 0x%02x\n", radio->forbidden);
698 if (mode & radio->forbidden) {
706 r = wl1273_fm_start(radio, mode);
709 wl1273_fm_stop(radio);
714 r = core->write(core, WL1273_INT_MASK_SET, radio->irq_flags);
722 r = wl1273_fm_set_rx_freq(radio, radio->rx_frequency);
737 r = wl1273_fm_set_tx_freq(radio, radio->tx_frequency);
744 dev_dbg(radio->dev, "%s: Set audio mode.\n", __func__);
752 r = wl1273_fm_stop(radio);
761 r = wl1273_fm_suspend(radio);
781 static int wl1273_fm_set_seek(struct wl1273_device *radio,
786 struct wl1273_core *core = radio->core;
791 f = radio->rx_frequency;
792 dev_dbg(radio->dev, "rx_frequency: %d\n", f);
794 if (dir && f + radio->spacing <= radio->rangehigh)
795 r = wl1273_fm_set_rx_freq(radio, f + radio->spacing);
797 r = wl1273_fm_set_rx_freq(radio, radio->rangelow);
798 else if (f - radio->spacing >= radio->rangelow)
799 r = wl1273_fm_set_rx_freq(radio, f - radio->spacing);
801 r = wl1273_fm_set_rx_freq(radio, radio->rangehigh);
809 reinit_completion(&radio->busy);
810 dev_dbg(radio->dev, "%s: BUSY\n", __func__);
812 r = core->write(core, WL1273_INT_MASK_SET, radio->irq_flags);
816 dev_dbg(radio->dev, "%s\n", __func__);
831 wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(1000));
832 if (!(radio->irq_received & WL1273_BL_EVENT)) {
837 radio->irq_received &= ~WL1273_BL_EVENT;
843 dev_dbg(radio->dev, "Wrap around in HW seek.\n");
846 f = radio->rangelow;
848 f = radio->rangehigh;
850 r = wl1273_fm_set_rx_freq(radio, f);
854 reinit_completion(&radio->busy);
855 dev_dbg(radio->dev, "%s: BUSY\n", __func__);
862 if (!wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(1000)))
865 dev_dbg(radio->dev, "%s: Err: %d\n", __func__, r);
871 * @radio: A pointer to the device struct.
873 static unsigned int wl1273_fm_get_tx_ctune(struct wl1273_device *radio)
875 struct wl1273_core *core = radio->core;
876 struct device *dev = radio->dev;
896 * @radio: A pointer to the device struct.
902 static int wl1273_fm_set_preemphasis(struct wl1273_device *radio,
905 struct wl1273_core *core = radio->core;
934 radio->preemphasis = preemphasis;
941 static int wl1273_fm_rds_on(struct wl1273_device *radio)
943 struct wl1273_core *core = radio->core;
946 dev_dbg(radio->dev, "%s\n", __func__);
947 if (radio->rds_on)
955 r = wl1273_fm_set_rx_freq(radio, radio->rx_frequency);
957 dev_err(radio->dev, "set freq fails: %d.\n", r);
962 static int wl1273_fm_rds_off(struct wl1273_device *radio)
964 struct wl1273_core *core = radio->core;
967 if (!radio->rds_on)
970 radio->irq_flags &= ~WL1273_RDS_EVENT;
972 r = core->write(core, WL1273_INT_MASK_SET, radio->irq_flags);
977 wake_up_interruptible(&radio->read_queue);
979 dev_dbg(radio->dev, "%s\n", __func__);
985 r = wl1273_fm_set_rx_freq(radio, radio->rx_frequency);
987 dev_err(radio->dev, "set freq fails: %d.\n", r);
989 dev_dbg(radio->dev, "%s: exiting...\n", __func__);
994 static int wl1273_fm_set_rds(struct wl1273_device *radio, unsigned int new_mode)
997 struct wl1273_core *core = radio->core;
1013 r = wl1273_fm_rds_off(radio);
1015 r = wl1273_fm_rds_on(radio);
1017 dev_err(radio->dev, "%s: Unknown mode: %d\n",
1023 radio->rds_on = (new_mode == WL1273_RDS_ON) ? true : false;
1031 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1032 struct wl1273_core *core = radio->core;
1036 dev_dbg(radio->dev, "%s\n", __func__);
1041 if (radio->rds_users == 0) {
1042 dev_warn(radio->dev, "%s: RDS not on.\n", __func__);
1052 if (radio->owner && radio->owner != file) {
1056 radio->owner = file;
1066 if (copy_from_user(radio->write_buf + 1, buf, val)) {
1071 dev_dbg(radio->dev, "Count: %d\n", val);
1072 dev_dbg(radio->dev, "From user: \"%s\"\n", radio->write_buf);
1074 radio->write_buf[0] = WL1273_RDS_DATA_SET;
1075 core->write_data(core, radio->write_buf, val + 1);
1087 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1088 struct wl1273_core *core = radio->core;
1090 if (radio->owner && radio->owner != file)
1093 radio->owner = file;
1096 poll_wait(file, &radio->read_queue, pts);
1098 if (radio->rd_index != radio->wr_index)
1110 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1111 struct wl1273_core *core = radio->core;
1114 dev_dbg(radio->dev, "%s\n", __func__);
1116 if (core->mode == WL1273_MODE_RX && radio->rds_on &&
1117 !radio->rds_users) {
1118 dev_dbg(radio->dev, "%s: Mode: %d\n", __func__, core->mode);
1123 radio->irq_flags |= WL1273_RDS_EVENT;
1126 radio->irq_flags);
1132 radio->rds_users++;
1142 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1143 struct wl1273_core *core = radio->core;
1146 dev_dbg(radio->dev, "%s\n", __func__);
1148 if (radio->rds_users > 0) {
1149 radio->rds_users--;
1150 if (radio->rds_users == 0) {
1153 radio->irq_flags &= ~WL1273_RDS_EVENT;
1158 radio->irq_flags);
1168 if (file == radio->owner)
1169 radio->owner = NULL;
1178 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1179 struct wl1273_core *core = radio->core;
1183 dev_dbg(radio->dev, "%s\n", __func__);
1188 if (radio->rds_users == 0) {
1189 dev_warn(radio->dev, "%s: RDS not on.\n", __func__);
1200 if (radio->owner && radio->owner != file) {
1204 radio->owner = file;
1208 dev_err(radio->dev, "%s: Get RDS_SYNC fails.\n", __func__);
1211 dev_info(radio->dev, "RDS_SYNC: Not synchronized\n");
1217 while (radio->wr_index == radio->rd_index) {
1223 dev_dbg(radio->dev, "%s: Wait for RDS data.\n", __func__);
1224 if (wait_event_interruptible(radio->read_queue,
1225 radio->wr_index !=
1226 radio->rd_index) < 0) {
1237 if (radio->rd_index == radio->wr_index)
1241 if (copy_to_user(buf, &radio->buffer[radio->rd_index],
1246 radio->rd_index += RDS_BLOCK_SIZE;
1247 if (radio->rd_index >= radio->buf_size)
1248 radio->rd_index = 0;
1257 dev_dbg(radio->dev, "%s: exit\n", __func__);
1276 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1278 dev_dbg(radio->dev, "%s\n", __func__);
1284 strscpy(capability->bus_info, radio->bus_type,
1292 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1294 dev_dbg(radio->dev, "%s\n", __func__);
1304 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1306 dev_dbg(radio->dev, "%s\n", __func__);
1316 * @radio: A pointer to the device struct.
1319 static int wl1273_fm_set_tx_power(struct wl1273_device *radio, u16 power)
1321 struct wl1273_core *core = radio->core;
1335 radio->tx_power = power;
1346 static int wl1273_fm_tx_set_spacing(struct wl1273_device *radio,
1349 struct wl1273_core *core = radio->core;
1355 radio->spacing = 100;
1359 radio->spacing = 50;
1363 radio->spacing = 100;
1367 radio->spacing = 200;
1375 struct wl1273_device *radio = ctrl->priv;
1376 struct wl1273_core *core = radio->core;
1378 dev_dbg(radio->dev, "%s\n", __func__);
1385 ctrl->val = wl1273_fm_get_tx_ctune(radio);
1389 dev_warn(radio->dev, "%s: Unknown IOCTL: %d\n",
1412 struct wl1273_device *radio = to_radio(ctrl);
1413 struct wl1273_core *core = radio->core;
1416 dev_dbg(radio->dev, "%s\n", __func__);
1441 r = wl1273_fm_set_mode(radio, WL1273_MODE_OFF);
1447 r = wl1273_fm_set_preemphasis(radio, ctrl->val);
1451 r = wl1273_fm_set_tx_power(radio, ctrl->val);
1455 dev_warn(radio->dev, "%s: Unknown IOCTL: %d\n",
1460 dev_dbg(radio->dev, "%s\n", __func__);
1467 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1469 dev_dbg(radio->dev, "%s\n", __func__);
1483 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1485 dev_dbg(radio->dev, "%s\n", __func__);
1499 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1500 struct wl1273_core *core = radio->core;
1504 dev_dbg(radio->dev, "%s\n", __func__);
1519 if (radio->stereo)
1544 dev_dbg(radio->dev, "Signal: %d\n", tuner->signal);
1563 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1564 struct wl1273_core *core = radio->core;
1567 dev_dbg(radio->dev, "%s\n", __func__);
1568 dev_dbg(radio->dev, "tuner->index: %d\n", tuner->index);
1569 dev_dbg(radio->dev, "tuner->name: %s\n", tuner->name);
1570 dev_dbg(radio->dev, "tuner->capability: 0x%04x\n", tuner->capability);
1571 dev_dbg(radio->dev, "tuner->rxsubchans: 0x%04x\n", tuner->rxsubchans);
1572 dev_dbg(radio->dev, "tuner->rangelow: %d\n", tuner->rangelow);
1573 dev_dbg(radio->dev, "tuner->rangehigh: %d\n", tuner->rangehigh);
1581 r = wl1273_fm_set_mode(radio, WL1273_MODE_RX);
1586 r = wl1273_fm_set_rds(radio, WL1273_RDS_ON);
1588 r = wl1273_fm_set_rds(radio, WL1273_RDS_OFF);
1591 dev_warn(radio->dev, "%s: RDS fails: %d\n", __func__, r);
1596 dev_warn(radio->dev, "%s: MOST_MODE fails: %d\n",
1600 radio->stereo = false;
1604 dev_warn(radio->dev, "%s: MOST_MODE fails: %d\n",
1608 radio->stereo = true;
1610 dev_err(radio->dev, "%s: tuner->audmode: %d\n",
1625 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1626 struct wl1273_core *core = radio->core;
1628 dev_dbg(radio->dev, "%s\n", __func__);
1634 freq->frequency = WL1273_FREQ(wl1273_fm_get_freq(radio));
1644 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1645 struct wl1273_core *core = radio->core;
1648 dev_dbg(radio->dev, "%s: %d\n", __func__, freq->frequency);
1651 dev_dbg(radio->dev,
1660 dev_dbg(radio->dev, "freq: %d\n", freq->frequency);
1662 r = wl1273_fm_set_rx_freq(radio,
1665 dev_warn(radio->dev, WL1273_FM_DRIVER_NAME
1668 r = wl1273_fm_set_tx_freq(radio,
1671 dev_warn(radio->dev, WL1273_FM_DRIVER_NAME
1677 dev_dbg(radio->dev, "wl1273_vidioc_s_frequency: DONE\n");
1686 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1687 struct wl1273_core *core = radio->core;
1690 dev_dbg(radio->dev, "%s\n", __func__);
1701 r = wl1273_fm_set_mode(radio, WL1273_MODE_RX);
1705 r = wl1273_fm_tx_set_spacing(radio, seek->spacing);
1707 dev_warn(radio->dev, "HW seek failed: %d\n", r);
1709 r = wl1273_fm_set_seek(radio, seek->wrap_around, seek->seek_upward,
1712 dev_warn(radio->dev, "HW seek failed: %d\n", r);
1722 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1723 struct wl1273_core *core = radio->core;
1726 dev_dbg(radio->dev, "%s\n", __func__);
1734 r = wl1273_fm_set_mode(radio, WL1273_MODE_TX);
1739 r = wl1273_fm_set_rds(radio, WL1273_RDS_ON);
1741 r = wl1273_fm_set_rds(radio, WL1273_RDS_OFF);
1749 dev_warn(radio->dev, WL1273_FM_DRIVER_NAME
1760 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1761 struct wl1273_core *core = radio->core;
1765 dev_dbg(radio->dev, "%s\n", __func__);
1791 if (radio->rds_on)
1801 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1802 struct wl1273_core *core = radio->core;
1803 struct device *dev = radio->dev;
1856 int bf = radio->rangelow;
1982 struct wl1273_device *radio = platform_get_drvdata(pdev);
1983 struct wl1273_core *core = radio->core;
1987 free_irq(core->client->irq, radio);
1990 v4l2_ctrl_handler_free(&radio->ctrl_handler);
1991 video_unregister_device(&radio->videodev);
1992 v4l2_device_unregister(&radio->v4l2dev);
2000 struct wl1273_device *radio;
2012 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
2013 if (!radio) {
2019 radio->buf_size = rds_buf * RDS_BLOCK_SIZE;
2020 radio->buffer = devm_kzalloc(&pdev->dev, radio->buf_size, GFP_KERNEL);
2021 if (!radio->buffer) {
2027 radio->core = *core;
2028 radio->irq_flags = WL1273_IRQ_MASK;
2029 radio->dev = &radio->core->client->dev;
2030 radio->rds_on = false;
2031 radio->core->mode = WL1273_MODE_OFF;
2032 radio->tx_power = 118;
2033 radio->core->audio_mode = WL1273_AUDIO_ANALOG;
2034 radio->band = WL1273_BAND_OTHER;
2035 radio->core->i2s_mode = WL1273_I2S_DEF_MODE;
2036 radio->core->channel_number = 2;
2037 radio->core->volume = WL1273_DEFAULT_VOLUME;
2038 radio->rx_frequency = WL1273_BAND_OTHER_LOW;
2039 radio->tx_frequency = WL1273_BAND_OTHER_HIGH;
2040 radio->rangelow = WL1273_BAND_OTHER_LOW;
2041 radio->rangehigh = WL1273_BAND_OTHER_HIGH;
2042 radio->stereo = true;
2043 radio->bus_type = "I2C";
2045 if (radio->core->pdata->request_resources) {
2046 r = radio->core->pdata->request_resources(radio->core->client);
2048 dev_err(radio->dev, WL1273_FM_DRIVER_NAME
2053 dev_dbg(radio->dev, "irq: %d\n", radio->core->client->irq);
2055 r = request_threaded_irq(radio->core->client->irq, NULL,
2058 "wl1273-fm", radio);
2060 dev_err(radio->dev, WL1273_FM_DRIVER_NAME
2065 dev_err(radio->dev, WL1273_FM_DRIVER_NAME ": Core WL1273 IRQ not configured");
2070 init_completion(&radio->busy);
2071 init_waitqueue_head(&radio->read_queue);
2073 radio->write_buf = devm_kzalloc(&pdev->dev, 256, GFP_KERNEL);
2074 if (!radio->write_buf) {
2079 radio->dev = &pdev->dev;
2080 radio->v4l2dev.ctrl_handler = &radio->ctrl_handler;
2081 radio->rds_users = 0;
2083 r = v4l2_device_register(&pdev->dev, &radio->v4l2dev);
2090 radio->videodev = wl1273_viddev_template;
2092 radio->videodev.v4l2_dev = &radio->v4l2dev;
2094 v4l2_ctrl_handler_init(&radio->ctrl_handler, 6);
2097 v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops,
2101 v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops,
2104 v4l2_ctrl_new_std_menu(&radio->ctrl_handler, &wl1273_ctrl_ops,
2109 v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops,
2112 ctrl = v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops,
2118 if (radio->ctrl_handler.error) {
2119 r = radio->ctrl_handler.error;
2124 video_set_drvdata(&radio->videodev, radio);
2125 platform_set_drvdata(pdev, radio);
2128 r = video_register_device(&radio->videodev, VFL_TYPE_RADIO, radio_nr);
2138 v4l2_ctrl_handler_free(&radio->ctrl_handler);
2139 v4l2_device_unregister(&radio->v4l2dev);
2141 free_irq(radio->core->client->irq, radio);
2143 radio->core->pdata->free_resources();