mfd: core: introduce of_node_name for mfd sub devices
Subsystems (2)
PATCH 1/1 mfd: core: introduce of_node_name for mfd sub devices
Multi Function Devices (MFDs) have multiple sub module whose driver is developed in different sub-system like GPIO, regulators, RTC, clock etc. The device tree of such device contains multiple sub-node which contains the properties of these sub-modules.
The sub module gets of_node handle either by the dev->of_node or by getting the child node handle from parent DT handle by finding child name on parent's of_node.
To provide the of_node of sub-module directly, currently there is only one approach:
- Add compatible value when defining the sub-module in mfd core and add this properties when adding DT.
Introduce the of_node_name of each sub devices which is set when defining the mfd_cells of the sub devices and get the handle of these child node when adding the mfd_devices by getting the sub-node handle with matching the node name getting the sub-node handle with matching the node name.
---
Creating this patch based on the discussion on patch [PATCH 1/4] mfd: add support for AMS AS3722 PMIC
The discussion on above patch is not concluded and want to have further discussion on this patch.
Documentation/devicetree/bindings/mfd/mfd-core.txt | 57 ++++++++++++++++++++ drivers/mfd/mfd-core.c | 10 +++- include/linux/mfd/core.h | 6 ++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/mfd/mfd-core.txt
Documentation/devicetree/bindings/mfd/mfd-core.txt new file +57 -0
@@ -0,0 +1,57 @@ +MFD DT binding document +----------------------- + +Multi Function Devices (MFDs) have multiple sub module whose driver is developed +in different sub-system like GPIO, regulators, RTC, clock etc. The device +tree of such device contains multiple sub-node which contains the properties +of these sub-modules. +The sub modules get of_node handle either by the dev->of_node or by getting +the child node handle from parent DT handle by finding child name on parent's +of_node. +To provide the of_node of sub-module directly, there is two approach: +- Add compatible value when defining the sub-module in mfd core and + add this properties when adding DT. +- Add the of_node_name when defining the sub-module in mfd core and + add keep same name of child node when adding DT. + +If none of above matches then sub-module driver will not get their of_node +and they need to derive the method to get their node from parent node. + +Examples: +DT file: +-------- + mfd_device_dt { + .... + gpio_child { + /* Properties which need by gpio sub module */ + }; + + rtc_child { + /* Properties which need by rtc sub module */ + }; + + regulator_child { + /* Properties which need by regulator sub module */ + }; + }; + + +Driver code: +----------- +static struct mfd_cell mfd_abc_devs[] = { + { + .name = "mfd-abc-gpio", + .of_node_name = "gpio_child"; + }, + { + .name = "mfd-abc-regulator", + .of_node_name = "regulator_child"; + }, + { + .name = "mfd-abc-rtc", + .of_node_name = "rtc_child"; + }, +}; + +Here sub-node names are gpio_child, rtc_child, regulator_child and it is same +as of_node_name defined in the driver.
drivers/mfd/mfd-core.c +8 -2
@@ -99,9 +99,15 @@ static int mfd_add_device(struct device *parent, int id, pdev->dev.dma_mask = parent->dma_mask; pdev->dev.dma_parms = parent->dma_parms; -if (parent->of_node && cell->of_compatible) { +if (parent->of_node && (cell->of_compatible || cell->of_node_name)) {for_each_child_of_node (parent->of_node, np) { -if (of_device_is_compatible (np, cell->of_compatible)) { +if (cell->of_compatible && +of_device_is_compatible (np, cell->of_compatible)) { + pdev->dev.of_node = np; +break ; + } +if (cell->of_node_name && np->name && + !strcmp (cell->of_node_name, np->name)) { pdev->dev.of_node = np;break ; }
include/linux/mfd/core.h +6 -0
@@ -45,6 +45,12 @@ struct mfd_cell {const char *of_compatible;/* +* Device tree sub-node name. +* See: Documentation/devicetree/bindings/mfd/mfd-core.txt +*/ +const char *of_node_name; + +/* * These resources can be specified relative to the parent device. * For accessing hardware you should use resources from the platform dev */
Signature · 1 line
1.7.1.1
Quoted 19 lines · Laxman Dewangan
Multi Function Devices (MFDs) have multiple sub module whose driver is developed in different sub-system like GPIO, regulators, RTC, clock etc. The device tree of such device contains multiple sub-node which contains the properties of these sub-modules.
The sub module gets
of_nodehandle either by thedev->of_nodeor by getting the child node handle from parent DT handle by finding child name on parent'sof_node.To provide the
of_nodeof sub-module directly, currently there is only one approach:
- Add compatible value when defining the sub-module in mfd core and add this properties when adding DT.Introduce the
of_node_nameof each sub devices which is set when defining themfd_cellsof the sub devices and get the handle of these child node when adding themfd_devicesby getting the sub-node handle with matching the node name getting the sub-node handle with matching the node name.
Quoted 6 lines
Signed-off-by Laxman Dewangan <[email protected]>---
Creating this patch based on the discussion on patch [PATCH 1/4] mfd: add support for AMS AS3722 PMIC
The discussion on above patch is not concluded and want to have further discussion on this patch.
I'm not entirely sure this is what Mark was saying. I think he was complaining about the existence of the sub-nodes rather than how the MFD Core assigns their of_node. My take is that the chip is really a single device which provides different bits of functionality. To break that functionality up and disperse the drivers into various subsystems is a Linuxisum. By providing each functional block with its own node you're describing how we do things in Linux, rather than specifying a single node for the AS3722 which would probably be the norm.
Do the sub-nodes have their own properties? If so, it would be worth breaking them up as other OSes could reuse the specifics. If they do, then you need so put them in the binding. If they don't, then you do not require sub-nodes. The MFD core will ensure the sub-devices are probed and there is no requirement for the of_node to be assigned.
Quoted 108 lines
Documentation/devicetree/bindings/mfd/mfd-core.txt | 57 ++++++++++++++++++++ drivers/mfd/mfd-core.c | 10 +++- include/linux/mfd/core.h | 6 ++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/mfd/mfd-core.txtDocumentation/devicetree/bindings/mfd/mfd-core.txt new file +57
-0@@ -0,0 +1,57 @@ +MFD DT binding document +----------------------- + +Multi Function Devices (MFDs) have multiple sub module whose driver is developed +in different sub-system like GPIO, regulators, RTC, clock etc. The device +tree of such device contains multiple sub-node which contains the properties +of these sub-modules. +The sub modules get of_node handle either by the dev->of_node or by getting +the child node handle from parent DT handle by finding child name on parent's +of_node. +To provide the of_node of sub-module directly, there is two approach: +- Add compatible value when defining the sub-module in mfd core and + add this properties when adding DT. +- Add the of_node_name when defining the sub-module in mfd core and + add keep same name of child node when adding DT. + +If none of above matches then sub-module driver will not get their of_node +and they need to derive the method to get their node from parent node. + +Examples: +DT file: +-------- + mfd_device_dt { + .... + gpio_child { + /* Properties which need by gpio sub module */ + }; + + rtc_child { + /* Properties which need by rtc sub module */ + }; + + regulator_child { + /* Properties which need by regulator sub module */ + }; + }; + + +Driver code: +----------- +static struct mfd_cell mfd_abc_devs[] = { + { + .name = "mfd-abc-gpio", + .of_node_name = "gpio_child"; + }, + { + .name = "mfd-abc-regulator", + .of_node_name = "regulator_child"; + }, + { + .name = "mfd-abc-rtc", + .of_node_name = "rtc_child"; + }, +}; + +Here sub-node names are gpio_child, rtc_child, regulator_child and it is same +as of_node_name defined in the driver.drivers/mfd/mfd-core.c +8
-2@@ -99,9 +99,15 @@ static int mfd_add_device(struct device *parent, int id, pdev->dev.dma_mask = parent->dma_mask; pdev->dev.dma_parms = parent->dma_parms; -if (parent->of_node && cell->of_compatible) { +if (parent->of_node && (cell->of_compatible || cell->of_node_name)) {for_each_child_of_node (parent->of_node, np) { -if (of_device_is_compatible (np, cell->of_compatible)) { +if (cell->of_compatible && +of_device_is_compatible (np, cell->of_compatible)) { + pdev->dev.of_node = np; +break ; + } +if (cell->of_node_name && np->name && + !strcmp (cell->of_node_name, np->name)) { pdev->dev.of_node = np;break ; }include/linux/mfd/core.h +6
-0@@ -45,6 +45,12 @@ struct mfd_cell {const char *of_compatible;/* +* Device tree sub-node name. +* See: Documentation/devicetree/bindings/mfd/mfd-core.txt +*/ +const char *of_node_name; + +/* * These resources can be specified relative to the parent device. * For accessing hardware you should use resources from the platform dev */
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 27 lines · Lee Jones
Quoted 19 lines · Laxman Dewangan
Multi Function Devices (MFDs) have multiple sub module whose driver is developed in different sub-system like GPIO, regulators, RTC, clock etc. The device tree of such device contains multiple sub-node which contains the properties of these sub-modules.
The sub module gets
of_nodehandle either by thedev->of_nodeor by getting the child node handle from parent DT handle by finding child name on parent'sof_node.To provide the
of_nodeof sub-module directly, currently there is only one approach:
- Add compatible value when defining the sub-module in mfd core and add this properties when adding DT.Introduce the
of_node_nameof each sub devices which is set when defining themfd_cellsof the sub devices and get the handle of these child node when adding themfd_devicesby getting the sub-node handle with matching the node name getting the sub-node handle with matching the node name.Quoted 6 lines
Signed-off-by Laxman Dewangan <[email protected]>---
Creating this patch based on the discussion on patch [PATCH 1/4] mfd: add support for AMS AS3722 PMIC
The discussion on above patch is not concluded and want to have further discussion on this patch.
Quoted 3 lines
I'm not entirely sure this is what Mark was saying. I think he was complaining about the existence of the sub-nodes rather than how the MFD Core assigns their
of_node.
Yes, Mark is only saying that he is not comfortable with the compatible until it is ip based driver. I wanted to continue the discussion to find out the acceptable way so that I can use this in as3722 driver.
I added the of_node_name because each sub-driver gets its sub node by finding child node name from parent and hence duplicated the code on each driver.
Quoted 8 lines · Lee Jones
I'm not entirely sure this is what Mark was saying. I think he was complaining about the existence of the sub-nodes rather than how the MFD Core assigns their
of_node. My take is that the chip is really a single device which provides different bits of functionality. To break that functionality up and disperse the drivers into various subsystems is a Linuxisum. By providing each functional block with its own node you're describing how we do things in Linux, rather than specifying a single node for the AS3722 which would probably be the norm.
Yes, that's exactly what I was thinking of.
Quoted 5 lines
Do the sub-nodes have their own properties? If so, it would be worth breaking them up as other OSes could reuse the specifics. If they do, then you need so put them in the binding. If they don't, then you do not require sub-nodes. The MFD core will ensure the sub-devices are probed and there is no requirement for the
of_nodeto be assigned.
You do see some reusable IP blocks (like the regualtors on the wm831x PMICs for example, they're repeated blocks) which can be reused but generally they have a register base as part of the binding. Personally if it's just a property or two I'd probably just put them on the root node for the device.
Quoted 19 lines · Mark Brown
Quoted 8 lines · Lee Jones
I'm not entirely sure this is what Mark was saying. I think he was complaining about the existence of the sub-nodes rather than how the MFD Core assigns their
of_node. My take is that the chip is really a single device which provides different bits of functionality. To break that functionality up and disperse the drivers into various subsystems is a Linuxisum. By providing each functional block with its own node you're describing how we do things in Linux, rather than specifying a single node for the AS3722 which would probably be the norm.Yes, that's exactly what I was thinking of.
Quoted 5 lines
Do the sub-nodes have their own properties? If so, it would be worth breaking them up as other OSes could reuse the specifics. If they do, then you need so put them in the binding. If they don't, then you do not require sub-nodes. The MFD core will ensure the sub-devices are probed and there is no requirement for the
of_nodeto be assigned.
Quoted 5 lines
You do see some reusable IP blocks (like the regualtors on the wm831x PMICs for example, they're repeated blocks) which can be reused but generally they have a register base as part of the binding. Personally if it's just a property or two I'd probably just put them on the root node for the device.
Agreed. Besides, there doesn't seem to be *any* sub-device properties defined in the binding document. So what are you trying to achieve with the child nodes?
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 19 lines · Lee Jones
Quoted 17 lines · Mark Brown
Quoted 8 lines · Lee Jones
I'm not entirely sure this is what Mark was saying. I think he was complaining about the existence of the sub-nodes rather than how the MFD Core assigns their
of_node. My take is that the chip is really a single device which provides different bits of functionality. To break that functionality up and disperse the drivers into various subsystems is a Linuxisum. By providing each functional block with its own node you're describing how we do things in Linux, rather than specifying a single node for the AS3722 which would probably be the norm.Yes, that's exactly what I was thinking of.
Quoted 5 lines
Do the sub-nodes have their own properties? If so, it would be worth breaking them up as other OSes could reuse the specifics. If they do, then you need so put them in the binding. If they don't, then you do not require sub-nodes. The MFD core will ensure the sub-devices are probed and there is no requirement for the
of_nodeto be assigned.
Quoted 9 lines
Quoted 5 lines
You do see some reusable IP blocks (like the regualtors on the wm831x PMICs for example, they're repeated blocks) which can be reused but generally they have a register base as part of the binding. Personally if it's just a property or two I'd probably just put them on the root node for the device.
Agreed. Besides, there doesn't seem to be *any* sub-device properties defined in the binding document. So what are you trying to achieve with the child nodes?
I wanted to have the DT like:
as3722 {
compatible = "ams,as3722";
reg = <0x40>;
#interrupt-controller;
.....
regulators {
ldo1-in-supply = <..>;
....
sd0 {
regulator-name = "vdd-cpu";
.....
};
sd1 {
regulator-name = "vdd-ddr";
.....
};
....
};
};And regulator driver should get the regulator node by their pdev->dev.of_node.
Currently, in most of driver, we are having the code on regulator driver to get "regulators" node from parent node which I want to avoid.
Quoted 39 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Do the sub-nodes have their own properties? If so, it would be worth breaking them up as other OSes could reuse the specifics. If they do, then you need so put them in the binding. If they don't, then you do not require sub-nodes. The MFD core will ensure the sub-devices are probed and there is no requirement for the
of_nodeto be assigned.Quoted 8 lines
Quoted 5 lines
You do see some reusable IP blocks (like the regualtors on the wm831x PMICs for example, they're repeated blocks) which can be reused but generally they have a register base as part of the binding. Personally if it's just a property or two I'd probably just put them on the root node for the device.
Agreed. Besides, there doesn't seem to be *any* sub-device properties defined in the binding document. So what are you trying to achieve with the child nodes?
I wanted to have the DT like:
as3722 { compatible = "ams,as3722"; reg = <0x40>; #interrupt-controller; ..... regulators { ldo1-in-supply = <..>; .... sd0 { regulator-name = "vdd-cpu"; ..... }; sd1 { regulator-name = "vdd-ddr"; ..... }; .... }; };
Quoted 5 lines
And regulator driver should get the regulator node by their
pdev->dev.of_node.
Currently, in most of driver, we are having the code on regulator driver to get "regulators" node from parent node which I want to avoid.
Ah, I see. Yes, I believe the regulators should have their own node, complete with a compatible string. To have each regulator listed separately in the parent node seems a little messy. Just out of interest, how many regulators are we talking about here?
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 43 lines · Lee Jones
Quoted 38 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Do the sub-nodes have their own properties? If so, it would be worth breaking them up as other OSes could reuse the specifics. If they do, then you need so put them in the binding. If they don't, then you do not require sub-nodes. The MFD core will ensure the sub-devices are probed and there is no requirement for the
of_nodeto be assigned.Quoted 8 lines
Quoted 5 lines
You do see some reusable IP blocks (like the regualtors on the wm831x PMICs for example, they're repeated blocks) which can be reused but generally they have a register base as part of the binding. Personally if it's just a property or two I'd probably just put them on the root node for the device.
Agreed. Besides, there doesn't seem to be *any* sub-device properties defined in the binding document. So what are you trying to achieve with the child nodes?
I wanted to have the DT like:
as3722 { compatible = "ams,as3722"; reg = <0x40>; #interrupt-controller; ..... regulators { ldo1-in-supply = <..>; .... sd0 { regulator-name = "vdd-cpu"; ..... }; sd1 { regulator-name = "vdd-ddr"; ..... }; .... }; };Quoted 5 lines
And regulator driver should get the regulator node by their
pdev->dev.of_node.
Currently, in most of driver, we are having the code on regulator driver to get "regulators" node from parent node which I want to avoid.
Quoted 5 lines
Ah, I see. Yes, I believe the regulators should have their own node, complete with a compatible string. To have each regulator listed separately in the parent node seems a little messy. Just out of interest, how many regulators are we talking about here?
There is 7 DCDC step down and 10 LDOs.
It is more readable if sub-module properties are grouped and defined on different sub-node in place of having this in single parent node.
Quoted 39 lines · Lee Jones
Quoted 39 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Do the sub-nodes have their own properties? If so, it would be worth breaking them up as other OSes could reuse the specifics. If they do, then you need so put them in the binding. If they don't, then you do not require sub-nodes. The MFD core will ensure the sub-devices are probed and there is no requirement for the
of_nodeto be assigned.Quoted 8 lines
Quoted 5 lines
You do see some reusable IP blocks (like the regualtors on the wm831x PMICs for example, they're repeated blocks) which can be reused but generally they have a register base as part of the binding. Personally if it's just a property or two I'd probably just put them on the root node for the device.
Agreed. Besides, there doesn't seem to be *any* sub-device properties defined in the binding document. So what are you trying to achieve with the child nodes?
I wanted to have the DT like:
as3722 { compatible = "ams,as3722"; reg = <0x40>; #interrupt-controller; ..... regulators { ldo1-in-supply = <..>; .... sd0 { regulator-name = "vdd-cpu"; ..... }; sd1 { regulator-name = "vdd-ddr"; ..... }; .... }; };
Quoted 7 lines
Quoted 5 lines
And regulator driver should get the regulator node by their
pdev->dev.of_node.
Currently, in most of driver, we are having the code on regulator driver to get "regulators" node from parent node which I want to avoid.Ah, I see. Yes, I believe the regulators should have their own node,
The use of a "regulators" node to keep all the regulator configuration in one place seems fine...
Quoted 1 line
complete with a compatible string.
... but I see not reason why that node has to have a separate compatible property, or /has/ to have a separate driver.
I think having a compatible value in this node would only be required if the HW block that implements those registers is actually expected to be shared between n different chips, and hence it's likely that you'd get re-use out of a separate binding, driver, etc.
It's perfectly reasonable for the regulator MFD driver to know that the binding for the top-level PMIC node has a regulators child node, and go find it by name, and read whatever properties/nodes it needs directly out of it. Writing code that way in no ways implies a need for a compatible value.
Quoted 3 lines
To have each regulator listed
separately in the parent node seems a little messy. Just out of interest, how many regulators are we talking about here?
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 21 lines
Quoted 7 lines
Quoted 5 lines
And regulator driver should get the regulator node by their
pdev->dev.of_node.
Currently, in most of driver, we are having the code on regulator driver to get "regulators" node from parent node which I want to avoid.Ah, I see. Yes, I believe the regulators should have their own node,
The use of a "regulators" node to keep all the regulator configuration in one place seems fine...
Quoted 1 line
complete with a compatible string.
... but I see not reason why that node has to have a separate compatible property, or /has/ to have a separate driver.
I think having a compatible value in this node would only be required if the HW block that implements those registers is actually expected to be shared between n different chips, and hence it's likely that you'd get re-use out of a separate binding, driver, etc.
Quoted 5 lines
It's perfectly reasonable for the regulator MFD driver to know that the binding for the top-level PMIC node has a regulators child node, and go find it by name, and read whatever properties/nodes it needs directly out of it. Writing code that way in no ways implies a need for a compatible value.
Sounds fine.
Quoted 3 lines
Quoted 3 lines
To have each regulator listed
separately in the parent node seems a little messy. Just out of interest, how many regulators are we talking about here?
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 10 lines · Laxman Dewangan
Documentation/devicetree/bindings/mfd/mfd-core.txt +8
-0+MFD DT binding document +----------------------- + +Multi Function Devices (MFDs) have multiple sub module whose driver is developed +in different sub-system like GPIO, regulators, RTC, clock etc. The device +tree of such device contains multiple sub-node which contains the properties +of these sub-modules. +The sub modules get of_node handle either by the dev->of_node or by getting
Documentation/devicetree/bindings/mfd/mfd-core.txt line 18
Quoted 10 lines
Documentation/devicetree/bindings/mfd/mfd-core.txt +10
-0+the child node handle from parent DT handle by finding child name on parent's +of_node. +To provide the of_node of sub-module directly, there is two approach: +- Add compatible value when defining the sub-module in mfd core and + add this properties when adding DT. +- Add the of_node_name when defining the sub-module in mfd core and + add keep same name of child node when adding DT. + +If none of above matches then sub-module driver will not get their of_node +and they need to derive the method to get their node from parent node.
That's all *far* too specific to Linux's internals for a DT binding document.
I think it's fine for DT bindings for aggregate devices to be written to require a separate node (with a specific name) for various sub-components of the HW, if it makes sense to do so from a purely DT binding perspective. However, the fact that some DT bindings might be written that way implies nothing about any other particular DT binding, nor about all other DT bindings.
And indeed if you find that there are a bunch of DT bindings that share this structure, by all means create some common code to simplify the drivers for those bindings. However, that still doesn't mean that every driver or binding has to be structured like that.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html