All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vaishnav M A <vaishnav@beagleboard.org>
To: johan@kernel.org
Cc: ribalda@kernel.org, robh@kernel.org, gregkh@linuxfoundation.org,
	jirislaby@kernel.org, masahiroy@kernel.org,
	andriy.shevchenko@linux.intel.com, linux-kernel@vger.kernel.org,
	linux-serial@vger.kernel.org, linux-kbuild@vger.kernel.org,
	jkridner@beagleboard.org, drew@beagleboard.org,
	robertcnelson@beagleboard.org, vaishnav@beagleboard.org
Subject: [RFC PATCH 3/5] serdev: add of_ helper to get serdev controller
Date: Mon, 26 Oct 2020 23:27:16 +0530	[thread overview]
Message-ID: <20201026175718.965773-4-vaishnav@beagleboard.org> (raw)
In-Reply-To: <20201026175718.965773-1-vaishnav@beagleboard.org>

add of_find_serdev_controller_by_node() to obtain a
serdev_controller from the device_node, which can 
help if the serdev_device is not described over 
device tree and instantiation of the device happens later
from a different driver, for the same purpose an option
to not delete an empty serdev controller is added.

Signed-off-by: Vaishnav M A <vaishnav@beagleboard.org>
---
 drivers/tty/serdev/core.c | 17 +++++++++++++++++
 include/linux/serdev.h    |  2 ++
 2 files changed, 19 insertions(+)

diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
index 01b248fdc264..85977b36ed7f 100644
--- a/drivers/tty/serdev/core.c
+++ b/drivers/tty/serdev/core.c
@@ -582,6 +582,17 @@ static int of_serdev_register_devices(struct serdev_controller *ctrl)
 	return 0;
 }
 
+struct serdev_controller *of_find_serdev_controller_by_node(struct device_node *node)
+{
+	struct device *dev = bus_find_device_by_of_node(&serdev_bus_type, node);
+
+	if (!dev)
+		return NULL;
+
+	return (dev->type == &serdev_ctrl_type) ? to_serdev_controller(dev) : NULL;
+}
+EXPORT_SYMBOL_GPL(of_find_serdev_controller_by_node);
+
 #ifdef CONFIG_ACPI
 
 #define SERDEV_ACPI_MAX_SCAN_DEPTH 32
@@ -779,6 +790,12 @@ int serdev_controller_add(struct serdev_controller *ctrl)
 
 	pm_runtime_enable(&ctrl->dev);
 
+	/* provide option to not delete a serdev controller without devices
+	 * if property is present
+	 */
+	if (device_property_present(&ctrl->dev, "force-empty-serdev-controller"))
+		return 0;
+
 	ret_of = of_serdev_register_devices(ctrl);
 	ret_acpi = acpi_serdev_register_devices(ctrl);
 	if (ret_of && ret_acpi) {
diff --git a/include/linux/serdev.h b/include/linux/serdev.h
index 0d9c90a250b0..2e1eb4d17e1b 100644
--- a/include/linux/serdev.h
+++ b/include/linux/serdev.h
@@ -115,6 +115,8 @@ static inline struct serdev_controller *to_serdev_controller(struct device *d)
 	return container_of(d, struct serdev_controller, dev);
 }
 
+struct serdev_controller *of_find_serdev_controller_by_node(struct device_node *node);
+
 static inline void *serdev_device_get_drvdata(const struct serdev_device *serdev)
 {
 	return dev_get_drvdata(&serdev->dev);
-- 
2.25.1


  parent reply	other threads:[~2020-10-26 17:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 17:57 [RFC PATCH 0/5] Add serdev_device_id for platform instantiation Vaishnav M A
2020-10-26 17:57 ` [RFC PATCH 1/5] serdev: Add serdev_device_id Vaishnav M A
2020-10-26 17:57 ` [RFC PATCH 2/5] file2alias: Support for serdev devices Vaishnav M A
2020-10-26 17:57 ` Vaishnav M A [this message]
2020-10-26 17:57 ` [RFC PATCH 4/5] gnss: ubx add MODULE_DEVICE_TABLE(serdev) Vaishnav M A
2020-10-26 17:57 ` [RFC PATCH 5/5] gnss: change of_property_read to device_property_read Vaishnav M A

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=20201026175718.965773-4-vaishnav@beagleboard.org \
    --to=vaishnav@beagleboard.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=drew@beagleboard.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=jkridner@beagleboard.org \
    --cc=johan@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=ribalda@kernel.org \
    --cc=robertcnelson@beagleboard.org \
    --cc=robh@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 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.