linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <johan@kernel.org>, <andy.shevchenko@gmail.com>,
	Alexandru Ardelean <alexandru.ardelean@analog.com>
Subject: [PATCH v2 2/6] iio: core: add iio_device_set_parent() helper
Date: Wed, 3 Jun 2020 14:40:19 +0300	[thread overview]
Message-ID: <20200603114023.175102-3-alexandru.ardelean@analog.com> (raw)
In-Reply-To: <20200603114023.175102-1-alexandru.ardelean@analog.com>

By default, the device allocation will also assign a parent device to the
IIO device object. In cases where devm_iio_device_alloc() is used,
sometimes the parent device must be different than the device used to
manage the allocation.

In that case, this helper should be used to change the parent, hence the
requirement to call this between allocation & registration.

This pattern/requirement is not very common in the IIO space, and it may be
cleaned up later.
But until then, assigning the parent manually between allocation &
registration is slightly easier.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 include/linux/iio/iio.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 91a69f4751aa..5784f8c9508f 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -649,6 +649,26 @@ static inline struct iio_dev *iio_device_get(struct iio_dev *indio_dev)
 	return indio_dev ? dev_to_iio_dev(get_device(&indio_dev->dev)) : NULL;
 }
 
+/**
+ * iio_device_set_parent() - assign parent device to the IIO device object
+ * @indio_dev: 		IIO device structure
+ * @parent:		reference to parent device object
+ *
+ * This utility must be called between IIO device allocation
+ * (via devm_iio_device_alloc()) & IIO device registration
+ * (via {devm_}iio_device_register()).
+ * By default, the device allocation will also assign a parent device to
+ * the IIO device object. In cases where devm_iio_device_alloc() is used,
+ * sometimes the parent device must be different than the device used to
+ * manage the allocation.
+ * In that case, this helper should be used to change the parent, hence the
+ * requirement to call this between allocation & registration.
+ **/
+static inline void iio_device_set_parent(struct iio_dev *indio_dev,
+					 struct device *parent)
+{
+	indio_dev->dev.parent = parent;
+}
 
 /**
  * iio_device_set_drvdata() - Set device driver data
-- 
2.25.1


  parent reply	other threads:[~2020-06-03 11:40 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03 11:40 [PATCH v2 0/6] iio: core: pass parent device as parameter during allocation Alexandru Ardelean
2020-06-03 11:40 ` [PATCH v2 1/6] " Alexandru Ardelean
2020-06-06 15:24   ` Jonathan Cameron
2020-06-03 11:40 ` Alexandru Ardelean [this message]
2020-06-06 15:25   ` [PATCH v2 2/6] iio: core: add iio_device_set_parent() helper Jonathan Cameron
2020-06-03 11:40 ` [PATCH v2 3/6] iio: remove explicit IIO device parent assignment Alexandru Ardelean
2020-06-03 11:40 ` [PATCH v2 4/6] iio: remove left-over comments about " Alexandru Ardelean
2020-06-06 15:46   ` Jonathan Cameron
2020-06-03 11:40 ` [PATCH v2 5/6] iio: light: lm3533-als: use iio_device_set_parent() to assign parent Alexandru Ardelean
2020-06-06 15:46   ` Jonathan Cameron
2020-06-03 11:40 ` [PATCH v2 6/6] iio: remove left-over parent assignments Alexandru Ardelean
2020-06-06 16:05   ` Jonathan Cameron
2020-06-11  6:52     ` Ardelean, Alexandru
2020-06-14 12:14       ` Jonathan Cameron
2020-06-03 11:41 ` [PATCH v2 0/6] iio: core: pass parent device as parameter during allocation Ardelean, Alexandru
2020-06-04 17:34   ` Jonathan Cameron
2020-06-06 16:02     ` Jonathan Cameron
2020-06-08  6:37       ` Alexandru Ardelean
2020-06-08 11:10         ` Jonathan Cameron

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=20200603114023.175102-3-alexandru.ardelean@analog.com \
    --to=alexandru.ardelean@analog.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=johan@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).