Skip to contentSkip to conversation

palmas usb driver

PATCH In review Kishon Vijay Abraham I 6 participants 29 messages May 24, 2013 – May 30, 2013 1 message not in the archive

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

cover palmas usb driver

This patch series adds driver for palmas usb which is used to detect attach/detach events of usb device and usb host.

[PATCH v5 2/3] extcon: Palmas Extcon Driver which was sent previously is added in this patch series itself. The revision history is added in the patch comments section.

A checkpatch warning "WARNING: static const char * array should probably be static const char * const"is ignored since it introduces a compilation warning.

Graeme Gregory (2):
drivers: regulator: palmas: add an API to set/clear the switch bit on

    SMPS10

extcon: Palmas Extcon Driver

Kishon Vijay Abraham I (1):
usb: dwc3: use extcon fwrk to receive connect/disconnect notification

 .../devicetree/bindings/extcon/extcon-twl.txt      |  16 +
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-palmas.c                     | 341 +++++++++++++++++++++
 drivers/regulator/palmas-regulator.c               |  26 ++
 drivers/usb/dwc3/dwc3-omap.c                       |  80 +++--
 include/linux/mfd/palmas.h                         |  27 +-
 include/linux/usb/dwc3-omap.h                      |  30 --
 8 files changed, 470 insertions(+), 58 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-twl.txt
 create mode 100644 drivers/extcon/extcon-palmas.c
 delete mode 100644 include/linux/usb/dwc3-omap.h
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH 1/3 drivers: regulator: palmas: add an API to set/clear the switch bit on SMPS10

From: Graeme Gregory <[email protected]>

Added an API to set/clear the switch bit on SMPS10 which can be used by palmas usb. The switch bit should be set in order for palmas to supply VBUS and is needed when OMAP is acting as USB HOST.

---
 drivers/regulator/palmas-regulator.c | 26 ++++++++++++++++++++++++++
 include/linux/mfd/palmas.h           |  2 ++
 2 files changed, 28 insertions(+)
drivers/regulator/palmas-regulator.c +26 -0
index 92ceed0..d57ab55 100644
@@ -465,6 +465,32 @@ static int palmas_smps_set_ramp_delay(struct regulator_dev *rdev,
 	return ret;
 }
 
+/**
+ * palmas_set_switch_smps10() - set or clear the switch bit on SMPS10
+ * @param palmas pointer to the palmas mfd structure
+ * @param sw boolean to indicate switch status
+ *
+ * There is not a way to represent this function within the regulator
+ * framework. This sets/clears the switch of SMPS10 so SMPS10_OUT1 and
+ * SMPS10_OUT2 are shorted together.
+ */
+int palmas_set_switch_smps10(struct palmas *palmas, int sw)
+{
+	unsigned int reg;
+
+	palmas_smps_read(palmas, PALMAS_SMPS10_CTRL, &reg);
+
+	if (sw)
+		reg |= SMPS10_SWITCH_EN;
+	else
+		reg &= ~SMPS10_SWITCH_EN;
+
+	palmas_smps_write(palmas, PALMAS_SMPS10_CTRL, reg);
+
+	return 0;
+}
+EXPORT_SYMBOL(palmas_set_switch_smps10);
+
 static struct regulator_ops palmas_ops_smps = {
 	.is_enabled		= palmas_is_enabled_smps,
 	.enable			= palmas_enable_smps,
include/linux/mfd/palmas.h +2 -0
index 8f21daf..6df375d 100644
@@ -404,6 +404,8 @@ enum usb_irq_events {
 	N_PALMAS_USB_VOTG_SESS_VLD,
 };
 
+extern int palmas_set_switch_smps10(struct palmas *palmas, int sw);
+
 /* defines so we can store the mux settings */
 #define PALMAS_GPIO_0_MUXED					(1 << 0)
 #define PALMAS_GPIO_1_MUXED					(1 << 1)
Signature · 1 line
1.8.1.2
#2 lore raw

Re: [PATCH 1/3] drivers: regulator: palmas: add an API to set/clear the switch bit on SMPS10

Hello.

Quoted 18 lines · Kishon Vijay Abraham I

From: Graeme Gregory <[email protected]>

Added an API to set/clear the switch bit on SMPS10 which can be used by palmas usb. The switch bit should be set in order for palmas to supply VBUS and is needed when OMAP is acting as USB HOST.

---
  drivers/regulator/palmas-regulator.c | 26 ++++++++++++++++++++++++++
  include/linux/mfd/palmas.h           |  2 ++
  2 files changed, 28 insertions(+)
drivers/regulator/palmas-regulator.c +0 -0
index 92ceed0..d57ab55 100644

drivers/regulator/palmas-regulator.c static int palmas_smps_set_ramp_delay(struct regulator_dev *rdev, · line 471

Quoted 7 lines
drivers/regulator/palmas-regulator.c +4 -0
@@ -465,6 +465,32 @@ static int palmas_smps_set_ramp_delay(struct regulator_dev *rdev,
  	return ret;
  }
 
+/**
+ * palmas_set_switch_smps10() - set or clear the switch bit on SMPS10
+ * @param palmas pointer to the palmas mfd structure
+ * @param sw boolean to indicate switch status

Please follow the kernel-doc style described in
Documentation/kernel-doc-nano-HOWTO.txt.

[...]

WBR, Sergei

#3 lore raw

Re: [PATCH 1/3] drivers: regulator: palmas: add an API to set/clear the switch bit on SMPS10

In reply to Kishon Vijay Abraham I

Hi Kishon/Graeme,

Quoted 21 lines · Kishon Vijay Abraham I

From: Graeme Gregory <[email protected]>

Added an API to set/clear the switch bit on SMPS10 which can be used by palmas usb. The switch bit should be set in order for palmas to supply VBUS and is needed when OMAP is acting as USB HOST.

---
  drivers/regulator/palmas-regulator.c | 26 ++++++++++++++++++++++++++
  include/linux/mfd/palmas.h           |  2 ++
  2 files changed, 28 insertions(+)
drivers/regulator/palmas-regulator.c +0 -0
index 92ceed0..d57ab55 100644
@@ -465,6 +465,32 @@ static int palmas_smps_set_ramp_delay(struct regulator_dev *rdev,
  	return ret;
  }
 

drivers/regulator/palmas-regulator.c static int palmas_smps_set_ramp_delay(struct regulator_dev *rdev, · line 477

Quoted 10 lines
drivers/regulator/palmas-regulator.c +9 -0
+/**
+ * palmas_set_switch_smps10() - set or clear the switch bit on SMPS10
+ * @param palmas pointer to the palmas mfd structure
+ * @param sw boolean to indicate switch status
+ *
+ * There is not a way to represent this function within the regulator
+ * framework. This sets/clears the switch of SMPS10 so SMPS10_OUT1 and
+ * SMPS10_OUT2 are shorted together.
+ */
 

As per datasheet, SMPS10 has 2 outputs, OUT1 and OUT2.
OUT2 is always available either through parasitic diode or bypass switch or boost mode. It can not be off at all. OUT2 can be enable/disable through the switch bit.

The smps10 regulator is implemented enable/disable on which it just enable/disable boost mode.
I think this is not proper control, actually we should control OUT1 switch on regulator enable/disable of the smps10.

And hence in this case, we will not need this API.

Otherwise it will difficult to use this api outside of palmas.

In tegra platform, we have connected the USB-VBUS supply from SMPS10-OUT1 and usb driver control the vbus enabled/disable and so it can not call this API. This functionality need to be exposed through the regulator only.

#4 lore raw

PATCH v5 2/3 extcon: Palmas Extcon Driver

In reply to Kishon Vijay Abraham I

From: Graeme Gregory <[email protected]>

This is the driver for the USB comparator built into the palmas chip. It handles the various USB OTG events that can be generated by cable insertion/removal.

---
Changes from v4:
* removed no_control_vbus property (to be used if the platform wants to use its own vbus control.
* removed unnecessary headers
* moved the palmas_usb_state to palmas.h
* misc cleanups
*A checkpatch warning "WARNING: static const char * array should
probably be static const char * const"is ignored since it introduces a compilation warning.
Changes from v3:
* adapted the driver to extcon framework (so moved to drivers/extcon)
* removed palmas_usb_(write/read) and replaced all calls with palmas_(read/write).
* ignored a checkpatch warning in the line

	static const char *palmas_extcon_cable[] = {

as it seemed to be incorrect?
* removed all references to OMAP in this driver.
* couldn't test this driver with mainline as omap5 panda is not booting with mainline.
* A comment to change to platform_get_irq from regmap is not done as I felt the data should come from regmap in this case. Graeme?
Changes from v2:
* Moved the driver to drivers/usb/phy/
* Added a bit more explanation in Kconfig

 .../devicetree/bindings/extcon/extcon-twl.txt      |  16 +
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-palmas.c                     | 341 +++++++++++++++++++++
 include/linux/mfd/palmas.h                         |  25 +-
 5 files changed, 380 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-twl.txt
 create mode 100644 drivers/extcon/extcon-palmas.c
Documentation/devicetree/bindings/extcon/extcon-twl.txt new file +15 -0
new file mode 100644
index 0000000..8ffdeed
@@ -0,0 +1,15 @@
+EXTCON FOR TWL CHIPS
+
+PALMAS USB COMPARATOR
+Required Properties:
+ - compatible : Should be "ti,palmas-usb" or "ti,twl6035-usb"
+ - vbus-supply : phandle to the regulator device tree node.
+
+Optional Properties:
+ - ti,wakeup : To enable the wakeup comparator in probe
+
+palmas-usb {
+       compatible = "ti,twl6035-usb", "ti,palmas-usb";
+       vbus-supply = <&smps10_reg>;
+       ti,wakeup;
+};
drivers/extcon/Kconfig +7 -0
index 3297301..63f454e 100644
@@ -53,4 +53,11 @@ config EXTCON_ARIZONA
 	  with Wolfson Arizona devices. These are audio CODECs with
 	  advanced audio accessory detection support.
 
+config EXTCON_PALMAS
+	tristate "Palmas USB EXTCON support"
+	depends on MFD_PALMAS
+	help
+	  Say Y here to enable support for USB peripheral and USB host
+	  detection by palmas usb.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index f98a3c4..540e2c3 100644
@@ -8,3 +8,4 @@ obj-$(CONFIG_EXTCON_ADC_JACK)	+= extcon-adc-jack.o
 obj-$(CONFIG_EXTCON_MAX77693)	+= extcon-max77693.o
 obj-$(CONFIG_EXTCON_MAX8997)	+= extcon-max8997.o
 obj-$(CONFIG_EXTCON_ARIZONA)	+= extcon-arizona.o
+obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
drivers/extcon/extcon-palmas.c new file +341 -0

341 lines not on this page · raw message

include/linux/mfd/palmas.h +15 -10
index 6df375d..eb4846b 100644
@@ -20,6 +20,8 @@
 #include <linux/leds.h>
 #include <linux/regmap.h>
 #include <linux/regulator/driver.h>
+#include <linux/extcon.h>
+#include <linux/usb/phy_companion.h>
 
 #define PALMAS_NUM_CLIENTS		3
 
@@ -37,6 +39,12 @@ struct palmas_gpadc;
 struct palmas_resource;
 struct palmas_usb;
 
+enum palmas_usb_state {
+	PALMAS_USB_STATE_DISCONNECT,
+	PALMAS_USB_STATE_VBUS,
+	PALMAS_USB_STATE_ID,
+};
+
 struct palmas {
 	struct device *dev;
 
@@ -180,9 +188,6 @@ struct palmas_pmic_platform_data {
 };
 
 struct palmas_usb_platform_data {
-	/* Set this if platform wishes its own vbus control */
-	int no_control_vbus;
-
 	/* Do we enable the wakeup comparator on probe */
 	int wakeup;
 };
@@ -350,22 +355,22 @@ struct palmas_usb {
 	struct palmas *palmas;
 	struct device *dev;
 
-	/* for vbus reporting with irqs disabled */
-	spinlock_t lock;
+	struct extcon_dev edev;
+	struct phy_companion comparator;
 
 	struct regulator *vbus_reg;
 
 	/* used to set vbus, in atomic path */
 	struct work_struct set_vbus_work;
 
-	int irq1;
-	int irq2;
-	int irq3;
-	int irq4;
+	int id_otg_irq;
+	int id_irq;
+	int vbus_otg_irq;
+	int vbus_irq;
 
 	int vbus_enable;
 
-	u8 linkstat;
+	enum palmas_usb_state linkstat;
 };
 
 #define comparator_to_palmas(x) container_of((x), struct palmas_usb, comparator)
Signature · 1 line
1.8.1.2
#5 lore raw

Re: [PATCH v5 2/3] extcon: Palmas Extcon Driver

Hi Graeme/Kishon,

Quoted 5 lines · Kishon Vijay Abraham I

From: Graeme Gregory <[email protected]>

This is the driver for the USB comparator built into the palmas chip. It handles the various USB OTG events that can be generated by cable insertion/removal.

I have following feedback on this driver to use this on Tegra platform:
1. Can we have very simple driver for detecting VBUS and ID and just generate notification. No VBUS control logic or lots of USB related configurations?
2. We will need the VBUS control as optional if it is require for TI platform. Currently it is mandatory and hence it is not suite in our context.
3. There is VBUS control (enabled/disable) in VBUS detection also. When palma detect the VBUS then why actually it need to enable VBUS as VBUS is already supplied by HOST? It may be only need when palma detect the ID pin and maybe want to enable VBUS but again VBUS control (enable/disable) should be part of USB driver, out of extcon driver.

maintainer
#6 lore raw

Re: [PATCH v5 2/3] extcon: Palmas Extcon Driver

In reply to Kishon Vijay Abraham I

Hi Kishon,

I have some comment about this patch
and upload modified patch to following repository (extcon-for-palmas).
- http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/commit/?h=extcon-for-palmas&id=f2b7cb80699cbe1a5fd6c97ef2c600915f8d7f2c

This patchset include patch related to other module
,so I need your opinion to apply this patchset to git repository.

Quoted 73 lines · Kishon Vijay Abraham I

From: Graeme Gregory <[email protected]>

This is the driver for the USB comparator built into the palmas chip. It handles the various USB OTG events that can be generated by cable insertion/removal.

---
Changes from v4:
* removed no_control_vbus property (to be used if the platform wants to use its own vbus control.
* removed unnecessary headers
* moved the palmas_usb_state to palmas.h
* misc cleanups
*A checkpatch warning "WARNING: static const char * array should
probably be static const char * const"is ignored since it introduces a compilation warning.
Changes from v3:
* adapted the driver to extcon framework (so moved to drivers/extcon)
* removed palmas_usb_(write/read) and replaced all calls with palmas_(read/write).
* ignored a checkpatch warning in the line

	static const char *palmas_extcon_cable[] = {

as it seemed to be incorrect?
* removed all references to OMAP in this driver.
* couldn't test this driver with mainline as omap5 panda is not booting with mainline.
* A comment to change to platform_get_irq from regmap is not done as I felt the data should come from regmap in this case. Graeme?
Changes from v2:
* Moved the driver to drivers/usb/phy/
* Added a bit more explanation in Kconfig

 .../devicetree/bindings/extcon/extcon-twl.txt      |  16 +
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-palmas.c                     | 341 +++++++++++++++++++++
 include/linux/mfd/palmas.h                         |  25 +-
 5 files changed, 380 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-twl.txt
 create mode 100644 drivers/extcon/extcon-palmas.c
Documentation/devicetree/bindings/extcon/extcon-twl.txt new file +15 -0
new file mode 100644
index 0000000..8ffdeed
@@ -0,0 +1,15 @@
+EXTCON FOR TWL CHIPS
+
+PALMAS USB COMPARATOR
+Required Properties:
+ - compatible : Should be "ti,palmas-usb" or "ti,twl6035-usb"
+ - vbus-supply : phandle to the regulator device tree node.
+
+Optional Properties:
+ - ti,wakeup : To enable the wakeup comparator in probe
+
+palmas-usb {
+       compatible = "ti,twl6035-usb", "ti,palmas-usb";
+       vbus-supply = <&smps10_reg>;
+       ti,wakeup;
+};
drivers/extcon/Kconfig +0 -0
index 3297301..63f454e 100644

drivers/extcon/Kconfig config EXTCON_ARIZONA · line 58

Quoted 6 lines
drivers/extcon/Kconfig +3 -0
@@ -53,4 +53,11 @@ config EXTCON_ARIZONA
 	  with Wolfson Arizona devices. These are audio CODECs with
 	  advanced audio accessory detection support.
 
+config EXTCON_PALMAS
+	tristate "Palmas USB EXTCON support"
+	depends on MFD_PALMAS

You should add REGULATOR_PALMAS dependency because palmas_set_switch_smps10() is defined in palmas regulator driver.

+ depends on MFD_PALMAS && REGULATOR_PALMAS

Quoted 75 lines
drivers/extcon/Kconfig +4 -0
+	help
+	  Say Y here to enable support for USB peripheral and USB host
+	  detection by palmas usb.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index f98a3c4..540e2c3 100644
@@ -8,3 +8,4 @@ obj-$(CONFIG_EXTCON_ADC_JACK)	+= extcon-adc-jack.o
 obj-$(CONFIG_EXTCON_MAX77693)	+= extcon-max77693.o
 obj-$(CONFIG_EXTCON_MAX8997)	+= extcon-max8997.o
 obj-$(CONFIG_EXTCON_ARIZONA)	+= extcon-arizona.o
+obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
drivers/extcon/extcon-palmas.c new file +55 -0
new file mode 100644
index 0000000..9e613e9
@@ -0,0 +1,341 @@
+/*
+ * Palmas USB transceiver driver
+ *
+ * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.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.
+ *
+ * Author: Graeme Gregory <[email protected]>
+ * Author: Kishon Vijay Abraham I <[email protected]>
+ *
+ * Based on twl6030_usb.c
+ *
+ * Author: Hema HK <[email protected]>
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/usb/phy_companion.h>
+#include <linux/err.h>
+#include <linux/mfd/palmas.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+
+static const char *palmas_extcon_cable[] = {
+	[0] = "USB",
+	[1] = "USB-HOST",
+	NULL,
+};
+
+static const int mutually_exclusive[] = {0x3, 0x0};
+
+static void palmas_usb_wakeup(struct palmas *palmas, int enable)
+{
+	if (enable)
+		palmas_write(palmas, PALMAS_USB_OTG_BASE, PALMAS_USB_WAKEUP,
+			PALMAS_USB_WAKEUP_ID_WK_UP_COMP);
+	else
+		palmas_write(palmas, PALMAS_USB_OTG_BASE, PALMAS_USB_WAKEUP, 0);
+}
+
+static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
+{
+	int ret;
+	struct palmas_usb *palmas_usb = _palmas_usb;
+	unsigned int vbus_line_state;
+
+	palmas_read(palmas_usb->palmas, PALMAS_INTERRUPT_BASE,

drivers/extcon/extcon-palmas.c line 65

Quoted 10 lines
drivers/extcon/extcon-palmas.c new file +10 -0
+		PALMAS_INT3_LINE_STATE, &vbus_line_state);
+
+	if (vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS) {
+		if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) {
+			if (palmas_usb->vbus_reg) {
+				ret = regulator_enable(palmas_usb->vbus_reg);
+				if (ret) {
+					dev_dbg(palmas_usb->dev,
+						"regulator enable failed\n");
+					goto ret0;

I prefer to use consistent name of goto statement becuase you use 'fail_' prefix in palmas_usb_probe()
- goto ret0;
+ goto fail;

Quoted 11 lines
drivers/extcon/extcon-palmas.c new file +11 -0
+				}
+			}
+			palmas_usb->linkstat = PALMAS_USB_STATE_VBUS;
+			extcon_set_cable_state(&palmas_usb->edev, "USB", true);
+		} else {
+			dev_dbg(palmas_usb->dev,
+				"Spurious connect event detected\n");
+		}
+	} else if (!(vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS)) {
+		if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) {
+			if (palmas_usb->vbus_reg)

drivers/extcon/extcon-palmas.c line 86

Quoted 10 lines
drivers/extcon/extcon-palmas.c new file +10 -0
+				regulator_disable(palmas_usb->vbus_reg);
+			palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
+			extcon_set_cable_state(&palmas_usb->edev, "USB", false);
+		} else {
+			dev_dbg(palmas_usb->dev,
+				"Spurious disconnect event detected\n");
+		}
+	}
+
+ret0:

ditto.

-ret0:
+fail:

drivers/extcon/extcon-palmas.c line 94

Quoted 8 lines
drivers/extcon/extcon-palmas.c new file +8 -0
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
+{
+	int			ret;
+	unsigned int		set;
+	struct palmas_usb	*palmas_usb = _palmas_usb;

You should use space instead of tab when defined local variables.

+    int ret;
+    unsigned int set;
+    struct palmas_usb *palmas_usb = _palmas_usb;

drivers/extcon/extcon-palmas.c line 106

Quoted 12 lines
drivers/extcon/extcon-palmas.c new file +12 -0
+
+	palmas_read(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
+		PALMAS_USB_ID_INT_LATCH_SET, &set);
+
+	if (set & PALMAS_USB_ID_INT_SRC_ID_GND) {
+		palmas_set_switch_smps10(palmas_usb->palmas, 1);
+		if (palmas_usb->vbus_reg) {
+			ret = regulator_enable(palmas_usb->vbus_reg);
+			if (ret) {
+				dev_dbg(palmas_usb->dev,
+					"regulator enable failed\n");
+				goto ret0;

ditto.

Quoted 21 lines
drivers/extcon/extcon-palmas.c new file +21 -0
+			}
+		}
+		palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
+			PALMAS_USB_ID_INT_EN_HI_SET,
+			PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT);
+		palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
+			PALMAS_USB_ID_INT_EN_HI_CLR,
+			PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
+		palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
+			PALMAS_USB_ID_INT_LATCH_CLR,
+			PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
+		palmas_usb->linkstat = PALMAS_USB_STATE_ID;
+		extcon_set_cable_state(&palmas_usb->edev, "USB-HOST", true);
+	} else if (set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) {
+		palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
+			PALMAS_USB_ID_INT_EN_HI_SET,
+			PALMAS_USB_ID_INT_EN_HI_SET_ID_GND);
+		palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
+			PALMAS_USB_ID_INT_EN_HI_CLR,
+			PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
+		palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,

drivers/extcon/extcon-palmas.c line 137

Quoted 10 lines
drivers/extcon/extcon-palmas.c new file +10 -0
+			PALMAS_USB_ID_INT_LATCH_CLR,
+			PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
+		if (palmas_usb->vbus_reg)
+			regulator_disable(palmas_usb->vbus_reg);
+		palmas_set_switch_smps10(palmas_usb->palmas, 0);
+		palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
+		extcon_set_cable_state(&palmas_usb->edev, "USB-HOST", false);
+	}
+
+ret0:

ditto.

Quoted 84 lines
drivers/extcon/extcon-palmas.c new file +84 -0
+	return IRQ_HANDLED;
+}
+
+static void palmas_enable_irq(struct palmas_usb *palmas_usb)
+{
+	palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
+		PALMAS_USB_VBUS_CTRL_SET,
+		PALMAS_USB_VBUS_CTRL_SET_VBUS_ACT_COMP);
+
+	palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
+		PALMAS_USB_ID_CTRL_SET, PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP);
+
+	palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
+		PALMAS_USB_ID_INT_EN_HI_SET,
+		PALMAS_USB_ID_INT_EN_HI_SET_ID_GND);
+
+	palmas_vbus_irq_handler(palmas_usb->vbus_irq, palmas_usb);
+
+	/* cold plug for host mode needs this delay */
+	msleep(30);
+	palmas_id_irq_handler(palmas_usb->id_irq, palmas_usb);
+}
+
+static void palmas_set_vbus_work(struct work_struct *data)
+{
+	int ret;
+	struct palmas_usb *palmas_usb = container_of(data, struct palmas_usb,
+								set_vbus_work);
+
+	/*
+	 * Start driving VBUS. Set OPA_MODE bit in CHARGERUSB_CTRL1
+	 * register. This enables boost mode.
+	 */
+
+	if (palmas_usb->vbus_enable) {
+		ret = regulator_enable(palmas_usb->vbus_reg);
+		if (ret)
+			dev_dbg(palmas_usb->dev, "regulator enable failed\n");
+	} else {
+		regulator_disable(palmas_usb->vbus_reg);
+	}
+}
+
+static int palmas_set_vbus(struct phy_companion *comparator, bool enabled)
+{
+	struct palmas_usb *palmas_usb = comparator_to_palmas(comparator);
+
+	palmas_usb->vbus_enable = enabled;
+	schedule_work(&palmas_usb->set_vbus_work);
+
+	return 0;
+}
+
+static int palmas_start_srp(struct phy_companion *comparator)
+{
+	struct palmas_usb *palmas_usb = comparator_to_palmas(comparator);
+
+	palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
+		PALMAS_USB_VBUS_CTRL_SET, PALMAS_USB_VBUS_CTRL_SET_VBUS_DISCHRG
+		| PALMAS_USB_VBUS_CTRL_SET_VBUS_IADP_SINK);
+	palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
+		PALMAS_USB_VBUS_CTRL_SET,
+		PALMAS_USB_VBUS_CTRL_SET_VBUS_CHRG_VSYS |
+		PALMAS_USB_VBUS_CTRL_SET_VBUS_IADP_SINK);
+
+	msleep(100);
+
+	palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
+		PALMAS_USB_VBUS_CTRL_CLR,
+		PALMAS_USB_VBUS_CTRL_SET_VBUS_CHRG_VSYS |
+		PALMAS_USB_VBUS_CTRL_SET_VBUS_CHRG_VSYS);
+
+	return 0;
+}
+
+static int palmas_usb_probe(struct platform_device *pdev)
+{
+	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
+	struct palmas_usb_platform_data	*pdata = pdev->dev.platform_data;
+	struct device_node *node = pdev->dev.of_node;
+	struct palmas_usb *palmas_usb;
+	int status;
+
+	if (node && !pdata) {

drivers/extcon/extcon-palmas.c line 231

Quoted 10 lines
drivers/extcon/extcon-palmas.c new file +10 -0
+		pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+
+		if (!pdata)
+			return -ENOMEM;
+
+		pdata->wakeup = of_property_read_bool(node, "ti,wakeup");
+	}
+
+	if (!pdata)
+		return -EINVAL;

I think that if condition of first if statement is true, second if statement is unnecessary. So, I prefer to modify if/else statement as following:

+	} else if (!pdata) {
		return -EINVAL;

+ }

drivers/extcon/extcon-palmas.c line 240

Quoted 9 lines
drivers/extcon/extcon-palmas.c new file +9 -0
+
+	palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL);
+	if (!palmas_usb)
+		return -ENOMEM;
+
+	palmas->usb		= palmas_usb;
+	palmas_usb->palmas	= palmas;
+
+	palmas_usb->dev		= &pdev->dev;

You should use space instead of tab when assign some value to variables.

+ palmas->usb = palmas_usb;
+ palmas_usb->palmas = palmas;
+
+ palmas_usb->dev= &pdev->dev;

Quoted 167 lines
drivers/extcon/extcon-palmas.c new file +101 -0
+
+	palmas_usb->id_otg_irq = regmap_irq_get_virq(palmas->irq_data,
+						PALMAS_ID_OTG_IRQ);
+	palmas_usb->id_irq = regmap_irq_get_virq(palmas->irq_data,
+						PALMAS_ID_IRQ);
+	palmas_usb->vbus_otg_irq = regmap_irq_get_virq(palmas->irq_data,
+						PALMAS_VBUS_OTG_IRQ);
+	palmas_usb->vbus_irq = regmap_irq_get_virq(palmas->irq_data,
+						PALMAS_VBUS_IRQ);
+
+	palmas_usb->comparator.set_vbus	= palmas_set_vbus;
+	palmas_usb->comparator.start_srp = palmas_start_srp;
+
+	palmas_usb_wakeup(palmas, pdata->wakeup);
+
+	palmas_usb->vbus_reg = devm_regulator_get(&pdev->dev, "vbus");
+	if (IS_ERR(palmas_usb->vbus_reg)) {
+		dev_err(&pdev->dev, "vbus init failed\n");
+		return PTR_ERR(palmas_usb->vbus_reg);
+	}
+
+	INIT_WORK(&palmas_usb->set_vbus_work, palmas_set_vbus_work);
+
+	platform_set_drvdata(pdev, palmas_usb);
+
+	palmas_usb->edev.name = "palmas-usb";
+	palmas_usb->edev.supported_cable = palmas_extcon_cable;
+	palmas_usb->edev.mutually_exclusive = mutually_exclusive;
+
+	status = extcon_dev_register(&palmas_usb->edev, palmas_usb->dev);
+	if (status) {
+		dev_err(&pdev->dev, "failed to register extcon device\n");
+		goto fail_irq;
+	}
+
+	status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->id_irq,
+			NULL, palmas_id_irq_handler,
+			IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
+			"palmas_usb_id", palmas_usb);
+	if (status < 0) {
+		dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
+					palmas_usb->id_irq, status);
+		goto fail_extcon;
+	}
+
+	status = devm_request_threaded_irq(palmas_usb->dev,
+			palmas_usb->vbus_irq, NULL, palmas_vbus_irq_handler,
+			IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
+			"palmas_usb_vbus", palmas_usb);
+	if (status < 0) {
+		dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
+					palmas_usb->vbus_irq, status);
+		goto fail_extcon;
+	}
+
+	palmas_enable_irq(palmas_usb);
+
+	return 0;
+
+fail_extcon:
+	extcon_dev_unregister(&palmas_usb->edev);
+
+fail_irq:
+	cancel_work_sync(&palmas_usb->set_vbus_work);
+
+	return status;
+}
+
+static int palmas_usb_remove(struct platform_device *pdev)
+{
+	struct palmas_usb *palmas_usb = platform_get_drvdata(pdev);
+
+		cancel_work_sync(&palmas_usb->set_vbus_work);
+	extcon_dev_unregister(&palmas_usb->edev);
+
+	return 0;
+}
+
+static struct of_device_id of_palmas_match_tbl[] = {
+	{ .compatible = "ti,palmas-usb", },
+	{ .compatible = "ti,twl6035-usb", },
+	{ /* end */ }
+};
+
+static struct platform_driver palmas_usb_driver = {
+	.probe = palmas_usb_probe,
+	.remove = palmas_usb_remove,
+	.driver = {
+		.name = "palmas-usb",
+		.of_match_table = of_palmas_match_tbl,
+		.owner = THIS_MODULE,
+	},
+};
+
+module_platform_driver(palmas_usb_driver);
+
+MODULE_ALIAS("platform:palmas-usb");
+MODULE_AUTHOR("Graeme Gregory <[email protected]>");
+MODULE_DESCRIPTION("Palmas USB transceiver driver");
+MODULE_LICENSE("GPL");
+MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);
include/linux/mfd/palmas.h +15 -10
index 6df375d..eb4846b 100644
@@ -20,6 +20,8 @@
 #include <linux/leds.h>
 #include <linux/regmap.h>
 #include <linux/regulator/driver.h>
