Re: [RFC PATCH regulator] regulator: ready_mask_table[] can be static

2019-04-16 Thread Pascal PAILLET-LME
The same patch was proposed by YueHaibing

Acked-by: Pascal Paillet 

thank you,
pascal


Le 04/15/2019 06:52 PM, kbuild test robot a écrit :
> Fixes: 6cdae8173f67 ("regulator: Add support for stm32 power regulators")
> Signed-off-by: kbuild test robot 
> ---
>   stm32-pwr.c |6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/regulator/stm32-pwr.c b/drivers/regulator/stm32-pwr.c
> index e434b26..222d593 100644
> --- a/drivers/regulator/stm32-pwr.c
> +++ b/drivers/regulator/stm32-pwr.c
> @@ -32,7 +32,7 @@ enum {
>   STM32PWR_REG_NUM_REGS
>   };
>   
> -u32 ready_mask_table[STM32PWR_REG_NUM_REGS] = {
> +static u32 ready_mask_table[STM32PWR_REG_NUM_REGS] = {
>   [PWR_REG11] = REG_1_1_RDY,
>   [PWR_REG18] = REG_1_8_RDY,
>   [PWR_USB33] = USB_3_3_RDY,
> @@ -44,7 +44,7 @@ struct stm32_pwr_reg {
>   u32 ready_mask;
>   };
>   
> -int stm32_pwr_reg_is_ready(struct regulator_dev *rdev)
> +static int stm32_pwr_reg_is_ready(struct regulator_dev *rdev)
>   {
>   struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
>   u32 val;
> @@ -54,7 +54,7 @@ int stm32_pwr_reg_is_ready(struct regulator_dev *rdev)
>   return (val & priv->ready_mask);
>   }
>   
> -int stm32_pwr_reg_is_enabled(struct regulator_dev *rdev)
> +static int stm32_pwr_reg_is_enabled(struct regulator_dev *rdev)
>   {
>   struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
>   u32 val;
>


[PATCH v2 0/2] Add support for STM32MP1 power regulators

2019-04-15 Thread Pascal PAILLET-LME
The POWER block of the STM32MP1 integrates 3 fixed regulators with a ready
status bit for each one. The goal of this patchset is to add support those
regulators.

Pascal Paillet (2):
changes in v2:
* add COMPILE_TEST switch
* do not test ready in is_enabled() callback
* remove of_regulator_match
* change author

  dt-bindings: regulator: Add stm32mp1 pwr regulators
  regulator: Add support for stm32 power regulators

 .../bindings/regulator/st,stm32mp1-pwr-reg.txt |  43 +
 drivers/regulator/Kconfig  |   7 +
 drivers/regulator/Makefile |   1 +
 drivers/regulator/stm32-pwr.c  | 190 +
 4 files changed, 241 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/regulator/st,stm32mp1-pwr-reg.txt
 create mode 100644 drivers/regulator/stm32-pwr.c

-- 
1.9.1


[PATCH v2 1/2] dt-bindings: regulator: Add stm32mp1 pwr regulators

2019-04-15 Thread Pascal PAILLET-LME
Document devicetree bindings for stm32mp1 pwr regulators.

Signed-off-by: Pascal Paillet 
---
 .../bindings/regulator/st,stm32mp1-pwr-reg.txt | 43 ++
 1 file changed, 43 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/regulator/st,stm32mp1-pwr-reg.txt

diff --git 
a/Documentation/devicetree/bindings/regulator/st,stm32mp1-pwr-reg.txt 
b/Documentation/devicetree/bindings/regulator/st,stm32mp1-pwr-reg.txt
new file mode 100644
index 000..e372dd3
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/st,stm32mp1-pwr-reg.txt
@@ -0,0 +1,43 @@
+STM32MP1 PWR Regulators
+---
+
+Available Regulators in STM32MP1 PWR block are:
+  - reg11 for regulator 1V1
+  - reg18 for regulator 1V8
+  - usb33 for the swtich USB3V3
+
+Required properties:
+- compatible: Must be "st,stm32mp1,pwr-reg"
+- list of child nodes that specify the regulator reg11, reg18 or usb33
+  initialization data for defined regulators. The definition for each of
+  these nodes is defined using the standard binding for regulators found at
+  Documentation/devicetree/bindings/regulator/regulator.txt.
+- vdd-supply: phandle to the parent supply/regulator node for vdd input
+- vdd_3v3_usbfs-supply: phandle to the parent supply/regulator node for usb33
+
+Example:
+
+pwr_regulators: pwr@50001000 {
+   compatible = "st,stm32mp1,pwr-reg";
+   reg = <0x50001000 0x10>;
+   vdd-supply = <>;
+   vdd_3v3_usbfs-supply = <_usb>;
+
+   reg11: reg11 {
+   regulator-name = "reg11";
+   regulator-min-microvolt = <110>;
+   regulator-max-microvolt = <110>;
+   };
+
+   reg18: reg18 {
+   regulator-name = "reg18";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+   };
+
+   usb33: usb33 {
+   regulator-name = "usb33";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   };
+};
-- 
1.9.1


[PATCH v2 2/2] regulator: Add support for stm32 power regulators

2019-04-15 Thread Pascal PAILLET-LME
Add support for 1V1 1V8 USB3V3 power regulators.

Signed-off-by: Pascal Paillet 
---
 drivers/regulator/Kconfig |   7 ++
 drivers/regulator/Makefile|   1 +
 drivers/regulator/stm32-pwr.c | 190 ++
 3 files changed, 198 insertions(+)
 create mode 100644 drivers/regulator/stm32-pwr.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index c4dc2bc..6c37f0d 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -840,6 +840,13 @@ config REGULATOR_STM32_VREFBUF
  This driver can also be built as a module. If so, the module
  will be called stm32-vrefbuf.
 
+config REGULATOR_STM32_PWR
+   bool "STMicroelectronics STM32 PWR"
+   depends on ARCH_STM32 || COMPILE_TEST
+   help
+ This driver supports internal regulators (1V1, 1V8, 3V3) in the
+ STMicroelectronics STM32 chips.
+
 config REGULATOR_STPMIC1
tristate "STMicroelectronics STPMIC1 PMIC Regulators"
depends on MFD_STPMIC1
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 1169f8a..93f5384 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -105,6 +105,7 @@ obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
 obj-$(CONFIG_REGULATOR_SC2731) += sc2731-regulator.o
 obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o
 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_SY8106A) += sy8106a-regulator.o
diff --git a/drivers/regulator/stm32-pwr.c b/drivers/regulator/stm32-pwr.c
new file mode 100644
index 000..e434b26
--- /dev/null
+++ b/drivers/regulator/stm32-pwr.c
@@ -0,0 +1,190 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2019
+// Authors: Gabriel Fernandez 
+//  Pascal Paillet .
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * Registers description
+ */
+#define REG_PWR_CR3 0x0C
+
+#define USB_3_3_EN BIT(24)
+#define USB_3_3_RDY BIT(26)
+#define REG_1_8_EN BIT(28)
+#define REG_1_8_RDY BIT(29)
+#define REG_1_1_EN BIT(30)
+#define REG_1_1_RDY BIT(31)
+
+/* list of supported regulators */
+enum {
+   PWR_REG11,
+   PWR_REG18,
+   PWR_USB33,
+   STM32PWR_REG_NUM_REGS
+};
+
+u32 ready_mask_table[STM32PWR_REG_NUM_REGS] = {
+   [PWR_REG11] = REG_1_1_RDY,
+   [PWR_REG18] = REG_1_8_RDY,
+   [PWR_USB33] = USB_3_3_RDY,
+};
+
+struct stm32_pwr_reg {
+   void __iomem *base;
+   const struct regulator_desc *desc;
+   u32 ready_mask;
+};
+
+int stm32_pwr_reg_is_ready(struct regulator_dev *rdev)
+{
+   struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
+   u32 val;
+
+   val = readl_relaxed(priv->base + REG_PWR_CR3);
+
+   return (val & priv->ready_mask);
+}
+
+int stm32_pwr_reg_is_enabled(struct regulator_dev *rdev)
+{
+   struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
+   u32 val;
+
+   val = readl_relaxed(priv->base + REG_PWR_CR3);
+
+   return (val & priv->desc->enable_mask);
+}
+
+static int stm32_pwr_reg_enable(struct regulator_dev *rdev)
+{
+   struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
+   int ret;
+   u32 val;
+
+   val = readl_relaxed(priv->base + REG_PWR_CR3);
+   val |= priv->desc->enable_mask;
+   writel_relaxed(val, priv->base + REG_PWR_CR3);
+
+   /* use an arbitrary timeout of 20ms */
+   ret = readx_poll_timeout(stm32_pwr_reg_is_ready, rdev, val, val,
+100, 20 * 1000);
+   if (ret)
+   dev_err(>dev, "regulator enable timed out!\n");
+
+   return ret;
+}
+
+static int stm32_pwr_reg_disable(struct regulator_dev *rdev)
+{
+   struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
+   int ret;
+   u32 val;
+
+   val = readl_relaxed(priv->base + REG_PWR_CR3);
+   val &= ~priv->desc->enable_mask;
+   writel_relaxed(val, priv->base + REG_PWR_CR3);
+
+   /* use an arbitrary timeout of 20ms */
+   ret = readx_poll_timeout(stm32_pwr_reg_is_ready, rdev, val, !val,
+100, 20 * 1000);
+   if (ret)
+   dev_err(>dev, "regulator disable timed out!\n");
+
+   return ret;
+}
+
+static const struct regulator_ops stm32_pwr_reg_ops = {
+   .list_voltage   = regulator_list_voltage_linear,
+   .enable = stm32_pwr_reg_enable,
+   .disable= stm32_pwr_reg_disable,
+   .is_enabled = stm32_pwr_reg_is_enabled,
+};
+
+#define PWR_REG(_id, _name, _volt, _en, _supply) \
+   [_id] = { \
+   .id = _id, \
+   .name = _name, \
+   .of_match = of_match_ptr(_name), \
+   .n_voltages = 1, \
+   .type = REGULATOR_VOLTAGE, \
+   .min_uV = _volt, \
+   .fixed_uV = 

[PATCH v2 2/3] ARM: dts: stm32: add stpmic1 support on stm32mp157a dk1 board

2019-04-09 Thread Pascal PAILLET-LME
This patch adds stpmic1 support on stm32mp157a dk1 board.
The STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.
The DMAs are disabled because the PMIC generates a very few traffic and
DMA channels may lack for other usage.

Signed-off-by: Pascal Paillet 
---
 arch/arm/boot/dts/stm32mp157a-dk1.dts | 158 --
 1 file changed, 150 insertions(+), 8 deletions(-)

diff --git a/arch/arm/boot/dts/stm32mp157a-dk1.dts 
b/arch/arm/boot/dts/stm32mp157a-dk1.dts
index 1b1886d..4bb91ab 100644
--- a/arch/arm/boot/dts/stm32mp157a-dk1.dts
+++ b/arch/arm/boot/dts/stm32mp157a-dk1.dts
@@ -9,6 +9,7 @@
 #include "stm32mp157c.dtsi"
 #include "stm32mp157-pinctrl.dtsi"
 #include 
+#include 
 
 / {
model = "STMicroelectronics STM32MP157A-DK1 Discovery Board";
@@ -36,14 +37,6 @@
default-state = "off";
};
};
-
-   v3v3: regulator-3v3 {
-   compatible = "regulator-fixed";
-   regulator-name = "v3v3";
-   regulator-min-microvolt = <330>;
-   regulator-max-microvolt = <330>;
-   regulator-always-on;
-   };
 };
 
  {
@@ -65,6 +58,155 @@
};
 };
 
+
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   i2c-scl-rising-time-ns = <185>;
+   i2c-scl-falling-time-ns = <20>;
+   status = "okay";
+   /* spare dmas for other usage */
+   /delete-property/dmas;
+   /delete-property/dma-names;
+
+   pmic: stpmic@33 {
+   compatible = "st,stpmic1";
+   reg = <0x33>;
+   interrupts-extended = < 0 IRQ_TYPE_EDGE_FALLING>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   status = "okay";
+
+   regulators {
+   compatible = "st,stpmic1-regulators";
+   ldo1-supply = <>;
+   ldo3-supply = <_ddr>;
+   ldo6-supply = <>;
+   pwr_sw1-supply = <_out>;
+   pwr_sw2-supply = <_out>;
+
+   vddcore: buck1 {
+   regulator-name = "vddcore";
+   regulator-min-microvolt = <80>;
+   regulator-max-microvolt = <135>;
+   regulator-always-on;
+   regulator-initial-mode = <0>;
+   regulator-over-current-protection;
+   };
+
+   vdd_ddr: buck2 {
+   regulator-name = "vdd_ddr";
+   regulator-min-microvolt = <135>;
+   regulator-max-microvolt = <135>;
+   regulator-always-on;
+   regulator-initial-mode = <0>;
+   regulator-over-current-protection;
+   };
+
+   vdd: buck3 {
+   regulator-name = "vdd";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-always-on;
+   st,mask-reset;
+   regulator-initial-mode = <0>;
+   regulator-over-current-protection;
+   };
+
+   v3v3: buck4 {
+   regulator-name = "v3v3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-always-on;
+   regulator-over-current-protection;
+   regulator-initial-mode = <0>;
+   };
+
+   v1v8_audio: ldo1 {
+   regulator-name = "v1v8_audio";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+   regulator-always-on;
+   interrupts = ;
+   };
+
+   v3v3_hdmi: ldo2 {
+   regulator-name = "v3v3_hdmi";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-always-on;
+   interrupts = ;
+   };
+
+   vtt_ddr: ldo3 {
+   regulator-name = "vtt_ddr";
+   regulator-min-microvolt = <50>;
+   regulator-max-microvolt = <75>;
+

[PATCH v2 0/3] Add support for STPMIC1

2019-04-09 Thread Pascal PAILLET-LME
Add support for STPMIC1 on:
- stm32mp157c ed1 board
- stm32mp157a dk1 board
- arm multi_v7_defconfig

Pascal Paillet (3):

changes in v2:
* Describe why we disable the DMAs for PMIC

  ARM: dts: stm32: add stpmic1 support on stm32mp157c ed1 board
  ARM: dts: stm32: add stpmic1 support on stm32mp157a dk1 board
  ARM: multi_v7_defconfig: Enable support for STPMIC1

 arch/arm/boot/dts/stm32mp157a-dk1.dts | 158 --
 arch/arm/boot/dts/stm32mp157c-ed1.dts | 156 +
 arch/arm/configs/multi_v7_defconfig   |   4 +
 3 files changed, 294 insertions(+), 24 deletions(-)

-- 
1.9.1


[PATCH v2 3/3] ARM: multi_v7_defconfig: Enable support for STPMIC1

2019-04-09 Thread Pascal PAILLET-LME
STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
---
 arch/arm/configs/multi_v7_defconfig | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/configs/multi_v7_defconfig 
b/arch/arm/configs/multi_v7_defconfig
index c75051b..2e9fa53 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -299,6 +299,7 @@ CONFIG_INPUT_MAX8997_HAPTIC=m
 CONFIG_INPUT_CPCAP_PWRBUTTON=m
 CONFIG_INPUT_AXP20X_PEK=m
 CONFIG_INPUT_ADXL34X=m
+CONFIG_INPUT_STPMIC1_ONKEY=y
 CONFIG_SERIO_AMBAKMI=y
 CONFIG_SERIAL_8250=y
 CONFIG_SERIAL_8250_CONSOLE=y
@@ -486,6 +487,7 @@ CONFIG_TEGRA_WATCHDOG=m
 CONFIG_MESON_WATCHDOG=y
 CONFIG_DIGICOLOR_WATCHDOG=y
 CONFIG_RENESAS_WDT=m
+CONFIG_STPMIC1_WATCHDOG=y
 CONFIG_BCM47XX_WDT=y
 CONFIG_BCM2835_WDT=y
 CONFIG_BCM_KONA_WDT=y
@@ -527,6 +529,7 @@ CONFIG_MFD_TPS65218=y
 CONFIG_MFD_TPS6586X=y
 CONFIG_MFD_TPS65910=y
 CONFIG_MFD_STM32_LPTIMER=m
+CONFIG_MFD_STPMIC1=y
 CONFIG_REGULATOR_ACT8865=y
 CONFIG_REGULATOR_ACT8945A=y
 CONFIG_REGULATOR_ANATOP=y
@@ -559,6 +562,7 @@ CONFIG_REGULATOR_RN5T618=y
 CONFIG_REGULATOR_S2MPS11=y
 CONFIG_REGULATOR_S5M8767=y
 CONFIG_REGULATOR_STM32_VREFBUF=m
+CONFIG_REGULATOR_STPMIC1=y
 CONFIG_REGULATOR_TI_ABB=y
 CONFIG_REGULATOR_TPS51632=y
 CONFIG_REGULATOR_TPS62360=y
-- 
1.9.1


[PATCH v2 1/3] ARM: dts: stm32: add stpmic1 support on stm32mp157c ed1 board

2019-04-09 Thread Pascal PAILLET-LME
This patch adds stpmic1 support on stm32mp157c ed1 board.
The STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.
The DMAs are disabled because the PMIC generates a very few traffic and
DMA channels may lack for other usage.

Signed-off-by: Pascal Paillet 
---
 arch/arm/boot/dts/stm32mp157c-ed1.dts | 156 ++
 1 file changed, 140 insertions(+), 16 deletions(-)

diff --git a/arch/arm/boot/dts/stm32mp157c-ed1.dts 
b/arch/arm/boot/dts/stm32mp157c-ed1.dts
index 9fd7943..62a8c78 100644
--- a/arch/arm/boot/dts/stm32mp157c-ed1.dts
+++ b/arch/arm/boot/dts/stm32mp157c-ed1.dts
@@ -8,6 +8,7 @@
 #include "stm32mp157c.dtsi"
 #include "stm32mp157-pinctrl.dtsi"
 #include 
+#include 
 
 / {
model = "STMicroelectronics STM32MP157C eval daughter";
@@ -42,22 +43,6 @@
regulator-always-on;
};
 
-   vdd_sd: regulator-vdd_sd {
-   compatible = "regulator-fixed";
-   regulator-name = "vdd_sd";
-   regulator-min-microvolt = <330>;
-   regulator-max-microvolt = <330>;
-   regulator-always-on;
-   };
-
-   vdd_usb: vdd-usb {
-   compatible = "regulator-fixed";
-   regulator-name = "vdd_usb";
-   regulator-min-microvolt = <330>;
-   regulator-max-microvolt = <330>;
-   regulator-always-on;
-   };
-
sd_switch: regulator-sd_switch {
compatible = "regulator-gpio";
regulator-name = "sd_switch";
@@ -82,6 +67,145 @@
i2c-scl-rising-time-ns = <185>;
i2c-scl-falling-time-ns = <20>;
status = "okay";
+   /* spare dmas for other usage */
+   /delete-property/dmas;
+   /delete-property/dma-names;
+
+   pmic: stpmic@33 {
+   compatible = "st,stpmic1";
+   reg = <0x33>;
+   interrupts-extended = < 0 IRQ_TYPE_EDGE_FALLING>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   status = "okay";
+
+   regulators {
+   compatible = "st,stpmic1-regulators";
+   ldo1-supply = <>;
+   ldo2-supply = <>;
+   ldo3-supply = <_ddr>;
+   ldo5-supply = <>;
+   ldo6-supply = <>;
+   pwr_sw1-supply = <_out>;
+   pwr_sw2-supply = <_out>;
+
+   vddcore: buck1 {
+   regulator-name = "vddcore";
+   regulator-min-microvolt = <80>;
+   regulator-max-microvolt = <135>;
+   regulator-always-on;
+   regulator-initial-mode = <0>;
+   regulator-over-current-protection;
+   };
+
+   vdd_ddr: buck2 {
+   regulator-name = "vdd_ddr";
+   regulator-min-microvolt = <135>;
+   regulator-max-microvolt = <135>;
+   regulator-always-on;
+   regulator-initial-mode = <0>;
+   regulator-over-current-protection;
+   };
+
+   vdd: buck3 {
+   regulator-name = "vdd";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-always-on;
+   st,mask-reset;
+   regulator-initial-mode = <0>;
+   regulator-over-current-protection;
+   };
+
+   v3v3: buck4 {
+   regulator-name = "v3v3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-always-on;
+   regulator-over-current-protection;
+   regulator-initial-mode = <0>;
+   };
+
+   vdda: ldo1 {
+   regulator-name = "vdda";
+   regulator-min-microvolt = <290>;
+   regulator-max-microvolt = <290>;
+   interrupts = ;
+   };
+
+   v2v8: ldo2 {
+   regulator-name = "v2v8";
+   regulator-min-microvolt = <280>;
+   regulator-max-microvolt = <280>;
+   interrupts = ;
+   };
+
+   

[PATCH 1/2] dt-bindings: regulator: Add stm32mp1 pwr regulators

2019-04-08 Thread Pascal PAILLET-LME
Document devicetree bindings for stm32mp1 pwr regulators.

Signed-off-by: Pascal Paillet 
---
 .../bindings/regulator/st,stm32mp1-pwr-reg.txt | 43 ++
 1 file changed, 43 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/regulator/st,stm32mp1-pwr-reg.txt

diff --git 
a/Documentation/devicetree/bindings/regulator/st,stm32mp1-pwr-reg.txt 
b/Documentation/devicetree/bindings/regulator/st,stm32mp1-pwr-reg.txt
new file mode 100644
index 000..e372dd3
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/st,stm32mp1-pwr-reg.txt
@@ -0,0 +1,43 @@
+STM32MP1 PWR Regulators
+---
+
+Available Regulators in STM32MP1 PWR block are:
+  - reg11 for regulator 1V1
+  - reg18 for regulator 1V8
+  - usb33 for the swtich USB3V3
+
+Required properties:
+- compatible: Must be "st,stm32mp1,pwr-reg"
+- list of child nodes that specify the regulator reg11, reg18 or usb33
+  initialization data for defined regulators. The definition for each of
+  these nodes is defined using the standard binding for regulators found at
+  Documentation/devicetree/bindings/regulator/regulator.txt.
+- vdd-supply: phandle to the parent supply/regulator node for vdd input
+- vdd_3v3_usbfs-supply: phandle to the parent supply/regulator node for usb33
+
+Example:
+
+pwr_regulators: pwr@50001000 {
+   compatible = "st,stm32mp1,pwr-reg";
+   reg = <0x50001000 0x10>;
+   vdd-supply = <>;
+   vdd_3v3_usbfs-supply = <_usb>;
+
+   reg11: reg11 {
+   regulator-name = "reg11";
+   regulator-min-microvolt = <110>;
+   regulator-max-microvolt = <110>;
+   };
+
+   reg18: reg18 {
+   regulator-name = "reg18";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+   };
+
+   usb33: usb33 {
+   regulator-name = "usb33";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   };
+};
-- 
1.9.1


[PATCH 0/2] Add support for STM32MP1 power regulators

2019-04-08 Thread Pascal PAILLET-LME
The POWER block of the STM32MP1 integrates 3 fixed regulators with a ready
status bit for each one. The goal of this patchset is to add support those
regulators.

Pascal Paillet (2):
  dt-bindings: regulator: Add stm32mp1 pwr regulators
  regulator: Add support for stm32 power regulators

 .../bindings/regulator/st,stm32mp1-pwr-reg.txt |  43 +
 drivers/regulator/Kconfig  |   7 +
 drivers/regulator/Makefile |   1 +
 drivers/regulator/stm32-pwr.c  | 193 +
 4 files changed, 244 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/regulator/st,stm32mp1-pwr-reg.txt
 create mode 100644 drivers/regulator/stm32-pwr.c

-- 
1.9.1


[PATCH 2/2] regulator: Add support for stm32 power regulators

2019-04-08 Thread Pascal PAILLET-LME
Add support for 1V1 1V8 USB3V3 power regulators.

Signed-off-by: Pascal Paillet 
---
 drivers/regulator/Kconfig |   7 ++
 drivers/regulator/Makefile|   1 +
 drivers/regulator/stm32-pwr.c | 193 ++
 3 files changed, 201 insertions(+)
 create mode 100644 drivers/regulator/stm32-pwr.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index c4dc2bc..26e6e26 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -840,6 +840,13 @@ config REGULATOR_STM32_VREFBUF
  This driver can also be built as a module. If so, the module
  will be called stm32-vrefbuf.
 
+config REGULATOR_STM32_PWR
+   bool "STMicroelectronics STM32 PWR"
+   depends on ARCH_STM32
+   help
+ This driver supports internal regulators (1V1, 1V8, 3V3) in the
+ STMicroelectronics STM32 chips.
+
 config REGULATOR_STPMIC1
tristate "STMicroelectronics STPMIC1 PMIC Regulators"
depends on MFD_STPMIC1
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 1169f8a..93f5384 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -105,6 +105,7 @@ obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
 obj-$(CONFIG_REGULATOR_SC2731) += sc2731-regulator.o
 obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o
 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_SY8106A) += sy8106a-regulator.o
diff --git a/drivers/regulator/stm32-pwr.c b/drivers/regulator/stm32-pwr.c
new file mode 100644
index 000..166dc44
--- /dev/null
+++ b/drivers/regulator/stm32-pwr.c
@@ -0,0 +1,193 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2019
+// Authors: Gabriel Fernandez 
+//  Pascal Paillet .
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * Registers description
+ */
+#define REG_PWR_CR3 0x0C
+
+#define USB_3_3_EN BIT(24)
+#define USB_3_3_RDY BIT(26)
+#define REG_1_8_EN BIT(28)
+#define REG_1_8_RDY BIT(29)
+#define REG_1_1_EN BIT(30)
+#define REG_1_1_RDY BIT(31)
+
+/* list of supported regulators */
+enum {
+   PWR_REG11,
+   PWR_REG18,
+   PWR_USB33,
+   STM32PWR_REG_NUM_REGS
+};
+
+u32 ready_mask_table[STM32PWR_REG_NUM_REGS] = {
+   [PWR_REG11] = REG_1_1_RDY,
+   [PWR_REG18] = REG_1_8_RDY,
+   [PWR_USB33] = USB_3_3_RDY,
+};
+
+struct stm32_pwr_reg {
+   void __iomem *base;
+   const struct regulator_desc *desc;
+   u32 ready_mask;
+};
+
+int stm32_pwr_reg_is_enabled(struct regulator_dev *rdev)
+{
+   struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
+   u32 val;
+
+   val = readl_relaxed(priv->base + REG_PWR_CR3);
+
+   return (val & priv->ready_mask);
+}
+
+static int stm32_pwr_reg_enable(struct regulator_dev *rdev)
+{
+   struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
+   int ret;
+   u32 val;
+
+   val = readl_relaxed(priv->base + REG_PWR_CR3);
+   val |= priv->desc->enable_mask;
+   writel_relaxed(val, priv->base + REG_PWR_CR3);
+
+   /* use an arbitrary timeout of 20ms */
+   ret = readx_poll_timeout(stm32_pwr_reg_is_enabled, rdev, val, val,
+100, 20 * 1000);
+   if (ret)
+   dev_err(>dev, "regulator enable timed out!\n");
+
+   return ret;
+}
+
+static int stm32_pwr_reg_disable(struct regulator_dev *rdev)
+{
+   struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
+   int ret;
+   u32 val;
+
+   val = readl_relaxed(priv->base + REG_PWR_CR3);
+   val &= ~priv->desc->enable_mask;
+   writel_relaxed(val, priv->base + REG_PWR_CR3);
+
+   /* use an arbitrary timeout of 20ms */
+   ret = readx_poll_timeout(stm32_pwr_reg_is_enabled, rdev, val, !val,
+100, 20 * 1000);
+   if (ret)
+   dev_err(>dev, "regulator disable timed out!\n");
+
+   return ret;
+}
+
+static const struct regulator_ops stm32_pwr_reg_ops = {
+   .list_voltage   = regulator_list_voltage_linear,
+   .enable = stm32_pwr_reg_enable,
+   .disable= stm32_pwr_reg_disable,
+   .is_enabled = stm32_pwr_reg_is_enabled,
+};
+
+#define PWR_REG(_id, _name, _volt, _en, _supply) \
+   [_id] = { \
+   .id = _id, \
+   .name = _name, \
+   .n_voltages = 1, \
+   .type = REGULATOR_VOLTAGE, \
+   .min_uV = _volt, \
+   .fixed_uV = _volt, \
+   .ops = _pwr_reg_ops, \
+   .enable_mask = _en, \
+   .owner = THIS_MODULE, \
+   .supply_name = _supply, \
+   } \
+
+static const struct regulator_desc stm32_pwr_desc[] = {
+   PWR_REG(PWR_REG11, "reg11", 110, REG_1_1_EN, "vdd"),
+   

Re: [PATCH 1/3] ARM: dts: stm32: add stpmic1 support on stm32mp157c ed1 board

2019-04-08 Thread Pascal PAILLET-LME
Hello!

Le 04/08/2019 02:05 PM, Linus Walleij a écrit :
> On Wed, Apr 3, 2019 at 3:41 PM Pascal PAILLET-LME  wrote:
>
>> This patch adds stpmic1 support on stm32mp157c ed1 board.
>> The STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
>> regulators, 3 power switches, a watchdog and an input for a power on key.
>>
>> Signed-off-by: Pascal Paillet 
> OK
>
>> +   /delete-property/dmas;
>> +   /delete-property/dma-names;
> Maybe you can add a comment both to the commit message and the
> DTS file as to why you are doing this?
>
> I hope you are not trying to work around a bug in the driver by
> stripping out DMA configuration from the device tree, because then
> it is probably a better idea to fix the bug.
This is not a workaround. The PMIC can use the DMA over I2C bus.
Our goal is to avoid using a DMA channel for a consumer that generates a
very few traffic. Dma channels may lack for other use cases.

If you agree, you can add the to the commit message.
> Yours,
> Linus Walleij
>

thank you,
Best Regards,
Pascal


[PATCH 2/3] ARM: dts: stm32: add stpmic1 support on stm32mp157a dk1 board

2019-04-03 Thread Pascal PAILLET-LME
This patch adds stpmic1 support on stm32mp157a dk1 board.
The STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
---
 arch/arm/boot/dts/stm32mp157a-dk1.dts | 157 --
 1 file changed, 149 insertions(+), 8 deletions(-)

diff --git a/arch/arm/boot/dts/stm32mp157a-dk1.dts 
b/arch/arm/boot/dts/stm32mp157a-dk1.dts
index 1b1886d..b25b551 100644
--- a/arch/arm/boot/dts/stm32mp157a-dk1.dts
+++ b/arch/arm/boot/dts/stm32mp157a-dk1.dts
@@ -9,6 +9,7 @@
 #include "stm32mp157c.dtsi"
 #include "stm32mp157-pinctrl.dtsi"
 #include 
+#include 
 
 / {
model = "STMicroelectronics STM32MP157A-DK1 Discovery Board";
@@ -36,14 +37,6 @@
default-state = "off";
};
};
-
-   v3v3: regulator-3v3 {
-   compatible = "regulator-fixed";
-   regulator-name = "v3v3";
-   regulator-min-microvolt = <330>;
-   regulator-max-microvolt = <330>;
-   regulator-always-on;
-   };
 };
 
  {
@@ -65,6 +58,154 @@
};
 };
 
+
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   i2c-scl-rising-time-ns = <185>;
+   i2c-scl-falling-time-ns = <20>;
+   status = "okay";
+   /delete-property/dmas;
+   /delete-property/dma-names;
+
+   pmic: stpmic@33 {
+   compatible = "st,stpmic1";
+   reg = <0x33>;
+   interrupts-extended = < 0 IRQ_TYPE_EDGE_FALLING>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   status = "okay";
+
+   regulators {
+   compatible = "st,stpmic1-regulators";
+   ldo1-supply = <>;
+   ldo3-supply = <_ddr>;
+   ldo6-supply = <>;
+   pwr_sw1-supply = <_out>;
+   pwr_sw2-supply = <_out>;
+
+   vddcore: buck1 {
+   regulator-name = "vddcore";
+   regulator-min-microvolt = <80>;
+   regulator-max-microvolt = <135>;
+   regulator-always-on;
+   regulator-initial-mode = <0>;
+   regulator-over-current-protection;
+   };
+
+   vdd_ddr: buck2 {
+   regulator-name = "vdd_ddr";
+   regulator-min-microvolt = <135>;
+   regulator-max-microvolt = <135>;
+   regulator-always-on;
+   regulator-initial-mode = <0>;
+   regulator-over-current-protection;
+   };
+
+   vdd: buck3 {
+   regulator-name = "vdd";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-always-on;
+   st,mask-reset;
+   regulator-initial-mode = <0>;
+   regulator-over-current-protection;
+   };
+
+   v3v3: buck4 {
+   regulator-name = "v3v3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-always-on;
+   regulator-over-current-protection;
+   regulator-initial-mode = <0>;
+   };
+
+   v1v8_audio: ldo1 {
+   regulator-name = "v1v8_audio";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+   regulator-always-on;
+   interrupts = ;
+   };
+
+   v3v3_hdmi: ldo2 {
+   regulator-name = "v3v3_hdmi";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-always-on;
+   interrupts = ;
+   };
+
+   vtt_ddr: ldo3 {
+   regulator-name = "vtt_ddr";
+   regulator-min-microvolt = <50>;
+   regulator-max-microvolt = <75>;
+   regulator-always-on;
+   regulator-over-current-protection;
+   };
+
+   

[PATCH 1/3] ARM: dts: stm32: add stpmic1 support on stm32mp157c ed1 board

2019-04-03 Thread Pascal PAILLET-LME
This patch adds stpmic1 support on stm32mp157c ed1 board.
The STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
---
 arch/arm/boot/dts/stm32mp157c-ed1.dts | 155 ++
 1 file changed, 139 insertions(+), 16 deletions(-)

diff --git a/arch/arm/boot/dts/stm32mp157c-ed1.dts 
b/arch/arm/boot/dts/stm32mp157c-ed1.dts
index 9fd7943..678b0f1 100644
--- a/arch/arm/boot/dts/stm32mp157c-ed1.dts
+++ b/arch/arm/boot/dts/stm32mp157c-ed1.dts
@@ -8,6 +8,7 @@
 #include "stm32mp157c.dtsi"
 #include "stm32mp157-pinctrl.dtsi"
 #include 
+#include 
 
 / {
model = "STMicroelectronics STM32MP157C eval daughter";
@@ -42,22 +43,6 @@
regulator-always-on;
};
 
-   vdd_sd: regulator-vdd_sd {
-   compatible = "regulator-fixed";
-   regulator-name = "vdd_sd";
-   regulator-min-microvolt = <330>;
-   regulator-max-microvolt = <330>;
-   regulator-always-on;
-   };
-
-   vdd_usb: vdd-usb {
-   compatible = "regulator-fixed";
-   regulator-name = "vdd_usb";
-   regulator-min-microvolt = <330>;
-   regulator-max-microvolt = <330>;
-   regulator-always-on;
-   };
-
sd_switch: regulator-sd_switch {
compatible = "regulator-gpio";
regulator-name = "sd_switch";
@@ -82,6 +67,144 @@
i2c-scl-rising-time-ns = <185>;
i2c-scl-falling-time-ns = <20>;
status = "okay";
+   /delete-property/dmas;
+   /delete-property/dma-names;
+
+   pmic: stpmic@33 {
+   compatible = "st,stpmic1";
+   reg = <0x33>;
+   interrupts-extended = < 0 IRQ_TYPE_EDGE_FALLING>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   status = "okay";
+
+   regulators {
+   compatible = "st,stpmic1-regulators";
+   ldo1-supply = <>;
+   ldo2-supply = <>;
+   ldo3-supply = <_ddr>;
+   ldo5-supply = <>;
+   ldo6-supply = <>;
+   pwr_sw1-supply = <_out>;
+   pwr_sw2-supply = <_out>;
+
+   vddcore: buck1 {
+   regulator-name = "vddcore";
+   regulator-min-microvolt = <80>;
+   regulator-max-microvolt = <135>;
+   regulator-always-on;
+   regulator-initial-mode = <0>;
+   regulator-over-current-protection;
+   };
+
+   vdd_ddr: buck2 {
+   regulator-name = "vdd_ddr";
+   regulator-min-microvolt = <135>;
+   regulator-max-microvolt = <135>;
+   regulator-always-on;
+   regulator-initial-mode = <0>;
+   regulator-over-current-protection;
+   };
+
+   vdd: buck3 {
+   regulator-name = "vdd";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-always-on;
+   st,mask-reset;
+   regulator-initial-mode = <0>;
+   regulator-over-current-protection;
+   };
+
+   v3v3: buck4 {
+   regulator-name = "v3v3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-always-on;
+   regulator-over-current-protection;
+   regulator-initial-mode = <0>;
+   };
+
+   vdda: ldo1 {
+   regulator-name = "vdda";
+   regulator-min-microvolt = <290>;
+   regulator-max-microvolt = <290>;
+   interrupts = ;
+   };
+
+   v2v8: ldo2 {
+   regulator-name = "v2v8";
+   regulator-min-microvolt = <280>;
+   regulator-max-microvolt = <280>;
+   interrupts = ;
+   };
+
+   vtt_ddr: ldo3 {
+   regulator-name = "vtt_ddr";
+   regulator-min-microvolt 

[PATCH 0/3] Add support for STPMIC1

2019-04-03 Thread Pascal PAILLET-LME
Add support for STPMIC1 on:
- stm32mp157c ed1 board
- stm32mp157a dk1 board
- arm multi_v7_defconfig

Pascal Paillet (3):
  ARM: dts: stm32: add stpmic1 support on stm32mp157c ed1 board
  ARM: dts: stm32: add stpmic1 support on stm32mp157a dk1 board
  ARM: multi_v7_defconfig: Enable support for STPMIC1

 arch/arm/boot/dts/stm32mp157a-dk1.dts | 157 --
 arch/arm/boot/dts/stm32mp157c-ed1.dts | 155 +
 arch/arm/configs/multi_v7_defconfig   |   4 +
 3 files changed, 292 insertions(+), 24 deletions(-)

-- 
1.9.1


[PATCH 3/3] ARM: multi_v7_defconfig: Enable support for STPMIC1

2019-04-03 Thread Pascal PAILLET-LME
STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
---
 arch/arm/configs/multi_v7_defconfig | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/configs/multi_v7_defconfig 
b/arch/arm/configs/multi_v7_defconfig
index c75051b..2e9fa53 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -299,6 +299,7 @@ CONFIG_INPUT_MAX8997_HAPTIC=m
 CONFIG_INPUT_CPCAP_PWRBUTTON=m
 CONFIG_INPUT_AXP20X_PEK=m
 CONFIG_INPUT_ADXL34X=m
+CONFIG_INPUT_STPMIC1_ONKEY=y
 CONFIG_SERIO_AMBAKMI=y
 CONFIG_SERIAL_8250=y
 CONFIG_SERIAL_8250_CONSOLE=y
@@ -486,6 +487,7 @@ CONFIG_TEGRA_WATCHDOG=m
 CONFIG_MESON_WATCHDOG=y
 CONFIG_DIGICOLOR_WATCHDOG=y
 CONFIG_RENESAS_WDT=m
+CONFIG_STPMIC1_WATCHDOG=y
 CONFIG_BCM47XX_WDT=y
 CONFIG_BCM2835_WDT=y
 CONFIG_BCM_KONA_WDT=y
@@ -527,6 +529,7 @@ CONFIG_MFD_TPS65218=y
 CONFIG_MFD_TPS6586X=y
 CONFIG_MFD_TPS65910=y
 CONFIG_MFD_STM32_LPTIMER=m
+CONFIG_MFD_STPMIC1=y
 CONFIG_REGULATOR_ACT8865=y
 CONFIG_REGULATOR_ACT8945A=y
 CONFIG_REGULATOR_ANATOP=y
@@ -559,6 +562,7 @@ CONFIG_REGULATOR_RN5T618=y
 CONFIG_REGULATOR_S2MPS11=y
 CONFIG_REGULATOR_S5M8767=y
 CONFIG_REGULATOR_STM32_VREFBUF=m
+CONFIG_REGULATOR_STPMIC1=y
 CONFIG_REGULATOR_TI_ABB=y
 CONFIG_REGULATOR_TPS51632=y
 CONFIG_REGULATOR_TPS62360=y
-- 
1.9.1


[PATCH 4/8] dt-bindings: regulator: remove regulator pull-down support for stpmic1

2019-02-19 Thread Pascal PAILLET-LME
Regulator high pull down are enabled by default so remove support in the
driver.

Signed-off-by: Pascal Paillet 
---
 Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt | 2 --
 1 file changed, 2 deletions(-)

diff --git 
a/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt 
b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
index de27897..bf9385b 100644
--- a/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
@@ -23,8 +23,6 @@ Switches are fixed voltage regulators with only 
enable/disable capability.
 Optional properties:
 - st,mask-reset: mask reset for this regulator: the regulator configuration
   is maintained during pmic reset.
-- regulator-pull-down: enable high pull down
-  if not specified light pull down is used
 - regulator-over-current-protection:
 if set, all regulators are switched off in case of over-current detection
 on this regulator,
-- 
1.9.1


[PATCH 0/8] STPMIC1 Fixes

2019-02-19 Thread Pascal PAILLET-LME
The goal of this patch-set is to improve the stpmic1 regulator driver:
with Fixes:
- Simplify regulator registration code
- Remove support of regulator pull-down
- Fix buck1 voltage range
- Fix binding documentation
with a new feature:
- Add support for active discharge

Pascal Paillet (8):
  regulator: stpmic1: Use regulator mode definition from bindings
  regulator: stpmic1: Simplify regulators registration
  dt-bindings: regulator: remove interrupt-parent description on stpmic1
  dt-bindings: regulator: remove regulator pull-down support for stpmic1
  regulator: stpmic1: Remove support for regulator pull down
  regulator: stpmic1: Change buck1 voltage range
  dt-bindings: regulator: Add active discharge support for stpmic1
  regulator: stpmic1: Add active discharge support

 .../bindings/regulator/st,stpmic1-regulator.txt|   6 +-
 drivers/regulator/stpmic1_regulator.c  | 258 +
 2 files changed, 113 insertions(+), 151 deletions(-)

-- 
1.9.1


[PATCH 3/8] dt-bindings: regulator: remove interrupt-parent description on stpmic1

2019-02-19 Thread Pascal PAILLET-LME
The interrupt parent description is not needed as the parent is a parent
node with 'interrupt-controller' property.

Signed-off-by: pascal paillet 
---
 Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt | 3 ---
 1 file changed, 3 deletions(-)

diff --git 
a/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt 
b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
index a3f4762..de27897 100644
--- a/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
@@ -29,7 +29,6 @@ Optional properties:
 if set, all regulators are switched off in case of over-current detection
 on this regulator,
 if not set, the driver only sends an over-current event.
-- interrupt-parent: phandle to the parent interrupt controller
 - interrupts: index of current limit detection interrupt
 - -supply: phandle to the parent supply/regulator node
each regulator supply can be described except vref_ddr.
@@ -43,7 +42,6 @@ regulators {
vdd_core: buck1 {
regulator-name = "vdd_core";
interrupts = ;
-   interrupt-parent = <>;
st,mask-reset;
regulator-pull-down;
regulator-min-microvolt = <70>;
@@ -53,7 +51,6 @@ regulators {
v3v3: buck4 {
regulator-name = "v3v3";
interrupts = ;
-   interrupt-parent = <>;
 
regulator-min-microvolt = <330>;
regulator-max-microvolt = <330>;
-- 
1.9.1


[PATCH 1/8] regulator: stpmic1: Use regulator mode definition from bindings

2019-02-19 Thread Pascal PAILLET-LME
Get the regulator mode definition from the bindings header.

Signed-off-by: pascal paillet 
---
 drivers/regulator/stpmic1_regulator.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/stpmic1_regulator.c 
b/drivers/regulator/stpmic1_regulator.c
index d456fb5..c25f82f 100644
--- a/drivers/regulator/stpmic1_regulator.c
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -12,6 +12,8 @@
 #include 
 #include 
 
+#include 
+
 /**
  * stpmic1 regulator description
  * @desc: regulator framework description
@@ -68,9 +70,6 @@ enum {
 /* Enable time worst case is 5000mV/(2250uV/uS) */
 #define PMIC_ENABLE_TIME_US 2200
 
-#define STPMIC1_BUCK_MODE_NORMAL 0
-#define STPMIC1_BUCK_MODE_LP BUCK_HPLP_ENABLE_MASK
-
 static const struct regulator_linear_range buck1_ranges[] = {
REGULATOR_LINEAR_RANGE(60, 0, 30, 25000),
REGULATOR_LINEAR_RANGE(135, 31, 63, 0),
-- 
1.9.1


[PATCH 7/8] dt-bindings: regulator: Add active discharge support for stpmic1

2019-02-19 Thread Pascal PAILLET-LME
Add support for active discharge for USB power switches.

Signed-off-by: pascal paillet 
---
 Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt 
b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
index bf9385b..6189df7 100644
--- a/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
@@ -30,6 +30,7 @@ Optional properties:
 - interrupts: index of current limit detection interrupt
 - -supply: phandle to the parent supply/regulator node
each regulator supply can be described except vref_ddr.
+- regulator-active-discharge: can be used on pwr_sw1 and pwr_sw2.
 
 Example:
 regulators {
-- 
1.9.1


[PATCH 6/8] regulator: stpmic1: Change buck1 voltage range

2019-02-19 Thread Pascal PAILLET-LME
Change buck1 voltage range to be conform with the data-sheet.

Signed-off-by: pascal paillet 
---
 drivers/regulator/stpmic1_regulator.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/stpmic1_regulator.c 
b/drivers/regulator/stpmic1_regulator.c
index 6970e45..41128c4 100644
--- a/drivers/regulator/stpmic1_regulator.c
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -56,8 +56,9 @@ enum {
 #define PMIC_ENABLE_TIME_US 2200
 
 static const struct regulator_linear_range buck1_ranges[] = {
-   REGULATOR_LINEAR_RANGE(60, 0, 30, 25000),
-   REGULATOR_LINEAR_RANGE(135, 31, 63, 0),
+   REGULATOR_LINEAR_RANGE(725000, 0, 4, 0),
+   REGULATOR_LINEAR_RANGE(725000, 5, 36, 25000),
+   REGULATOR_LINEAR_RANGE(150, 37, 63, 0),
 };
 
 static const struct regulator_linear_range buck2_ranges[] = {
-- 
1.9.1


[PATCH 5/8] regulator: stpmic1: Remove support for regulator pull down

2019-02-19 Thread Pascal PAILLET-LME
Regulator high pull down are enabled by default so remove support in the
driver.

Signed-off-by: pascal paillet 
---
 drivers/regulator/stpmic1_regulator.c | 12 
 1 file changed, 12 deletions(-)

diff --git a/drivers/regulator/stpmic1_regulator.c 
b/drivers/regulator/stpmic1_regulator.c
index f5c0e58..6970e45 100644
--- a/drivers/regulator/stpmic1_regulator.c
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -133,7 +133,6 @@ enum {
.disable = regulator_disable_regmap,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
-   .set_pull_down = regulator_set_pull_down_regmap,
.set_over_current_protection = stpmic1_set_icc,
 };
 
@@ -145,7 +144,6 @@ enum {
.disable = regulator_disable_regmap,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
-   .set_pull_down = regulator_set_pull_down_regmap,
.get_bypass = regulator_get_bypass_regmap,
.set_bypass = regulator_set_bypass_regmap,
.set_over_current_protection = stpmic1_set_icc,
@@ -155,7 +153,6 @@ enum {
.is_enabled = regulator_is_enabled_regmap,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
-   .set_pull_down = regulator_set_pull_down_regmap,
.set_over_current_protection = stpmic1_set_icc,
 };
 
@@ -177,7 +174,6 @@ enum {
.is_enabled = regulator_is_enabled_regmap,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
-   .set_pull_down = regulator_set_pull_down_regmap,
 };
 
 static const struct regulator_ops stpmic1_switch_regul_ops = {
@@ -203,8 +199,6 @@ enum {
.enable_val = 1, \
.disable_val = 0, \
.enable_time = PMIC_ENABLE_TIME_US, \
-   .pull_down_reg = ids##_PULL_DOWN_REG, \
-   .pull_down_mask = ids##_PULL_DOWN_MASK, \
.supply_name = #base, \
 }
 
@@ -228,8 +222,6 @@ enum {
.bypass_mask = LDO_BYPASS_MASK, \
.bypass_val_on = LDO_BYPASS_MASK, \
.bypass_val_off = 0, \
-   .pull_down_reg = ids##_PULL_DOWN_REG, \
-   .pull_down_mask = ids##_PULL_DOWN_MASK, \
.supply_name = #base, \
 }
 
@@ -247,8 +239,6 @@ enum {
.enable_val = 1, \
.disable_val = 0, \
.enable_time = PMIC_ENABLE_TIME_US, \
-   .pull_down_reg = ids##_PULL_DOWN_REG, \
-   .pull_down_mask = ids##_PULL_DOWN_MASK, \
.supply_name = #base, \
 }
 
@@ -288,8 +278,6 @@ enum {
.enable_val = 1, \
.disable_val = 0, \
.enable_time = PMIC_ENABLE_TIME_US, \
-   .pull_down_reg = ids##_PULL_DOWN_REG, \
-   .pull_down_mask = ids##_PULL_DOWN_MASK, \
.supply_name = #base, \
 }
 
-- 
1.9.1


[PATCH 8/8] regulator: stpmic1: Add active discharge support

2019-02-19 Thread Pascal PAILLET-LME
Add support for active discharge for USB power switches.

Signed-off-by: pascal paillet 
---
 drivers/regulator/stpmic1_regulator.c | 68 ---
 1 file changed, 55 insertions(+), 13 deletions(-)

diff --git a/drivers/regulator/stpmic1_regulator.c 
b/drivers/regulator/stpmic1_regulator.c
index 41128c4..f090614 100644
--- a/drivers/regulator/stpmic1_regulator.c
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -177,11 +177,19 @@ enum {
.disable = regulator_disable_regmap,
 };
 
+static const struct regulator_ops stpmic1_boost_regul_ops = {
+   .is_enabled = regulator_is_enabled_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .set_over_current_protection = stpmic1_set_icc,
+};
+
 static const struct regulator_ops stpmic1_switch_regul_ops = {
.is_enabled = regulator_is_enabled_regmap,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
.set_over_current_protection = stpmic1_set_icc,
+   .set_active_discharge = regulator_set_active_discharge_regmap,
 };
 
 #define REG_LDO(ids, base) { \
@@ -282,7 +290,44 @@ enum {
.supply_name = #base, \
 }
 
-#define REG_SWITCH(ids, base, reg, mask, val) { \
+#define REG_BOOST(ids, base) { \
+   .name = #ids, \
+   .id = STPMIC1_##ids, \
+   .n_voltages = 1, \
+   .ops = _boost_regul_ops, \
+   .type = REGULATOR_VOLTAGE, \
+   .owner = THIS_MODULE, \
+   .min_uV = 0, \
+   .fixed_uV = 500, \
+   .enable_reg = BST_SW_CR, \
+   .enable_mask = BOOST_ENABLED, \
+   .enable_val = BOOST_ENABLED, \
+   .disable_val = 0, \
+   .enable_time = PMIC_ENABLE_TIME_US, \
+   .supply_name = #base, \
+}
+
+#define REG_VBUS_OTG(ids, base) { \
+   .name = #ids, \
+   .id = STPMIC1_##ids, \
+   .n_voltages = 1, \
+   .ops = _switch_regul_ops, \
+   .type = REGULATOR_VOLTAGE, \
+   .owner = THIS_MODULE, \
+   .min_uV = 0, \
+   .fixed_uV = 500, \
+   .enable_reg = BST_SW_CR, \
+   .enable_mask = USBSW_OTG_SWITCH_ENABLED, \
+   .enable_val = USBSW_OTG_SWITCH_ENABLED, \
+   .disable_val = 0, \
+   .enable_time = PMIC_ENABLE_TIME_US, \
+   .supply_name = #base, \
+   .active_discharge_reg = BST_SW_CR, \
+   .active_discharge_mask = VBUS_OTG_DISCHARGE, \
+   .active_discharge_on = VBUS_OTG_DISCHARGE, \
+}
+
+#define REG_SW_OUT(ids, base) { \
.name = #ids, \
.id = STPMIC1_##ids, \
.n_voltages = 1, \
@@ -291,12 +336,15 @@ enum {
.owner = THIS_MODULE, \
.min_uV = 0, \
.fixed_uV = 500, \
-   .enable_reg = (reg), \
-   .enable_mask = (mask), \
-   .enable_val = (val), \
+   .enable_reg = BST_SW_CR, \
+   .enable_mask = SWIN_SWOUT_ENABLED, \
+   .enable_val = SWIN_SWOUT_ENABLED, \
.disable_val = 0, \
.enable_time = PMIC_ENABLE_TIME_US, \
.supply_name = #base, \
+   .active_discharge_reg = BST_SW_CR, \
+   .active_discharge_mask = SW_OUT_DISCHARGE, \
+   .active_discharge_on = SW_OUT_DISCHARGE, \
 }
 
 static const struct stpmic1_regulator_cfg stpmic1_regulator_cfgs[] = {
@@ -376,23 +424,17 @@ enum {
.mask_reset_mask = BIT(6),
},
[STPMIC1_BOOST] = {
-   .desc = REG_SWITCH(BOOST, boost, BST_SW_CR,
-  BOOST_ENABLED,
-  BOOST_ENABLED),
+   .desc = REG_BOOST(BOOST, boost),
.icc_reg = BUCKS_ICCTO_CR,
.icc_mask = BIT(6),
},
[STPMIC1_VBUS_OTG] = {
-   .desc = REG_SWITCH(VBUS_OTG, pwr_sw1, BST_SW_CR,
-  USBSW_OTG_SWITCH_ENABLED,
-  USBSW_OTG_SWITCH_ENABLED),
+   .desc = REG_VBUS_OTG(VBUS_OTG, pwr_sw1),
.icc_reg = BUCKS_ICCTO_CR,
.icc_mask = BIT(4),
},
[STPMIC1_SW_OUT] = {
-   .desc = REG_SWITCH(SW_OUT, pwr_sw2, BST_SW_CR,
-  SWIN_SWOUT_ENABLED,
-  SWIN_SWOUT_ENABLED),
+   .desc = REG_SW_OUT(SW_OUT, pwr_sw2),
.icc_reg = BUCKS_ICCTO_CR,
.icc_mask = BIT(5),
},
-- 
1.9.1


[PATCH 2/8] regulator: stpmic1: Simplify regulators registration

2019-02-19 Thread Pascal PAILLET-LME
Stop using a regulator_init callback. This leads to a more simple regulator
registration code. This also permits to spuress struct stpmic1_regulator.
Also rename stpmic1_regulators_matches to stpmic1_matches.

Signed-off-by: pascal paillet 
---
 drivers/regulator/stpmic1_regulator.c | 168 +++---
 1 file changed, 52 insertions(+), 116 deletions(-)

diff --git a/drivers/regulator/stpmic1_regulator.c 
b/drivers/regulator/stpmic1_regulator.c
index c25f82f..f5c0e58 100644
--- a/drivers/regulator/stpmic1_regulator.c
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -15,7 +15,7 @@
 #include 
 
 /**
- * stpmic1 regulator description
+ * stpmic1 regulator description: this structure is used as driver data
  * @desc: regulator framework description
  * @mask_reset_reg: mask reset register address
  * @mask_reset_mask: mask rank and mask reset register mask
@@ -30,24 +30,9 @@ struct stpmic1_regulator_cfg {
u8 icc_mask;
 };
 
-/**
- * stpmic1 regulator data: this structure is used as driver data
- * @reg_node: DT node of regulator (unused on non-DT platforms)
- * @cfg: stpmic specific regulator description
- * @mask_reset: mask_reset bit value
- * @irq_curlim: current limit interrupt number
- */
-struct stpmic1_regulator {
-   struct device_node *reg_node;
-   const struct stpmic1_regulator_cfg *cfg;
-   u8 mask_reset;
-   int irq_curlim;
-};
-
 static int stpmic1_set_mode(struct regulator_dev *rdev, unsigned int mode);
 static unsigned int stpmic1_get_mode(struct regulator_dev *rdev);
 static int stpmic1_set_icc(struct regulator_dev *rdev);
-static int stpmic1_regulator_parse_dt(void *driver_data);
 static unsigned int stpmic1_map_mode(unsigned int mode);
 
 enum {
@@ -439,8 +424,9 @@ static unsigned int stpmic1_map_mode(unsigned int mode)
 static unsigned int stpmic1_get_mode(struct regulator_dev *rdev)
 {
int value;
+   struct regmap *regmap = rdev_get_regmap(rdev);
 
-   regmap_read(rdev->regmap, rdev->desc->enable_reg, );
+   regmap_read(regmap, rdev->desc->enable_reg, );
 
if (value & STPMIC1_BUCK_MODE_LP)
return REGULATOR_MODE_STANDBY;
@@ -451,6 +437,7 @@ static unsigned int stpmic1_get_mode(struct regulator_dev 
*rdev)
 static int stpmic1_set_mode(struct regulator_dev *rdev, unsigned int mode)
 {
int value;
+   struct regmap *regmap = rdev_get_regmap(rdev);
 
switch (mode) {
case REGULATOR_MODE_NORMAL:
@@ -463,18 +450,18 @@ static int stpmic1_set_mode(struct regulator_dev *rdev, 
unsigned int mode)
return -EINVAL;
}
 
-   return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+   return regmap_update_bits(regmap, rdev->desc->enable_reg,
  STPMIC1_BUCK_MODE_LP, value);
 }
 
 static int stpmic1_set_icc(struct regulator_dev *rdev)
 {
-   struct stpmic1_regulator *regul = rdev_get_drvdata(rdev);
+   struct stpmic1_regulator_cfg *cfg = rdev_get_drvdata(rdev);
struct regmap *regmap = rdev_get_regmap(rdev);
 
/* enable switch off in case of over current */
-   return regmap_update_bits(regmap, regul->cfg->icc_reg,
- regul->cfg->icc_mask, regul->cfg->icc_mask);
+   return regmap_update_bits(regmap, cfg->icc_reg, cfg->icc_mask,
+ cfg->icc_mask);
 }
 
 static irqreturn_t stpmic1_curlim_irq_handler(int irq, void *data)
@@ -493,47 +480,13 @@ static irqreturn_t stpmic1_curlim_irq_handler(int irq, 
void *data)
return IRQ_HANDLED;
 }
 
-static int stpmic1_regulator_init(struct platform_device *pdev,
- struct regulator_dev *rdev)
-{
-   struct stpmic1_regulator *regul = rdev_get_drvdata(rdev);
-   struct regmap *regmap = rdev_get_regmap(rdev);
-   int ret = 0;
-
-   /* set mask reset */
-   if (regul->mask_reset && regul->cfg->mask_reset_reg != 0) {
-   ret = regmap_update_bits(regmap,
-regul->cfg->mask_reset_reg,
-regul->cfg->mask_reset_mask,
-regul->cfg->mask_reset_mask);
-   if (ret) {
-   dev_err(>dev, "set mask reset failed\n");
-   return ret;
-   }
-   }
-
-   /* setup an irq handler for over-current detection */
-   if (regul->irq_curlim > 0) {
-   ret = devm_request_threaded_irq(>dev,
-   regul->irq_curlim, NULL,
-   stpmic1_curlim_irq_handler,
-   IRQF_ONESHOT | IRQF_SHARED,
-   pdev->name, rdev);
-   if (ret) {
-   dev_err(>dev, "Request IRQ failed\n");
-   return ret;
-   }
-   }
-   return 0;
-}
-
 #define 

Re: [PATCH] regulator: stpmic1: Remove regul_id and *regmap from struct stpmic1_regulator

2019-02-11 Thread Pascal PAILLET-LME
Hello Axel,

Le 02/09/2019 05:39 AM, Axel Lin a écrit :
> At the context with *rdev available, there is no problem to get regulator
> id and *regmap, so no need to store them in struct stpmic1_regulator.
>
> Signed-off-by: Axel Lin 
> ---
>   drivers/regulator/stpmic1_regulator.c | 10 ++
>   1 file changed, 2 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/regulator/stpmic1_regulator.c 
> b/drivers/regulator/stpmic1_regulator.c
> index 963e67fa9ca6..dd5c8fb1ff86 100644
> --- a/drivers/regulator/stpmic1_regulator.c
> +++ b/drivers/regulator/stpmic1_regulator.c
> @@ -30,20 +30,16 @@ struct stpmic1_regulator_cfg {
>   
>   /**
>* stpmic1 regulator data: this structure is used as driver data
> - * @regul_id: regulator id
>* @reg_node: DT node of regulator (unused on non-DT platforms)
>* @cfg: stpmic specific regulator description
>* @mask_reset: mask_reset bit value
>* @irq_curlim: current limit interrupt number
> - * @regmap: point to parent regmap structure
>*/
>   struct stpmic1_regulator {
> - unsigned int regul_id;
>   struct device_node *reg_node;
>   const struct stpmic1_regulator_cfg *cfg;
>   u8 mask_reset;
>   int irq_curlim;
> - struct regmap *regmap;
>   };
>   
>   static int stpmic1_set_mode(struct regulator_dev *rdev, unsigned int mode);
> @@ -477,7 +473,7 @@ static int stpmic1_set_icc(struct regulator_dev *rdev)
>   struct stpmic1_regulator *regul = rdev_get_drvdata(rdev);
>   
>   /* enable switch off in case of over current */
> - return regmap_update_bits(regul->regmap, regul->cfg->icc_reg,
> + return regmap_update_bits(rdev->regmap, regul->cfg->icc_reg,
> regul->cfg->icc_mask, regul->cfg->icc_mask);
Maybe this is not compatible with a recommandation from
include/linux/regulator/driver.h:438:
  * This should *not* be used directly by anything except the regulator
  * core and notification injection (which should take the mutex and do
  * no other direct access).

>   }
>
...


thank you,
pascal


[PATCH RESEND v8 3/6] dt-bindings: input: document stpmic1 pmic onkey

2019-01-14 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. It can be configured
to shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
---
changes in v8: nothing

 .../devicetree/bindings/input/st,stpmic1-onkey.txt | 28 ++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt

diff --git a/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt 
b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
new file mode 100644
index 000..4494613
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
@@ -0,0 +1,28 @@
+STMicroelectronics STPMIC1 Onkey
+
+Required properties:
+
+- compatible = "st,stpmic1-onkey";
+- interrupts: interrupt line to use
+- interrupt-names = "onkey-falling", "onkey-rising"
+   onkey-falling: happens when onkey is pressed; IT_PONKEY_F of pmic
+   onkey-rising: happens when onkey is released; IT_PONKEY_R of pmic
+
+Optional properties:
+
+- st,onkey-clear-cc-flag: onkey is able power on after an
+  over-current shutdown event.
+- st,onkey-pu-inactive: onkey pull up is not active
+- power-off-time-sec: Duration in seconds which the key should be kept
+pressed for device to power off automatically (from 1 to 16 seconds).
+see See Documentation/devicetree/bindings/input/keys.txt
+
+Example:
+
+onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupt-parent = <>;
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+};
-- 
1.9.1


[PATCH RESEND v8 2/6] mfd: stpmic1: add stpmic1 driver

2019-01-14 Thread Pascal PAILLET-LME
STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
Acked-for-MFD-by: Lee Jones 
---
changes in v8: nothing

 drivers/mfd/Kconfig |  16 
 drivers/mfd/Makefile|   1 +
 drivers/mfd/stpmic1.c   | 213 
 include/linux/mfd/stpmic1.h | 212 +++
 4 files changed, 442 insertions(+)
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 include/linux/mfd/stpmic1.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 8c5dfdc..0761cb8 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1871,6 +1871,22 @@ config MFD_STM32_TIMERS
  for PWM and IIO Timer. This driver allow to share the
  registers between the others drivers.
 
+config MFD_STPMIC1
+   tristate "Support for STPMIC1 PMIC"
+   depends on (I2C=y && OF)
+   select REGMAP_I2C
+   select REGMAP_IRQ
+   select MFD_CORE
+   help
+ Support for ST Microelectronics STPMIC1 PMIC. STPMIC1 has power on
+ key, watchdog and regulator functionalities which are supported via
+ the relevant subsystems. This driver provides core support for the
+ STPMIC1. In order to use the actual functionaltiy of the device other
+ drivers must be enabled.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1.
+
 menu "Multimedia Capabilities Port drivers"
depends on ARCH_SA1100
 
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 12980a4..a62fb01 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -233,6 +233,7 @@ obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI)   += 
intel_soc_pmic_chtdc_ti.o
 obj-$(CONFIG_MFD_MT6397)   += mt6397-core.o
 
 obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o
+obj-$(CONFIG_MFD_STPMIC1)  += stpmic1.o
 obj-$(CONFIG_MFD_SUN4I_GPADC)  += sun4i-gpadc.o
 
 obj-$(CONFIG_MFD_STM32_LPTIMER)+= stm32-lptimer.o
diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
new file mode 100644
index 000..7dfbe89
--- /dev/null
+++ b/drivers/mfd/stpmic1.c
@@ -0,0 +1,213 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define STPMIC1_MAIN_IRQ 0
+
+static const struct regmap_range stpmic1_readable_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_MASK_R1, INT_MASK_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R1),
+};
+
+static const struct regmap_range stpmic1_writeable_ranges[] = {
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+};
+
+static const struct regmap_range stpmic1_volatile_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(WCHDG_CR, WCHDG_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R4),
+};
+
+static const struct regmap_access_table stpmic1_readable_table = {
+   .yes_ranges = stpmic1_readable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_readable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_writeable_table = {
+   .yes_ranges = stpmic1_writeable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_writeable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_volatile_table = {
+   .yes_ranges = stpmic1_volatile_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_volatile_ranges),
+};
+
+const struct regmap_config stpmic1_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .cache_type = REGCACHE_RBTREE,
+   .max_register = PMIC_MAX_REGISTER_ADDRESS,
+   .rd_table = _readable_table,
+   .wr_table = _writeable_table,
+   .volatile_table = _volatile_table,
+};
+
+static const struct regmap_irq stpmic1_irqs[] = {
+   REGMAP_IRQ_REG(IT_PONKEY_F, 0, 0x01),
+   REGMAP_IRQ_REG(IT_PONKEY_R, 0, 0x02),
+   REGMAP_IRQ_REG(IT_WAKEUP_F, 0, 0x04),
+   REGMAP_IRQ_REG(IT_WAKEUP_R, 0, 0x08),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_F, 0, 0x10),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_R, 0, 0x20),
+   REGMAP_IRQ_REG(IT_SWOUT_F, 0, 0x40),
+   

[PATCH RESEND v8 0/6] Introduce STPMIC1 PMIC Driver

2019-01-14 Thread Pascal PAILLET-LME
The goal of this patch-set is to propose a driver for the STPMIC1 PMIC from 
STMicroelectronics. 
The STPMIC1 regulators supply power to an application processor as well as 
to external system peripherals such as DDR, Flash memories and system
devices. It also features onkey button input and an hardware watchdog.
The STPMIC1 is controlled via I2C. 

Main driver is drivers/mfd/stpmic1 that handle I2C regmap configuration and
irqchip. stpmic1_regulator, stpmic1_onkey and stpmic1_wdt need stpmic1 mfd
as parent.

STPMIC1 MFD and regulator drivers maybe mandatory at boot time.

Pascal Paillet (6):
  dt-bindings: mfd: document stpmic1
  mfd: stpmic1: add stpmic1 driver
  dt-bindings: input: document stpmic1 pmic onkey
  input: stpmic1: add stpmic1 onkey driver
  dt-bindings: watchdog: document stpmic1 pmic watchdog
  watchdog: stpmic1: add stpmic1 watchdog driver

 .../devicetree/bindings/input/st,stpmic1-onkey.txt |  28 +++
 .../devicetree/bindings/mfd/st,stpmic1.txt |  61 ++
 .../bindings/watchdog/st,stpmic1-wdt.txt   |  11 ++
 drivers/input/misc/Kconfig |  11 ++
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 +++
 drivers/mfd/Kconfig|  16 ++
 drivers/mfd/Makefile   |   1 +
 drivers/mfd/stpmic1.c  | 213 +
 drivers/watchdog/Kconfig   |  12 ++
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 ++
 include/dt-bindings/mfd/st,stpmic1.h   |  50 +
 include/linux/mfd/stpmic1.h| 212 
 14 files changed, 955 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
 create mode 100644 drivers/input/misc/stpmic1_onkey.c
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 drivers/watchdog/stpmic1_wdt.c
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h
 create mode 100644 include/linux/mfd/stpmic1.h

-- 
1.9.1


[PATCH RESEND v8 4/6] input: stpmic1: add stpmic1 onkey driver

2019-01-14 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. This driver exposes
the stpmic1 onkey as an input device. It can also be configured to
shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
Acked-by: Dmitry Torokhov 
---
changes in v8: nothing

 drivers/input/misc/Kconfig |  11 +++
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 +
 3 files changed, 211 insertions(+)
 create mode 100644 drivers/input/misc/stpmic1_onkey.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index ca59a2b..279fb02 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -851,4 +851,15 @@ config INPUT_SC27XX_VIBRA
  To compile this driver as a module, choose M here. The module will
  be called sc27xx_vibra.
 
+config INPUT_STPMIC1_ONKEY
+   tristate "STPMIC1 PMIC Onkey support"
+   depends on MFD_STPMIC1
+   help
+ Say Y to enable support of onkey embedded into STPMIC1 PMIC. onkey
+ can be used to wakeup from low power modes and force a shut-down on
+ long press.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1_onkey.
+
 endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 9d0f9d1..1b44202 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_INPUT_SGI_BTNS)  += sgi_btns.o
 obj-$(CONFIG_INPUT_SIRFSOC_ONKEY)  += sirfsoc-onkey.o
 obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY)   += soc_button_array.o
 obj-$(CONFIG_INPUT_SPARCSPKR)  += sparcspkr.o
+obj-$(CONFIG_INPUT_STPMIC1_ONKEY)  += stpmic1_onkey.o
 obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON) += tps65218-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON)  += twl4030-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_VIBRA)  += twl4030-vibra.o
@@ -81,3 +82,4 @@ obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
 obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)+= xen-kbdfront.o
 obj-$(CONFIG_INPUT_YEALINK)+= yealink.o
 obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR)   += ideapad_slidebar.o
+
diff --git a/drivers/input/misc/stpmic1_onkey.c 
b/drivers/input/misc/stpmic1_onkey.c
new file mode 100644
index 000..7b49c99
--- /dev/null
+++ b/drivers/input/misc/stpmic1_onkey.c
@@ -0,0 +1,198 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * struct stpmic1_onkey - OnKey data
+ * @input_dev: pointer to input device
+ * @irq_falling:   irq that we are hooked on to
+ * @irq_rising:irq that we are hooked on to
+ */
+struct stpmic1_onkey {
+   struct input_dev *input_dev;
+   int irq_falling;
+   int irq_rising;
+};
+
+static irqreturn_t onkey_falling_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 1);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static irqreturn_t onkey_rising_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 0);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static int stpmic1_onkey_probe(struct platform_device *pdev)
+{
+   struct stpmic1 *pmic = dev_get_drvdata(pdev->dev.parent);
+   struct device *dev = >dev;
+   struct input_dev *input_dev;
+   struct stpmic1_onkey *onkey;
+   unsigned int val, reg = 0;
+   int error;
+
+   onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->irq_falling = platform_get_irq_byname(pdev, "onkey-falling");
+   if (onkey->irq_falling < 0) {
+   dev_err(dev, "failed: request IRQ onkey-falling %d\n",
+   onkey->irq_falling);
+   return onkey->irq_falling;
+   }
+
+   onkey->irq_rising = platform_get_irq_byname(pdev, "onkey-rising");
+   if (onkey->irq_rising < 0) {
+   dev_err(dev, "failed: request IRQ onkey-rising %d\n",
+   onkey->irq_rising);
+   return onkey->irq_rising;
+   }
+
+   if (!device_property_read_u32(dev, "power-off-time-sec", )) {
+   if (val > 0 && val <= 16) {
+   dev_dbg(dev, "power-off-time=%d seconds\n", val);
+   reg |= PONKEY_PWR_OFF;
+   reg |= ((16 - val) & PONKEY_TURNOFF_TIMER_MASK);
+   } else {
+   dev_err(dev, 

[PATCH RESEND v8 6/6] watchdog: stpmic1: add stpmic1 watchdog driver

2019-01-14 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default. As soon
as the watchdog is started, it must be refreshed periodically otherwise
the PMIC goes off.

Signed-off-by: Pascal Paillet 
Reviewed-by: Guenter Roeck 
---
changes in v8: nothing

 drivers/watchdog/Kconfig   |  12 
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 +
 3 files changed, 152 insertions(+)
 create mode 100644 drivers/watchdog/stpmic1_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 2d64333..cc5155b 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -817,6 +817,18 @@ config STM32_WATCHDOG
  To compile this driver as a module, choose M here: the
  module will be called stm32_iwdg.
 
+config STPMIC1_WATCHDOG
+   tristate "STPMIC1 PMIC watchdog support"
+   depends on MFD_STPMIC1
+   select WATCHDOG_CORE
+   help
+ Say Y here to include watchdog support embedded into STPMIC1 PMIC.
+ If the watchdog timer expires, stpmic1 will shut down all its power
+ supplies.
+
+ To compile this driver as a module, choose M here: the
+ module will be called spmic1_wdt.
+
 config UNIPHIER_WATCHDOG
tristate "UniPhier watchdog support"
depends on ARCH_UNIPHIER || COMPILE_TEST
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index f69cdff..bdc072c 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -218,3 +218,4 @@ obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
 obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
 obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o
 obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
+obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o
diff --git a/drivers/watchdog/stpmic1_wdt.c b/drivers/watchdog/stpmic1_wdt.c
new file mode 100644
index 000..ad431d8
--- /dev/null
+++ b/drivers/watchdog/stpmic1_wdt.c
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* WATCHDOG CONTROL REGISTER bit */
+#define WDT_START  BIT(0)
+#define WDT_PING   BIT(1)
+#define WDT_START_MASK BIT(0)
+#define WDT_PING_MASK  BIT(1)
+#define WDT_STOP   0
+
+#define PMIC_WDT_MIN_TIMEOUT 1
+#define PMIC_WDT_MAX_TIMEOUT 256
+#define PMIC_WDT_DEFAULT_TIMEOUT 30
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct stpmic1_wdt {
+   struct stpmic1 *pmic;
+   struct watchdog_device wdtdev;
+};
+
+static int pmic_wdt_start(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_START);
+}
+
+static int pmic_wdt_stop(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_STOP);
+}
+
+static int pmic_wdt_ping(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_PING_MASK, WDT_PING);
+}
+
+static int pmic_wdt_set_timeout(struct watchdog_device *wdd,
+   unsigned int timeout)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   wdd->timeout = timeout;
+   /* timeout is equal to register value + 1 */
+   return regmap_write(wdt->pmic->regmap, WCHDG_TIMER_CR, timeout - 1);
+}
+
+static const struct watchdog_info pmic_watchdog_info = {
+   .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+   .identity = "STPMIC1 PMIC Watchdog",
+};
+
+static const struct watchdog_ops pmic_watchdog_ops = {
+   .owner = THIS_MODULE,
+   .start = pmic_wdt_start,
+   .stop = pmic_wdt_stop,
+   .ping = pmic_wdt_ping,
+   .set_timeout = pmic_wdt_set_timeout,
+};
+
+static int pmic_wdt_probe(struct platform_device *pdev)
+{
+   int ret;
+   struct stpmic1 *pmic;
+   struct stpmic1_wdt *wdt;
+
+   if (!pdev->dev.parent)
+   return -EINVAL;
+
+   pmic = dev_get_drvdata(pdev->dev.parent);
+   if (!pmic)
+   return -EINVAL;
+
+   wdt = devm_kzalloc(>dev, sizeof(struct stpmic1_wdt), GFP_KERNEL);
+   if (!wdt)
+   return -ENOMEM;
+
+   wdt->pmic = pmic;
+
+   wdt->wdtdev.info = _watchdog_info;
+   wdt->wdtdev.ops = _watchdog_ops;
+   wdt->wdtdev.min_timeout = PMIC_WDT_MIN_TIMEOUT;
+   

[PATCH RESEND v8 1/6] dt-bindings: mfd: document stpmic1

2019-01-14 Thread Pascal PAILLET-LME
STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
Acked-for-MFD-by: Lee Jones 
---
changes in v8: nothing

 .../devicetree/bindings/mfd/st,stpmic1.txt | 61 ++
 include/dt-bindings/mfd/st,stpmic1.h   | 50 ++
 2 files changed, 111 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h

diff --git a/Documentation/devicetree/bindings/mfd/st,stpmic1.txt 
b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
new file mode 100644
index 000..afd45c0
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
@@ -0,0 +1,61 @@
+* STMicroelectronics STPMIC1 Power Management IC
+
+Required properties:
+- compatible:  : "st,stpmic1"
+- reg: : The I2C slave address for the STPMIC1 chip.
+- interrupts:  : The interrupt line the device is connected to.
+- #interrupt-cells:: Should be 1.
+- interrupt-controller:: Marks the device node as an interrupt 
controller.
+   Interrupt numbers are defined at
+   dt-bindings/mfd/st,stpmic1.h.
+
+STPMIC1 consists in a varied group of sub-devices.
+Each sub-device binding is be described in own documentation file.
+
+Device  Description
+-- 
+st,stpmic1-onkey   : Power on key, see ../input/st,stpmic1-onkey.txt
+st,stpmic1-regulators  : Regulators, see ../regulator/st,stpmic1-regulator.txt
+st,stpmic1-wdt : Watchdog, see ../watchdog/st,stpmic1-wdt.txt
+
+Example:
+
+#include 
+
+pmic: pmic@33 {
+   compatible = "st,stpmic1";
+   reg = <0x33>;
+   interrupt-parent = <>;
+   interrupts = <0 2>;
+
+   interrupt-controller;
+   #interrupt-cells = <2>;
+
+   onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+   };
+
+   watchdog {
+   compatible = "st,stpmic1-wdt";
+   };
+
+   regulators {
+   compatible = "st,stpmic1-regulators";
+
+   vdd_core: buck1 {
+   regulator-name = "vdd_core";
+   regulator-boot-on;
+   regulator-min-microvolt = <70>;
+   regulator-max-microvolt = <120>;
+   };
+   vdd: buck3 {
+   regulator-name = "vdd";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-boot-on;
+   regulator-pull-down;
+   };
+   };
diff --git a/include/dt-bindings/mfd/st,stpmic1.h 
b/include/dt-bindings/mfd/st,stpmic1.h
new file mode 100644
index 000..321cd087
--- /dev/null
+++ b/include/dt-bindings/mfd/st,stpmic1.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) STMicroelectronics 2018 - All Rights Reserved
+ * Author: Philippe Peurichard ,
+ * Pascal Paillet  for STMicroelectronics.
+ */
+
+#ifndef __DT_BINDINGS_STPMIC1_H__
+#define __DT_BINDINGS_STPMIC1_H__
+
+/* IRQ definitions */
+#define IT_PONKEY_F0
+#define IT_PONKEY_R1
+#define IT_WAKEUP_F2
+#define IT_WAKEUP_R3
+#define IT_VBUS_OTG_F  4
+#define IT_VBUS_OTG_R  5
+#define IT_SWOUT_F 6
+#define IT_SWOUT_R 7
+
+#define IT_CURLIM_BUCK18
+#define IT_CURLIM_BUCK29
+#define IT_CURLIM_BUCK310
+#define IT_CURLIM_BUCK411
+#define IT_OCP_OTG 12
+#define IT_OCP_SWOUT   13
+#define IT_OCP_BOOST   14
+#define IT_OVP_BOOST   15
+
+#define IT_CURLIM_LDO1 16
+#define IT_CURLIM_LDO2 17
+#define IT_CURLIM_LDO3 18
+#define IT_CURLIM_LDO4 19
+#define IT_CURLIM_LDO5 20
+#define IT_CURLIM_LDO6 21
+#define IT_SHORT_SWOTG 22
+#define IT_SHORT_SWOUT 23
+
+#define IT_TWARN_F 24
+#define IT_TWARN_R 25
+#define IT_VINLOW_F26
+#define IT_VINLOW_R27
+#define IT_SWIN_F  30
+#define IT_SWIN_R  31
+
+/* BUCK MODES definitions */
+#define STPMIC1_BUCK_MODE_NORMAL 0
+#define STPMIC1_BUCK_MODE_LP 2
+
+#endif /* __DT_BINDINGS_STPMIC1_H__ */
-- 
1.9.1


[PATCH RESEND v8 5/6] dt-bindings: watchdog: document stpmic1 pmic watchdog

2019-01-14 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default.
In case of watchdog, the PMIC goes off.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
Reviewed-by: Guenter Roeck 
---
changes in v8: nothing

 Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt

diff --git a/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt 
b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
new file mode 100644
index 000..7cc1407
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
@@ -0,0 +1,11 @@
+STMicroelectronics STPMIC1 Watchdog
+
+Required properties:
+
+- compatible : should be "st,stpmic1-wdt"
+
+Example:
+
+watchdog {
+   compatible = "st,stpmic1-wdt";
+};
-- 
1.9.1


Re: [PATCH v7 0/7] Introduce STPMIC1 PMIC Driver

2018-12-14 Thread Pascal PAILLET-LME
Hello Lee,

Le 12/14/2018 01:47 PM, Lee Jones a écrit :
> changes in v7:
> * rebase on regul/for-next
>
>dt-bindings: mfd: document stpmic1
>mfd: stpmic1: add stpmic1 driver
>dt-bindings: input: document stpmic1 pmic onkey
>input: stpmic1: add stpmic1 onkey driver
>dt-bindings: watchdog: document stpmic1 pmic watchdog
>watchdog: stpmic1: add stpmic1 watchdog driver
>regulator: stpmic1: fix regulator_lock usage
> Could you please remove any patches which have been applied and
> [RESEND]?
DONE, I have resent a V8 without  the regulator patch.

> Also, is Dmitry planning on Acking:
>
>dt-bindings: input: document stpmic1 pmic onkey
>
> ... or is Rob's Ack enough?
>


thank you,
pascal


[PATCH v8 0/6] Introduce STPMIC1 PMIC Driver

2018-12-14 Thread Pascal PAILLET-LME
The goal of this patch-set is to propose a driver for the STPMIC1 PMIC from 
STMicroelectronics. 
The STPMIC1 regulators supply power to an application processor as well as 
to external system peripherals such as DDR, Flash memories and system
devices. It also features onkey button input and an hardware watchdog.
The STPMIC1 is controlled via I2C. 

Main driver is drivers/mfd/stpmic1 that handle I2C regmap configuration and
irqchip. stpmic1_regulator, stpmic1_onkey and stpmic1_wdt need stpmic1 mfd
as parent.

STPMIC1 MFD and regulator drivers maybe mandatory at boot time.

Pascal Paillet (6):
  dt-bindings: mfd: document stpmic1
  mfd: stpmic1: add stpmic1 driver
  dt-bindings: input: document stpmic1 pmic onkey
  input: stpmic1: add stpmic1 onkey driver
  dt-bindings: watchdog: document stpmic1 pmic watchdog
  watchdog: stpmic1: add stpmic1 watchdog driver

 .../devicetree/bindings/input/st,stpmic1-onkey.txt |  28 +++
 .../devicetree/bindings/mfd/st,stpmic1.txt |  61 ++
 .../bindings/watchdog/st,stpmic1-wdt.txt   |  11 ++
 drivers/input/misc/Kconfig |  11 ++
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 +++
 drivers/mfd/Kconfig|  16 ++
 drivers/mfd/Makefile   |   1 +
 drivers/mfd/stpmic1.c  | 213 +
 drivers/watchdog/Kconfig   |  12 ++
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 ++
 include/dt-bindings/mfd/st,stpmic1.h   |  50 +
 include/linux/mfd/stpmic1.h| 212 
 14 files changed, 955 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
 create mode 100644 drivers/input/misc/stpmic1_onkey.c
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 drivers/watchdog/stpmic1_wdt.c
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h
 create mode 100644 include/linux/mfd/stpmic1.h

-- 
1.9.1


[PATCH v8 3/6] dt-bindings: input: document stpmic1 pmic onkey

2018-12-14 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. It can be configured
to shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
---
changes in v8: nothing

 .../devicetree/bindings/input/st,stpmic1-onkey.txt | 28 ++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt

diff --git a/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt 
b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
new file mode 100644
index 000..4494613
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
@@ -0,0 +1,28 @@
+STMicroelectronics STPMIC1 Onkey
+
+Required properties:
+
+- compatible = "st,stpmic1-onkey";
+- interrupts: interrupt line to use
+- interrupt-names = "onkey-falling", "onkey-rising"
+   onkey-falling: happens when onkey is pressed; IT_PONKEY_F of pmic
+   onkey-rising: happens when onkey is released; IT_PONKEY_R of pmic
+
+Optional properties:
+
+- st,onkey-clear-cc-flag: onkey is able power on after an
+  over-current shutdown event.
+- st,onkey-pu-inactive: onkey pull up is not active
+- power-off-time-sec: Duration in seconds which the key should be kept
+pressed for device to power off automatically (from 1 to 16 seconds).
+see See Documentation/devicetree/bindings/input/keys.txt
+
+Example:
+
+onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupt-parent = <>;
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+};
-- 
1.9.1


[PATCH v8 2/6] mfd: stpmic1: add stpmic1 driver

2018-12-14 Thread Pascal PAILLET-LME
STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
Acked-for-MFD-by: Lee Jones 
---
changes in v8: nothing

 drivers/mfd/Kconfig |  16 
 drivers/mfd/Makefile|   1 +
 drivers/mfd/stpmic1.c   | 213 
 include/linux/mfd/stpmic1.h | 212 +++
 4 files changed, 442 insertions(+)
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 include/linux/mfd/stpmic1.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 8c5dfdc..0761cb8 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1871,6 +1871,22 @@ config MFD_STM32_TIMERS
  for PWM and IIO Timer. This driver allow to share the
  registers between the others drivers.
 
+config MFD_STPMIC1
+   tristate "Support for STPMIC1 PMIC"
+   depends on (I2C=y && OF)
+   select REGMAP_I2C
+   select REGMAP_IRQ
+   select MFD_CORE
+   help
+ Support for ST Microelectronics STPMIC1 PMIC. STPMIC1 has power on
+ key, watchdog and regulator functionalities which are supported via
+ the relevant subsystems. This driver provides core support for the
+ STPMIC1. In order to use the actual functionaltiy of the device other
+ drivers must be enabled.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1.
+
 menu "Multimedia Capabilities Port drivers"
depends on ARCH_SA1100
 
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 12980a4..a62fb01 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -233,6 +233,7 @@ obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI)   += 
intel_soc_pmic_chtdc_ti.o
 obj-$(CONFIG_MFD_MT6397)   += mt6397-core.o
 
 obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o
+obj-$(CONFIG_MFD_STPMIC1)  += stpmic1.o
 obj-$(CONFIG_MFD_SUN4I_GPADC)  += sun4i-gpadc.o
 
 obj-$(CONFIG_MFD_STM32_LPTIMER)+= stm32-lptimer.o
diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
new file mode 100644
index 000..7dfbe89
--- /dev/null
+++ b/drivers/mfd/stpmic1.c
@@ -0,0 +1,213 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define STPMIC1_MAIN_IRQ 0
+
+static const struct regmap_range stpmic1_readable_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_MASK_R1, INT_MASK_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R1),
+};
+
+static const struct regmap_range stpmic1_writeable_ranges[] = {
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+};
+
+static const struct regmap_range stpmic1_volatile_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(WCHDG_CR, WCHDG_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R4),
+};
+
+static const struct regmap_access_table stpmic1_readable_table = {
+   .yes_ranges = stpmic1_readable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_readable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_writeable_table = {
+   .yes_ranges = stpmic1_writeable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_writeable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_volatile_table = {
+   .yes_ranges = stpmic1_volatile_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_volatile_ranges),
+};
+
+const struct regmap_config stpmic1_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .cache_type = REGCACHE_RBTREE,
+   .max_register = PMIC_MAX_REGISTER_ADDRESS,
+   .rd_table = _readable_table,
+   .wr_table = _writeable_table,
+   .volatile_table = _volatile_table,
+};
+
+static const struct regmap_irq stpmic1_irqs[] = {
+   REGMAP_IRQ_REG(IT_PONKEY_F, 0, 0x01),
+   REGMAP_IRQ_REG(IT_PONKEY_R, 0, 0x02),
+   REGMAP_IRQ_REG(IT_WAKEUP_F, 0, 0x04),
+   REGMAP_IRQ_REG(IT_WAKEUP_R, 0, 0x08),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_F, 0, 0x10),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_R, 0, 0x20),
+   REGMAP_IRQ_REG(IT_SWOUT_F, 0, 0x40),
+   

[PATCH v8 4/6] input: stpmic1: add stpmic1 onkey driver

2018-12-14 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. This driver exposes
the stpmic1 onkey as an input device. It can also be configured to
shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
Acked-by: Dmitry Torokhov 
---
changes in v8: nothing

 drivers/input/misc/Kconfig |  11 +++
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 +
 3 files changed, 211 insertions(+)
 create mode 100644 drivers/input/misc/stpmic1_onkey.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index ca59a2b..279fb02 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -851,4 +851,15 @@ config INPUT_SC27XX_VIBRA
  To compile this driver as a module, choose M here. The module will
  be called sc27xx_vibra.
 
+config INPUT_STPMIC1_ONKEY
+   tristate "STPMIC1 PMIC Onkey support"
+   depends on MFD_STPMIC1
+   help
+ Say Y to enable support of onkey embedded into STPMIC1 PMIC. onkey
+ can be used to wakeup from low power modes and force a shut-down on
+ long press.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1_onkey.
+
 endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 9d0f9d1..1b44202 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_INPUT_SGI_BTNS)  += sgi_btns.o
 obj-$(CONFIG_INPUT_SIRFSOC_ONKEY)  += sirfsoc-onkey.o
 obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY)   += soc_button_array.o
 obj-$(CONFIG_INPUT_SPARCSPKR)  += sparcspkr.o
+obj-$(CONFIG_INPUT_STPMIC1_ONKEY)  += stpmic1_onkey.o
 obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON) += tps65218-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON)  += twl4030-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_VIBRA)  += twl4030-vibra.o
@@ -81,3 +82,4 @@ obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
 obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)+= xen-kbdfront.o
 obj-$(CONFIG_INPUT_YEALINK)+= yealink.o
 obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR)   += ideapad_slidebar.o
+
diff --git a/drivers/input/misc/stpmic1_onkey.c 
b/drivers/input/misc/stpmic1_onkey.c
new file mode 100644
index 000..7b49c99
--- /dev/null
+++ b/drivers/input/misc/stpmic1_onkey.c
@@ -0,0 +1,198 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * struct stpmic1_onkey - OnKey data
+ * @input_dev: pointer to input device
+ * @irq_falling:   irq that we are hooked on to
+ * @irq_rising:irq that we are hooked on to
+ */
+struct stpmic1_onkey {
+   struct input_dev *input_dev;
+   int irq_falling;
+   int irq_rising;
+};
+
+static irqreturn_t onkey_falling_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 1);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static irqreturn_t onkey_rising_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 0);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static int stpmic1_onkey_probe(struct platform_device *pdev)
+{
+   struct stpmic1 *pmic = dev_get_drvdata(pdev->dev.parent);
+   struct device *dev = >dev;
+   struct input_dev *input_dev;
+   struct stpmic1_onkey *onkey;
+   unsigned int val, reg = 0;
+   int error;
+
+   onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->irq_falling = platform_get_irq_byname(pdev, "onkey-falling");
+   if (onkey->irq_falling < 0) {
+   dev_err(dev, "failed: request IRQ onkey-falling %d\n",
+   onkey->irq_falling);
+   return onkey->irq_falling;
+   }
+
+   onkey->irq_rising = platform_get_irq_byname(pdev, "onkey-rising");
+   if (onkey->irq_rising < 0) {
+   dev_err(dev, "failed: request IRQ onkey-rising %d\n",
+   onkey->irq_rising);
+   return onkey->irq_rising;
+   }
+
+   if (!device_property_read_u32(dev, "power-off-time-sec", )) {
+   if (val > 0 && val <= 16) {
+   dev_dbg(dev, "power-off-time=%d seconds\n", val);
+   reg |= PONKEY_PWR_OFF;
+   reg |= ((16 - val) & PONKEY_TURNOFF_TIMER_MASK);
+   } else {
+   dev_err(dev, 

[PATCH v8 5/6] dt-bindings: watchdog: document stpmic1 pmic watchdog

2018-12-14 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default.
In case of watchdog, the PMIC goes off.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
Reviewed-by: Guenter Roeck 
---
changes in v8: nothing

 Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt

diff --git a/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt 
b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
new file mode 100644
index 000..7cc1407
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
@@ -0,0 +1,11 @@
+STMicroelectronics STPMIC1 Watchdog
+
+Required properties:
+
+- compatible : should be "st,stpmic1-wdt"
+
+Example:
+
+watchdog {
+   compatible = "st,stpmic1-wdt";
+};
-- 
1.9.1


[PATCH v8 1/6] dt-bindings: mfd: document stpmic1

2018-12-14 Thread Pascal PAILLET-LME
STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
Acked-for-MFD-by: Lee Jones 
---
changes in v8: nothing

 .../devicetree/bindings/mfd/st,stpmic1.txt | 61 ++
 include/dt-bindings/mfd/st,stpmic1.h   | 50 ++
 2 files changed, 111 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h

diff --git a/Documentation/devicetree/bindings/mfd/st,stpmic1.txt 
b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
new file mode 100644
index 000..afd45c0
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
@@ -0,0 +1,61 @@
+* STMicroelectronics STPMIC1 Power Management IC
+
+Required properties:
+- compatible:  : "st,stpmic1"
+- reg: : The I2C slave address for the STPMIC1 chip.
+- interrupts:  : The interrupt line the device is connected to.
+- #interrupt-cells:: Should be 1.
+- interrupt-controller:: Marks the device node as an interrupt 
controller.
+   Interrupt numbers are defined at
+   dt-bindings/mfd/st,stpmic1.h.
+
+STPMIC1 consists in a varied group of sub-devices.
+Each sub-device binding is be described in own documentation file.
+
+Device  Description
+-- 
+st,stpmic1-onkey   : Power on key, see ../input/st,stpmic1-onkey.txt
+st,stpmic1-regulators  : Regulators, see ../regulator/st,stpmic1-regulator.txt
+st,stpmic1-wdt : Watchdog, see ../watchdog/st,stpmic1-wdt.txt
+
+Example:
+
+#include 
+
+pmic: pmic@33 {
+   compatible = "st,stpmic1";
+   reg = <0x33>;
+   interrupt-parent = <>;
+   interrupts = <0 2>;
+
+   interrupt-controller;
+   #interrupt-cells = <2>;
+
+   onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+   };
+
+   watchdog {
+   compatible = "st,stpmic1-wdt";
+   };
+
+   regulators {
+   compatible = "st,stpmic1-regulators";
+
+   vdd_core: buck1 {
+   regulator-name = "vdd_core";
+   regulator-boot-on;
+   regulator-min-microvolt = <70>;
+   regulator-max-microvolt = <120>;
+   };
+   vdd: buck3 {
+   regulator-name = "vdd";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-boot-on;
+   regulator-pull-down;
+   };
+   };
diff --git a/include/dt-bindings/mfd/st,stpmic1.h 
b/include/dt-bindings/mfd/st,stpmic1.h
new file mode 100644
index 000..321cd087
--- /dev/null
+++ b/include/dt-bindings/mfd/st,stpmic1.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) STMicroelectronics 2018 - All Rights Reserved
+ * Author: Philippe Peurichard ,
+ * Pascal Paillet  for STMicroelectronics.
+ */
+
+#ifndef __DT_BINDINGS_STPMIC1_H__
+#define __DT_BINDINGS_STPMIC1_H__
+
+/* IRQ definitions */
+#define IT_PONKEY_F0
+#define IT_PONKEY_R1
+#define IT_WAKEUP_F2
+#define IT_WAKEUP_R3
+#define IT_VBUS_OTG_F  4
+#define IT_VBUS_OTG_R  5
+#define IT_SWOUT_F 6
+#define IT_SWOUT_R 7
+
+#define IT_CURLIM_BUCK18
+#define IT_CURLIM_BUCK29
+#define IT_CURLIM_BUCK310
+#define IT_CURLIM_BUCK411
+#define IT_OCP_OTG 12
+#define IT_OCP_SWOUT   13
+#define IT_OCP_BOOST   14
+#define IT_OVP_BOOST   15
+
+#define IT_CURLIM_LDO1 16
+#define IT_CURLIM_LDO2 17
+#define IT_CURLIM_LDO3 18
+#define IT_CURLIM_LDO4 19
+#define IT_CURLIM_LDO5 20
+#define IT_CURLIM_LDO6 21
+#define IT_SHORT_SWOTG 22
+#define IT_SHORT_SWOUT 23
+
+#define IT_TWARN_F 24
+#define IT_TWARN_R 25
+#define IT_VINLOW_F26
+#define IT_VINLOW_R27
+#define IT_SWIN_F  30
+#define IT_SWIN_R  31
+
+/* BUCK MODES definitions */
+#define STPMIC1_BUCK_MODE_NORMAL 0
+#define STPMIC1_BUCK_MODE_LP 2
+
+#endif /* __DT_BINDINGS_STPMIC1_H__ */
-- 
1.9.1


[PATCH v8 6/6] watchdog: stpmic1: add stpmic1 watchdog driver

2018-12-14 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default. As soon
as the watchdog is started, it must be refreshed periodically otherwise
the PMIC goes off.

Signed-off-by: Pascal Paillet 
Reviewed-by: Guenter Roeck 
---
changes in v8: nothing

 drivers/watchdog/Kconfig   |  12 
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 +
 3 files changed, 152 insertions(+)
 create mode 100644 drivers/watchdog/stpmic1_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 2d64333..cc5155b 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -817,6 +817,18 @@ config STM32_WATCHDOG
  To compile this driver as a module, choose M here: the
  module will be called stm32_iwdg.
 
+config STPMIC1_WATCHDOG
+   tristate "STPMIC1 PMIC watchdog support"
+   depends on MFD_STPMIC1
+   select WATCHDOG_CORE
+   help
+ Say Y here to include watchdog support embedded into STPMIC1 PMIC.
+ If the watchdog timer expires, stpmic1 will shut down all its power
+ supplies.
+
+ To compile this driver as a module, choose M here: the
+ module will be called spmic1_wdt.
+
 config UNIPHIER_WATCHDOG
tristate "UniPhier watchdog support"
depends on ARCH_UNIPHIER || COMPILE_TEST
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index f69cdff..bdc072c 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -218,3 +218,4 @@ obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
 obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
 obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o
 obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
+obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o
diff --git a/drivers/watchdog/stpmic1_wdt.c b/drivers/watchdog/stpmic1_wdt.c
new file mode 100644
index 000..ad431d8
--- /dev/null
+++ b/drivers/watchdog/stpmic1_wdt.c
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* WATCHDOG CONTROL REGISTER bit */
+#define WDT_START  BIT(0)
+#define WDT_PING   BIT(1)
+#define WDT_START_MASK BIT(0)
+#define WDT_PING_MASK  BIT(1)
+#define WDT_STOP   0
+
+#define PMIC_WDT_MIN_TIMEOUT 1
+#define PMIC_WDT_MAX_TIMEOUT 256
+#define PMIC_WDT_DEFAULT_TIMEOUT 30
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct stpmic1_wdt {
+   struct stpmic1 *pmic;
+   struct watchdog_device wdtdev;
+};
+
+static int pmic_wdt_start(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_START);
+}
+
+static int pmic_wdt_stop(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_STOP);
+}
+
+static int pmic_wdt_ping(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_PING_MASK, WDT_PING);
+}
+
+static int pmic_wdt_set_timeout(struct watchdog_device *wdd,
+   unsigned int timeout)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   wdd->timeout = timeout;
+   /* timeout is equal to register value + 1 */
+   return regmap_write(wdt->pmic->regmap, WCHDG_TIMER_CR, timeout - 1);
+}
+
+static const struct watchdog_info pmic_watchdog_info = {
+   .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+   .identity = "STPMIC1 PMIC Watchdog",
+};
+
+static const struct watchdog_ops pmic_watchdog_ops = {
+   .owner = THIS_MODULE,
+   .start = pmic_wdt_start,
+   .stop = pmic_wdt_stop,
+   .ping = pmic_wdt_ping,
+   .set_timeout = pmic_wdt_set_timeout,
+};
+
+static int pmic_wdt_probe(struct platform_device *pdev)
+{
+   int ret;
+   struct stpmic1 *pmic;
+   struct stpmic1_wdt *wdt;
+
+   if (!pdev->dev.parent)
+   return -EINVAL;
+
+   pmic = dev_get_drvdata(pdev->dev.parent);
+   if (!pmic)
+   return -EINVAL;
+
+   wdt = devm_kzalloc(>dev, sizeof(struct stpmic1_wdt), GFP_KERNEL);
+   if (!wdt)
+   return -ENOMEM;
+
+   wdt->pmic = pmic;
+
+   wdt->wdtdev.info = _watchdog_info;
+   wdt->wdtdev.ops = _watchdog_ops;
+   wdt->wdtdev.min_timeout = PMIC_WDT_MIN_TIMEOUT;
+   

Re: [PATCH v7 0/7] Introduce STPMIC1 PMIC Driver

2018-12-05 Thread Pascal PAILLET-LME

pascal paillet (p.pail...@st.com) Le Mans / France
Microcontrollers and Digital ICs Group | Application Development
TEL: +33.(0)2.44.02.74.69 | TINA: 166 7469

Le 12/05/2018 10:36 AM, Lee Jones a écrit :
> On Tue, 04 Dec 2018, Pascal PAILLET-LME wrote:
>> Le 12/03/2018 08:11 AM, Lee Jones a écrit :
>>> On Fri, 30 Nov 2018, Pascal PAILLET-LME wrote:
>>>
>>>> The goal of this patch-set is to propose a driver for the STPMIC1 PMIC from
>>>> STMicroelectronics.
>>>> The STPMIC1 regulators supply power to an application processor as well as
>>>> to external system peripherals such as DDR, Flash memories and system
>>>> devices. It also features onkey button input and an hardware watchdog.
>>>> The STPMIC1 is controlled via I2C.
>>>>
>>>> Main driver is drivers/mfd/stpmic1 that handle I2C regmap configuration and
>>>> irqchip. stpmic1_regulator, stpmic1_onkey and stpmic1_wdt need stpmic1 mfd
>>>> as parent.
>>>>
>>>> STPMIC1 MFD and regulator drivers maybe mandatory at boot time.
>>>>
>>>> Pascal Paillet (7):
>>>> changes in v7:
>>>> * rebase on regul/for-next
>>>>
>>>> dt-bindings: mfd: document stpmic1
>>>> mfd: stpmic1: add stpmic1 driver
>>>> dt-bindings: input: document stpmic1 pmic onkey
>>>> input: stpmic1: add stpmic1 onkey driver
>>>> dt-bindings: watchdog: document stpmic1 pmic watchdog
>>>> watchdog: stpmic1: add stpmic1 watchdog driver
>>>> regulator: stpmic1: fix regulator_lock usage
>>>>
>>>>.../devicetree/bindings/input/st,stpmic1-onkey.txt |  28 +++
>>>>.../devicetree/bindings/mfd/st,stpmic1.txt |  61 ++
>>>>.../bindings/watchdog/st,stpmic1-wdt.txt   |  11 ++
>>>>drivers/input/misc/Kconfig |  11 ++
>>>>drivers/input/misc/Makefile|   2 +
>>>>drivers/input/misc/stpmic1_onkey.c | 198 
>>>> +++
>>>>drivers/mfd/Kconfig|  16 ++
>>>>drivers/mfd/Makefile   |   1 +
>>>>drivers/mfd/stpmic1.c  | 213 
>>>> +
>>>>drivers/regulator/stpmic1_regulator.c  |   2 +-
>>> Is it just Mark you're waiting on now?
>> It is ok now, Mark has applied the patch.
>> Evrey thing has been acked now. What is the nex step ?
> Mark has applied patch 7?
>
> Why don't I see that?  Should you have removed it from this set?
Hi Lee, I have received an email from Mark telliing that the regulator 
patch is applied on

  https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git  

I can see it on the branch regul/for-next.


thank you,
pascal


>


Re: [PATCH v7 0/7] Introduce STPMIC1 PMIC Driver

2018-12-05 Thread Pascal PAILLET-LME

pascal paillet (p.pail...@st.com) Le Mans / France
Microcontrollers and Digital ICs Group | Application Development
TEL: +33.(0)2.44.02.74.69 | TINA: 166 7469

Le 12/05/2018 10:36 AM, Lee Jones a écrit :
> On Tue, 04 Dec 2018, Pascal PAILLET-LME wrote:
>> Le 12/03/2018 08:11 AM, Lee Jones a écrit :
>>> On Fri, 30 Nov 2018, Pascal PAILLET-LME wrote:
>>>
>>>> The goal of this patch-set is to propose a driver for the STPMIC1 PMIC from
>>>> STMicroelectronics.
>>>> The STPMIC1 regulators supply power to an application processor as well as
>>>> to external system peripherals such as DDR, Flash memories and system
>>>> devices. It also features onkey button input and an hardware watchdog.
>>>> The STPMIC1 is controlled via I2C.
>>>>
>>>> Main driver is drivers/mfd/stpmic1 that handle I2C regmap configuration and
>>>> irqchip. stpmic1_regulator, stpmic1_onkey and stpmic1_wdt need stpmic1 mfd
>>>> as parent.
>>>>
>>>> STPMIC1 MFD and regulator drivers maybe mandatory at boot time.
>>>>
>>>> Pascal Paillet (7):
>>>> changes in v7:
>>>> * rebase on regul/for-next
>>>>
>>>> dt-bindings: mfd: document stpmic1
>>>> mfd: stpmic1: add stpmic1 driver
>>>> dt-bindings: input: document stpmic1 pmic onkey
>>>> input: stpmic1: add stpmic1 onkey driver
>>>> dt-bindings: watchdog: document stpmic1 pmic watchdog
>>>> watchdog: stpmic1: add stpmic1 watchdog driver
>>>> regulator: stpmic1: fix regulator_lock usage
>>>>
>>>>.../devicetree/bindings/input/st,stpmic1-onkey.txt |  28 +++
>>>>.../devicetree/bindings/mfd/st,stpmic1.txt |  61 ++
>>>>.../bindings/watchdog/st,stpmic1-wdt.txt   |  11 ++
>>>>drivers/input/misc/Kconfig |  11 ++
>>>>drivers/input/misc/Makefile|   2 +
>>>>drivers/input/misc/stpmic1_onkey.c | 198 
>>>> +++
>>>>drivers/mfd/Kconfig|  16 ++
>>>>drivers/mfd/Makefile   |   1 +
>>>>drivers/mfd/stpmic1.c  | 213 
>>>> +
>>>>drivers/regulator/stpmic1_regulator.c  |   2 +-
>>> Is it just Mark you're waiting on now?
>> It is ok now, Mark has applied the patch.
>> Evrey thing has been acked now. What is the nex step ?
> Mark has applied patch 7?
>
> Why don't I see that?  Should you have removed it from this set?
Hi Lee, I have received an email from Mark telliing that the regulator 
patch is applied on

  https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git  

I can see it on the branch regul/for-next.


thank you,
pascal


>


Re: [PATCH v7 0/7] Introduce STPMIC1 PMIC Driver

2018-12-04 Thread Pascal PAILLET-LME
Hi Lee,

Le 12/03/2018 08:11 AM, Lee Jones a écrit :
> On Fri, 30 Nov 2018, Pascal PAILLET-LME wrote:
>
>> The goal of this patch-set is to propose a driver for the STPMIC1 PMIC from
>> STMicroelectronics.
>> The STPMIC1 regulators supply power to an application processor as well as
>> to external system peripherals such as DDR, Flash memories and system
>> devices. It also features onkey button input and an hardware watchdog.
>> The STPMIC1 is controlled via I2C.
>>
>> Main driver is drivers/mfd/stpmic1 that handle I2C regmap configuration and
>> irqchip. stpmic1_regulator, stpmic1_onkey and stpmic1_wdt need stpmic1 mfd
>> as parent.
>>
>> STPMIC1 MFD and regulator drivers maybe mandatory at boot time.
>>
>> Pascal Paillet (7):
>> changes in v7:
>> * rebase on regul/for-next
>>
>>dt-bindings: mfd: document stpmic1
>>mfd: stpmic1: add stpmic1 driver
>>dt-bindings: input: document stpmic1 pmic onkey
>>input: stpmic1: add stpmic1 onkey driver
>>dt-bindings: watchdog: document stpmic1 pmic watchdog
>>watchdog: stpmic1: add stpmic1 watchdog driver
>>regulator: stpmic1: fix regulator_lock usage
>>
>>   .../devicetree/bindings/input/st,stpmic1-onkey.txt |  28 +++
>>   .../devicetree/bindings/mfd/st,stpmic1.txt |  61 ++
>>   .../bindings/watchdog/st,stpmic1-wdt.txt   |  11 ++
>>   drivers/input/misc/Kconfig |  11 ++
>>   drivers/input/misc/Makefile|   2 +
>>   drivers/input/misc/stpmic1_onkey.c | 198 
>> +++
>>   drivers/mfd/Kconfig|  16 ++
>>   drivers/mfd/Makefile   |   1 +
>>   drivers/mfd/stpmic1.c  | 213 
>> +
>>   drivers/regulator/stpmic1_regulator.c  |   2 +-
> Is it just Mark you're waiting on now?
It is ok now, Mark has applied the patch.
Evrey thing has been acked now. What is the nex step ?

>>   drivers/watchdog/Kconfig   |  12 ++
>>   drivers/watchdog/Makefile  |   1 +
>>   drivers/watchdog/stpmic1_wdt.c | 139 ++
>>   include/dt-bindings/mfd/st,stpmic1.h   |  50 +
>>   include/linux/mfd/stpmic1.h| 212 
>> 
>>   15 files changed, 956 insertions(+), 1 deletion(-)
>>   create mode 100644 
>> Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
>>   create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
>>   create mode 100644 
>> Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
>>   create mode 100644 drivers/input/misc/stpmic1_onkey.c
>>   create mode 100644 drivers/mfd/stpmic1.c
>>   create mode 100644 drivers/watchdog/stpmic1_wdt.c
>>   create mode 100644 include/dt-bindings/mfd/st,stpmic1.h
>>   create mode 100644 include/linux/mfd/stpmic1.h
>>


Re: [PATCH v7 0/7] Introduce STPMIC1 PMIC Driver

2018-12-04 Thread Pascal PAILLET-LME
Hi Lee,

Le 12/03/2018 08:11 AM, Lee Jones a écrit :
> On Fri, 30 Nov 2018, Pascal PAILLET-LME wrote:
>
>> The goal of this patch-set is to propose a driver for the STPMIC1 PMIC from
>> STMicroelectronics.
>> The STPMIC1 regulators supply power to an application processor as well as
>> to external system peripherals such as DDR, Flash memories and system
>> devices. It also features onkey button input and an hardware watchdog.
>> The STPMIC1 is controlled via I2C.
>>
>> Main driver is drivers/mfd/stpmic1 that handle I2C regmap configuration and
>> irqchip. stpmic1_regulator, stpmic1_onkey and stpmic1_wdt need stpmic1 mfd
>> as parent.
>>
>> STPMIC1 MFD and regulator drivers maybe mandatory at boot time.
>>
>> Pascal Paillet (7):
>> changes in v7:
>> * rebase on regul/for-next
>>
>>dt-bindings: mfd: document stpmic1
>>mfd: stpmic1: add stpmic1 driver
>>dt-bindings: input: document stpmic1 pmic onkey
>>input: stpmic1: add stpmic1 onkey driver
>>dt-bindings: watchdog: document stpmic1 pmic watchdog
>>watchdog: stpmic1: add stpmic1 watchdog driver
>>regulator: stpmic1: fix regulator_lock usage
>>
>>   .../devicetree/bindings/input/st,stpmic1-onkey.txt |  28 +++
>>   .../devicetree/bindings/mfd/st,stpmic1.txt |  61 ++
>>   .../bindings/watchdog/st,stpmic1-wdt.txt   |  11 ++
>>   drivers/input/misc/Kconfig |  11 ++
>>   drivers/input/misc/Makefile|   2 +
>>   drivers/input/misc/stpmic1_onkey.c | 198 
>> +++
>>   drivers/mfd/Kconfig|  16 ++
>>   drivers/mfd/Makefile   |   1 +
>>   drivers/mfd/stpmic1.c  | 213 
>> +
>>   drivers/regulator/stpmic1_regulator.c  |   2 +-
> Is it just Mark you're waiting on now?
It is ok now, Mark has applied the patch.
Evrey thing has been acked now. What is the nex step ?

>>   drivers/watchdog/Kconfig   |  12 ++
>>   drivers/watchdog/Makefile  |   1 +
>>   drivers/watchdog/stpmic1_wdt.c | 139 ++
>>   include/dt-bindings/mfd/st,stpmic1.h   |  50 +
>>   include/linux/mfd/stpmic1.h| 212 
>> 
>>   15 files changed, 956 insertions(+), 1 deletion(-)
>>   create mode 100644 
>> Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
>>   create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
>>   create mode 100644 
>> Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
>>   create mode 100644 drivers/input/misc/stpmic1_onkey.c
>>   create mode 100644 drivers/mfd/stpmic1.c
>>   create mode 100644 drivers/watchdog/stpmic1_wdt.c
>>   create mode 100644 include/dt-bindings/mfd/st,stpmic1.h
>>   create mode 100644 include/linux/mfd/stpmic1.h
>>


[PATCH v7 0/7] Introduce STPMIC1 PMIC Driver

2018-11-30 Thread Pascal PAILLET-LME
The goal of this patch-set is to propose a driver for the STPMIC1 PMIC from 
STMicroelectronics. 
The STPMIC1 regulators supply power to an application processor as well as 
to external system peripherals such as DDR, Flash memories and system
devices. It also features onkey button input and an hardware watchdog.
The STPMIC1 is controlled via I2C. 

Main driver is drivers/mfd/stpmic1 that handle I2C regmap configuration and
irqchip. stpmic1_regulator, stpmic1_onkey and stpmic1_wdt need stpmic1 mfd
as parent.

STPMIC1 MFD and regulator drivers maybe mandatory at boot time.

Pascal Paillet (7):
changes in v7:
* rebase on regul/for-next

  dt-bindings: mfd: document stpmic1
  mfd: stpmic1: add stpmic1 driver
  dt-bindings: input: document stpmic1 pmic onkey
  input: stpmic1: add stpmic1 onkey driver
  dt-bindings: watchdog: document stpmic1 pmic watchdog
  watchdog: stpmic1: add stpmic1 watchdog driver
  regulator: stpmic1: fix regulator_lock usage

 .../devicetree/bindings/input/st,stpmic1-onkey.txt |  28 +++
 .../devicetree/bindings/mfd/st,stpmic1.txt |  61 ++
 .../bindings/watchdog/st,stpmic1-wdt.txt   |  11 ++
 drivers/input/misc/Kconfig |  11 ++
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 +++
 drivers/mfd/Kconfig|  16 ++
 drivers/mfd/Makefile   |   1 +
 drivers/mfd/stpmic1.c  | 213 +
 drivers/regulator/stpmic1_regulator.c  |   2 +-
 drivers/watchdog/Kconfig   |  12 ++
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 ++
 include/dt-bindings/mfd/st,stpmic1.h   |  50 +
 include/linux/mfd/stpmic1.h| 212 
 15 files changed, 956 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
 create mode 100644 drivers/input/misc/stpmic1_onkey.c
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 drivers/watchdog/stpmic1_wdt.c
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h
 create mode 100644 include/linux/mfd/stpmic1.h

-- 
1.9.1


[PATCH v7 0/7] Introduce STPMIC1 PMIC Driver

2018-11-30 Thread Pascal PAILLET-LME
The goal of this patch-set is to propose a driver for the STPMIC1 PMIC from 
STMicroelectronics. 
The STPMIC1 regulators supply power to an application processor as well as 
to external system peripherals such as DDR, Flash memories and system
devices. It also features onkey button input and an hardware watchdog.
The STPMIC1 is controlled via I2C. 

Main driver is drivers/mfd/stpmic1 that handle I2C regmap configuration and
irqchip. stpmic1_regulator, stpmic1_onkey and stpmic1_wdt need stpmic1 mfd
as parent.

STPMIC1 MFD and regulator drivers maybe mandatory at boot time.

Pascal Paillet (7):
changes in v7:
* rebase on regul/for-next

  dt-bindings: mfd: document stpmic1
  mfd: stpmic1: add stpmic1 driver
  dt-bindings: input: document stpmic1 pmic onkey
  input: stpmic1: add stpmic1 onkey driver
  dt-bindings: watchdog: document stpmic1 pmic watchdog
  watchdog: stpmic1: add stpmic1 watchdog driver
  regulator: stpmic1: fix regulator_lock usage

 .../devicetree/bindings/input/st,stpmic1-onkey.txt |  28 +++
 .../devicetree/bindings/mfd/st,stpmic1.txt |  61 ++
 .../bindings/watchdog/st,stpmic1-wdt.txt   |  11 ++
 drivers/input/misc/Kconfig |  11 ++
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 +++
 drivers/mfd/Kconfig|  16 ++
 drivers/mfd/Makefile   |   1 +
 drivers/mfd/stpmic1.c  | 213 +
 drivers/regulator/stpmic1_regulator.c  |   2 +-
 drivers/watchdog/Kconfig   |  12 ++
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 ++
 include/dt-bindings/mfd/st,stpmic1.h   |  50 +
 include/linux/mfd/stpmic1.h| 212 
 15 files changed, 956 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
 create mode 100644 drivers/input/misc/stpmic1_onkey.c
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 drivers/watchdog/stpmic1_wdt.c
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h
 create mode 100644 include/linux/mfd/stpmic1.h

-- 
1.9.1


[PATCH v7 3/7] dt-bindings: input: document stpmic1 pmic onkey

2018-11-30 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. It can be configured
to shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
---
changes in v7: nothing

 .../devicetree/bindings/input/st,stpmic1-onkey.txt | 28 ++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt

diff --git a/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt 
b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
new file mode 100644
index 000..4494613
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
@@ -0,0 +1,28 @@
+STMicroelectronics STPMIC1 Onkey
+
+Required properties:
+
+- compatible = "st,stpmic1-onkey";
+- interrupts: interrupt line to use
+- interrupt-names = "onkey-falling", "onkey-rising"
+   onkey-falling: happens when onkey is pressed; IT_PONKEY_F of pmic
+   onkey-rising: happens when onkey is released; IT_PONKEY_R of pmic
+
+Optional properties:
+
+- st,onkey-clear-cc-flag: onkey is able power on after an
+  over-current shutdown event.
+- st,onkey-pu-inactive: onkey pull up is not active
+- power-off-time-sec: Duration in seconds which the key should be kept
+pressed for device to power off automatically (from 1 to 16 seconds).
+see See Documentation/devicetree/bindings/input/keys.txt
+
+Example:
+
+onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupt-parent = <>;
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+};
-- 
1.9.1


[PATCH v7 3/7] dt-bindings: input: document stpmic1 pmic onkey

2018-11-30 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. It can be configured
to shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
---
changes in v7: nothing

 .../devicetree/bindings/input/st,stpmic1-onkey.txt | 28 ++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt

diff --git a/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt 
b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
new file mode 100644
index 000..4494613
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
@@ -0,0 +1,28 @@
+STMicroelectronics STPMIC1 Onkey
+
+Required properties:
+
+- compatible = "st,stpmic1-onkey";
+- interrupts: interrupt line to use
+- interrupt-names = "onkey-falling", "onkey-rising"
+   onkey-falling: happens when onkey is pressed; IT_PONKEY_F of pmic
+   onkey-rising: happens when onkey is released; IT_PONKEY_R of pmic
+
+Optional properties:
+
+- st,onkey-clear-cc-flag: onkey is able power on after an
+  over-current shutdown event.
+- st,onkey-pu-inactive: onkey pull up is not active
+- power-off-time-sec: Duration in seconds which the key should be kept
+pressed for device to power off automatically (from 1 to 16 seconds).
+see See Documentation/devicetree/bindings/input/keys.txt
+
+Example:
+
+onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupt-parent = <>;
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+};
-- 
1.9.1


[PATCH v7 2/7] mfd: stpmic1: add stpmic1 driver

2018-11-30 Thread Pascal PAILLET-LME
STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
Acked-for-MFD-by: Lee Jones 
---
changes in v7: nothing

 drivers/mfd/Kconfig |  16 
 drivers/mfd/Makefile|   1 +
 drivers/mfd/stpmic1.c   | 213 
 include/linux/mfd/stpmic1.h | 212 +++
 4 files changed, 442 insertions(+)
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 include/linux/mfd/stpmic1.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 8c5dfdc..0761cb8 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1871,6 +1871,22 @@ config MFD_STM32_TIMERS
  for PWM and IIO Timer. This driver allow to share the
  registers between the others drivers.
 
+config MFD_STPMIC1
+   tristate "Support for STPMIC1 PMIC"
+   depends on (I2C=y && OF)
+   select REGMAP_I2C
+   select REGMAP_IRQ
+   select MFD_CORE
+   help
+ Support for ST Microelectronics STPMIC1 PMIC. STPMIC1 has power on
+ key, watchdog and regulator functionalities which are supported via
+ the relevant subsystems. This driver provides core support for the
+ STPMIC1. In order to use the actual functionaltiy of the device other
+ drivers must be enabled.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1.
+
 menu "Multimedia Capabilities Port drivers"
depends on ARCH_SA1100
 
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 12980a4..a62fb01 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -233,6 +233,7 @@ obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI)   += 
intel_soc_pmic_chtdc_ti.o
 obj-$(CONFIG_MFD_MT6397)   += mt6397-core.o
 
 obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o
+obj-$(CONFIG_MFD_STPMIC1)  += stpmic1.o
 obj-$(CONFIG_MFD_SUN4I_GPADC)  += sun4i-gpadc.o
 
 obj-$(CONFIG_MFD_STM32_LPTIMER)+= stm32-lptimer.o
diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
new file mode 100644
index 000..7dfbe89
--- /dev/null
+++ b/drivers/mfd/stpmic1.c
@@ -0,0 +1,213 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define STPMIC1_MAIN_IRQ 0
+
+static const struct regmap_range stpmic1_readable_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_MASK_R1, INT_MASK_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R1),
+};
+
+static const struct regmap_range stpmic1_writeable_ranges[] = {
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+};
+
+static const struct regmap_range stpmic1_volatile_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(WCHDG_CR, WCHDG_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R4),
+};
+
+static const struct regmap_access_table stpmic1_readable_table = {
+   .yes_ranges = stpmic1_readable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_readable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_writeable_table = {
+   .yes_ranges = stpmic1_writeable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_writeable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_volatile_table = {
+   .yes_ranges = stpmic1_volatile_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_volatile_ranges),
+};
+
+const struct regmap_config stpmic1_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .cache_type = REGCACHE_RBTREE,
+   .max_register = PMIC_MAX_REGISTER_ADDRESS,
+   .rd_table = _readable_table,
+   .wr_table = _writeable_table,
+   .volatile_table = _volatile_table,
+};
+
+static const struct regmap_irq stpmic1_irqs[] = {
+   REGMAP_IRQ_REG(IT_PONKEY_F, 0, 0x01),
+   REGMAP_IRQ_REG(IT_PONKEY_R, 0, 0x02),
+   REGMAP_IRQ_REG(IT_WAKEUP_F, 0, 0x04),
+   REGMAP_IRQ_REG(IT_WAKEUP_R, 0, 0x08),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_F, 0, 0x10),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_R, 0, 0x20),
+   REGMAP_IRQ_REG(IT_SWOUT_F, 0, 0x40),
+   

[PATCH v7 2/7] mfd: stpmic1: add stpmic1 driver

2018-11-30 Thread Pascal PAILLET-LME
STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
Acked-for-MFD-by: Lee Jones 
---
changes in v7: nothing

 drivers/mfd/Kconfig |  16 
 drivers/mfd/Makefile|   1 +
 drivers/mfd/stpmic1.c   | 213 
 include/linux/mfd/stpmic1.h | 212 +++
 4 files changed, 442 insertions(+)
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 include/linux/mfd/stpmic1.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 8c5dfdc..0761cb8 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1871,6 +1871,22 @@ config MFD_STM32_TIMERS
  for PWM and IIO Timer. This driver allow to share the
  registers between the others drivers.
 
+config MFD_STPMIC1
+   tristate "Support for STPMIC1 PMIC"
+   depends on (I2C=y && OF)
+   select REGMAP_I2C
+   select REGMAP_IRQ
+   select MFD_CORE
+   help
+ Support for ST Microelectronics STPMIC1 PMIC. STPMIC1 has power on
+ key, watchdog and regulator functionalities which are supported via
+ the relevant subsystems. This driver provides core support for the
+ STPMIC1. In order to use the actual functionaltiy of the device other
+ drivers must be enabled.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1.
+
 menu "Multimedia Capabilities Port drivers"
depends on ARCH_SA1100
 
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 12980a4..a62fb01 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -233,6 +233,7 @@ obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI)   += 
intel_soc_pmic_chtdc_ti.o
 obj-$(CONFIG_MFD_MT6397)   += mt6397-core.o
 
 obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o
+obj-$(CONFIG_MFD_STPMIC1)  += stpmic1.o
 obj-$(CONFIG_MFD_SUN4I_GPADC)  += sun4i-gpadc.o
 
 obj-$(CONFIG_MFD_STM32_LPTIMER)+= stm32-lptimer.o
diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
new file mode 100644
index 000..7dfbe89
--- /dev/null
+++ b/drivers/mfd/stpmic1.c
@@ -0,0 +1,213 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define STPMIC1_MAIN_IRQ 0
+
+static const struct regmap_range stpmic1_readable_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_MASK_R1, INT_MASK_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R1),
+};
+
+static const struct regmap_range stpmic1_writeable_ranges[] = {
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+};
+
+static const struct regmap_range stpmic1_volatile_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(WCHDG_CR, WCHDG_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R4),
+};
+
+static const struct regmap_access_table stpmic1_readable_table = {
+   .yes_ranges = stpmic1_readable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_readable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_writeable_table = {
+   .yes_ranges = stpmic1_writeable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_writeable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_volatile_table = {
+   .yes_ranges = stpmic1_volatile_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_volatile_ranges),
+};
+
+const struct regmap_config stpmic1_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .cache_type = REGCACHE_RBTREE,
+   .max_register = PMIC_MAX_REGISTER_ADDRESS,
+   .rd_table = _readable_table,
+   .wr_table = _writeable_table,
+   .volatile_table = _volatile_table,
+};
+
+static const struct regmap_irq stpmic1_irqs[] = {
+   REGMAP_IRQ_REG(IT_PONKEY_F, 0, 0x01),
+   REGMAP_IRQ_REG(IT_PONKEY_R, 0, 0x02),
+   REGMAP_IRQ_REG(IT_WAKEUP_F, 0, 0x04),
+   REGMAP_IRQ_REG(IT_WAKEUP_R, 0, 0x08),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_F, 0, 0x10),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_R, 0, 0x20),
+   REGMAP_IRQ_REG(IT_SWOUT_F, 0, 0x40),
+   

[PATCH v7 4/7] input: stpmic1: add stpmic1 onkey driver

2018-11-30 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. This driver exposes
the stpmic1 onkey as an input device. It can also be configured to
shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
Acked-by: Dmitry Torokhov 
---
changes in v7: nothing

 drivers/input/misc/Kconfig |  11 +++
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 +
 3 files changed, 211 insertions(+)
 create mode 100644 drivers/input/misc/stpmic1_onkey.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index ca59a2b..279fb02 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -851,4 +851,15 @@ config INPUT_SC27XX_VIBRA
  To compile this driver as a module, choose M here. The module will
  be called sc27xx_vibra.
 
+config INPUT_STPMIC1_ONKEY
+   tristate "STPMIC1 PMIC Onkey support"
+   depends on MFD_STPMIC1
+   help
+ Say Y to enable support of onkey embedded into STPMIC1 PMIC. onkey
+ can be used to wakeup from low power modes and force a shut-down on
+ long press.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1_onkey.
+
 endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 9d0f9d1..1b44202 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_INPUT_SGI_BTNS)  += sgi_btns.o
 obj-$(CONFIG_INPUT_SIRFSOC_ONKEY)  += sirfsoc-onkey.o
 obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY)   += soc_button_array.o
 obj-$(CONFIG_INPUT_SPARCSPKR)  += sparcspkr.o
+obj-$(CONFIG_INPUT_STPMIC1_ONKEY)  += stpmic1_onkey.o
 obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON) += tps65218-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON)  += twl4030-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_VIBRA)  += twl4030-vibra.o
@@ -81,3 +82,4 @@ obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
 obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)+= xen-kbdfront.o
 obj-$(CONFIG_INPUT_YEALINK)+= yealink.o
 obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR)   += ideapad_slidebar.o
+
diff --git a/drivers/input/misc/stpmic1_onkey.c 
b/drivers/input/misc/stpmic1_onkey.c
new file mode 100644
index 000..7b49c99
--- /dev/null
+++ b/drivers/input/misc/stpmic1_onkey.c
@@ -0,0 +1,198 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * struct stpmic1_onkey - OnKey data
+ * @input_dev: pointer to input device
+ * @irq_falling:   irq that we are hooked on to
+ * @irq_rising:irq that we are hooked on to
+ */
+struct stpmic1_onkey {
+   struct input_dev *input_dev;
+   int irq_falling;
+   int irq_rising;
+};
+
+static irqreturn_t onkey_falling_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 1);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static irqreturn_t onkey_rising_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 0);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static int stpmic1_onkey_probe(struct platform_device *pdev)
+{
+   struct stpmic1 *pmic = dev_get_drvdata(pdev->dev.parent);
+   struct device *dev = >dev;
+   struct input_dev *input_dev;
+   struct stpmic1_onkey *onkey;
+   unsigned int val, reg = 0;
+   int error;
+
+   onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->irq_falling = platform_get_irq_byname(pdev, "onkey-falling");
+   if (onkey->irq_falling < 0) {
+   dev_err(dev, "failed: request IRQ onkey-falling %d\n",
+   onkey->irq_falling);
+   return onkey->irq_falling;
+   }
+
+   onkey->irq_rising = platform_get_irq_byname(pdev, "onkey-rising");
+   if (onkey->irq_rising < 0) {
+   dev_err(dev, "failed: request IRQ onkey-rising %d\n",
+   onkey->irq_rising);
+   return onkey->irq_rising;
+   }
+
+   if (!device_property_read_u32(dev, "power-off-time-sec", )) {
+   if (val > 0 && val <= 16) {
+   dev_dbg(dev, "power-off-time=%d seconds\n", val);
+   reg |= PONKEY_PWR_OFF;
+   reg |= ((16 - val) & PONKEY_TURNOFF_TIMER_MASK);
+   } else {
+   dev_err(dev, 

[PATCH v7 5/7] dt-bindings: watchdog: document stpmic1 pmic watchdog

2018-11-30 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default.
In case of watchdog, the PMIC goes off.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
Reviewed-by: Guenter Roeck 
---
changes in v7: nothing

 Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt

diff --git a/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt 
b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
new file mode 100644
index 000..7cc1407
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
@@ -0,0 +1,11 @@
+STMicroelectronics STPMIC1 Watchdog
+
+Required properties:
+
+- compatible : should be "st,stpmic1-wdt"
+
+Example:
+
+watchdog {
+   compatible = "st,stpmic1-wdt";
+};
-- 
1.9.1


[PATCH v7 1/7] dt-bindings: mfd: document stpmic1

2018-11-30 Thread Pascal PAILLET-LME
STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
Acked-for-MFD-by: Lee Jones 
---
changes in v7: nothing

 .../devicetree/bindings/mfd/st,stpmic1.txt | 61 ++
 include/dt-bindings/mfd/st,stpmic1.h   | 50 ++
 2 files changed, 111 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h

diff --git a/Documentation/devicetree/bindings/mfd/st,stpmic1.txt 
b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
new file mode 100644
index 000..afd45c0
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
@@ -0,0 +1,61 @@
+* STMicroelectronics STPMIC1 Power Management IC
+
+Required properties:
+- compatible:  : "st,stpmic1"
+- reg: : The I2C slave address for the STPMIC1 chip.
+- interrupts:  : The interrupt line the device is connected to.
+- #interrupt-cells:: Should be 1.
+- interrupt-controller:: Marks the device node as an interrupt 
controller.
+   Interrupt numbers are defined at
+   dt-bindings/mfd/st,stpmic1.h.
+
+STPMIC1 consists in a varied group of sub-devices.
+Each sub-device binding is be described in own documentation file.
+
+Device  Description
+-- 
+st,stpmic1-onkey   : Power on key, see ../input/st,stpmic1-onkey.txt
+st,stpmic1-regulators  : Regulators, see ../regulator/st,stpmic1-regulator.txt
+st,stpmic1-wdt : Watchdog, see ../watchdog/st,stpmic1-wdt.txt
+
+Example:
+
+#include 
+
+pmic: pmic@33 {
+   compatible = "st,stpmic1";
+   reg = <0x33>;
+   interrupt-parent = <>;
+   interrupts = <0 2>;
+
+   interrupt-controller;
+   #interrupt-cells = <2>;
+
+   onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+   };
+
+   watchdog {
+   compatible = "st,stpmic1-wdt";
+   };
+
+   regulators {
+   compatible = "st,stpmic1-regulators";
+
+   vdd_core: buck1 {
+   regulator-name = "vdd_core";
+   regulator-boot-on;
+   regulator-min-microvolt = <70>;
+   regulator-max-microvolt = <120>;
+   };
+   vdd: buck3 {
+   regulator-name = "vdd";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-boot-on;
+   regulator-pull-down;
+   };
+   };
diff --git a/include/dt-bindings/mfd/st,stpmic1.h 
b/include/dt-bindings/mfd/st,stpmic1.h
new file mode 100644
index 000..321cd087
--- /dev/null
+++ b/include/dt-bindings/mfd/st,stpmic1.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) STMicroelectronics 2018 - All Rights Reserved
+ * Author: Philippe Peurichard ,
+ * Pascal Paillet  for STMicroelectronics.
+ */
+
+#ifndef __DT_BINDINGS_STPMIC1_H__
+#define __DT_BINDINGS_STPMIC1_H__
+
+/* IRQ definitions */
+#define IT_PONKEY_F0
+#define IT_PONKEY_R1
+#define IT_WAKEUP_F2
+#define IT_WAKEUP_R3
+#define IT_VBUS_OTG_F  4
+#define IT_VBUS_OTG_R  5
+#define IT_SWOUT_F 6
+#define IT_SWOUT_R 7
+
+#define IT_CURLIM_BUCK18
+#define IT_CURLIM_BUCK29
+#define IT_CURLIM_BUCK310
+#define IT_CURLIM_BUCK411
+#define IT_OCP_OTG 12
+#define IT_OCP_SWOUT   13
+#define IT_OCP_BOOST   14
+#define IT_OVP_BOOST   15
+
+#define IT_CURLIM_LDO1 16
+#define IT_CURLIM_LDO2 17
+#define IT_CURLIM_LDO3 18
+#define IT_CURLIM_LDO4 19
+#define IT_CURLIM_LDO5 20
+#define IT_CURLIM_LDO6 21
+#define IT_SHORT_SWOTG 22
+#define IT_SHORT_SWOUT 23
+
+#define IT_TWARN_F 24
+#define IT_TWARN_R 25
+#define IT_VINLOW_F26
+#define IT_VINLOW_R27
+#define IT_SWIN_F  30
+#define IT_SWIN_R  31
+
+/* BUCK MODES definitions */
+#define STPMIC1_BUCK_MODE_NORMAL 0
+#define STPMIC1_BUCK_MODE_LP 2
+
+#endif /* __DT_BINDINGS_STPMIC1_H__ */
-- 
1.9.1


[PATCH v7 7/7] regulator: stpmic1: fix regulator_lock usage

2018-11-30 Thread Pascal PAILLET-LME
fix a compilation issue due to regulator_lock usage.

Signed-off-by: Pascal Paillet 
---
changes in v7: 
* new patch due to rebase on regul/for-next

 drivers/regulator/stpmic1_regulator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/regulator/stpmic1_regulator.c 
b/drivers/regulator/stpmic1_regulator.c
index eac0848..16ba029 100644
--- a/drivers/regulator/stpmic1_regulator.c
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -489,7 +489,7 @@ static irqreturn_t stpmic1_curlim_irq_handler(int irq, void 
*data)
 {
struct regulator_dev *rdev = (struct regulator_dev *)data;
 
-   regulator_lock(rdev, NULL);
+   regulator_lock(rdev);
 
/* Send an overcurrent notification */
regulator_notifier_call_chain(rdev,
-- 
1.9.1


[PATCH v7 7/7] regulator: stpmic1: fix regulator_lock usage

2018-11-30 Thread Pascal PAILLET-LME
fix a compilation issue due to regulator_lock usage.

Signed-off-by: Pascal Paillet 
---
changes in v7: 
* new patch due to rebase on regul/for-next

 drivers/regulator/stpmic1_regulator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/regulator/stpmic1_regulator.c 
b/drivers/regulator/stpmic1_regulator.c
index eac0848..16ba029 100644
--- a/drivers/regulator/stpmic1_regulator.c
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -489,7 +489,7 @@ static irqreturn_t stpmic1_curlim_irq_handler(int irq, void 
*data)
 {
struct regulator_dev *rdev = (struct regulator_dev *)data;
 
-   regulator_lock(rdev, NULL);
+   regulator_lock(rdev);
 
/* Send an overcurrent notification */
regulator_notifier_call_chain(rdev,
-- 
1.9.1


[PATCH v7 4/7] input: stpmic1: add stpmic1 onkey driver

2018-11-30 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. This driver exposes
the stpmic1 onkey as an input device. It can also be configured to
shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
Acked-by: Dmitry Torokhov 
---
changes in v7: nothing

 drivers/input/misc/Kconfig |  11 +++
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 +
 3 files changed, 211 insertions(+)
 create mode 100644 drivers/input/misc/stpmic1_onkey.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index ca59a2b..279fb02 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -851,4 +851,15 @@ config INPUT_SC27XX_VIBRA
  To compile this driver as a module, choose M here. The module will
  be called sc27xx_vibra.
 
+config INPUT_STPMIC1_ONKEY
+   tristate "STPMIC1 PMIC Onkey support"
+   depends on MFD_STPMIC1
+   help
+ Say Y to enable support of onkey embedded into STPMIC1 PMIC. onkey
+ can be used to wakeup from low power modes and force a shut-down on
+ long press.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1_onkey.
+
 endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 9d0f9d1..1b44202 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_INPUT_SGI_BTNS)  += sgi_btns.o
 obj-$(CONFIG_INPUT_SIRFSOC_ONKEY)  += sirfsoc-onkey.o
 obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY)   += soc_button_array.o
 obj-$(CONFIG_INPUT_SPARCSPKR)  += sparcspkr.o
+obj-$(CONFIG_INPUT_STPMIC1_ONKEY)  += stpmic1_onkey.o
 obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON) += tps65218-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON)  += twl4030-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_VIBRA)  += twl4030-vibra.o
@@ -81,3 +82,4 @@ obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
 obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)+= xen-kbdfront.o
 obj-$(CONFIG_INPUT_YEALINK)+= yealink.o
 obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR)   += ideapad_slidebar.o
+
diff --git a/drivers/input/misc/stpmic1_onkey.c 
b/drivers/input/misc/stpmic1_onkey.c
new file mode 100644
index 000..7b49c99
--- /dev/null
+++ b/drivers/input/misc/stpmic1_onkey.c
@@ -0,0 +1,198 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * struct stpmic1_onkey - OnKey data
+ * @input_dev: pointer to input device
+ * @irq_falling:   irq that we are hooked on to
+ * @irq_rising:irq that we are hooked on to
+ */
+struct stpmic1_onkey {
+   struct input_dev *input_dev;
+   int irq_falling;
+   int irq_rising;
+};
+
+static irqreturn_t onkey_falling_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 1);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static irqreturn_t onkey_rising_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 0);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static int stpmic1_onkey_probe(struct platform_device *pdev)
+{
+   struct stpmic1 *pmic = dev_get_drvdata(pdev->dev.parent);
+   struct device *dev = >dev;
+   struct input_dev *input_dev;
+   struct stpmic1_onkey *onkey;
+   unsigned int val, reg = 0;
+   int error;
+
+   onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->irq_falling = platform_get_irq_byname(pdev, "onkey-falling");
+   if (onkey->irq_falling < 0) {
+   dev_err(dev, "failed: request IRQ onkey-falling %d\n",
+   onkey->irq_falling);
+   return onkey->irq_falling;
+   }
+
+   onkey->irq_rising = platform_get_irq_byname(pdev, "onkey-rising");
+   if (onkey->irq_rising < 0) {
+   dev_err(dev, "failed: request IRQ onkey-rising %d\n",
+   onkey->irq_rising);
+   return onkey->irq_rising;
+   }
+
+   if (!device_property_read_u32(dev, "power-off-time-sec", )) {
+   if (val > 0 && val <= 16) {
+   dev_dbg(dev, "power-off-time=%d seconds\n", val);
+   reg |= PONKEY_PWR_OFF;
+   reg |= ((16 - val) & PONKEY_TURNOFF_TIMER_MASK);
+   } else {
+   dev_err(dev, 

[PATCH v7 5/7] dt-bindings: watchdog: document stpmic1 pmic watchdog

2018-11-30 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default.
In case of watchdog, the PMIC goes off.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
Reviewed-by: Guenter Roeck 
---
changes in v7: nothing

 Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt

diff --git a/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt 
b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
new file mode 100644
index 000..7cc1407
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
@@ -0,0 +1,11 @@
+STMicroelectronics STPMIC1 Watchdog
+
+Required properties:
+
+- compatible : should be "st,stpmic1-wdt"
+
+Example:
+
+watchdog {
+   compatible = "st,stpmic1-wdt";
+};
-- 
1.9.1


[PATCH v7 1/7] dt-bindings: mfd: document stpmic1

2018-11-30 Thread Pascal PAILLET-LME
STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
Acked-for-MFD-by: Lee Jones 
---
changes in v7: nothing

 .../devicetree/bindings/mfd/st,stpmic1.txt | 61 ++
 include/dt-bindings/mfd/st,stpmic1.h   | 50 ++
 2 files changed, 111 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h

diff --git a/Documentation/devicetree/bindings/mfd/st,stpmic1.txt 
b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
new file mode 100644
index 000..afd45c0
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
@@ -0,0 +1,61 @@
+* STMicroelectronics STPMIC1 Power Management IC
+
+Required properties:
+- compatible:  : "st,stpmic1"
+- reg: : The I2C slave address for the STPMIC1 chip.
+- interrupts:  : The interrupt line the device is connected to.
+- #interrupt-cells:: Should be 1.
+- interrupt-controller:: Marks the device node as an interrupt 
controller.
+   Interrupt numbers are defined at
+   dt-bindings/mfd/st,stpmic1.h.
+
+STPMIC1 consists in a varied group of sub-devices.
+Each sub-device binding is be described in own documentation file.
+
+Device  Description
+-- 
+st,stpmic1-onkey   : Power on key, see ../input/st,stpmic1-onkey.txt
+st,stpmic1-regulators  : Regulators, see ../regulator/st,stpmic1-regulator.txt
+st,stpmic1-wdt : Watchdog, see ../watchdog/st,stpmic1-wdt.txt
+
+Example:
+
+#include 
+
+pmic: pmic@33 {
+   compatible = "st,stpmic1";
+   reg = <0x33>;
+   interrupt-parent = <>;
+   interrupts = <0 2>;
+
+   interrupt-controller;
+   #interrupt-cells = <2>;
+
+   onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+   };
+
+   watchdog {
+   compatible = "st,stpmic1-wdt";
+   };
+
+   regulators {
+   compatible = "st,stpmic1-regulators";
+
+   vdd_core: buck1 {
+   regulator-name = "vdd_core";
+   regulator-boot-on;
+   regulator-min-microvolt = <70>;
+   regulator-max-microvolt = <120>;
+   };
+   vdd: buck3 {
+   regulator-name = "vdd";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-boot-on;
+   regulator-pull-down;
+   };
+   };
diff --git a/include/dt-bindings/mfd/st,stpmic1.h 
b/include/dt-bindings/mfd/st,stpmic1.h
new file mode 100644
index 000..321cd087
--- /dev/null
+++ b/include/dt-bindings/mfd/st,stpmic1.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) STMicroelectronics 2018 - All Rights Reserved
+ * Author: Philippe Peurichard ,
+ * Pascal Paillet  for STMicroelectronics.
+ */
+
+#ifndef __DT_BINDINGS_STPMIC1_H__
+#define __DT_BINDINGS_STPMIC1_H__
+
+/* IRQ definitions */
+#define IT_PONKEY_F0
+#define IT_PONKEY_R1
+#define IT_WAKEUP_F2
+#define IT_WAKEUP_R3
+#define IT_VBUS_OTG_F  4
+#define IT_VBUS_OTG_R  5
+#define IT_SWOUT_F 6
+#define IT_SWOUT_R 7
+
+#define IT_CURLIM_BUCK18
+#define IT_CURLIM_BUCK29
+#define IT_CURLIM_BUCK310
+#define IT_CURLIM_BUCK411
+#define IT_OCP_OTG 12
+#define IT_OCP_SWOUT   13
+#define IT_OCP_BOOST   14
+#define IT_OVP_BOOST   15
+
+#define IT_CURLIM_LDO1 16
+#define IT_CURLIM_LDO2 17
+#define IT_CURLIM_LDO3 18
+#define IT_CURLIM_LDO4 19
+#define IT_CURLIM_LDO5 20
+#define IT_CURLIM_LDO6 21
+#define IT_SHORT_SWOTG 22
+#define IT_SHORT_SWOUT 23
+
+#define IT_TWARN_F 24
+#define IT_TWARN_R 25
+#define IT_VINLOW_F26
+#define IT_VINLOW_R27
+#define IT_SWIN_F  30
+#define IT_SWIN_R  31
+
+/* BUCK MODES definitions */
+#define STPMIC1_BUCK_MODE_NORMAL 0
+#define STPMIC1_BUCK_MODE_LP 2
+
+#endif /* __DT_BINDINGS_STPMIC1_H__ */
-- 
1.9.1


[PATCH v7 6/7] watchdog: stpmic1: add stpmic1 watchdog driver

2018-11-30 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default. As soon
as the watchdog is started, it must be refreshed periodically otherwise
the PMIC goes off.

Signed-off-by: Pascal Paillet 
Reviewed-by: Guenter Roeck 
---
changes in v7: nothing

 drivers/watchdog/Kconfig   |  12 
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 +
 3 files changed, 152 insertions(+)
 create mode 100644 drivers/watchdog/stpmic1_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 2d64333..cc5155b 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -817,6 +817,18 @@ config STM32_WATCHDOG
  To compile this driver as a module, choose M here: the
  module will be called stm32_iwdg.
 
+config STPMIC1_WATCHDOG
+   tristate "STPMIC1 PMIC watchdog support"
+   depends on MFD_STPMIC1
+   select WATCHDOG_CORE
+   help
+ Say Y here to include watchdog support embedded into STPMIC1 PMIC.
+ If the watchdog timer expires, stpmic1 will shut down all its power
+ supplies.
+
+ To compile this driver as a module, choose M here: the
+ module will be called spmic1_wdt.
+
 config UNIPHIER_WATCHDOG
tristate "UniPhier watchdog support"
depends on ARCH_UNIPHIER || COMPILE_TEST
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index f69cdff..bdc072c 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -218,3 +218,4 @@ obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
 obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
 obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o
 obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
+obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o
diff --git a/drivers/watchdog/stpmic1_wdt.c b/drivers/watchdog/stpmic1_wdt.c
new file mode 100644
index 000..ad431d8
--- /dev/null
+++ b/drivers/watchdog/stpmic1_wdt.c
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* WATCHDOG CONTROL REGISTER bit */
+#define WDT_START  BIT(0)
+#define WDT_PING   BIT(1)
+#define WDT_START_MASK BIT(0)
+#define WDT_PING_MASK  BIT(1)
+#define WDT_STOP   0
+
+#define PMIC_WDT_MIN_TIMEOUT 1
+#define PMIC_WDT_MAX_TIMEOUT 256
+#define PMIC_WDT_DEFAULT_TIMEOUT 30
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct stpmic1_wdt {
+   struct stpmic1 *pmic;
+   struct watchdog_device wdtdev;
+};
+
+static int pmic_wdt_start(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_START);
+}
+
+static int pmic_wdt_stop(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_STOP);
+}
+
+static int pmic_wdt_ping(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_PING_MASK, WDT_PING);
+}
+
+static int pmic_wdt_set_timeout(struct watchdog_device *wdd,
+   unsigned int timeout)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   wdd->timeout = timeout;
+   /* timeout is equal to register value + 1 */
+   return regmap_write(wdt->pmic->regmap, WCHDG_TIMER_CR, timeout - 1);
+}
+
+static const struct watchdog_info pmic_watchdog_info = {
+   .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+   .identity = "STPMIC1 PMIC Watchdog",
+};
+
+static const struct watchdog_ops pmic_watchdog_ops = {
+   .owner = THIS_MODULE,
+   .start = pmic_wdt_start,
+   .stop = pmic_wdt_stop,
+   .ping = pmic_wdt_ping,
+   .set_timeout = pmic_wdt_set_timeout,
+};
+
+static int pmic_wdt_probe(struct platform_device *pdev)
+{
+   int ret;
+   struct stpmic1 *pmic;
+   struct stpmic1_wdt *wdt;
+
+   if (!pdev->dev.parent)
+   return -EINVAL;
+
+   pmic = dev_get_drvdata(pdev->dev.parent);
+   if (!pmic)
+   return -EINVAL;
+
+   wdt = devm_kzalloc(>dev, sizeof(struct stpmic1_wdt), GFP_KERNEL);
+   if (!wdt)
+   return -ENOMEM;
+
+   wdt->pmic = pmic;
+
+   wdt->wdtdev.info = _watchdog_info;
+   wdt->wdtdev.ops = _watchdog_ops;
+   wdt->wdtdev.min_timeout = PMIC_WDT_MIN_TIMEOUT;
+   

[PATCH v7 6/7] watchdog: stpmic1: add stpmic1 watchdog driver

2018-11-30 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default. As soon
as the watchdog is started, it must be refreshed periodically otherwise
the PMIC goes off.

Signed-off-by: Pascal Paillet 
Reviewed-by: Guenter Roeck 
---
changes in v7: nothing

 drivers/watchdog/Kconfig   |  12 
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 +
 3 files changed, 152 insertions(+)
 create mode 100644 drivers/watchdog/stpmic1_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 2d64333..cc5155b 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -817,6 +817,18 @@ config STM32_WATCHDOG
  To compile this driver as a module, choose M here: the
  module will be called stm32_iwdg.
 
+config STPMIC1_WATCHDOG
+   tristate "STPMIC1 PMIC watchdog support"
+   depends on MFD_STPMIC1
+   select WATCHDOG_CORE
+   help
+ Say Y here to include watchdog support embedded into STPMIC1 PMIC.
+ If the watchdog timer expires, stpmic1 will shut down all its power
+ supplies.
+
+ To compile this driver as a module, choose M here: the
+ module will be called spmic1_wdt.
+
 config UNIPHIER_WATCHDOG
tristate "UniPhier watchdog support"
depends on ARCH_UNIPHIER || COMPILE_TEST
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index f69cdff..bdc072c 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -218,3 +218,4 @@ obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
 obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
 obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o
 obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
+obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o
diff --git a/drivers/watchdog/stpmic1_wdt.c b/drivers/watchdog/stpmic1_wdt.c
new file mode 100644
index 000..ad431d8
--- /dev/null
+++ b/drivers/watchdog/stpmic1_wdt.c
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* WATCHDOG CONTROL REGISTER bit */
+#define WDT_START  BIT(0)
+#define WDT_PING   BIT(1)
+#define WDT_START_MASK BIT(0)
+#define WDT_PING_MASK  BIT(1)
+#define WDT_STOP   0
+
+#define PMIC_WDT_MIN_TIMEOUT 1
+#define PMIC_WDT_MAX_TIMEOUT 256
+#define PMIC_WDT_DEFAULT_TIMEOUT 30
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct stpmic1_wdt {
+   struct stpmic1 *pmic;
+   struct watchdog_device wdtdev;
+};
+
+static int pmic_wdt_start(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_START);
+}
+
+static int pmic_wdt_stop(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_STOP);
+}
+
+static int pmic_wdt_ping(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_PING_MASK, WDT_PING);
+}
+
+static int pmic_wdt_set_timeout(struct watchdog_device *wdd,
+   unsigned int timeout)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   wdd->timeout = timeout;
+   /* timeout is equal to register value + 1 */
+   return regmap_write(wdt->pmic->regmap, WCHDG_TIMER_CR, timeout - 1);
+}
+
+static const struct watchdog_info pmic_watchdog_info = {
+   .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+   .identity = "STPMIC1 PMIC Watchdog",
+};
+
+static const struct watchdog_ops pmic_watchdog_ops = {
+   .owner = THIS_MODULE,
+   .start = pmic_wdt_start,
+   .stop = pmic_wdt_stop,
+   .ping = pmic_wdt_ping,
+   .set_timeout = pmic_wdt_set_timeout,
+};
+
+static int pmic_wdt_probe(struct platform_device *pdev)
+{
+   int ret;
+   struct stpmic1 *pmic;
+   struct stpmic1_wdt *wdt;
+
+   if (!pdev->dev.parent)
+   return -EINVAL;
+
+   pmic = dev_get_drvdata(pdev->dev.parent);
+   if (!pmic)
+   return -EINVAL;
+
+   wdt = devm_kzalloc(>dev, sizeof(struct stpmic1_wdt), GFP_KERNEL);
+   if (!wdt)
+   return -ENOMEM;
+
+   wdt->pmic = pmic;
+
+   wdt->wdtdev.info = _watchdog_info;
+   wdt->wdtdev.ops = _watchdog_ops;
+   wdt->wdtdev.min_timeout = PMIC_WDT_MIN_TIMEOUT;
+   

Re: [PATCH v6 3/8] dt-bindings: regulator: document stpmic1 pmic regulators

2018-11-30 Thread Pascal PAILLET-LME
Le 11/28/2018 10:48 AM, Mark Brown a écrit :
> On Tue, Nov 27, 2018 at 04:52:15PM +0000, Pascal PAILLET-LME wrote:
>> The STPMIC1 regulators supply power to the application processor as well as
>> to the external system peripherals such as DDR, Flash memories and system
>> devices.
> Please do not submit new versions of already applied patches, please
> submit incremental updates to the existing code.  Modifying existing
> commits creates problems for other users building on top of those
> commits so it's best practice to only change pubished git commits if
> absolutely essential.

Sorry Mark, I will submit my changes on the regulator driver in separate 
patches.

pascal



Re: [PATCH v6 3/8] dt-bindings: regulator: document stpmic1 pmic regulators

2018-11-30 Thread Pascal PAILLET-LME
Le 11/28/2018 10:48 AM, Mark Brown a écrit :
> On Tue, Nov 27, 2018 at 04:52:15PM +0000, Pascal PAILLET-LME wrote:
>> The STPMIC1 regulators supply power to the application processor as well as
>> to the external system peripherals such as DDR, Flash memories and system
>> devices.
> Please do not submit new versions of already applied patches, please
> submit incremental updates to the existing code.  Modifying existing
> commits creates problems for other users building on top of those
> commits so it's best practice to only change pubished git commits if
> absolutely essential.

Sorry Mark, I will submit my changes on the regulator driver in separate 
patches.

pascal



[PATCH v6 7/8] dt-bindings: watchdog: document stpmic1 pmic watchdog

2018-11-27 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default.
In case of watchdog, the PMIC goes off.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
Reviewed-by: Guenter Roeck 
---
changes in v6: nothing

 Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt

diff --git a/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt 
b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
new file mode 100644
index 000..7cc1407
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
@@ -0,0 +1,11 @@
+STMicroelectronics STPMIC1 Watchdog
+
+Required properties:
+
+- compatible : should be "st,stpmic1-wdt"
+
+Example:
+
+watchdog {
+   compatible = "st,stpmic1-wdt";
+};
-- 
1.9.1


[PATCH v6 7/8] dt-bindings: watchdog: document stpmic1 pmic watchdog

2018-11-27 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default.
In case of watchdog, the PMIC goes off.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
Reviewed-by: Guenter Roeck 
---
changes in v6: nothing

 Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt

diff --git a/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt 
b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
new file mode 100644
index 000..7cc1407
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
@@ -0,0 +1,11 @@
+STMicroelectronics STPMIC1 Watchdog
+
+Required properties:
+
+- compatible : should be "st,stpmic1-wdt"
+
+Example:
+
+watchdog {
+   compatible = "st,stpmic1-wdt";
+};
-- 
1.9.1


[PATCH v6 8/8] watchdog: stpmic1: add stpmic1 watchdog driver

2018-11-27 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default. As soon
as the watchdog is started, it must be refreshed periodically otherwise
the PMIC goes off.

Signed-off-by: Pascal Paillet 
Reviewed-by: Guenter Roeck 
---
changes in v6: nothing

 drivers/watchdog/Kconfig   |  12 
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 +
 3 files changed, 152 insertions(+)
 create mode 100644 drivers/watchdog/stpmic1_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 5ea8909..6d2ffef 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -806,6 +806,18 @@ config STM32_WATCHDOG
  To compile this driver as a module, choose M here: the
  module will be called stm32_iwdg.
 
+config STPMIC1_WATCHDOG
+   tristate "STPMIC1 PMIC watchdog support"
+   depends on MFD_STPMIC1
+   select WATCHDOG_CORE
+   help
+ Say Y here to include watchdog support embedded into STPMIC1 PMIC.
+ If the watchdog timer expires, stpmic1 will shut down all its power
+ supplies.
+
+ To compile this driver as a module, choose M here: the
+ module will be called spmic1_wdt.
+
 config UNIPHIER_WATCHDOG
tristate "UniPhier watchdog support"
depends on ARCH_UNIPHIER || COMPILE_TEST
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index bf92e7b..2649cf3 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -217,3 +217,4 @@ obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
 obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
 obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o
 obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
+obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o
diff --git a/drivers/watchdog/stpmic1_wdt.c b/drivers/watchdog/stpmic1_wdt.c
new file mode 100644
index 000..ad431d8
--- /dev/null
+++ b/drivers/watchdog/stpmic1_wdt.c
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* WATCHDOG CONTROL REGISTER bit */
+#define WDT_START  BIT(0)
+#define WDT_PING   BIT(1)
+#define WDT_START_MASK BIT(0)
+#define WDT_PING_MASK  BIT(1)
+#define WDT_STOP   0
+
+#define PMIC_WDT_MIN_TIMEOUT 1
+#define PMIC_WDT_MAX_TIMEOUT 256
+#define PMIC_WDT_DEFAULT_TIMEOUT 30
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct stpmic1_wdt {
+   struct stpmic1 *pmic;
+   struct watchdog_device wdtdev;
+};
+
+static int pmic_wdt_start(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_START);
+}
+
+static int pmic_wdt_stop(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_STOP);
+}
+
+static int pmic_wdt_ping(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_PING_MASK, WDT_PING);
+}
+
+static int pmic_wdt_set_timeout(struct watchdog_device *wdd,
+   unsigned int timeout)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   wdd->timeout = timeout;
+   /* timeout is equal to register value + 1 */
+   return regmap_write(wdt->pmic->regmap, WCHDG_TIMER_CR, timeout - 1);
+}
+
+static const struct watchdog_info pmic_watchdog_info = {
+   .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+   .identity = "STPMIC1 PMIC Watchdog",
+};
+
+static const struct watchdog_ops pmic_watchdog_ops = {
+   .owner = THIS_MODULE,
+   .start = pmic_wdt_start,
+   .stop = pmic_wdt_stop,
+   .ping = pmic_wdt_ping,
+   .set_timeout = pmic_wdt_set_timeout,
+};
+
+static int pmic_wdt_probe(struct platform_device *pdev)
+{
+   int ret;
+   struct stpmic1 *pmic;
+   struct stpmic1_wdt *wdt;
+
+   if (!pdev->dev.parent)
+   return -EINVAL;
+
+   pmic = dev_get_drvdata(pdev->dev.parent);
+   if (!pmic)
+   return -EINVAL;
+
+   wdt = devm_kzalloc(>dev, sizeof(struct stpmic1_wdt), GFP_KERNEL);
+   if (!wdt)
+   return -ENOMEM;
+
+   wdt->pmic = pmic;
+
+   wdt->wdtdev.info = _watchdog_info;
+   wdt->wdtdev.ops = _watchdog_ops;
+   wdt->wdtdev.min_timeout = PMIC_WDT_MIN_TIMEOUT;
+   

[PATCH v6 8/8] watchdog: stpmic1: add stpmic1 watchdog driver

2018-11-27 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default. As soon
as the watchdog is started, it must be refreshed periodically otherwise
the PMIC goes off.

Signed-off-by: Pascal Paillet 
Reviewed-by: Guenter Roeck 
---
changes in v6: nothing

 drivers/watchdog/Kconfig   |  12 
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 +
 3 files changed, 152 insertions(+)
 create mode 100644 drivers/watchdog/stpmic1_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 5ea8909..6d2ffef 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -806,6 +806,18 @@ config STM32_WATCHDOG
  To compile this driver as a module, choose M here: the
  module will be called stm32_iwdg.
 
+config STPMIC1_WATCHDOG
+   tristate "STPMIC1 PMIC watchdog support"
+   depends on MFD_STPMIC1
+   select WATCHDOG_CORE
+   help
+ Say Y here to include watchdog support embedded into STPMIC1 PMIC.
+ If the watchdog timer expires, stpmic1 will shut down all its power
+ supplies.
+
+ To compile this driver as a module, choose M here: the
+ module will be called spmic1_wdt.
+
 config UNIPHIER_WATCHDOG
tristate "UniPhier watchdog support"
depends on ARCH_UNIPHIER || COMPILE_TEST
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index bf92e7b..2649cf3 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -217,3 +217,4 @@ obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
 obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
 obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o
 obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
+obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o
diff --git a/drivers/watchdog/stpmic1_wdt.c b/drivers/watchdog/stpmic1_wdt.c
new file mode 100644
index 000..ad431d8
--- /dev/null
+++ b/drivers/watchdog/stpmic1_wdt.c
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* WATCHDOG CONTROL REGISTER bit */
+#define WDT_START  BIT(0)
+#define WDT_PING   BIT(1)
+#define WDT_START_MASK BIT(0)
+#define WDT_PING_MASK  BIT(1)
+#define WDT_STOP   0
+
+#define PMIC_WDT_MIN_TIMEOUT 1
+#define PMIC_WDT_MAX_TIMEOUT 256
+#define PMIC_WDT_DEFAULT_TIMEOUT 30
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct stpmic1_wdt {
+   struct stpmic1 *pmic;
+   struct watchdog_device wdtdev;
+};
+
+static int pmic_wdt_start(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_START);
+}
+
+static int pmic_wdt_stop(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_STOP);
+}
+
+static int pmic_wdt_ping(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_PING_MASK, WDT_PING);
+}
+
+static int pmic_wdt_set_timeout(struct watchdog_device *wdd,
+   unsigned int timeout)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   wdd->timeout = timeout;
+   /* timeout is equal to register value + 1 */
+   return regmap_write(wdt->pmic->regmap, WCHDG_TIMER_CR, timeout - 1);
+}
+
+static const struct watchdog_info pmic_watchdog_info = {
+   .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+   .identity = "STPMIC1 PMIC Watchdog",
+};
+
+static const struct watchdog_ops pmic_watchdog_ops = {
+   .owner = THIS_MODULE,
+   .start = pmic_wdt_start,
+   .stop = pmic_wdt_stop,
+   .ping = pmic_wdt_ping,
+   .set_timeout = pmic_wdt_set_timeout,
+};
+
+static int pmic_wdt_probe(struct platform_device *pdev)
+{
+   int ret;
+   struct stpmic1 *pmic;
+   struct stpmic1_wdt *wdt;
+
+   if (!pdev->dev.parent)
+   return -EINVAL;
+
+   pmic = dev_get_drvdata(pdev->dev.parent);
+   if (!pmic)
+   return -EINVAL;
+
+   wdt = devm_kzalloc(>dev, sizeof(struct stpmic1_wdt), GFP_KERNEL);
+   if (!wdt)
+   return -ENOMEM;
+
+   wdt->pmic = pmic;
+
+   wdt->wdtdev.info = _watchdog_info;
+   wdt->wdtdev.ops = _watchdog_ops;
+   wdt->wdtdev.min_timeout = PMIC_WDT_MIN_TIMEOUT;
+   

[PATCH v6 2/8] mfd: stpmic1: add stpmic1 driver

2018-11-27 Thread Pascal PAILLET-LME
STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
---
changes in v6:
* replace i2c_device_id by of_device_id
* fix commit message and Kconfig description

 drivers/mfd/Kconfig |  16 
 drivers/mfd/Makefile|   1 +
 drivers/mfd/stpmic1.c   | 213 
 include/linux/mfd/stpmic1.h | 212 +++
 4 files changed, 442 insertions(+)
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 include/linux/mfd/stpmic1.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 11841f4..0677bac 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1855,6 +1855,22 @@ config MFD_STM32_TIMERS
  for PWM and IIO Timer. This driver allow to share the
  registers between the others drivers.
 
+config MFD_STPMIC1
+   tristate "Support for STPMIC1 PMIC"
+   depends on (I2C=y && OF)
+   select REGMAP_I2C
+   select REGMAP_IRQ
+   select MFD_CORE
+   help
+ Support for ST Microelectronics STPMIC1 PMIC. STPMIC1 has power on
+ key, watchdog and regulator functionalities which are supported via
+ the relevant subsystems. This driver provides core support for the
+ STPMIC1. In order to use the actual functionaltiy of the device other
+ drivers must be enabled.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1.
+
 menu "Multimedia Capabilities Port drivers"
depends on ARCH_SA1100
 
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 5856a94..76fff14 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -232,6 +232,7 @@ obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI)   += 
intel_soc_pmic_chtdc_ti.o
 obj-$(CONFIG_MFD_MT6397)   += mt6397-core.o
 
 obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o
+obj-$(CONFIG_MFD_STPMIC1)  += stpmic1.o
 obj-$(CONFIG_MFD_SUN4I_GPADC)  += sun4i-gpadc.o
 
 obj-$(CONFIG_MFD_STM32_LPTIMER)+= stm32-lptimer.o
diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
new file mode 100644
index 000..7dfbe89
--- /dev/null
+++ b/drivers/mfd/stpmic1.c
@@ -0,0 +1,213 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define STPMIC1_MAIN_IRQ 0
+
+static const struct regmap_range stpmic1_readable_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_MASK_R1, INT_MASK_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R1),
+};
+
+static const struct regmap_range stpmic1_writeable_ranges[] = {
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+};
+
+static const struct regmap_range stpmic1_volatile_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(WCHDG_CR, WCHDG_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R4),
+};
+
+static const struct regmap_access_table stpmic1_readable_table = {
+   .yes_ranges = stpmic1_readable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_readable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_writeable_table = {
+   .yes_ranges = stpmic1_writeable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_writeable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_volatile_table = {
+   .yes_ranges = stpmic1_volatile_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_volatile_ranges),
+};
+
+const struct regmap_config stpmic1_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .cache_type = REGCACHE_RBTREE,
+   .max_register = PMIC_MAX_REGISTER_ADDRESS,
+   .rd_table = _readable_table,
+   .wr_table = _writeable_table,
+   .volatile_table = _volatile_table,
+};
+
+static const struct regmap_irq stpmic1_irqs[] = {
+   REGMAP_IRQ_REG(IT_PONKEY_F, 0, 0x01),
+   REGMAP_IRQ_REG(IT_PONKEY_R, 0, 0x02),
+   REGMAP_IRQ_REG(IT_WAKEUP_F, 0, 0x04),
+   REGMAP_IRQ_REG(IT_WAKEUP_R, 0, 0x08),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_F, 0, 0x10),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_R, 0, 0x20),
+   

[PATCH v6 2/8] mfd: stpmic1: add stpmic1 driver

2018-11-27 Thread Pascal PAILLET-LME
STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
---
changes in v6:
* replace i2c_device_id by of_device_id
* fix commit message and Kconfig description

 drivers/mfd/Kconfig |  16 
 drivers/mfd/Makefile|   1 +
 drivers/mfd/stpmic1.c   | 213 
 include/linux/mfd/stpmic1.h | 212 +++
 4 files changed, 442 insertions(+)
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 include/linux/mfd/stpmic1.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 11841f4..0677bac 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1855,6 +1855,22 @@ config MFD_STM32_TIMERS
  for PWM and IIO Timer. This driver allow to share the
  registers between the others drivers.
 
+config MFD_STPMIC1
+   tristate "Support for STPMIC1 PMIC"
+   depends on (I2C=y && OF)
+   select REGMAP_I2C
+   select REGMAP_IRQ
+   select MFD_CORE
+   help
+ Support for ST Microelectronics STPMIC1 PMIC. STPMIC1 has power on
+ key, watchdog and regulator functionalities which are supported via
+ the relevant subsystems. This driver provides core support for the
+ STPMIC1. In order to use the actual functionaltiy of the device other
+ drivers must be enabled.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1.
+
 menu "Multimedia Capabilities Port drivers"
depends on ARCH_SA1100
 
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 5856a94..76fff14 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -232,6 +232,7 @@ obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI)   += 
intel_soc_pmic_chtdc_ti.o
 obj-$(CONFIG_MFD_MT6397)   += mt6397-core.o
 
 obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o
+obj-$(CONFIG_MFD_STPMIC1)  += stpmic1.o
 obj-$(CONFIG_MFD_SUN4I_GPADC)  += sun4i-gpadc.o
 
 obj-$(CONFIG_MFD_STM32_LPTIMER)+= stm32-lptimer.o
diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
new file mode 100644
index 000..7dfbe89
--- /dev/null
+++ b/drivers/mfd/stpmic1.c
@@ -0,0 +1,213 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define STPMIC1_MAIN_IRQ 0
+
+static const struct regmap_range stpmic1_readable_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_MASK_R1, INT_MASK_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R1),
+};
+
+static const struct regmap_range stpmic1_writeable_ranges[] = {
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+};
+
+static const struct regmap_range stpmic1_volatile_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(WCHDG_CR, WCHDG_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R4),
+};
+
+static const struct regmap_access_table stpmic1_readable_table = {
+   .yes_ranges = stpmic1_readable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_readable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_writeable_table = {
+   .yes_ranges = stpmic1_writeable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_writeable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_volatile_table = {
+   .yes_ranges = stpmic1_volatile_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_volatile_ranges),
+};
+
+const struct regmap_config stpmic1_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .cache_type = REGCACHE_RBTREE,
+   .max_register = PMIC_MAX_REGISTER_ADDRESS,
+   .rd_table = _readable_table,
+   .wr_table = _writeable_table,
+   .volatile_table = _volatile_table,
+};
+
+static const struct regmap_irq stpmic1_irqs[] = {
+   REGMAP_IRQ_REG(IT_PONKEY_F, 0, 0x01),
+   REGMAP_IRQ_REG(IT_PONKEY_R, 0, 0x02),
+   REGMAP_IRQ_REG(IT_WAKEUP_F, 0, 0x04),
+   REGMAP_IRQ_REG(IT_WAKEUP_R, 0, 0x08),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_F, 0, 0x10),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_R, 0, 0x20),
+   

[PATCH v6 0/8] Introduce STPMIC1 PMIC Driver

2018-11-27 Thread Pascal PAILLET-LME
The goal of this patch-set is to propose a driver for the STPMIC1 PMIC from 
STMicroelectronics. 
The STPMIC1 regulators supply power to an application processor as well as 
to external system peripherals such as DDR, Flash memories and system
devices. It also features onkey button input and an hardware watchdog.
The STPMIC1 is controlled via I2C. 

