All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shuah Khan <shuah.kh@samsung.com>
To: Mauro Carvalho Chehab <m.chehab@samsung.com>,
	One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>,
	Greg KH <gregkh@linuxfoundation.org>
Cc: tj@kernel.org, rafael.j.wysocki@intel.com, linux@roeck-us.net,
	toshi.kani@hp.com, linux-kernel@vger.kernel.org,
	linux-media@vger.kernel.org, shuahkhan@gmail.com,
	Shuah Khan <shuah.kh@samsung.com>
Subject: Re: [RFC PATCH 0/2] managed token devres interfaces
Date: Fri, 11 Apr 2014 14:28:28 -0600	[thread overview]
Message-ID: <5348506C.6000604@samsung.com> (raw)
In-Reply-To: <20140410113949.7de1312b@samsung.com>

Here is an example driver use-case for this token resource: This is not 
polished, but should give an idea on this new token resource is intended 
to be used:

- create token resources in em28xx_usb_probe() right before the required 
modules are loaded. It creates tuner, video and audio tokens to use as a 
large grain lock on tuner, video DMA engine, and audio DMA engine 
respectively.

- lock video token in em28xx_init_usb_xfer()
- unlock in em28xx_uninit_usb_xfer()

- destroy token in em28xx_release_resources()


I did some hotplug testing with this:

dmesg | grep token
[  771.613332] usb 8-1: devm_token_create(): created token: 
tuner:8-1-0000:00:10.1-0
[  771.613335] em2874 #0: devm_token_create() returned 0
[  771.613340] usb 8-1: devm_token_create(): created token: 
video:8-1-0000:00:10.1
[  851.202931] usb 8-1: devm_token_release(): release token
[  851.202936] usb 8-1: devm_token_release(): release token
[ 1775.052273] usb 8-2: devm_token_create(): created token: 
tuner:8-2-0000:00:10.1-0
[ 1775.052276] em2874 #0: devm_token_create() returned 0
[ 1775.052285] usb 8-2: devm_token_create(): created token: 
video:8-2-0000:00:10.1
shuah@anduin:~$ dmesg | grep token
[  771.613332] usb 8-1: devm_token_create(): created token: 
tuner:8-1-0000:00:10.1-0
[  771.613335] em2874 #0: devm_token_create() returned 0
[  771.613340] usb 8-1: devm_token_create(): created token: 
video:8-1-0000:00:10.1
[  851.202931] usb 8-1: devm_token_release(): release token
[  851.202936] usb 8-1: devm_token_release(): release token
[ 1775.052273] usb 8-2: devm_token_create(): created token: 
tuner:8-2-0000:00:10.1-0
[ 1775.052276] em2874 #0: devm_token_create() returned 0
[ 1775.052285] usb 8-2: devm_token_create(): created token: 
video:8-2-0000:00:10.1
[ 1799.610007] usb 8-2: devm_token_release(): release token
[ 1799.610013] usb 8-2: devm_token_release(): release token


diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
b/drivers/media/usb/em28xx/em28xx-cards.c
index 50aa5a5..3305250 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ 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
diff --git a/drivers/media/usb/em28xx/em28xx-core.c 
b/drivers/media/usb/em28xx/em28xx-core.c
index 523d7e9..8129a9c 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ 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) {
diff --git a/drivers/media/usb/em28xx/em28xx.h 
b/drivers/media/usb/em28xx/em28xx.h
index 2051fc9..b13ec6e 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ 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 */
         unsigned int has_video:1;

thanks
-- Shuah

-- 
Shuah Khan
Senior Linux Kernel Developer - Open Source Group
Samsung Research America(Silicon Valley)
shuah.kh@samsung.com | (970) 672-0658

  reply	other threads:[~2014-04-11 20:28 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-09 15:21 [RFC PATCH 0/2] managed token devres interfaces Shuah Khan
2014-04-09 15:21 ` [RFC PATCH 1/2] drivers/base: add new devres_update() interface to devres_* Shuah Khan
2014-04-09 15:21 ` [RFC PATCH 2/2] drivers/base: add managed token devres interfaces Shuah Khan
2014-04-16 21:58   ` Tejun Heo
2014-04-17 20:01     ` Shuah Khan
2014-04-17 20:10       ` Tejun Heo
2014-04-17 20:22         ` Tejun Heo
2014-04-17 23:27           ` Shuah Khan
2014-04-17 20:50         ` Shuah Khan
2014-04-09 19:17 ` [RFC PATCH 0/2] " Greg KH
2014-04-09 22:44   ` Shuah Khan
2014-04-10 11:04     ` One Thousand Gnomes
2014-04-10 11:38       ` Mauro Carvalho Chehab
2014-04-10 11:46         ` One Thousand Gnomes
2014-04-10 14:39           ` Mauro Carvalho Chehab
2014-04-11 20:28             ` Shuah Khan [this message]
2014-04-14 22:48             ` Shuah Khan
2014-04-10 14:32         ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5348506C.6000604@samsung.com \
    --to=shuah.kh@samsung.com \
    --cc=gnomes@lxorguk.ukuu.org.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=m.chehab@samsung.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=shuahkhan@gmail.com \
    --cc=tj@kernel.org \
    --cc=toshi.kani@hp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.