drivers/media/radio/radio-shark.c

Source file repositories/reference/linux-study-clean/drivers/media/radio/radio-shark.c

File Facts

System
Linux kernel
Corpus path
drivers/media/radio/radio-shark.c
Extension
.c
Size
11762 bytes
Lines
430
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct shark_device {
	struct usb_device *usbdev;
	struct v4l2_device v4l2_dev;
	struct snd_tea575x tea;

#ifdef SHARK_USE_LEDS
	struct work_struct led_work;
	struct led_classdev leds[NO_LEDS];
	char led_names[NO_LEDS][32];
	atomic_t brightness[NO_LEDS];
	unsigned long brightness_new;
#endif

	u8 *transfer_buffer;
	u32 last_val;
};

static atomic_t shark_instance = ATOMIC_INIT(0);

static void shark_write_val(struct snd_tea575x *tea, u32 val)
{
	struct shark_device *shark = tea->private_data;
	int i, res, actual_len;

	/* Avoid unnecessary (slow) USB transfers */
	if (shark->last_val == val)
		return;

	memset(shark->transfer_buffer, 0, TB_LEN);
	shark->transfer_buffer[0] = 0xc0; /* Write shift register command */
	for (i = 0; i < 4; i++)
		shark->transfer_buffer[i] |= (val >> (24 - i * 8)) & 0xff;

	res = usb_interrupt_msg(shark->usbdev,
				usb_sndintpipe(shark->usbdev, SHARK_OUT_EP),
				shark->transfer_buffer, TB_LEN,
				&actual_len, 1000);
	if (res >= 0)
		shark->last_val = val;
	else
		v4l2_err(&shark->v4l2_dev, "set-freq error: %d\n", res);
}

static u32 shark_read_val(struct snd_tea575x *tea)
{
	struct shark_device *shark = tea->private_data;
	int i, res, actual_len;
	u32 val = 0;

	memset(shark->transfer_buffer, 0, TB_LEN);
	shark->transfer_buffer[0] = 0x80;
	res = usb_interrupt_msg(shark->usbdev,
				usb_sndintpipe(shark->usbdev, SHARK_OUT_EP),
				shark->transfer_buffer, TB_LEN,
				&actual_len, 1000);
	if (res < 0) {
		v4l2_err(&shark->v4l2_dev, "request-status error: %d\n", res);
		return shark->last_val;
	}

	res = usb_interrupt_msg(shark->usbdev,
				usb_rcvintpipe(shark->usbdev, SHARK_IN_EP),
				shark->transfer_buffer, TB_LEN,
				&actual_len, 1000);
	if (res < 0) {
		v4l2_err(&shark->v4l2_dev, "get-status error: %d\n", res);
		return shark->last_val;
	}

	for (i = 0; i < 4; i++)
		val |= shark->transfer_buffer[i] << (24 - i * 8);

	shark->last_val = val;

	/*
	 * The shark does not allow actually reading the stereo / mono pin :(
	 * So assume that when we're tuned to an FM station and mono has not
	 * been requested, that we're receiving stereo.
	 */
	if (((val & TEA575X_BIT_BAND_MASK) == TEA575X_BIT_BAND_FM) &&
	    !(val & TEA575X_BIT_MONO))
		shark->tea.stereo = true;
	else
		shark->tea.stereo = false;

	return val;
}

static const struct snd_tea575x_ops shark_tea_ops = {
	.write_val = shark_write_val,

Annotation

Implementation Notes