Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Linux V4L2 radio driver for the Griffin radioSHARK USB radio receiver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Note the radioSHARK offers the audio through a regular USB audio device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * this driver only handles the tuning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * The info necessary to drive the shark was taken from the small userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * shark.c program by Michael Rolig, which he kindly placed in the Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Domain.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Copyright (c) 2012 Hans de Goede <hdegoede@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * the Free Software Foundation; either version 2 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <media/v4l2-device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <media/drv-intf/tea575x.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #if defined(CONFIG_LEDS_CLASS) || \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)     (defined(CONFIG_LEDS_CLASS_MODULE) && defined(CONFIG_RADIO_SHARK_MODULE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define SHARK_USE_LEDS 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * Version Information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) MODULE_DESCRIPTION("Griffin radioSHARK, USB radio receiver driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define SHARK_IN_EP		0x83
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define SHARK_OUT_EP		0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define TEA575X_BIT_MONO	(1<<22)		/* 0 = stereo, 1 = mono */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define TEA575X_BIT_BAND_MASK	(3<<20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define TEA575X_BIT_BAND_FM	(0<<20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define TB_LEN 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define DRV_NAME "radioshark"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define v4l2_dev_to_shark(d) container_of(d, struct shark_device, v4l2_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) /* Note BLUE_IS_PULSE comes after NO_LEDS as it is a status bit, not a LED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) enum { BLUE_LED, BLUE_PULSE_LED, RED_LED, NO_LEDS, BLUE_IS_PULSE };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) struct shark_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct usb_device *usbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct v4l2_device v4l2_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct snd_tea575x tea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #ifdef SHARK_USE_LEDS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct work_struct led_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct led_classdev leds[NO_LEDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	char led_names[NO_LEDS][32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	atomic_t brightness[NO_LEDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	unsigned long brightness_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	u8 *transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	u32 last_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static atomic_t shark_instance = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static void shark_write_val(struct snd_tea575x *tea, u32 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct shark_device *shark = tea->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	int i, res, actual_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	/* Avoid unnecessary (slow) USB transfers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (shark->last_val == val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	memset(shark->transfer_buffer, 0, TB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	shark->transfer_buffer[0] = 0xc0; /* Write shift register command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	for (i = 0; i < 4; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		shark->transfer_buffer[i] |= (val >> (24 - i * 8)) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	res = usb_interrupt_msg(shark->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 				usb_sndintpipe(shark->usbdev, SHARK_OUT_EP),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 				shark->transfer_buffer, TB_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 				&actual_len, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (res >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		shark->last_val = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		v4l2_err(&shark->v4l2_dev, "set-freq error: %d\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static u32 shark_read_val(struct snd_tea575x *tea)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct shark_device *shark = tea->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	int i, res, actual_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	u32 val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	memset(shark->transfer_buffer, 0, TB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	shark->transfer_buffer[0] = 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	res = usb_interrupt_msg(shark->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 				usb_sndintpipe(shark->usbdev, SHARK_OUT_EP),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 				shark->transfer_buffer, TB_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 				&actual_len, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (res < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		v4l2_err(&shark->v4l2_dev, "request-status error: %d\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		return shark->last_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	res = usb_interrupt_msg(shark->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				usb_rcvintpipe(shark->usbdev, SHARK_IN_EP),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 				shark->transfer_buffer, TB_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 				&actual_len, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (res < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		v4l2_err(&shark->v4l2_dev, "get-status error: %d\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		return shark->last_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	for (i = 0; i < 4; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		val |= shark->transfer_buffer[i] << (24 - i * 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	shark->last_val = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	 * The shark does not allow actually reading the stereo / mono pin :(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 * So assume that when we're tuned to an FM station and mono has not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	 * been requested, that we're receiving stereo.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (((val & TEA575X_BIT_BAND_MASK) == TEA575X_BIT_BAND_FM) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	    !(val & TEA575X_BIT_MONO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		shark->tea.stereo = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		shark->tea.stereo = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static const struct snd_tea575x_ops shark_tea_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	.write_val = shark_write_val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	.read_val  = shark_read_val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #ifdef SHARK_USE_LEDS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static void shark_led_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	struct shark_device *shark =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		container_of(work, struct shark_device, led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	int i, res, brightness, actual_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	for (i = 0; i < 3; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		if (!test_and_clear_bit(i, &shark->brightness_new))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		brightness = atomic_read(&shark->brightness[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		memset(shark->transfer_buffer, 0, TB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		if (i != RED_LED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			shark->transfer_buffer[0] = 0xA0 + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			shark->transfer_buffer[1] = brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			shark->transfer_buffer[0] = brightness ? 0xA9 : 0xA8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		res = usb_interrupt_msg(shark->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 					usb_sndintpipe(shark->usbdev, 0x05),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 					shark->transfer_buffer, TB_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 					&actual_len, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			v4l2_err(&shark->v4l2_dev, "set LED %s error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 				 shark->led_names[i], res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static void shark_led_set_blue(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			       enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct shark_device *shark =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		container_of(led_cdev, struct shark_device, leds[BLUE_LED]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	atomic_set(&shark->brightness[BLUE_LED], value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	set_bit(BLUE_LED, &shark->brightness_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	clear_bit(BLUE_IS_PULSE, &shark->brightness_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	schedule_work(&shark->led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static void shark_led_set_blue_pulse(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 				     enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	struct shark_device *shark = container_of(led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 				struct shark_device, leds[BLUE_PULSE_LED]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	atomic_set(&shark->brightness[BLUE_PULSE_LED], 256 - value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	set_bit(BLUE_PULSE_LED, &shark->brightness_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	set_bit(BLUE_IS_PULSE, &shark->brightness_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	schedule_work(&shark->led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static void shark_led_set_red(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			      enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct shark_device *shark =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		container_of(led_cdev, struct shark_device, leds[RED_LED]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	atomic_set(&shark->brightness[RED_LED], value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	set_bit(RED_LED, &shark->brightness_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	schedule_work(&shark->led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static const struct led_classdev shark_led_templates[NO_LEDS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	[BLUE_LED] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		.name		= "%s:blue:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		.brightness	= LED_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		.max_brightness = 127,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		.brightness_set = shark_led_set_blue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	[BLUE_PULSE_LED] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		.name		= "%s:blue-pulse:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		.brightness	= LED_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		.max_brightness = 255,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		.brightness_set = shark_led_set_blue_pulse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	[RED_LED] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		.name		= "%s:red:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		.brightness	= LED_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		.max_brightness = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		.brightness_set = shark_led_set_red,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static int shark_register_leds(struct shark_device *shark, struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	int i, retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	atomic_set(&shark->brightness[BLUE_LED], 127);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	INIT_WORK(&shark->led_work, shark_led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	for (i = 0; i < NO_LEDS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		shark->leds[i] = shark_led_templates[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		snprintf(shark->led_names[i], sizeof(shark->led_names[0]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			 shark->leds[i].name, shark->v4l2_dev.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		shark->leds[i].name = shark->led_names[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		retval = led_classdev_register(dev, &shark->leds[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			v4l2_err(&shark->v4l2_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				 "couldn't register led: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 				 shark->led_names[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static void shark_unregister_leds(struct shark_device *shark)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	for (i = 0; i < NO_LEDS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		led_classdev_unregister(&shark->leds[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	cancel_work_sync(&shark->led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static inline void shark_resume_leds(struct shark_device *shark)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (test_bit(BLUE_IS_PULSE, &shark->brightness_new))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		set_bit(BLUE_PULSE_LED, &shark->brightness_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		set_bit(BLUE_LED, &shark->brightness_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	set_bit(RED_LED, &shark->brightness_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	schedule_work(&shark->led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static int shark_register_leds(struct shark_device *shark, struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	v4l2_warn(&shark->v4l2_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		  "CONFIG_LEDS_CLASS not enabled, LED support disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static inline void shark_unregister_leds(struct shark_device *shark) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static inline void shark_resume_leds(struct shark_device *shark) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static void usb_shark_disconnect(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	struct v4l2_device *v4l2_dev = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	struct shark_device *shark = v4l2_dev_to_shark(v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	mutex_lock(&shark->tea.mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	v4l2_device_disconnect(&shark->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	snd_tea575x_exit(&shark->tea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	mutex_unlock(&shark->tea.mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	shark_unregister_leds(shark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	v4l2_device_put(&shark->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static void usb_shark_release(struct v4l2_device *v4l2_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	struct shark_device *shark = v4l2_dev_to_shark(v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	v4l2_device_unregister(&shark->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	kfree(shark->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	kfree(shark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static int usb_shark_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			   const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	struct shark_device *shark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	int retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	shark = kzalloc(sizeof(struct shark_device), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (!shark)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	shark->transfer_buffer = kmalloc(TB_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	if (!shark->transfer_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		goto err_alloc_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	v4l2_device_set_name(&shark->v4l2_dev, DRV_NAME, &shark_instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	retval = shark_register_leds(shark, &intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		goto err_reg_leds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	shark->v4l2_dev.release = usb_shark_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	retval = v4l2_device_register(&intf->dev, &shark->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		v4l2_err(&shark->v4l2_dev, "couldn't register v4l2_device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		goto err_reg_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	shark->usbdev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	shark->tea.v4l2_dev = &shark->v4l2_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	shark->tea.private_data = shark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	shark->tea.radio_nr = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	shark->tea.ops = &shark_tea_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	shark->tea.cannot_mute = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	shark->tea.has_am = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	strscpy(shark->tea.card, "Griffin radioSHARK",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		sizeof(shark->tea.card));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	usb_make_path(shark->usbdev, shark->tea.bus_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		sizeof(shark->tea.bus_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	retval = snd_tea575x_init(&shark->tea, THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		v4l2_err(&shark->v4l2_dev, "couldn't init tea5757\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		goto err_init_tea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) err_init_tea:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	v4l2_device_unregister(&shark->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) err_reg_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	shark_unregister_leds(shark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) err_reg_leds:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	kfree(shark->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) err_alloc_buffer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	kfree(shark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static int usb_shark_suspend(struct usb_interface *intf, pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static int usb_shark_resume(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	struct v4l2_device *v4l2_dev = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	struct shark_device *shark = v4l2_dev_to_shark(v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	mutex_lock(&shark->tea.mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	snd_tea575x_set_freq(&shark->tea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	mutex_unlock(&shark->tea.mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	shark_resume_leds(shark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /* Specify the bcdDevice value, as the radioSHARK and radioSHARK2 share ids */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) static const struct usb_device_id usb_shark_device_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	{ .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 			 USB_DEVICE_ID_MATCH_INT_CLASS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	  .idVendor     = 0x077d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	  .idProduct    = 0x627a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	  .bcdDevice_lo = 0x0001,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	  .bcdDevice_hi = 0x0001,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	  .bInterfaceClass = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) MODULE_DEVICE_TABLE(usb, usb_shark_device_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static struct usb_driver usb_shark_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	.name			= DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	.probe			= usb_shark_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	.disconnect		= usb_shark_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	.id_table		= usb_shark_device_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	.suspend		= usb_shark_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	.resume			= usb_shark_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	.reset_resume		= usb_shark_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) module_usb_driver(usb_shark_driver);