b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -2428,6 +2428,51 @@ static struct em28xx_hash_table em28xx_i2c_hash[] = {
};
/* NOTE: introduce a separate hash table for devices with 16 bit
eeproms */
+/* interfaces to create and destroy token resources */
+static int em28xx_create_token_resources(struct em28xx *dev)
+{
+ int rc = 0;
+
+ /* create token devres for tuner */
+ snprintf(dev->tuner_tkn_id, sizeof(dev->tuner_tkn_id),
+ "tuner:%s-%s-%d",
+ dev_name(&dev->udev->dev),
+ dev->udev->bus->bus_name,
+ dev->tuner_addr);
+
+ rc = devm_token_create(&dev->udev->dev, dev->tuner_tkn_id);
+ em28xx_info("devm_token_create() returned %d\n", rc);
+
+ if (dev->has_video || dev->board.has_dvb) {
+ snprintf(dev->video_tkn_id, sizeof(dev->video_tkn_id),
+ "video:%s-%s",
+ dev_name(&dev->udev->dev),
+ dev->udev->bus->bus_name);
+ rc = devm_token_create(&dev->udev->dev, dev->video_tkn_id);
+ }
+ if (dev->audio_mode.has_audio) {
+ snprintf(dev->audio_tkn_id, sizeof(dev->audio_tkn_id),
+ "audio:%s-%s",
+ dev_name(&dev->udev->dev),
+ dev->udev->bus->bus_name);
+ rc = devm_token_create(&dev->udev->dev, dev->audio_tkn_id);
+ }
+ return rc;
+}
+
+static int em28xx_destroy_token_resources(struct em28xx *dev)
+{
+ int rc = 0;
+
+ devm_token_destroy(&dev->udev->dev, dev->tuner_tkn_id);
+ if (dev->has_video || dev->board.has_dvb)
+ rc = devm_token_destroy(&dev->udev->dev, dev->video_tkn_id);
+ if (dev->audio_mode.has_audio)
+ rc = devm_token_destroy(&dev->udev->dev, dev->audio_tkn_id);
+
+ return rc;
+}
int em28xx_tuner_callback(void *ptr, int component, int command, int arg)
{
struct em28xx_i2c_bus *i2c_bus = ptr;
@@ -2949,6 +2994,10 @@ static void em28xx_release_resources(struct
em28xx *dev)
em28xx_i2c_unregister(dev, 1);
em28xx_i2c_unregister(dev, 0);
+ /* destroy token resources */
+ if (em28xx_destroy_token_resources(dev))
+ em28xx_info("Error destroying token resources\n");
+
usb_put_dev(dev->udev);
/* Mark device as unused */
@@ -3431,6 +3480,10 @@ static int em28xx_usb_probe(struct usb_interface
*interface,
kref_init(&dev->ref);
+ /* create token resources before requesting for modules */
+ if (em28xx_create_token_resources(dev))
+ em28xx_info("Error creating token resources\n");
+
request_modules(dev);
/* Should be the last thing to do, to avoid newer udev's to
b/drivers/media/usb/em28xx/em28xx-core.c
@@ -824,6 +824,9 @@ void em28xx_uninit_usb_xfer(struct em28xx *dev, enum
em28xx_mode mode)
usb_bufs->num_bufs = 0;
em28xx_capture_start(dev, 0);
+
+ /* unlock token */
+ devm_token_unlock(&dev->udev->dev, dev->video_tkn_id);
}
EXPORT_SYMBOL_GPL(em28xx_uninit_usb_xfer);
@@ -993,6 +996,11 @@ int em28xx_init_usb_xfer(struct em28xx *dev, enum
em28xx_mode mode,
em28xx_isocdbg("em28xx: called em28xx_init_usb_xfer in mode %d\n",
mode);
+ /* lock token */
+ rc = devm_token_lock(&dev->udev->dev, dev->video_tkn_id);
+ if (rc)
+ return rc;
+
dev->usb_ctl.urb_data_copy = urb_data_copy;
if (mode == EM28XX_DIGITAL_MODE) {
b/drivers/media/usb/em28xx/em28xx.h
@@ -34,6 +34,7 @@
#include <linux/mutex.h>
#include <linux/kref.h>
#include <linux/videodev2.h>
+#include <linux/token_devres.h>
#include <media/videobuf2-vmalloc.h>
#include <media/v4l2-device.h>
@@ -547,6 +548,11 @@ struct em28xx {
int devno; /* marks the number of this device */
enum em28xx_chip_id chip_id;
+ /* token resources */
+ char tuner_tkn_id[64]; /* tuner token id */
+ char video_tkn_id[64]; /* video dma engine token */
+ char audio_tkn_id[64]; /* audio dma engine token id */
+
unsigned int is_em25xx:1; /* em25xx/em276x/7x/8x family
bridge */
unsigned char disconnected:1; /* device has been diconnected */