diff mbox series

[v6,2/8] regulator: dt-bindings: Document max8997-pmic nodes

Message ID 20201230205139.1812366-2-timon.baetz@protonmail.com
State New
Headers show
Series [v6,1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling | expand

Commit Message

Timon Baetz Dec. 30, 2020, 8:52 p.m. UTC
Add maxim,max8997-battery and maxim,max8997-muic optional nodes.

Signed-off-by: Timon Baetz <timon.baetz@protonmail.com>
Acked-by: Krzysztof Kozlowski <krzk@kernel.org>
---
v6: No change.
v5: No change.
v4: Make extcon and charger-supply optional.
v3: Reorder patch, no change.
v2: Add patch.

 .../bindings/regulator/max8997-regulator.txt         | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Mark Brown Jan. 4, 2021, 1:51 p.m. UTC | #1
On Wed, Dec 30, 2020 at 08:52:07PM +0000, Timon Baetz wrote:

> +- charger: Node for configuring the charger driver.
> +  Required properties:
> +  - compatible: "maxim,max8997-battery"
> +  Optional properties:
> +  - extcon: extcon specifier for charging events
> +  - charger-supply: regulator node for charging current
> +
> +- muic: Node used only by extcon consumers.
> +  Required properties:
> +  - compatible: "maxim,max8997-muic"

Why do these need to appear in the DT binding?  We know these features
are there simply from knowing this is a max8997.
Krzysztof Kozlowski Jan. 4, 2021, 6:18 p.m. UTC | #2
On Mon, Jan 04, 2021 at 01:51:56PM +0000, Mark Brown wrote:
> On Wed, Dec 30, 2020 at 08:52:07PM +0000, Timon Baetz wrote:

> 

> > +- charger: Node for configuring the charger driver.

> > +  Required properties:

> > +  - compatible: "maxim,max8997-battery"

> > +  Optional properties:

> > +  - extcon: extcon specifier for charging events

> > +  - charger-supply: regulator node for charging current

> > +

> > +- muic: Node used only by extcon consumers.

> > +  Required properties:

> > +  - compatible: "maxim,max8997-muic"

> 

> Why do these need to appear in the DT binding?  We know these features

> are there simply from knowing this is a max8997.


If you refer to children nodes, then we do not know these entirely
because the features could be disabled (pins not connected).  In such
case these subnodes can be disabled and MFD framework will not
instantiate children devices.

If you mean "the properties" like extcon or charger, then indeed it's a
good question. In theory, wires still could be routed differently, e.g.
different charging regulator used as a charger.
In practice this is highly unlikely, however such DT design allows
easier hooking up of different devices and even potential re-usage of
kernel drivers (also unlikely...).

Best regards,
Krzysztof
Mark Brown Jan. 4, 2021, 6:27 p.m. UTC | #3
On Mon, Jan 04, 2021 at 07:18:25PM +0100, Krzysztof Kozlowski wrote:
> On Mon, Jan 04, 2021 at 01:51:56PM +0000, Mark Brown wrote:

> > > +- charger: Node for configuring the charger driver.
> > > +  Required properties:
> > > +  - compatible: "maxim,max8997-battery"

> > > +  Optional properties:
> > > +  - extcon: extcon specifier for charging events
> > > +  - charger-supply: regulator node for charging current

> > > +- muic: Node used only by extcon consumers.
> > > +  Required properties:
> > > +  - compatible: "maxim,max8997-muic"

> > Why do these need to appear in the DT binding?  We know these features
> > are there simply from knowing this is a max8997.

> If you refer to children nodes, then we do not know these entirely
> because the features could be disabled (pins not connected).  In such
> case these subnodes can be disabled and MFD framework will not
> instantiate children devices.

We can indicate the presence of features without adding new compatible
strings, that's just encoding the way Linux currently divides things up
into the bindings.  For example having an extcon property seems like it
should be enough to figure out if we're using extcon.
Krzysztof Kozlowski Jan. 4, 2021, 6:38 p.m. UTC | #4
On Mon, Jan 04, 2021 at 06:27:34PM +0000, Mark Brown wrote:
> On Mon, Jan 04, 2021 at 07:18:25PM +0100, Krzysztof Kozlowski wrote:

> > On Mon, Jan 04, 2021 at 01:51:56PM +0000, Mark Brown wrote:

> 

> > > > +- charger: Node for configuring the charger driver.

> > > > +  Required properties:

> > > > +  - compatible: "maxim,max8997-battery"

> 

> > > > +  Optional properties:

> > > > +  - extcon: extcon specifier for charging events

> > > > +  - charger-supply: regulator node for charging current

> 

> > > > +- muic: Node used only by extcon consumers.

> > > > +  Required properties:

> > > > +  - compatible: "maxim,max8997-muic"

> 

> > > Why do these need to appear in the DT binding?  We know these features

> > > are there simply from knowing this is a max8997.

> 

> > If you refer to children nodes, then we do not know these entirely

> > because the features could be disabled (pins not connected).  In such

> > case these subnodes can be disabled and MFD framework will not

> > instantiate children devices.

> 

> We can indicate the presence of features without adding new compatible

> strings, that's just encoding the way Linux currently divides things up

> into the bindings.  For example having an extcon property seems like it

> should be enough to figure out if we're using extcon.


It won't be enough because MFD will create device for extcon and bind
the driver. The same for the charger. We have a board where max8997 is
used only as PMIC (providing regulators) without battery and USB
connectivity.

Another point, is that this reflects the real hardware. The same as we
model entire SoC as multiple children of soc node (with their own
properties), here we represent smaller chip which also has
sub-components.

Best regards,
Krzysztof
Mark Brown Jan. 4, 2021, 9:24 p.m. UTC | #5
On Mon, Jan 04, 2021 at 07:38:21PM +0100, Krzysztof Kozlowski wrote:
> On Mon, Jan 04, 2021 at 06:27:34PM +0000, Mark Brown wrote:

> > We can indicate the presence of features without adding new compatible
> > strings, that's just encoding the way Linux currently divides things up
> > into the bindings.  For example having an extcon property seems like it
> > should be enough to figure out if we're using extcon.

> It won't be enough because MFD will create device for extcon and bind
> the driver. The same for the charger. We have a board where max8997 is
> used only as PMIC (providing regulators) without battery and USB
> connectivity.

I'm not sure I follow, sorry?  Either the core driver can parse the
bindings enough to know what children it has or (probably better) it can
instantiate the children unconditionally and then the function drivers
can figure out if they need to do anything.

> Another point, is that this reflects the real hardware. The same as we
> model entire SoC as multiple children of soc node (with their own
> properties), here we represent smaller chip which also has
> sub-components.

Components we're calling things like "extcon"...
Krzysztof Kozlowski Jan. 5, 2021, 4:55 p.m. UTC | #6
On Mon, Jan 04, 2021 at 09:24:49PM +0000, Mark Brown wrote:
> On Mon, Jan 04, 2021 at 07:38:21PM +0100, Krzysztof Kozlowski wrote:

> > On Mon, Jan 04, 2021 at 06:27:34PM +0000, Mark Brown wrote:

> 

> > > We can indicate the presence of features without adding new compatible

> > > strings, that's just encoding the way Linux currently divides things up

> > > into the bindings.  For example having an extcon property seems like it

> > > should be enough to figure out if we're using extcon.

> 

> > It won't be enough because MFD will create device for extcon and bind

> > the driver. The same for the charger. We have a board where max8997 is

> > used only as PMIC (providing regulators) without battery and USB

> > connectivity.

> 

> I'm not sure I follow, sorry?  Either the core driver can parse the

> bindings enough to know what children it has or (probably better) it can

> instantiate the children unconditionally and then the function drivers

> can figure out if they need to do anything.


Currently the MFD parent/core driver will instantiate children
unconditionally.  It would have to be adapted. With proposed bindings -
nothing to change.  MFD core already does the thing.

The point is that function drivers should not be even bound, should not
start to probe. Otherwise if they probe and fail, they will pollute the
dmesg/probe log with failure. With the failure coming from looking for
missing of_node or any other condition from parent/core driver.

> > Another point, is that this reflects the real hardware. The same as we

> > model entire SoC as multiple children of soc node (with their own

> > properties), here we represent smaller chip which also has

> > sub-components.

> 

> Components we're calling things like "extcon"...


I am rather thinking about charger, but yes, extcon as well. Either you
have USB socket (and want to use associated logic) or not.

Best regards,
Krzysztof
Timon Baetz Jan. 8, 2021, 3:16 p.m. UTC | #7
On Wed, 6 Jan 2021 14:59:31 +0000, Mark Brown wrote:
> On Tue, Jan 05, 2021 at 05:55:29PM +0100, Krzysztof Kozlowski wrote:
> > On Mon, Jan 04, 2021 at 09:24:49PM +0000, Mark Brown wrote:  
> 
> > > I'm not sure I follow, sorry?  Either the core driver can parse the
> > > bindings enough to know what children it has or (probably better) it can
> > > instantiate the children unconditionally and then the function drivers
> > > can figure out if they need to do anything.  
> 
> > Currently the MFD parent/core driver will instantiate children
> > unconditionally.  It would have to be adapted. With proposed bindings -
> > nothing to change.  MFD core already does the thing.  
> 
> We're not talking massive amounts of code here, but we are talking ABI
> for a DT update.
> 
> > The point is that function drivers should not be even bound, should not
> > start to probe. Otherwise if they probe and fail, they will pollute the
> > dmesg/probe log with failure. With the failure coming from looking for
> > missing of_node or any other condition from parent/core driver.  
> 
> There will only be an error message if one is printed, if we can do a
> definitive -ENODEV there should be no need to print an error.
> 
> > > > Another point, is that this reflects the real hardware. The same as we
> > > > model entire SoC as multiple children of soc node (with their own
> > > > properties), here we represent smaller chip which also has
> > > > sub-components.  
> 
> > > Components we're calling things like "extcon"...  
> 
> > I am rather thinking about charger, but yes, extcon as well. Either you
> > have USB socket (and want to use associated logic) or not.  
> 
> Right, I'm just saying we don't need to add new device nodes reflecting
> implementation details into the DT to do that.

I'm not sure I can contribute that much to this discussion (this is my
first proper kernel patch, also I don't really understand the argument).
FWIW I looked at other MFD devices while implementing this like max77836, 
max77693, max77650, max77843 (just to name a few). 
Assigning of_node to sub-devices using sub-nodes with compatible strings 
seemed to be a common pattern for MFD devices.
Muic needs a node to be used with extcon_get_edev_by_phandle().
Charger needs a node to reference a regulator.
Mark Brown Jan. 8, 2021, 4:16 p.m. UTC | #8
On Fri, Jan 08, 2021 at 03:16:48PM +0000, Timon Baetz wrote:

> Muic needs a node to be used with extcon_get_edev_by_phandle().

> Charger needs a node to reference a regulator.


The pattern is to use the parent device's node.
Rob Herring Jan. 11, 2021, 9:50 p.m. UTC | #9
On Wed, Dec 30, 2020 at 08:52:07PM +0000, Timon Baetz wrote:
> Add maxim,max8997-battery and maxim,max8997-muic optional nodes.
> 
> Signed-off-by: Timon Baetz <timon.baetz@protonmail.com>
> Acked-by: Krzysztof Kozlowski <krzk@kernel.org>
> ---
> v6: No change.
> v5: No change.
> v4: Make extcon and charger-supply optional.
> v3: Reorder patch, no change.
> v2: Add patch.
> 
>  .../bindings/regulator/max8997-regulator.txt         | 12 ++++++++++++
>  1 file changed, 12 insertions(+)

This exceeds my threshold of changes for please convert this to schema 
first. However, I agree with what Mark has said already, so maybe some 
of this isn't needed.

> 
> diff --git a/Documentation/devicetree/bindings/regulator/max8997-regulator.txt b/Documentation/devicetree/bindings/regulator/max8997-regulator.txt
> index 6fe825b8ac1b..faaf2bbf0272 100644
> --- a/Documentation/devicetree/bindings/regulator/max8997-regulator.txt
> +++ b/Documentation/devicetree/bindings/regulator/max8997-regulator.txt
> @@ -53,6 +53,18 @@ Additional properties required if either of the optional properties are used:
>  - max8997,pmic-buck125-dvs-gpios: GPIO specifiers for three host gpio's used
>    for dvs. The format of the gpio specifier depends in the gpio controller.
>  
> +Optional nodes:
> +- charger: Node for configuring the charger driver.
> +  Required properties:
> +  - compatible: "maxim,max8997-battery"
> +  Optional properties:
> +  - extcon: extcon specifier for charging events

Don't use 'extcon' for new bindings. Define a connector node. USB I 
suppose?

> +  - charger-supply: regulator node for charging current
> +
> +- muic: Node used only by extcon consumers.
> +  Required properties:
> +  - compatible: "maxim,max8997-muic"
> +
>  Regulators: The regulators of max8997 that have to be instantiated should be
>  included in a sub-node named 'regulators'. Regulator nodes included in this
>  sub-node should be of the format as listed below.
> -- 
> 2.25.1
> 
>
Mark Brown Jan. 15, 2021, 1:42 p.m. UTC | #10
On Fri, Jan 15, 2021 at 06:19:28AM +0000, Timon Baetz wrote:
> On Fri, 8 Jan 2021 16:16:53 +0000, Mark Brown wrote:

> > On Fri, Jan 08, 2021 at 03:16:48PM +0000, Timon Baetz wrote:


> > > Muic needs a node to be used with extcon_get_edev_by_phandle().

> > > Charger needs a node to reference a regulator.  


> > The pattern is to use the parent device's node.


> So is extcon going to be a self-reference then?


I guess, assuming you even need to look this up via the device tree.

> Just for my understanding: I can see sub-nodes for MFD all over the

> place. It is still not clear to me why sub-nodes aren't the right

> choice in this specific case?


They probably aren't the right choice for a lot of the other usages
either, there's a great tendency to just encode the specific way that
Linux currently handles things into the DT without really thinking about
what it means.
Timon Baetz Jan. 16, 2021, 8:03 a.m. UTC | #11
On Fri, 15 Jan 2021 13:42:14 +0000, Mark Brown wrote:
> On Fri, Jan 15, 2021 at 06:19:28AM +0000, Timon Baetz wrote:
> > On Fri, 8 Jan 2021 16:16:53 +0000, Mark Brown wrote:  
> > > On Fri, Jan 08, 2021 at 03:16:48PM +0000, Timon Baetz wrote:  
> 
> > > > Muic needs a node to be used with extcon_get_edev_by_phandle().
> > > > Charger needs a node to reference a regulator.    
> 
> > > The pattern is to use the parent device's node.  
> 
> > So is extcon going to be a self-reference then?  
> 
> I guess, assuming you even need to look this up via the device tree.

I could use extcon_get_extcon_dev("max8997-muic") and basically hard
code the extcon device name in the charger driver. Then I only need
charger-supply in DTS which could be added to the parent device's node.

Would that be acceptable for everyone?

Thanks,
Timon
diff mbox series

Patch

diff --git a/Documentation/devicetree/bindings/regulator/max8997-regulator.txt b/Documentation/devicetree/bindings/regulator/max8997-regulator.txt
index 6fe825b8ac1b..faaf2bbf0272 100644
--- a/Documentation/devicetree/bindings/regulator/max8997-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/max8997-regulator.txt
@@ -53,6 +53,18 @@  Additional properties required if either of the optional properties are used:
 - max8997,pmic-buck125-dvs-gpios: GPIO specifiers for three host gpio's used
   for dvs. The format of the gpio specifier depends in the gpio controller.
 
+Optional nodes:
+- charger: Node for configuring the charger driver.
+  Required properties:
+  - compatible: "maxim,max8997-battery"
+  Optional properties:
+  - extcon: extcon specifier for charging events
+  - charger-supply: regulator node for charging current
+
+- muic: Node used only by extcon consumers.
+  Required properties:
+  - compatible: "maxim,max8997-muic"
+
 Regulators: The regulators of max8997 that have to be instantiated should be
 included in a sub-node named 'regulators'. Regulator nodes included in this
 sub-node should be of the format as listed below.