Re: [PATCH v2 3/3] regulator: mcp16502: add regulator driver for MCP16502

2018-11-27 Thread kbuild test robot
Hi Andrei.Stefanescu,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on regulator/for-next]
[also build test WARNING on v4.20-rc4 next-20181127]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Andrei-Stefanescu-microchip-com/add-support-for-MCP16502-PMIC/20181128-041809
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git 
for-next


coccinelle warnings: (new ones prefixed by >>)

>> drivers/regulator/mcp16502.c:530:3-8: No need to set .owner here. The core 
>> will do it.

Please review and possibly fold the followup patch.

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


Re: [PATCH v2 3/3] regulator: mcp16502: add regulator driver for MCP16502

2018-11-27 Thread kbuild test robot
Hi Andrei.Stefanescu,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on regulator/for-next]
[also build test ERROR on v4.20-rc4 next-20181127]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Andrei-Stefanescu-microchip-com/add-support-for-MCP16502-PMIC/20181128-041809
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git 
for-next
config: sh-allyesconfig (attached as .config)
compiler: sh4-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=sh 

All error/warnings (new ones prefixed by >>):

   drivers//regulator/mcp16502.c: In function 'mcp16502_suspend_get_target_reg':
>> drivers//regulator/mcp16502.c:273:10: error: 'pm_suspend_target_state' 
>> undeclared (first use in this function); did you mean 'pm_suspended_storage'?
 switch (pm_suspend_target_state) {
 ^~~
 pm_suspended_storage
   drivers//regulator/mcp16502.c:273:10: note: each undeclared identifier is 
reported only once for each function it appears in
   drivers//regulator/mcp16502.c: In function 'mcp16502_set_suspend_mode':
   drivers//regulator/mcp16502.c:310:10: error: 'pm_suspend_target_state' 
undeclared (first use in this function); did you mean 'pm_suspended_storage'?
 switch (pm_suspend_target_state) {
 ^~~
 pm_suspended_storage
   drivers//regulator/mcp16502.c: In function 'mcp16502_suspend_get_target_reg':
>> drivers//regulator/mcp16502.c:284:1: warning: control reaches end of 
>> non-void function [-Wreturn-type]
}
^
   drivers//regulator/mcp16502.c: In function 'mcp16502_set_suspend_mode':
   drivers//regulator/mcp16502.c:321:1: warning: control reaches end of 
non-void function [-Wreturn-type]
}
^

vim +273 drivers//regulator/mcp16502.c

   266  
   267  /*
   268   * mcp16502_suspend_get_target_reg() - get the reg of the target 
suspend PMIC
   269   * mode
   270   */
   271  static int mcp16502_suspend_get_target_reg(struct regulator_dev *rdev)
   272  {
 > 273  switch (pm_suspend_target_state) {
   274  case PM_SUSPEND_STANDBY:
   275  return mcp16502_get_reg(rdev, MCP16502_OPMODE_LPM);
   276  case PM_SUSPEND_ON:
   277  case PM_SUSPEND_MEM:
   278  return mcp16502_get_reg(rdev, MCP16502_OPMODE_HIB);
   279  default:
   280  dev_err(&rdev->dev, "invalid suspend target: %d\n",
   281  pm_suspend_target_state);
   282  return -EINVAL;
   283  }
 > 284  }
   285  

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


[PATCH v2 3/3] regulator: mcp16502: add regulator driver for MCP16502

2018-11-27 Thread Andrei.Stefanescu
This patch adds a regulator driver for the MCP16502 PMIC.
This drivers supports basic operations through the
regulator interface such as:
- setting/reading voltage
- setting/reading operating mode
- reading current status
- transitioning to/from suspend-to-ram and standby
  power states

Signed-off-by: Andrei Stefanescu 
---
 drivers/regulator/Kconfig|   9 +
 drivers/regulator/Makefile   |   1 +
 drivers/regulator/mcp16502.c | 542 +++
 3 files changed, 552 insertions(+)
 create mode 100644 drivers/regulator/mcp16502.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 926cee0..719d9d6 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -567,6 +567,15 @@ config REGULATOR_MC13892
  Say y here to support the regulators found on the Freescale MC13892
  PMIC.
 
+config REGULATOR_MCP16502
+   tristate "Microchip MCP16502 PMIC"
+   depends on I2C && OF
+   help
+ Say y here to support the MCP16502 PMIC. This driver supports
+ basic operations (get/set voltage, get/set operating mode)
+ through the regulator interface. In addition it enables
+ suspend-to-ram/standby transition.
+
 config REGULATOR_MT6311
tristate "MediaTek MT6311 PMIC"
depends on I2C
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 72488ef..b12e1c9 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -74,6 +74,7 @@ obj-$(CONFIG_REGULATOR_MAX77802) += max77802-regulator.o
 obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
 obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
 obj-$(CONFIG_REGULATOR_MC13XXX_CORE) +=  mc13xxx-regulator-core.o
+obj-$(CONFIG_REGULATOR_MCP16502) += mcp16502.o
 obj-$(CONFIG_REGULATOR_MT6311) += mt6311-regulator.o
 obj-$(CONFIG_REGULATOR_MT6323) += mt6323-regulator.o
 obj-$(CONFIG_REGULATOR_MT6380) += mt6380-regulator.o
diff --git a/drivers/regulator/mcp16502.c b/drivers/regulator/mcp16502.c
new file mode 100644
index 000..b623fb0
--- /dev/null
+++ b/drivers/regulator/mcp16502.c
@@ -0,0 +1,542 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * MCP16502 PMIC driver
+ *
+ * Copyright (C) 2018 Microchip Technology Inc. and its subsidiaries
+ *
+ * Author: Andrei Stefanescu 
+ *
+ * Inspired from tps65086-regulator.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define VDD_LOW_SEL 0x0D
+#define VDD_HIGH_SEL 0x3F
+
+#define MCP16502_FLT BIT(7)
+#define MCP16502_ENS BIT(0)
+
+/*
+ *
+ * The PMIC has four sets of registers corresponding to four power modes:
+ * Performance, Active, Low-power, Hibernate.
+ *
+ * Registers:
+ * Each regulator has a register for each power mode. To access a register
+ * for a specific regulator and mode BASE_* and OFFSET_* need to be added.
+ *
+ * Operating modes:
+ * In order for the PMIC to transition to operating modes it has to be
+ * controlled via GPIO lines called LPM and HPM.
+ *
+ * The registers are fully configurable such that you can put all regulators in
+ * a low-power state while the PMIC is in Active mode. They are supposed to be
+ * configured at startup and then simply transition to/from a global low-power
+ * state by setting the GPIO lpm pin high/low.
+ *
+ * This driver keeps the PMIC in Active mode, Low-power state is set for the
+ * regulators by enabling/disabling operating mode (FPWM or Auto PFM).
+ *
+ * The PMIC's Low-power and Hibernate modes are used during standby/suspend.
+ * To enter standby/suspend the PMIC will go to Low-power mode. From there, it
+ * will transition to Hibernate when the PWRHLD line is set to low by the MPU.
+ */
+
+/*
+ * This function is useful for iterating over all regulators and accessing 
their
+ * registers in a generic way or accessing a regulator device by its id.
+ */
+#define MCP16502_BASE(i) (((i) + 1) << 4)
+#define MCP16502_STAT_BASE(i) ((i) + 5)
+
+#define MCP16502_OFFSET_MODE_A 0
+#define MCP16502_OFFSET_MODE_LPM 1
+#define MCP16502_OFFSET_MODE_HIB 2
+
+#define MCP16502_OPMODE_ACTIVE REGULATOR_MODE_NORMAL
+#define MCP16502_OPMODE_LPM REGULATOR_MODE_IDLE
+#define MCP16502_OPMODE_HIB REGULATOR_MODE_STANDBY
+
+#define MCP16502_MODE_AUTO_PFM 0
+#define MCP16502_MODE_FPWM BIT(6)
+
+#define MCP16502_VSEL 0x3F
+#define MCP16502_EN BIT(7)
+#define MCP16502_MODE BIT(6)
+
+#define MCP16502_MIN_REG 0x0
+#define MCP16502_MAX_REG 0x65
+
+static unsigned int mcp16502_of_map_mode(unsigned int mode)
+{
+   if (mode == REGULATOR_MODE_NORMAL || mode == REGULATOR_MODE_IDLE)
+   return mode;
+
+   return REGULATOR_MODE_INVALID;
+}
+
+#define MCP16502_REGULATOR(_name, _id, _ranges, _ops)  \
+   [_id] = {   \
+   .name   = _name,\
+   .regulators_node= of_match_ptr("regulators"),   \
+   .id