+#include <linux/extcon.h>
+#include <linux/usb/phy_companion.h>
 
 #define PALMAS_NUM_CLIENTS		3
 
@@ -37,6 +39,12 @@ struct palmas_gpadc;
 struct palmas_resource;
 struct palmas_usb;
 
+enum palmas_usb_state {
+	PALMAS_USB_STATE_DISCONNECT,
+	PALMAS_USB_STATE_VBUS,
+	PALMAS_USB_STATE_ID,
+};
+
 struct palmas {
 	struct device *dev;
 
@@ -180,9 +188,6 @@ struct palmas_pmic_platform_data {
 };
 
 struct palmas_usb_platform_data {
-	/* Set this if platform wishes its own vbus control */
-	int no_control_vbus;
-
 	/* Do we enable the wakeup comparator on probe */
 	int wakeup;
 };
@@ -350,22 +355,22 @@ struct palmas_usb {
 	struct palmas *palmas;
 	struct device *dev;
 
-	/* for vbus reporting with irqs disabled */
-	spinlock_t lock;
+	struct extcon_dev edev;
+	struct phy_companion comparator;
 
 	struct regulator *vbus_reg;
 
 	/* used to set vbus, in atomic path */
 	struct work_struct set_vbus_work;
 
-	int irq1;
-	int irq2;
-	int irq3;
-	int irq4;
+	int id_otg_irq;
+	int id_irq;
+	int vbus_otg_irq;
+	int vbus_irq;
 
 	int vbus_enable;
 
-	u8 linkstat;
+	enum palmas_usb_state linkstat;
 };
 
 #define comparator_to_palmas(x) container_of((x), struct palmas_usb, comparator)
#7 lore raw

Re: [PATCH v5 2/3] extcon: Palmas Extcon Driver

Hi,

Quoted 8 lines · Chanwoo Choi

Hi Kishon,

I have some comment about this patch
and upload modified patch to following repository (extcon-for-palmas).
- http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/commit/?h=extcon-for-palmas&id=f2b7cb80699cbe1a5fd6c97ef2c600915f8d7f2c

This patchset include patch related to other module
,so I need your opinion to apply this patchset to git repository.

yeah.. Still there is some confusion with palmas_set_switch_smps10(). I think we can remove it for now and add it separately later. By this at least we can have device mode fully functional in OMAP5. What do you think?

Thanks
Kishon

maintainer
#8 lore raw

Re: [PATCH v5 2/3] extcon: Palmas Extcon Driver

Quoted 5 lines · Kishon Vijay Abraham I

Hi,

Quoted 2 lines · Chanwoo Choi

Hi Kishon,

Quoted 9 lines
Quoted 6 lines

I have some comment about this patch
and upload modified patch to following repository (extcon-for-palmas).
- http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/commit/?h=extcon-for-palmas&id=f2b7cb80699cbe1a5fd6c97ef2c600915f8d7f2c

This patchset include patch related to other module
,so I need your opinion to apply this patchset to git repository.

yeah.. Still there is some confusion with palmas_set_switch_smps10(). I think we can remove it for now and add it separately later. By this at least we can have device mode fully functional in OMAP5. What do you think?

I agree your opinion.

But, I propose some fixes about palmas_set_switch_smps10().
I dont' prefer to call global function in exton-palmas.c from palmas-regulator.c. So, Why don't you use regulator consumer instead of global function? You can register specific regulator for enabling or disabling SMPS10_SWITCH_EN and then control SMPS10_SWITCH_EN bit through regulator framework in extcon-palmas.c without calling global function.

Thanks,
Chanwoo Choi

#9 lore raw

Re: [PATCH v5 2/3] extcon: Palmas Extcon Driver

Quoted 14 lines · Chanwoo Choi
Quoted 5 lines · Kishon Vijay Abraham I

Hi,

Quoted 2 lines · Chanwoo Choi

Hi Kishon,

Quoted 8 lines
Quoted 6 lines

I have some comment about this patch
and upload modified patch to following repository (extcon-for-palmas).
- http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/commit/?h=extcon-for-palmas&id=f2b7cb80699cbe1a5fd6c97ef2c600915f8d7f2c

This patchset include patch related to other module
,so I need your opinion to apply this patchset to git repository.

yeah.. Still there is some confusion with palmas_set_switch_smps10(). I think we can remove it for now and add it separately later. By this at least we can have device mode fully functional in OMAP5. What do you think?

Quoted 8 lines

I agree your opinion.

But, I propose some fixes about palmas_set_switch_smps10().
I dont' prefer to call global function in exton-palmas.c from palmas-regulator.c. So, Why don't you use regulator consumer instead of global function? You can register specific regulator for enabling or disabling SMPS10_SWITCH_EN and then control SMPS10_SWITCH_EN bit through regulator framework in extcon-palmas.c without calling global function.

Along with this, I also like to make the VBUS regulator control to be optional here. Currently it is mandatory.

#10 lore raw

Re: [PATCH v5 2/3] extcon: Palmas Extcon Driver

Hi,

Quoted 32 lines · Laxman Dewangan
Quoted 21 lines · Chanwoo Choi
Quoted 11 lines · Kishon Vijay Abraham I

Hi,

Quoted 8 lines · Chanwoo Choi

Hi Kishon,

I have some comment about this patch
and upload modified patch to following repository (extcon-for-palmas). -
http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/commit/?h=extcon-for-palmas&id=f2b7cb80699cbe1a5fd6c97ef2c600915f8d7f2c

Quoted 7 lines
Quoted 2 lines

This patchset include patch related to other module
,so I need your opinion to apply this patchset to git repository.

yeah.. Still there is some confusion with palmas_set_switch_smps10(). I think we can remove it for now and add it separately later. By this at least we can have device mode fully functional in OMAP5. What do you think?

I agree your opinion.

Quoted 9 lines

But, I propose some fixes about palmas_set_switch_smps10(). I dont' prefer to call global function in exton-palmas.c from palmas-regulator.c.
So, Why don't you use regulator consumer instead of global function? You can register specific regulator for enabling or disabling SMPS10_SWITCH_EN
and then control SMPS10_SWITCH_EN bit through regulator framework in extcon-palmas.c
without calling global function.

Quoted 2 lines

Along with this, I also like to make the VBUS regulator control to be optional here. Currently it is mandatory.

But dint you just tell on my v4 of this patch that you don’t require this.
http://www.spinics.net/lists/linux-doc/msg10638.html

Thanks
Kishon

#11 lore raw

Re: [PATCH v5 2/3] extcon: Palmas Extcon Driver

Quoted 34 lines · Kishon Vijay Abraham I

Hi,

Quoted 31 lines · Laxman Dewangan
Quoted 30 lines · Chanwoo Choi
Quoted 11 lines · Kishon Vijay Abraham I

Hi,

Quoted 8 lines · Chanwoo Choi

Hi Kishon,

I have some comment about this patch
and upload modified patch to following repository (extcon-for-palmas). -
http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/commit/?h=extcon-for-palmas&id=f2b7cb80699cbe1a5fd6c97ef2c600915f8d7f2c

Quoted 7 lines
Quoted 2 lines

This patchset include patch related to other module
,so I need your opinion to apply this patchset to git repository.

yeah.. Still there is some confusion with palmas_set_switch_smps10(). I think we can remove it for now and add it separately later. By this at least we can have device mode fully functional in OMAP5. What do you think?

I agree your opinion.

But, I propose some fixes about palmas_set_switch_smps10(). I dont' prefer to call global function in exton-palmas.c from palmas-regulator.c.
So, Why don't you use regulator consumer instead of global function? You can register specific regulator for enabling or disabling SMPS10_SWITCH_EN
and then control SMPS10_SWITCH_EN bit through regulator framework in extcon-palmas.c
without calling global function.

Quoted 4 lines
Quoted 2 lines

Along with this, I also like to make the VBUS regulator control to be optional here. Currently it is mandatory.

But dint you just tell on my v4 of this patch that you don’t require this.
http://www.spinics.net/lists/linux-doc/msg10638.html

In V4, I said remove this VBUS control and my mean was to remove all regulator calls for VBUS enabled/disable. I saw you just remove the platform data option to have this control and made VBUS mandatory.

Probably some gap here.

In tegra platform, we dont need VBUS regualtor control from extcon.

#12 lore raw

Re: [PATCH v5 2/3] extcon: Palmas Extcon Driver

Hi,

Quoted 43 lines · Laxman Dewangan
Quoted 36 lines · Kishon Vijay Abraham I

Hi,

Quoted 33 lines · Laxman Dewangan
Quoted 32 lines · Chanwoo Choi
Quoted 13 lines · Kishon Vijay Abraham I

Hi,

Quoted 10 lines · Chanwoo Choi

Hi Kishon,

I have some comment about this patch
and upload modified patch to following repository
(extcon-for-palmas).
-
http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/commit/?h=extcon-for-palmas&id=f2b7cb80699cbe1a5fd6c97ef2c600915f8d7f2c

Quoted 7 lines
Quoted 2 lines

This patchset include patch related to other module
,so I need your opinion to apply this patchset to git repository.

yeah.. Still there is some confusion with palmas_set_switch_smps10(). I think we can remove it for now and add it separately later. By this at least we can have device mode fully functional in OMAP5. What do you think?

I agree your opinion.

But, I propose some fixes about palmas_set_switch_smps10(). I dont' prefer to call global function in exton-palmas.c from palmas-regulator.c.
So, Why don't you use regulator consumer instead of global function? You can register specific regulator for enabling or disabling SMPS10_SWITCH_EN
and then control SMPS10_SWITCH_EN bit through regulator framework in extcon-palmas.c
without calling global function.

Quoted 5 lines
Quoted 2 lines

Along with this, I also like to make the VBUS regulator control to be optional here. Currently it is mandatory.

But dint you just tell on my v4 of this patch that you don’t require this.
http://www.spinics.net/lists/linux-doc/msg10638.html

Quoted 6 lines

In V4, I said remove this VBUS control and my mean was to remove all regulator calls for VBUS enabled/disable.
I saw you just remove the platform data option to have this control and made VBUS mandatory.

Probably some gap here.

Indeed..
I think then we should stick back to how it was with my v4 or else it would break OMAP. The regulator calls can't be moved anywhere else as it is specific to PALMAS.

Thanks
Kishon

#13 lore raw

Re: [PATCH v5 2/3] extcon: Palmas Extcon Driver

Quoted 50 lines · Kishon Vijay Abraham I

Hi,

Quoted 47 lines · Laxman Dewangan
Quoted 36 lines · Kishon Vijay Abraham I

Hi,

Quoted 33 lines · Laxman Dewangan
Quoted 32 lines · Chanwoo Choi
Quoted 13 lines · Kishon Vijay Abraham I

Hi,

Quoted 10 lines · Chanwoo Choi

Hi Kishon,

I have some comment about this patch
and upload modified patch to following repository
(extcon-for-palmas).
-
http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/commit/?h=extcon-for-palmas&id=f2b7cb80699cbe1a5fd6c97ef2c600915f8d7f2c

Quoted 7 lines
Quoted 2 lines

This patchset include patch related to other module
,so I need your opinion to apply this patchset to git repository.

yeah.. Still there is some confusion with palmas_set_switch_smps10(). I think we can remove it for now and add it separately later. By this at least we can have device mode fully functional in OMAP5. What do you think?

I agree your opinion.

But, I propose some fixes about palmas_set_switch_smps10(). I dont' prefer to call global function in exton-palmas.c from palmas-regulator.c.
So, Why don't you use regulator consumer instead of global function? You can register specific regulator for enabling or disabling SMPS10_SWITCH_EN
and then control SMPS10_SWITCH_EN bit through regulator framework in extcon-palmas.c
without calling global function.

Quoted 5 lines
Quoted 2 lines

Along with this, I also like to make the VBUS regulator control to be optional here. Currently it is mandatory.

But dint you just tell on my v4 of this patch that you don’t require this.
http://www.spinics.net/lists/linux-doc/msg10638.html

In V4, I said remove this VBUS control and my mean was to remove all regulator calls for VBUS enabled/disable.
I saw you just remove the platform data option to have this control and made VBUS mandatory.

Quoted 6 lines
Quoted 1 line

Probably some gap here.

Indeed..
I think then we should stick back to how it was with my v4 or else it would break OMAP. The regulator calls can't be moved anywhere else as it is specific to PALMAS.

I was thinking that extcon driver just detect the cable type and notify to the client. After cable detection, the next level of configuration should be done in the respective client.

On Tegra platform, for ID pin detection, Tegra SOC is capable of detect the ID pin presence or Palma is capable. Depending on the board design, how the ID pin routed from USB connector to PMIC or to Tegra, we enable corresponding detection logic. Once the USB driver got notification for ID pin presence (by any means), the enabling of VBUS (as the Tegra will work as Host now and need to supply VBUS), is done in USB driver.
Not sure about the OMAP here.

So in above context, I really do not want to have the VBUS control on extcon driver from Tegra context. If it is require in OMAP context then please make it as optional so that we can satisfy for Tegra and Omap platform.

#14 lore raw

Re: [PATCH v5 2/3] extcon: Palmas Extcon Driver

Hi,

Quoted 65 lines · Laxman Dewangan
Quoted 53 lines · Kishon Vijay Abraham I

Hi,

Quoted 50 lines · Laxman Dewangan
Quoted 39 lines · Kishon Vijay Abraham I

Hi,

Quoted 36 lines · Laxman Dewangan
Quoted 35 lines · Chanwoo Choi
Quoted 14 lines · Kishon Vijay Abraham I

Hi,

Quoted 11 lines · Chanwoo Choi

Hi Kishon,

I have some comment about this patch
and upload modified patch to following repository
(extcon-for-palmas).
-
http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/commit/?h=extcon-for-palmas&id=f2b7cb80699cbe1a5fd6c97ef2c600915f8d7f2c

Quoted 9 lines
Quoted 2 lines

This patchset include patch related to other module
,so I need your opinion to apply this patchset to git repository.

yeah.. Still there is some confusion with palmas_set_switch_smps10().
I think we can remove it for now and add it separately later. By this
at least we can have device mode fully functional in OMAP5. What do you think?

I agree your opinion.

But, I propose some fixes about palmas_set_switch_smps10(). I dont' prefer to call global function in exton-palmas.c from palmas-regulator.c.
So, Why don't you use regulator consumer instead of global function? You can register specific regulator for enabling or disabling SMPS10_SWITCH_EN
and then control SMPS10_SWITCH_EN bit through regulator framework in extcon-palmas.c
without calling global function.

Quoted 5 lines
Quoted 2 lines

Along with this, I also like to make the VBUS regulator control to be optional here. Currently it is mandatory.

But dint you just tell on my v4 of this patch that you don’t require this.
http://www.spinics.net/lists/linux-doc/msg10638.html

In V4, I said remove this VBUS control and my mean was to remove all regulator calls for VBUS enabled/disable.
I saw you just remove the platform data option to have this control and made VBUS mandatory.

Quoted 6 lines
Quoted 1 line

Probably some gap here.

Indeed..
I think then we should stick back to how it was with my v4 or else it would break OMAP. The regulator calls can't be moved anywhere else as it is specific to PALMAS.

I was thinking that extcon driver just detect the cable type and notify to the client. After cable detection, the next level of configuration should be done in the respective client.

Quoted 8 lines

On Tegra platform, for ID pin detection, Tegra SOC is capable of detect the ID pin presence or Palma is capable. Depending on the board design, how the ID pin routed from USB connector to PMIC or to Tegra, we enable corresponding detection logic.
Once the USB driver got notification for ID pin presence (by any means), the enabling of VBUS (as the Tegra will work as Host now and need to supply VBUS), is done in USB driver.
Not sure about the OMAP here.

I think I got your point here. Will check and send a patch.

Thanks
Kishon

#15 lore raw

PATCH 3/3 usb: dwc3: use extcon fwrk to receive connect/disconnect notification

In reply to Kishon Vijay Abraham I

Modified dwc3-omap to receive connect and disconnect notification using extcon framework. Also did the necessary cleanups required after adapting to extcon framework.

---
 drivers/usb/dwc3/dwc3-omap.c  | 80 +++++++++++++++++++++++++++++++++----------
 include/linux/usb/dwc3-omap.h | 30 ----------------
 2 files changed, 62 insertions(+), 48 deletions(-)
 delete mode 100644 include/linux/usb/dwc3-omap.h
drivers/usb/dwc3/dwc3-omap.c +62 -18
index 34638b9..771f936 100644
@@ -43,13 +43,13 @@
 #include <linux/spinlock.h>
 #include <linux/platform_device.h>
 #include <linux/platform_data/dwc3-omap.h>
-#include <linux/usb/dwc3-omap.h>
 #include <linux/pm_runtime.h>
 #include <linux/dma-mapping.h>
 #include <linux/ioport.h>
 #include <linux/io.h>
 #include <linux/of.h>
 #include <linux/of_platform.h>
+#include <linux/extcon.h>
 
 #include <linux/usb/otg.h>
 
@@ -124,9 +124,19 @@ struct dwc3_omap {
 	u32			utmi_otg_status;
 
 	u32			dma_status:1;
+
+	struct extcon_specific_cable_nb extcon_vbus_dev;
+	struct extcon_specific_cable_nb extcon_id_dev;
+	struct notifier_block	vbus_nb;
+	struct notifier_block	id_nb;
 };
 
-static struct dwc3_omap		*_omap;
+enum omap_dwc3_vbus_id_status {
+	OMAP_DWC3_ID_FLOAT,
+	OMAP_DWC3_ID_GROUND,
+	OMAP_DWC3_VBUS_OFF,
+	OMAP_DWC3_VBUS_VALID,
+};
 
 static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
 {
@@ -138,13 +148,10 @@ static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value)
 	writel(value, base + offset);
 }
 