Main driver is drivers/mfd/stpmic1 that handle I2C regmap configuration and
irqchip. stpmic1_regulator, stpmic1_onkey and stpmic1_wdt need stpmic1 mfd
as parent.

STPMIC1 MFD and regulator drivers maybe mandatory at boot time.

Pascal Paillet (9):
  dt-bindings: mfd: document stpmic1
  mfd: stpmic1: add stpmic1 driver
  dt-bindings: regulator: document stpmic1 pmic regulators
  regulator: stpmic1: add stpmic1 regulator driver
  dt-bindings: input: document stpmic1 pmic onkey
  input: stpmic1: add stpmic1 onkey driver
  dt-bindings: watchdog: document stpmic1 pmic watchdog
  watchdog: stpmic1: add stpmic1 watchdog driver
  defc

 .../devicetree/bindings/input/st,stpmic1-onkey.txt |  28 +
 .../devicetree/bindings/mfd/st,stpmic1.txt |  61 ++
 .../bindings/regulator/st,stpmic1-regulator.txt|  67 ++
 .../bindings/watchdog/st,stpmic1-wdt.txt   |  11 +
 arch/arm/configs/pascal_defconfig  | 680 +
 drivers/input/misc/Kconfig |  11 +
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 ++
 drivers/mfd/Kconfig|  16 +
 drivers/mfd/Makefile   |   1 +
 drivers/mfd/stpmic1.c  | 213 +++
 drivers/regulator/Kconfig  |  12 +
 drivers/regulator/Makefile |   1 +
 drivers/regulator/stpmic1_regulator.c  | 667 
 drivers/watchdog/Kconfig   |  12 +
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 +
 include/dt-bindings/mfd/st,stpmic1.h   |  50 ++
 include/linux/mfd/stpmic1.h| 212 +++
 19 files changed, 2382 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 
Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
 create mode 100644 arch/arm/configs/pascal_defconfig
 create mode 100644 drivers/input/misc/stpmic1_onkey.c
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 drivers/regulator/stpmic1_regulator.c
 create mode 100644 drivers/watchdog/stpmic1_wdt.c
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h
 create mode 100644 include/linux/mfd/stpmic1.h

-- 
1.9.1


[PATCH v6 1/8] dt-bindings: mfd: document stpmic1

2018-11-27 Thread Pascal PAILLET-LME
STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
Acked-for-MFD-by: Lee Jones 
---
changes in v6:
* fix commit message

 .../devicetree/bindings/mfd/st,stpmic1.txt | 61 ++
 include/dt-bindings/mfd/st,stpmic1.h   | 50 ++
 2 files changed, 111 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h

diff --git a/Documentation/devicetree/bindings/mfd/st,stpmic1.txt 
b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
new file mode 100644
index 000..afd45c0
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
@@ -0,0 +1,61 @@
+* STMicroelectronics STPMIC1 Power Management IC
+
+Required properties:
+- compatible:  : "st,stpmic1"
+- reg: : The I2C slave address for the STPMIC1 chip.
+- interrupts:  : The interrupt line the device is connected to.
+- #interrupt-cells:: Should be 1.
+- interrupt-controller:: Marks the device node as an interrupt 
controller.
+   Interrupt numbers are defined at
+   dt-bindings/mfd/st,stpmic1.h.
+
+STPMIC1 consists in a varied group of sub-devices.
+Each sub-device binding is be described in own documentation file.
+
+Device  Description
+-- 
+st,stpmic1-onkey   : Power on key, see ../input/st,stpmic1-onkey.txt
+st,stpmic1-regulators  : Regulators, see ../regulator/st,stpmic1-regulator.txt
+st,stpmic1-wdt : Watchdog, see ../watchdog/st,stpmic1-wdt.txt
+
+Example:
+
+#include 
+
+pmic: pmic@33 {
+   compatible = "st,stpmic1";
+   reg = <0x33>;
+   interrupt-parent = <>;
+   interrupts = <0 2>;
+
+   interrupt-controller;
+   #interrupt-cells = <2>;
+
+   onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+   };
+
+   watchdog {
+   compatible = "st,stpmic1-wdt";
+   };
+
+   regulators {
+   compatible = "st,stpmic1-regulators";
+
+   vdd_core: buck1 {
+   regulator-name = "vdd_core";
+   regulator-boot-on;
+   regulator-min-microvolt = <70>;
+   regulator-max-microvolt = <120>;
+   };
+   vdd: buck3 {
+   regulator-name = "vdd";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-boot-on;
+   regulator-pull-down;
+   };
+   };
diff --git a/include/dt-bindings/mfd/st,stpmic1.h 
b/include/dt-bindings/mfd/st,stpmic1.h
new file mode 100644
index 000..321cd087
--- /dev/null
+++ b/include/dt-bindings/mfd/st,stpmic1.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) STMicroelectronics 2018 - All Rights Reserved
+ * Author: Philippe Peurichard ,
+ * Pascal Paillet  for STMicroelectronics.
+ */
+
+#ifndef __DT_BINDINGS_STPMIC1_H__
+#define __DT_BINDINGS_STPMIC1_H__
+
+/* IRQ definitions */
+#define IT_PONKEY_F0
+#define IT_PONKEY_R1
+#define IT_WAKEUP_F2
+#define IT_WAKEUP_R3
+#define IT_VBUS_OTG_F  4
+#define IT_VBUS_OTG_R  5
+#define IT_SWOUT_F 6
+#define IT_SWOUT_R 7
+
+#define IT_CURLIM_BUCK18
+#define IT_CURLIM_BUCK29
+#define IT_CURLIM_BUCK310
+#define IT_CURLIM_BUCK411
+#define IT_OCP_OTG 12
+#define IT_OCP_SWOUT   13
+#define IT_OCP_BOOST   14
+#define IT_OVP_BOOST   15
+
+#define IT_CURLIM_LDO1 16
+#define IT_CURLIM_LDO2 17
+#define IT_CURLIM_LDO3 18
+#define IT_CURLIM_LDO4 19
+#define IT_CURLIM_LDO5 20
+#define IT_CURLIM_LDO6 21
+#define IT_SHORT_SWOTG 22
+#define IT_SHORT_SWOUT 23
+
+#define IT_TWARN_F 24
+#define IT_TWARN_R 25
+#define IT_VINLOW_F26
+#define IT_VINLOW_R27
+#define IT_SWIN_F  30
+#define IT_SWIN_R  31
+
+/* BUCK MODES definitions */
+#define STPMIC1_BUCK_MODE_NORMAL 0
+#define STPMIC1_BUCK_MODE_LP 2
+
+#endif /* __DT_BINDINGS_STPMIC1_H__ */
-- 
1.9.1


[PATCH v6 6/8] input: stpmic1: add stpmic1 onkey driver

2018-11-27 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. This driver exposes
the stpmic1 onkey as an input device. It can also be configured to
shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
Acked-by: Dmitry Torokhov 
---
changes in v6: nothing

 drivers/input/misc/Kconfig |  11 +++
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 +
 3 files changed, 211 insertions(+)
 create mode 100644 drivers/input/misc/stpmic1_onkey.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index ca59a2b..279fb02 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -851,4 +851,15 @@ config INPUT_SC27XX_VIBRA
  To compile this driver as a module, choose M here. The module will
  be called sc27xx_vibra.
 
+config INPUT_STPMIC1_ONKEY
+   tristate "STPMIC1 PMIC Onkey support"
+   depends on MFD_STPMIC1
+   help
+ Say Y to enable support of onkey embedded into STPMIC1 PMIC. onkey
+ can be used to wakeup from low power modes and force a shut-down on
+ long press.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1_onkey.
+
 endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 9d0f9d1..1b44202 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_INPUT_SGI_BTNS)  += sgi_btns.o
 obj-$(CONFIG_INPUT_SIRFSOC_ONKEY)  += sirfsoc-onkey.o
 obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY)   += soc_button_array.o
 obj-$(CONFIG_INPUT_SPARCSPKR)  += sparcspkr.o
+obj-$(CONFIG_INPUT_STPMIC1_ONKEY)  += stpmic1_onkey.o
 obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON) += tps65218-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON)  += twl4030-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_VIBRA)  += twl4030-vibra.o
@@ -81,3 +82,4 @@ obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
 obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)+= xen-kbdfront.o
 obj-$(CONFIG_INPUT_YEALINK)+= yealink.o
 obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR)   += ideapad_slidebar.o
+
diff --git a/drivers/input/misc/stpmic1_onkey.c 
b/drivers/input/misc/stpmic1_onkey.c
new file mode 100644
index 000..7b49c99
--- /dev/null
+++ b/drivers/input/misc/stpmic1_onkey.c
@@ -0,0 +1,198 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * struct stpmic1_onkey - OnKey data
+ * @input_dev: pointer to input device
+ * @irq_falling:   irq that we are hooked on to
+ * @irq_rising:irq that we are hooked on to
+ */
+struct stpmic1_onkey {
+   struct input_dev *input_dev;
+   int irq_falling;
+   int irq_rising;
+};
+
+static irqreturn_t onkey_falling_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 1);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static irqreturn_t onkey_rising_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 0);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static int stpmic1_onkey_probe(struct platform_device *pdev)
+{
+   struct stpmic1 *pmic = dev_get_drvdata(pdev->dev.parent);
+   struct device *dev = >dev;
+   struct input_dev *input_dev;
+   struct stpmic1_onkey *onkey;
+   unsigned int val, reg = 0;
+   int error;
+
+   onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->irq_falling = platform_get_irq_byname(pdev, "onkey-falling");
+   if (onkey->irq_falling < 0) {
+   dev_err(dev, "failed: request IRQ onkey-falling %d\n",
+   onkey->irq_falling);
+   return onkey->irq_falling;
+   }
+
+   onkey->irq_rising = platform_get_irq_byname(pdev, "onkey-rising");
+   if (onkey->irq_rising < 0) {
+   dev_err(dev, "failed: request IRQ onkey-rising %d\n",
+   onkey->irq_rising);
+   return onkey->irq_rising;
+   }
+
+   if (!device_property_read_u32(dev, "power-off-time-sec", )) {
+   if (val > 0 && val <= 16) {
+   dev_dbg(dev, "power-off-time=%d seconds\n", val);
+   reg |= PONKEY_PWR_OFF;
+   reg |= ((16 - val) & PONKEY_TURNOFF_TIMER_MASK);
+   } else {
+   dev_err(dev, 

[PATCH v6 0/8] Introduce STPMIC1 PMIC Driver

2018-11-27 Thread Pascal PAILLET-LME
The goal of this patch-set is to propose a driver for the STPMIC1 PMIC from 
STMicroelectronics. 
The STPMIC1 regulators supply power to an application processor as well as 
to external system peripherals such as DDR, Flash memories and system
devices. It also features onkey button input and an hardware watchdog.
The STPMIC1 is controlled via I2C. 

Main driver is drivers/mfd/stpmic1 that handle I2C regmap configuration and
irqchip. stpmic1_regulator, stpmic1_onkey and stpmic1_wdt need stpmic1 mfd
as parent.

STPMIC1 MFD and regulator drivers maybe mandatory at boot time.

Pascal Paillet (9):
  dt-bindings: mfd: document stpmic1
  mfd: stpmic1: add stpmic1 driver
  dt-bindings: regulator: document stpmic1 pmic regulators
  regulator: stpmic1: add stpmic1 regulator driver
  dt-bindings: input: document stpmic1 pmic onkey
  input: stpmic1: add stpmic1 onkey driver
  dt-bindings: watchdog: document stpmic1 pmic watchdog
  watchdog: stpmic1: add stpmic1 watchdog driver
  defc

 .../devicetree/bindings/input/st,stpmic1-onkey.txt |  28 +
 .../devicetree/bindings/mfd/st,stpmic1.txt |  61 ++
 .../bindings/regulator/st,stpmic1-regulator.txt|  67 ++
 .../bindings/watchdog/st,stpmic1-wdt.txt   |  11 +
 arch/arm/configs/pascal_defconfig  | 680 +
 drivers/input/misc/Kconfig |  11 +
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 ++
 drivers/mfd/Kconfig|  16 +
 drivers/mfd/Makefile   |   1 +
 drivers/mfd/stpmic1.c  | 213 +++
 drivers/regulator/Kconfig  |  12 +
 drivers/regulator/Makefile |   1 +
 drivers/regulator/stpmic1_regulator.c  | 667 
 drivers/watchdog/Kconfig   |  12 +
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 +
 include/dt-bindings/mfd/st,stpmic1.h   |  50 ++
 include/linux/mfd/stpmic1.h| 212 +++
 19 files changed, 2382 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 
Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
 create mode 100644 arch/arm/configs/pascal_defconfig
 create mode 100644 drivers/input/misc/stpmic1_onkey.c
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 drivers/regulator/stpmic1_regulator.c
 create mode 100644 drivers/watchdog/stpmic1_wdt.c
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h
 create mode 100644 include/linux/mfd/stpmic1.h

-- 
1.9.1


[PATCH v6 1/8] dt-bindings: mfd: document stpmic1

2018-11-27 Thread Pascal PAILLET-LME
STPMIC1 is a PMIC from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
Acked-for-MFD-by: Lee Jones 
---
changes in v6:
* fix commit message

 .../devicetree/bindings/mfd/st,stpmic1.txt | 61 ++
 include/dt-bindings/mfd/st,stpmic1.h   | 50 ++
 2 files changed, 111 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h

diff --git a/Documentation/devicetree/bindings/mfd/st,stpmic1.txt 
b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
new file mode 100644
index 000..afd45c0
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
@@ -0,0 +1,61 @@
+* STMicroelectronics STPMIC1 Power Management IC
+
+Required properties:
+- compatible:  : "st,stpmic1"
+- reg: : The I2C slave address for the STPMIC1 chip.
+- interrupts:  : The interrupt line the device is connected to.
+- #interrupt-cells:: Should be 1.
+- interrupt-controller:: Marks the device node as an interrupt 
controller.
+   Interrupt numbers are defined at
+   dt-bindings/mfd/st,stpmic1.h.
+
+STPMIC1 consists in a varied group of sub-devices.
+Each sub-device binding is be described in own documentation file.
+
+Device  Description
+-- 
+st,stpmic1-onkey   : Power on key, see ../input/st,stpmic1-onkey.txt
+st,stpmic1-regulators  : Regulators, see ../regulator/st,stpmic1-regulator.txt
+st,stpmic1-wdt : Watchdog, see ../watchdog/st,stpmic1-wdt.txt
+
+Example:
+
+#include 
+
+pmic: pmic@33 {
+   compatible = "st,stpmic1";
+   reg = <0x33>;
+   interrupt-parent = <>;
+   interrupts = <0 2>;
+
+   interrupt-controller;
+   #interrupt-cells = <2>;
+
+   onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+   };
+
+   watchdog {
+   compatible = "st,stpmic1-wdt";
+   };
+
+   regulators {
+   compatible = "st,stpmic1-regulators";
+
+   vdd_core: buck1 {
+   regulator-name = "vdd_core";
+   regulator-boot-on;
+   regulator-min-microvolt = <70>;
+   regulator-max-microvolt = <120>;
+   };
+   vdd: buck3 {
+   regulator-name = "vdd";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-boot-on;
+   regulator-pull-down;
+   };
+   };
diff --git a/include/dt-bindings/mfd/st,stpmic1.h 
b/include/dt-bindings/mfd/st,stpmic1.h
new file mode 100644
index 000..321cd087
--- /dev/null
+++ b/include/dt-bindings/mfd/st,stpmic1.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) STMicroelectronics 2018 - All Rights Reserved
+ * Author: Philippe Peurichard ,
+ * Pascal Paillet  for STMicroelectronics.
+ */
+
+#ifndef __DT_BINDINGS_STPMIC1_H__
+#define __DT_BINDINGS_STPMIC1_H__
+
+/* IRQ definitions */
+#define IT_PONKEY_F0
+#define IT_PONKEY_R1
+#define IT_WAKEUP_F2
+#define IT_WAKEUP_R3
+#define IT_VBUS_OTG_F  4
+#define IT_VBUS_OTG_R  5
+#define IT_SWOUT_F 6
+#define IT_SWOUT_R 7
+
+#define IT_CURLIM_BUCK18
+#define IT_CURLIM_BUCK29
+#define IT_CURLIM_BUCK310
+#define IT_CURLIM_BUCK411
+#define IT_OCP_OTG 12
+#define IT_OCP_SWOUT   13
+#define IT_OCP_BOOST   14
+#define IT_OVP_BOOST   15
+
+#define IT_CURLIM_LDO1 16
+#define IT_CURLIM_LDO2 17
+#define IT_CURLIM_LDO3 18
+#define IT_CURLIM_LDO4 19
+#define IT_CURLIM_LDO5 20
+#define IT_CURLIM_LDO6 21
+#define IT_SHORT_SWOTG 22
+#define IT_SHORT_SWOUT 23
+
+#define IT_TWARN_F 24
+#define IT_TWARN_R 25
+#define IT_VINLOW_F26
+#define IT_VINLOW_R27
+#define IT_SWIN_F  30
+#define IT_SWIN_R  31
+
+/* BUCK MODES definitions */
+#define STPMIC1_BUCK_MODE_NORMAL 0
+#define STPMIC1_BUCK_MODE_LP 2
+
+#endif /* __DT_BINDINGS_STPMIC1_H__ */
-- 
1.9.1


[PATCH v6 6/8] input: stpmic1: add stpmic1 onkey driver

2018-11-27 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. This driver exposes
the stpmic1 onkey as an input device. It can also be configured to
shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
Acked-by: Dmitry Torokhov 
---
changes in v6: nothing

 drivers/input/misc/Kconfig |  11 +++
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 +
 3 files changed, 211 insertions(+)
 create mode 100644 drivers/input/misc/stpmic1_onkey.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index ca59a2b..279fb02 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -851,4 +851,15 @@ config INPUT_SC27XX_VIBRA
  To compile this driver as a module, choose M here. The module will
  be called sc27xx_vibra.
 
+config INPUT_STPMIC1_ONKEY
+   tristate "STPMIC1 PMIC Onkey support"
+   depends on MFD_STPMIC1
+   help
+ Say Y to enable support of onkey embedded into STPMIC1 PMIC. onkey
+ can be used to wakeup from low power modes and force a shut-down on
+ long press.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1_onkey.
+
 endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 9d0f9d1..1b44202 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_INPUT_SGI_BTNS)  += sgi_btns.o
 obj-$(CONFIG_INPUT_SIRFSOC_ONKEY)  += sirfsoc-onkey.o
 obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY)   += soc_button_array.o
 obj-$(CONFIG_INPUT_SPARCSPKR)  += sparcspkr.o
+obj-$(CONFIG_INPUT_STPMIC1_ONKEY)  += stpmic1_onkey.o
 obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON) += tps65218-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON)  += twl4030-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_VIBRA)  += twl4030-vibra.o
@@ -81,3 +82,4 @@ obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
 obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)+= xen-kbdfront.o
 obj-$(CONFIG_INPUT_YEALINK)+= yealink.o
 obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR)   += ideapad_slidebar.o
+
diff --git a/drivers/input/misc/stpmic1_onkey.c 
b/drivers/input/misc/stpmic1_onkey.c
new file mode 100644
index 000..7b49c99
--- /dev/null
+++ b/drivers/input/misc/stpmic1_onkey.c
@@ -0,0 +1,198 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * struct stpmic1_onkey - OnKey data
+ * @input_dev: pointer to input device
+ * @irq_falling:   irq that we are hooked on to
+ * @irq_rising:irq that we are hooked on to
+ */
+struct stpmic1_onkey {
+   struct input_dev *input_dev;
+   int irq_falling;
+   int irq_rising;
+};
+
+static irqreturn_t onkey_falling_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 1);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static irqreturn_t onkey_rising_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 0);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static int stpmic1_onkey_probe(struct platform_device *pdev)
+{
+   struct stpmic1 *pmic = dev_get_drvdata(pdev->dev.parent);
+   struct device *dev = >dev;
+   struct input_dev *input_dev;
+   struct stpmic1_onkey *onkey;
+   unsigned int val, reg = 0;
+   int error;
+
+   onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->irq_falling = platform_get_irq_byname(pdev, "onkey-falling");
+   if (onkey->irq_falling < 0) {
+   dev_err(dev, "failed: request IRQ onkey-falling %d\n",
+   onkey->irq_falling);
+   return onkey->irq_falling;
+   }
+
+   onkey->irq_rising = platform_get_irq_byname(pdev, "onkey-rising");
+   if (onkey->irq_rising < 0) {
+   dev_err(dev, "failed: request IRQ onkey-rising %d\n",
+   onkey->irq_rising);
+   return onkey->irq_rising;
+   }
+
+   if (!device_property_read_u32(dev, "power-off-time-sec", )) {
+   if (val > 0 && val <= 16) {
+   dev_dbg(dev, "power-off-time=%d seconds\n", val);
+   reg |= PONKEY_PWR_OFF;
+   reg |= ((16 - val) & PONKEY_TURNOFF_TIMER_MASK);
+   } else {
+   dev_err(dev, 

[PATCH v6 4/8] regulator: stpmic1: add stpmic1 regulator driver

2018-11-27 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds several regulators and switches with
different capabilities.

Signed-off-by: Pascal Paillet 
---
changes in v6: nothing

 drivers/regulator/Kconfig |  12 +
 drivers/regulator/Makefile|   1 +
 drivers/regulator/stpmic1_regulator.c | 667 ++
 3 files changed, 680 insertions(+)
 create mode 100644 drivers/regulator/stpmic1_regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 6e96ef1..026d480 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -803,6 +803,18 @@ config REGULATOR_STM32_VREFBUF
  This driver can also be built as a module. If so, the module
  will be called stm32-vrefbuf.
 
+config REGULATOR_STPMIC1
+   tristate "STMicroelectronics STPMIC1 PMIC Regulators"
+   depends on MFD_STPMIC1
+   help
+ This driver supports STMicroelectronics STPMIC1 PMIC voltage
+ regulators and switches. The STPMIC1 regulators supply power to
+ an application processor as well as to external system
+ peripherals such as DDR, Flash memories and system devices.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1_regulator.
+
 config REGULATOR_TI_ABB
tristate "TI Adaptive Body Bias on-chip LDO"
depends on ARCH_OMAP
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index eac4d79..300bc4c 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -101,6 +101,7 @@ obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
 obj-$(CONFIG_REGULATOR_SC2731) += sc2731-regulator.o
 obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o
 obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
+obj-$(CONFIG_REGULATOR_STPMIC1) += stpmic1_regulator.o
 obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o
 obj-$(CONFIG_REGULATOR_SY8106A) += sy8106a-regulator.o
 obj-$(CONFIG_REGULATOR_TI_ABB) += ti-abb-regulator.o
diff --git a/drivers/regulator/stpmic1_regulator.c 
b/drivers/regulator/stpmic1_regulator.c
new file mode 100644
index 000..c96edcd
--- /dev/null
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -0,0 +1,667 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/**
+ * stpmic1 regulator description
+ * @desc: regulator framework description
+ * @mask_reset_reg: mask reset register address
+ * @mask_reset_mask: mask rank and mask reset register mask
+ * @icc_reg: icc register address
+ * @icc_mask: icc register mask
+ */
+struct stpmic1_regulator_cfg {
+   struct regulator_desc desc;
+   u8 mask_reset_reg;
+   u8 mask_reset_mask;
+   u8 icc_reg;
+   u8 icc_mask;
+};
+
+/**
+ * stpmic1 regulator data: this structure is used as driver data
+ * @regul_id: regulator id
+ * @reg_node: DT node of regulator (unused on non-DT platforms)
+ * @cfg: stpmic specific regulator description
+ * @regmap: point to parent regmap structure
+ */
+struct stpmic1_regulator {
+   unsigned int regul_id;
+   struct device_node *reg_node;
+   struct stpmic1_regulator_cfg *cfg;
+   struct regmap *regmap;
+};
+
+static int stpmic1_set_mode(struct regulator_dev *rdev, unsigned int mode);
+static unsigned int stpmic1_get_mode(struct regulator_dev *rdev);
+static int stpmic1_set_icc(struct regulator_dev *rdev);
+static unsigned int stpmic1_map_mode(unsigned int mode);
+
+enum {
+   STPMIC1_BUCK1 = 0,
+   STPMIC1_BUCK2 = 1,
+   STPMIC1_BUCK3 = 2,
+   STPMIC1_BUCK4 = 3,
+   STPMIC1_LDO1 = 4,
+   STPMIC1_LDO2 = 5,
+   STPMIC1_LDO3 = 6,
+   STPMIC1_LDO4 = 7,
+   STPMIC1_LDO5 = 8,
+   STPMIC1_LDO6 = 9,
+   STPMIC1_VREF_DDR = 10,
+   STPMIC1_BOOST = 11,
+   STPMIC1_VBUS_OTG = 12,
+   STPMIC1_SW_OUT = 13,
+};
+
+/* Enable time worst case is 5000mV/(2250uV/uS) */
+#define PMIC_ENABLE_TIME_US 2200
+
+struct regulator_linear_range buck1_ranges[] = {
+   REGULATOR_LINEAR_RANGE(60, 0, 30, 25000),
+   REGULATOR_LINEAR_RANGE(135, 31, 63, 0),
+};
+
+struct regulator_linear_range buck2_ranges[] = {
+   REGULATOR_LINEAR_RANGE(100, 0, 17, 0),
+   REGULATOR_LINEAR_RANGE(105, 18, 19, 0),
+   REGULATOR_LINEAR_RANGE(110, 20, 21, 0),
+   REGULATOR_LINEAR_RANGE(115, 22, 23, 0),
+   REGULATOR_LINEAR_RANGE(120, 24, 25, 0),
+   REGULATOR_LINEAR_RANGE(125, 26, 27, 0),
+   REGULATOR_LINEAR_RANGE(130, 28, 29, 0),
+   REGULATOR_LINEAR_RANGE(135, 30, 31, 0),
+   REGULATOR_LINEAR_RANGE(140, 32, 33, 0),
+   REGULATOR_LINEAR_RANGE(145, 34, 35, 0),
+   REGULATOR_LINEAR_RANGE(150, 36, 63, 0),
+};
+
+struct regulator_linear_range buck3_ranges[] = {
+   REGULATOR_LINEAR_RANGE(100, 0, 19, 0),
+   

[PATCH v6 4/8] regulator: stpmic1: add stpmic1 regulator driver

2018-11-27 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds several regulators and switches with
different capabilities.

Signed-off-by: Pascal Paillet 
---
changes in v6: nothing

 drivers/regulator/Kconfig |  12 +
 drivers/regulator/Makefile|   1 +
 drivers/regulator/stpmic1_regulator.c | 667 ++
 3 files changed, 680 insertions(+)
 create mode 100644 drivers/regulator/stpmic1_regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 6e96ef1..026d480 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -803,6 +803,18 @@ config REGULATOR_STM32_VREFBUF
  This driver can also be built as a module. If so, the module
  will be called stm32-vrefbuf.
 
+config REGULATOR_STPMIC1
+   tristate "STMicroelectronics STPMIC1 PMIC Regulators"
+   depends on MFD_STPMIC1
+   help
+ This driver supports STMicroelectronics STPMIC1 PMIC voltage
+ regulators and switches. The STPMIC1 regulators supply power to
+ an application processor as well as to external system
+ peripherals such as DDR, Flash memories and system devices.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1_regulator.
+
 config REGULATOR_TI_ABB
tristate "TI Adaptive Body Bias on-chip LDO"
depends on ARCH_OMAP
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index eac4d79..300bc4c 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -101,6 +101,7 @@ obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
 obj-$(CONFIG_REGULATOR_SC2731) += sc2731-regulator.o
 obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o
 obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
+obj-$(CONFIG_REGULATOR_STPMIC1) += stpmic1_regulator.o
 obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o
 obj-$(CONFIG_REGULATOR_SY8106A) += sy8106a-regulator.o
 obj-$(CONFIG_REGULATOR_TI_ABB) += ti-abb-regulator.o
diff --git a/drivers/regulator/stpmic1_regulator.c 
b/drivers/regulator/stpmic1_regulator.c
new file mode 100644
index 000..c96edcd
--- /dev/null
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -0,0 +1,667 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/**
+ * stpmic1 regulator description
+ * @desc: regulator framework description
+ * @mask_reset_reg: mask reset register address
+ * @mask_reset_mask: mask rank and mask reset register mask
+ * @icc_reg: icc register address
+ * @icc_mask: icc register mask
+ */
+struct stpmic1_regulator_cfg {
+   struct regulator_desc desc;
+   u8 mask_reset_reg;
+   u8 mask_reset_mask;
+   u8 icc_reg;
+   u8 icc_mask;
+};
+
+/**
+ * stpmic1 regulator data: this structure is used as driver data
+ * @regul_id: regulator id
+ * @reg_node: DT node of regulator (unused on non-DT platforms)
+ * @cfg: stpmic specific regulator description
+ * @regmap: point to parent regmap structure
+ */
+struct stpmic1_regulator {
+   unsigned int regul_id;
+   struct device_node *reg_node;
+   struct stpmic1_regulator_cfg *cfg;
+   struct regmap *regmap;
+};
+
+static int stpmic1_set_mode(struct regulator_dev *rdev, unsigned int mode);
+static unsigned int stpmic1_get_mode(struct regulator_dev *rdev);
+static int stpmic1_set_icc(struct regulator_dev *rdev);
+static unsigned int stpmic1_map_mode(unsigned int mode);
+
+enum {
+   STPMIC1_BUCK1 = 0,
+   STPMIC1_BUCK2 = 1,
+   STPMIC1_BUCK3 = 2,
+   STPMIC1_BUCK4 = 3,
+   STPMIC1_LDO1 = 4,
+   STPMIC1_LDO2 = 5,
+   STPMIC1_LDO3 = 6,
+   STPMIC1_LDO4 = 7,
+   STPMIC1_LDO5 = 8,
+   STPMIC1_LDO6 = 9,
+   STPMIC1_VREF_DDR = 10,
+   STPMIC1_BOOST = 11,
+   STPMIC1_VBUS_OTG = 12,
+   STPMIC1_SW_OUT = 13,
+};
+
+/* Enable time worst case is 5000mV/(2250uV/uS) */
+#define PMIC_ENABLE_TIME_US 2200
+
+struct regulator_linear_range buck1_ranges[] = {
+   REGULATOR_LINEAR_RANGE(60, 0, 30, 25000),
+   REGULATOR_LINEAR_RANGE(135, 31, 63, 0),
+};
+
+struct regulator_linear_range buck2_ranges[] = {
+   REGULATOR_LINEAR_RANGE(100, 0, 17, 0),
+   REGULATOR_LINEAR_RANGE(105, 18, 19, 0),
+   REGULATOR_LINEAR_RANGE(110, 20, 21, 0),
+   REGULATOR_LINEAR_RANGE(115, 22, 23, 0),
+   REGULATOR_LINEAR_RANGE(120, 24, 25, 0),
+   REGULATOR_LINEAR_RANGE(125, 26, 27, 0),
+   REGULATOR_LINEAR_RANGE(130, 28, 29, 0),
+   REGULATOR_LINEAR_RANGE(135, 30, 31, 0),
+   REGULATOR_LINEAR_RANGE(140, 32, 33, 0),
+   REGULATOR_LINEAR_RANGE(145, 34, 35, 0),
+   REGULATOR_LINEAR_RANGE(150, 36, 63, 0),
+};
+
+struct regulator_linear_range buck3_ranges[] = {
+   REGULATOR_LINEAR_RANGE(100, 0, 19, 0),
+   

[PATCH v6 5/8] dt-bindings: input: document stpmic1 pmic onkey

2018-11-27 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. It can be configured
to shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
---
changes in v6: nothing

 .../devicetree/bindings/input/st,stpmic1-onkey.txt | 28 ++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt

diff --git a/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt 
b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
new file mode 100644
index 000..4494613
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
@@ -0,0 +1,28 @@
+STMicroelectronics STPMIC1 Onkey
+
+Required properties:
+
+- compatible = "st,stpmic1-onkey";
+- interrupts: interrupt line to use
+- interrupt-names = "onkey-falling", "onkey-rising"
+   onkey-falling: happens when onkey is pressed; IT_PONKEY_F of pmic
+   onkey-rising: happens when onkey is released; IT_PONKEY_R of pmic
+
+Optional properties:
+
+- st,onkey-clear-cc-flag: onkey is able power on after an
+  over-current shutdown event.
+- st,onkey-pu-inactive: onkey pull up is not active
+- power-off-time-sec: Duration in seconds which the key should be kept
+pressed for device to power off automatically (from 1 to 16 seconds).
+see See Documentation/devicetree/bindings/input/keys.txt
+
+Example:
+
+onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupt-parent = <>;
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+};
-- 
1.9.1


[PATCH v6 5/8] dt-bindings: input: document stpmic1 pmic onkey

2018-11-27 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. It can be configured
to shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
---
changes in v6: nothing

 .../devicetree/bindings/input/st,stpmic1-onkey.txt | 28 ++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt

diff --git a/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt 
b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
new file mode 100644
index 000..4494613
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
@@ -0,0 +1,28 @@
+STMicroelectronics STPMIC1 Onkey
+
+Required properties:
+
+- compatible = "st,stpmic1-onkey";
+- interrupts: interrupt line to use
+- interrupt-names = "onkey-falling", "onkey-rising"
+   onkey-falling: happens when onkey is pressed; IT_PONKEY_F of pmic
+   onkey-rising: happens when onkey is released; IT_PONKEY_R of pmic
+
+Optional properties:
+
+- st,onkey-clear-cc-flag: onkey is able power on after an
+  over-current shutdown event.
+- st,onkey-pu-inactive: onkey pull up is not active
+- power-off-time-sec: Duration in seconds which the key should be kept
+pressed for device to power off automatically (from 1 to 16 seconds).
+see See Documentation/devicetree/bindings/input/keys.txt
+
+Example:
+
+onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupt-parent = <>;
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+};
-- 
1.9.1


[PATCH v6 3/8] dt-bindings: regulator: document stpmic1 pmic regulators

2018-11-27 Thread Pascal PAILLET-LME
The STPMIC1 regulators supply power to the application processor as well as
to the external system peripherals such as DDR, Flash memories and system
devices.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
---
changes in v6:
* remove interrupt parent

 .../bindings/regulator/st,stpmic1-regulator.txt| 67 ++
 1 file changed, 67 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt

diff --git 
a/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt 
b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
new file mode 100644
index 000..5adc938
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
@@ -0,0 +1,66 @@
+STMicroelectronics STPMIC1 Voltage regulators
+
+Regulator Nodes are optional depending on needs.
+
+Available Regulators in STPMIC1 device are:
+  - buck1 for Buck BUCK1
+  - buck2 for Buck BUCK2
+  - buck3 for Buck BUCK3
+  - buck4 for Buck BUCK4
+  - ldo1 for LDO LDO1
+  - ldo2 for LDO LDO2
+  - ldo3 for LDO LDO3
+  - ldo4 for LDO LDO4
+  - ldo5 for LDO LDO5
+  - ldo6 for LDO LDO6
+  - vref_ddr for LDO Vref DDR
+  - boost for Buck BOOST
+  - pwr_sw1 for VBUS_OTG switch
+  - pwr_sw2 for SW_OUT switch
+
+Switches are fixed voltage regulators with only enable/disable capability.
+
+Optional properties:
+- st,mask-reset: mask reset for this regulator: the regulator configuration
+  is maintained during pmic reset.
+- regulator-pull-down: enable high pull down
+  if not specified light pull down is used
+- regulator-over-current-protection:
+if set, all regulators are switched off in case of over-current detection
+on this regulator,
+if not set, the driver only sends an over-current event.
+- interrupts: index of current limit detection interrupt
+- -supply: phandle to the parent supply/regulator node
+   each regulator supply can be described except vref_ddr.
+- regulator-active-discharge: can be used on pwr_sw1 and pwr_sw2.
+
+Example:
+regulators {
+   compatible = "st,stpmic1-regulators";
+
+   ldo6-supply = <>;
+
+   vdd_core: buck1 {
+   regulator-name = "vdd_core";
+   interrupts = ;
+   st,mask-reset;
+   regulator-pull-down;
+   regulator-min-microvolt = <70>;
+   regulator-max-microvolt = <120>;
+   };
+
+   v3v3: buck4 {
+   regulator-name = "v3v3";
+   interrupts = ;
+
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   };
+
+   v1v8: ldo6 {
+   regulator-name = "v1v8";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+   regulator-over-current-protection;
+   };
+};
-- 
1.9.1


[PATCH v6 3/8] dt-bindings: regulator: document stpmic1 pmic regulators

2018-11-27 Thread Pascal PAILLET-LME
The STPMIC1 regulators supply power to the application processor as well as
to the external system peripherals such as DDR, Flash memories and system
devices.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
---
changes in v6:
* remove interrupt parent

 .../bindings/regulator/st,stpmic1-regulator.txt| 67 ++
 1 file changed, 67 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt

diff --git 
a/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt 
b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
new file mode 100644
index 000..5adc938
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
@@ -0,0 +1,66 @@
+STMicroelectronics STPMIC1 Voltage regulators
+
+Regulator Nodes are optional depending on needs.
+
+Available Regulators in STPMIC1 device are:
+  - buck1 for Buck BUCK1
+  - buck2 for Buck BUCK2
+  - buck3 for Buck BUCK3
+  - buck4 for Buck BUCK4
+  - ldo1 for LDO LDO1
+  - ldo2 for LDO LDO2
+  - ldo3 for LDO LDO3
+  - ldo4 for LDO LDO4
+  - ldo5 for LDO LDO5
+  - ldo6 for LDO LDO6
+  - vref_ddr for LDO Vref DDR
+  - boost for Buck BOOST
+  - pwr_sw1 for VBUS_OTG switch
+  - pwr_sw2 for SW_OUT switch
+
+Switches are fixed voltage regulators with only enable/disable capability.
+
+Optional properties:
+- st,mask-reset: mask reset for this regulator: the regulator configuration
+  is maintained during pmic reset.
+- regulator-pull-down: enable high pull down
+  if not specified light pull down is used
+- regulator-over-current-protection:
+if set, all regulators are switched off in case of over-current detection
+on this regulator,
+if not set, the driver only sends an over-current event.
+- interrupts: index of current limit detection interrupt
+- -supply: phandle to the parent supply/regulator node
+   each regulator supply can be described except vref_ddr.
+- regulator-active-discharge: can be used on pwr_sw1 and pwr_sw2.
+
+Example:
+regulators {
+   compatible = "st,stpmic1-regulators";
+
+   ldo6-supply = <>;
+
+   vdd_core: buck1 {
+   regulator-name = "vdd_core";
+   interrupts = ;
+   st,mask-reset;
+   regulator-pull-down;
+   regulator-min-microvolt = <70>;
+   regulator-max-microvolt = <120>;
+   };
+
+   v3v3: buck4 {
+   regulator-name = "v3v3";
+   interrupts = ;
+
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   };
+
+   v1v8: ldo6 {
+   regulator-name = "v1v8";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+   regulator-over-current-protection;
+   };
+};
-- 
1.9.1


Re: [PATCH v5 2/8] mfd: stpmic1: add stpmic1 driver

2018-11-26 Thread Pascal PAILLET-LME
Hi Lee,
I have just one question regarding i2c_device_id.


Le 11/13/2018 08:40 AM, Lee Jones a écrit :
> On Mon, 29 Oct 2018, Pascal PAILLET-LME wrote:
>
>> stpmic1 is a pmic from STMicroelectronics. The STPMIC1 integrates 10
> "STPMIC1 is a PMIC"
>
>> regulators, 3 power switches, a watchdog and an input for a power on key.
>>
>> Signed-off-by: Pascal Paillet 
>> ---
>> changes in v5:
>> * use macro to define regmap register ranges
>> * use REGMAP_IRQ_REG marco to define interrupts
>> * remove st properties
>>
>>   drivers/mfd/Kconfig |  13 +++
>>   drivers/mfd/Makefile|   1 +
>>   drivers/mfd/stpmic1.c   | 215 
>> 
>>   include/linux/mfd/stpmic1.h | 212 
>> +++
>>   4 files changed, 444 insertions(+)
>>   create mode 100644 drivers/mfd/stpmic1.c
>>   create mode 100644 include/linux/mfd/stpmic1.h
>>
>> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
>> index 11841f4..07e39a6 100644
>> --- a/drivers/mfd/Kconfig
>> +++ b/drivers/mfd/Kconfig
>> @@ -1855,6 +1855,22 @@ config MFD_STM32_TIMERS
>>for PWM and IIO Timer. This driver allow to share the
>>registers between the others drivers.
>>   
>> +config MFD_STPMIC1
>> +tristate "Support for STPMIC1 PMIC"
>> +depends on (I2C=y && OF)
>> +select REGMAP_I2C
>> +select REGMAP_IRQ
>> +select MFD_CORE
>> +help
>> +  Support for ST Microelectronics STPMIC1 PMIC. STPMIC1 has power on
>> +  key, watchdog and regulator functionalities which are supported via
>> +  the relevant subsystems.  This driver provides core support for the
>> +  STPMIC1, in order to use the actual functionaltiy of the device other
> s/,/./
>
>> +  drivers must be enabled.
>> +
>> +  To compile this driver as a module, choose M here: the
>> +  module will be called stpmic1.
>> +
>>   menu "Multimedia Capabilities Port drivers"
>>  depends on ARCH_SA1100
>>   
>> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
>> index 5856a94..76fff14 100644
>> --- a/drivers/mfd/Makefile
>> +++ b/drivers/mfd/Makefile
>> @@ -232,6 +232,7 @@ obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI)+= 
>> intel_soc_pmic_chtdc_ti.o
>>   obj-$(CONFIG_MFD_MT6397)   += mt6397-core.o
>>   
>>   obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o
>> +obj-$(CONFIG_MFD_STPMIC1)   += stpmic1.o
>>   obj-$(CONFIG_MFD_SUN4I_GPADC)  += sun4i-gpadc.o
>>   
>>   obj-$(CONFIG_MFD_STM32_LPTIMER)+= stm32-lptimer.o
>> diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
>> new file mode 100644
>> index 000..2f4fd5e
>> --- /dev/null
>> +++ b/drivers/mfd/stpmic1.c
>> @@ -0,0 +1,215 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +// Copyright (C) STMicroelectronics 2018
>> +// Author: Pascal Paillet 
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include 
>> +
>> +#define STPMIC1_MAIN_IRQ 0
>> +
>> +static const struct regmap_range stpmic1_readable_ranges[] = {
>> +regmap_reg_range(TURN_ON_SR, VERSION_SR),
>> +regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
>> +regmap_reg_range(BST_SW_CR, BST_SW_CR),
>> +regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
>> +regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
>> +regmap_reg_range(INT_MASK_R1, INT_MASK_R4),
>> +regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
>> +regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
>> +regmap_reg_range(INT_SRC_R1, INT_SRC_R1),
>> +};
>> +
>> +static const struct regmap_range stpmic1_writeable_ranges[] = {
>> +regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
>> +regmap_reg_range(BST_SW_CR, BST_SW_CR),
>> +regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
>> +regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
>> +regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
>> +};
>> +
>> +static const struct regmap_range stpmic1_volatile_ranges[] = {
>> +regmap_reg_range(TURN_ON_SR, VERSION_SR),
>> +regmap_reg_range(WCHDG_CR, WCHDG_CR),
>> +regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
>> +regmap_reg_range(INT_SRC_R1, INT_SRC_R4),
>> +};
> Nice!
>
>> +s

Re: [PATCH v5 2/8] mfd: stpmic1: add stpmic1 driver

2018-11-26 Thread Pascal PAILLET-LME
Hi Lee,
I have just one question regarding i2c_device_id.


Le 11/13/2018 08:40 AM, Lee Jones a écrit :
> On Mon, 29 Oct 2018, Pascal PAILLET-LME wrote:
>
>> stpmic1 is a pmic from STMicroelectronics. The STPMIC1 integrates 10
> "STPMIC1 is a PMIC"
>
>> regulators, 3 power switches, a watchdog and an input for a power on key.
>>
>> Signed-off-by: Pascal Paillet 
>> ---
>> changes in v5:
>> * use macro to define regmap register ranges
>> * use REGMAP_IRQ_REG marco to define interrupts
>> * remove st properties
>>
>>   drivers/mfd/Kconfig |  13 +++
>>   drivers/mfd/Makefile|   1 +
>>   drivers/mfd/stpmic1.c   | 215 
>> 
>>   include/linux/mfd/stpmic1.h | 212 
>> +++
>>   4 files changed, 444 insertions(+)
>>   create mode 100644 drivers/mfd/stpmic1.c
>>   create mode 100644 include/linux/mfd/stpmic1.h
>>
>> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
>> index 11841f4..07e39a6 100644
>> --- a/drivers/mfd/Kconfig
>> +++ b/drivers/mfd/Kconfig
>> @@ -1855,6 +1855,22 @@ config MFD_STM32_TIMERS
>>for PWM and IIO Timer. This driver allow to share the
>>registers between the others drivers.
>>   
>> +config MFD_STPMIC1
>> +tristate "Support for STPMIC1 PMIC"
>> +depends on (I2C=y && OF)
>> +select REGMAP_I2C
>> +select REGMAP_IRQ
>> +select MFD_CORE
>> +help
>> +  Support for ST Microelectronics STPMIC1 PMIC. STPMIC1 has power on
>> +  key, watchdog and regulator functionalities which are supported via
>> +  the relevant subsystems.  This driver provides core support for the
>> +  STPMIC1, in order to use the actual functionaltiy of the device other
> s/,/./
>
>> +  drivers must be enabled.
>> +
>> +  To compile this driver as a module, choose M here: the
>> +  module will be called stpmic1.
>> +
>>   menu "Multimedia Capabilities Port drivers"
>>  depends on ARCH_SA1100
>>   
>> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
>> index 5856a94..76fff14 100644
>> --- a/drivers/mfd/Makefile
>> +++ b/drivers/mfd/Makefile
>> @@ -232,6 +232,7 @@ obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI)+= 
>> intel_soc_pmic_chtdc_ti.o
>>   obj-$(CONFIG_MFD_MT6397)   += mt6397-core.o
>>   
>>   obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o
>> +obj-$(CONFIG_MFD_STPMIC1)   += stpmic1.o
>>   obj-$(CONFIG_MFD_SUN4I_GPADC)  += sun4i-gpadc.o
>>   
>>   obj-$(CONFIG_MFD_STM32_LPTIMER)+= stm32-lptimer.o
>> diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
>> new file mode 100644
>> index 000..2f4fd5e
>> --- /dev/null
>> +++ b/drivers/mfd/stpmic1.c
>> @@ -0,0 +1,215 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +// Copyright (C) STMicroelectronics 2018
>> +// Author: Pascal Paillet 
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include 
>> +
>> +#define STPMIC1_MAIN_IRQ 0
>> +
>> +static const struct regmap_range stpmic1_readable_ranges[] = {
>> +regmap_reg_range(TURN_ON_SR, VERSION_SR),
>> +regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
>> +regmap_reg_range(BST_SW_CR, BST_SW_CR),
>> +regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
>> +regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
>> +regmap_reg_range(INT_MASK_R1, INT_MASK_R4),
>> +regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
>> +regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
>> +regmap_reg_range(INT_SRC_R1, INT_SRC_R1),
>> +};
>> +
>> +static const struct regmap_range stpmic1_writeable_ranges[] = {
>> +regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
>> +regmap_reg_range(BST_SW_CR, BST_SW_CR),
>> +regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
>> +regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
>> +regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
>> +};
>> +
>> +static const struct regmap_range stpmic1_volatile_ranges[] = {
>> +regmap_reg_range(TURN_ON_SR, VERSION_SR),
>> +regmap_reg_range(WCHDG_CR, WCHDG_CR),
>> +regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
>> +regmap_reg_range(INT_SRC_R1, INT_SRC_R4),
>> +};
> Nice!
>
>> +s

[PATCH v5 8/8] watchdog: stpmic1: add stpmic1 watchdog driver

2018-10-29 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default. As soon
as the watchdog is started, it must be refreshed periodically otherwise
the PMIC goes off.

Signed-off-by: Pascal Paillet 
---
changes in v5:
* initialize wdtdev.parent
* fix checkpatch warning

 drivers/watchdog/Kconfig   |  12 
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 +
 3 files changed, 152 insertions(+)
 create mode 100644 drivers/watchdog/stpmic1_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 5ea8909..6d2ffef 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -806,6 +806,18 @@ config STM32_WATCHDOG
  To compile this driver as a module, choose M here: the
  module will be called stm32_iwdg.
 
+config STPMIC1_WATCHDOG
+   tristate "STPMIC1 PMIC watchdog support"
+   depends on MFD_STPMIC1
+   select WATCHDOG_CORE
+   help
+ Say Y here to include watchdog support embedded into STPMIC1 PMIC.
+ If the watchdog timer expires, stpmic1 will shut down all its power
+ supplies.
+
+ To compile this driver as a module, choose M here: the
+ module will be called spmic1_wdt.
+
 config UNIPHIER_WATCHDOG
tristate "UniPhier watchdog support"
depends on ARCH_UNIPHIER || COMPILE_TEST
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index bf92e7b..2649cf3 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -217,3 +217,4 @@ obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
 obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
 obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o
 obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
+obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o
diff --git a/drivers/watchdog/stpmic1_wdt.c b/drivers/watchdog/stpmic1_wdt.c
new file mode 100644
index 000..ad431d8
--- /dev/null
+++ b/drivers/watchdog/stpmic1_wdt.c
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* WATCHDOG CONTROL REGISTER bit */
+#define WDT_START  BIT(0)
+#define WDT_PING   BIT(1)
+#define WDT_START_MASK BIT(0)
+#define WDT_PING_MASK  BIT(1)
+#define WDT_STOP   0
+
+#define PMIC_WDT_MIN_TIMEOUT 1
+#define PMIC_WDT_MAX_TIMEOUT 256
+#define PMIC_WDT_DEFAULT_TIMEOUT 30
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct stpmic1_wdt {
+   struct stpmic1 *pmic;
+   struct watchdog_device wdtdev;
+};
+
+static int pmic_wdt_start(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_START);
+}
+
+static int pmic_wdt_stop(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_STOP);
+}
+
+static int pmic_wdt_ping(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_PING_MASK, WDT_PING);
+}
+
+static int pmic_wdt_set_timeout(struct watchdog_device *wdd,
+   unsigned int timeout)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   wdd->timeout = timeout;
+   /* timeout is equal to register value + 1 */
+   return regmap_write(wdt->pmic->regmap, WCHDG_TIMER_CR, timeout - 1);
+}
+
+static const struct watchdog_info pmic_watchdog_info = {
+   .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+   .identity = "STPMIC1 PMIC Watchdog",
+};
+
+static const struct watchdog_ops pmic_watchdog_ops = {
+   .owner = THIS_MODULE,
+   .start = pmic_wdt_start,
+   .stop = pmic_wdt_stop,
+   .ping = pmic_wdt_ping,
+   .set_timeout = pmic_wdt_set_timeout,
+};
+
+static int pmic_wdt_probe(struct platform_device *pdev)
+{
+   int ret;
+   struct stpmic1 *pmic;
+   struct stpmic1_wdt *wdt;
+
+   if (!pdev->dev.parent)
+   return -EINVAL;
+
+   pmic = dev_get_drvdata(pdev->dev.parent);
+   if (!pmic)
+   return -EINVAL;
+
+   wdt = devm_kzalloc(>dev, sizeof(struct stpmic1_wdt), GFP_KERNEL);
+   if (!wdt)
+   return -ENOMEM;
+
+   wdt->pmic = pmic;
+
+   wdt->wdtdev.info = _watchdog_info;
+   wdt->wdtdev.ops = _watchdog_ops;
+   wdt->wdtdev.min_timeout = PMIC_WDT_MIN_TIMEOUT;
+   

[PATCH v5 5/8] dt-bindings: input: document stpmic1 pmic onkey

2018-10-29 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. It can be configured
to shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
---
changes in v5: nothing

 .../devicetree/bindings/input/st,stpmic1-onkey.txt | 28 ++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt

diff --git a/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt 
b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
new file mode 100644
index 000..4494613
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
@@ -0,0 +1,28 @@
+STMicroelectronics STPMIC1 Onkey
+
+Required properties:
+
+- compatible = "st,stpmic1-onkey";
+- interrupts: interrupt line to use
+- interrupt-names = "onkey-falling", "onkey-rising"
+   onkey-falling: happens when onkey is pressed; IT_PONKEY_F of pmic
+   onkey-rising: happens when onkey is released; IT_PONKEY_R of pmic
+
+Optional properties:
+
+- st,onkey-clear-cc-flag: onkey is able power on after an
+  over-current shutdown event.
+- st,onkey-pu-inactive: onkey pull up is not active
+- power-off-time-sec: Duration in seconds which the key should be kept
+pressed for device to power off automatically (from 1 to 16 seconds).
+see See Documentation/devicetree/bindings/input/keys.txt
+
+Example:
+
+onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupt-parent = <>;
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+};
-- 
1.9.1


[PATCH v5 3/8] dt-bindings: regulator: document stpmic1 pmic regulators

2018-10-29 Thread Pascal PAILLET-LME
The STPMIC1 regulators supply power to the application processor as well as
to the external system peripherals such as DDR, Flash memories and system
devices.

Signed-off-by: Pascal Paillet 
---
changes in v5:
* describe regulator-active-discharge is available for power switches
* remove interrupt parents

 .../bindings/regulator/st,stpmic1-regulator.txt| 67 ++
 1 file changed, 67 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt

diff --git 
a/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt 
b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
new file mode 100644
index 000..5adc938
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
@@ -0,0 +1,67 @@
+STMicroelectronics STPMIC1 Voltage regulators
+
+Regulator Nodes are optional depending on needs.
+
+Available Regulators in STPMIC1 device are:
+  - buck1 for Buck BUCK1
+  - buck2 for Buck BUCK2
+  - buck3 for Buck BUCK3
+  - buck4 for Buck BUCK4
+  - ldo1 for LDO LDO1
+  - ldo2 for LDO LDO2
+  - ldo3 for LDO LDO3
+  - ldo4 for LDO LDO4
+  - ldo5 for LDO LDO5
+  - ldo6 for LDO LDO6
+  - vref_ddr for LDO Vref DDR
+  - boost for Buck BOOST
+  - pwr_sw1 for VBUS_OTG switch
+  - pwr_sw2 for SW_OUT switch
+
+Switches are fixed voltage regulators with only enable/disable capability.
+
+Optional properties:
+- st,mask-reset: mask reset for this regulator: the regulator configuration
+  is maintained during pmic reset.
+- regulator-pull-down: enable high pull down
+  if not specified light pull down is used
+- regulator-over-current-protection:
+if set, all regulators are switched off in case of over-current detection
+on this regulator,
+if not set, the driver only sends an over-current event.
+- interrupt-parent: phandle to the parent interrupt controller
+- interrupts: index of current limit detection interrupt
+- -supply: phandle to the parent supply/regulator node
+   each regulator supply can be described except vref_ddr.
+- regulator-active-discharge: can be used on pwr_sw1 and pwr_sw2.
+
+Example:
+regulators {
+   compatible = "st,stpmic1-regulators";
+
+   ldo6-supply = <>;
+
+   vdd_core: buck1 {
+   regulator-name = "vdd_core";
+   interrupts = ;
+   st,mask-reset;
+   regulator-pull-down;
+   regulator-min-microvolt = <70>;
+   regulator-max-microvolt = <120>;
+   };
+
+   v3v3: buck4 {
+   regulator-name = "v3v3";
+   interrupts = ;
+
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   };
+
+   v1v8: ldo6 {
+   regulator-name = "v1v8";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+   regulator-over-current-protection;
+   };
+};
-- 
1.9.1


[PATCH v5 5/8] dt-bindings: input: document stpmic1 pmic onkey

2018-10-29 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. It can be configured
to shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
---
changes in v5: nothing

 .../devicetree/bindings/input/st,stpmic1-onkey.txt | 28 ++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt

diff --git a/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt 
b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
new file mode 100644
index 000..4494613
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
@@ -0,0 +1,28 @@
+STMicroelectronics STPMIC1 Onkey
+
+Required properties:
+
+- compatible = "st,stpmic1-onkey";
+- interrupts: interrupt line to use
+- interrupt-names = "onkey-falling", "onkey-rising"
+   onkey-falling: happens when onkey is pressed; IT_PONKEY_F of pmic
+   onkey-rising: happens when onkey is released; IT_PONKEY_R of pmic
+
+Optional properties:
+
+- st,onkey-clear-cc-flag: onkey is able power on after an
+  over-current shutdown event.
+- st,onkey-pu-inactive: onkey pull up is not active
+- power-off-time-sec: Duration in seconds which the key should be kept
+pressed for device to power off automatically (from 1 to 16 seconds).
+see See Documentation/devicetree/bindings/input/keys.txt
+
+Example:
+
+onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupt-parent = <>;
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+};
-- 
1.9.1


[PATCH v5 3/8] dt-bindings: regulator: document stpmic1 pmic regulators

2018-10-29 Thread Pascal PAILLET-LME
The STPMIC1 regulators supply power to the application processor as well as
to the external system peripherals such as DDR, Flash memories and system
devices.

Signed-off-by: Pascal Paillet 
---
changes in v5:
* describe regulator-active-discharge is available for power switches
* remove interrupt parents

 .../bindings/regulator/st,stpmic1-regulator.txt| 67 ++
 1 file changed, 67 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt

diff --git 
a/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt 
b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
new file mode 100644
index 000..5adc938
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
@@ -0,0 +1,67 @@
+STMicroelectronics STPMIC1 Voltage regulators
+
+Regulator Nodes are optional depending on needs.
+
+Available Regulators in STPMIC1 device are:
+  - buck1 for Buck BUCK1
+  - buck2 for Buck BUCK2
+  - buck3 for Buck BUCK3
+  - buck4 for Buck BUCK4
+  - ldo1 for LDO LDO1
+  - ldo2 for LDO LDO2
+  - ldo3 for LDO LDO3
+  - ldo4 for LDO LDO4
+  - ldo5 for LDO LDO5
+  - ldo6 for LDO LDO6
+  - vref_ddr for LDO Vref DDR
+  - boost for Buck BOOST
+  - pwr_sw1 for VBUS_OTG switch
+  - pwr_sw2 for SW_OUT switch
+
+Switches are fixed voltage regulators with only enable/disable capability.
+
+Optional properties:
+- st,mask-reset: mask reset for this regulator: the regulator configuration
+  is maintained during pmic reset.
+- regulator-pull-down: enable high pull down
+  if not specified light pull down is used
+- regulator-over-current-protection:
+if set, all regulators are switched off in case of over-current detection
+on this regulator,
+if not set, the driver only sends an over-current event.
+- interrupt-parent: phandle to the parent interrupt controller
+- interrupts: index of current limit detection interrupt
+- -supply: phandle to the parent supply/regulator node
+   each regulator supply can be described except vref_ddr.
+- regulator-active-discharge: can be used on pwr_sw1 and pwr_sw2.
+
+Example:
+regulators {
+   compatible = "st,stpmic1-regulators";
+
+   ldo6-supply = <>;
+
+   vdd_core: buck1 {
+   regulator-name = "vdd_core";
+   interrupts = ;
+   st,mask-reset;
+   regulator-pull-down;
+   regulator-min-microvolt = <70>;
+   regulator-max-microvolt = <120>;
+   };
+
+   v3v3: buck4 {
+   regulator-name = "v3v3";
+   interrupts = ;
+
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   };
+
+   v1v8: ldo6 {
+   regulator-name = "v1v8";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+   regulator-over-current-protection;
+   };
+};
-- 
1.9.1


[PATCH v5 8/8] watchdog: stpmic1: add stpmic1 watchdog driver

2018-10-29 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default. As soon
as the watchdog is started, it must be refreshed periodically otherwise
the PMIC goes off.

Signed-off-by: Pascal Paillet 
---
changes in v5:
* initialize wdtdev.parent
* fix checkpatch warning

 drivers/watchdog/Kconfig   |  12 
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 +
 3 files changed, 152 insertions(+)
 create mode 100644 drivers/watchdog/stpmic1_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 5ea8909..6d2ffef 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -806,6 +806,18 @@ config STM32_WATCHDOG
  To compile this driver as a module, choose M here: the
  module will be called stm32_iwdg.
 
+config STPMIC1_WATCHDOG
+   tristate "STPMIC1 PMIC watchdog support"
+   depends on MFD_STPMIC1
+   select WATCHDOG_CORE
+   help
+ Say Y here to include watchdog support embedded into STPMIC1 PMIC.
+ If the watchdog timer expires, stpmic1 will shut down all its power
+ supplies.
+
+ To compile this driver as a module, choose M here: the
+ module will be called spmic1_wdt.
+
 config UNIPHIER_WATCHDOG
tristate "UniPhier watchdog support"
depends on ARCH_UNIPHIER || COMPILE_TEST
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index bf92e7b..2649cf3 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -217,3 +217,4 @@ obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
 obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
 obj-$(CONFIG_MENZ069_WATCHDOG) += menz69_wdt.o
 obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
+obj-$(CONFIG_STPMIC1_WATCHDOG) += stpmic1_wdt.o
diff --git a/drivers/watchdog/stpmic1_wdt.c b/drivers/watchdog/stpmic1_wdt.c
new file mode 100644
index 000..ad431d8
--- /dev/null
+++ b/drivers/watchdog/stpmic1_wdt.c
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* WATCHDOG CONTROL REGISTER bit */
+#define WDT_START  BIT(0)
+#define WDT_PING   BIT(1)
+#define WDT_START_MASK BIT(0)
+#define WDT_PING_MASK  BIT(1)
+#define WDT_STOP   0
+
+#define PMIC_WDT_MIN_TIMEOUT 1
+#define PMIC_WDT_MAX_TIMEOUT 256
+#define PMIC_WDT_DEFAULT_TIMEOUT 30
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct stpmic1_wdt {
+   struct stpmic1 *pmic;
+   struct watchdog_device wdtdev;
+};
+
+static int pmic_wdt_start(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_START);
+}
+
+static int pmic_wdt_stop(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_START_MASK, WDT_STOP);
+}
+
+static int pmic_wdt_ping(struct watchdog_device *wdd)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   return regmap_update_bits(wdt->pmic->regmap,
+ WCHDG_CR, WDT_PING_MASK, WDT_PING);
+}
+
+static int pmic_wdt_set_timeout(struct watchdog_device *wdd,
+   unsigned int timeout)
+{
+   struct stpmic1_wdt *wdt = watchdog_get_drvdata(wdd);
+
+   wdd->timeout = timeout;
+   /* timeout is equal to register value + 1 */
+   return regmap_write(wdt->pmic->regmap, WCHDG_TIMER_CR, timeout - 1);
+}
+
+static const struct watchdog_info pmic_watchdog_info = {
+   .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+   .identity = "STPMIC1 PMIC Watchdog",
+};
+
+static const struct watchdog_ops pmic_watchdog_ops = {
+   .owner = THIS_MODULE,
+   .start = pmic_wdt_start,
+   .stop = pmic_wdt_stop,
+   .ping = pmic_wdt_ping,
+   .set_timeout = pmic_wdt_set_timeout,
+};
+
+static int pmic_wdt_probe(struct platform_device *pdev)
+{
+   int ret;
+   struct stpmic1 *pmic;
+   struct stpmic1_wdt *wdt;
+
+   if (!pdev->dev.parent)
+   return -EINVAL;
+
+   pmic = dev_get_drvdata(pdev->dev.parent);
+   if (!pmic)
+   return -EINVAL;
+
+   wdt = devm_kzalloc(>dev, sizeof(struct stpmic1_wdt), GFP_KERNEL);
+   if (!wdt)
+   return -ENOMEM;
+
+   wdt->pmic = pmic;
+
+   wdt->wdtdev.info = _watchdog_info;
+   wdt->wdtdev.ops = _watchdog_ops;
+   wdt->wdtdev.min_timeout = PMIC_WDT_MIN_TIMEOUT;
+   

[PATCH v5 1/8] dt-bindings: mfd: document stpmic1

2018-10-29 Thread Pascal PAILLET-LME
stpmic1 is a pmic from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
---
changes in v5:
* removed st properties
* added buck modes definitions in the header

 .../devicetree/bindings/mfd/st,stpmic1.txt | 61 ++
 include/dt-bindings/mfd/st,stpmic1.h   | 50 ++
 2 files changed, 111 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h

diff --git a/Documentation/devicetree/bindings/mfd/st,stpmic1.txt 
b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
new file mode 100644
index 000..afd45c0
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
@@ -0,0 +1,61 @@
+* STMicroelectronics STPMIC1 Power Management IC
+
+Required properties:
+- compatible:  : "st,stpmic1"
+- reg: : The I2C slave address for the STPMIC1 chip.
+- interrupts:  : The interrupt line the device is connected to.
+- #interrupt-cells:: Should be 1.
+- interrupt-controller:: Marks the device node as an interrupt 
controller.
+   Interrupt numbers are defined at
+   dt-bindings/mfd/st,stpmic1.h.
+
+STPMIC1 consists in a varied group of sub-devices.
+Each sub-device binding is be described in own documentation file.
+
+Device  Description
+-- 
+st,stpmic1-onkey   : Power on key, see ../input/st,stpmic1-onkey.txt
+st,stpmic1-regulators  : Regulators, see ../regulator/st,stpmic1-regulator.txt
+st,stpmic1-wdt : Watchdog, see ../watchdog/st,stpmic1-wdt.txt
+
+Example:
+
+#include 
+
+pmic: pmic@33 {
+   compatible = "st,stpmic1";
+   reg = <0x33>;
+   interrupt-parent = <>;
+   interrupts = <0 2>;
+
+   interrupt-controller;
+   #interrupt-cells = <2>;
+
+   onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+   };
+
+   watchdog {
+   compatible = "st,stpmic1-wdt";
+   };
+
+   regulators {
+   compatible = "st,stpmic1-regulators";
+
+   vdd_core: buck1 {
+   regulator-name = "vdd_core";
+   regulator-boot-on;
+   regulator-min-microvolt = <70>;
+   regulator-max-microvolt = <120>;
+   };
+   vdd: buck3 {
+   regulator-name = "vdd";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-boot-on;
+   regulator-pull-down;
+   };
+   };
diff --git a/include/dt-bindings/mfd/st,stpmic1.h 
b/include/dt-bindings/mfd/st,stpmic1.h
new file mode 100644
index 000..321cd087
--- /dev/null
+++ b/include/dt-bindings/mfd/st,stpmic1.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) STMicroelectronics 2018 - All Rights Reserved
+ * Author: Philippe Peurichard ,
+ * Pascal Paillet  for STMicroelectronics.
+ */
+
+#ifndef __DT_BINDINGS_STPMIC1_H__
+#define __DT_BINDINGS_STPMIC1_H__
+
+/* IRQ definitions */
+#define IT_PONKEY_F0
+#define IT_PONKEY_R1
+#define IT_WAKEUP_F2
+#define IT_WAKEUP_R3
+#define IT_VBUS_OTG_F  4
+#define IT_VBUS_OTG_R  5
+#define IT_SWOUT_F 6
+#define IT_SWOUT_R 7
+
+#define IT_CURLIM_BUCK18
+#define IT_CURLIM_BUCK29
+#define IT_CURLIM_BUCK310
+#define IT_CURLIM_BUCK411
+#define IT_OCP_OTG 12
+#define IT_OCP_SWOUT   13
+#define IT_OCP_BOOST   14
+#define IT_OVP_BOOST   15
+
+#define IT_CURLIM_LDO1 16
+#define IT_CURLIM_LDO2 17
+#define IT_CURLIM_LDO3 18
+#define IT_CURLIM_LDO4 19
+#define IT_CURLIM_LDO5 20
+#define IT_CURLIM_LDO6 21
+#define IT_SHORT_SWOTG 22
+#define IT_SHORT_SWOUT 23
+
+#define IT_TWARN_F 24
+#define IT_TWARN_R 25
+#define IT_VINLOW_F26
+#define IT_VINLOW_R27
+#define IT_SWIN_F  30
+#define IT_SWIN_R  31
+
+/* BUCK MODES definitions */
+#define STPMIC1_BUCK_MODE_NORMAL 0
+#define STPMIC1_BUCK_MODE_LP 2
+
+#endif /* __DT_BINDINGS_STPMIC1_H__ */
-- 
1.9.1


[PATCH v5 2/8] mfd: stpmic1: add stpmic1 driver

2018-10-29 Thread Pascal PAILLET-LME
stpmic1 is a pmic from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
---
changes in v5:
* use macro to define regmap register ranges
* use REGMAP_IRQ_REG marco to define interrupts
* remove st properties

 drivers/mfd/Kconfig |  13 +++
 drivers/mfd/Makefile|   1 +
 drivers/mfd/stpmic1.c   | 215 
 include/linux/mfd/stpmic1.h | 212 +++
 4 files changed, 444 insertions(+)
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 include/linux/mfd/stpmic1.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 11841f4..07e39a6 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1855,6 +1855,22 @@ config MFD_STM32_TIMERS
  for PWM and IIO Timer. This driver allow to share the
  registers between the others drivers.
 
+config MFD_STPMIC1
+   tristate "Support for STPMIC1 PMIC"
+   depends on (I2C=y && OF)
+   select REGMAP_I2C
+   select REGMAP_IRQ
+   select MFD_CORE
+   help
+ Support for ST Microelectronics STPMIC1 PMIC. STPMIC1 has power on
+ key, watchdog and regulator functionalities which are supported via
+ the relevant subsystems.  This driver provides core support for the
+ STPMIC1, in order to use the actual functionaltiy of the device other
+ drivers must be enabled.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1.
+
 menu "Multimedia Capabilities Port drivers"
depends on ARCH_SA1100
 
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 5856a94..76fff14 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -232,6 +232,7 @@ obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI)   += 
intel_soc_pmic_chtdc_ti.o
 obj-$(CONFIG_MFD_MT6397)   += mt6397-core.o
 
 obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o
+obj-$(CONFIG_MFD_STPMIC1)  += stpmic1.o
 obj-$(CONFIG_MFD_SUN4I_GPADC)  += sun4i-gpadc.o
 
 obj-$(CONFIG_MFD_STM32_LPTIMER)+= stm32-lptimer.o
diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
new file mode 100644
index 000..2f4fd5e
--- /dev/null
+++ b/drivers/mfd/stpmic1.c
@@ -0,0 +1,215 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define STPMIC1_MAIN_IRQ 0
+
+static const struct regmap_range stpmic1_readable_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_MASK_R1, INT_MASK_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R1),
+};
+
+static const struct regmap_range stpmic1_writeable_ranges[] = {
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+};
+
+static const struct regmap_range stpmic1_volatile_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(WCHDG_CR, WCHDG_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R4),
+};
+
+static const struct regmap_access_table stpmic1_readable_table = {
+   .yes_ranges = stpmic1_readable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_readable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_writeable_table = {
+   .yes_ranges = stpmic1_writeable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_writeable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_volatile_table = {
+   .yes_ranges = stpmic1_volatile_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_volatile_ranges),
+};
+
+const struct regmap_config stpmic1_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .cache_type = REGCACHE_RBTREE,
+   .max_register = PMIC_MAX_REGISTER_ADDRESS,
+   .rd_table = _readable_table,
+   .wr_table = _writeable_table,
+   .volatile_table = _volatile_table,
+};
+
+static const struct regmap_irq stpmic1_irqs[] = {
+   REGMAP_IRQ_REG(IT_PONKEY_F, 0, 0x01),
+   REGMAP_IRQ_REG(IT_PONKEY_R, 0, 0x02),
+   REGMAP_IRQ_REG(IT_WAKEUP_F, 0, 0x04),
+   REGMAP_IRQ_REG(IT_WAKEUP_R, 0, 0x08),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_F, 0, 0x10),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_R, 0, 

[PATCH v5 1/8] dt-bindings: mfd: document stpmic1

2018-10-29 Thread Pascal PAILLET-LME
stpmic1 is a pmic from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
---
changes in v5:
* removed st properties
* added buck modes definitions in the header

 .../devicetree/bindings/mfd/st,stpmic1.txt | 61 ++
 include/dt-bindings/mfd/st,stpmic1.h   | 50 ++
 2 files changed, 111 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h

diff --git a/Documentation/devicetree/bindings/mfd/st,stpmic1.txt 
b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
new file mode 100644
index 000..afd45c0
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/st,stpmic1.txt
@@ -0,0 +1,61 @@
+* STMicroelectronics STPMIC1 Power Management IC
+
+Required properties:
+- compatible:  : "st,stpmic1"
+- reg: : The I2C slave address for the STPMIC1 chip.
+- interrupts:  : The interrupt line the device is connected to.
+- #interrupt-cells:: Should be 1.
+- interrupt-controller:: Marks the device node as an interrupt 
controller.
+   Interrupt numbers are defined at
+   dt-bindings/mfd/st,stpmic1.h.
+
+STPMIC1 consists in a varied group of sub-devices.
+Each sub-device binding is be described in own documentation file.
+
+Device  Description
+-- 
+st,stpmic1-onkey   : Power on key, see ../input/st,stpmic1-onkey.txt
+st,stpmic1-regulators  : Regulators, see ../regulator/st,stpmic1-regulator.txt
+st,stpmic1-wdt : Watchdog, see ../watchdog/st,stpmic1-wdt.txt
+
+Example:
+
+#include 
+
+pmic: pmic@33 {
+   compatible = "st,stpmic1";
+   reg = <0x33>;
+   interrupt-parent = <>;
+   interrupts = <0 2>;
+
+   interrupt-controller;
+   #interrupt-cells = <2>;
+
+   onkey {
+   compatible = "st,stpmic1-onkey";
+   interrupts = ,;
+   interrupt-names = "onkey-falling", "onkey-rising";
+   power-off-time-sec = <10>;
+   };
+
+   watchdog {
+   compatible = "st,stpmic1-wdt";
+   };
+
+   regulators {
+   compatible = "st,stpmic1-regulators";
+
+   vdd_core: buck1 {
+   regulator-name = "vdd_core";
+   regulator-boot-on;
+   regulator-min-microvolt = <70>;
+   regulator-max-microvolt = <120>;
+   };
+   vdd: buck3 {
+   regulator-name = "vdd";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-boot-on;
+   regulator-pull-down;
+   };
+   };
diff --git a/include/dt-bindings/mfd/st,stpmic1.h 
b/include/dt-bindings/mfd/st,stpmic1.h
new file mode 100644
index 000..321cd087
--- /dev/null
+++ b/include/dt-bindings/mfd/st,stpmic1.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) STMicroelectronics 2018 - All Rights Reserved
+ * Author: Philippe Peurichard ,
+ * Pascal Paillet  for STMicroelectronics.
+ */
+
+#ifndef __DT_BINDINGS_STPMIC1_H__
+#define __DT_BINDINGS_STPMIC1_H__
+
+/* IRQ definitions */
+#define IT_PONKEY_F0
+#define IT_PONKEY_R1
+#define IT_WAKEUP_F2
+#define IT_WAKEUP_R3
+#define IT_VBUS_OTG_F  4
+#define IT_VBUS_OTG_R  5
+#define IT_SWOUT_F 6
+#define IT_SWOUT_R 7
+
+#define IT_CURLIM_BUCK18
+#define IT_CURLIM_BUCK29
+#define IT_CURLIM_BUCK310
+#define IT_CURLIM_BUCK411
+#define IT_OCP_OTG 12
+#define IT_OCP_SWOUT   13
+#define IT_OCP_BOOST   14
+#define IT_OVP_BOOST   15
+
+#define IT_CURLIM_LDO1 16
+#define IT_CURLIM_LDO2 17
+#define IT_CURLIM_LDO3 18
+#define IT_CURLIM_LDO4 19
+#define IT_CURLIM_LDO5 20
+#define IT_CURLIM_LDO6 21
+#define IT_SHORT_SWOTG 22
+#define IT_SHORT_SWOUT 23
+
+#define IT_TWARN_F 24
+#define IT_TWARN_R 25
+#define IT_VINLOW_F26
+#define IT_VINLOW_R27
+#define IT_SWIN_F  30
+#define IT_SWIN_R  31
+
+/* BUCK MODES definitions */
+#define STPMIC1_BUCK_MODE_NORMAL 0
+#define STPMIC1_BUCK_MODE_LP 2
+
+#endif /* __DT_BINDINGS_STPMIC1_H__ */
-- 
1.9.1


[PATCH v5 2/8] mfd: stpmic1: add stpmic1 driver

2018-10-29 Thread Pascal PAILLET-LME
stpmic1 is a pmic from STMicroelectronics. The STPMIC1 integrates 10
regulators, 3 power switches, a watchdog and an input for a power on key.

Signed-off-by: Pascal Paillet 
---
changes in v5:
* use macro to define regmap register ranges
* use REGMAP_IRQ_REG marco to define interrupts
* remove st properties

 drivers/mfd/Kconfig |  13 +++
 drivers/mfd/Makefile|   1 +
 drivers/mfd/stpmic1.c   | 215 
 include/linux/mfd/stpmic1.h | 212 +++
 4 files changed, 444 insertions(+)
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 include/linux/mfd/stpmic1.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 11841f4..07e39a6 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1855,6 +1855,22 @@ config MFD_STM32_TIMERS
  for PWM and IIO Timer. This driver allow to share the
  registers between the others drivers.
 
+config MFD_STPMIC1
+   tristate "Support for STPMIC1 PMIC"
+   depends on (I2C=y && OF)
+   select REGMAP_I2C
+   select REGMAP_IRQ
+   select MFD_CORE
+   help
+ Support for ST Microelectronics STPMIC1 PMIC. STPMIC1 has power on
+ key, watchdog and regulator functionalities which are supported via
+ the relevant subsystems.  This driver provides core support for the
+ STPMIC1, in order to use the actual functionaltiy of the device other
+ drivers must be enabled.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1.
+
 menu "Multimedia Capabilities Port drivers"
depends on ARCH_SA1100
 
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 5856a94..76fff14 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -232,6 +232,7 @@ obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI)   += 
intel_soc_pmic_chtdc_ti.o
 obj-$(CONFIG_MFD_MT6397)   += mt6397-core.o
 
 obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o
+obj-$(CONFIG_MFD_STPMIC1)  += stpmic1.o
 obj-$(CONFIG_MFD_SUN4I_GPADC)  += sun4i-gpadc.o
 
 obj-$(CONFIG_MFD_STM32_LPTIMER)+= stm32-lptimer.o
diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
new file mode 100644
index 000..2f4fd5e
--- /dev/null
+++ b/drivers/mfd/stpmic1.c
@@ -0,0 +1,215 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define STPMIC1_MAIN_IRQ 0
+
+static const struct regmap_range stpmic1_readable_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_MASK_R1, INT_MASK_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R1),
+};
+
+static const struct regmap_range stpmic1_writeable_ranges[] = {
+   regmap_reg_range(SWOFF_PWRCTRL_CR, LDO6_STDBY_CR),
+   regmap_reg_range(BST_SW_CR, BST_SW_CR),
+   regmap_reg_range(INT_CLEAR_R1, INT_CLEAR_R4),
+   regmap_reg_range(INT_SET_MASK_R1, INT_SET_MASK_R4),
+   regmap_reg_range(INT_CLEAR_MASK_R1, INT_CLEAR_MASK_R4),
+};
+
+static const struct regmap_range stpmic1_volatile_ranges[] = {
+   regmap_reg_range(TURN_ON_SR, VERSION_SR),
+   regmap_reg_range(WCHDG_CR, WCHDG_CR),
+   regmap_reg_range(INT_PENDING_R1, INT_PENDING_R4),
+   regmap_reg_range(INT_SRC_R1, INT_SRC_R4),
+};
+
+static const struct regmap_access_table stpmic1_readable_table = {
+   .yes_ranges = stpmic1_readable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_readable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_writeable_table = {
+   .yes_ranges = stpmic1_writeable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_writeable_ranges),
+};
+
+static const struct regmap_access_table stpmic1_volatile_table = {
+   .yes_ranges = stpmic1_volatile_ranges,
+   .n_yes_ranges = ARRAY_SIZE(stpmic1_volatile_ranges),
+};
+
+const struct regmap_config stpmic1_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .cache_type = REGCACHE_RBTREE,
+   .max_register = PMIC_MAX_REGISTER_ADDRESS,
+   .rd_table = _readable_table,
+   .wr_table = _writeable_table,
+   .volatile_table = _volatile_table,
+};
+
+static const struct regmap_irq stpmic1_irqs[] = {
+   REGMAP_IRQ_REG(IT_PONKEY_F, 0, 0x01),
+   REGMAP_IRQ_REG(IT_PONKEY_R, 0, 0x02),
+   REGMAP_IRQ_REG(IT_WAKEUP_F, 0, 0x04),
+   REGMAP_IRQ_REG(IT_WAKEUP_R, 0, 0x08),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_F, 0, 0x10),
+   REGMAP_IRQ_REG(IT_VBUS_OTG_R, 0, 

[PATCH v5 4/8] regulator: stpmic1: add stpmic1 regulator driver

2018-10-29 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds several regulators and switches with
different capabilities.

Signed-off-by: Pascal Paillet 
---
changes in v5:
* rework probe: do not modify init data
* merge stpmic1_regulator_init and stpmic1_regulator_parse_dt in the probe fn
* map_mode returns REGULATOR_MODE_INVALID
* add active discharge ops for usb power switches
* move buck modes definition to the binding header

 drivers/regulator/Kconfig |  12 +
 drivers/regulator/Makefile|   1 +
 drivers/regulator/stpmic1_regulator.c | 667 ++
 3 files changed, 680 insertions(+)
 create mode 100644 drivers/regulator/stpmic1_regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 6e96ef1..026d480 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -803,6 +803,18 @@ config REGULATOR_STM32_VREFBUF
  This driver can also be built as a module. If so, the module
  will be called stm32-vrefbuf.
 
+config REGULATOR_STPMIC1
+   tristate "STMicroelectronics STPMIC1 PMIC Regulators"
+   depends on MFD_STPMIC1
+   help
+ This driver supports STMicroelectronics STPMIC1 PMIC voltage
+ regulators and switches. The STPMIC1 regulators supply power to
+ an application processor as well as to external system
+ peripherals such as DDR, Flash memories and system devices.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1_regulator.
+
 config REGULATOR_TI_ABB
tristate "TI Adaptive Body Bias on-chip LDO"
depends on ARCH_OMAP
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index eac4d79..300bc4c 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -101,6 +101,7 @@ obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
 obj-$(CONFIG_REGULATOR_SC2731) += sc2731-regulator.o
 obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o
 obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
+obj-$(CONFIG_REGULATOR_STPMIC1) += stpmic1_regulator.o
 obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o
 obj-$(CONFIG_REGULATOR_SY8106A) += sy8106a-regulator.o
 obj-$(CONFIG_REGULATOR_TI_ABB) += ti-abb-regulator.o
diff --git a/drivers/regulator/stpmic1_regulator.c 
b/drivers/regulator/stpmic1_regulator.c
new file mode 100644
index 000..c96edcd
--- /dev/null
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -0,0 +1,667 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/**
+ * stpmic1 regulator description
+ * @desc: regulator framework description
+ * @mask_reset_reg: mask reset register address
+ * @mask_reset_mask: mask rank and mask reset register mask
+ * @icc_reg: icc register address
+ * @icc_mask: icc register mask
+ */
+struct stpmic1_regulator_cfg {
+   struct regulator_desc desc;
+   u8 mask_reset_reg;
+   u8 mask_reset_mask;
+   u8 icc_reg;
+   u8 icc_mask;
+};
+
+/**
+ * stpmic1 regulator data: this structure is used as driver data
+ * @regul_id: regulator id
+ * @reg_node: DT node of regulator (unused on non-DT platforms)
+ * @cfg: stpmic specific regulator description
+ * @regmap: point to parent regmap structure
+ */
+struct stpmic1_regulator {
+   unsigned int regul_id;
+   struct device_node *reg_node;
+   struct stpmic1_regulator_cfg *cfg;
+   struct regmap *regmap;
+};
+
+static int stpmic1_set_mode(struct regulator_dev *rdev, unsigned int mode);
+static unsigned int stpmic1_get_mode(struct regulator_dev *rdev);
+static int stpmic1_set_icc(struct regulator_dev *rdev);
+static unsigned int stpmic1_map_mode(unsigned int mode);
+
+enum {
+   STPMIC1_BUCK1 = 0,
+   STPMIC1_BUCK2 = 1,
+   STPMIC1_BUCK3 = 2,
+   STPMIC1_BUCK4 = 3,
+   STPMIC1_LDO1 = 4,
+   STPMIC1_LDO2 = 5,
+   STPMIC1_LDO3 = 6,
+   STPMIC1_LDO4 = 7,
+   STPMIC1_LDO5 = 8,
+   STPMIC1_LDO6 = 9,
+   STPMIC1_VREF_DDR = 10,
+   STPMIC1_BOOST = 11,
+   STPMIC1_VBUS_OTG = 12,
+   STPMIC1_SW_OUT = 13,
+};
+
+/* Enable time worst case is 5000mV/(2250uV/uS) */
+#define PMIC_ENABLE_TIME_US 2200
+
+struct regulator_linear_range buck1_ranges[] = {
+   REGULATOR_LINEAR_RANGE(60, 0, 30, 25000),
+   REGULATOR_LINEAR_RANGE(135, 31, 63, 0),
+};
+
+struct regulator_linear_range buck2_ranges[] = {
+   REGULATOR_LINEAR_RANGE(100, 0, 17, 0),
+   REGULATOR_LINEAR_RANGE(105, 18, 19, 0),
+   REGULATOR_LINEAR_RANGE(110, 20, 21, 0),
+   REGULATOR_LINEAR_RANGE(115, 22, 23, 0),
+   REGULATOR_LINEAR_RANGE(120, 24, 25, 0),
+   REGULATOR_LINEAR_RANGE(125, 26, 27, 0),
+   REGULATOR_LINEAR_RANGE(130, 28, 29, 0),
+   REGULATOR_LINEAR_RANGE(135, 30, 31, 0),
+   

[PATCH v5 6/8] input: stpmic1: add stpmic1 onkey driver

2018-10-29 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. This driver exposes
the stpmic1 onkey as an input device. It can also be configured to
shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
---
changes in v5:
* fix checkpatch warning

 drivers/input/misc/Kconfig |  11 +++
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 +
 3 files changed, 211 insertions(+)
 create mode 100644 drivers/input/misc/stpmic1_onkey.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index ca59a2b..279fb02 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -851,4 +851,15 @@ config INPUT_SC27XX_VIBRA
  To compile this driver as a module, choose M here. The module will
  be called sc27xx_vibra.
 
+config INPUT_STPMIC1_ONKEY
+   tristate "STPMIC1 PMIC Onkey support"
+   depends on MFD_STPMIC1
+   help
+ Say Y to enable support of onkey embedded into STPMIC1 PMIC. onkey
+ can be used to wakeup from low power modes and force a shut-down on
+ long press.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1_onkey.
+
 endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 9d0f9d1..1b44202 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_INPUT_SGI_BTNS)  += sgi_btns.o
 obj-$(CONFIG_INPUT_SIRFSOC_ONKEY)  += sirfsoc-onkey.o
 obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY)   += soc_button_array.o
 obj-$(CONFIG_INPUT_SPARCSPKR)  += sparcspkr.o
+obj-$(CONFIG_INPUT_STPMIC1_ONKEY)  += stpmic1_onkey.o
 obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON) += tps65218-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON)  += twl4030-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_VIBRA)  += twl4030-vibra.o
@@ -81,3 +82,4 @@ obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
 obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)+= xen-kbdfront.o
 obj-$(CONFIG_INPUT_YEALINK)+= yealink.o
 obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR)   += ideapad_slidebar.o
+
diff --git a/drivers/input/misc/stpmic1_onkey.c 
b/drivers/input/misc/stpmic1_onkey.c
new file mode 100644
index 000..7b49c99
--- /dev/null
+++ b/drivers/input/misc/stpmic1_onkey.c
@@ -0,0 +1,198 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * struct stpmic1_onkey - OnKey data
+ * @input_dev: pointer to input device
+ * @irq_falling:   irq that we are hooked on to
+ * @irq_rising:irq that we are hooked on to
+ */
+struct stpmic1_onkey {
+   struct input_dev *input_dev;
+   int irq_falling;
+   int irq_rising;
+};
+
+static irqreturn_t onkey_falling_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 1);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static irqreturn_t onkey_rising_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 0);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static int stpmic1_onkey_probe(struct platform_device *pdev)
+{
+   struct stpmic1 *pmic = dev_get_drvdata(pdev->dev.parent);
+   struct device *dev = >dev;
+   struct input_dev *input_dev;
+   struct stpmic1_onkey *onkey;
+   unsigned int val, reg = 0;
+   int error;
+
+   onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->irq_falling = platform_get_irq_byname(pdev, "onkey-falling");
+   if (onkey->irq_falling < 0) {
+   dev_err(dev, "failed: request IRQ onkey-falling %d\n",
+   onkey->irq_falling);
+   return onkey->irq_falling;
+   }
+
+   onkey->irq_rising = platform_get_irq_byname(pdev, "onkey-rising");
+   if (onkey->irq_rising < 0) {
+   dev_err(dev, "failed: request IRQ onkey-rising %d\n",
+   onkey->irq_rising);
+   return onkey->irq_rising;
+   }
+
+   if (!device_property_read_u32(dev, "power-off-time-sec", )) {
+   if (val > 0 && val <= 16) {
+   dev_dbg(dev, "power-off-time=%d seconds\n", val);
+   reg |= PONKEY_PWR_OFF;
+   reg |= ((16 - val) & PONKEY_TURNOFF_TIMER_MASK);
+   } else {
+   dev_err(dev, 

[PATCH v5 4/8] regulator: stpmic1: add stpmic1 regulator driver

2018-10-29 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds several regulators and switches with
different capabilities.

Signed-off-by: Pascal Paillet 
---
changes in v5:
* rework probe: do not modify init data
* merge stpmic1_regulator_init and stpmic1_regulator_parse_dt in the probe fn
* map_mode returns REGULATOR_MODE_INVALID
* add active discharge ops for usb power switches
* move buck modes definition to the binding header

 drivers/regulator/Kconfig |  12 +
 drivers/regulator/Makefile|   1 +
 drivers/regulator/stpmic1_regulator.c | 667 ++
 3 files changed, 680 insertions(+)
 create mode 100644 drivers/regulator/stpmic1_regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 6e96ef1..026d480 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -803,6 +803,18 @@ config REGULATOR_STM32_VREFBUF
  This driver can also be built as a module. If so, the module
  will be called stm32-vrefbuf.
 
+config REGULATOR_STPMIC1
+   tristate "STMicroelectronics STPMIC1 PMIC Regulators"
+   depends on MFD_STPMIC1
+   help
+ This driver supports STMicroelectronics STPMIC1 PMIC voltage
+ regulators and switches. The STPMIC1 regulators supply power to
+ an application processor as well as to external system
+ peripherals such as DDR, Flash memories and system devices.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1_regulator.
+
 config REGULATOR_TI_ABB
tristate "TI Adaptive Body Bias on-chip LDO"
depends on ARCH_OMAP
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index eac4d79..300bc4c 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -101,6 +101,7 @@ obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
 obj-$(CONFIG_REGULATOR_SC2731) += sc2731-regulator.o
 obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o
 obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
+obj-$(CONFIG_REGULATOR_STPMIC1) += stpmic1_regulator.o
 obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o
 obj-$(CONFIG_REGULATOR_SY8106A) += sy8106a-regulator.o
 obj-$(CONFIG_REGULATOR_TI_ABB) += ti-abb-regulator.o
diff --git a/drivers/regulator/stpmic1_regulator.c 
b/drivers/regulator/stpmic1_regulator.c
new file mode 100644
index 000..c96edcd
--- /dev/null
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -0,0 +1,667 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/**
+ * stpmic1 regulator description
+ * @desc: regulator framework description
+ * @mask_reset_reg: mask reset register address
+ * @mask_reset_mask: mask rank and mask reset register mask
+ * @icc_reg: icc register address
+ * @icc_mask: icc register mask
+ */
+struct stpmic1_regulator_cfg {
+   struct regulator_desc desc;
+   u8 mask_reset_reg;
+   u8 mask_reset_mask;
+   u8 icc_reg;
+   u8 icc_mask;
+};
+
+/**
+ * stpmic1 regulator data: this structure is used as driver data
+ * @regul_id: regulator id
+ * @reg_node: DT node of regulator (unused on non-DT platforms)
+ * @cfg: stpmic specific regulator description
+ * @regmap: point to parent regmap structure
+ */
+struct stpmic1_regulator {
+   unsigned int regul_id;
+   struct device_node *reg_node;
+   struct stpmic1_regulator_cfg *cfg;
+   struct regmap *regmap;
+};
+
+static int stpmic1_set_mode(struct regulator_dev *rdev, unsigned int mode);
+static unsigned int stpmic1_get_mode(struct regulator_dev *rdev);
+static int stpmic1_set_icc(struct regulator_dev *rdev);
+static unsigned int stpmic1_map_mode(unsigned int mode);
+
+enum {
+   STPMIC1_BUCK1 = 0,
+   STPMIC1_BUCK2 = 1,
+   STPMIC1_BUCK3 = 2,
+   STPMIC1_BUCK4 = 3,
+   STPMIC1_LDO1 = 4,
+   STPMIC1_LDO2 = 5,
+   STPMIC1_LDO3 = 6,
+   STPMIC1_LDO4 = 7,
+   STPMIC1_LDO5 = 8,
+   STPMIC1_LDO6 = 9,
+   STPMIC1_VREF_DDR = 10,
+   STPMIC1_BOOST = 11,
+   STPMIC1_VBUS_OTG = 12,
+   STPMIC1_SW_OUT = 13,
+};
+
+/* Enable time worst case is 5000mV/(2250uV/uS) */
+#define PMIC_ENABLE_TIME_US 2200
+
+struct regulator_linear_range buck1_ranges[] = {
+   REGULATOR_LINEAR_RANGE(60, 0, 30, 25000),
+   REGULATOR_LINEAR_RANGE(135, 31, 63, 0),
+};
+
+struct regulator_linear_range buck2_ranges[] = {
+   REGULATOR_LINEAR_RANGE(100, 0, 17, 0),
+   REGULATOR_LINEAR_RANGE(105, 18, 19, 0),
+   REGULATOR_LINEAR_RANGE(110, 20, 21, 0),
+   REGULATOR_LINEAR_RANGE(115, 22, 23, 0),
+   REGULATOR_LINEAR_RANGE(120, 24, 25, 0),
+   REGULATOR_LINEAR_RANGE(125, 26, 27, 0),
+   REGULATOR_LINEAR_RANGE(130, 28, 29, 0),
+   REGULATOR_LINEAR_RANGE(135, 30, 31, 0),
+   

[PATCH v5 6/8] input: stpmic1: add stpmic1 onkey driver

2018-10-29 Thread Pascal PAILLET-LME
The stpmic1 pmic is able to manage an onkey button. This driver exposes
the stpmic1 onkey as an input device. It can also be configured to
shut-down the power supplies on a long key-press with an adjustable
duration.

Signed-off-by: Pascal Paillet 
---
changes in v5:
* fix checkpatch warning

 drivers/input/misc/Kconfig |  11 +++
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 +
 3 files changed, 211 insertions(+)
 create mode 100644 drivers/input/misc/stpmic1_onkey.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index ca59a2b..279fb02 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -851,4 +851,15 @@ config INPUT_SC27XX_VIBRA
  To compile this driver as a module, choose M here. The module will
  be called sc27xx_vibra.
 
+config INPUT_STPMIC1_ONKEY
+   tristate "STPMIC1 PMIC Onkey support"
+   depends on MFD_STPMIC1
+   help
+ Say Y to enable support of onkey embedded into STPMIC1 PMIC. onkey
+ can be used to wakeup from low power modes and force a shut-down on
+ long press.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stpmic1_onkey.
+
 endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 9d0f9d1..1b44202 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_INPUT_SGI_BTNS)  += sgi_btns.o
 obj-$(CONFIG_INPUT_SIRFSOC_ONKEY)  += sirfsoc-onkey.o
 obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY)   += soc_button_array.o
 obj-$(CONFIG_INPUT_SPARCSPKR)  += sparcspkr.o
+obj-$(CONFIG_INPUT_STPMIC1_ONKEY)  += stpmic1_onkey.o
 obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON) += tps65218-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON)  += twl4030-pwrbutton.o
 obj-$(CONFIG_INPUT_TWL4030_VIBRA)  += twl4030-vibra.o
@@ -81,3 +82,4 @@ obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
 obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)+= xen-kbdfront.o
 obj-$(CONFIG_INPUT_YEALINK)+= yealink.o
 obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR)   += ideapad_slidebar.o
+
diff --git a/drivers/input/misc/stpmic1_onkey.c 
b/drivers/input/misc/stpmic1_onkey.c
new file mode 100644
index 000..7b49c99
--- /dev/null
+++ b/drivers/input/misc/stpmic1_onkey.c
@@ -0,0 +1,198 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) STMicroelectronics 2018
+// Author: Pascal Paillet  for STMicroelectronics.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * struct stpmic1_onkey - OnKey data
+ * @input_dev: pointer to input device
+ * @irq_falling:   irq that we are hooked on to
+ * @irq_rising:irq that we are hooked on to
+ */
+struct stpmic1_onkey {
+   struct input_dev *input_dev;
+   int irq_falling;
+   int irq_rising;
+};
+
+static irqreturn_t onkey_falling_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 1);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static irqreturn_t onkey_rising_irq(int irq, void *ponkey)
+{
+   struct stpmic1_onkey *onkey = ponkey;
+   struct input_dev *input_dev = onkey->input_dev;
+
+   input_report_key(input_dev, KEY_POWER, 0);
+   pm_wakeup_event(input_dev->dev.parent, 0);
+   input_sync(input_dev);
+
+   return IRQ_HANDLED;
+}
+
+static int stpmic1_onkey_probe(struct platform_device *pdev)
+{
+   struct stpmic1 *pmic = dev_get_drvdata(pdev->dev.parent);
+   struct device *dev = >dev;
+   struct input_dev *input_dev;
+   struct stpmic1_onkey *onkey;
+   unsigned int val, reg = 0;
+   int error;
+
+   onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->irq_falling = platform_get_irq_byname(pdev, "onkey-falling");
+   if (onkey->irq_falling < 0) {
+   dev_err(dev, "failed: request IRQ onkey-falling %d\n",
+   onkey->irq_falling);
+   return onkey->irq_falling;
+   }
+
+   onkey->irq_rising = platform_get_irq_byname(pdev, "onkey-rising");
+   if (onkey->irq_rising < 0) {
+   dev_err(dev, "failed: request IRQ onkey-rising %d\n",
+   onkey->irq_rising);
+   return onkey->irq_rising;
+   }
+
+   if (!device_property_read_u32(dev, "power-off-time-sec", )) {
+   if (val > 0 && val <= 16) {
+   dev_dbg(dev, "power-off-time=%d seconds\n", val);
+   reg |= PONKEY_PWR_OFF;
+   reg |= ((16 - val) & PONKEY_TURNOFF_TIMER_MASK);
+   } else {
+   dev_err(dev, 

[PATCH v5 7/8] dt-bindings: watchdog: document stpmic1 pmic watchdog

2018-10-29 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default.
In case of watchdog, the PMIC goes off.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
---
changes in v5: nothing

 Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt

diff --git a/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt 
b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
new file mode 100644
index 000..7cc1407
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
@@ -0,0 +1,11 @@
+STMicroelectronics STPMIC1 Watchdog
+
+Required properties:
+
+- compatible : should be "st,stpmic1-wdt"
+
+Example:
+
+watchdog {
+   compatible = "st,stpmic1-wdt";
+};
-- 
1.9.1


[PATCH v5 7/8] dt-bindings: watchdog: document stpmic1 pmic watchdog

2018-10-29 Thread Pascal PAILLET-LME
The stpmic1 PMIC embeds a watchdog which is disabled by default.
In case of watchdog, the PMIC goes off.

Signed-off-by: Pascal Paillet 
Reviewed-by: Rob Herring 
---
changes in v5: nothing

 Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt

diff --git a/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt 
b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
new file mode 100644
index 000..7cc1407
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
@@ -0,0 +1,11 @@
+STMicroelectronics STPMIC1 Watchdog
+
+Required properties:
+
+- compatible : should be "st,stpmic1-wdt"
+
+Example:
+
+watchdog {
+   compatible = "st,stpmic1-wdt";
+};
-- 
1.9.1


[PATCH v5 0/8] Introduce STPMIC1 PMIC Driver

2018-10-29 Thread Pascal PAILLET-LME
The goal of this patch-set is to propose a driver for the STPMIC1 PMIC from 
STMicroelectronics. 
The STPMIC1 regulators supply power to an application processor as well as 
to external system peripherals such as DDR, Flash memories and system
devices. It also features onkey button input and an hardware watchdog.
The STPMIC1 is controlled via I2C. 

Main driver is drivers/mfd/stpmic1 that handle I2C regmap configuration and
irqchip. stpmic1_regulator, stpmic1_onkey and stpmic1_wdt need stpmic1 mfd
as parent.

stpmic1 mfd and regulator drivers maybe mandatory at boot time.

Pascal Paillet (8):
  dt-bindings: mfd: document stpmic1
  mfd: stpmic1: add stpmic1 driver
  dt-bindings: regulator: document stpmic1 pmic regulators
  regulator: stpmic1: add stpmic1 regulator driver
  dt-bindings: input: document stpmic1 pmic onkey
  input: stpmic1: add stpmic1 onkey driver
  dt-bindings: watchdog: document stpmic1 pmic watchdog
  watchdog: stpmic1: add stpmic1 watchdog driver

 .../devicetree/bindings/input/st,stpmic1-onkey.txt |  28 +
 .../devicetree/bindings/mfd/st,stpmic1.txt |  61 ++
 .../bindings/regulator/st,stpmic1-regulator.txt|  67 +++
 .../bindings/watchdog/st,stpmic1-wdt.txt   |  11 +
 drivers/input/misc/Kconfig |  11 +
 drivers/input/misc/Makefile|   2 +
 drivers/input/misc/stpmic1_onkey.c | 198 ++
 drivers/mfd/Kconfig|  16 +
 drivers/mfd/Makefile   |   1 +
 drivers/mfd/stpmic1.c  | 215 +++
 drivers/regulator/Kconfig  |  12 +
 drivers/regulator/Makefile |   1 +
 drivers/regulator/stpmic1_regulator.c  | 667 +
 drivers/watchdog/Kconfig   |  12 +
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/stpmic1_wdt.c | 139 +
 include/dt-bindings/mfd/st,stpmic1.h   |  50 ++
 include/linux/mfd/stpmic1.h| 212 +++
 18 files changed, 1704 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/st,stpmic1-onkey.txt
 create mode 100644 Documentation/devicetree/bindings/mfd/st,stpmic1.txt
 create mode 100644 
Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
 create mode 100644 
Documentation/devicetree/bindings/watchdog/st,stpmic1-wdt.txt
 create mode 100644 drivers/input/misc/stpmic1_onkey.c
 create mode 100644 drivers/mfd/stpmic1.c
 create mode 100644 drivers/regulator/stpmic1_regulator.c
 create mode 100644 drivers/watchdog/stpmic1_wdt.c
 create mode 100644 include/dt-bindings/mfd/st,stpmic1.h
 create mode 100644 include/linux/mfd/stpmic1.h

-- 
1.9.1


  1   2   >