Skip to contentSkip to conversation

mfd: Allow multiple MFD cells with the same name

PATCH/RFC Mark Brown 2 participants 4 messages Jul 2, 2009 – Jul 25, 2009 Multifunction devices (MFD)

lore
Share & tools
lore

Mark Brown

author
#0 lore raw

Provide basic support for MFDs having multiple cells of a given type with different IDs by adding an id to the mfd_cell structure and then adding that to the id passed in to mfd_add_devices().

As it stands this approach requires that MFDs using this feature deal with ensuring that there aren't any ID collisions resulting from multiple MFDs of the same type being instantiated. This needs to happen with the existing code too, but with this approach there is a knock on effect on the IDs for non-duplicated devices.

---

I'm not 100% convinced that this is the best way to do this but I can't think of anything better.

 drivers/mfd/mfd-core.c   |    2 +-
 include/linux/mfd/core.h |    1 +
 2 files changed, 2 insertions(+), 1 deletions(-)
drivers/mfd/mfd-core.c +1 -1
index 54ddf37..ae15e49 100644
@@ -25,7 +25,7 @@ static int mfd_add_device(struct device *parent, int id,
 	int ret = -ENOMEM;
 	int r;
 
-	pdev = platform_device_alloc(cell->name, id);
+	pdev = platform_device_alloc(cell->name, id + cell->id);
 	if (!pdev)
 		goto fail_alloc;
 
include/linux/mfd/core.h +1 -0
index 49ef857..11d740b 100644
@@ -23,6 +23,7 @@
  */
 struct mfd_cell {
 	const char		*name;
+	int			id;
 
 	int			(*enable)(struct platform_device *dev);
 	int			(*disable)(struct platform_device *dev);
Signature · 1 line
1.6.3.3
author
#1 lore raw
Quoted 11 lines · Mark Brown

Provide basic support for MFDs having multiple cells of a given type with different IDs by adding an id to the mfd_cell structure and then adding that to the id passed in to mfd_add_devices().

As it stands this approach requires that MFDs using this feature deal with ensuring that there aren't any ID collisions resulting from multiple MFDs of the same type being instantiated. This needs to happen with the existing code too, but with this approach there is a knock on effect on the IDs for non-duplicated devices.

Samuel, do you have any thoughts on this patch? As I said...

Quoted 2 lines

I'm not 100% convinced that this is the best way to do this but I can't think of anything better

...but it'd be really helpful to get some idea if this approach is going to be viable for some code I'm currently working on.

Quoted 39 lines
 drivers/mfd/mfd-core.c   |    2 +-
 include/linux/mfd/core.h |    1 +
 2 files changed, 2 insertions(+), 1 deletions(-)
drivers/mfd/mfd-core.c +1 -1
index 54ddf37..ae15e49 100644
@@ -25,7 +25,7 @@ static int mfd_add_device(struct device *parent, int id,
 	int ret = -ENOMEM;
 	int r;
 
-	pdev = platform_device_alloc(cell->name, id);
+	pdev = platform_device_alloc(cell->name, id + cell->id);
 	if (!pdev)
 		goto fail_alloc;
 
include/linux/mfd/core.h +1 -0
index 49ef857..11d740b 100644
@@ -23,6 +23,7 @@
  */
 struct mfd_cell {
 	const char		*name;
+	int			id;
 
 	int			(*enable)(struct platform_device *dev);
 	int			(*disable)(struct platform_device *dev);
Signature · 7 lines
1.6.3.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Signature · 1 line
"You grabbed my hand and we fell into it, like a daydream - or a fever."
#2 lore raw

Hi Mark,

Quoted 11 lines · Mark Brown
Quoted 10 lines · Mark Brown

Provide basic support for MFDs having multiple cells of a given type with different IDs by adding an id to the mfd_cell structure and then adding that to the id passed in to mfd_add_devices().

As it stands this approach requires that MFDs using this feature deal with ensuring that there aren't any ID collisions resulting from multiple MFDs of the same type being instantiated. This needs to happen with the existing code too, but with this approach there is a knock on effect on the IDs for non-duplicated devices.

Quoted 3 lines
Quoted 1 line

Samuel, do you have any thoughts on this patch? As I said...

I think it's safe to expect people that decide they need this feature will be careful enough to make sure they dont get ID collisions.

Quoted 5 lines
Quoted 2 lines

I'm not 100% convinced that this is the best way to do this but I can't think of anything better

...but it'd be really helpful to get some idea if this approach is going to be viable for some code I'm currently working on.

I'm ok with this patch, but I'd like the new cell->id field to be more documented. In particular we should mention that one should leave it to 0 unless trying to add several cells of the same type.
I'll push this patch once I'll be back from vacation, thanks.

Cheers,
Samuel.

Quoted 43 lines
Quoted 40 lines

 drivers/mfd/mfd-core.c   |    2 +-
 include/linux/mfd/core.h |    1 +
 2 files changed, 2 insertions(+), 1 deletions(-)
drivers/mfd/mfd-core.c +1 -1
index 54ddf37..ae15e49 100644
@@ -25,7 +25,7 @@ static int mfd_add_device(struct device *parent, int id,
 	int ret = -ENOMEM;
 	int r;
 
-	pdev = platform_device_alloc(cell->name, id);
+	pdev = platform_device_alloc(cell->name, id + cell->id);
 	if (!pdev)
 		goto fail_alloc;
 
include/linux/mfd/core.h +1 -0
index 49ef857..11d740b 100644
@@ -23,6 +23,7 @@
  */
 struct mfd_cell {
 	const char		*name;
+	int			id;
 
 	int			(*enable)(struct platform_device *dev);
 	int			(*disable)(struct platform_device *dev);
Signature · 7 lines
1.6.3.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Signature · 1 line
"You grabbed my hand and we fell into it, like a daydream - or a fever."
Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
author
#3 lore raw
Quoted 6 lines · Samuel Ortiz
Quoted 1 line · Mark Brown

Samuel, do you have any thoughts on this patch? As I said...

I think it's safe to expect people that decide they need this feature will be careful enough to make sure they dont get ID collisions.

Yes, and it should be fairly easy to work out what's gone wrong if there are any problems.

Quoted 7 lines
Quoted 2 lines

...but it'd be really helpful to get some idea if this approach is going to be viable for some code I'm currently working on.

I'm ok with this patch, but I'd like the new cell->id field to be more documented. In particular we should mention that one should leave it to 0 unless trying to add several cells of the same type.
I'll push this patch once I'll be back from vacation, thanks.

OK, thanks. I'm not sure when you're back from your vacation but early next week I should be releasing the code which I was mentioning above - if you've not applied it before then I'll try to include a revised version with more documentation in that series.