From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
Philipp Zabel <p.zabel@pengutronix.de>,
Linus Walleij <linus.walleij@linaro.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Lee Jones <lee@kernel.org>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: linux-mips@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org,
linux-gpio@vger.kernel.org,
"Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>,
"Gregory CLEMENT" <gregory.clement@bootlin.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Tawfik Bayouk" <tawfik.bayouk@mobileye.com>,
"Théo Lebrun" <theo.lebrun@bootlin.com>
Subject: [PATCH v2 04/11] driver core: platform: Introduce platform_device_add_with_name()
Date: Fri, 03 May 2024 16:20:49 +0200 [thread overview]
Message-ID: <20240503-mbly-olb-v2-4-95ce5a1e18fe@bootlin.com> (raw)
In-Reply-To: <20240503-mbly-olb-v2-0-95ce5a1e18fe@bootlin.com>
Public function platform_device_add() does three things:
- Name device using pdev->name and pdev->id;
- Insert resources into resource tree;
- device_add().
This implies device name must be based upon pdev->name. Add
platform_device_add_with_name() to allow caller to pick device name.
pdev->name cannot be picked freely: it might be used to match platform
driver id_table or name. This applies to MFD cells for example.
In header file, avoid breakage by aliasing platform_device_add(pdev) to
platform_device_add_with_name(pdev, NULL).
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
drivers/base/platform.c | 17 +++++++++++------
include/linux/platform_device.h | 12 +++++++++++-
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 10c577963418..dce282cb2e50 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -648,13 +648,15 @@ int platform_device_add_data(struct platform_device *pdev, const void *data,
EXPORT_SYMBOL_GPL(platform_device_add_data);
/**
- * platform_device_add - add a platform device to device hierarchy
+ * platform_device_add_with_name - add a platform device to device hierarchy
* @pdev: platform device we're adding
+ * @devname: optional device name to assign, fallback to platform device name
*
* This is part 2 of platform_device_register(), though may be called
* separately _iff_ pdev was allocated by platform_device_alloc().
*/
-int platform_device_add(struct platform_device *pdev)
+int platform_device_add_with_name(struct platform_device *pdev,
+ const char *devname)
{
struct device *dev = &pdev->dev;
u32 i;
@@ -665,12 +667,15 @@ int platform_device_add(struct platform_device *pdev)
dev->bus = &platform_bus_type;
+ if (!devname)
+ devname = pdev->name;
+
switch (pdev->id) {
default:
- dev_set_name(dev, "%s.%d", pdev->name, pdev->id);
+ dev_set_name(dev, "%s.%d", devname, pdev->id);
break;
case PLATFORM_DEVID_NONE:
- dev_set_name(dev, "%s", pdev->name);
+ dev_set_name(dev, "%s", devname);
break;
case PLATFORM_DEVID_AUTO:
/*
@@ -683,7 +688,7 @@ int platform_device_add(struct platform_device *pdev)
return ret;
pdev->id = ret;
pdev->id_auto = true;
- dev_set_name(dev, "%s.%d.auto", pdev->name, pdev->id);
+ dev_set_name(dev, "%s.%d.auto", devname, pdev->id);
break;
}
@@ -733,7 +738,7 @@ int platform_device_add(struct platform_device *pdev)
return ret;
}
-EXPORT_SYMBOL_GPL(platform_device_add);
+EXPORT_SYMBOL_GPL(platform_device_add_with_name);
/**
* platform_device_del - remove a platform-level device
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 7a41c72c1959..bc1463c83f69 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -229,10 +229,20 @@ extern int platform_device_add_resources(struct platform_device *pdev,
unsigned int num);
extern int platform_device_add_data(struct platform_device *pdev,
const void *data, size_t size);
-extern int platform_device_add(struct platform_device *pdev);
+extern int platform_device_add_with_name(struct platform_device *pdev,
+ const char *devname);
extern void platform_device_del(struct platform_device *pdev);
extern void platform_device_put(struct platform_device *pdev);
+/**
+ * platform_device_add - add a platform device to device hierarchy
+ * @pdev: platform device we're adding
+ */
+static inline int platform_device_add(struct platform_device *pdev)
+{
+ return platform_device_add_with_name(pdev, NULL);
+}
+
struct platform_driver {
int (*probe)(struct platform_device *);
--
2.45.0
next prev parent reply other threads:[~2024-05-03 14:21 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-03 14:20 [PATCH v2 00/11] Add Mobileye EyeQ system controller support (clk, reset, pinctrl) Théo Lebrun
2024-05-03 14:20 ` [PATCH v2 01/11] dt-bindings: clock: mobileye,eyeq5-clk: drop bindings Théo Lebrun
2024-05-03 15:57 ` Krzysztof Kozlowski
2024-05-03 16:05 ` Krzysztof Kozlowski
2024-05-07 15:07 ` Théo Lebrun
2024-05-07 15:34 ` Krzysztof Kozlowski
2024-06-20 17:39 ` Théo Lebrun
2024-05-03 14:20 ` [PATCH v2 02/11] dt-bindings: clock: mobileye,eyeq5-reset: " Théo Lebrun
2024-05-03 15:35 ` Rob Herring (Arm)
2024-05-03 14:20 ` [PATCH v2 03/11] dt-bindings: soc: mobileye: add EyeQ OLB system controller Théo Lebrun
2024-05-03 15:35 ` Rob Herring (Arm)
2024-05-07 12:51 ` Rob Herring
2024-06-20 17:41 ` Théo Lebrun
2024-05-03 14:20 ` Théo Lebrun [this message]
2024-05-03 14:20 ` [PATCH v2 05/11] mfd: Add cell device name Théo Lebrun
2024-05-03 14:20 ` [PATCH v2 06/11] mfd: olb: Add support for Mobileye OLB system-controller Théo Lebrun
2024-05-31 11:05 ` Lee Jones
2024-06-20 17:48 ` Théo Lebrun
2024-05-03 14:20 ` [PATCH v2 07/11] clk: divider: Introduce CLK_DIVIDER_EVEN_INTEGERS flag Théo Lebrun
2024-05-03 14:20 ` [PATCH v2 08/11] clk: eyeq: add driver Théo Lebrun
2024-05-03 14:20 ` [PATCH v2 09/11] reset: eyeq: add platform driver Théo Lebrun
2024-05-03 14:20 ` [PATCH v2 10/11] pinctrl: eyeq5: " Théo Lebrun
2024-05-03 14:20 ` [PATCH v2 11/11] MIPS: mobileye: eyeq5: add OLB system-controller node Théo Lebrun
2024-05-04 2:34 ` [PATCH v2 00/11] Add Mobileye EyeQ system controller support (clk, reset, pinctrl) Stephen Boyd
2024-05-07 14:52 ` Théo Lebrun
2024-05-07 15:14 ` Théo Lebrun
2024-05-07 21:48 ` Stephen Boyd
2024-06-20 18:00 ` Théo Lebrun
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=20240503-mbly-olb-v2-4-95ce5a1e18fe@bootlin.com \
--to=theo.lebrun@bootlin.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=gregory.clement@bootlin.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lee@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=p.zabel@pengutronix.de \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=tawfik.bayouk@mobileye.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=tsbogend@alpha.franken.de \
--cc=vladimir.kondratiev@mobileye.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox