Re: [PATCH v5 3/5] regulator: sy7636a: Initial commit

2021-04-19 Thread Mark Brown
On Mon, Apr 19, 2021 at 07:02:20AM +1000, Alistair Francis wrote:

>  drivers/regulator/sy7636a-regulator.c | 127 ++
>  include/linux/mfd/sy7636a.h   |   1 +

It would make merging slightly easier if you could either put the MFD
change in the MFD patch or allocate separate driver data in the
regulator driver.


signature.asc
Description: PGP signature


[PATCH v5 3/5] regulator: sy7636a: Initial commit

2021-04-19 Thread Alistair Francis
Initial support for the Silergy SY7636A-regulator Power Management chip.

Signed-off-by: Alistair Francis 
---
v5:
 - Simplify the implementation

 drivers/regulator/Kconfig |   6 ++
 drivers/regulator/Makefile|   1 +
 drivers/regulator/sy7636a-regulator.c | 127 ++
 include/linux/mfd/sy7636a.h   |   1 +
 4 files changed, 135 insertions(+)
 create mode 100644 drivers/regulator/sy7636a-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 77c43134bc9e..6d501ce921a8 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -1130,6 +1130,12 @@ config REGULATOR_STW481X_VMMC
  This driver supports the internal VMMC regulator in the STw481x
  PMIC chips.
 
+config REGULATOR_SY7636A
+   tristate "Silergy SY7636A voltage regulator"
+   depends on MFD_SY7636A
+   help
+ This driver supports Silergy SY3686A voltage regulator.
+
 config REGULATOR_SY8106A
tristate "Silergy SY8106A regulator"
depends on I2C && (OF || COMPILE_TEST)
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 44d2f8bf4b74..5a981036a9f0 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -134,6 +134,7 @@ obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
 obj-$(CONFIG_REGULATOR_STM32_PWR) += stm32-pwr.o
 obj-$(CONFIG_REGULATOR_STPMIC1) += stpmic1_regulator.o
 obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o
+obj-$(CONFIG_REGULATOR_SY7636A) += sy7636a-regulator.o
 obj-$(CONFIG_REGULATOR_SY8106A) += sy8106a-regulator.o
 obj-$(CONFIG_REGULATOR_SY8824X) += sy8824x.o
 obj-$(CONFIG_REGULATOR_SY8827N) += sy8827n.o
diff --git a/drivers/regulator/sy7636a-regulator.c 
b/drivers/regulator/sy7636a-regulator.c
new file mode 100644
index ..c384c2b6ac46
--- /dev/null
+++ b/drivers/regulator/sy7636a-regulator.c
@@ -0,0 +1,127 @@
+// SPDX-License-Identifier: GPL-2.0+
+//
+// Functions to access SY3686A power management chip voltages
+//
+// Copyright (C) 2019 reMarkable AS - http://www.remarkable.com/
+//
+// Authors: Lars Ivar Miljeteig 
+//  Alistair Francis 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SY7636A_POLL_ENABLED_TIME 500
+
+static int sy7636a_get_vcom_voltage_op(struct regulator_dev *rdev)
+{
+   int ret;
+   unsigned int val, val_h;
+
+   ret = regmap_read(rdev->regmap, SY7636A_REG_VCOM_ADJUST_CTRL_L, );
+   if (ret)
+   return ret;
+
+   ret = regmap_read(rdev->regmap, SY7636A_REG_VCOM_ADJUST_CTRL_H, _h);
+   if (ret)
+   return ret;
+
+   val |= (val_h << VCOM_ADJUST_CTRL_SHIFT);
+
+   return (val & VCOM_ADJUST_CTRL_MASK) * VCOM_ADJUST_CTRL_SCAL;
+}
+
+static int sy7636a_get_status(struct regulator_dev *rdev)
+{
+   struct sy7636a *sy7636a = dev_get_drvdata(rdev->dev.parent);
+   int ret = 0;
+
+   ret = gpiod_get_value_cansleep(sy7636a->pgood_gpio);
+   if (ret < 0)
+   dev_err(>dev, "Failed to read pgood gpio: %d\n", ret);
+
+   return ret;
+}
+
+static const struct regulator_ops sy7636a_vcom_volt_ops = {
+   .get_voltage = sy7636a_get_vcom_voltage_op,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+   .get_status = sy7636a_get_status,
+};
+
+struct regulator_desc desc = {
+   .name = "vcom",
+   .id = 0,
+   .ops = _vcom_volt_ops,
+   .type = REGULATOR_VOLTAGE,
+   .owner = THIS_MODULE,
+   .enable_reg = SY7636A_REG_OPERATION_MODE_CRL,
+   .enable_mask = SY7636A_OPERATION_MODE_CRL_ONOFF,
+   .poll_enabled_time  = SY7636A_POLL_ENABLED_TIME,
+   .regulators_node = of_match_ptr("regulators"),
+   .of_match = of_match_ptr("vcom"),
+};
+
+static int sy7636a_regulator_probe(struct platform_device *pdev)
+{
+   struct sy7636a *sy7636a = dev_get_drvdata(pdev->dev.parent);
+   struct regulator_config config = { };
+   struct regulator_dev *rdev;
+   struct gpio_desc *gdp;
+   int ret;
+
+   if (!sy7636a)
+   return -EPROBE_DEFER;
+
+   platform_set_drvdata(pdev, sy7636a);
+
+   gdp = devm_gpiod_get(sy7636a->dev, "epd-pwr-good", GPIOD_IN);
+   if (IS_ERR(gdp)) {
+   dev_err(sy7636a->dev, "Power good GPIO fault %ld\n", 
PTR_ERR(gdp));
+   return PTR_ERR(gdp);
+   }
+
+   sy7636a->pgood_gpio = gdp;
+
+   ret = regmap_write(sy7636a->regmap, SY7636A_REG_POWER_ON_DELAY_TIME, 
0x0);
+   if (ret) {
+   dev_err(sy7636a->dev, "Failed to initialize regulator: %d\n", 
ret);
+   return ret;
+   }
+
+   config.dev = >dev;
+   config.dev->of_node = sy7636a->dev->of_node;
+   config.driver_data = sy7636a;
+   config.regmap = sy7636a->regmap;
+
+   rdev = devm_regulator_register(>dev, , );
+   if (IS_ERR(rdev)) {
+   dev_err(sy7636a->dev,