^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 radioSHARK2 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 radioSHARK2 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 shark2 was taken from the small userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * shark2.c program by Hisaaki Shibata, 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 "radio-tea5777.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_SHARK2_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) MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) MODULE_DESCRIPTION("Griffin radioSHARK2, USB radio receiver driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static int debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) module_param(debug, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) MODULE_PARM_DESC(debug, "Debug level (0-1)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define SHARK_IN_EP 0x83
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define SHARK_OUT_EP 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define TB_LEN 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define DRV_NAME "radioshark2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define v4l2_dev_to_shark(d) container_of(d, struct shark_device, v4l2_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) enum { BLUE_LED, RED_LED, NO_LEDS };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct shark_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct usb_device *usbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct v4l2_device v4l2_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct radio_tea5777 tea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #ifdef SHARK_USE_LEDS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct work_struct led_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct led_classdev leds[NO_LEDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) char led_names[NO_LEDS][32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) atomic_t brightness[NO_LEDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) unsigned long brightness_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) u8 *transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static atomic_t shark_instance = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct shark_device *shark = tea->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) int i, res, actual_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) memset(shark->transfer_buffer, 0, TB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) shark->transfer_buffer[0] = 0x81; /* Write register command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) for (i = 0; i < 6; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) shark->transfer_buffer[i + 1] = (reg >> (40 - i * 8)) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) v4l2_dbg(1, debug, tea->v4l2_dev, "shark2-write: %*ph\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 7, shark->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) res = usb_interrupt_msg(shark->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) usb_sndintpipe(shark->usbdev, SHARK_OUT_EP),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) shark->transfer_buffer, TB_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) &actual_len, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (res < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) v4l2_err(tea->v4l2_dev, "write error: %d\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int shark_read_reg(struct radio_tea5777 *tea, u32 *reg_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct shark_device *shark = tea->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int i, res, actual_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) u32 reg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) memset(shark->transfer_buffer, 0, TB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) shark->transfer_buffer[0] = 0x82;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) res = usb_interrupt_msg(shark->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) usb_sndintpipe(shark->usbdev, SHARK_OUT_EP),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) shark->transfer_buffer, TB_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) &actual_len, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (res < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) v4l2_err(tea->v4l2_dev, "request-read error: %d\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) res = usb_interrupt_msg(shark->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) usb_rcvintpipe(shark->usbdev, SHARK_IN_EP),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) shark->transfer_buffer, TB_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) &actual_len, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (res < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) v4l2_err(tea->v4l2_dev, "read error: %d\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) for (i = 0; i < 3; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) reg |= shark->transfer_buffer[i] << (16 - i * 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) v4l2_dbg(1, debug, tea->v4l2_dev, "shark2-read: %*ph\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 3, shark->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) *reg_ret = reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return 0;
^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) static const struct radio_tea5777_ops shark_tea_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .write_reg = shark_write_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .read_reg = shark_read_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #ifdef SHARK_USE_LEDS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static void shark_led_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct shark_device *shark =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) container_of(work, struct shark_device, led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int i, res, brightness, actual_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (!test_and_clear_bit(i, &shark->brightness_new))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) brightness = atomic_read(&shark->brightness[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) memset(shark->transfer_buffer, 0, TB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) shark->transfer_buffer[0] = 0x83 + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) shark->transfer_buffer[1] = brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) res = usb_interrupt_msg(shark->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) usb_sndintpipe(shark->usbdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) SHARK_OUT_EP),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) shark->transfer_buffer, TB_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) &actual_len, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) v4l2_err(&shark->v4l2_dev, "set LED %s error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) shark->led_names[i], res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static void shark_led_set_blue(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct shark_device *shark =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) container_of(led_cdev, struct shark_device, leds[BLUE_LED]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) atomic_set(&shark->brightness[BLUE_LED], value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) set_bit(BLUE_LED, &shark->brightness_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) schedule_work(&shark->led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static void shark_led_set_red(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct shark_device *shark =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) container_of(led_cdev, struct shark_device, leds[RED_LED]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) atomic_set(&shark->brightness[RED_LED], value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) set_bit(RED_LED, &shark->brightness_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) schedule_work(&shark->led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static const struct led_classdev shark_led_templates[NO_LEDS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) [BLUE_LED] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) .name = "%s:blue:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) .brightness = LED_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) .max_brightness = 127,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) .brightness_set = shark_led_set_blue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) [RED_LED] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) .name = "%s:red:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .brightness = LED_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) .max_brightness = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) .brightness_set = shark_led_set_red,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static int shark_register_leds(struct shark_device *shark, struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) int i, retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) atomic_set(&shark->brightness[BLUE_LED], 127);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) INIT_WORK(&shark->led_work, shark_led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) for (i = 0; i < NO_LEDS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) shark->leds[i] = shark_led_templates[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) snprintf(shark->led_names[i], sizeof(shark->led_names[0]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) shark->leds[i].name, shark->v4l2_dev.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) shark->leds[i].name = shark->led_names[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) retval = led_classdev_register(dev, &shark->leds[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) v4l2_err(&shark->v4l2_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) "couldn't register led: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) shark->led_names[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static void shark_unregister_leds(struct shark_device *shark)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) for (i = 0; i < NO_LEDS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) led_classdev_unregister(&shark->leds[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) cancel_work_sync(&shark->led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static inline void shark_resume_leds(struct shark_device *shark)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) for (i = 0; i < NO_LEDS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) set_bit(i, &shark->brightness_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) schedule_work(&shark->led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static int shark_register_leds(struct shark_device *shark, struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) v4l2_warn(&shark->v4l2_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) "CONFIG_LEDS_CLASS not enabled, LED support disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static inline void shark_unregister_leds(struct shark_device *shark) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static inline void shark_resume_leds(struct shark_device *shark) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static void usb_shark_disconnect(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct v4l2_device *v4l2_dev = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) struct shark_device *shark = v4l2_dev_to_shark(v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) mutex_lock(&shark->tea.mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) v4l2_device_disconnect(&shark->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) radio_tea5777_exit(&shark->tea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) mutex_unlock(&shark->tea.mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) shark_unregister_leds(shark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) v4l2_device_put(&shark->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static void usb_shark_release(struct v4l2_device *v4l2_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct shark_device *shark = v4l2_dev_to_shark(v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) v4l2_device_unregister(&shark->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) kfree(shark->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) kfree(shark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static int usb_shark_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) struct shark_device *shark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) int retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) shark = kzalloc(sizeof(struct shark_device), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (!shark)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) shark->transfer_buffer = kmalloc(TB_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (!shark->transfer_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) goto err_alloc_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) v4l2_device_set_name(&shark->v4l2_dev, DRV_NAME, &shark_instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) retval = shark_register_leds(shark, &intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) goto err_reg_leds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) shark->v4l2_dev.release = usb_shark_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) retval = v4l2_device_register(&intf->dev, &shark->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) v4l2_err(&shark->v4l2_dev, "couldn't register v4l2_device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) goto err_reg_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) shark->usbdev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) shark->tea.v4l2_dev = &shark->v4l2_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) shark->tea.private_data = shark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) shark->tea.ops = &shark_tea_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) shark->tea.has_am = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) shark->tea.write_before_read = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) strscpy(shark->tea.card, "Griffin radioSHARK2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) sizeof(shark->tea.card));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) usb_make_path(shark->usbdev, shark->tea.bus_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) sizeof(shark->tea.bus_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) retval = radio_tea5777_init(&shark->tea, THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) v4l2_err(&shark->v4l2_dev, "couldn't init tea5777\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) goto err_init_tea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) err_init_tea:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) v4l2_device_unregister(&shark->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) err_reg_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) shark_unregister_leds(shark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) err_reg_leds:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) kfree(shark->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) err_alloc_buffer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) kfree(shark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static int usb_shark_suspend(struct usb_interface *intf, pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static int usb_shark_resume(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct v4l2_device *v4l2_dev = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct shark_device *shark = v4l2_dev_to_shark(v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) mutex_lock(&shark->tea.mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) ret = radio_tea5777_set_freq(&shark->tea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) mutex_unlock(&shark->tea.mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) shark_resume_leds(shark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) /* Specify the bcdDevice value, as the radioSHARK and radioSHARK2 share ids */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static const struct usb_device_id usb_shark_device_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) { .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) USB_DEVICE_ID_MATCH_INT_CLASS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) .idVendor = 0x077d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) .idProduct = 0x627a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) .bcdDevice_lo = 0x0010,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) .bcdDevice_hi = 0x0010,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) .bInterfaceClass = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) MODULE_DEVICE_TABLE(usb, usb_shark_device_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static struct usb_driver usb_shark_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) .name = DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) .probe = usb_shark_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) .disconnect = usb_shark_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) .id_table = usb_shark_device_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) .suspend = usb_shark_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) .resume = usb_shark_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) .reset_resume = usb_shark_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) module_usb_driver(usb_shark_driver);