Lines Matching +full:tx +full:- +full:freq
1 // SPDX-License-Identifier: GPL-2.0-or-later
13 #include <media/v4l2-device.h>
14 #include <media/v4l2-ioctl.h>
15 #include <media/v4l2-ctrls.h>
16 #include <media/v4l2-event.h>
57 u8 tx; member
69 /* Set frequency (if non-0), PA, mute and turn on/off the FM transmitter. */
70 static int keene_cmd_main(struct keene_device *radio, unsigned freq, bool play) in keene_cmd_main() argument
72 unsigned short freq_send = freq ? (freq - 76 * 16000) / 800 : 0; in keene_cmd_main()
75 radio->buffer[0] = 0x00; in keene_cmd_main()
76 radio->buffer[1] = 0x50; in keene_cmd_main()
77 radio->buffer[2] = (freq_send >> 8) & 0xff; in keene_cmd_main()
78 radio->buffer[3] = freq_send & 0xff; in keene_cmd_main()
79 radio->buffer[4] = radio->pa; in keene_cmd_main()
85 radio->buffer[5] = (radio->muted ? 4 : 8) | (play ? 1 : 2) | in keene_cmd_main()
86 (freq ? 0x10 : 0); in keene_cmd_main()
87 radio->buffer[6] = 0x00; in keene_cmd_main()
88 radio->buffer[7] = 0x00; in keene_cmd_main()
90 ret = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0), in keene_cmd_main()
91 9, 0x21, 0x200, 2, radio->buffer, BUFFER_LENGTH, USB_TIMEOUT); in keene_cmd_main()
94 dev_warn(&radio->vdev.dev, "%s failed (%d)\n", __func__, ret); in keene_cmd_main()
97 if (freq) in keene_cmd_main()
98 radio->curfreq = freq; in keene_cmd_main()
102 /* Set TX, stereo and preemphasis mode (50 us vs 75 us). */
107 radio->buffer[0] = 0x00; in keene_cmd_set()
108 radio->buffer[1] = 0x51; in keene_cmd_set()
109 radio->buffer[2] = radio->tx; in keene_cmd_set()
113 radio->buffer[3] = (radio->stereo ? 0 : 1) | (radio->preemph_75_us ? 4 : 0); in keene_cmd_set()
114 radio->buffer[4] = 0x00; in keene_cmd_set()
115 radio->buffer[5] = 0x00; in keene_cmd_set()
116 radio->buffer[6] = 0x00; in keene_cmd_set()
117 radio->buffer[7] = 0x00; in keene_cmd_set()
119 ret = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0), in keene_cmd_set()
120 9, 0x21, 0x200, 2, radio->buffer, BUFFER_LENGTH, USB_TIMEOUT); in keene_cmd_set()
123 dev_warn(&radio->vdev.dev, "%s failed (%d)\n", __func__, ret); in keene_cmd_set()
138 mutex_lock(&radio->lock); in usb_keene_disconnect()
140 video_unregister_device(&radio->vdev); in usb_keene_disconnect()
141 v4l2_device_disconnect(&radio->v4l2_dev); in usb_keene_disconnect()
142 mutex_unlock(&radio->lock); in usb_keene_disconnect()
143 v4l2_device_put(&radio->v4l2_dev); in usb_keene_disconnect()
159 keene_cmd_main(radio, radio->curfreq, true); in usb_keene_resume()
168 strscpy(v->driver, "radio-keene", sizeof(v->driver)); in vidioc_querycap()
169 strscpy(v->card, "Keene FM Transmitter", sizeof(v->card)); in vidioc_querycap()
170 usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info)); in vidioc_querycap()
179 if (v->index > 0) in vidioc_g_modulator()
180 return -EINVAL; in vidioc_g_modulator()
182 strscpy(v->name, "FM", sizeof(v->name)); in vidioc_g_modulator()
183 v->rangelow = FREQ_MIN * FREQ_MUL; in vidioc_g_modulator()
184 v->rangehigh = FREQ_MAX * FREQ_MUL; in vidioc_g_modulator()
185 v->txsubchans = radio->stereo ? V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO; in vidioc_g_modulator()
186 v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO; in vidioc_g_modulator()
195 if (v->index > 0) in vidioc_s_modulator()
196 return -EINVAL; in vidioc_s_modulator()
198 radio->stereo = (v->txsubchans == V4L2_TUNER_SUB_STEREO); in vidioc_s_modulator()
206 unsigned freq = f->frequency; in vidioc_s_frequency() local
208 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) in vidioc_s_frequency()
209 return -EINVAL; in vidioc_s_frequency()
210 freq = clamp(freq, FREQ_MIN * FREQ_MUL, FREQ_MAX * FREQ_MUL); in vidioc_s_frequency()
211 return keene_cmd_main(radio, freq, true); in vidioc_s_frequency()
219 if (f->tuner != 0) in vidioc_g_frequency()
220 return -EINVAL; in vidioc_g_frequency()
221 f->type = V4L2_TUNER_RADIO; in vidioc_g_frequency()
222 f->frequency = radio->curfreq; in vidioc_g_frequency()
229 /* -15, -12, -9, -6, -3, 0 dB */ in keene_s_ctrl()
235 container_of(ctrl->handler, struct keene_device, hdl); in keene_s_ctrl()
237 switch (ctrl->id) { in keene_s_ctrl()
239 radio->muted = ctrl->val; in keene_s_ctrl()
245 radio->pa = (ctrl->val - 71) * 100 / 62; in keene_s_ctrl()
249 radio->preemph_75_us = ctrl->val == V4L2_PREEMPHASIS_75_uS; in keene_s_ctrl()
253 radio->tx = db2tx[(ctrl->val - (s32)ctrl->minimum) / (s32)ctrl->step]; in keene_s_ctrl()
256 return -EINVAL; in keene_s_ctrl()
288 v4l2_ctrl_handler_free(&radio->hdl); in usb_keene_video_device_release()
289 kfree(radio->buffer); in usb_keene_video_device_release()
311 if (dev->product && strcmp(dev->product, "B-LINK USB Audio ")) in usb_keene_probe()
312 return -ENODEV; in usb_keene_probe()
316 radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL); in usb_keene_probe()
318 if (!radio || !radio->buffer) { in usb_keene_probe()
319 dev_err(&intf->dev, "kmalloc for keene_device failed\n"); in usb_keene_probe()
321 retval = -ENOMEM; in usb_keene_probe()
325 hdl = &radio->hdl; in usb_keene_probe()
334 -15, 18, 3, 0); in usb_keene_probe()
335 radio->pa = 118; in usb_keene_probe()
336 radio->tx = 0x32; in usb_keene_probe()
337 radio->stereo = true; in usb_keene_probe()
338 if (hdl->error) { in usb_keene_probe()
339 retval = hdl->error; in usb_keene_probe()
344 retval = v4l2_device_register(&intf->dev, &radio->v4l2_dev); in usb_keene_probe()
346 dev_err(&intf->dev, "couldn't register v4l2_device\n"); in usb_keene_probe()
350 mutex_init(&radio->lock); in usb_keene_probe()
352 radio->v4l2_dev.ctrl_handler = hdl; in usb_keene_probe()
353 radio->v4l2_dev.release = usb_keene_video_device_release; in usb_keene_probe()
354 strscpy(radio->vdev.name, radio->v4l2_dev.name, in usb_keene_probe()
355 sizeof(radio->vdev.name)); in usb_keene_probe()
356 radio->vdev.v4l2_dev = &radio->v4l2_dev; in usb_keene_probe()
357 radio->vdev.fops = &usb_keene_fops; in usb_keene_probe()
358 radio->vdev.ioctl_ops = &usb_keene_ioctl_ops; in usb_keene_probe()
359 radio->vdev.lock = &radio->lock; in usb_keene_probe()
360 radio->vdev.release = video_device_release_empty; in usb_keene_probe()
361 radio->vdev.vfl_dir = VFL_DIR_TX; in usb_keene_probe()
362 radio->vdev.device_caps = V4L2_CAP_RADIO | V4L2_CAP_MODULATOR; in usb_keene_probe()
364 radio->usbdev = interface_to_usbdev(intf); in usb_keene_probe()
365 radio->intf = intf; in usb_keene_probe()
366 usb_set_intfdata(intf, &radio->v4l2_dev); in usb_keene_probe()
368 video_set_drvdata(&radio->vdev, radio); in usb_keene_probe()
374 retval = video_register_device(&radio->vdev, VFL_TYPE_RADIO, -1); in usb_keene_probe()
376 dev_err(&intf->dev, "could not register video device\n"); in usb_keene_probe()
380 dev_info(&intf->dev, "V4L2 device registered as %s\n", in usb_keene_probe()
381 video_device_node_name(&radio->vdev)); in usb_keene_probe()
385 v4l2_device_unregister(&radio->v4l2_dev); in usb_keene_probe()
387 kfree(radio->buffer); in usb_keene_probe()
395 .name = "radio-keene",