-int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
+static void dwc3_omap_set_mailbox(struct dwc3_omap *omap,
+	enum omap_dwc3_vbus_id_status status)
 {
-	u32			val;
-	struct dwc3_omap	*omap = _omap;
-
-	if (!omap)
-		return -EPROBE_DEFER;
+	u32	val;
 
 	switch (status) {
 	case OMAP_DWC3_ID_GROUND:
@@ -185,12 +192,9 @@ int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
 		break;
 
 	default:
-		dev_dbg(omap->dev, "ID float\n");
+		dev_dbg(omap->dev, "invalid state\n");
 	}
-
-	return 0;
 }
-EXPORT_SYMBOL_GPL(dwc3_omap_mailbox);
 
 static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
 {
@@ -282,6 +286,32 @@ static void dwc3_omap_disable_irqs(struct dwc3_omap *omap)
 
 static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32);
 
+static int dwc3_omap_id_notifier(struct notifier_block *nb,
+	unsigned long event, void *ptr)
+{
+	struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, id_nb);
+
+	if (event)
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
+	else
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_FLOAT);
+
+	return NOTIFY_DONE;
+}
+
+static int dwc3_omap_vbus_notifier(struct notifier_block *nb,
+	unsigned long event, void *ptr)
+{
+	struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, vbus_nb);
+
+	if (event)
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
+	else
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_OFF);
+
+	return NOTIFY_DONE;
+}
+
 static int dwc3_omap_probe(struct platform_device *pdev)
 {
 	struct device_node	*node = pdev->dev.of_node;
@@ -289,6 +319,7 @@ static int dwc3_omap_probe(struct platform_device *pdev)
 	struct dwc3_omap	*omap;
 	struct resource		*res;
 	struct device		*dev = &pdev->dev;
+	struct extcon_dev	*edev;
 
 	int			ret = -ENOMEM;
 	int			irq;
@@ -330,19 +361,25 @@ static int dwc3_omap_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	}
 
