Lines Matching +full:in +full:- +full:band

1 // SPDX-License-Identifier: GPL-2.0-only
16 #include <media/v4l2-device.h>
17 #include <media/v4l2-ioctl.h>
18 #include <media/v4l2-ctrls.h>
19 #include <media/v4l2-event.h>
22 * 'Thanko's Raremono' is a Japanese si4734-based AM/FM/SW USB receiver:
30 * Sadly the firmware used in this product hides lots of goodies since the
42 * The vendor and product IDs (and in fact all other lsusb information as
61 /* Frequency limits in KHz */
74 /* Band FM */
84 /* Band AM */
93 /* Band SW */
112 u32 band; member
122 static int raremono_cmd_main(struct raremono_device *radio, unsigned band, unsigned freq) in raremono_cmd_main() argument
127 switch (band) { in raremono_cmd_main()
139 radio->buffer[0] = 0x04 + band_offset; in raremono_cmd_main()
140 radio->buffer[1] = freq >> 8; in raremono_cmd_main()
141 radio->buffer[2] = freq & 0xff; in raremono_cmd_main()
143 ret = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0), in raremono_cmd_main()
146 0x0300 + radio->buffer[0], 2, in raremono_cmd_main()
147 radio->buffer, 3, USB_TIMEOUT); in raremono_cmd_main()
150 dev_warn(radio->v4l2_dev.dev, "%s failed (%d)\n", __func__, ret); in raremono_cmd_main()
153 radio->curfreq = (band == BAND_FM) ? freq * 10 : freq; in raremono_cmd_main()
158 * We call video_unregister_device in any case.
159 * The last function called in this procedure is
166 dev_info(&intf->dev, "Thanko's Raremono disconnected\n"); in usb_raremono_disconnect()
168 mutex_lock(&radio->lock); in usb_raremono_disconnect()
170 video_unregister_device(&radio->vdev); in usb_raremono_disconnect()
171 v4l2_device_disconnect(&radio->v4l2_dev); in usb_raremono_disconnect()
172 mutex_unlock(&radio->lock); in usb_raremono_disconnect()
173 v4l2_device_put(&radio->v4l2_dev); in usb_raremono_disconnect()
184 strscpy(v->driver, "radio-raremono", sizeof(v->driver)); in vidioc_querycap()
185 strscpy(v->card, "Thanko's Raremono", sizeof(v->card)); in vidioc_querycap()
186 usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info)); in vidioc_querycap()
191 struct v4l2_frequency_band *band) in vidioc_enum_freq_bands() argument
193 if (band->tuner != 0) in vidioc_enum_freq_bands()
194 return -EINVAL; in vidioc_enum_freq_bands()
196 if (band->index >= ARRAY_SIZE(bands)) in vidioc_enum_freq_bands()
197 return -EINVAL; in vidioc_enum_freq_bands()
199 *band = bands[band->index]; in vidioc_enum_freq_bands()
210 if (v->index > 0) in vidioc_g_tuner()
211 return -EINVAL; in vidioc_g_tuner()
213 strscpy(v->name, "AM/FM/SW", sizeof(v->name)); in vidioc_g_tuner()
214 v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO | in vidioc_g_tuner()
216 v->rangelow = AM_FREQ_RANGE_LOW * 16; in vidioc_g_tuner()
217 v->rangehigh = FM_FREQ_RANGE_HIGH * 16; in vidioc_g_tuner()
218 v->rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO; in vidioc_g_tuner()
219 v->audmode = (radio->curfreq < FM_FREQ_RANGE_LOW) ? in vidioc_g_tuner()
221 memset(radio->buffer, 1, BUFFER_LENGTH); in vidioc_g_tuner()
222 ret = usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), in vidioc_g_tuner()
223 1, 0xa1, 0x030d, 2, radio->buffer, BUFFER_LENGTH, USB_TIMEOUT); in vidioc_g_tuner()
226 dev_warn(radio->v4l2_dev.dev, "%s failed (%d)\n", __func__, ret); in vidioc_g_tuner()
229 v->signal = ((radio->buffer[1] & 0xf) << 8 | radio->buffer[2]) << 4; in vidioc_g_tuner()
236 return v->index ? -EINVAL : 0; in vidioc_s_tuner()
244 unsigned band; in vidioc_s_frequency() local
246 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) in vidioc_s_frequency()
247 return -EINVAL; in vidioc_s_frequency()
249 if (f->frequency >= (FM_FREQ_RANGE_LOW + SW_FREQ_RANGE_HIGH) * 8) in vidioc_s_frequency()
250 band = BAND_FM; in vidioc_s_frequency()
251 else if (f->frequency <= (AM_FREQ_RANGE_HIGH + SW_FREQ_RANGE_LOW) * 8) in vidioc_s_frequency()
252 band = BAND_AM; in vidioc_s_frequency()
254 band = BAND_SW; in vidioc_s_frequency()
256 freq = clamp_t(u32, f->frequency, bands[band].rangelow, bands[band].rangehigh); in vidioc_s_frequency()
257 return raremono_cmd_main(radio, band, freq / 16); in vidioc_s_frequency()
265 if (f->tuner != 0) in vidioc_g_frequency()
266 return -EINVAL; in vidioc_g_frequency()
267 f->type = V4L2_TUNER_RADIO; in vidioc_g_frequency()
268 f->frequency = radio->curfreq * 16; in vidioc_g_frequency()
276 kfree(radio->buffer); in raremono_device_release()
306 return -ENOMEM; in usb_raremono_probe()
307 radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL); in usb_raremono_probe()
308 if (!radio->buffer) { in usb_raremono_probe()
310 return -ENOMEM; in usb_raremono_probe()
313 radio->usbdev = interface_to_usbdev(intf); in usb_raremono_probe()
314 radio->intf = intf; in usb_raremono_probe()
326 retval = usb_control_msg(radio->usbdev, in usb_raremono_probe()
327 usb_rcvctrlpipe(radio->usbdev, 0), in usb_raremono_probe()
331 radio->buffer, 3, 500); in usb_raremono_probe()
333 (get_unaligned_be16(&radio->buffer[1]) & 0xfff) == 0x0242) { in usb_raremono_probe()
334 dev_info(&intf->dev, "this is not Thanko's Raremono.\n"); in usb_raremono_probe()
335 retval = -ENODEV; in usb_raremono_probe()
339 dev_info(&intf->dev, "Thanko's Raremono connected: (%04X:%04X)\n", in usb_raremono_probe()
340 id->idVendor, id->idProduct); in usb_raremono_probe()
342 retval = v4l2_device_register(&intf->dev, &radio->v4l2_dev); in usb_raremono_probe()
344 dev_err(&intf->dev, "couldn't register v4l2_device\n"); in usb_raremono_probe()
348 mutex_init(&radio->lock); in usb_raremono_probe()
350 strscpy(radio->vdev.name, radio->v4l2_dev.name, in usb_raremono_probe()
351 sizeof(radio->vdev.name)); in usb_raremono_probe()
352 radio->vdev.v4l2_dev = &radio->v4l2_dev; in usb_raremono_probe()
353 radio->vdev.fops = &usb_raremono_fops; in usb_raremono_probe()
354 radio->vdev.ioctl_ops = &usb_raremono_ioctl_ops; in usb_raremono_probe()
355 radio->vdev.lock = &radio->lock; in usb_raremono_probe()
356 radio->vdev.release = video_device_release_empty; in usb_raremono_probe()
357 radio->vdev.device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO; in usb_raremono_probe()
358 radio->v4l2_dev.release = raremono_device_release; in usb_raremono_probe()
360 usb_set_intfdata(intf, &radio->v4l2_dev); in usb_raremono_probe()
362 video_set_drvdata(&radio->vdev, radio); in usb_raremono_probe()
366 retval = video_register_device(&radio->vdev, VFL_TYPE_RADIO, -1); in usb_raremono_probe()
368 dev_info(&intf->dev, "V4L2 device registered as %s\n", in usb_raremono_probe()
369 video_device_node_name(&radio->vdev)); in usb_raremono_probe()
372 dev_err(&intf->dev, "could not register video device\n"); in usb_raremono_probe()
373 v4l2_device_unregister(&radio->v4l2_dev); in usb_raremono_probe()
376 kfree(radio->buffer); in usb_raremono_probe()
383 .name = "radio-raremono",