Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

2020-06-17 Thread Mark Brown
On Wed, Jun 17, 2020 at 05:39:26PM +0530, Sumit Semwal wrote:
> On Wed, 17 Jun 2020 at 17:36, Mark Brown  wrote:

> > That seems...  interesting.  Are you sure the regulator has fully ramped
> > when STATUS1 starts flagging?

> On a consumer device, I am not sure I have any way of checking that,
> but if there's some way you'd like me to validate it, I'll be happy
> to.

Without any way of validating what's going on or information on the
hardware I'd be inclined to go with whatever reports more slowly for
safety.


signature.asc
Description: PGP signature


Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

2020-06-17 Thread Sumit Semwal
On Wed, 17 Jun 2020 at 17:36, Mark Brown  wrote:
>
> On Wed, Jun 17, 2020 at 05:27:12PM +0530, Sumit Semwal wrote:
> > On Wed, 17 Jun 2020 at 17:17, Mark Brown  wrote:
> > > On Wed, Jun 17, 2020 at 05:12:35PM +0530, Sumit Semwal wrote:
>
> > > > I understand from a pure regulators' correctness point of view,
> > > > ENABLE_CTL should be the one checked there, so I can change the patch
> > > > as you suggested, but there seems to be some performance penalty
> > > > there.
>
> > > I thought the goal was to have the performance penalty to ensure that
> > > the regulator had actually started?
>
> > IMHO, with the poll_enabled_time mechanism added, we would not need to
> > wait for the full enabled_time time for the regulator to get enabled,
> > but we could poll (and potentially know earlier) if the regulator is
> > enabled.
> > The performance penalty I was talking, is about how should we check if
> > the regulator is really enabled or not - via reading the STATUS1
> > register, which seems to tell the status a bit faster, or via reading
> > the ENABLE_CTL register which we also use to enable/disable the
> > regulator, but which seems to be slower in updating the status.
>
> That seems...  interesting.  Are you sure the regulator has fully ramped
> when STATUS1 starts flagging?
On a consumer device, I am not sure I have any way of checking that,
but if there's some way you'd like me to validate it, I'll be happy
to.
>
> > > > > > The WARN_ON? This was suggested by Bjorn to catch the case where the
> > > > > > DT binding for a PMIC instantiates only one of the regulators.
>
> > > > > No, this whole loop - why this whole match and get child stuff?
>
> > > > This loop mechanism is what I saw in the other qcom regulators
> > > > upstream, so thought it was an acceptable way.
> > > > For the two children nodes, do you recommend another mechanism to get
> > > > and validate both nodes?
>
> > > I don't understand what you mean by "two children nodes" here?
>
> > The two 'lab' and 'ibb' regulator nodes that are part of the labibb node.
>
> Use of_match and regulators_node like other regulator drivers.

Ok, let me see what I can do with those; we still need to flag if some
platform only instantiates one of the two lab/ibb regulators - I was
given the impression they're 'both or none' case.

Best,
Sumit.


Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

2020-06-17 Thread Mark Brown
On Wed, Jun 17, 2020 at 05:27:12PM +0530, Sumit Semwal wrote:
> On Wed, 17 Jun 2020 at 17:17, Mark Brown  wrote:
> > On Wed, Jun 17, 2020 at 05:12:35PM +0530, Sumit Semwal wrote:

> > > I understand from a pure regulators' correctness point of view,
> > > ENABLE_CTL should be the one checked there, so I can change the patch
> > > as you suggested, but there seems to be some performance penalty
> > > there.

> > I thought the goal was to have the performance penalty to ensure that
> > the regulator had actually started?

> IMHO, with the poll_enabled_time mechanism added, we would not need to
> wait for the full enabled_time time for the regulator to get enabled,
> but we could poll (and potentially know earlier) if the regulator is
> enabled.
> The performance penalty I was talking, is about how should we check if
> the regulator is really enabled or not - via reading the STATUS1
> register, which seems to tell the status a bit faster, or via reading
> the ENABLE_CTL register which we also use to enable/disable the
> regulator, but which seems to be slower in updating the status.

That seems...  interesting.  Are you sure the regulator has fully ramped
when STATUS1 starts flagging?

> > > > > The WARN_ON? This was suggested by Bjorn to catch the case where the
> > > > > DT binding for a PMIC instantiates only one of the regulators.

> > > > No, this whole loop - why this whole match and get child stuff?