+	edev = extcon_get_extcon_dev("palmas-usb");
+	if (!edev) {
+		dev_dbg(dev, "couldn't get extcon device\n");
+		return -EPROBE_DEFER;
+	}
+
 	spin_lock_init(&omap->lock);
 
 	omap->dev	= dev;
 	omap->irq	= irq;
 	omap->base	= base;
+	omap->vbus_nb.notifier_call = dwc3_omap_vbus_notifier;
+	extcon_register_interest(&omap->extcon_vbus_dev, "palmas-usb", "USB",
+		&omap->vbus_nb);
+	omap->id_nb.notifier_call = dwc3_omap_id_notifier;
+	extcon_register_interest(&omap->extcon_id_dev, "palmas-usb", "USB-HOST",
+		&omap->id_nb);
 	dev->dma_mask	= &dwc3_omap_dma_mask;
 
-	/*
-	 * REVISIT if we ever have two instances of the wrapper, we will be
-	 * in big trouble
-	 */
-	_omap	= omap;
-
 	pm_runtime_enable(dev);
 	ret = pm_runtime_get_sync(dev);
 	if (ret < 0) {
@@ -387,6 +424,11 @@ static int dwc3_omap_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	if (extcon_get_cable_state(edev, "USB") == true)
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
+	if (extcon_get_cable_state(edev, "USB-HOST") == true)
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
+
 	return 0;
 }
 
