[PATCH v2 05/11] mfd: Add cell device name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Current device name is picked from pdev->name, coming from cell->name.
pdev->name is sometimes used to match driver so cannot be changed.
Add cell->devname field to let MFDs configure their sub-devices names
using newly introduced platform_device_add_with_name().

This comes in handy when MFDs instantiate the same platform driver.
First solution is to use auto IDs:

	// MFD device A generates sub-device named "foo.0.auto"
	struct mfd_cell cell = { .name = "foo" };
	mfd_add_devices(dev, PLATFORM_DEVID_AUTO, &cell, 1, ...);

	// MFD device B generates sub-device named "foo.1.auto"
	struct mfd_cell cell = { .name = "foo" };
	mfd_add_devices(dev, PLATFORM_DEVID_AUTO, &cell, 1, ...);

An alternative is to manually pick IDs using cell->id:

	// MFD device A generates sub-device named "foo.0"
	struct mfd_cell cell = { .name = "foo", .id = 0 };
	mfd_add_devices(dev, 0, &cell, 1, ...);

	// MFD device B generates sub-device named "foo.1"
	struct mfd_cell cell = { .name = "foo", .id = 1 };
	mfd_add_devices(dev, 0, &cell, 1, ...);

Devices still have obscure names. With changes, two MFD devices can do:

	// MFD device A generates sub-device named "foo-a"
	struct mfd_cell cell = { .name = "foo", .devname = "foo-a" };
	mfd_add_devices(dev, PLATFORM_DEVID_NONE, &cell, 1, ...);

	// MFD device B generates sub-device named "foo-b"
	struct mfd_cell cell = { .name = "foo", .devname = "foo-b" };
	mfd_add_devices(dev, PLATFORM_DEVID_NONE, &cell, 1, ...);

Device names are explicit and facilitate identification.
Benefit increases with more instances.

No shorthand MFD_CELL_*() macro is created to exploit this field.

Signed-off-by: Théo Lebrun <theo.lebrun@xxxxxxxxxxx>
---
 drivers/mfd/mfd-core.c   |  2 +-
 include/linux/mfd/core.h | 19 ++++++++++++-------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 6ad5c93027af..bdfbe860295a 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -271,7 +271,7 @@ static int mfd_add_device(struct device *parent, int id,
 	if (ret)
 		goto fail_res_conflict;
 
-	ret = platform_device_add(pdev);
+	ret = platform_device_add_with_name(pdev, cell->devname);
 	if (ret)
 		goto fail_res_conflict;
 
diff --git a/include/linux/mfd/core.h b/include/linux/mfd/core.h
index e8bcad641d8c..a2040372ca91 100644
--- a/include/linux/mfd/core.h
+++ b/include/linux/mfd/core.h
@@ -14,7 +14,8 @@
 
 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
 
-#define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, _use_of_reg, _match) \
+#define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat,	\
+		     _of_reg, _use_of_reg, _match, _devname)		\
 	{								\
 		.name = (_name),					\
 		.resources = (_res),					\
@@ -26,25 +27,26 @@
 		.use_of_reg = (_use_of_reg),				\
 		.acpi_match = (_match),					\
 		.id = (_id),						\
+		.devname = (_devname),					\
 	}
 
 #define MFD_CELL_OF_REG(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg) \
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, true, NULL)
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, true, NULL, NULL)
 
 #define MFD_CELL_OF(_name, _res, _pdata, _pdsize, _id, _compat) \
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, 0, false, NULL)
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, 0, false, NULL, NULL)
 
 #define MFD_CELL_ACPI(_name, _res, _pdata, _pdsize, _id, _match) \
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, _match)
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, _match, NULL)
 
 #define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id) \
-	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, NULL)
+	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, NULL, NULL)
 
 #define MFD_CELL_RES(_name, _res) \
-	MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, 0, false, NULL)
+	MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, 0, false, NULL, NULL)
 
 #define MFD_CELL_NAME(_name) \
-	MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, false, NULL)
+	MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, false, NULL, NULL)
 
 #define MFD_DEP_LEVEL_NORMAL 0
 #define MFD_DEP_LEVEL_HIGH 1
@@ -118,6 +120,9 @@ struct mfd_cell {
 	 */
 	int			num_parent_supplies;
 	const char * const	*parent_supplies;
+
+	/* Optional struct device name. */
+	const char		*devname;
 };
 
 /*

-- 
2.45.0





[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux