drivers/media/radio/radio-keene.c
Source file repositories/reference/linux-study-clean/drivers/media/radio/radio-keene.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/radio/radio-keene.c- Extension
.c- Size
- 11369 bytes
- Lines
- 406
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/init.hlinux/slab.hlinux/input.hlinux/videodev2.hmedia/v4l2-device.hmedia/v4l2-ioctl.hmedia/v4l2-ctrls.hmedia/v4l2-event.hlinux/usb.hlinux/mutex.h
Detected Declarations
struct keene_devicefunction keene_cmd_mainfunction keene_cmd_setfunction usb_keene_disconnectfunction usb_keene_suspendfunction usb_keene_resumefunction vidioc_querycapfunction vidioc_g_modulatorfunction vidioc_s_modulatorfunction vidioc_s_frequencyfunction vidioc_g_frequencyfunction keene_s_ctrlfunction usb_keene_video_device_releasefunction usb_keene_probe
Annotated Snippet
struct keene_device {
struct usb_device *usbdev;
struct usb_interface *intf;
struct video_device vdev;
struct v4l2_device v4l2_dev;
struct v4l2_ctrl_handler hdl;
struct mutex lock;
u8 *buffer;
unsigned curfreq;
u8 tx;
u8 pa;
bool stereo;
bool muted;
bool preemph_75_us;
};
static inline struct keene_device *to_keene_dev(struct v4l2_device *v4l2_dev)
{
return container_of(v4l2_dev, struct keene_device, v4l2_dev);
}
/* Set frequency (if non-0), PA, mute and turn on/off the FM transmitter. */
static int keene_cmd_main(struct keene_device *radio, unsigned freq, bool play)
{
unsigned short freq_send = freq ? (freq - 76 * 16000) / 800 : 0;
int ret;
radio->buffer[0] = 0x00;
radio->buffer[1] = 0x50;
radio->buffer[2] = (freq_send >> 8) & 0xff;
radio->buffer[3] = freq_send & 0xff;
radio->buffer[4] = radio->pa;
/* If bit 4 is set, then tune to the frequency.
If bit 3 is set, then unmute; if bit 2 is set, then mute.
If bit 1 is set, then enter idle mode; if bit 0 is set,
then enter transmit mode.
*/
radio->buffer[5] = (radio->muted ? 4 : 8) | (play ? 1 : 2) |
(freq ? 0x10 : 0);
radio->buffer[6] = 0x00;
radio->buffer[7] = 0x00;
ret = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0),
9, 0x21, 0x200, 2, radio->buffer, BUFFER_LENGTH, USB_TIMEOUT);
if (ret < 0) {
dev_warn(&radio->vdev.dev, "%s failed (%d)\n", __func__, ret);
return ret;
}
if (freq)
radio->curfreq = freq;
return 0;
}
/* Set TX, stereo and preemphasis mode (50 us vs 75 us). */
static int keene_cmd_set(struct keene_device *radio)
{
int ret;
radio->buffer[0] = 0x00;
radio->buffer[1] = 0x51;
radio->buffer[2] = radio->tx;
/* If bit 0 is set, then transmit mono, otherwise stereo.
If bit 2 is set, then enable 75 us preemphasis, otherwise
it is 50 us. */
radio->buffer[3] = (radio->stereo ? 0 : 1) | (radio->preemph_75_us ? 4 : 0);
radio->buffer[4] = 0x00;
radio->buffer[5] = 0x00;
radio->buffer[6] = 0x00;
radio->buffer[7] = 0x00;
ret = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0),
9, 0x21, 0x200, 2, radio->buffer, BUFFER_LENGTH, USB_TIMEOUT);
if (ret < 0) {
dev_warn(&radio->vdev.dev, "%s failed (%d)\n", __func__, ret);
return ret;
}
return 0;
}
/* Handle unplugging the device.
* We call video_unregister_device in any case.
* The last function called in this procedure is
* usb_keene_device_release.
*/
static void usb_keene_disconnect(struct usb_interface *intf)
{
struct keene_device *radio = to_keene_dev(usb_get_intfdata(intf));
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/init.h`, `linux/slab.h`, `linux/input.h`, `linux/videodev2.h`, `media/v4l2-device.h`, `media/v4l2-ioctl.h`.
- Detected declarations: `struct keene_device`, `function keene_cmd_main`, `function keene_cmd_set`, `function usb_keene_disconnect`, `function usb_keene_suspend`, `function usb_keene_resume`, `function vidioc_querycap`, `function vidioc_g_modulator`, `function vidioc_s_modulator`, `function vidioc_s_frequency`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.