All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Russell King <linux@armlinux.org.uk>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org, kernel@pengutronix.de,
	Arnd Bergmann <arnd@arndb.de>,
	linux-arm-kernel@lists.infradead.org,
	Ulf Hansson <ulf.hansson@linaro.org>
Subject: [PATCH v3 5/5] amba: Make use of bus_type functions
Date: Tue, 26 Jan 2021 17:58:35 +0100	[thread overview]
Message-ID: <20210126165835.687514-6-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20210126165835.687514-1-u.kleine-koenig@pengutronix.de>

Instead of assigning the needed functions for each driver separately do it
only once in amba_bustype. Move the definition of the functions to their
proper place among the other callbacks used there. Note that the bus's
shutdown function might be called for unbound devices, too, so it needs
additional guarding.

This prepares getting rid of these callbacks in struct device_driver.

Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/amba/bus.c | 158 +++++++++++++++++++++++----------------------
 1 file changed, 81 insertions(+), 77 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 48b5d4b4e889..939ca220bf78 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -174,6 +174,84 @@ static int amba_uevent(struct device *dev, struct kobj_uevent_env *env)
 	return retval;
 }
 
+/*
+ * These are the device model conversion veneers; they convert the
+ * device model structures to our more specific structures.
+ */
+static int amba_probe(struct device *dev)
+{
+	struct amba_device *pcdev = to_amba_device(dev);
+	struct amba_driver *pcdrv = to_amba_driver(dev->driver);
+	const struct amba_id *id = amba_lookup(pcdrv->id_table, pcdev);
+	int ret;
+
+	do {
+		ret = of_clk_set_defaults(dev->of_node, false);
+		if (ret < 0)
+			break;
+
+		ret = dev_pm_domain_attach(dev, true);
+		if (ret)
+			break;
+
+		ret = amba_get_enable_pclk(pcdev);
+		if (ret) {
+			dev_pm_domain_detach(dev, true);
+			break;
+		}
+
+		pm_runtime_get_noresume(dev);
+		pm_runtime_set_active(dev);
+		pm_runtime_enable(dev);
+
+		ret = pcdrv->probe(pcdev, id);
+		if (ret == 0)
+			break;
+
+		pm_runtime_disable(dev);
+		pm_runtime_set_suspended(dev);
+		pm_runtime_put_noidle(dev);
+
+		amba_put_disable_pclk(pcdev);
+		dev_pm_domain_detach(dev, true);
+	} while (0);
+
+	return ret;
+}
+
+static int amba_remove(struct device *dev)
+{
+	struct amba_device *pcdev = to_amba_device(dev);
+	struct amba_driver *drv = to_amba_driver(dev->driver);
+
+	pm_runtime_get_sync(dev);
+	if (drv->remove)
+		drv->remove(pcdev);
+	pm_runtime_put_noidle(dev);
+
+	/* Undo the runtime PM settings in amba_probe() */
+	pm_runtime_disable(dev);
+	pm_runtime_set_suspended(dev);
+	pm_runtime_put_noidle(dev);
+
+	amba_put_disable_pclk(pcdev);
+	dev_pm_domain_detach(dev, true);
+
+	return 0;
+}
+
+static void amba_shutdown(struct device *dev)
+{
+	struct amba_driver *drv;
+
+	if (!dev->driver)
+		return;
+
+	drv = to_amba_driver(dev->driver);
+	if (drv->shutdown)
+		drv->shutdown(to_amba_device(dev));
+}
+
 #ifdef CONFIG_PM
 /*
  * Hooks to provide runtime PM of the pclk (bus clock).  It is safe to
@@ -239,6 +317,9 @@ struct bus_type amba_bustype = {
 	.dev_groups	= amba_dev_groups,
 	.match		= amba_match,
 	.uevent		= amba_uevent,
+	.probe		= amba_probe,
+	.remove		= amba_remove,
+	.shutdown	= amba_shutdown,
 	.dma_configure	= platform_dma_configure,
 	.pm		= &amba_pm,
 };
@@ -251,80 +332,6 @@ static int __init amba_init(void)
 
 postcore_initcall(amba_init);
 
-/*
- * These are the device model conversion veneers; they convert the
- * device model structures to our more specific structures.
- */
-static int amba_probe(struct device *dev)
-{
-	struct amba_device *pcdev = to_amba_device(dev);
-	struct amba_driver *pcdrv = to_amba_driver(dev->driver);
-	const struct amba_id *id = amba_lookup(pcdrv->id_table, pcdev);
-	int ret;
-
-	do {
-		ret = of_clk_set_defaults(dev->of_node, false);
-		if (ret < 0)
-			break;
-
-		ret = dev_pm_domain_attach(dev, true);
-		if (ret)
-			break;
-
-		ret = amba_get_enable_pclk(pcdev);
-		if (ret) {
-			dev_pm_domain_detach(dev, true);
-			break;
-		}
-
-		pm_runtime_get_noresume(dev);
-		pm_runtime_set_active(dev);
-		pm_runtime_enable(dev);
-
-		ret = pcdrv->probe(pcdev, id);
-		if (ret == 0)
-			break;
-
-		pm_runtime_disable(dev);
-		pm_runtime_set_suspended(dev);
-		pm_runtime_put_noidle(dev);
-
-		amba_put_disable_pclk(pcdev);
-		dev_pm_domain_detach(dev, true);
-	} while (0);
-
-	return ret;
-}
-
-static int amba_remove(struct device *dev)
-{
-	struct amba_device *pcdev = to_amba_device(dev);
-	struct amba_driver *drv = to_amba_driver(dev->driver);
-
-	pm_runtime_get_sync(dev);
-	if (drv->remove)
-		drv->remove(pcdev);
-	pm_runtime_put_noidle(dev);
-
-	/* Undo the runtime PM settings in amba_probe() */
-	pm_runtime_disable(dev);
-	pm_runtime_set_suspended(dev);
-	pm_runtime_put_noidle(dev);
-
-	amba_put_disable_pclk(pcdev);
-	dev_pm_domain_detach(dev, true);
-
-	return 0;
-}
-
-static void amba_shutdown(struct device *dev)
-{
-	struct amba_driver *drv = to_amba_driver(dev->driver);
-
-	if (drv->shutdown)
-		drv->shutdown(to_amba_device(dev));
-}
-
 /**
  *	amba_driver_register - register an AMBA device driver
  *	@drv: amba device driver structure
@@ -339,9 +346,6 @@ int amba_driver_register(struct amba_driver *drv)
 		return -EINVAL;
 
 	drv->drv.bus = &amba_bustype;
-	drv->drv.probe = amba_probe;
-	drv->drv.remove = amba_remove;
-	drv->drv.shutdown = amba_shutdown;
 
 	return driver_register(&drv->drv);
 }
-- 
2.29.2


WARNING: multiple messages have this Message-ID (diff)
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Russell King <linux@armlinux.org.uk>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-arm-kernel@lists.infradead.org,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Arnd Bergmann <arnd@arndb.de>,
	linux-kernel@vger.kernel.org, kernel@pengutronix.de
Subject: [PATCH v3 5/5] amba: Make use of bus_type functions
Date: Tue, 26 Jan 2021 17:58:35 +0100	[thread overview]
Message-ID: <20210126165835.687514-6-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20210126165835.687514-1-u.kleine-koenig@pengutronix.de>

Instead of assigning the needed functions for each driver separately do it
only once in amba_bustype. Move the definition of the functions to their
proper place among the other callbacks used there. Note that the bus's
shutdown function might be called for unbound devices, too, so it needs
additional guarding.

This prepares getting rid of these callbacks in struct device_driver.

Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/amba/bus.c | 158 +++++++++++++++++++++++----------------------
 1 file changed, 81 insertions(+), 77 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 48b5d4b4e889..939ca220bf78 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -174,6 +174,84 @@ static int amba_uevent(struct device *dev, struct kobj_uevent_env *env)
 	return retval;
 }
 
+/*
+ * These are the device model conversion veneers; they convert the
+ * device model structures to our more specific structures.
+ */
+static int amba_probe(struct device *dev)
+{
+	struct amba_device *pcdev = to_amba_device(dev);
+	struct amba_driver *pcdrv = to_amba_driver(dev->driver);
+	const struct amba_id *id = amba_lookup(pcdrv->id_table, pcdev);
+	int ret;
+
+	do {
+		ret = of_clk_set_defaults(dev->of_node, false);
+		if (ret < 0)
+			break;
+
+		ret = dev_pm_domain_attach(dev, true);
+		if (ret)
+			break;
+
+		ret = amba_get_enable_pclk(pcdev);
+		if (ret) {
+			dev_pm_domain_detach(dev, true);
+			break;
+		}
+
+		pm_runtime_get_noresume(dev);
+		pm_runtime_set_active(dev);
+		pm_runtime_enable(dev);
+
+		ret = pcdrv->probe(pcdev, id);
+		if (ret == 0)
+			break;
+
+		pm_runtime_disable(dev);
+		pm_runtime_set_suspended(dev);
+		pm_runtime_put_noidle(dev);
+
+		amba_put_disable_pclk(pcdev);
+		dev_pm_domain_detach(dev, true);
+	} while (0);
+
+	return ret;
+}
+
+static int amba_remove(struct device *dev)
+{
+	struct amba_device *pcdev = to_amba_device(dev);
+	struct amba_driver *drv = to_amba_driver(dev->driver);
+
+	pm_runtime_get_sync(dev);
+	if (drv->remove)
+		drv->remove(pcdev);
+	pm_runtime_put_noidle(dev);
+
+	/* Undo the runtime PM settings in amba_probe() */
+	pm_runtime_disable(dev);
+	pm_runtime_set_suspended(dev);
+	pm_runtime_put_noidle(dev);
+
+	amba_put_disable_pclk(pcdev);
+	dev_pm_domain_detach(dev, true);
+
+	return 0;
+}
+
+static void amba_shutdown(struct device *dev)
+{
+	struct amba_driver *drv;
+
+	if (!dev->driver)
+		return;
+
+	drv = to_amba_driver(dev->driver);
+	if (drv->shutdown)
+		drv->shutdown(to_amba_device(dev));
+}
+
 #ifdef CONFIG_PM
 /*
  * Hooks to provide runtime PM of the pclk (bus clock).  It is safe to
@@ -239,6 +317,9 @@ struct bus_type amba_bustype = {
 	.dev_groups	= amba_dev_groups,
 	.match		= amba_match,
 	.uevent		= amba_uevent,
+	.probe		= amba_probe,
+	.remove		= amba_remove,
+	.shutdown	= amba_shutdown,
 	.dma_configure	= platform_dma_configure,
 	.pm		= &amba_pm,
 };
@@ -251,80 +332,6 @@ static int __init amba_init(void)
 
 postcore_initcall(amba_init);
 
-/*
- * These are the device model conversion veneers; they convert the
- * device model structures to our more specific structures.
- */
-static int amba_probe(struct device *dev)
-{
-	struct amba_device *pcdev = to_amba_device(dev);
-	struct amba_driver *pcdrv = to_amba_driver(dev->driver);
-	const struct amba_id *id = amba_lookup(pcdrv->id_table, pcdev);
-	int ret;
-
-	do {
-		ret = of_clk_set_defaults(dev->of_node, false);
-		if (ret < 0)
-			break;
-
-		ret = dev_pm_domain_attach(dev, true);
-		if (ret)
-			break;
-
-		ret = amba_get_enable_pclk(pcdev);
-		if (ret) {
-			dev_pm_domain_detach(dev, true);
-			break;
-		}
-
-		pm_runtime_get_noresume(dev);
-		pm_runtime_set_active(dev);
-		pm_runtime_enable(dev);
-
-		ret = pcdrv->probe(pcdev, id);
-		if (ret == 0)
-			break;
-
-		pm_runtime_disable(dev);
-		pm_runtime_set_suspended(dev);
-		pm_runtime_put_noidle(dev);
-
-		amba_put_disable_pclk(pcdev);
-		dev_pm_domain_detach(dev, true);
-	} while (0);
-
-	return ret;
-}
-
-static int amba_remove(struct device *dev)
-{
-	struct amba_device *pcdev = to_amba_device(dev);
-	struct amba_driver *drv = to_amba_driver(dev->driver);
-
-	pm_runtime_get_sync(dev);
-	if (drv->remove)
-		drv->remove(pcdev);
-	pm_runtime_put_noidle(dev);
-
-	/* Undo the runtime PM settings in amba_probe() */
-	pm_runtime_disable(dev);
-	pm_runtime_set_suspended(dev);
-	pm_runtime_put_noidle(dev);
-
-	amba_put_disable_pclk(pcdev);
-	dev_pm_domain_detach(dev, true);
-
-	return 0;
-}
-
-static void amba_shutdown(struct device *dev)
-{
-	struct amba_driver *drv = to_amba_driver(dev->driver);
-
-	if (drv->shutdown)
-		drv->shutdown(to_amba_device(dev));
-}
-
 /**
  *	amba_driver_register - register an AMBA device driver
  *	@drv: amba device driver structure
@@ -339,9 +346,6 @@ int amba_driver_register(struct amba_driver *drv)
 		return -EINVAL;
 
 	drv->drv.bus = &amba_bustype;
-	drv->drv.probe = amba_probe;
-	drv->drv.remove = amba_remove;
-	drv->drv.shutdown = amba_shutdown;
 
 	return driver_register(&drv->drv);
 }
-- 
2.29.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2021-01-27  0:35 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26 16:58 [PATCH v3 0/5] amba: minor fix and various cleanups Uwe Kleine-König
2021-01-26 16:58 ` Uwe Kleine-König
2021-01-26 16:58 ` Uwe Kleine-König
2021-01-26 16:58 ` [PATCH v3 1/5] amba: Fix resource leak for drivers without .remove Uwe Kleine-König
2021-01-26 16:58   ` Uwe Kleine-König
2021-01-26 16:58 ` [PATCH v3 2/5] amba: reorder functions Uwe Kleine-König
2021-01-26 16:58   ` Uwe Kleine-König
2021-01-26 16:58 ` [PATCH v3 3/5] vfio: platform: simplify device removal Uwe Kleine-König
2021-01-26 16:58   ` Uwe Kleine-König
2021-01-26 16:58 ` [PATCH v3 4/5] amba: Make the remove callback return void Uwe Kleine-König
2021-01-26 16:58   ` Uwe Kleine-König
2021-01-26 16:58   ` Uwe Kleine-König
2021-01-26 17:08   ` Suzuki K Poulose
2021-01-26 17:08     ` Suzuki K Poulose
2021-01-26 17:08     ` Suzuki K Poulose
2021-01-26 17:56     ` Uwe Kleine-König
2021-01-26 17:56       ` Uwe Kleine-König
2021-01-26 17:56       ` Uwe Kleine-König
2021-01-26 19:05       ` Russell King - ARM Linux admin
2021-01-26 19:05         ` Russell King - ARM Linux admin
2021-01-26 19:05         ` Russell King - ARM Linux admin
2021-01-26 17:30   ` Vinod Koul
2021-01-26 17:30     ` Vinod Koul
2021-01-26 17:30     ` Vinod Koul
2021-01-26 19:24   ` Guenter Roeck
2021-01-26 19:24     ` Guenter Roeck
2021-01-26 19:24     ` Guenter Roeck
2021-01-27  6:47   ` Wolfram Sang
2021-01-27  6:47     ` Wolfram Sang
2021-01-27  6:47     ` Wolfram Sang
2021-01-27  6:50   ` Takashi Iwai
2021-01-27  6:50     ` Takashi Iwai
2021-01-27  6:50     ` Takashi Iwai
2021-01-27  8:12   ` Vladimir Zapolskiy
2021-01-27  8:12     ` Vladimir Zapolskiy
2021-01-27  8:12     ` Vladimir Zapolskiy
2021-01-27 12:03   ` Greg Kroah-Hartman
2021-01-27 12:03     ` Greg Kroah-Hartman
2021-01-27 12:03     ` Greg Kroah-Hartman
2021-02-03 13:18   ` Auger Eric
2021-02-03 13:18     ` Auger Eric
2021-02-03 13:18     ` Auger Eric
2021-01-26 16:58 ` Uwe Kleine-König [this message]
2021-01-26 16:58   ` [PATCH v3 5/5] amba: Make use of bus_type functions Uwe Kleine-König
2021-02-02 10:49 ` [PATCH v3 0/5] amba: minor fix and various cleanups Russell King - ARM Linux admin
2021-02-02 10:49   ` Russell King - ARM Linux admin
2021-02-02 10:49   ` Russell King - ARM Linux admin
2021-02-03  7:45   ` Uwe Kleine-König
2021-02-03  7:45     ` Uwe Kleine-König
2021-02-03  7:45     ` Uwe Kleine-König
2021-02-02 13:53 ` [GIT PULL] immutable branch for amba changes targeting v5.12-rc1 Uwe Kleine-König
2021-02-02 13:53   ` Uwe Kleine-König
2021-02-02 13:53   ` Uwe Kleine-König
2021-02-02 14:06   ` Greg Kroah-Hartman
2021-02-02 14:06     ` Greg Kroah-Hartman
2021-02-02 14:06     ` Greg Kroah-Hartman
2021-02-04 16:52     ` Russell King - ARM Linux admin
2021-02-04 16:52       ` Russell King - ARM Linux admin
2021-02-04 16:52       ` Russell King - ARM Linux admin
2021-02-04 16:56       ` Greg Kroah-Hartman
2021-02-04 16:56         ` Greg Kroah-Hartman
2021-02-04 16:56         ` Greg Kroah-Hartman
2021-02-04 16:59         ` Russell King - ARM Linux admin
2021-02-04 16:59           ` Russell King - ARM Linux admin
2021-02-04 16:59           ` Russell King - ARM Linux admin
2021-02-04 18:15           ` Uwe Kleine-König
2021-02-04 18:15             ` Uwe Kleine-König
2021-02-04 18:15             ` Uwe Kleine-König
2021-02-05  9:37             ` Uwe Kleine-König
2021-02-05  9:37               ` Uwe Kleine-König
2021-02-05  9:37               ` Uwe Kleine-König
2021-02-05 10:18               ` Greg Kroah-Hartman
2021-02-05 10:18                 ` Greg Kroah-Hartman
2021-02-05 10:18                 ` Greg Kroah-Hartman
2021-02-05 10:56                 ` Uwe Kleine-König
2021-02-05 10:56                   ` Uwe Kleine-König
2021-02-05 10:56                   ` Uwe Kleine-König
2021-02-05 11:07                   ` Greg Kroah-Hartman
2021-02-05 11:07                     ` Greg Kroah-Hartman
2021-02-05 11:07                     ` Greg Kroah-Hartman
2021-02-02 19:43   ` [PATCH] mailbox: arm_mhuv2: make remove callback return void Uwe Kleine-König
2021-02-02 19:43     ` Uwe Kleine-König
2021-02-02 19:43     ` Uwe Kleine-König
2021-02-03  2:57     ` Viresh Kumar
2021-02-03  2:57       ` Viresh Kumar
2021-02-03  2:57       ` Viresh Kumar
2021-02-02 21:35   ` [GIT PULL] immutable branch for amba changes targeting v5.12-rc1 Uwe Kleine-König
2021-02-02 21:35     ` Uwe Kleine-König
2021-02-02 21:35     ` Uwe Kleine-König

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=20210126165835.687514-6-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=ulf.hansson@linaro.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.