[PATCH v2 2/2] regulator: tps65132: add device-tree binding

2017-04-12 Thread Venkat Reddy Talla
Add tps65132 regulator device-tree binding documentation

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
---
Changes for v2:
 - change dts property names
 - add reg dts property
--- 
 .../bindings/regulator/tps65132-regulator.txt  | 46 ++
 1 file changed, 46 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/regulator/tps65132-regulator.txt

diff --git a/Documentation/devicetree/bindings/regulator/tps65132-regulator.txt 
b/Documentation/devicetree/bindings/regulator/tps65132-regulator.txt
new file mode 100644
index 000..3a35055
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/tps65132-regulator.txt
@@ -0,0 +1,46 @@
+TPS65132 regulators
+
+Required properties:
+- compatible: "ti,tps65132"
+- reg: I2C slave address
+
+Optional Subnode:
+Device supports two regulators OUTP and OUTN. A sub node within the
+   device node describe the properties of these regulators. The sub-node
+   names must be as follows:
+   -For regulator outp, the sub node name should be "outp".
+   -For regulator outn, the sub node name should be "outn".
+
+-enable-gpios:(active high, output) Regulators are controlled by the input 
pins.
+   If it is connected to GPIO through host system then provide the
+   gpio number as per gpio.txt.
+-active-discharge-gpios: (active high, output) Some configurations use delay 
mechanisms
+  on the enable pin, to keep the regulator enabled for some time after
+  the enable signal goes low. This GPIO is used to actively discharge
+  the delay mechanism. Requires specification of ti,active-discharge-time-us
+-ti,active-discharge-time-us: how long the active discharge gpio should be
+  asserted for during active discharge, in microseconds.
+
+Each regulator is defined using the standard binding for regulators.
+
+Example:
+
+   tps65132@3e {
+   compatible = "ti,tps65132";
+   reg = <0x3e>;
+
+   outp {
+   regulator-name = "outp";
+   regulator-boot-on;
+   regulator-always-on;
+   enable-gpios = < 23 0>;
+   };
+
+   outn {
+   regulator-name = "outn";
+   regulator-boot-on;
+   regulator-always-on;
+   regulator-active-discharge = <0>;
+   enable-gpios = < 40 0>;
+   };
+   };
-- 
2.1.4



[PATCH v2 2/2] regulator: tps65132: add device-tree binding

2017-04-12 Thread Venkat Reddy Talla
Add tps65132 regulator device-tree binding documentation

Signed-off-by: Venkat Reddy Talla 
---
Changes for v2:
 - change dts property names
 - add reg dts property
--- 
 .../bindings/regulator/tps65132-regulator.txt  | 46 ++
 1 file changed, 46 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/regulator/tps65132-regulator.txt

diff --git a/Documentation/devicetree/bindings/regulator/tps65132-regulator.txt 
b/Documentation/devicetree/bindings/regulator/tps65132-regulator.txt
new file mode 100644
index 000..3a35055
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/tps65132-regulator.txt
@@ -0,0 +1,46 @@
+TPS65132 regulators
+
+Required properties:
+- compatible: "ti,tps65132"
+- reg: I2C slave address
+
+Optional Subnode:
+Device supports two regulators OUTP and OUTN. A sub node within the
+   device node describe the properties of these regulators. The sub-node
+   names must be as follows:
+   -For regulator outp, the sub node name should be "outp".
+   -For regulator outn, the sub node name should be "outn".
+
+-enable-gpios:(active high, output) Regulators are controlled by the input 
pins.
+   If it is connected to GPIO through host system then provide the
+   gpio number as per gpio.txt.
+-active-discharge-gpios: (active high, output) Some configurations use delay 
mechanisms
+  on the enable pin, to keep the regulator enabled for some time after
+  the enable signal goes low. This GPIO is used to actively discharge
+  the delay mechanism. Requires specification of ti,active-discharge-time-us
+-ti,active-discharge-time-us: how long the active discharge gpio should be
+  asserted for during active discharge, in microseconds.
+
+Each regulator is defined using the standard binding for regulators.
+
+Example:
+
+   tps65132@3e {
+   compatible = "ti,tps65132";
+   reg = <0x3e>;
+
+   outp {
+   regulator-name = "outp";
+   regulator-boot-on;
+   regulator-always-on;
+   enable-gpios = < 23 0>;
+   };
+
+   outn {
+   regulator-name = "outn";
+   regulator-boot-on;
+   regulator-always-on;
+   regulator-active-discharge = <0>;
+   enable-gpios = < 40 0>;
+   };
+   };
-- 
2.1.4



[PATCH v2 1/2] regulator: tps65132: add regulator driver for TI TPS65132

2017-04-12 Thread Venkat Reddy Talla
Add regulator driver for the device TI TPS65132 which is single
inductor - dual output power supply device. TPS65132 device is
designed to support general positive/negative driven applications
like TFT display panels.

TPS65132 regulator driver supports to enable/disable and set voltage
on its output.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
Signed-off-by: Laxman Dewangan <ldewan...@nvidia.com>
---
Changes for v2:
 - use of_parse_cb to parse dts properties
 - change dts property names
 - use module_i2c_driver
---
 drivers/regulator/Kconfig  |   8 +
 drivers/regulator/Makefile |   1 +
 drivers/regulator/tps65132-regulator.c | 285 +
 3 files changed, 294 insertions(+)
 create mode 100644 drivers/regulator/tps65132-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index be06eb2..39d6ffe 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -788,6 +788,14 @@ config REGULATOR_TPS65090
  This driver provides support for the voltage regulators on the
  TI TPS65090 PMIC.
 
+config REGULATOR_TPS65132
+   tristate "TI TPS65132 Dual Output Power regulators"
+   depends on I2C && GPIOLIB
+   select REGMAP_I2C
+   help
+ This driver supports TPS65132 single inductor - dual output
+ power supply specifcally designed for display panels.
+
 config REGULATOR_TPS65217
tristate "TI TPS65217 Power regulators"
depends on MFD_TPS65217
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index ef7725e..8bc7faa 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -105,6 +105,7 @@ obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o
 obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o
 obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o
 obj-$(CONFIG_REGULATOR_TPS80031) += tps80031-regulator.o
+obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o
 obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o
 obj-$(CONFIG_REGULATOR_VEXPRESS) += vexpress-regulator.o
 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o
diff --git a/drivers/regulator/tps65132-regulator.c 
b/drivers/regulator/tps65132-regulator.c
new file mode 100644
index 000..a949206
--- /dev/null
+++ b/drivers/regulator/tps65132-regulator.c
@@ -0,0 +1,285 @@
+/*
+ * TI TPS65132 Regulator driver
+ *
+ * Copyright (C) 2017 NVIDIA CORPORATION. All rights reserved.
+ *
+ * Author: Venkat Reddy Talla <vreddyta...@nvidia.com>
+ * Laxman Dewangan <ldewan...@nvidia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
+ * whether express or implied; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define TPS65132_REG_VPOS  0x00
+#define TPS65132_REG_VNEG  0x01
+#define TPS65132_REG_APPS_DISP_DISN0x03
+#define TPS65132_REG_CONTROL   0x0FF
+
+#define TPS65132_VOUT_MASK 0x1F
+#define TPS65132_VOUT_N_VOLTAGE0x15
+#define TPS65132_VOUT_VMIN 400
+#define TPS65132_VOUT_VMAX 600
+#define TPS65132_VOUT_STEP 10
+
+#define TPS65132_REG_APPS_DIS_VPOS BIT(0)
+#define TPS65132_REG_APPS_DIS_VNEG BIT(1)
+
+#define TPS65132_REGULATOR_ID_VPOS 0
+#define TPS65132_REGULATOR_ID_VNEG 1
+#define TPS65132_MAX_REGULATORS2
+
+#define TPS65132_ACT_DIS_TIME_SLACK1000
+
+struct tps65132_reg_pdata {
+   struct gpio_desc *en_gpiod;
+   struct gpio_desc *act_dis_gpiod;
+   unsigned int act_dis_time_us;
+   int ena_gpio_state;
+};
+
+struct tps65132_regulator {
+   struct device *dev;
+   struct regmap *rmap;
+   struct regulator_desc *rdesc[TPS65132_MAX_REGULATORS];
+   struct tps65132_reg_pdata reg_pdata[TPS65132_MAX_REGULATORS];
+   struct regulator_dev *rdev[TPS65132_MAX_REGULATORS];
+};
+
+static int tps65132_regulator_enable(struct regulator_dev *rdev)
+{
+   struct tps65132_regulator *tps = rdev_get_drvdata(rdev);
+   int id = rdev_get_id(rdev);
+   struct tps65132_reg_pdata *rpdata = >reg_pdata[id];
+   int ret;
+
+   if (!IS_ERR(rpdata->en_gpiod)) {
+   gpiod_set_value_cansleep(rpdata->en_gpiod, 1);
+   rpdata->ena_gpio_state = 1;
+   }
+
+   /* Hardware automatically enable 

[PATCH v2 1/2] regulator: tps65132: add regulator driver for TI TPS65132

2017-04-12 Thread Venkat Reddy Talla
Add regulator driver for the device TI TPS65132 which is single
inductor - dual output power supply device. TPS65132 device is
designed to support general positive/negative driven applications
like TFT display panels.

TPS65132 regulator driver supports to enable/disable and set voltage
on its output.

Signed-off-by: Venkat Reddy Talla 
Signed-off-by: Laxman Dewangan 
---
Changes for v2:
 - use of_parse_cb to parse dts properties
 - change dts property names
 - use module_i2c_driver
---
 drivers/regulator/Kconfig  |   8 +
 drivers/regulator/Makefile |   1 +
 drivers/regulator/tps65132-regulator.c | 285 +
 3 files changed, 294 insertions(+)
 create mode 100644 drivers/regulator/tps65132-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index be06eb2..39d6ffe 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -788,6 +788,14 @@ config REGULATOR_TPS65090
  This driver provides support for the voltage regulators on the
  TI TPS65090 PMIC.
 
+config REGULATOR_TPS65132
+   tristate "TI TPS65132 Dual Output Power regulators"
+   depends on I2C && GPIOLIB
+   select REGMAP_I2C
+   help
+ This driver supports TPS65132 single inductor - dual output
+ power supply specifcally designed for display panels.
+
 config REGULATOR_TPS65217
tristate "TI TPS65217 Power regulators"
depends on MFD_TPS65217
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index ef7725e..8bc7faa 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -105,6 +105,7 @@ obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o
 obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o
 obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o
 obj-$(CONFIG_REGULATOR_TPS80031) += tps80031-regulator.o
+obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o
 obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o
 obj-$(CONFIG_REGULATOR_VEXPRESS) += vexpress-regulator.o
 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o
diff --git a/drivers/regulator/tps65132-regulator.c 
b/drivers/regulator/tps65132-regulator.c
new file mode 100644
index 000..a949206
--- /dev/null
+++ b/drivers/regulator/tps65132-regulator.c
@@ -0,0 +1,285 @@
+/*
+ * TI TPS65132 Regulator driver
+ *
+ * Copyright (C) 2017 NVIDIA CORPORATION. All rights reserved.
+ *
+ * Author: Venkat Reddy Talla 
+ * Laxman Dewangan 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
+ * whether express or implied; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define TPS65132_REG_VPOS  0x00
+#define TPS65132_REG_VNEG  0x01
+#define TPS65132_REG_APPS_DISP_DISN0x03
+#define TPS65132_REG_CONTROL   0x0FF
+
+#define TPS65132_VOUT_MASK 0x1F
+#define TPS65132_VOUT_N_VOLTAGE0x15
+#define TPS65132_VOUT_VMIN 400
+#define TPS65132_VOUT_VMAX 600
+#define TPS65132_VOUT_STEP 10
+
+#define TPS65132_REG_APPS_DIS_VPOS BIT(0)
+#define TPS65132_REG_APPS_DIS_VNEG BIT(1)
+
+#define TPS65132_REGULATOR_ID_VPOS 0
+#define TPS65132_REGULATOR_ID_VNEG 1
+#define TPS65132_MAX_REGULATORS2
+
+#define TPS65132_ACT_DIS_TIME_SLACK1000
+
+struct tps65132_reg_pdata {
+   struct gpio_desc *en_gpiod;
+   struct gpio_desc *act_dis_gpiod;
+   unsigned int act_dis_time_us;
+   int ena_gpio_state;
+};
+
+struct tps65132_regulator {
+   struct device *dev;
+   struct regmap *rmap;
+   struct regulator_desc *rdesc[TPS65132_MAX_REGULATORS];
+   struct tps65132_reg_pdata reg_pdata[TPS65132_MAX_REGULATORS];
+   struct regulator_dev *rdev[TPS65132_MAX_REGULATORS];
+};
+
+static int tps65132_regulator_enable(struct regulator_dev *rdev)
+{
+   struct tps65132_regulator *tps = rdev_get_drvdata(rdev);
+   int id = rdev_get_id(rdev);
+   struct tps65132_reg_pdata *rpdata = >reg_pdata[id];
+   int ret;
+
+   if (!IS_ERR(rpdata->en_gpiod)) {
+   gpiod_set_value_cansleep(rpdata->en_gpiod, 1);
+   rpdata->ena_gpio_state = 1;
+   }
+
+   /* Hardware automatically enable discharge bit in enable */
+   if (rdev->constraints->active_discharge ==
+   REGULATOR_ACTIVE_DISCHARGE_DISABLE) {
+  

[PATCH 2/2] regulator: tps65132: add device-tree binding

2017-03-06 Thread Venkat Reddy Talla
Adding tps65132 regulator devicetree binding documentation

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
---
 .../bindings/regulator/tps65132-regulator.txt  | 46 ++
 1 file changed, 46 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/regulator/tps65132-regulator.txt

diff --git a/Documentation/devicetree/bindings/regulator/tps65132-regulator.txt 
b/Documentation/devicetree/bindings/regulator/tps65132-regulator.txt
new file mode 100644
index 000..1ef6ede
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/tps65132-regulator.txt
@@ -0,0 +1,46 @@
+TPS65132 regulators
+
+Required properties:
+- compatible: "ti,tps65132"
+- reg: I2C slave address
+
+Optional Subnode:
+Device supports two regulators OUTP and OUTN. A sub node within the
+   device node descrbe the properties of these regulators. The sub-node
+   names must be as follows:
+   -For regulator outp, the sub node name should be "outp".
+   -For regulator outn, the sub node name should be "outn".
+
+-ti,enable-gpio: Regulators are controlled by the input pins. If
+   it is connected to GPIO through host system then provide the
+   gpio number as per gpio.txt.
+-ti,disable-active-discharge: Boolean, presence of this property
+   will disable active discharge on the regulator output.
+-ti,active-discharge-gpio: Some configurations use delay mechanisms
+  on the enable pin, to keep the regulator enabled for some time after
+  the enable signal goes low. This GPIO is used to actively discharge
+  the delay mechanism. Requires specification of ti,active-discharge-time
+-ti,active-discharge-time: how long the active discharge gpio should be
+  asserted for during active discharge, in microseconds.
+
+Each regulator is defined using the standard binding for regulators.
+
+Example:
+
+   tps65132@3e {
+   compatible = "ti,tps65132";
+
+   outp {
+   regulator-name = "outp";
+   regulator-boot-on;
+   regulator-always-on;
+   ti,enable-gpio = < 23 0>;
+   };
+
+   outn {
+   regulator-name = "outn";
+   regulator-boot-on;
+   regulator-always-on;
+   ti,enable-gpio = < 40 0>;
+   };
+   };
-- 
2.1.4



[PATCH 2/2] regulator: tps65132: add device-tree binding

2017-03-06 Thread Venkat Reddy Talla
Adding tps65132 regulator devicetree binding documentation

Signed-off-by: Venkat Reddy Talla 
---
 .../bindings/regulator/tps65132-regulator.txt  | 46 ++
 1 file changed, 46 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/regulator/tps65132-regulator.txt

diff --git a/Documentation/devicetree/bindings/regulator/tps65132-regulator.txt 
b/Documentation/devicetree/bindings/regulator/tps65132-regulator.txt
new file mode 100644
index 000..1ef6ede
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/tps65132-regulator.txt
@@ -0,0 +1,46 @@
+TPS65132 regulators
+
+Required properties:
+- compatible: "ti,tps65132"
+- reg: I2C slave address
+
+Optional Subnode:
+Device supports two regulators OUTP and OUTN. A sub node within the
+   device node descrbe the properties of these regulators. The sub-node
+   names must be as follows:
+   -For regulator outp, the sub node name should be "outp".
+   -For regulator outn, the sub node name should be "outn".
+
+-ti,enable-gpio: Regulators are controlled by the input pins. If
+   it is connected to GPIO through host system then provide the
+   gpio number as per gpio.txt.
+-ti,disable-active-discharge: Boolean, presence of this property
+   will disable active discharge on the regulator output.
+-ti,active-discharge-gpio: Some configurations use delay mechanisms
+  on the enable pin, to keep the regulator enabled for some time after
+  the enable signal goes low. This GPIO is used to actively discharge
+  the delay mechanism. Requires specification of ti,active-discharge-time
+-ti,active-discharge-time: how long the active discharge gpio should be
+  asserted for during active discharge, in microseconds.
+
+Each regulator is defined using the standard binding for regulators.
+
+Example:
+
+   tps65132@3e {
+   compatible = "ti,tps65132";
+
+   outp {
+   regulator-name = "outp";
+   regulator-boot-on;
+   regulator-always-on;
+   ti,enable-gpio = < 23 0>;
+   };
+
+   outn {
+   regulator-name = "outn";
+   regulator-boot-on;
+   regulator-always-on;
+   ti,enable-gpio = < 40 0>;
+   };
+   };
-- 
2.1.4



[PATCH 1/2] regulator: tps65132: add regulator driver for TI TPS65132

2017-03-06 Thread Venkat Reddy Talla
Adding regulator driver for the device TI TPS65132 which is
single inductor - dual output power supply device. TPS65132
device is designed to support general positive/negative
driven applications like TFT display panels.

TPS65132 regulator driver supports to enable/disable and
set voltage on its output.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
---
 drivers/regulator/Kconfig  |   8 +
 drivers/regulator/Makefile |   1 +
 drivers/regulator/tps65132-regulator.c | 327 +
 3 files changed, 336 insertions(+)
 create mode 100644 drivers/regulator/tps65132-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index be06eb2..85d295d 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -843,6 +843,14 @@ config REGULATOR_TPS80031
  converters, 11 general purpose LDOs, VBUS generator and digital
  output to control regulators.

+config REGULATOR_TPS65132
+   tristate "TI TPS65132 Dual Output Power regulators"
+   depends on I2C && GPIOLIB
+   select REGMAP_I2C
+   help
+ This driver supports TPS65132 single inductor - dual output
+ power supply specifcally designed for display panels.
+
 config REGULATOR_TWL4030
tristate "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC"
depends on TWL4030_CORE
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index ef7725e..8bc7faa 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -105,6 +105,7 @@ obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o
 obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o
 obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o
 obj-$(CONFIG_REGULATOR_TPS80031) += tps80031-regulator.o
+obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o
 obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o
 obj-$(CONFIG_REGULATOR_VEXPRESS) += vexpress-regulator.o
 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o
diff --git a/drivers/regulator/tps65132-regulator.c 
b/drivers/regulator/tps65132-regulator.c
new file mode 100644
index 000..f50f3ad
--- /dev/null
+++ b/drivers/regulator/tps65132-regulator.c
@@ -0,0 +1,327 @@
+/*
+ * TI TPS65132 Regulator driver
+ *
+ * Copyright (C) 2015 NVIDIA CORPORATION. All rights reserved.
+ *
+ * Author: Laxman Dewangan <ldewan...@nvidia.com>
+ * Venkat Reddy Talla <vreddyta...@nvidia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
+ * whether express or implied; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define tps65132_rails(_name)  "tps65132-"#_name
+
+#define TPS65132_REG_VPOS  0x00
+#define TPS65132_REG_VNEG  0x01
+#define TPS65132_REG_APPS_DISP_DISN0x03
+#define TPS65132_REG_CONTROL   0x0FF
+
+#define TPS65132_VOUT_MASK 0x1F
+#define TPS65132_VOUT_N_VOLTAGE0x15
+#define TPS65132_VOUT_VMIN 400
+#define TPS65132_VOUT_VMAX 600
+#define TPS65132_VOUT_STEP 10
+
+#define TPS65132_REG_APPS_DISN BIT(0)
+#define TPS65132_REG_APPS_DISP BIT(1)
+
+#define TPS65132_REGULATOR_ID_VPOS 0
+#define TPS65132_REGULATOR_ID_VNEG 1
+#define TPS65132_MAX_REGULATORS2
+
+#define TPS65132_ACT_DIS_TIME_SLACK1000
+
+struct tps65132_reg_pdata {
+   struct regulator_init_data *ridata;
+   unsigned int active_discharge_time;
+   int enable_gpio;
+   int active_discharge_gpio;
+   bool disable_active_discharge;
+};
+
+struct tps65132_regulator {
+   struct device *dev;
+   struct regmap *rmap;
+   struct regulator_desc *rdesc[TPS65132_MAX_REGULATORS];
+   struct tps65132_reg_pdata reg_pdata[TPS65132_MAX_REGULATORS];
+   struct regulator_dev *rdev[TPS65132_MAX_REGULATORS];
+};
+
+static int tps65132_enable(struct regulator_dev *rdev)
+{
+   struct tps65132_regulator *tps = rdev_get_drvdata(rdev);
+   int id = rdev_get_id(rdev);
+   unsigned int dis_mask;
+   int ret;
+
+   dis_mask = (id == TPS65132_REGULATOR_ID_VPOS) ?
+   TPS65132_REG_APPS_DISP : TPS65132_REG_APPS_DISN;
+
+   if (tps->reg_pdata[id].disable_active_discharge) {
+   ret = regmap_update_bits(tps->rmap, TPS65132_REG_APPS_DISP

[PATCH 1/2] regulator: tps65132: add regulator driver for TI TPS65132

2017-03-06 Thread Venkat Reddy Talla
Adding regulator driver for the device TI TPS65132 which is
single inductor - dual output power supply device. TPS65132
device is designed to support general positive/negative
driven applications like TFT display panels.

TPS65132 regulator driver supports to enable/disable and
set voltage on its output.

Signed-off-by: Venkat Reddy Talla 
---
 drivers/regulator/Kconfig  |   8 +
 drivers/regulator/Makefile |   1 +
 drivers/regulator/tps65132-regulator.c | 327 +
 3 files changed, 336 insertions(+)
 create mode 100644 drivers/regulator/tps65132-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index be06eb2..85d295d 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -843,6 +843,14 @@ config REGULATOR_TPS80031
  converters, 11 general purpose LDOs, VBUS generator and digital
  output to control regulators.

+config REGULATOR_TPS65132
+   tristate "TI TPS65132 Dual Output Power regulators"
+   depends on I2C && GPIOLIB
+   select REGMAP_I2C
+   help
+ This driver supports TPS65132 single inductor - dual output
+ power supply specifcally designed for display panels.
+
 config REGULATOR_TWL4030
tristate "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC"
depends on TWL4030_CORE
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index ef7725e..8bc7faa 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -105,6 +105,7 @@ obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o
 obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o
 obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o
 obj-$(CONFIG_REGULATOR_TPS80031) += tps80031-regulator.o
+obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o
 obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o
 obj-$(CONFIG_REGULATOR_VEXPRESS) += vexpress-regulator.o
 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o
diff --git a/drivers/regulator/tps65132-regulator.c 
b/drivers/regulator/tps65132-regulator.c
new file mode 100644
index 000..f50f3ad
--- /dev/null
+++ b/drivers/regulator/tps65132-regulator.c
@@ -0,0 +1,327 @@
+/*
+ * TI TPS65132 Regulator driver
+ *
+ * Copyright (C) 2015 NVIDIA CORPORATION. All rights reserved.
+ *
+ * Author: Laxman Dewangan 
+ * Venkat Reddy Talla 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
+ * whether express or implied; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define tps65132_rails(_name)  "tps65132-"#_name
+
+#define TPS65132_REG_VPOS  0x00
+#define TPS65132_REG_VNEG  0x01
+#define TPS65132_REG_APPS_DISP_DISN0x03
+#define TPS65132_REG_CONTROL   0x0FF
+
+#define TPS65132_VOUT_MASK 0x1F
+#define TPS65132_VOUT_N_VOLTAGE0x15
+#define TPS65132_VOUT_VMIN 400
+#define TPS65132_VOUT_VMAX 600
+#define TPS65132_VOUT_STEP 10
+
+#define TPS65132_REG_APPS_DISN BIT(0)
+#define TPS65132_REG_APPS_DISP BIT(1)
+
+#define TPS65132_REGULATOR_ID_VPOS 0
+#define TPS65132_REGULATOR_ID_VNEG 1
+#define TPS65132_MAX_REGULATORS2
+
+#define TPS65132_ACT_DIS_TIME_SLACK1000
+
+struct tps65132_reg_pdata {
+   struct regulator_init_data *ridata;
+   unsigned int active_discharge_time;
+   int enable_gpio;
+   int active_discharge_gpio;
+   bool disable_active_discharge;
+};
+
+struct tps65132_regulator {
+   struct device *dev;
+   struct regmap *rmap;
+   struct regulator_desc *rdesc[TPS65132_MAX_REGULATORS];
+   struct tps65132_reg_pdata reg_pdata[TPS65132_MAX_REGULATORS];
+   struct regulator_dev *rdev[TPS65132_MAX_REGULATORS];
+};
+
+static int tps65132_enable(struct regulator_dev *rdev)
+{
+   struct tps65132_regulator *tps = rdev_get_drvdata(rdev);
+   int id = rdev_get_id(rdev);
+   unsigned int dis_mask;
+   int ret;
+
+   dis_mask = (id == TPS65132_REGULATOR_ID_VPOS) ?
+   TPS65132_REG_APPS_DISP : TPS65132_REG_APPS_DISN;
+
+   if (tps->reg_pdata[id].disable_active_discharge) {
+   ret = regmap_update_bits(tps->rmap, TPS65132_REG_APPS_DISP_DISN,
+   dis_mask, 0);
+   i

[PATCH] rtc: max77683: avoid regmap bulk write for max77620

2016-12-12 Thread Venkat Reddy Talla
Adding support to avoid regmap bulk write for the
devices which are not supported register bulk write.
Max77620 RTC device does not support register bulk write
so disabling regmap bulk write for max77620 rtc device
and enabling only for max77683.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
---
 drivers/rtc/rtc-max77686.c | 39 ++-
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 182fdd0..401ab25 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -84,6 +84,7 @@ struct max77686_rtc_driver_data {
int alarm_pending_status_reg;
/* RTC IRQ CHIP for regmap */
const struct regmap_irq_chip *rtc_irq_chip;
+   bool avoid_rtc_bulk_write;
 };
 
 struct max77686_rtc_info {
@@ -197,6 +198,7 @@ static const struct max77686_rtc_driver_data 
max77686_drv_data = {
.alarm_pending_status_reg = MAX77686_REG_STATUS2,
.rtc_i2c_addr = MAX77686_I2C_ADDR_RTC,
.rtc_irq_chip = _rtc_irq_chip,
+   .avoid_rtc_bulk_write = false,
 };
 
 static const struct max77686_rtc_driver_data max77620_drv_data = {
@@ -208,6 +210,7 @@ static const struct max77686_rtc_driver_data 
max77620_drv_data = {
.alarm_pending_status_reg = MAX77686_INVALID_REG,
.rtc_i2c_addr = MAX77620_I2C_ADDR_RTC,
.rtc_irq_chip = _rtc_irq_chip,
+   .avoid_rtc_bulk_write = true,
 };
 
 static const unsigned int max77802_map[REG_RTC_END] = {
@@ -259,6 +262,32 @@ static const struct max77686_rtc_driver_data 
max77802_drv_data = {
.rtc_irq_chip = _rtc_irq_chip,
 };
 
+static inline int _regmap_bulk_write(struct max77686_rtc_info *info,
+   unsigned int reg, void *val, int len)
+{
+   int ret = 0;
+
+   if (!info->drv_data->avoid_rtc_bulk_write) {
+   /* RTC registers support sequential writing */
+   ret = regmap_bulk_write(info->rtc_regmap, reg, val, len);
+   } else {
+   /* Power registers support register-data pair writing */
+   u8 *src = (u8 *)val;
+   int i;
+
+   for (i = 0; i < len; i++) {
+   ret = regmap_write(info->rtc_regmap, reg, *src++);
+   if (ret < 0)
+   break;
+   reg++;
+   }
+   }
+   if (ret < 0)
+   dev_err(info->dev, "%s() failed, e %d\n", __func__, ret);
+
+   return ret;
+}
+
 static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
struct max77686_rtc_info *info)
 {
@@ -383,7 +412,7 @@ static int max77686_rtc_set_time(struct device *dev, struct 
rtc_time *tm)
 
mutex_lock(>lock);
 
-   ret = regmap_bulk_write(info->rtc_regmap,
+   ret = _regmap_bulk_write(info,
info->drv_data->map[REG_RTC_SEC],
data, ARRAY_SIZE(data));
if (ret < 0) {
@@ -506,7 +535,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info 
*info)
for (i = 0; i < ARRAY_SIZE(data); i++)
data[i] &= ~ALARM_ENABLE_MASK;
 
-   ret = regmap_bulk_write(info->rtc_regmap, map[REG_ALARM1_SEC],
+   ret = _regmap_bulk_write(info, map[REG_ALARM1_SEC],
data, ARRAY_SIZE(data));
}
 
@@ -558,7 +587,7 @@ static int max77686_rtc_start_alarm(struct 
max77686_rtc_info *info)
if (data[RTC_DATE] & 0x1f)
data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
 
-   ret = regmap_bulk_write(info->rtc_regmap, map[REG_ALARM1_SEC],
+   ret = _regmap_bulk_write(info, map[REG_ALARM1_SEC],
data, ARRAY_SIZE(data));
}
 
@@ -588,7 +617,7 @@ static int max77686_rtc_set_alarm(struct device *dev, 
struct rtc_wkalrm *alrm)
if (ret < 0)
goto out;
 
-   ret = regmap_bulk_write(info->rtc_regmap,
+   ret = _regmap_bulk_write(info,
info->drv_data->map[REG_ALARM1_SEC],
data, ARRAY_SIZE(data));
 
@@ -654,7 +683,7 @@ static int max77686_rtc_init_reg(struct max77686_rtc_info 
*info)
 
info->rtc_24hr_mode = 1;
 
-   ret = regmap_bulk_write(info->rtc_regmap,
+   ret = _regmap_bulk_write(info,
info->drv_data->map[REG_RTC_CONTROLM],
data, ARRAY_SIZE(data));
if (ret < 0) {
-- 
2.1.4



[PATCH] rtc: max77683: avoid regmap bulk write for max77620

2016-12-12 Thread Venkat Reddy Talla
Adding support to avoid regmap bulk write for the
devices which are not supported register bulk write.
Max77620 RTC device does not support register bulk write
so disabling regmap bulk write for max77620 rtc device
and enabling only for max77683.

Signed-off-by: Venkat Reddy Talla 
---
 drivers/rtc/rtc-max77686.c | 39 ++-
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 182fdd0..401ab25 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -84,6 +84,7 @@ struct max77686_rtc_driver_data {
int alarm_pending_status_reg;
/* RTC IRQ CHIP for regmap */
const struct regmap_irq_chip *rtc_irq_chip;
+   bool avoid_rtc_bulk_write;
 };
 
 struct max77686_rtc_info {
@@ -197,6 +198,7 @@ static const struct max77686_rtc_driver_data 
max77686_drv_data = {
.alarm_pending_status_reg = MAX77686_REG_STATUS2,
.rtc_i2c_addr = MAX77686_I2C_ADDR_RTC,
.rtc_irq_chip = _rtc_irq_chip,
+   .avoid_rtc_bulk_write = false,
 };
 
 static const struct max77686_rtc_driver_data max77620_drv_data = {
@@ -208,6 +210,7 @@ static const struct max77686_rtc_driver_data 
max77620_drv_data = {
.alarm_pending_status_reg = MAX77686_INVALID_REG,
.rtc_i2c_addr = MAX77620_I2C_ADDR_RTC,
.rtc_irq_chip = _rtc_irq_chip,
+   .avoid_rtc_bulk_write = true,
 };
 
 static const unsigned int max77802_map[REG_RTC_END] = {
@@ -259,6 +262,32 @@ static const struct max77686_rtc_driver_data 
max77802_drv_data = {
.rtc_irq_chip = _rtc_irq_chip,
 };
 
+static inline int _regmap_bulk_write(struct max77686_rtc_info *info,
+   unsigned int reg, void *val, int len)
+{
+   int ret = 0;
+
+   if (!info->drv_data->avoid_rtc_bulk_write) {
+   /* RTC registers support sequential writing */
+   ret = regmap_bulk_write(info->rtc_regmap, reg, val, len);
+   } else {
+   /* Power registers support register-data pair writing */
+   u8 *src = (u8 *)val;
+   int i;
+
+   for (i = 0; i < len; i++) {
+   ret = regmap_write(info->rtc_regmap, reg, *src++);
+   if (ret < 0)
+   break;
+   reg++;
+   }
+   }
+   if (ret < 0)
+   dev_err(info->dev, "%s() failed, e %d\n", __func__, ret);
+
+   return ret;
+}
+
 static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
struct max77686_rtc_info *info)
 {
@@ -383,7 +412,7 @@ static int max77686_rtc_set_time(struct device *dev, struct 
rtc_time *tm)
 
mutex_lock(>lock);
 
-   ret = regmap_bulk_write(info->rtc_regmap,
+   ret = _regmap_bulk_write(info,
info->drv_data->map[REG_RTC_SEC],
data, ARRAY_SIZE(data));
if (ret < 0) {
@@ -506,7 +535,7 @@ static int max77686_rtc_stop_alarm(struct max77686_rtc_info 
*info)
for (i = 0; i < ARRAY_SIZE(data); i++)
data[i] &= ~ALARM_ENABLE_MASK;
 
-   ret = regmap_bulk_write(info->rtc_regmap, map[REG_ALARM1_SEC],
+   ret = _regmap_bulk_write(info, map[REG_ALARM1_SEC],
data, ARRAY_SIZE(data));
}
 
@@ -558,7 +587,7 @@ static int max77686_rtc_start_alarm(struct 
max77686_rtc_info *info)
if (data[RTC_DATE] & 0x1f)
data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
 
-   ret = regmap_bulk_write(info->rtc_regmap, map[REG_ALARM1_SEC],
+   ret = _regmap_bulk_write(info, map[REG_ALARM1_SEC],
data, ARRAY_SIZE(data));
}
 
@@ -588,7 +617,7 @@ static int max77686_rtc_set_alarm(struct device *dev, 
struct rtc_wkalrm *alrm)
if (ret < 0)
goto out;
 
-   ret = regmap_bulk_write(info->rtc_regmap,
+   ret = _regmap_bulk_write(info,
info->drv_data->map[REG_ALARM1_SEC],
data, ARRAY_SIZE(data));
 
@@ -654,7 +683,7 @@ static int max77686_rtc_init_reg(struct max77686_rtc_info 
*info)
 
info->rtc_24hr_mode = 1;
 
-   ret = regmap_bulk_write(info->rtc_regmap,
+   ret = _regmap_bulk_write(info,
info->drv_data->map[REG_RTC_CONTROLM],
data, ARRAY_SIZE(data));
if (ret < 0) {
-- 
2.1.4



[PATCH v2 2/2] dt-bindings: max77620: add documentation for MPOK property

2016-11-17 Thread Venkat Reddy Talla
Adding documentation for maxim,power-ok-control dts property

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>

---
Changes from V1:
 None
---
 Documentation/devicetree/bindings/mfd/max77620.txt | 12 
 1 file changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/max77620.txt 
b/Documentation/devicetree/bindings/mfd/max77620.txt
index 2ad44f7..9c16d51 100644
--- a/Documentation/devicetree/bindings/mfd/max77620.txt
+++ b/Documentation/devicetree/bindings/mfd/max77620.txt
@@ -106,6 +106,18 @@ Here supported time periods by device in microseconds are 
as follows:
 MAX77620 supports 40, 80, 160, 320, 640, 1280, 2560 and 5120 microseconds.
 MAX20024 supports 20, 40, 80, 160, 320, 640, 1280 and 2540 microseconds.
 
+-maxim,power-ok-control: configure map power ok bit
+   1: Enables POK(Power OK) to control nRST_IO and GPIO1
+   POK function.
+   0: Disables POK control.
+   if property missing, do not configure MPOK bit.
+   If POK mapping is enabled for GPIO1/nRST_IO then,
+   GPIO1/nRST_IO pins are HIGH only if all rails
+   that have POK control enabled are HIGH.
+   If any of the rails goes down(which are enabled for POK
+   control) then, GPIO1/nRST_IO goes LOW.
+   this property is valid for max20024 only.
+
 For DT binding details of different sub modules like GPIO, pincontrol,
 regulator, power, please refer respective device-tree binding document
 under their respective sub-system directories.
-- 
2.1.4



[PATCH v2 2/2] dt-bindings: max77620: add documentation for MPOK property

2016-11-17 Thread Venkat Reddy Talla
Adding documentation for maxim,power-ok-control dts property

Signed-off-by: Venkat Reddy Talla 

---
Changes from V1:
 None
---
 Documentation/devicetree/bindings/mfd/max77620.txt | 12 
 1 file changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/max77620.txt 
b/Documentation/devicetree/bindings/mfd/max77620.txt
index 2ad44f7..9c16d51 100644
--- a/Documentation/devicetree/bindings/mfd/max77620.txt
+++ b/Documentation/devicetree/bindings/mfd/max77620.txt
@@ -106,6 +106,18 @@ Here supported time periods by device in microseconds are 
as follows:
 MAX77620 supports 40, 80, 160, 320, 640, 1280, 2560 and 5120 microseconds.
 MAX20024 supports 20, 40, 80, 160, 320, 640, 1280 and 2540 microseconds.
 
+-maxim,power-ok-control: configure map power ok bit
+   1: Enables POK(Power OK) to control nRST_IO and GPIO1
+   POK function.
+   0: Disables POK control.
+   if property missing, do not configure MPOK bit.
+   If POK mapping is enabled for GPIO1/nRST_IO then,
+   GPIO1/nRST_IO pins are HIGH only if all rails
+   that have POK control enabled are HIGH.
+   If any of the rails goes down(which are enabled for POK
+   control) then, GPIO1/nRST_IO goes LOW.
+   this property is valid for max20024 only.
+
 For DT binding details of different sub modules like GPIO, pincontrol,
 regulator, power, please refer respective device-tree binding document
 under their respective sub-system directories.
-- 
2.1.4



[PATCH v2 1/2] regulator: max77620: add support to configure MPOK

2016-11-17 Thread Venkat Reddy Talla
Adding support to configure regulator POK mapping bit
to control nRST_IO and GPIO1 POK function.
In  tegra based platform which uses MAX20024 pmic, when
some of regulators are configured FPS_NONE(flexible power sequencer)
causes PMIC GPIO1 to go low which lead to various other rails turning off,
to avoid this MPOK bit of those regulators need to be set to 0
so that PMIC GPIO1 will not go low.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>

---
changes in v2:
- updated commit message for the patch
- address review comments
---
 drivers/regulator/max77620-regulator.c | 46 ++
 include/linux/mfd/max77620.h   |  2 ++
 2 files changed, 48 insertions(+)

diff --git a/drivers/regulator/max77620-regulator.c 
b/drivers/regulator/max77620-regulator.c
index a1b49a6..850b14c 100644
--- a/drivers/regulator/max77620-regulator.c
+++ b/drivers/regulator/max77620-regulator.c
@@ -81,6 +81,7 @@ struct max77620_regulator_pdata {
int suspend_fps_pd_slot;
int suspend_fps_pu_slot;
int current_mode;
+   int power_ok;
int ramp_rate_setting;
 };
 
@@ -351,11 +352,48 @@ static int max77620_set_slew_rate(struct 
max77620_regulator *pmic, int id,
return 0;
 }
 
+static int max77620_config_power_ok(struct max77620_regulator *pmic, int id)
+{
+   struct max77620_regulator_pdata *rpdata = >reg_pdata[id];
+   struct max77620_regulator_info *rinfo = pmic->rinfo[id];
+   struct max77620_chip *chip = dev_get_drvdata(pmic->dev->parent);
+   u8 val, mask;
+   int ret;
+
+   switch (chip->chip_id) {
+   case MAX20024:
+   if (rpdata->power_ok >= 0) {
+   if (rinfo->type == MAX77620_REGULATOR_TYPE_SD)
+   mask = MAX20024_SD_CFG1_MPOK_MASK;
+   else
+   mask = MAX20024_LDO_CFG2_MPOK_MASK;
+
+   val = rpdata->power_ok ? mask : 0;
+
+   ret = regmap_update_bits(pmic->rmap, rinfo->cfg_addr,
+mask, val);
+   if (ret < 0) {
+   dev_err(pmic->dev, "Reg 0x%02x update failed 
%d\n",
+   rinfo->cfg_addr, ret);
+   return ret;
+   }
+   }
+   break;
+
+   default:
+   break;
+   }
+
+   return 0;
+}
+
 static int max77620_init_pmic(struct max77620_regulator *pmic, int id)
 {
struct max77620_regulator_pdata *rpdata = >reg_pdata[id];
int ret;
 
+   max77620_config_power_ok(pmic, id);
+
/* Update power mode */
ret = max77620_regulator_get_power_mode(pmic, id);
if (ret < 0)
@@ -595,6 +633,12 @@ static int max77620_of_parse_cb(struct device_node *np,
np, "maxim,suspend-fps-power-down-slot", );
rpdata->suspend_fps_pd_slot = (!ret) ? pval : -1;
 
+   ret = of_property_read_u32(np, "maxim,power-ok-control", );
+   if (!ret)
+   rpdata->power_ok = pval;
+   else
+   rpdata->power_ok = -1;
+
ret = of_property_read_u32(np, "maxim,ramp-rate-setting", );
rpdata->ramp_rate_setting = (!ret) ? pval : 0;
 
@@ -807,6 +851,8 @@ static int max77620_regulator_resume(struct device *dev)
for (id = 0; id < MAX77620_NUM_REGS; id++) {
reg_pdata = >reg_pdata[id];
 
+   max77620_config_power_ok(pmic, id);
+
max77620_regulator_set_fps_slots(pmic, id, false);
if (reg_pdata->active_fps_src < 0)
continue;
diff --git a/include/linux/mfd/max77620.h b/include/linux/mfd/max77620.h
index 3ca0af07..ad2a9a8 100644
--- a/include/linux/mfd/max77620.h
+++ b/include/linux/mfd/max77620.h
@@ -180,6 +180,7 @@
 #define MAX77620_SD_CFG1_FPWM_SD_MASK  BIT(2)
 #define MAX77620_SD_CFG1_FPWM_SD_SKIP  0
 #define MAX77620_SD_CFG1_FPWM_SD_FPWM  BIT(2)
+#define MAX20024_SD_CFG1_MPOK_MASK BIT(1)
 #define MAX77620_SD_CFG1_FSRADE_SD_MASKBIT(0)
 #define MAX77620_SD_CFG1_FSRADE_SD_DISABLE 0
 #define MAX77620_SD_CFG1_FSRADE_SD_ENABLE  BIT(0)
@@ -187,6 +188,7 @@
 /* LDO_CNFG2 */
 #define MAX77620_LDO_POWER_MODE_MASK   0xC0
 #define MAX77620_LDO_POWER_MODE_SHIFT  6
+#define MAX20024_LDO_CFG2_MPOK_MASKBIT(2)
 #define MAX77620_LDO_CFG2_ADE_MASK BIT(1)
 #define MAX77620_LDO_CFG2_ADE_DISABLE  0
 #define MAX77620_LDO_CFG2_ADE_ENABLE   BIT(1)
-- 
2.1.4



[PATCH v2 1/2] regulator: max77620: add support to configure MPOK

2016-11-17 Thread Venkat Reddy Talla
Adding support to configure regulator POK mapping bit
to control nRST_IO and GPIO1 POK function.
In  tegra based platform which uses MAX20024 pmic, when
some of regulators are configured FPS_NONE(flexible power sequencer)
causes PMIC GPIO1 to go low which lead to various other rails turning off,
to avoid this MPOK bit of those regulators need to be set to 0
so that PMIC GPIO1 will not go low.

Signed-off-by: Venkat Reddy Talla 

---
changes in v2:
- updated commit message for the patch
- address review comments
---
 drivers/regulator/max77620-regulator.c | 46 ++
 include/linux/mfd/max77620.h   |  2 ++
 2 files changed, 48 insertions(+)

diff --git a/drivers/regulator/max77620-regulator.c 
b/drivers/regulator/max77620-regulator.c
index a1b49a6..850b14c 100644
--- a/drivers/regulator/max77620-regulator.c
+++ b/drivers/regulator/max77620-regulator.c
@@ -81,6 +81,7 @@ struct max77620_regulator_pdata {
int suspend_fps_pd_slot;
int suspend_fps_pu_slot;
int current_mode;
+   int power_ok;
int ramp_rate_setting;
 };
 
@@ -351,11 +352,48 @@ static int max77620_set_slew_rate(struct 
max77620_regulator *pmic, int id,
return 0;
 }
 
+static int max77620_config_power_ok(struct max77620_regulator *pmic, int id)
+{
+   struct max77620_regulator_pdata *rpdata = >reg_pdata[id];
+   struct max77620_regulator_info *rinfo = pmic->rinfo[id];
+   struct max77620_chip *chip = dev_get_drvdata(pmic->dev->parent);
+   u8 val, mask;
+   int ret;
+
+   switch (chip->chip_id) {
+   case MAX20024:
+   if (rpdata->power_ok >= 0) {
+   if (rinfo->type == MAX77620_REGULATOR_TYPE_SD)
+   mask = MAX20024_SD_CFG1_MPOK_MASK;
+   else
+   mask = MAX20024_LDO_CFG2_MPOK_MASK;
+
+   val = rpdata->power_ok ? mask : 0;
+
+   ret = regmap_update_bits(pmic->rmap, rinfo->cfg_addr,
+mask, val);
+   if (ret < 0) {
+   dev_err(pmic->dev, "Reg 0x%02x update failed 
%d\n",
+   rinfo->cfg_addr, ret);
+   return ret;
+   }
+   }
+   break;
+
+   default:
+   break;
+   }
+
+   return 0;
+}
+
 static int max77620_init_pmic(struct max77620_regulator *pmic, int id)
 {
struct max77620_regulator_pdata *rpdata = >reg_pdata[id];
int ret;
 
+   max77620_config_power_ok(pmic, id);
+
/* Update power mode */
ret = max77620_regulator_get_power_mode(pmic, id);
if (ret < 0)
@@ -595,6 +633,12 @@ static int max77620_of_parse_cb(struct device_node *np,
np, "maxim,suspend-fps-power-down-slot", );
rpdata->suspend_fps_pd_slot = (!ret) ? pval : -1;
 
+   ret = of_property_read_u32(np, "maxim,power-ok-control", );
+   if (!ret)
+   rpdata->power_ok = pval;
+   else
+   rpdata->power_ok = -1;
+
ret = of_property_read_u32(np, "maxim,ramp-rate-setting", );
rpdata->ramp_rate_setting = (!ret) ? pval : 0;
 
@@ -807,6 +851,8 @@ static int max77620_regulator_resume(struct device *dev)
for (id = 0; id < MAX77620_NUM_REGS; id++) {
reg_pdata = >reg_pdata[id];
 
+   max77620_config_power_ok(pmic, id);
+
max77620_regulator_set_fps_slots(pmic, id, false);
if (reg_pdata->active_fps_src < 0)
continue;
diff --git a/include/linux/mfd/max77620.h b/include/linux/mfd/max77620.h
index 3ca0af07..ad2a9a8 100644
--- a/include/linux/mfd/max77620.h
+++ b/include/linux/mfd/max77620.h
@@ -180,6 +180,7 @@
 #define MAX77620_SD_CFG1_FPWM_SD_MASK  BIT(2)
 #define MAX77620_SD_CFG1_FPWM_SD_SKIP  0
 #define MAX77620_SD_CFG1_FPWM_SD_FPWM  BIT(2)
+#define MAX20024_SD_CFG1_MPOK_MASK BIT(1)
 #define MAX77620_SD_CFG1_FSRADE_SD_MASKBIT(0)
 #define MAX77620_SD_CFG1_FSRADE_SD_DISABLE 0
 #define MAX77620_SD_CFG1_FSRADE_SD_ENABLE  BIT(0)
@@ -187,6 +188,7 @@
 /* LDO_CNFG2 */
 #define MAX77620_LDO_POWER_MODE_MASK   0xC0
 #define MAX77620_LDO_POWER_MODE_SHIFT  6
+#define MAX20024_LDO_CFG2_MPOK_MASKBIT(2)
 #define MAX77620_LDO_CFG2_ADE_MASK BIT(1)
 #define MAX77620_LDO_CFG2_ADE_DISABLE  0
 #define MAX77620_LDO_CFG2_ADE_ENABLE   BIT(1)
-- 
2.1.4



[PATCH 2/2] dt-bindings: max77620: add documentation for MPOK property

2016-11-16 Thread Venkat Reddy Talla
Adding documentation for maxim,power-ok-control dts property

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
---
 Documentation/devicetree/bindings/mfd/max77620.txt | 12 
 1 file changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/max77620.txt 
b/Documentation/devicetree/bindings/mfd/max77620.txt
index 2ad44f7..9c16d51 100644
--- a/Documentation/devicetree/bindings/mfd/max77620.txt
+++ b/Documentation/devicetree/bindings/mfd/max77620.txt
@@ -106,6 +106,18 @@ Here supported time periods by device in microseconds are 
as follows:
 MAX77620 supports 40, 80, 160, 320, 640, 1280, 2560 and 5120 microseconds.
 MAX20024 supports 20, 40, 80, 160, 320, 640, 1280 and 2540 microseconds.
 
+-maxim,power-ok-control: configure map power ok bit
+   1: Enables POK(Power OK) to control nRST_IO and GPIO1
+   POK function.
+   0: Disables POK control.
+   if property missing, do not configure MPOK bit.
+   If POK mapping is enabled for GPIO1/nRST_IO then,
+   GPIO1/nRST_IO pins are HIGH only if all rails
+   that have POK control enabled are HIGH.
+   If any of the rails goes down(which are enabled for POK
+   control) then, GPIO1/nRST_IO goes LOW.
+   this property is valid for max20024 only.
+
 For DT binding details of different sub modules like GPIO, pincontrol,
 regulator, power, please refer respective device-tree binding document
 under their respective sub-system directories.
-- 
2.1.4



[PATCH 2/2] dt-bindings: max77620: add documentation for MPOK property

2016-11-16 Thread Venkat Reddy Talla
Adding documentation for maxim,power-ok-control dts property

Signed-off-by: Venkat Reddy Talla 
---
 Documentation/devicetree/bindings/mfd/max77620.txt | 12 
 1 file changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/max77620.txt 
b/Documentation/devicetree/bindings/mfd/max77620.txt
index 2ad44f7..9c16d51 100644
--- a/Documentation/devicetree/bindings/mfd/max77620.txt
+++ b/Documentation/devicetree/bindings/mfd/max77620.txt
@@ -106,6 +106,18 @@ Here supported time periods by device in microseconds are 
as follows:
 MAX77620 supports 40, 80, 160, 320, 640, 1280, 2560 and 5120 microseconds.
 MAX20024 supports 20, 40, 80, 160, 320, 640, 1280 and 2540 microseconds.
 
+-maxim,power-ok-control: configure map power ok bit
+   1: Enables POK(Power OK) to control nRST_IO and GPIO1
+   POK function.
+   0: Disables POK control.
+   if property missing, do not configure MPOK bit.
+   If POK mapping is enabled for GPIO1/nRST_IO then,
+   GPIO1/nRST_IO pins are HIGH only if all rails
+   that have POK control enabled are HIGH.
+   If any of the rails goes down(which are enabled for POK
+   control) then, GPIO1/nRST_IO goes LOW.
+   this property is valid for max20024 only.
+
 For DT binding details of different sub modules like GPIO, pincontrol,
 regulator, power, please refer respective device-tree binding document
 under their respective sub-system directories.
-- 
2.1.4



[PATCH 1/2] regulator: max77620: add support to configure MPOK

2016-11-16 Thread Venkat Reddy Talla
Adding support to configure regulator POK mapping bit
to control nRST_IO and GPIO1 POK function.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
---
 drivers/regulator/max77620-regulator.c | 39 ++
 include/linux/mfd/max77620.h   |  2 ++
 2 files changed, 41 insertions(+)

diff --git a/drivers/regulator/max77620-regulator.c 
b/drivers/regulator/max77620-regulator.c
index a1b49a6..973bed1 100644
--- a/drivers/regulator/max77620-regulator.c
+++ b/drivers/regulator/max77620-regulator.c
@@ -81,6 +81,7 @@ struct max77620_regulator_pdata {
int suspend_fps_pd_slot;
int suspend_fps_pu_slot;
int current_mode;
+   int power_ok;
int ramp_rate_setting;
 };
 
@@ -351,11 +352,44 @@ static int max77620_set_slew_rate(struct 
max77620_regulator *pmic, int id,
return 0;
 }
 
+static int max77620_config_power_ok(struct max77620_regulator *pmic, int id)
+{
+   struct max77620_regulator_pdata *rpdata = >reg_pdata[id];
+   struct max77620_regulator_info *rinfo = pmic->rinfo[id];
+   struct max77620_chip *chip = dev_get_drvdata(pmic->dev->parent);
+   u8 val, mask;
+   int ret;
+
+   if (chip->chip_id == MAX20024) {
+   if (rpdata->power_ok >= 0) {
+   if (rinfo->type == MAX77620_REGULATOR_TYPE_SD)
+   mask = MAX20024_SD_CFG1_MPOK_MASK;
+   else
+   mask = MAX20024_LDO_CFG2_MPOK_MASK;
+
+   val = rpdata->power_ok ? mask : 0;
+
+   ret = regmap_update_bits(pmic->rmap, rinfo->cfg_addr,
+mask, val);
+   if (ret < 0) {
+   dev_err(pmic->dev,
+   "Reg 0x%02x update failed %d\n",
+   rinfo->cfg_addr, ret);
+   return ret;
+   }
+   }
+   }
+
+   return 0;
+}
+
 static int max77620_init_pmic(struct max77620_regulator *pmic, int id)
 {
struct max77620_regulator_pdata *rpdata = >reg_pdata[id];
int ret;
 
+   max77620_config_power_ok(pmic, id);
+
/* Update power mode */
ret = max77620_regulator_get_power_mode(pmic, id);
if (ret < 0)
@@ -595,6 +629,9 @@ static int max77620_of_parse_cb(struct device_node *np,
np, "maxim,suspend-fps-power-down-slot", );
rpdata->suspend_fps_pd_slot = (!ret) ? pval : -1;
 
+   ret = of_property_read_u32(np, "maxim,power-ok-control", );
+   rpdata->power_ok = (!ret) ? pval : -1;
+
ret = of_property_read_u32(np, "maxim,ramp-rate-setting", );
rpdata->ramp_rate_setting = (!ret) ? pval : 0;
 
@@ -807,6 +844,8 @@ static int max77620_regulator_resume(struct device *dev)
for (id = 0; id < MAX77620_NUM_REGS; id++) {
reg_pdata = >reg_pdata[id];
 
+   max77620_config_power_ok(pmic, id);
+
max77620_regulator_set_fps_slots(pmic, id, false);
if (reg_pdata->active_fps_src < 0)
continue;
diff --git a/include/linux/mfd/max77620.h b/include/linux/mfd/max77620.h
index 3ca0af07..ad2a9a8 100644
--- a/include/linux/mfd/max77620.h
+++ b/include/linux/mfd/max77620.h
@@ -180,6 +180,7 @@
 #define MAX77620_SD_CFG1_FPWM_SD_MASK  BIT(2)
 #define MAX77620_SD_CFG1_FPWM_SD_SKIP  0
 #define MAX77620_SD_CFG1_FPWM_SD_FPWM  BIT(2)
+#define MAX20024_SD_CFG1_MPOK_MASK BIT(1)
 #define MAX77620_SD_CFG1_FSRADE_SD_MASKBIT(0)
 #define MAX77620_SD_CFG1_FSRADE_SD_DISABLE 0
 #define MAX77620_SD_CFG1_FSRADE_SD_ENABLE  BIT(0)
@@ -187,6 +188,7 @@
 /* LDO_CNFG2 */
 #define MAX77620_LDO_POWER_MODE_MASK   0xC0
 #define MAX77620_LDO_POWER_MODE_SHIFT  6
+#define MAX20024_LDO_CFG2_MPOK_MASKBIT(2)
 #define MAX77620_LDO_CFG2_ADE_MASK BIT(1)
 #define MAX77620_LDO_CFG2_ADE_DISABLE  0
 #define MAX77620_LDO_CFG2_ADE_ENABLE   BIT(1)
-- 
2.1.4



[PATCH 1/2] regulator: max77620: add support to configure MPOK

2016-11-16 Thread Venkat Reddy Talla
Adding support to configure regulator POK mapping bit
to control nRST_IO and GPIO1 POK function.

Signed-off-by: Venkat Reddy Talla 
---
 drivers/regulator/max77620-regulator.c | 39 ++
 include/linux/mfd/max77620.h   |  2 ++
 2 files changed, 41 insertions(+)

diff --git a/drivers/regulator/max77620-regulator.c 
b/drivers/regulator/max77620-regulator.c
index a1b49a6..973bed1 100644
--- a/drivers/regulator/max77620-regulator.c
+++ b/drivers/regulator/max77620-regulator.c
@@ -81,6 +81,7 @@ struct max77620_regulator_pdata {
int suspend_fps_pd_slot;
int suspend_fps_pu_slot;
int current_mode;
+   int power_ok;
int ramp_rate_setting;
 };
 
@@ -351,11 +352,44 @@ static int max77620_set_slew_rate(struct 
max77620_regulator *pmic, int id,
return 0;
 }
 
+static int max77620_config_power_ok(struct max77620_regulator *pmic, int id)
+{
+   struct max77620_regulator_pdata *rpdata = >reg_pdata[id];
+   struct max77620_regulator_info *rinfo = pmic->rinfo[id];
+   struct max77620_chip *chip = dev_get_drvdata(pmic->dev->parent);
+   u8 val, mask;
+   int ret;
+
+   if (chip->chip_id == MAX20024) {
+   if (rpdata->power_ok >= 0) {
+   if (rinfo->type == MAX77620_REGULATOR_TYPE_SD)
+   mask = MAX20024_SD_CFG1_MPOK_MASK;
+   else
+   mask = MAX20024_LDO_CFG2_MPOK_MASK;
+
+   val = rpdata->power_ok ? mask : 0;
+
+   ret = regmap_update_bits(pmic->rmap, rinfo->cfg_addr,
+mask, val);
+   if (ret < 0) {
+   dev_err(pmic->dev,
+   "Reg 0x%02x update failed %d\n",
+   rinfo->cfg_addr, ret);
+   return ret;
+   }
+   }
+   }
+
+   return 0;
+}
+
 static int max77620_init_pmic(struct max77620_regulator *pmic, int id)
 {
struct max77620_regulator_pdata *rpdata = >reg_pdata[id];
int ret;
 
+   max77620_config_power_ok(pmic, id);
+
/* Update power mode */
ret = max77620_regulator_get_power_mode(pmic, id);
if (ret < 0)
@@ -595,6 +629,9 @@ static int max77620_of_parse_cb(struct device_node *np,
np, "maxim,suspend-fps-power-down-slot", );
rpdata->suspend_fps_pd_slot = (!ret) ? pval : -1;
 
+   ret = of_property_read_u32(np, "maxim,power-ok-control", );
+   rpdata->power_ok = (!ret) ? pval : -1;
+
ret = of_property_read_u32(np, "maxim,ramp-rate-setting", );
rpdata->ramp_rate_setting = (!ret) ? pval : 0;
 
@@ -807,6 +844,8 @@ static int max77620_regulator_resume(struct device *dev)
for (id = 0; id < MAX77620_NUM_REGS; id++) {
reg_pdata = >reg_pdata[id];
 
+   max77620_config_power_ok(pmic, id);
+
max77620_regulator_set_fps_slots(pmic, id, false);
if (reg_pdata->active_fps_src < 0)
continue;
diff --git a/include/linux/mfd/max77620.h b/include/linux/mfd/max77620.h
index 3ca0af07..ad2a9a8 100644
--- a/include/linux/mfd/max77620.h
+++ b/include/linux/mfd/max77620.h
@@ -180,6 +180,7 @@
 #define MAX77620_SD_CFG1_FPWM_SD_MASK  BIT(2)
 #define MAX77620_SD_CFG1_FPWM_SD_SKIP  0
 #define MAX77620_SD_CFG1_FPWM_SD_FPWM  BIT(2)
+#define MAX20024_SD_CFG1_MPOK_MASK BIT(1)
 #define MAX77620_SD_CFG1_FSRADE_SD_MASKBIT(0)
 #define MAX77620_SD_CFG1_FSRADE_SD_DISABLE 0
 #define MAX77620_SD_CFG1_FSRADE_SD_ENABLE  BIT(0)
@@ -187,6 +188,7 @@
 /* LDO_CNFG2 */
 #define MAX77620_LDO_POWER_MODE_MASK   0xC0
 #define MAX77620_LDO_POWER_MODE_SHIFT  6
+#define MAX20024_LDO_CFG2_MPOK_MASKBIT(2)
 #define MAX77620_LDO_CFG2_ADE_MASK BIT(1)
 #define MAX77620_LDO_CFG2_ADE_DISABLE  0
 #define MAX77620_LDO_CFG2_ADE_ENABLE   BIT(1)
-- 
2.1.4



[PATCH] extcon: adc-jack: update cable state during boot

2016-07-05 Thread Venkat Reddy Talla
Update cable state during boot to avoid any missing
external cable events occurred before driver initialisation.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
---
 drivers/extcon/extcon-adc-jack.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c
index 44e48aa..48dec94 100644
--- a/drivers/extcon/extcon-adc-jack.c
+++ b/drivers/extcon/extcon-adc-jack.c
@@ -158,6 +158,7 @@ static int adc_jack_probe(struct platform_device *pdev)
if (data->wakeup_source)
device_init_wakeup(>dev, 1);
 
+   adc_jack_handler(>handler.work);
return 0;
 }
 
-- 
2.1.4



[PATCH] extcon: adc-jack: update cable state during boot

2016-07-05 Thread Venkat Reddy Talla
Update cable state during boot to avoid any missing
external cable events occurred before driver initialisation.

Signed-off-by: Venkat Reddy Talla 
---
 drivers/extcon/extcon-adc-jack.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c
index 44e48aa..48dec94 100644
--- a/drivers/extcon/extcon-adc-jack.c
+++ b/drivers/extcon/extcon-adc-jack.c
@@ -158,6 +158,7 @@ static int adc_jack_probe(struct platform_device *pdev)
if (data->wakeup_source)
device_init_wakeup(>dev, 1);
 
+   adc_jack_handler(>handler.work);
return 0;
 }
 
-- 
2.1.4



[PATCH] extcon: adc-jack: add suspend/resume support

2016-06-30 Thread Venkat Reddy Talla
adding suspend and resume funtionality for extcon-adc-jack
driver to configure system wake up for extcon events,
also adding support to enable/disable system wakeup
through flag wakeup_source based on platform requirement.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
---
 drivers/extcon/extcon-adc-jack.c   | 34 ++
 include/linux/extcon/extcon-adc-jack.h |  2 ++
 2 files changed, 36 insertions(+)

diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c
index 7fc0ae1..44e48aa 100644
--- a/drivers/extcon/extcon-adc-jack.c
+++ b/drivers/extcon/extcon-adc-jack.c
@@ -38,6 +38,7 @@
  * @chan:  iio channel being queried.
  */
 struct adc_jack_data {
+   struct device *dev;
struct extcon_dev *edev;
 
const unsigned int **cable_names;
@@ -49,6 +50,7 @@ struct adc_jack_data {
struct delayed_work handler;
 
struct iio_channel *chan;
+   bool wakeup_source;
 };
 
 static void adc_jack_handler(struct work_struct *work)
@@ -105,6 +107,7 @@ static int adc_jack_probe(struct platform_device *pdev)
return -EINVAL;
}
 
+   data->dev = >dev;
data->edev = devm_extcon_dev_allocate(>dev, pdata->cable_names);
if (IS_ERR(data->edev)) {
dev_err(>dev, "failed to allocate extcon device\n");
@@ -128,6 +131,7 @@ static int adc_jack_probe(struct platform_device *pdev)
return PTR_ERR(data->chan);
 
data->handling_delay = msecs_to_jiffies(pdata->handling_delay_ms);
+   data->wakeup_source = pdata->wakeup_source;
 
INIT_DEFERRABLE_WORK(>handler, adc_jack_handler);
 
@@ -151,6 +155,9 @@ static int adc_jack_probe(struct platform_device *pdev)
return err;
}
 
+   if (data->wakeup_source)
+   device_init_wakeup(>dev, 1);
+
return 0;
 }
 
@@ -165,11 +172,38 @@ static int adc_jack_remove(struct platform_device *pdev)
return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int adc_jack_suspend(struct device *dev)
+{
+   struct adc_jack_data *data = dev_get_drvdata(dev);
+
+   cancel_delayed_work_sync(>handler);
+   if (device_may_wakeup(data->dev))
+   enable_irq_wake(data->irq);
+
+   return 0;
+}
+
+static int adc_jack_resume(struct device *dev)
+{
+   struct adc_jack_data *data = dev_get_drvdata(dev);
+
+   if (device_may_wakeup(data->dev))
+   disable_irq_wake(data->irq);
+
+   return 0;
+}
+#endif /* CONFIG_PM_SLEEP */
+
+static SIMPLE_DEV_PM_OPS(adc_jack_pm_ops,
+   adc_jack_suspend, adc_jack_resume);
+
 static struct platform_driver adc_jack_driver = {
.probe  = adc_jack_probe,
.remove = adc_jack_remove,
.driver = {
.name   = "adc-jack",
+   .pm = _jack_pm_ops,
},
 };
 
diff --git a/include/linux/extcon/extcon-adc-jack.h 
b/include/linux/extcon/extcon-adc-jack.h
index 53c6080..ac85f20 100644
--- a/include/linux/extcon/extcon-adc-jack.h
+++ b/include/linux/extcon/extcon-adc-jack.h
@@ -53,6 +53,7 @@ struct adc_jack_cond {
  * milli-seconds after the interrupt occurs. You may
  * describe such delays with @handling_delay_ms, which
  * is rounded-off by jiffies.
+ * @wakeup_source: flag to wake up the system for extcon events.
  */
 struct adc_jack_pdata {
const char *name;
@@ -65,6 +66,7 @@ struct adc_jack_pdata {
 
unsigned long irq_flags;
unsigned long handling_delay_ms; /* in ms */
+   bool wakeup_source;
 };
 
 #endif /* _EXTCON_ADC_JACK_H */
-- 
2.1.4



[PATCH] extcon: adc-jack: add suspend/resume support

2016-06-30 Thread Venkat Reddy Talla
adding suspend and resume funtionality for extcon-adc-jack
driver to configure system wake up for extcon events,
also adding support to enable/disable system wakeup
through flag wakeup_source based on platform requirement.

Signed-off-by: Venkat Reddy Talla 
---
 drivers/extcon/extcon-adc-jack.c   | 34 ++
 include/linux/extcon/extcon-adc-jack.h |  2 ++
 2 files changed, 36 insertions(+)

diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c
index 7fc0ae1..44e48aa 100644
--- a/drivers/extcon/extcon-adc-jack.c
+++ b/drivers/extcon/extcon-adc-jack.c
@@ -38,6 +38,7 @@
  * @chan:  iio channel being queried.
  */
 struct adc_jack_data {
+   struct device *dev;
struct extcon_dev *edev;
 
const unsigned int **cable_names;
@@ -49,6 +50,7 @@ struct adc_jack_data {
struct delayed_work handler;
 
struct iio_channel *chan;
+   bool wakeup_source;
 };
 
 static void adc_jack_handler(struct work_struct *work)
@@ -105,6 +107,7 @@ static int adc_jack_probe(struct platform_device *pdev)
return -EINVAL;
}
 
+   data->dev = >dev;
data->edev = devm_extcon_dev_allocate(>dev, pdata->cable_names);
if (IS_ERR(data->edev)) {
dev_err(>dev, "failed to allocate extcon device\n");
@@ -128,6 +131,7 @@ static int adc_jack_probe(struct platform_device *pdev)
return PTR_ERR(data->chan);
 
data->handling_delay = msecs_to_jiffies(pdata->handling_delay_ms);
+   data->wakeup_source = pdata->wakeup_source;
 
INIT_DEFERRABLE_WORK(>handler, adc_jack_handler);
 
@@ -151,6 +155,9 @@ static int adc_jack_probe(struct platform_device *pdev)
return err;
}
 
+   if (data->wakeup_source)
+   device_init_wakeup(>dev, 1);
+
return 0;
 }
 
@@ -165,11 +172,38 @@ static int adc_jack_remove(struct platform_device *pdev)
return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int adc_jack_suspend(struct device *dev)
+{
+   struct adc_jack_data *data = dev_get_drvdata(dev);
+
+   cancel_delayed_work_sync(>handler);
+   if (device_may_wakeup(data->dev))
+   enable_irq_wake(data->irq);
+
+   return 0;
+}
+
+static int adc_jack_resume(struct device *dev)
+{
+   struct adc_jack_data *data = dev_get_drvdata(dev);
+
+   if (device_may_wakeup(data->dev))
+   disable_irq_wake(data->irq);
+
+   return 0;
+}
+#endif /* CONFIG_PM_SLEEP */
+
+static SIMPLE_DEV_PM_OPS(adc_jack_pm_ops,
+   adc_jack_suspend, adc_jack_resume);
+
 static struct platform_driver adc_jack_driver = {
.probe  = adc_jack_probe,
.remove = adc_jack_remove,
.driver = {
.name   = "adc-jack",
+   .pm = _jack_pm_ops,
},
 };
 
diff --git a/include/linux/extcon/extcon-adc-jack.h 
b/include/linux/extcon/extcon-adc-jack.h
index 53c6080..ac85f20 100644
--- a/include/linux/extcon/extcon-adc-jack.h
+++ b/include/linux/extcon/extcon-adc-jack.h
@@ -53,6 +53,7 @@ struct adc_jack_cond {
  * milli-seconds after the interrupt occurs. You may
  * describe such delays with @handling_delay_ms, which
  * is rounded-off by jiffies.
+ * @wakeup_source: flag to wake up the system for extcon events.
  */
 struct adc_jack_pdata {
const char *name;
@@ -65,6 +66,7 @@ struct adc_jack_pdata {
 
unsigned long irq_flags;
unsigned long handling_delay_ms; /* in ms */
+   bool wakeup_source;
 };
 
 #endif /* _EXTCON_ADC_JACK_H */
-- 
2.1.4



[PATCH v2 1/1] regulator: max77620: check for valid regulator info

2016-06-29 Thread Venkat Reddy Talla
SD4 regulator is not registered with regulator core
framework in probe as there is no support in MAX77620 PMIC,
removing SD4 entry from MAX77620 regulator information list
and checking for valid regulator information data before
configuring FPS source and FPS power up/down period to avoid
NULL pointer exception if regulator not registered with core.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>

---
changes in v2:
- updated commit message for the patch
---
 drivers/regulator/max77620-regulator.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/max77620-regulator.c 
b/drivers/regulator/max77620-regulator.c
index 321e804..a1b49a6 100644
--- a/drivers/regulator/max77620-regulator.c
+++ b/drivers/regulator/max77620-regulator.c
@@ -123,6 +123,9 @@ static int max77620_regulator_set_fps_src(struct 
max77620_regulator *pmic,
unsigned int val;
int ret;
 
+   if (!rinfo)
+   return 0;
+
switch (fps_src) {
case MAX77620_FPS_SRC_0:
case MAX77620_FPS_SRC_1:
@@ -171,6 +174,9 @@ static int max77620_regulator_set_fps_slots(struct 
max77620_regulator *pmic,
int pd = rpdata->active_fps_pd_slot;
int ret = 0;
 
+   if (!rinfo)
+   return 0;
+
if (is_suspend) {
pu = rpdata->suspend_fps_pu_slot;
pd = rpdata->suspend_fps_pd_slot;
@@ -680,7 +686,6 @@ static struct max77620_regulator_info 
max77620_regs_info[MAX77620_NUM_REGS] = {
RAIL_SD(SD1, sd1, "in-sd1", SD1, 60, 155, 12500, 0x22, SD1),
RAIL_SD(SD2, sd2, "in-sd2", SDX, 60, 3787500, 12500, 0xFF, NONE),
RAIL_SD(SD3, sd3, "in-sd3", SDX, 60, 3787500, 12500, 0xFF, NONE),
-   RAIL_SD(SD4, sd4, "in-sd4", SDX, 60, 3787500, 12500, 0xFF, NONE),
 
RAIL_LDO(LDO0, ldo0, "in-ldo0-1", N, 80, 2375000, 25000),
RAIL_LDO(LDO1, ldo1, "in-ldo0-1", N, 80, 2375000, 25000),
-- 
2.1.4



[PATCH v2 1/1] regulator: max77620: check for valid regulator info

2016-06-29 Thread Venkat Reddy Talla
SD4 regulator is not registered with regulator core
framework in probe as there is no support in MAX77620 PMIC,
removing SD4 entry from MAX77620 regulator information list
and checking for valid regulator information data before
configuring FPS source and FPS power up/down period to avoid
NULL pointer exception if regulator not registered with core.

Signed-off-by: Venkat Reddy Talla 

---
changes in v2:
- updated commit message for the patch
---
 drivers/regulator/max77620-regulator.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/max77620-regulator.c 
b/drivers/regulator/max77620-regulator.c
index 321e804..a1b49a6 100644
--- a/drivers/regulator/max77620-regulator.c
+++ b/drivers/regulator/max77620-regulator.c
@@ -123,6 +123,9 @@ static int max77620_regulator_set_fps_src(struct 
max77620_regulator *pmic,
unsigned int val;
int ret;
 
+   if (!rinfo)
+   return 0;
+
switch (fps_src) {
case MAX77620_FPS_SRC_0:
case MAX77620_FPS_SRC_1:
@@ -171,6 +174,9 @@ static int max77620_regulator_set_fps_slots(struct 
max77620_regulator *pmic,
int pd = rpdata->active_fps_pd_slot;
int ret = 0;
 
+   if (!rinfo)
+   return 0;
+
if (is_suspend) {
pu = rpdata->suspend_fps_pu_slot;
pd = rpdata->suspend_fps_pd_slot;
@@ -680,7 +686,6 @@ static struct max77620_regulator_info 
max77620_regs_info[MAX77620_NUM_REGS] = {
RAIL_SD(SD1, sd1, "in-sd1", SD1, 60, 155, 12500, 0x22, SD1),
RAIL_SD(SD2, sd2, "in-sd2", SDX, 60, 3787500, 12500, 0xFF, NONE),
RAIL_SD(SD3, sd3, "in-sd3", SDX, 60, 3787500, 12500, 0xFF, NONE),
-   RAIL_SD(SD4, sd4, "in-sd4", SDX, 60, 3787500, 12500, 0xFF, NONE),
 
RAIL_LDO(LDO0, ldo0, "in-ldo0-1", N, 80, 2375000, 25000),
RAIL_LDO(LDO1, ldo1, "in-ldo0-1", N, 80, 2375000, 25000),
-- 
2.1.4



RE: [PATCH 1/1] regulator: max77620: check for valid regulator info

2016-06-27 Thread Venkat Reddy Talla
> * PGP Signed by an unknown key
> 
> On Mon, Jun 27, 2016 at 05:13:44PM +0530, Venkat Reddy Talla wrote:
> > Check for valid regulator information data before configuring FPS
> > source and FPS power up/down period to avoid NULL pointer exception if
> > entries for PMIC regulators not provided through device tree.
> 
> This sounds like it's papering over a bug in the driver - the driver should be
> able to instantiate without anything beyond the registration of the device.
> What's the driver relying on from the DT?
> 
Sorry for confusion, there is no dependent on DTS entry, I mean, in probe
SD4 regulator for MAX77620 PMIC is not registered with regulator core framework 
so
Regulator info will be null.

> > SD4 regulator is not supported by MAX77620 PMIC, removing
> > SD4 entry from regulator information list.
> 
> This appears to be a separate change to the above and should be a separate
> patch.
> 
Regulator info data will be null since SD4 regulator is not getting registered 
with core framework,
MAX77620 not supporting SD4 regulator, due to this reason I have included this 
change as part of this patch.
I will change the commit message and push another patch on top of this patch.

Thanks for review.

> * Unknown Key
> * 0x5D5487D0


RE: [PATCH 1/1] regulator: max77620: check for valid regulator info

2016-06-27 Thread Venkat Reddy Talla
> * PGP Signed by an unknown key
> 
> On Mon, Jun 27, 2016 at 05:13:44PM +0530, Venkat Reddy Talla wrote:
> > Check for valid regulator information data before configuring FPS
> > source and FPS power up/down period to avoid NULL pointer exception if
> > entries for PMIC regulators not provided through device tree.
> 
> This sounds like it's papering over a bug in the driver - the driver should be
> able to instantiate without anything beyond the registration of the device.
> What's the driver relying on from the DT?
> 
Sorry for confusion, there is no dependent on DTS entry, I mean, in probe
SD4 regulator for MAX77620 PMIC is not registered with regulator core framework 
so
Regulator info will be null.

> > SD4 regulator is not supported by MAX77620 PMIC, removing
> > SD4 entry from regulator information list.
> 
> This appears to be a separate change to the above and should be a separate
> patch.
> 
Regulator info data will be null since SD4 regulator is not getting registered 
with core framework,
MAX77620 not supporting SD4 regulator, due to this reason I have included this 
change as part of this patch.
I will change the commit message and push another patch on top of this patch.

Thanks for review.

> * Unknown Key
> * 0x5D5487D0


[PATCH 1/1] regulator: max77620: check for valid regulator info

2016-06-27 Thread Venkat Reddy Talla
Check for valid regulator information data before
configuring FPS source and FPS power up/down
period to avoid NULL pointer exception if entries for
PMIC regulators not provided through device tree.
SD4 regulator is not supported by MAX77620 PMIC, removing
SD4 entry from regulator information list.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
---
 drivers/regulator/max77620-regulator.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/max77620-regulator.c 
b/drivers/regulator/max77620-regulator.c
index 321e804..a1b49a6 100644
--- a/drivers/regulator/max77620-regulator.c
+++ b/drivers/regulator/max77620-regulator.c
@@ -123,6 +123,9 @@ static int max77620_regulator_set_fps_src(struct 
max77620_regulator *pmic,
unsigned int val;
int ret;
 
+   if (!rinfo)
+   return 0;
+
switch (fps_src) {
case MAX77620_FPS_SRC_0:
case MAX77620_FPS_SRC_1:
@@ -171,6 +174,9 @@ static int max77620_regulator_set_fps_slots(struct 
max77620_regulator *pmic,
int pd = rpdata->active_fps_pd_slot;
int ret = 0;
 
+   if (!rinfo)
+   return 0;
+
if (is_suspend) {
pu = rpdata->suspend_fps_pu_slot;
pd = rpdata->suspend_fps_pd_slot;
@@ -680,7 +686,6 @@ static struct max77620_regulator_info 
max77620_regs_info[MAX77620_NUM_REGS] = {
RAIL_SD(SD1, sd1, "in-sd1", SD1, 60, 155, 12500, 0x22, SD1),
RAIL_SD(SD2, sd2, "in-sd2", SDX, 60, 3787500, 12500, 0xFF, NONE),
RAIL_SD(SD3, sd3, "in-sd3", SDX, 60, 3787500, 12500, 0xFF, NONE),
-   RAIL_SD(SD4, sd4, "in-sd4", SDX, 60, 3787500, 12500, 0xFF, NONE),
 
RAIL_LDO(LDO0, ldo0, "in-ldo0-1", N, 80, 2375000, 25000),
RAIL_LDO(LDO1, ldo1, "in-ldo0-1", N, 80, 2375000, 25000),
-- 
2.1.4



[PATCH 1/1] regulator: max77620: check for valid regulator info

2016-06-27 Thread Venkat Reddy Talla
Check for valid regulator information data before
configuring FPS source and FPS power up/down
period to avoid NULL pointer exception if entries for
PMIC regulators not provided through device tree.
SD4 regulator is not supported by MAX77620 PMIC, removing
SD4 entry from regulator information list.

Signed-off-by: Venkat Reddy Talla 
---
 drivers/regulator/max77620-regulator.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/max77620-regulator.c 
b/drivers/regulator/max77620-regulator.c
index 321e804..a1b49a6 100644
--- a/drivers/regulator/max77620-regulator.c
+++ b/drivers/regulator/max77620-regulator.c
@@ -123,6 +123,9 @@ static int max77620_regulator_set_fps_src(struct 
max77620_regulator *pmic,
unsigned int val;
int ret;
 
+   if (!rinfo)
+   return 0;
+
switch (fps_src) {
case MAX77620_FPS_SRC_0:
case MAX77620_FPS_SRC_1:
@@ -171,6 +174,9 @@ static int max77620_regulator_set_fps_slots(struct 
max77620_regulator *pmic,
int pd = rpdata->active_fps_pd_slot;
int ret = 0;
 
+   if (!rinfo)
+   return 0;
+
if (is_suspend) {
pu = rpdata->suspend_fps_pu_slot;
pd = rpdata->suspend_fps_pd_slot;
@@ -680,7 +686,6 @@ static struct max77620_regulator_info 
max77620_regs_info[MAX77620_NUM_REGS] = {
RAIL_SD(SD1, sd1, "in-sd1", SD1, 60, 155, 12500, 0x22, SD1),
RAIL_SD(SD2, sd2, "in-sd2", SDX, 60, 3787500, 12500, 0xFF, NONE),
RAIL_SD(SD3, sd3, "in-sd3", SDX, 60, 3787500, 12500, 0xFF, NONE),
-   RAIL_SD(SD4, sd4, "in-sd4", SDX, 60, 3787500, 12500, 0xFF, NONE),
 
RAIL_LDO(LDO0, ldo0, "in-ldo0-1", N, 80, 2375000, 25000),
RAIL_LDO(LDO1, ldo1, "in-ldo0-1", N, 80, 2375000, 25000),
-- 
2.1.4



[PATCH 1/1] gpio: max77620: get gpio value based on direction

2016-06-27 Thread Venkat Reddy Talla
Gpio direction is determined by DIRx bit of GPIO
configuration register, return max77620 gpio value
based on direction in or out.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
---
 drivers/gpio/gpio-max77620.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-max77620.c b/drivers/gpio/gpio-max77620.c
index 8658c32..b46b436 100644
--- a/drivers/gpio/gpio-max77620.c
+++ b/drivers/gpio/gpio-max77620.c
@@ -123,7 +123,10 @@ static int max77620_gpio_get(struct gpio_chip *gc, 
unsigned int offset)
return ret;
}
 
-   return !!(val & MAX77620_CNFG_GPIO_INPUT_VAL_MASK);
+   if  (val & MAX77620_CNFG_GPIO_DIR_MASK)
+   return !!(val & MAX77620_CNFG_GPIO_INPUT_VAL_MASK);
+   else
+   return !!(val & MAX77620_CNFG_GPIO_OUTPUT_VAL_MASK);
 }
 
 static int max77620_gpio_dir_output(struct gpio_chip *gc, unsigned int offset,
-- 
2.1.4



[PATCH 1/1] gpio: max77620: get gpio value based on direction

2016-06-27 Thread Venkat Reddy Talla
Gpio direction is determined by DIRx bit of GPIO
configuration register, return max77620 gpio value
based on direction in or out.

Signed-off-by: Venkat Reddy Talla 
---
 drivers/gpio/gpio-max77620.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-max77620.c b/drivers/gpio/gpio-max77620.c
index 8658c32..b46b436 100644
--- a/drivers/gpio/gpio-max77620.c
+++ b/drivers/gpio/gpio-max77620.c
@@ -123,7 +123,10 @@ static int max77620_gpio_get(struct gpio_chip *gc, 
unsigned int offset)
return ret;
}
 
-   return !!(val & MAX77620_CNFG_GPIO_INPUT_VAL_MASK);
+   if  (val & MAX77620_CNFG_GPIO_DIR_MASK)
+   return !!(val & MAX77620_CNFG_GPIO_INPUT_VAL_MASK);
+   else
+   return !!(val & MAX77620_CNFG_GPIO_OUTPUT_VAL_MASK);
 }
 
 static int max77620_gpio_dir_output(struct gpio_chip *gc, unsigned int offset,
-- 
2.1.4



RE: [PATCH v4] extcon: gpio: Add the support for Device tree bindings

2016-05-26 Thread Venkat Reddy Talla
Hi Choi,

Sorry for changing author, will update author field with your name.

Regarding Rob Herring comments, You had already replied.

I felt separate compatible for each external connector is not required,
as client driver can detect the type of external cable(sdp,dcp, microphone) on 
receiving notification from extcon provider,
I have also added more description for wakeup-source.

Do you see any other changes required on top of v4 patch?

Regards,
Venkat

> -Original Message-
> From: Chanwoo Choi [mailto:cwcho...@gmail.com]
> Sent: Thursday, May 26, 2016 6:52 PM
> To: Venkat Reddy Talla
> Cc: MyungJoo Ham; Rob Herring; Pawel Moll; Mark Rutland; Ian Campbell;
> devicetree; Kumar Gala; linux-kernel; Laxman Dewangan
> Subject: Re: [PATCH v4] extcon: gpio: Add the support for Device tree
> bindings
> 
> Hi Venkat,
> 
> There is some miscommunication. On previous my reply, I don't mean that
> the author of the patch[1] is changed from me to you.
> 
> I'd like you to remain the original author(me) for the patch[1] without
> changing the author.
> [1] https://lkml.org/lkml/2015/10/21/8
> - [PATCH v3] extcon: gpio: Add the support for Device tree bindings
> 
> You can use the patch[1] as based patch and you can add new feature on
> base patch[1]. Also, If you ok, you can modify the extccon-gpio.c driver as
> Rob comment[2].
> 
> But, Rob Herring gave me the some comment[2].
> [2] https://lkml.org/lkml/2015/10/21/906
> 
> 
> Thanks,
> Chanwoo Choi
> 
> 
> On Thu, May 26, 2016 at 8:47 PM, Venkat Reddy Talla
> <vreddyta...@nvidia.com> wrote:
> > Add the support for Device tree bindings of extcon-gpio driver.
> > The extcon-gpio device tree node must include the both 'extcon-id' and
> > 'gpios' property.
> >
> > For example:
> > usb_cable: extcon-gpio-0 {
> > compatible = "extcon-gpio";
> > extcon-id = ;
> > gpios = < 1 GPIO_ACTIVE_HIGH>;
> > }
> > ta_cable: extcon-gpio-1 {
> > compatible = "extcon-gpio";
> > extcon-id = ;
> > gpios = < 2 GPIO_ACTIVE_LOW>;
> > debounce-ms = <50>; /* 50 millisecond */
> > wakeup-source;
> > }
> > _usb {
> > extcon = <_cable>;
> > };
> >  {
> > extcon = <_cable>;
> > };
> >
> > Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
> > Signed-off-by: Chanwoo Choi <cw00.c...@samsung.com>
> > Signed-off-by: MyungJoo Ham <myungjoo@samsung.com>
> >
> > ---
> > changes from v3:
> > - add description for wakeup-source in documentation
> > - change dts property extcon-gpio name to gpios
> > - use of_get_named_gpio_flags to get gpio number and flags Changes
> > from v2:
> > - Add the more description for 'extcon-id' property in documentation
> > Changes from v1:
> > - Create the include/dt-bindings/extcon/extcon.h including the
> > identification of external connector. These definitions are used in dts 
> > file.
> > - Fix error if CONFIG_OF is disabled.
> > - Add signed-off tag by Myungjoo Ham
> > ---
> > ---
> >  .../devicetree/bindings/extcon/extcon-gpio.txt |  48 +
> >  drivers/extcon/extcon-gpio.c   | 109 
> > +
> >  include/dt-bindings/extcon/extcon.h|  47 +
> >  include/linux/extcon/extcon-gpio.h |   8 +-
> >  4 files changed, 189 insertions(+), 23 deletions(-)  create mode
> > 100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> >  create mode 100644 include/dt-bindings/extcon/extcon.h
> >
> > diff --git a/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> > b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> > new file mode 100644
> > index 000..81f7932
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> > @@ -0,0 +1,48 @@
> > +GPIO Extcon device
> > +
> > +This is a virtual device used to generate the specific cable states
> > +from the GPIO pin.
> > +
> > +Required properties:
> > +- compatible: Must be "extcon-gpio".
> > +- extcon-id: The extcon support the various type of external
> > +connector to check
> > +  whether connector is attached or detached. The each external
> > +connector has
> > +  the unique number to identify it. So this property includes the
> > +un

RE: [PATCH v4] extcon: gpio: Add the support for Device tree bindings

2016-05-26 Thread Venkat Reddy Talla
Hi Choi,

Sorry for changing author, will update author field with your name.

Regarding Rob Herring comments, You had already replied.

I felt separate compatible for each external connector is not required,
as client driver can detect the type of external cable(sdp,dcp, microphone) on 
receiving notification from extcon provider,
I have also added more description for wakeup-source.

Do you see any other changes required on top of v4 patch?

Regards,
Venkat

> -Original Message-
> From: Chanwoo Choi [mailto:cwcho...@gmail.com]
> Sent: Thursday, May 26, 2016 6:52 PM
> To: Venkat Reddy Talla
> Cc: MyungJoo Ham; Rob Herring; Pawel Moll; Mark Rutland; Ian Campbell;
> devicetree; Kumar Gala; linux-kernel; Laxman Dewangan
> Subject: Re: [PATCH v4] extcon: gpio: Add the support for Device tree
> bindings
> 
> Hi Venkat,
> 
> There is some miscommunication. On previous my reply, I don't mean that
> the author of the patch[1] is changed from me to you.
> 
> I'd like you to remain the original author(me) for the patch[1] without
> changing the author.
> [1] https://lkml.org/lkml/2015/10/21/8
> - [PATCH v3] extcon: gpio: Add the support for Device tree bindings
> 
> You can use the patch[1] as based patch and you can add new feature on
> base patch[1]. Also, If you ok, you can modify the extccon-gpio.c driver as
> Rob comment[2].
> 
> But, Rob Herring gave me the some comment[2].
> [2] https://lkml.org/lkml/2015/10/21/906
> 
> 
> Thanks,
> Chanwoo Choi
> 
> 
> On Thu, May 26, 2016 at 8:47 PM, Venkat Reddy Talla
>  wrote:
> > Add the support for Device tree bindings of extcon-gpio driver.
> > The extcon-gpio device tree node must include the both 'extcon-id' and
> > 'gpios' property.
> >
> > For example:
> > usb_cable: extcon-gpio-0 {
> > compatible = "extcon-gpio";
> > extcon-id = ;
> > gpios = < 1 GPIO_ACTIVE_HIGH>;
> > }
> > ta_cable: extcon-gpio-1 {
> > compatible = "extcon-gpio";
> > extcon-id = ;
> > gpios = < 2 GPIO_ACTIVE_LOW>;
> > debounce-ms = <50>; /* 50 millisecond */
> > wakeup-source;
> > }
> > _usb {
> > extcon = <_cable>;
> > };
> >  {
> > extcon = <_cable>;
> > };
> >
> > Signed-off-by: Venkat Reddy Talla 
> > Signed-off-by: Chanwoo Choi 
> > Signed-off-by: MyungJoo Ham 
> >
> > ---
> > changes from v3:
> > - add description for wakeup-source in documentation
> > - change dts property extcon-gpio name to gpios
> > - use of_get_named_gpio_flags to get gpio number and flags Changes
> > from v2:
> > - Add the more description for 'extcon-id' property in documentation
> > Changes from v1:
> > - Create the include/dt-bindings/extcon/extcon.h including the
> > identification of external connector. These definitions are used in dts 
> > file.
> > - Fix error if CONFIG_OF is disabled.
> > - Add signed-off tag by Myungjoo Ham
> > ---
> > ---
> >  .../devicetree/bindings/extcon/extcon-gpio.txt |  48 +
> >  drivers/extcon/extcon-gpio.c   | 109 
> > +
> >  include/dt-bindings/extcon/extcon.h|  47 +
> >  include/linux/extcon/extcon-gpio.h |   8 +-
> >  4 files changed, 189 insertions(+), 23 deletions(-)  create mode
> > 100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> >  create mode 100644 include/dt-bindings/extcon/extcon.h
> >
> > diff --git a/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> > b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> > new file mode 100644
> > index 000..81f7932
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> > @@ -0,0 +1,48 @@
> > +GPIO Extcon device
> > +
> > +This is a virtual device used to generate the specific cable states
> > +from the GPIO pin.
> > +
> > +Required properties:
> > +- compatible: Must be "extcon-gpio".
> > +- extcon-id: The extcon support the various type of external
> > +connector to check
> > +  whether connector is attached or detached. The each external
> > +connector has
> > +  the unique number to identify it. So this property includes the
> > +unique number
> > +  which indicates the specific external connector. When external
> > +connector is
> > + 

[PATCH v4] extcon: gpio: Add the support for Device tree bindings

2016-05-26 Thread Venkat Reddy Talla
Add the support for Device tree bindings of extcon-gpio driver.
The extcon-gpio device tree node must include the both 'extcon-id' and
'gpios' property.

For example:
usb_cable: extcon-gpio-0 {
compatible = "extcon-gpio";
extcon-id = ;
gpios = < 1 GPIO_ACTIVE_HIGH>;
}
ta_cable: extcon-gpio-1 {
compatible = "extcon-gpio";
extcon-id = ;
gpios = < 2 GPIO_ACTIVE_LOW>;
debounce-ms = <50>; /* 50 millisecond */
wakeup-source;
}
_usb {
extcon = <_cable>;
};
 {
extcon = <_cable>;
};

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
Signed-off-by: Chanwoo Choi <cw00.c...@samsung.com>
Signed-off-by: MyungJoo Ham <myungjoo@samsung.com>

---
changes from v3:
- add description for wakeup-source in documentation
- change dts property extcon-gpio name to gpios
- use of_get_named_gpio_flags to get gpio number and flags
Changes from v2:
- Add the more description for 'extcon-id' property in documentation
Changes from v1:
- Create the include/dt-bindings/extcon/extcon.h including the identification
of external connector. These definitions are used in dts file.
- Fix error if CONFIG_OF is disabled.
- Add signed-off tag by Myungjoo Ham
---
---
 .../devicetree/bindings/extcon/extcon-gpio.txt |  48 +
 drivers/extcon/extcon-gpio.c   | 109 +
 include/dt-bindings/extcon/extcon.h|  47 +
 include/linux/extcon/extcon-gpio.h |   8 +-
 4 files changed, 189 insertions(+), 23 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt
 create mode 100644 include/dt-bindings/extcon/extcon.h

diff --git a/Documentation/devicetree/bindings/extcon/extcon-gpio.txt 
b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
new file mode 100644
index 000..81f7932
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
@@ -0,0 +1,48 @@
+GPIO Extcon device
+
+This is a virtual device used to generate the specific cable states from the
+GPIO pin.
+
+Required properties:
+- compatible: Must be "extcon-gpio".
+- extcon-id: The extcon support the various type of external connector to check
+  whether connector is attached or detached. The each external connector has
+  the unique number to identify it. So this property includes the unique number
+  which indicates the specific external connector. When external connector is
+  attached or detached, GPIO pin detect the changed state. See include/
+  dt-bindings/extcon/extcon.h which defines the unique number for supported
+  external connector from extcon framework.
+- gpios: GPIO pin to detect the external connector. See gpio binding.
+
+Optional properties:
+- debounce-ms: the debounce dealy for GPIO pin in millisecond.
+- wakeup-source: Boolean, extcon can wake-up the system from suspend.
+  if gpio provided in extcon-gpio DT node is registered as interrupt,
+  then extcon can wake-up the system from suspend if wakeup-source property
+  is available in DT node, if gpio registered as interrupt but wakeup-source
+  is not available in DT node, then system wake-up due to extcon events
+  not supported.
+
+Example: Examples of extcon-gpio node as listed below:
+
+   usb_cable: extcon-gpio-0 {
+   compatible = "extcon-gpio";
+   extcon-id = ;
+   extcon-gpio = < 1 GPIO_ACTIVE_HIGH>;
+   }
+
+   ta_cable: extcon-gpio-1 {
+   compatible = "extcon-gpio";
+   extcon-id = ;
+   extcon-gpio = < 2 GPIO_ACTIVE_LOW>;
+   debounce-ms = <50>; /* 50 millisecond */
+   wakeup-source;
+   }
+
+   _usb {
+   extcon = <_cable>;
+   };
+
+{
+   extcon = <_cable>;
+   };
diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index d023789..592f395 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -1,11 +1,9 @@
 /*
  * extcon_gpio.c - Single-state GPIO extcon driver based on extcon class
  *
- * Copyright (C) 2008 Google, Inc.
- * Author: Mike Lockwood <lockw...@android.com>
- *
- * Modified by MyungJoo Ham <myungjoo@samsung.com> to support extcon
- * (originally switch class is supported)
+ * Copyright (C) 2016 Chanwoo Choi <cw00.c...@samsung.com>, Samsung Electronics
+ * Copyright (C) 2012 MyungJoo Ham <myungjoo@samsung.com>, Samsung 
Electronics
+ * Copyright (C) 2008 Mike Lockwood <lockw...@android.com>, Google, Inc.
  *
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
@@ -

[PATCH v4] extcon: gpio: Add the support for Device tree bindings

2016-05-26 Thread Venkat Reddy Talla
Add the support for Device tree bindings of extcon-gpio driver.
The extcon-gpio device tree node must include the both 'extcon-id' and
'gpios' property.

For example:
usb_cable: extcon-gpio-0 {
compatible = "extcon-gpio";
extcon-id = ;
gpios = < 1 GPIO_ACTIVE_HIGH>;
}
ta_cable: extcon-gpio-1 {
compatible = "extcon-gpio";
extcon-id = ;
gpios = < 2 GPIO_ACTIVE_LOW>;
debounce-ms = <50>; /* 50 millisecond */
wakeup-source;
}
_usb {
extcon = <_cable>;
};
 {
extcon = <_cable>;
};

Signed-off-by: Venkat Reddy Talla 
Signed-off-by: Chanwoo Choi 
Signed-off-by: MyungJoo Ham 

---
changes from v3:
- add description for wakeup-source in documentation
- change dts property extcon-gpio name to gpios
- use of_get_named_gpio_flags to get gpio number and flags
Changes from v2:
- Add the more description for 'extcon-id' property in documentation
Changes from v1:
- Create the include/dt-bindings/extcon/extcon.h including the identification
of external connector. These definitions are used in dts file.
- Fix error if CONFIG_OF is disabled.
- Add signed-off tag by Myungjoo Ham
---
---
 .../devicetree/bindings/extcon/extcon-gpio.txt |  48 +
 drivers/extcon/extcon-gpio.c   | 109 +
 include/dt-bindings/extcon/extcon.h|  47 +
 include/linux/extcon/extcon-gpio.h |   8 +-
 4 files changed, 189 insertions(+), 23 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt
 create mode 100644 include/dt-bindings/extcon/extcon.h

diff --git a/Documentation/devicetree/bindings/extcon/extcon-gpio.txt 
b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
new file mode 100644
index 000..81f7932
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
@@ -0,0 +1,48 @@
+GPIO Extcon device
+
+This is a virtual device used to generate the specific cable states from the
+GPIO pin.
+
+Required properties:
+- compatible: Must be "extcon-gpio".
+- extcon-id: The extcon support the various type of external connector to check
+  whether connector is attached or detached. The each external connector has
+  the unique number to identify it. So this property includes the unique number
+  which indicates the specific external connector. When external connector is
+  attached or detached, GPIO pin detect the changed state. See include/
+  dt-bindings/extcon/extcon.h which defines the unique number for supported
+  external connector from extcon framework.
+- gpios: GPIO pin to detect the external connector. See gpio binding.
+
+Optional properties:
+- debounce-ms: the debounce dealy for GPIO pin in millisecond.
+- wakeup-source: Boolean, extcon can wake-up the system from suspend.
+  if gpio provided in extcon-gpio DT node is registered as interrupt,
+  then extcon can wake-up the system from suspend if wakeup-source property
+  is available in DT node, if gpio registered as interrupt but wakeup-source
+  is not available in DT node, then system wake-up due to extcon events
+  not supported.
+
+Example: Examples of extcon-gpio node as listed below:
+
+   usb_cable: extcon-gpio-0 {
+   compatible = "extcon-gpio";
+   extcon-id = ;
+   extcon-gpio = < 1 GPIO_ACTIVE_HIGH>;
+   }
+
+   ta_cable: extcon-gpio-1 {
+   compatible = "extcon-gpio";
+   extcon-id = ;
+   extcon-gpio = < 2 GPIO_ACTIVE_LOW>;
+   debounce-ms = <50>; /* 50 millisecond */
+   wakeup-source;
+   }
+
+   _usb {
+   extcon = <_cable>;
+   };
+
+{
+   extcon = <_cable>;
+   };
diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index d023789..592f395 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -1,11 +1,9 @@
 /*
  * extcon_gpio.c - Single-state GPIO extcon driver based on extcon class
  *
- * Copyright (C) 2008 Google, Inc.
- * Author: Mike Lockwood 
- *
- * Modified by MyungJoo Ham  to support extcon
- * (originally switch class is supported)
+ * Copyright (C) 2016 Chanwoo Choi , Samsung Electronics
+ * Copyright (C) 2012 MyungJoo Ham , Samsung 
Electronics
+ * Copyright (C) 2008 Mike Lockwood , Google, Inc.
  *
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
@@ -25,13 +23,17 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
+#include 
 #include 
 #include 
 
 struct gpio_extcon_data {
struct extcon_dev *edev;
int irq;
+   bool irq_wakeup;
struct dela

[PATCH v2 2/2] extcon: gpio: add DT binding doc for extcon-gpio

2016-05-25 Thread Venkat Reddy Talla
Adding DT binding doc for extcon gpio device
properties.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>

---
changes in v2:
- added description for extcon-gpio
- using gpio flag cell to handle gpio active state
- change dts property name gpio to gpios
- removed prefix for debounce
- added description for extcon-gpio,cable-names
---
---
 .../devicetree/bindings/extcon/extcon-gpio.txt | 22 ++
 1 file changed, 22 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt

diff --git a/Documentation/devicetree/bindings/extcon/extcon-gpio.txt 
b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
new file mode 100644
index 000..2302960
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
@@ -0,0 +1,22 @@
+EXTCON FOR GPIO
+
+extcon-gpio responsible to detect external cable state when
+attached or detached.
+
+Required Properties:
+ - compatible : Should be "extcon-gpio";
+
+Optional Properties:
+ - extcon-gpio,name: Name of extcon device.
+ - gpios: gpio number.
+ - extcon-gpio,irq-flags: IRQ flags for gpio.
+ - debounce-ms: Debounce time in ms.
+ - extcon-gpio,cable-names: The unique id of specific external connector
+   defined in include/linux/extcon.h
+
+extcon-gpio {
+   compatible = "extcon-gpio";
+extcon-gpio,name = "VBUS";
+   gpios = < 20 0>;
+   extcon-gpio,cable-names = ;
+};
-- 
2.1.4



[PATCH v2 2/2] extcon: gpio: add DT binding doc for extcon-gpio

2016-05-25 Thread Venkat Reddy Talla
Adding DT binding doc for extcon gpio device
properties.

Signed-off-by: Venkat Reddy Talla 

---
changes in v2:
- added description for extcon-gpio
- using gpio flag cell to handle gpio active state
- change dts property name gpio to gpios
- removed prefix for debounce
- added description for extcon-gpio,cable-names
---
---
 .../devicetree/bindings/extcon/extcon-gpio.txt | 22 ++
 1 file changed, 22 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt

diff --git a/Documentation/devicetree/bindings/extcon/extcon-gpio.txt 
b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
new file mode 100644
index 000..2302960
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
@@ -0,0 +1,22 @@
+EXTCON FOR GPIO
+
+extcon-gpio responsible to detect external cable state when
+attached or detached.
+
+Required Properties:
+ - compatible : Should be "extcon-gpio";
+
+Optional Properties:
+ - extcon-gpio,name: Name of extcon device.
+ - gpios: gpio number.
+ - extcon-gpio,irq-flags: IRQ flags for gpio.
+ - debounce-ms: Debounce time in ms.
+ - extcon-gpio,cable-names: The unique id of specific external connector
+   defined in include/linux/extcon.h
+
+extcon-gpio {
+   compatible = "extcon-gpio";
+extcon-gpio,name = "VBUS";
+   gpios = < 20 0>;
+   extcon-gpio,cable-names = ;
+};
-- 
2.1.4



[PATCH v2 1/2] extcon: gpio: add device tree support for extcon-gpio

2016-05-25 Thread Venkat Reddy Talla
Adding device tree support for extcon-gpio driver.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>

---
changes in v2:
- using gpio flag cell to handle gpio active state
- change dts property name gpio to gpios
- removed prefix for debounce
---
---
 drivers/extcon/extcon-gpio.c   | 80 +++---
 include/linux/extcon/extcon-gpio.h |  4 +-
 2 files changed, 77 insertions(+), 7 deletions(-)

diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index d023789..f29032c 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -28,6 +28,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 struct gpio_extcon_data {
struct extcon_dev *edev;
@@ -90,21 +92,80 @@ static int gpio_extcon_init(struct device *dev, struct 
gpio_extcon_data *data)
return 0;
 }
 
+static struct gpio_extcon_pdata *gpio_extcon_of_pdata(
+   struct platform_device *pdev)
+{
+   struct gpio_extcon_pdata *pdata;
+   struct device_node *np = pdev->dev.of_node;
+   enum of_gpio_flags flags;
+   int gpio;
+   u32 pval;
+   int ret;
+
+   pdata = devm_kzalloc(>dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return ERR_PTR(-ENOMEM);
+
+   gpio = of_get_named_gpio_flags(np, "gpios", 0, );
+   if (gpio < 0)
+   return ERR_PTR(gpio);
+
+   pdata->gpio = gpio;
+
+   if (flags & OF_GPIO_ACTIVE_LOW)
+   pdata->gpio_active_low = 1;
+
+   ret = of_property_read_u32(np, "extcon-gpio,irq-flags", );
+   if (!ret)
+   pdata->irq_flags = pval;
+   else
+   pdata->irq_flags = IRQF_TRIGGER_RISING |
+   IRQF_TRIGGER_FALLING;
+
+   ret = of_property_read_u32(np, "debounce-ms", );
+   if (!ret)
+   pdata->debounce = pval;
+
+   pdata->extcon_cable_cnt = of_property_count_u32_elems(np,
+   "extcon-gpio,cable-names");
+   if (pdata->extcon_cable_cnt <= 0) {
+   dev_err(>dev, "not found out cable names\n");
+   return ERR_PTR(-EINVAL);
+   }
+
+   pdata->extcon_id = devm_kzalloc(>dev,
+   (pdata->extcon_cable_cnt) *
+   sizeof(*pdata->extcon_id), GFP_KERNEL);
+   if (!pdata->extcon_id)
+   return ERR_PTR(-ENOMEM);
+
+   ret = of_property_read_u32_array(np, "extcon-gpio,cable-names",
+   pdata->extcon_id, pdata->extcon_cable_cnt);
+   if (ret)
+   return ERR_PTR(-EINVAL);
+
+   return pdata;
+}
+
 static int gpio_extcon_probe(struct platform_device *pdev)
 {
struct gpio_extcon_pdata *pdata = dev_get_platdata(>dev);
struct gpio_extcon_data *data;
int ret;
 
-   if (!pdata)
-   return -EBUSY;
-   if (!pdata->irq_flags || pdata->extcon_id > EXTCON_NONE)
-   return -EINVAL;
-
data = devm_kzalloc(>dev, sizeof(struct gpio_extcon_data),
   GFP_KERNEL);
if (!data)
return -ENOMEM;
+
+   if (!pdata && pdev->dev.of_node)
+   pdata = gpio_extcon_of_pdata(pdev);
+
+   if (IS_ERR(pdata))
+   return PTR_ERR(pdata);
+   if (!pdata->irq_flags || !pdata->extcon_id)
+   return -EINVAL;
+
data->pdata = pdata;
 
/* Initialize the gpio */
@@ -113,7 +174,7 @@ static int gpio_extcon_probe(struct platform_device *pdev)
return ret;
 
/* Allocate the memory of extcon devie and register extcon device */
-   data->edev = devm_extcon_dev_allocate(>dev, >extcon_id);
+   data->edev = devm_extcon_dev_allocate(>dev, pdata->extcon_id);
if (IS_ERR(data->edev)) {
dev_err(>dev, "failed to allocate extcon device\n");
return -ENOMEM;
@@ -167,12 +228,19 @@ static int gpio_extcon_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(gpio_extcon_pm_ops, NULL, gpio_extcon_resume);
 
+static const struct of_device_id of_extcon_gpio_tbl[] = {
+   { .compatible = "extcon-gpio", },
+   { /* end */ }
+};
+MODULE_DEVICE_TABLE(of, of_extcon_gpio_tbl);
+
 static struct platform_driver gpio_extcon_driver = {
.probe  = gpio_extcon_probe,
.remove = gpio_extcon_remove,
.driver = {
.name   = "extcon-gpio",
.pm = _extcon_pm_ops,
+   .of_match_table = of_extcon_gpio_tbl,
},
 };
 
diff --git a/include/linux/extcon/extcon-gpio.h 
b/include/linux/extcon/extcon-gpio.h
index 7cacafb..1914894 100644
--- a/include/linux/extcon/extcon-gpio.h
+++ b/include/linux/extcon/

[PATCH v2 1/2] extcon: gpio: add device tree support for extcon-gpio

2016-05-25 Thread Venkat Reddy Talla
Adding device tree support for extcon-gpio driver.

Signed-off-by: Venkat Reddy Talla 

---
changes in v2:
- using gpio flag cell to handle gpio active state
- change dts property name gpio to gpios
- removed prefix for debounce
---
---
 drivers/extcon/extcon-gpio.c   | 80 +++---
 include/linux/extcon/extcon-gpio.h |  4 +-
 2 files changed, 77 insertions(+), 7 deletions(-)

diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index d023789..f29032c 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -28,6 +28,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 struct gpio_extcon_data {
struct extcon_dev *edev;
@@ -90,21 +92,80 @@ static int gpio_extcon_init(struct device *dev, struct 
gpio_extcon_data *data)
return 0;
 }
 
+static struct gpio_extcon_pdata *gpio_extcon_of_pdata(
+   struct platform_device *pdev)
+{
+   struct gpio_extcon_pdata *pdata;
+   struct device_node *np = pdev->dev.of_node;
+   enum of_gpio_flags flags;
+   int gpio;
+   u32 pval;
+   int ret;
+
+   pdata = devm_kzalloc(>dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return ERR_PTR(-ENOMEM);
+
+   gpio = of_get_named_gpio_flags(np, "gpios", 0, );
+   if (gpio < 0)
+   return ERR_PTR(gpio);
+
+   pdata->gpio = gpio;
+
+   if (flags & OF_GPIO_ACTIVE_LOW)
+   pdata->gpio_active_low = 1;
+
+   ret = of_property_read_u32(np, "extcon-gpio,irq-flags", );
+   if (!ret)
+   pdata->irq_flags = pval;
+   else
+   pdata->irq_flags = IRQF_TRIGGER_RISING |
+   IRQF_TRIGGER_FALLING;
+
+   ret = of_property_read_u32(np, "debounce-ms", );
+   if (!ret)
+   pdata->debounce = pval;
+
+   pdata->extcon_cable_cnt = of_property_count_u32_elems(np,
+   "extcon-gpio,cable-names");
+   if (pdata->extcon_cable_cnt <= 0) {
+   dev_err(>dev, "not found out cable names\n");
+   return ERR_PTR(-EINVAL);
+   }
+
+   pdata->extcon_id = devm_kzalloc(>dev,
+   (pdata->extcon_cable_cnt) *
+   sizeof(*pdata->extcon_id), GFP_KERNEL);
+   if (!pdata->extcon_id)
+   return ERR_PTR(-ENOMEM);
+
+   ret = of_property_read_u32_array(np, "extcon-gpio,cable-names",
+   pdata->extcon_id, pdata->extcon_cable_cnt);
+   if (ret)
+   return ERR_PTR(-EINVAL);
+
+   return pdata;
+}
+
 static int gpio_extcon_probe(struct platform_device *pdev)
 {
struct gpio_extcon_pdata *pdata = dev_get_platdata(>dev);
struct gpio_extcon_data *data;
int ret;
 
-   if (!pdata)
-   return -EBUSY;
-   if (!pdata->irq_flags || pdata->extcon_id > EXTCON_NONE)
-   return -EINVAL;
-
data = devm_kzalloc(>dev, sizeof(struct gpio_extcon_data),
   GFP_KERNEL);
if (!data)
return -ENOMEM;
+
+   if (!pdata && pdev->dev.of_node)
+   pdata = gpio_extcon_of_pdata(pdev);
+
+   if (IS_ERR(pdata))
+   return PTR_ERR(pdata);
+   if (!pdata->irq_flags || !pdata->extcon_id)
+   return -EINVAL;
+
data->pdata = pdata;
 
/* Initialize the gpio */
@@ -113,7 +174,7 @@ static int gpio_extcon_probe(struct platform_device *pdev)
return ret;
 
/* Allocate the memory of extcon devie and register extcon device */
-   data->edev = devm_extcon_dev_allocate(>dev, >extcon_id);
+   data->edev = devm_extcon_dev_allocate(>dev, pdata->extcon_id);
if (IS_ERR(data->edev)) {
dev_err(>dev, "failed to allocate extcon device\n");
return -ENOMEM;
@@ -167,12 +228,19 @@ static int gpio_extcon_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(gpio_extcon_pm_ops, NULL, gpio_extcon_resume);
 
+static const struct of_device_id of_extcon_gpio_tbl[] = {
+   { .compatible = "extcon-gpio", },
+   { /* end */ }
+};
+MODULE_DEVICE_TABLE(of, of_extcon_gpio_tbl);
+
 static struct platform_driver gpio_extcon_driver = {
.probe  = gpio_extcon_probe,
.remove = gpio_extcon_remove,
.driver = {
.name   = "extcon-gpio",
.pm = _extcon_pm_ops,
+   .of_match_table = of_extcon_gpio_tbl,
},
 };
 
diff --git a/include/linux/extcon/extcon-gpio.h 
b/include/linux/extcon/extcon-gpio.h
index 7cacafb..1914894 100644
--- a/include/linux/extcon/extcon-gpio.h
+++ b/include/linux/extcon/extcon-gpio.h
@@ -31,15 +31,17 @@
  *   

RE: [PATCH 2/2] extcon: gpio: add DT binding doc for extcon-gpio

2016-05-17 Thread Venkat Reddy Talla
Thanks for review, please find my inline reply.

> -Original Message-
> From: Rob Herring [mailto:r...@kernel.org]
> Sent: Wednesday, May 04, 2016 7:01 PM
> To: Venkat Reddy Talla
> Cc: MyungJoo Ham; Chanwoo Choi; Pawel Moll; Mark Rutland; Ian Campbell;
> Kumar Gala; linux-kernel@vger.kernel.org; devicet...@vger.kernel.org;
> Laxman Dewangan
> Subject: Re: [PATCH 2/2] extcon: gpio: add DT binding doc for extcon-gpio
> 
> On Tue, May 03, 2016 at 11:19:51AM +0530, Venkat Reddy Talla wrote:
> > Addiing DT binding doc for the extcon gpios properties.
> >
> > Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
> > ---
> >  .../devicetree/bindings/extcon/extcon-gpio.txt| 19
> +++
> >  1 file changed, 19 insertions(+)
> >  create mode 100644
> > Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> >
> > diff --git a/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> > b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> > new file mode 100644
> > index 000..4a49c23
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> > @@ -0,0 +1,19 @@
> > +EXTCON FOR GPIO
> 
> This needs a better description of what this is and what h/w this applies to.
> 
I will take care in my next patch.

> > +
> > +Required Properties:
> > + - compatible : Should be "extcon-gpio";
> > +
> > +Optional Properties:
> > + - extcon-gpio,name: Name of extcon device.
> > + - gpio: gpio number.
> 
> Should be 'gpios'.
> 
OK, I will take care in my next patch.

> > + - extcon-gpio,irq-flags: IRQ flags for GPIO.
> 
> If this is an interrupt, then you should be using the interrupts property.
> 
Need to provide GPIO number instead of interrupt from DTS to read GPIO value 
when external connected attached/detached and also driver supports platform 
data with passing GPIO number.
So need to pass irq-flags using separate dts property or need to hardcode in 
driver.

> > + - extcon-gpio,debounce: Debounce time in ms.
> 
> extcon-gpio is not a vendor prefix, so drop it.
> 
> Add unit suffix (-ms).
> 
OK, I will take care in my next patch.

> > + - extcon-gpio,connection-state-low: boolean, Connection state with
> > +gpio state. True if gpio low means connected.
> 
> The active state should be in the GPIO flags cell.
> 
OK, I will take care in my next patch.
> > +
> > +extcon-gpio {
> > +   compatible = "extcon-gpio";
> > +extcon-gpio,name = "VBUS";
> 
> How is VBus a gpio?
> 
Here VBUS is not gpio number, VBUS is extcon device name, extcon gpio is used 
to detect VBUS.

> > +   gpio = < 20 0>;
> > +   extcon-gpio,cable-names = ;
> 
> Not documented.
> 
> Rob
OK, I will take care in my next patch.


RE: [PATCH 2/2] extcon: gpio: add DT binding doc for extcon-gpio

2016-05-17 Thread Venkat Reddy Talla
Thanks for review, please find my inline reply.

> -Original Message-
> From: Rob Herring [mailto:r...@kernel.org]
> Sent: Wednesday, May 04, 2016 7:01 PM
> To: Venkat Reddy Talla
> Cc: MyungJoo Ham; Chanwoo Choi; Pawel Moll; Mark Rutland; Ian Campbell;
> Kumar Gala; linux-kernel@vger.kernel.org; devicet...@vger.kernel.org;
> Laxman Dewangan
> Subject: Re: [PATCH 2/2] extcon: gpio: add DT binding doc for extcon-gpio
> 
> On Tue, May 03, 2016 at 11:19:51AM +0530, Venkat Reddy Talla wrote:
> > Addiing DT binding doc for the extcon gpios properties.
> >
> > Signed-off-by: Venkat Reddy Talla 
> > ---
> >  .../devicetree/bindings/extcon/extcon-gpio.txt| 19
> +++
> >  1 file changed, 19 insertions(+)
> >  create mode 100644
> > Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> >
> > diff --git a/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> > b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> > new file mode 100644
> > index 000..4a49c23
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> > @@ -0,0 +1,19 @@
> > +EXTCON FOR GPIO
> 
> This needs a better description of what this is and what h/w this applies to.
> 
I will take care in my next patch.

> > +
> > +Required Properties:
> > + - compatible : Should be "extcon-gpio";
> > +
> > +Optional Properties:
> > + - extcon-gpio,name: Name of extcon device.
> > + - gpio: gpio number.
> 
> Should be 'gpios'.
> 
OK, I will take care in my next patch.

> > + - extcon-gpio,irq-flags: IRQ flags for GPIO.
> 
> If this is an interrupt, then you should be using the interrupts property.
> 
Need to provide GPIO number instead of interrupt from DTS to read GPIO value 
when external connected attached/detached and also driver supports platform 
data with passing GPIO number.
So need to pass irq-flags using separate dts property or need to hardcode in 
driver.

> > + - extcon-gpio,debounce: Debounce time in ms.
> 
> extcon-gpio is not a vendor prefix, so drop it.
> 
> Add unit suffix (-ms).
> 
OK, I will take care in my next patch.

> > + - extcon-gpio,connection-state-low: boolean, Connection state with
> > +gpio state. True if gpio low means connected.
> 
> The active state should be in the GPIO flags cell.
> 
OK, I will take care in my next patch.
> > +
> > +extcon-gpio {
> > +   compatible = "extcon-gpio";
> > +extcon-gpio,name = "VBUS";
> 
> How is VBus a gpio?
> 
Here VBUS is not gpio number, VBUS is extcon device name, extcon gpio is used 
to detect VBUS.

> > +   gpio = < 20 0>;
> > +   extcon-gpio,cable-names = ;
> 
> Not documented.
> 
> Rob
OK, I will take care in my next patch.


[PATCH 2/2] extcon: gpio: add DT binding doc for extcon-gpio

2016-05-02 Thread Venkat Reddy Talla
Addiing DT binding doc for the extcon gpios properties.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
---
 .../devicetree/bindings/extcon/extcon-gpio.txt| 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt

diff --git a/Documentation/devicetree/bindings/extcon/extcon-gpio.txt 
b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
new file mode 100644
index 000..4a49c23
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
@@ -0,0 +1,19 @@
+EXTCON FOR GPIO
+
+Required Properties:
+ - compatible : Should be "extcon-gpio";
+
+Optional Properties:
+ - extcon-gpio,name: Name of extcon device.
+ - gpio: gpio number.
+ - extcon-gpio,irq-flags: IRQ flags for GPIO.
+ - extcon-gpio,debounce: Debounce time in ms.
+ - extcon-gpio,connection-state-low: boolean, Connection state with
+gpio state. True if gpio low means connected.
+
+extcon-gpio {
+   compatible = "extcon-gpio";
+extcon-gpio,name = "VBUS";
+   gpio = < 20 0>;
+   extcon-gpio,cable-names = ;
+};
-- 
2.1.4



[PATCH 2/2] extcon: gpio: add DT binding doc for extcon-gpio

2016-05-02 Thread Venkat Reddy Talla
Addiing DT binding doc for the extcon gpios properties.

Signed-off-by: Venkat Reddy Talla 
---
 .../devicetree/bindings/extcon/extcon-gpio.txt| 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt

diff --git a/Documentation/devicetree/bindings/extcon/extcon-gpio.txt 
b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
new file mode 100644
index 000..4a49c23
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
@@ -0,0 +1,19 @@
+EXTCON FOR GPIO
+
+Required Properties:
+ - compatible : Should be "extcon-gpio";
+
+Optional Properties:
+ - extcon-gpio,name: Name of extcon device.
+ - gpio: gpio number.
+ - extcon-gpio,irq-flags: IRQ flags for GPIO.
+ - extcon-gpio,debounce: Debounce time in ms.
+ - extcon-gpio,connection-state-low: boolean, Connection state with
+gpio state. True if gpio low means connected.
+
+extcon-gpio {
+   compatible = "extcon-gpio";
+extcon-gpio,name = "VBUS";
+   gpio = < 20 0>;
+   extcon-gpio,cable-names = ;
+};
-- 
2.1.4



[PATCH 1/2] extcon: gpio: add device tree support for extcon-gpio

2016-05-02 Thread Venkat Reddy Talla
Adding device tree support for extcon-gpio driver.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
---
 drivers/extcon/extcon-gpio.c   | 80 +++---
 include/linux/extcon/extcon-gpio.h |  2 +
 2 files changed, 76 insertions(+), 6 deletions(-)

diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index d023789..b7fae7e 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -28,6 +28,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 struct gpio_extcon_data {
struct extcon_dev *edev;
@@ -90,21 +92,79 @@ static int gpio_extcon_init(struct device *dev, struct 
gpio_extcon_data *data)
return 0;
 }
 
+static struct gpio_extcon_pdata *gpio_extcon_of_pdata(
+   struct platform_device *pdev)
+{
+   struct gpio_extcon_pdata *pdata;
+   struct device_node *np = pdev->dev.of_node;
+   int gpio;
+   u32 pval;
+   int ret;
+
+   pdata = devm_kzalloc(>dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return ERR_PTR(-ENOMEM);
+
+   gpio = of_get_named_gpio(np, "gpio", 0);
+   if (gpio < 0)
+   return ERR_PTR(gpio);
+
+   pdata->gpio = gpio;
+
+   ret = of_property_read_u32(np, "extcon-gpio,irq-flags", );
+   if (!ret)
+   pdata->irq_flags = pval;
+   else
+   pdata->irq_flags = IRQF_TRIGGER_RISING |
+   IRQF_TRIGGER_FALLING;
+
+   ret = of_property_read_u32(np, "extcon-gpio,debounce", );
+   if (!ret)
+   pdata->debounce = pval;
+
+   pdata->gpio_active_low = of_property_read_bool(np,
+   "extcon-gpio,connection-state-low");
+
+   pdata->extcon_cable_cnt = of_property_count_u32_elems(np,
+   "extcon-gpio,cable-names");
+   if (pdata->extcon_cable_cnt <= 0) {
+   dev_err(>dev, "not found out cable names\n");
+   return ERR_PTR(-EINVAL);
+   }
+
+   pdata->extcon_cable_names = devm_kzalloc(>dev,
+   (pdata->extcon_cable_cnt) *
+   sizeof(*pdata->extcon_cable_names), GFP_KERNEL);
+   if (!pdata->extcon_cable_names)
+   return ERR_PTR(-ENOMEM);
+
+   ret = of_property_read_u32_array(np, "extcon-gpio,cable-names",
+   pdata->extcon_cable_names, pdata->extcon_cable_cnt);
+   if (ret)
+   return ERR_PTR(-EINVAL);
+
+   return pdata;
+}
+
 static int gpio_extcon_probe(struct platform_device *pdev)
 {
struct gpio_extcon_pdata *pdata = dev_get_platdata(>dev);
struct gpio_extcon_data *data;
int ret;
 
-   if (!pdata)
-   return -EBUSY;
-   if (!pdata->irq_flags || pdata->extcon_id > EXTCON_NONE)
-   return -EINVAL;
-
data = devm_kzalloc(>dev, sizeof(struct gpio_extcon_data),
   GFP_KERNEL);
if (!data)
return -ENOMEM;
+
+   if (!pdata && pdev->dev.of_node)
+   pdata = gpio_extcon_of_pdata(pdev);
+
+   if (IS_ERR(pdata))
+   return PTR_ERR(pdata);
+   if (!pdata->irq_flags || !pdata->extcon_cable_names)
+   return -EINVAL;
+
data->pdata = pdata;
 
/* Initialize the gpio */
@@ -113,7 +173,8 @@ static int gpio_extcon_probe(struct platform_device *pdev)
return ret;
 
/* Allocate the memory of extcon devie and register extcon device */
-   data->edev = devm_extcon_dev_allocate(>dev, >extcon_id);
+   data->edev = devm_extcon_dev_allocate(>dev,
+   pdata->extcon_cable_names);
if (IS_ERR(data->edev)) {
dev_err(>dev, "failed to allocate extcon device\n");
return -ENOMEM;
@@ -167,12 +228,19 @@ static int gpio_extcon_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(gpio_extcon_pm_ops, NULL, gpio_extcon_resume);
 
+static const struct of_device_id of_extcon_gpio_tbl[] = {
+   { .compatible = "extcon-gpio", },
+   { /* end */ }
+};
+MODULE_DEVICE_TABLE(of, of_extcon_gpio_tbl);
+
 static struct platform_driver gpio_extcon_driver = {
.probe  = gpio_extcon_probe,
.remove = gpio_extcon_remove,
.driver = {
.name   = "extcon-gpio",
.pm = _extcon_pm_ops,
+   .of_match_table = of_extcon_gpio_tbl,
},
 };
 
diff --git a/include/linux/extcon/extcon-gpio.h 
b/include/linux/extcon/extcon-gpio.h
index 7cacafb..c27df9b 100644
--- a/include/linux/extcon/extcon-gpio.h
+++ b/include/linux/extcon/extcon-gpio.h
@@ -36,6 +36,8 @@
  */
 struct gpio_extcon_pdata {
unsigned int extcon_id;
+   unsigned int *extcon_cable_names;
+   int extcon_cable_cnt;
unsigned gpio;
bool gpio_active_low;
unsigned long debounce;
-- 
2.1.4



[PATCH 1/2] extcon: gpio: add device tree support for extcon-gpio

2016-05-02 Thread Venkat Reddy Talla
Adding device tree support for extcon-gpio driver.

Signed-off-by: Venkat Reddy Talla 
---
 drivers/extcon/extcon-gpio.c   | 80 +++---
 include/linux/extcon/extcon-gpio.h |  2 +
 2 files changed, 76 insertions(+), 6 deletions(-)

diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index d023789..b7fae7e 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -28,6 +28,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 struct gpio_extcon_data {
struct extcon_dev *edev;
@@ -90,21 +92,79 @@ static int gpio_extcon_init(struct device *dev, struct 
gpio_extcon_data *data)
return 0;
 }
 
+static struct gpio_extcon_pdata *gpio_extcon_of_pdata(
+   struct platform_device *pdev)
+{
+   struct gpio_extcon_pdata *pdata;
+   struct device_node *np = pdev->dev.of_node;
+   int gpio;
+   u32 pval;
+   int ret;
+
+   pdata = devm_kzalloc(>dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return ERR_PTR(-ENOMEM);
+
+   gpio = of_get_named_gpio(np, "gpio", 0);
+   if (gpio < 0)
+   return ERR_PTR(gpio);
+
+   pdata->gpio = gpio;
+
+   ret = of_property_read_u32(np, "extcon-gpio,irq-flags", );
+   if (!ret)
+   pdata->irq_flags = pval;
+   else
+   pdata->irq_flags = IRQF_TRIGGER_RISING |
+   IRQF_TRIGGER_FALLING;
+
+   ret = of_property_read_u32(np, "extcon-gpio,debounce", );
+   if (!ret)
+   pdata->debounce = pval;
+
+   pdata->gpio_active_low = of_property_read_bool(np,
+   "extcon-gpio,connection-state-low");
+
+   pdata->extcon_cable_cnt = of_property_count_u32_elems(np,
+   "extcon-gpio,cable-names");
+   if (pdata->extcon_cable_cnt <= 0) {
+   dev_err(>dev, "not found out cable names\n");
+   return ERR_PTR(-EINVAL);
+   }
+
+   pdata->extcon_cable_names = devm_kzalloc(>dev,
+   (pdata->extcon_cable_cnt) *
+   sizeof(*pdata->extcon_cable_names), GFP_KERNEL);
+   if (!pdata->extcon_cable_names)
+   return ERR_PTR(-ENOMEM);
+
+   ret = of_property_read_u32_array(np, "extcon-gpio,cable-names",
+   pdata->extcon_cable_names, pdata->extcon_cable_cnt);
+   if (ret)
+   return ERR_PTR(-EINVAL);
+
+   return pdata;
+}
+
 static int gpio_extcon_probe(struct platform_device *pdev)
 {
struct gpio_extcon_pdata *pdata = dev_get_platdata(>dev);
struct gpio_extcon_data *data;
int ret;
 
-   if (!pdata)
-   return -EBUSY;
-   if (!pdata->irq_flags || pdata->extcon_id > EXTCON_NONE)
-   return -EINVAL;
-
data = devm_kzalloc(>dev, sizeof(struct gpio_extcon_data),
   GFP_KERNEL);
if (!data)
return -ENOMEM;
+
+   if (!pdata && pdev->dev.of_node)
+   pdata = gpio_extcon_of_pdata(pdev);
+
+   if (IS_ERR(pdata))
+   return PTR_ERR(pdata);
+   if (!pdata->irq_flags || !pdata->extcon_cable_names)
+   return -EINVAL;
+
data->pdata = pdata;
 
/* Initialize the gpio */
@@ -113,7 +173,8 @@ static int gpio_extcon_probe(struct platform_device *pdev)
return ret;
 
/* Allocate the memory of extcon devie and register extcon device */
-   data->edev = devm_extcon_dev_allocate(>dev, >extcon_id);
+   data->edev = devm_extcon_dev_allocate(>dev,
+   pdata->extcon_cable_names);
if (IS_ERR(data->edev)) {
dev_err(>dev, "failed to allocate extcon device\n");
return -ENOMEM;
@@ -167,12 +228,19 @@ static int gpio_extcon_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(gpio_extcon_pm_ops, NULL, gpio_extcon_resume);
 
+static const struct of_device_id of_extcon_gpio_tbl[] = {
+   { .compatible = "extcon-gpio", },
+   { /* end */ }
+};
+MODULE_DEVICE_TABLE(of, of_extcon_gpio_tbl);
+
 static struct platform_driver gpio_extcon_driver = {
.probe  = gpio_extcon_probe,
.remove = gpio_extcon_remove,
.driver = {
.name   = "extcon-gpio",
.pm = _extcon_pm_ops,
+   .of_match_table = of_extcon_gpio_tbl,
},
 };
 
diff --git a/include/linux/extcon/extcon-gpio.h 
b/include/linux/extcon/extcon-gpio.h
index 7cacafb..c27df9b 100644
--- a/include/linux/extcon/extcon-gpio.h
+++ b/include/linux/extcon/extcon-gpio.h
@@ -36,6 +36,8 @@
  */
 struct gpio_extcon_pdata {
unsigned int extcon_id;
+   unsigned int *extcon_cable_names;
+   int extcon_cable_cnt;
unsigned gpio;
bool gpio_active_low;
unsigned long debounce;
-- 
2.1.4



[PATCH 1/1] extcon: gpio: queue work only if debounce is NZ

2016-03-08 Thread Venkat Reddy Talla
Use queue_delayed_work only when debounce time is
required to read gpio state properly, read the gpio
state and set the extcon cable state in IRQ handler
context if gpio settling time is not needed.

Signed-off-by: Venkat Reddy Talla <vreddyta...@nvidia.com>
---
 drivers/extcon/extcon-gpio.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index 279ff8f..1beb086 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -56,8 +56,12 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
 {
struct gpio_extcon_data *data = dev_id;
 
-   queue_delayed_work(system_power_efficient_wq, >work,
+   if (data->debounce_jiffies)
+   queue_delayed_work(system_power_efficient_wq, >work,
  data->debounce_jiffies);
+   else
+   gpio_extcon_work(>work.work);
+
return IRQ_HANDLED;
 }
 
-- 
2.1.4



[PATCH 1/1] extcon: gpio: queue work only if debounce is NZ

2016-03-08 Thread Venkat Reddy Talla
Use queue_delayed_work only when debounce time is
required to read gpio state properly, read the gpio
state and set the extcon cable state in IRQ handler
context if gpio settling time is not needed.

Signed-off-by: Venkat Reddy Talla 
---
 drivers/extcon/extcon-gpio.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index 279ff8f..1beb086 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -56,8 +56,12 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
 {
struct gpio_extcon_data *data = dev_id;
 
-   queue_delayed_work(system_power_efficient_wq, >work,
+   if (data->debounce_jiffies)
+   queue_delayed_work(system_power_efficient_wq, >work,
  data->debounce_jiffies);
+   else
+   gpio_extcon_work(>work.work);
+
return IRQ_HANDLED;
 }
 
-- 
2.1.4