> > > This loop mechanism is what I saw in the other qcom regulators
> > > upstream, so thought it was an acceptable way.
> > > For the two children nodes, do you recommend another mechanism to get
> > > and validate both nodes?

> > I don't understand what you mean by "two children nodes" here?

> The two 'lab' and 'ibb' regulator nodes that are part of the labibb node.

Use of_match and regulators_node like other regulator drivers.


signature.asc
Description: PGP signature


Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

2020-06-17 Thread Sumit Semwal
On Wed, 17 Jun 2020 at 17:17, Mark Brown  wrote:
>
> On Wed, Jun 17, 2020 at 05:12:35PM +0530, Sumit Semwal wrote:
>
> > I understand from a pure regulators' correctness point of view,
> > ENABLE_CTL should be the one checked there, so I can change the patch
> > as you suggested, but there seems to be some performance penalty
> > there.
>
> I thought the goal was to have the performance penalty to ensure that
> the regulator had actually started?
IMHO, with the poll_enabled_time mechanism added, we would not need to
wait for the full enabled_time time for the regulator to get enabled,
but we could poll (and potentially know earlier) if the regulator is
enabled.
The performance penalty I was talking, is about how should we check if
the regulator is really enabled or not - via reading the STATUS1
register, which seems to tell the status a bit faster, or via reading
the ENABLE_CTL register which we also use to enable/disable the
regulator, but which seems to be slower in updating the status.

>
> > > > The WARN_ON? This was suggested by Bjorn to catch the case where the
> > > > DT binding for a PMIC instantiates only one of the regulators.
>
> > > No, this whole loop - why this whole match and get child stuff?
>
> > This loop mechanism is what I saw in the other qcom regulators
> > upstream, so thought it was an acceptable way.
> > For the two children nodes, do you recommend another mechanism to get
> > and validate both nodes?
>
> I don't understand what you mean by "two children nodes" here?
The two 'lab' and 'ibb' regulator nodes that are part of the labibb node.

Best,
Sumit.


Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

2020-06-17 Thread Mark Brown
On Wed, Jun 17, 2020 at 05:12:35PM +0530, Sumit Semwal wrote:

> I understand from a pure regulators' correctness point of view,
> ENABLE_CTL should be the one checked there, so I can change the patch
> as you suggested, but there seems to be some performance penalty
> there.

I thought the goal was to have the performance penalty to ensure that
the regulator had actually started?

> > > The WARN_ON? This was suggested by Bjorn to catch the case where the
> > > DT binding for a PMIC instantiates only one of the regulators.

> > No, this whole loop - why this whole match and get child stuff?

> This loop mechanism is what I saw in the other qcom regulators
> upstream, so thought it was an acceptable way.
> For the two children nodes, do you recommend another mechanism to get
> and validate both nodes?

I don't understand what you mean by "two children nodes" here?


signature.asc
Description: PGP signature


Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

2020-06-17 Thread Sumit Semwal
Hello Mark,

On Tue, 2 Jun 2020 at 17:55, Mark Brown  wrote:
>
> On Tue, Jun 02, 2020 at 05:40:45PM +0530, Sumit Semwal wrote:
> > On Tue, 2 Jun 2020 at 17:02, Mark Brown  wrote:
> > > On Tue, Jun 02, 2020 at 03:39:23PM +0530, Sumit Semwal wrote:
>
> > > This should be a get_status() callback...
>
> > From my (limited) understanding of downstream code, it seemed like for
> > this set of regulators, the 'enabled' check is done via the
> > 'REG_LABIBB_STATUS1 reg; for some reason, not via the same enable_reg
> > / enable_mask ones.  That's why I used it as is_enabled() callback.
> > I will try and check with the QC folks to clarify this point about
> > their hardware.
>
> The way this is functioning at the minute the downstream code is just
> buggy.

Apologies for the delay in responding - I pinged the QC folks, and was
waiting for their reply but haven't got any response so far.

I tried your suggestion to use the ENABLE_CTL register for checking if
the regulator is actually enabled. In my limited testing on the Poco,
it seems like the STATUS1 register updates faster than the ENABLE_CTL
register, so on the device, I see noticeable lag when I use ENABLE_CTL
for is_enabled() check. [This is especially true for the IBB, which
takes longer to become usable than the LAB regulator.]

I understand from a pure regulators' correctness point of view,
ENABLE_CTL should be the one checked there, so I can change the patch
as you suggested, but there seems to be some performance penalty
there.

>
> > > ...is_enabled() should just be regulator_is_enabled_regmap() and these
> > > functions should just be removed entirely, you can use the regmap
> > > operations directly as the ops without the wrapper.
>
> > The 2 wrappers are a precursor to the next patch, where we keep track
> > of regulator's enable status to check during SC handling.
>
> Add the functions when they're useful, not before.  TBH if the register
> is write only you're probably better off adding a register cache.

Agreed, I will remove the wrappers from here, using the regmap
functions, and add the wrappers with the SC handling patch.
>
> > > > + match = of_match_device(qcom_labibb_match, >dev);
> > > > + if (!match)
> > > > + return -ENODEV;
> > > > +
> > > > + for (reg_data = match->data; reg_data->name; reg_data++) {
> > > > + child = of_get_child_by_name(pdev->dev.of_node, 
> > > > reg_data->name);
> > > > +
> > > > + if (WARN_ON(child == NULL))
> > > > + return -EINVAL;
> > >
> > > This feels like the DT bindings are confused - why do we need to search
> > > like this?
>
> > The WARN_ON? This was suggested by Bjorn to catch the case where the
> > DT binding for a PMIC instantiates only one of the regulators.
>
> No, this whole loop - why this whole match and get child stuff?
This loop mechanism is what I saw in the other qcom regulators
upstream, so thought it was an acceptable way.
For the two children nodes, do you recommend another mechanism to get
and validate both nodes?

Best,
Sumit.


Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

2020-06-02 Thread Mark Brown
On Tue, Jun 02, 2020 at 05:40:45PM +0530, Sumit Semwal wrote:
> On Tue, 2 Jun 2020 at 17:02, Mark Brown  wrote:
> > On Tue, Jun 02, 2020 at 03:39:23PM +0530, Sumit Semwal wrote:

> > This should be a get_status() callback...

> From my (limited) understanding of downstream code, it seemed like for
> this set of regulators, the 'enabled' check is done via the
> 'REG_LABIBB_STATUS1 reg; for some reason, not via the same enable_reg
> / enable_mask ones.  That's why I used it as is_enabled() callback.
> I will try and check with the QC folks to clarify this point about
> their hardware.

The way this is functioning at the minute the downstream code is just
buggy.

> > ...is_enabled() should just be regulator_is_enabled_regmap() and these
> > functions should just be removed entirely, you can use the regmap
> > operations directly as the ops without the wrapper.

> The 2 wrappers are a precursor to the next patch, where we keep track
> of regulator's enable status to check during SC handling.

Add the functions when they're useful, not before.  TBH if the register
is write only you're probably better off adding a register cache.

> > > + match = of_match_device(qcom_labibb_match, >dev);
> > > + if (!match)
> > > + return -ENODEV;
> > > +
> > > + for (reg_data = match->data; reg_data->name; reg_data++) {
> > > + child = of_get_child_by_name(pdev->dev.of_node, 
> > > reg_data->name);
> > > +
> > > + if (WARN_ON(child == NULL))
> > > + return -EINVAL;
> >
> > This feels like the DT bindings are confused - why do we need to search
> > like this?

> The WARN_ON? This was suggested by Bjorn to catch the case where the
> DT binding for a PMIC instantiates only one of the regulators.

No, this whole loop - why this whole match and get child stuff?


signature.asc
Description: PGP signature


Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

2020-06-02 Thread Sumit Semwal
Hi Mark,

Thank you very much for reviewing.


On Tue, 2 Jun 2020 at 17:02, Mark Brown  wrote:
>
> On Tue, Jun 02, 2020 at 03:39:23PM +0530, Sumit Semwal wrote:
>
> > +static int qcom_labibb_regulator_is_enabled(struct regulator_dev *rdev)
> > +{
> > + int ret;
> > + unsigned int val;
> > + struct labibb_regulator *reg = rdev_get_drvdata(rdev);
> > +
> > + ret = regmap_read(reg->regmap, reg->base + REG_LABIBB_STATUS1, );
> > + if (ret < 0) {
> > + dev_err(reg->dev, "Read register failed ret = %d\n", ret);
> > + return ret;
> > + }
> > + return !!(val & LABIBB_STATUS1_VREG_OK_BIT);
> > +}
>
> This should be a get_status() callback...
>
>From my (limited) understanding of downstream code, it seemed like for
this set of regulators, the 'enabled' check is done via the
'REG_LABIBB_STATUS1 reg; for some reason, not via the same enable_reg
/ enable_mask ones.  That's why I used it as is_enabled() callback.
I will try and check with the QC folks to clarify this point about
their hardware.

> > +static int qcom_labibb_regulator_enable(struct regulator_dev *rdev)
> > +{
> > + return regulator_enable_regmap(rdev);
> > +}
> > +
> > +static int qcom_labibb_regulator_disable(struct regulator_dev *rdev)
> > +{
> > + return regulator_disable_regmap(rdev);
> > +}
>
> ...is_enabled() should just be regulator_is_enabled_regmap() and these
> functions should just be removed entirely, you can use the regmap
> operations directly as the ops without the wrapper.

The 2 wrappers are a precursor to the next patch, where we keep track
of regulator's enable status to check during SC handling.
>
> > + match = of_match_device(qcom_labibb_match, >dev);
> > + if (!match)
> > + return -ENODEV;
> > +
> > + for (reg_data = match->data; reg_data->name; reg_data++) {
> > + child = of_get_child_by_name(pdev->dev.of_node, 
> > reg_data->name);
> > +
> > + if (WARN_ON(child == NULL))
> > + return -EINVAL;
>
> This feels like the DT bindings are confused - why do we need to search
> like this?
The WARN_ON? This was suggested by Bjorn to catch the case where the
DT binding for a PMIC instantiates only one of the regulators.
>
> > + dev_info(dev, "Registering %s regulator\n", child->full_name);
>
> This is noise, remove it.  The regulator framework will announce new
> regulators anyway.
Agreed. will remove in the next iteration.

Best,
Sumit.


Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

2020-06-02 Thread Mark Brown
On Tue, Jun 02, 2020 at 03:39:23PM +0530, Sumit Semwal wrote:

> +static int qcom_labibb_regulator_is_enabled(struct regulator_dev *rdev)
> +{
> + int ret;
> + unsigned int val;
> + struct labibb_regulator *reg = rdev_get_drvdata(rdev);
> +
> + ret = regmap_read(reg->regmap, reg->base + REG_LABIBB_STATUS1, );
> + if (ret < 0) {
> + dev_err(reg->dev, "Read register failed ret = %d\n", ret);
> + return ret;
> + }
> + return !!(val & LABIBB_STATUS1_VREG_OK_BIT);
> +}

This should be a get_status() callback...

> +static int qcom_labibb_regulator_enable(struct regulator_dev *rdev)
> +{
> + return regulator_enable_regmap(rdev);
> +}
> +
> +static int qcom_labibb_regulator_disable(struct regulator_dev *rdev)
> +{
> + return regulator_disable_regmap(rdev);
> +}

...is_enabled() should just be regulator_is_enabled_regmap() and these
functions should just be removed entirely, you can use the regmap
operations directly as the ops without the wrapper.

> + match = of_match_device(qcom_labibb_match, >dev);
> + if (!match)
> + return -ENODEV;
> +
> + for (reg_data = match->data; reg_data->name; reg_data++) {
> + child = of_get_child_by_name(pdev->dev.of_node, reg_data->name);
> +
> + if (WARN_ON(child == NULL))
> + return -EINVAL;

This feels like the DT bindings are confused - why do we need to search
like this?

> + dev_info(dev, "Registering %s regulator\n", child->full_name);

This is noise, remove it.  The regulator framework will announce new
regulators anyway.


signature.asc
Description: PGP signature


[PATCH v4 4/5] regulator: qcom: Add labibb driver

2020-06-02 Thread Sumit Semwal
From: Nisha Kumari 

Qualcomm platforms have LAB(LCD AMOLED Boost)/IBB(Inverting Buck Boost)
regulators, labibb for short, which are used as power supply for
LCD Mode displays.

This patch adds labibb regulator driver for pmi8998 PMIC, found on
SDM845 platforms.

Signed-off-by: Nisha Kumari 
Signed-off-by: Sumit Semwal 
  [sumits: reworked to driver for more common code, using core regulator
features, and using newly-added poll_enabled_time functionality
from core]
--
v2: sumits: reworked the driver for more common code, and addressed
 review comments from v1
v3: sumits: addressed review comments from v2; moved to use core
 regulator features like enable_time, off_on_delay, and the newly
 added poll_enabled_time. Moved the check_enabled functionality
 to core framework via poll_enabled_time.
v4: sumits: address review comments from v3, including cleaning up
 register_labibb_regulator(), and adapted to updated meaning of
 poll_enabled_time.

---
 drivers/regulator/Kconfig |  10 ++
 drivers/regulator/Makefile|   1 +
 drivers/regulator/qcom-labibb-regulator.c | 193 ++
 3 files changed, 204 insertions(+)
 create mode 100644 drivers/regulator/qcom-labibb-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index f4b72cb098ef..58704a9fd05d 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -1167,5 +1167,15 @@ config REGULATOR_WM8994
  This driver provides support for the voltage regulators on the
  WM8994 CODEC.
 
+config REGULATOR_QCOM_LABIBB
+   tristate "QCOM LAB/IBB regulator support"
+   depends on SPMI || COMPILE_TEST
+   help
+ This driver supports Qualcomm's LAB/IBB regulators present on the
+ Qualcomm's PMIC chip pmi8998. QCOM LAB and IBB are SPMI
+ based PMIC implementations. LAB can be used as positive
+ boost regulator and IBB can be used as a negative boost regulator
+ for LCD display panel.
+
 endif
 
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 6610ee001d9a..5b313786c0e8 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -87,6 +87,7 @@ obj-$(CONFIG_REGULATOR_MT6323)+= mt6323-regulator.o
 obj-$(CONFIG_REGULATOR_MT6358) += mt6358-regulator.o
 obj-$(CONFIG_REGULATOR_MT6380) += mt6380-regulator.o
 obj-$(CONFIG_REGULATOR_MT6397) += mt6397-regulator.o
+obj-$(CONFIG_REGULATOR_QCOM_LABIBB) += qcom-labibb-regulator.o
 obj-$(CONFIG_REGULATOR_QCOM_RPM) += qcom_rpm-regulator.o
 obj-$(CONFIG_REGULATOR_QCOM_RPMH) += qcom-rpmh-regulator.o
 obj-$(CONFIG_REGULATOR_QCOM_SMD_RPM) += qcom_smd-regulator.o
diff --git a/drivers/regulator/qcom-labibb-regulator.c 
b/drivers/regulator/qcom-labibb-regulator.c
new file mode 100644
index ..33b764ac69d1
--- /dev/null
+++ b/drivers/regulator/qcom-labibb-regulator.c
@@ -0,0 +1,194 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright (c) 2020, The Linux Foundation. All rights reserved.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define REG_PERPH_TYPE  0x04
+#define QCOM_LAB_TYPE  0x24
+#define QCOM_IBB_TYPE  0x20
+
+#define REG_LABIBB_STATUS1 0x08
+#define REG_LABIBB_ENABLE_CTL  0x46
+#define LABIBB_STATUS1_VREG_OK_BIT BIT(7)
+#define LABIBB_CONTROL_ENABLE  BIT(7)
+
+#define LAB_ENABLE_CTL_MASKBIT(7)
+#define IBB_ENABLE_CTL_MASK(BIT(7) | BIT(6))
+
+#define LABIBB_OFF_ON_DELAY1000
+#define LAB_ENABLE_TIME(LABIBB_OFF_ON_DELAY * 2)
+#define IBB_ENABLE_TIME(LABIBB_OFF_ON_DELAY * 10)
+#define LABIBB_POLL_ENABLED_TIME   1000
+
+struct labibb_regulator {
+   struct regulator_desc   desc;
+   struct device   *dev;
+   struct regmap   *regmap;
+   struct regulator_dev*rdev;
+   u16 base;
+   u8  type;
+};
+
+struct labibb_regulator_data {
+   u16 base;
+   const char  *name;
+   u8  type;
+   unsigned intenable_time;
+   unsigned intenable_mask;
+};
+
+static int qcom_labibb_regulator_is_enabled(struct regulator_dev *rdev)
+{
+   int ret;
+   unsigned int val;
+   struct labibb_regulator *reg = rdev_get_drvdata(rdev);
+
+   ret = regmap_read(reg->regmap, reg->base + REG_LABIBB_STATUS1, );
+   if (ret < 0) {
+   dev_err(reg->dev, "Read register failed ret = %d\n", ret);
+   return ret;
+   }
+   return !!(val & LABIBB_STATUS1_VREG_OK_BIT);
+}
+
+static int qcom_labibb_regulator_enable(struct regulator_dev *rdev)
+{
+   return regulator_enable_regmap(rdev);
+}
+
+static int