@@ -394,6 +436,8 @@ static int dwc3_omap_remove(struct platform_device *pdev)
 {
 	struct dwc3_omap	*omap = platform_get_drvdata(pdev);
 
+	extcon_unregister_interest(&omap->extcon_vbus_dev);
+	extcon_unregister_interest(&omap->extcon_id_dev);
 	dwc3_omap_disable_irqs(omap);
 	pm_runtime_put_sync(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
include/linux/usb/dwc3-omap.h deleted +0 -30
deleted file mode 100644
index 5615f4d..0000000
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2013 by Texas Instruments
- *
- * The Inventra Controller Driver for Linux is free software; you
- * can redistribute it and/or modify it under the terms of the GNU
- * General Public License version 2 as published by the Free Software
- * Foundation.
- */
-
-#ifndef __DWC3_OMAP_H__
-#define __DWC3_OMAP_H__
-
-enum omap_dwc3_vbus_id_status {
-	OMAP_DWC3_UNKNOWN = 0,
-	OMAP_DWC3_ID_GROUND,
-	OMAP_DWC3_ID_FLOAT,
-	OMAP_DWC3_VBUS_VALID,
-	OMAP_DWC3_VBUS_OFF,
-};
-
-#if (defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_DWC3_MODULE))
-extern int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status);
-#else
-static inline int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
-{
-	return -ENODEV;
-}
-#endif
-
-#endif	/* __DWC3_OMAP_H__ */
Signature · 1 line
1.8.1.2
maintainer Acked-by on v1 3/3
#16 lore raw

Re: [PATCH 3/3] usb: dwc3: use extcon fwrk to receive connect/disconnect notification

Quoted 4 lines · Kishon Vijay Abraham I

Modified dwc3-omap to receive connect and disconnect notification using extcon framework. Also did the necessary cleanups required after adapting to extcon framework.

Quoted 8 lines
---
 drivers/usb/dwc3/dwc3-omap.c  | 80 +++++++++++++++++++++++++++++++++----------
 include/linux/usb/dwc3-omap.h | 30 ----------------
 2 files changed, 62 insertions(+), 48 deletions(-)
 delete mode 100644 include/linux/usb/dwc3-omap.h

I check the code about extcon framework.

Thanks,
Chanwoo Choi

maintainer
#17 lore raw

Re: [PATCH 3/3] usb: dwc3: use extcon fwrk to receive connect/disconnect notification

In reply to Kishon Vijay Abraham I
Quoted 10 lines · Kishon Vijay Abraham I

Modified dwc3-omap to receive connect and disconnect notification using extcon framework. Also did the necessary cleanups required after adapting to extcon framework.

---
 drivers/usb/dwc3/dwc3-omap.c  | 80 +++++++++++++++++++++++++++++++++----------
 include/linux/usb/dwc3-omap.h | 30 ----------------
 2 files changed, 62 insertions(+), 48 deletions(-)
 delete mode 100644 include/linux/usb/dwc3-omap.h

Hi Kishon,

Thi patch is suspended until fix following build error.
(If kernel builds extcon fwr as module, dwc3-omap.c happen error message)

---

tree:   git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon extcon-next
head:   30f5d6ea2561c2a54e40b1e8e8f9bb30e064e01b
commit: 30f5d6ea2561c2a54e40b1e8e8f9bb30e064e01b [3/3] usb: dwc3: use extcon fwrk to receive connect/disconnect notification
config: i386-randconfig-x14-0530 (attached as .config)

All error/warnings:

drivers/built-in.o: In function `dwc3_omap_remove':
dwc3-omap.c:(.text+0x8c0fa): undefined reference to extcon_unregister_interest' dwc3-omap.c:(.text+0x8c102): undefined reference to extcon_unregister_interest' drivers/built-in.o: In function `dwc3_omap_probe':
dwc3-omap.c:(.text+0x8c5e6): undefined reference to extcon_get_extcon_dev' dwc3-omap.c:(.text+0x8c6a4): undefined reference to extcon_register_interest' dwc3-omap.c:(.text+0x8c6c9): undefined reference to extcon_register_interest' dwc3-omap.c:(.text+0x8c831): undefined reference to extcon_get_cable_state' dwc3-omap.c:(.text+0x8c851): undefined reference to `extcon_get_cable_state'
---

Also, I missed a issue of this patch. If h/w target use other USB device instead of "palmas-usb", dwc-omap.c driver won't be operating. So, I propose two method about this issue.
First, we can get extcon device name through platform data or dt. Two, When use extcon_register_interest() to register notifier block, NULL pointer pass to extcon_register_interest() instead of specific extcon device name(palmas-usb). If extcon_register_interest() check NULL pointer of extcon device name parameter, extcon fwr will find previous registered extcon device and then register notifier block of consumer device driver(dwc3-omap.c) to previous registered extcon device.

Quoted 10 lines
drivers/usb/dwc3/dwc3-omap.c +6 -0
+	edev = extcon_get_extcon_dev("palmas-usb");
+	if (!edev) {
+		dev_dbg(dev, "couldn't get extcon device\n");
+		return -EPROBE_DEFER;
+	}
+
 	spin_lock_init(&omap->lock);
 
 	omap->dev	= dev;
 	omap->irq	= irq;

drivers/usb/dwc3/dwc3-omap.c static int dwc3_omap_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/usb/dwc3/dwc3-omap.c +7 -0
 	omap->base	= base;
+	omap->vbus_nb.notifier_call = dwc3_omap_vbus_notifier;
+	extcon_register_interest(&omap->extcon_vbus_dev, "palmas-usb", "USB",
+		&omap->vbus_nb);
+	omap->id_nb.notifier_call = dwc3_omap_id_notifier;
+	extcon_register_interest(&omap->extcon_id_dev, "palmas-usb", "USB-HOST",
+		&omap->id_nb);
 	dev->dma_mask	= &dwc3_omap_dma_mask;
 
+

Thanks,
Chanwoo Choi

#18 lore raw

PATCH v6 1/1 extcon: Palmas Extcon Driver

In reply to Kishon Vijay Abraham I

From: Graeme Gregory <[email protected]>

This is the driver for the USB comparator built into the palmas chip. It handles the various USB OTG events that can be generated by cable insertion/removal.

---
Changes from v5:
* removed regulator calls from palmas-usb as some platforms wont need it. These are now done in dwc3-omap.c as it is needed for OMAP.
* removed all references to phy_companion as none of it is validated (SRP) and all of them were currently unreachable code.

Changes from v4:
* removed no_control_vbus property (to be used if the platform wants to use its own vbus control.
* removed unnecessary headers
* moved the palmas_usb_state to palmas.h
* misc cleanups
*A checkpatch warning "WARNING: static const char * array should
probably be static const char * const"is ignored since it introduces a compilation warning.

Changes from v3:
* adapted the driver to extcon framework (so moved to drivers/extcon)
* removed palmas_usb_(write/read) and replaced all calls with palmas_(read/write).
* ignored a checkpatch warning in the line

	static const char *palmas_extcon_cable[] = {

as it seemed to be incorrect?
* removed all references to OMAP in this driver.
* couldn't test this driver with mainline as omap5 panda is not booting with mainline.
* A comment to change to platform_get_irq from regmap is not done as I felt the data should come from regmap in this case.

Changes from v2:
* Moved the driver to drivers/usb/phy/
* Added a bit more explanation in Kconfig

 .../devicetree/bindings/extcon/extcon-twl.txt      |  15 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-palmas.c                     | 246 +++++++++++++++++++++
 include/linux/mfd/palmas.h                         |  26 ++-
 5 files changed, 283 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-twl.txt
 create mode 100644 drivers/extcon/extcon-palmas.c
Documentation/devicetree/bindings/extcon/extcon-twl.txt new file +15 -0
new file mode 100644
index 0000000..58f531a
@@ -0,0 +1,15 @@
+EXTCON FOR TWL CHIPS
+
+PALMAS USB COMPARATOR
+Required Properties:
+ - compatible : Should be "ti,palmas-usb" or "ti,twl6035-usb"
+ - vbus-supply : phandle to the regulator device tree node.
+
+Optional Properties:
+ - ti,wakeup : To enable the wakeup comparator in probe
+
+palmas-usb {
+       compatible = "ti,twl6035-usb", "ti,palmas-usb";
+       vbus-supply = <&smps10_reg>;
+       ti,wakeup;
+};
drivers/extcon/Kconfig +7 -0
index 3297301..63f454e 100644
@@ -53,4 +53,11 @@ config EXTCON_ARIZONA
 	  with Wolfson Arizona devices. These are audio CODECs with
 	  advanced audio accessory detection support.
 
+config EXTCON_PALMAS
+	tristate "Palmas USB EXTCON support"
+	depends on MFD_PALMAS
+	help
+	  Say Y here to enable support for USB peripheral and USB host
+	  detection by palmas usb.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index f98a3c4..540e2c3 100644
@@ -8,3 +8,4 @@ obj-$(CONFIG_EXTCON_ADC_JACK)	+= extcon-adc-jack.o
 obj-$(CONFIG_EXTCON_MAX77693)	+= extcon-max77693.o
 obj-$(CONFIG_EXTCON_MAX8997)	+= extcon-max8997.o
 obj-$(CONFIG_EXTCON_ARIZONA)	+= extcon-arizona.o
+obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
drivers/extcon/extcon-palmas.c new file +246 -0

246 lines not on this page · raw message

include/linux/mfd/palmas.h +14 -12
index 8f21daf..9b81b2b 100644
@@ -20,6 +20,8 @@
 #include <linux/leds.h>
 #include <linux/regmap.h>
 #include <linux/regulator/driver.h>
+#include <linux/extcon.h>
+#include <linux/usb/phy_companion.h>
 
 #define PALMAS_NUM_CLIENTS		3
 
@@ -37,6 +39,12 @@ struct palmas_gpadc;
 struct palmas_resource;
 struct palmas_usb;
 
+enum palmas_usb_state {
+	PALMAS_USB_STATE_DISCONNECT,
+	PALMAS_USB_STATE_VBUS,
+	PALMAS_USB_STATE_ID,
+};
+
 struct palmas {
 	struct device *dev;
 
@@ -180,9 +188,6 @@ struct palmas_pmic_platform_data {
 };
 
 struct palmas_usb_platform_data {
-	/* Set this if platform wishes its own vbus control */
-	int no_control_vbus;
-
 	/* Do we enable the wakeup comparator on probe */
 	int wakeup;
 };
@@ -350,22 +355,19 @@ struct palmas_usb {
 	struct palmas *palmas;
 	struct device *dev;
 
-	/* for vbus reporting with irqs disabled */
-	spinlock_t lock;
-
-	struct regulator *vbus_reg;
+	struct extcon_dev edev;
 
 	/* used to set vbus, in atomic path */
 	struct work_struct set_vbus_work;
 
-	int irq1;
-	int irq2;
-	int irq3;
-	int irq4;
+	int id_otg_irq;
+	int id_irq;
+	int vbus_otg_irq;
+	int vbus_irq;
 
 	int vbus_enable;
 
-	u8 linkstat;
+	enum palmas_usb_state linkstat;
 };
 
 #define comparator_to_palmas(x) container_of((x), struct palmas_usb, comparator)
Signature · 1 line
1.8.1.2
maintainer
#19 lore raw

Re: [PATCH v6] extcon: Palmas Extcon Driver

Quoted 49 lines · Kishon Vijay Abraham I

From: Graeme Gregory <[email protected]>

This is the driver for the USB comparator built into the palmas chip. It handles the various USB OTG events that can be generated by cable insertion/removal.

---
Changes from v5:
* removed regulator calls from palmas-usb as some platforms wont need it. These are now done in dwc3-omap.c as it is needed for OMAP.
* removed all references to phy_companion as none of it is validated (SRP) and all of them were currently unreachable code.

Changes from v4:
* removed no_control_vbus property (to be used if the platform wants to use its own vbus control.
* removed unnecessary headers
* moved the palmas_usb_state to palmas.h
* misc cleanups
*A checkpatch warning "WARNING: static const char * array should
probably be static const char * const"is ignored since it introduces a compilation warning.

Changes from v3:
* adapted the driver to extcon framework (so moved to drivers/extcon)
* removed palmas_usb_(write/read) and replaced all calls with palmas_(read/write).
* ignored a checkpatch warning in the line

	static const char *palmas_extcon_cable[] = {

as it seemed to be incorrect?
* removed all references to OMAP in this driver.
* couldn't test this driver with mainline as omap5 panda is not booting with mainline.
* A comment to change to platform_get_irq from regmap is not done as I felt the data should come from regmap in this case.

Changes from v2:
* Moved the driver to drivers/usb/phy/
* Added a bit more explanation in Kconfig

Quoted 8 lines
 .../devicetree/bindings/extcon/extcon-twl.txt      |  15 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-palmas.c                     | 246 +++++++++++++++++++++
 include/linux/mfd/palmas.h                         |  26 ++-
 5 files changed, 283 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-twl.txt
 create mode 100644 drivers/extcon/extcon-palmas.c

Applied only this patch.

you can check on following git repository:
http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/log/?h=extcon-next

Thanks,
Chanwoo Choi

#20 lore raw

PATCH v2 1/1 usb: dwc3: use extcon fwrk to receive connect/disconnect notification

In reply to Kishon Vijay Abraham I

Modified dwc3-omap to receive connect and disconnect notification using extcon framework. Also did the necessary cleanups required after adapting to extcon framework.

---
Changes from v1:
* regulator enable/disable is now done here instead of palmas-usb as some users of palmas-usb wont need regulator.

 drivers/usb/dwc3/dwc3-omap.c  | 103 ++++++++++++++++++++++++++++++++++--------
 include/linux/usb/dwc3-omap.h |  30 ------------
 2 files changed, 85 insertions(+), 48 deletions(-)
 delete mode 100644 include/linux/usb/dwc3-omap.h
drivers/usb/dwc3/dwc3-omap.c +85 -18
index 34638b9..158f903 100644
@@ -43,13 +43,14 @@
 #include <linux/spinlock.h>
 #include <linux/platform_device.h>
 #include <linux/platform_data/dwc3-omap.h>
-#include <linux/usb/dwc3-omap.h>
 #include <linux/pm_runtime.h>
 #include <linux/dma-mapping.h>
 #include <linux/ioport.h>
 #include <linux/io.h>
 #include <linux/of.h>
 #include <linux/of_platform.h>
+#include <linux/extcon.h>
+#include <linux/regulator/consumer.h>
 
 #include <linux/usb/otg.h>
 
@@ -124,9 +125,21 @@ struct dwc3_omap {
 	u32			utmi_otg_status;
 
 	u32			dma_status:1;
+
+	struct extcon_specific_cable_nb extcon_vbus_dev;
+	struct extcon_specific_cable_nb extcon_id_dev;
+	struct notifier_block	vbus_nb;
+	struct notifier_block	id_nb;
+
+	struct regulator	*vbus_reg;
 };
 
-static struct dwc3_omap		*_omap;
+enum omap_dwc3_vbus_id_status {
+	OMAP_DWC3_ID_FLOAT,
+	OMAP_DWC3_ID_GROUND,
+	OMAP_DWC3_VBUS_OFF,
+	OMAP_DWC3_VBUS_VALID,
+};
 
 static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
 {
@@ -138,18 +151,21 @@ static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value)
 	writel(value, base + offset);
 }
 
-int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
+static void dwc3_omap_set_mailbox(struct dwc3_omap *omap,
+	enum omap_dwc3_vbus_id_status status)
 {
-	u32			val;
-	struct dwc3_omap	*omap = _omap;
-
-	if (!omap)
-		return -EPROBE_DEFER;
+	int	ret;
+	u32	val;
 
 	switch (status) {
 	case OMAP_DWC3_ID_GROUND:
 		dev_dbg(omap->dev, "ID GND\n");
 
+		ret = regulator_enable(omap->vbus_reg);
+		if (ret) {
+			dev_dbg(omap->dev, "regulator enable failed\n");
+			return;
+		}
 		val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
 		val &= ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG
 				| USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
@@ -162,6 +178,11 @@ int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
 	case OMAP_DWC3_VBUS_VALID:
 		dev_dbg(omap->dev, "VBUS Connect\n");
 
+		ret = regulator_enable(omap->vbus_reg);
+		if (ret) {
+			dev_dbg(omap->dev, "regulator enable failed\n");
+			return;
+		}
 		val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
 		val &= ~USBOTGSS_UTMI_OTG_STATUS_SESSEND;
 		val |= USBOTGSS_UTMI_OTG_STATUS_IDDIG
@@ -182,15 +203,13 @@ int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
 		val |= USBOTGSS_UTMI_OTG_STATUS_SESSEND
 				| USBOTGSS_UTMI_OTG_STATUS_IDDIG;
 		dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val);
+		regulator_disable(omap->vbus_reg);
 		break;
 
 	default:
-		dev_dbg(omap->dev, "ID float\n");
+		dev_dbg(omap->dev, "invalid state\n");
 	}
-
-	return 0;
 }
-EXPORT_SYMBOL_GPL(dwc3_omap_mailbox);
 
 static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
 {
@@ -282,6 +301,32 @@ static void dwc3_omap_disable_irqs(struct dwc3_omap *omap)
 
 static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32);
 
+static int dwc3_omap_id_notifier(struct notifier_block *nb,
+	unsigned long event, void *ptr)
+{
+	struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, id_nb);
+
+	if (event)
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
+	else
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_FLOAT);
+
+	return NOTIFY_DONE;
+}
+
+static int dwc3_omap_vbus_notifier(struct notifier_block *nb,
+	unsigned long event, void *ptr)
+{
+	struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, vbus_nb);
+
+	if (event)
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
+	else
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_OFF);
+
+	return NOTIFY_DONE;
+}
+
 static int dwc3_omap_probe(struct platform_device *pdev)
 {
 	struct device_node	*node = pdev->dev.of_node;
@@ -289,6 +334,8 @@ static int dwc3_omap_probe(struct platform_device *pdev)
 	struct dwc3_omap	*omap;
 	struct resource		*res;
 	struct device		*dev = &pdev->dev;
+	struct extcon_dev	*edev;
+	struct regulator	*vbus_reg;
 
 	int			ret = -ENOMEM;
 	int			irq;
@@ -330,19 +377,32 @@ static int dwc3_omap_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	}
 
+	edev = extcon_get_extcon_dev("palmas-usb");
+	if (!edev) {
+		dev_dbg(dev, "couldn't get extcon device\n");
+		return -EPROBE_DEFER;
+	}
+
+	vbus_reg = devm_regulator_get(&pdev->dev, "vbus");
+	if (IS_ERR(vbus_reg)) {
+		dev_err(dev, "vbus init failed\n");
+		return PTR_ERR(vbus_reg);
+	}
+
 	spin_lock_init(&omap->lock);
 
 	omap->dev	= dev;
 	omap->irq	= irq;
 	omap->base	= base;
+	omap->vbus_reg	= vbus_reg;
+	omap->vbus_nb.notifier_call = dwc3_omap_vbus_notifier;
+	extcon_register_interest(&omap->extcon_vbus_dev, "palmas-usb", "USB",
+		&omap->vbus_nb);
+	omap->id_nb.notifier_call = dwc3_omap_id_notifier;
+	extcon_register_interest(&omap->extcon_id_dev, "palmas-usb", "USB-HOST",
+		&omap->id_nb);
 	dev->dma_mask	= &dwc3_omap_dma_mask;
 
-	/*
-	 * REVISIT if we ever have two instances of the wrapper, we will be
-	 * in big trouble
-	 */
-	_omap	= omap;
-
 	pm_runtime_enable(dev);
 	ret = pm_runtime_get_sync(dev);
 	if (ret < 0) {
@@ -387,6 +447,11 @@ static int dwc3_omap_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	if (extcon_get_cable_state(edev, "USB") == true)
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
+	if (extcon_get_cable_state(edev, "USB-HOST") == true)
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
+
 	return 0;
 }
 
@@ -394,6 +459,8 @@ static int dwc3_omap_remove(struct platform_device *pdev)
 {
 	struct dwc3_omap	*omap = platform_get_drvdata(pdev);
 
+	extcon_unregister_interest(&omap->extcon_vbus_dev);
+	extcon_unregister_interest(&omap->extcon_id_dev);
 	dwc3_omap_disable_irqs(omap);
 	pm_runtime_put_sync(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
include/linux/usb/dwc3-omap.h deleted +0 -30
deleted file mode 100644
index 5615f4d..0000000
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2013 by Texas Instruments
- *
- * The Inventra Controller Driver for Linux is free software; you
- * can redistribute it and/or modify it under the terms of the GNU
- * General Public License version 2 as published by the Free Software
- * Foundation.
- */
-
-#ifndef __DWC3_OMAP_H__
-#define __DWC3_OMAP_H__
-
-enum omap_dwc3_vbus_id_status {
-	OMAP_DWC3_UNKNOWN = 0,
-	OMAP_DWC3_ID_GROUND,
-	OMAP_DWC3_ID_FLOAT,
-	OMAP_DWC3_VBUS_VALID,
-	OMAP_DWC3_VBUS_OFF,
-};
-
-#if (defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_DWC3_MODULE))
-extern int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status);
-#else
-static inline int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
-{
-	return -ENODEV;
-}
-#endif
-
-#endif	/* __DWC3_OMAP_H__ */
Signature · 1 line
1.8.1.2
maintainer
#21 lore raw

Re: [PATCH v2] usb: dwc3: use extcon fwrk to receive connect/disconnect notification

Quoted 6 lines · Kishon Vijay Abraham I

Modified dwc3-omap to receive connect and disconnect notification using extcon framework. Also did the necessary cleanups required after adapting to extcon framework.

Quoted 8 lines

---
Changes from v1:
* regulator enable/disable is now done here instead of palmas-usb as some users of palmas-usb wont need regulator.

 drivers/usb/dwc3/dwc3-omap.c  | 103 ++++++++++++++++++++++++++++++++++--------
 include/linux/usb/dwc3-omap.h |  30 ------------
 2 files changed, 85 insertions(+), 48 deletions(-)
 delete mode 100644 include/linux/usb/dwc3-omap.h

I think that usb or other maintainer have to confirm this patch for applying extcon-next branch.

Thanks,
Chanwoo Choi

#22 lore raw

Re: [PATCH v2] usb: dwc3: use extcon fwrk to receive connect/disconnect notification

Quoted 15 lines · Chanwoo Choi
Quoted 6 lines · Kishon Vijay Abraham I

Modified dwc3-omap to receive connect and disconnect notification using extcon framework. Also did the necessary cleanups required after adapting to extcon framework.

Quoted 8 lines

---
Changes from v1:
* regulator enable/disable is now done here instead of palmas-usb as some users of palmas-usb wont need regulator.

  drivers/usb/dwc3/dwc3-omap.c  | 103 ++++++++++++++++++++++++++++++++++--------
  include/linux/usb/dwc3-omap.h |  30 ------------
  2 files changed, 85 insertions(+), 48 deletions(-)

delete mode 100644 include/linux/usb/dwc3-omap.h

Quoted 2 lines

I think that usb or other maintainer have to confirm this patch for applying extcon-next branch.

Ok. I'll check with Felipe.

Thanks
Kishon

#23 lore raw
In reply to Kishon Vijay Abraham I
Quoted 11 lines · Kishon Vijay Abraham I

This patch series adds driver for palmas usb which is used to detect attach/detach events of usb device and usb host.

[PATCH v5 2/3] extcon: Palmas Extcon Driver which was sent previously is added in this patch series itself. The revision history is added in the patch comments section.

A checkpatch warning "WARNING: static const char * array should probably be static const char * const"is ignored since it introduces a compilation warning.

Quoted 7 lines

Graeme Gregory (2):
drivers: regulator: palmas: add an API to set/clear the switch bit on

    SMPS10

extcon: Palmas Extcon Driver

Kishon Vijay Abraham I (1):
usb: dwc3: use extcon fwrk to receive connect/disconnect notification

There were some comments to this series, what will happen with it ? Any new versions coming ?

Signature · 1 line
balbi

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

#24 lore raw

Hi Felipe,

Quoted 17 lines · Felipe Balbi
Quoted 16 lines · Kishon Vijay Abraham I

This patch series adds driver for palmas usb which is used to detect attach/detach events of usb device and usb host.

[PATCH v5 2/3] extcon: Palmas Extcon Driver which was sent previously is added in this patch series itself. The revision history is added in the patch comments section.

A checkpatch warning "WARNING: static const char * array should probably be static const char * const"is ignored since it introduces a compilation warning.

Graeme Gregory (2):
drivers: regulator: palmas: add an API to set/clear the switch bit on

     SMPS10

extcon: Palmas Extcon Driver

Quoted 6 lines
Quoted 2 lines

Kishon Vijay Abraham I (1):
usb: dwc3: use extcon fwrk to receive connect/disconnect notification

There were some comments to this series, what will happen with it ? Any new versions coming ?

I've already sent new versions. Palmas Extcon Driver is already queued in extcon-next.
Chanwoo can take this patch in his tree after your ACK. [PATCH v2] usb: dwc3: use extcon fwrk to receive connect/disconnect notification.

Thanks
Kishon

Acked-by
#25 lore raw

Hi,

Quoted 24 lines · Kishon Vijay Abraham I

Hi Felipe,

Quoted 21 lines · Felipe Balbi
Quoted 18 lines · Kishon Vijay Abraham I

This patch series adds driver for palmas usb which is used to detect attach/detach events of usb device and usb host.

[PATCH v5 2/3] extcon: Palmas Extcon Driver which was sent previously is added in this patch series itself. The revision history is added in the patch comments section.

A checkpatch warning "WARNING: static const char * array should probably be static const char * const"is ignored since it introduces a compilation warning.

Graeme Gregory (2):
drivers: regulator: palmas: add an API to set/clear the switch bit on

    SMPS10

extcon: Palmas Extcon Driver

Kishon Vijay Abraham I (1):
usb: dwc3: use extcon fwrk to receive connect/disconnect notification

Quoted 8 lines
Quoted 2 lines

There were some comments to this series, what will happen with it ? Any new versions coming ?

I've already sent new versions. Palmas Extcon Driver is already queued in extcon-next.
Chanwoo can take this patch in his tree after your ACK. [PATCH v2]
usb: dwc3: use extcon fwrk to receive connect/disconnect notification.

alright, thanks for the note, here it is:

Signature · 1 line
balbi

A message that is not in the archive (sent off-list or not yet received): 20130529173851.GC21290-S8G//mZuvNWo5Im9Ml3/[email protected]

#27 lore raw
Quoted 38 lines · Felipe Balbi

Hi,

Quoted 17 lines · Kishon Vijay Abraham I

Hi Felipe,

Quoted 14 lines · Felipe Balbi
Quoted 13 lines · Kishon Vijay Abraham I

This patch series adds driver for palmas usb which is used to detect attach/detach events of usb device and usb host.

[PATCH v5 2/3] extcon: Palmas Extcon Driver which was sent previously is added in this patch series itself. The revision history is added in the patch comments section.

A checkpatch warning "WARNING: static const char * array should probably be static const char * const"is ignored since it introduces a compilation warning.

Graeme Gregory (2):
drivers: regulator: palmas: add an API to set/clear the switch bit

on

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
    SMPS10

extcon: Palmas Extcon Driver

Kishon Vijay Abraham I (1):
usb: dwc3: use extcon fwrk to receive connect/disconnect

notification

Quoted 10 lines
Quoted 4 lines

There were some comments to this series, what will happen with it ? Any new versions coming ?

I've already sent new versions. Palmas Extcon Driver is already queued in extcon-next.
Chanwoo can take this patch in his tree after your ACK. [PATCH v2]
usb: dwc3: use extcon fwrk to receive connect/disconnect notification.

Quoted 6 lines

alright, thanks for the note, here it is:

OK, I applied this patchset on extcon-next branch
and I will send pull-request to GregKH.

You can check on following git repository:
http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/log/?h=extcon-next

Thanks,
Chanwoo Choi

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

#28 lore raw
In reply to a message not in the archive
Quoted 38 lines · Felipe Balbi

Hi,

Quoted 17 lines · Kishon Vijay Abraham I

Hi Felipe,

Quoted 14 lines · Felipe Balbi
Quoted 13 lines · Kishon Vijay Abraham I

This patch series adds driver for palmas usb which is used to detect attach/detach events of usb device and usb host.

[PATCH v5 2/3] extcon: Palmas Extcon Driver which was sent previously is added in this patch series itself. The revision history is added in the patch comments section.

A checkpatch warning "WARNING: static const char * array should probably be static const char * const"is ignored since it introduces a compilation warning.

Graeme Gregory (2):
drivers: regulator: palmas: add an API to set/clear the switch bit

on

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
    SMPS10

extcon: Palmas Extcon Driver

Kishon Vijay Abraham I (1):
usb: dwc3: use extcon fwrk to receive connect/disconnect

notification

Quoted 10 lines
Quoted 4 lines

There were some comments to this series, what will happen with it ? Any new versions coming ?

I've already sent new versions. Palmas Extcon Driver is already queued in extcon-next.
Chanwoo can take this patch in his tree after your ACK. [PATCH v2]
usb: dwc3: use extcon fwrk to receive connect/disconnect notification.

Quoted 6 lines

alright, thanks for the note, here it is:

OK, I applied this patchset on extcon-next branch
and I will send pull-request to GregKH.

You can check on following git repository:
http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/log/?h=extcon-next

Thanks,
Chanwoo Choi

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

#29 lore raw
In reply to a message not in the archive
Quoted 38 lines · Felipe Balbi

Hi,

Quoted 17 lines · Kishon Vijay Abraham I

Hi Felipe,

Quoted 14 lines · Felipe Balbi
Quoted 13 lines · Kishon Vijay Abraham I

This patch series adds driver for palmas usb which is used to detect attach/detach events of usb device and usb host.

[PATCH v5 2/3] extcon: Palmas Extcon Driver which was sent previously is added in this patch series itself. The revision history is added in the patch comments section.

A checkpatch warning "WARNING: static const char * array should probably be static const char * const"is ignored since it introduces a compilation warning.

Graeme Gregory (2):
drivers: regulator: palmas: add an API to set/clear the switch bit

on

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
    SMPS10

extcon: Palmas Extcon Driver

Kishon Vijay Abraham I (1):
usb: dwc3: use extcon fwrk to receive connect/disconnect

notification

Quoted 10 lines
Quoted 4 lines

There were some comments to this series, what will happen with it ? Any new versions coming ?

I've already sent new versions. Palmas Extcon Driver is already queued in extcon-next.
Chanwoo can take this patch in his tree after your ACK. [PATCH v2]
usb: dwc3: use extcon fwrk to receive connect/disconnect notification.

Quoted 9 lines

alright, thanks for the note, here it is:

--
balbi

OK, I applied this patchset on extcon-next branch
and I will send pull-request to GregKH.

You can check on following git repository:
http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/log/?h=extcon-next

Thanks,
Chanwoo Choi

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss