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

2020-05-28 Thread Bjorn Andersson
On Thu 28 May 08:46 PDT 2020, Sumit Semwal wrote:

> 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 
> 
> --
> 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.
> 
> ---
>  drivers/regulator/Kconfig |  10 +
>  drivers/regulator/Makefile|   1 +
>  drivers/regulator/qcom-labibb-regulator.c | 224 ++
>  3 files changed, 235 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 ..634d08461c6e
> --- /dev/null
> +++ b/drivers/regulator/qcom-labibb-regulator.c
> @@ -0,0 +1,225 @@
> +// 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_TYPE0x24
> +#define QCOM_IBB_TYPE0x20
> +
> +#define REG_LABIBB_STATUS1   0x08
> +#define REG_LABIBB_ENABLE_CTL0x46
> +#define LABIBB_STATUS1_VREG_OK_BIT   BIT(7)
> +#define LABIBB_CONTROL_ENABLEBIT(7)
> +
> +#define LAB_ENABLE_CTL_MASK  BIT(7)
> +#define IBB_ENABLE_CTL_MASK  (BIT(7) | BIT(6))
> +
> +#define LABIBB_ENABLE_TIME   1000
> +#define LAB_POLL_ENABLED_TIME(LABIBB_ENABLE_TIME * 2)
> +#define IBB_POLL_ENABLED_TIME(LABIBB_ENABLE_TIME * 10)
> +#define LABIBB_OFF_ON_DELAY  (8200)
> +
> +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 intpoll_enabled_time;
> +};
> +
> +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, &val);
> + 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)
> +{
> + int ret;
> + struct labibb_regulator *reg = rdev_get_drvdata(rdev);
> +
> + ret = regulator_enable_regmap(rdev);
> + if (ret < 0)
> +

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

2020-05-28 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 

--
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.

---
 drivers/regulator/Kconfig |  10 +
 drivers/regulator/Makefile|   1 +
 drivers/regulator/qcom-labibb-regulator.c | 224 ++
 3 files changed, 235 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 ..634d08461c6e
--- /dev/null
+++ b/drivers/regulator/qcom-labibb-regulator.c
@@ -0,0 +1,225 @@
+// 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_ENABLE_TIME 1000
+#define LAB_POLL_ENABLED_TIME  (LABIBB_ENABLE_TIME * 2)
+#define IBB_POLL_ENABLED_TIME  (LABIBB_ENABLE_TIME * 10)
+#define LABIBB_OFF_ON_DELAY(8200)
+
+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 intpoll_enabled_time;
+};
+
+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, &val);
+   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)
+{
+   int ret;
+   struct labibb_regulator *reg = rdev_get_drvdata(rdev);
+
+   ret = regulator_enable_regmap(rdev);
+   if (ret < 0)
+   dev_err(reg->dev, "Write failed: enable %s regulator\n",
+   reg->desc.name);
+
+   return ret;
+}
+
+static int qcom_labibb_regulator_disable(struct regulator_dev *rdev)
+{
+   int ret = 0;
+   struct labibb_regulator *reg = rdev_get_drvdata(rdev)