Skip to content

Commit

Permalink
[media] radio-shark: Add support for suspend & resume
Browse files Browse the repository at this point in the history
Signed-off-by: Hans de Goede <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
jwrdegoede authored and Mauro Carvalho Chehab committed Sep 13, 2012
1 parent d1f280d commit 559c200
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
43 changes: 42 additions & 1 deletion drivers/media/radio/radio-shark.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ MODULE_LICENSE("GPL");

#define v4l2_dev_to_shark(d) container_of(d, struct shark_device, v4l2_dev)

enum { BLUE_LED, BLUE_PULSE_LED, RED_LED, NO_LEDS };
/* Note BLUE_IS_PULSE comes after NO_LEDS as it is a status bit, not a LED */
enum { BLUE_LED, BLUE_PULSE_LED, RED_LED, NO_LEDS, BLUE_IS_PULSE };

struct shark_device {
struct usb_device *usbdev;
Expand Down Expand Up @@ -190,6 +191,7 @@ static void shark_led_set_blue(struct led_classdev *led_cdev,

atomic_set(&shark->brightness[BLUE_LED], value);
set_bit(BLUE_LED, &shark->brightness_new);
clear_bit(BLUE_IS_PULSE, &shark->brightness_new);
schedule_work(&shark->led_work);
}

Expand All @@ -201,6 +203,7 @@ static void shark_led_set_blue_pulse(struct led_classdev *led_cdev,

atomic_set(&shark->brightness[BLUE_PULSE_LED], 256 - value);
set_bit(BLUE_PULSE_LED, &shark->brightness_new);
set_bit(BLUE_IS_PULSE, &shark->brightness_new);
schedule_work(&shark->led_work);
}

Expand Down Expand Up @@ -240,6 +243,7 @@ static int shark_register_leds(struct shark_device *shark, struct device *dev)
{
int i, retval;

atomic_set(&shark->brightness[BLUE_LED], 127);
INIT_WORK(&shark->led_work, shark_led_work);
for (i = 0; i < NO_LEDS; i++) {
shark->leds[i] = shark_led_templates[i];
Expand All @@ -266,6 +270,16 @@ static void shark_unregister_leds(struct shark_device *shark)

cancel_work_sync(&shark->led_work);
}

static void shark_resume_leds(struct shark_device *shark)
{
if (test_bit(BLUE_IS_PULSE, &shark->brightness_new))
set_bit(BLUE_PULSE_LED, &shark->brightness_new);
else
set_bit(BLUE_LED, &shark->brightness_new);
set_bit(RED_LED, &shark->brightness_new);
schedule_work(&shark->led_work);
}
#else
static int shark_register_leds(struct shark_device *shark, struct device *dev)
{
Expand All @@ -274,6 +288,7 @@ static int shark_register_leds(struct shark_device *shark, struct device *dev)
return 0;
}
static inline void shark_unregister_leds(struct shark_device *shark) { }
static inline void shark_resume_leds(struct shark_device *shark) { }
#endif

static void usb_shark_disconnect(struct usb_interface *intf)
Expand Down Expand Up @@ -359,6 +374,27 @@ static int usb_shark_probe(struct usb_interface *intf,
return retval;
}

#ifdef CONFIG_PM
int usb_shark_suspend(struct usb_interface *intf, pm_message_t message)
{
return 0;
}

int usb_shark_resume(struct usb_interface *intf)
{
struct v4l2_device *v4l2_dev = usb_get_intfdata(intf);
struct shark_device *shark = v4l2_dev_to_shark(v4l2_dev);

mutex_lock(&shark->tea.mutex);
snd_tea575x_set_freq(&shark->tea);
mutex_unlock(&shark->tea.mutex);

shark_resume_leds(shark);

return 0;
}
#endif

/* Specify the bcdDevice value, as the radioSHARK and radioSHARK2 share ids */
static struct usb_device_id usb_shark_device_table[] = {
{ .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
Expand All @@ -378,5 +414,10 @@ static struct usb_driver usb_shark_driver = {
.probe = usb_shark_probe,
.disconnect = usb_shark_disconnect,
.id_table = usb_shark_device_table,
#ifdef CONFIG_PM
.suspend = usb_shark_suspend,
.resume = usb_shark_resume,
.reset_resume = usb_shark_resume,
#endif
};
module_usb_driver(usb_shark_driver);
1 change: 1 addition & 0 deletions include/sound/tea575x-tuner.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ struct snd_tea575x {

int snd_tea575x_init(struct snd_tea575x *tea, struct module *owner);
void snd_tea575x_exit(struct snd_tea575x *tea);
void snd_tea575x_set_freq(struct snd_tea575x *tea);

#endif /* __SOUND_TEA575X_TUNER_H */
3 changes: 2 additions & 1 deletion sound/i2c/other/tea575x-tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static u32 snd_tea575x_get_freq(struct snd_tea575x *tea)
return snd_tea575x_val_to_freq(tea, snd_tea575x_read(tea));
}

static void snd_tea575x_set_freq(struct snd_tea575x *tea)
void snd_tea575x_set_freq(struct snd_tea575x *tea)
{
u32 freq = tea->freq / 16; /* to kHz */
u32 band = 0;
Expand Down Expand Up @@ -571,3 +571,4 @@ module_exit(alsa_tea575x_module_exit)

EXPORT_SYMBOL(snd_tea575x_init);
EXPORT_SYMBOL(snd_tea575x_exit);
EXPORT_SYMBOL(snd_tea575x_set_freq);

0 comments on commit 559c200

Please sign in to comment.