All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/12] staging: typec: tcpci: move out of staging
@ 2017-09-26  0:45 Li Jun
       [not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
  0 siblings, 1 reply; 34+ messages in thread
From: Li Jun @ 2017-09-26  0:45 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	jun.li-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

This patch set attempts to move the tcpci driver out of staging by fix
some tcpci driver issues and verified on NXP PTN5110, which is a standard
tcpci typec port controller device with power delivery support, tested
power source and sink with drp config. 

Li Jun (12):
  usb: typec: add API to get port type and preferred role
  usb: typec: add basic typec properties
  staging: typec: tcpci: add documentation for tcpci
  staging: typec: tcpci: support port config passed via dt
  staging: typec: tcpci: register port before request irq
  staging: typec: tcpci: enable vbus detection
  typec: tcpm: add starting value for drp toggling
  staging: typec: tcpci: correct drp toggling
  usb: typec: tcpm: only drives the connected cc line when attached
  staging: typec: tcpci: update set_cc for different state
  staging: typec: tcpci: Only touch target bit when enable vconn
  staging: typec: tcpci: move tcpci driver out of staging

 .../devicetree/bindings/usb/typec-tcpci.txt        |  36 ++
 Documentation/devicetree/bindings/usb/typec.txt    |  46 ++
 drivers/staging/Kconfig                            |   2 -
 drivers/staging/Makefile                           |   1 -
 drivers/staging/typec/Kconfig                      |  14 -
 drivers/staging/typec/Makefile                     |   1 -
 drivers/staging/typec/TODO                         |   5 -
 drivers/staging/typec/tcpci.c                      | 526 -----------------
 drivers/staging/typec/tcpci.h                      | 133 -----
 drivers/usb/typec/Kconfig                          |   7 +
 drivers/usb/typec/Makefile                         |   1 +
 drivers/usb/typec/tcpci.c                          | 637 +++++++++++++++++++++
 drivers/usb/typec/tcpci.h                          | 133 +++++
 drivers/usb/typec/tcpm.c                           |  22 +-
 drivers/usb/typec/typec.c                          |  45 ++
 include/linux/usb/tcpm.h                           |   9 +-
 include/linux/usb/typec.h                          |   2 +
 17 files changed, 928 insertions(+), 692 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/typec-tcpci.txt
 create mode 100644 Documentation/devicetree/bindings/usb/typec.txt
 delete mode 100644 drivers/staging/typec/Kconfig
 delete mode 100644 drivers/staging/typec/Makefile
 delete mode 100644 drivers/staging/typec/TODO
 delete mode 100644 drivers/staging/typec/tcpci.c
 delete mode 100644 drivers/staging/typec/tcpci.h
 create mode 100644 drivers/usb/typec/tcpci.c
 create mode 100644 drivers/usb/typec/tcpci.h

-- 
2.6.6

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* [PATCH 01/12] usb: typec: add API to get port type and preferred role
       [not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
@ 2017-09-26  0:45   ` Li Jun
       [not found]     ` <1506386727-16370-2-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
  2017-09-26  0:45   ` [PATCH 02/12] usb: typec: add basic typec properties Li Jun
                     ` (10 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Li Jun @ 2017-09-26  0:45 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	jun.li-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

This patch add 2 APIs to get port type and preferred role from firmware
description.

Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
---
 drivers/usb/typec/typec.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/usb/typec.h |  2 ++
 2 files changed, 47 insertions(+)

diff --git a/drivers/usb/typec/typec.c b/drivers/usb/typec/typec.c
index 24e355b..0c77cc4 100644
--- a/drivers/usb/typec/typec.c
+++ b/drivers/usb/typec/typec.c
@@ -12,6 +12,7 @@
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/of.h>
 #include <linux/slab.h>
 #include <linux/usb/typec.h>
 
@@ -1249,6 +1250,50 @@ void typec_set_pwr_opmode(struct typec_port *port,
 }
 EXPORT_SYMBOL_GPL(typec_set_pwr_opmode);
 
+/**
+ * typec_get_port_type - Get the typec port type
+ * @dev: Device to get the property of
+ *
+ * This routine is used by typec hardware driver to read property port type
+ * from the device firmware description.
+ *
+ * Returns typec_port_type if success, otherwise negative error code.
+ */
+int typec_get_port_type(struct device *dev)
+{
+	const char *type_str;
+	int ret;
+
+	ret = device_property_read_string(dev, "port-type", &type_str);
+	if (ret < 0)
+		return ret;
+
+	return match_string(typec_port_types, ARRAY_SIZE(typec_port_types),
+								 type_str);
+}
+EXPORT_SYMBOL_GPL(typec_get_port_type);
+
+/**
+ * typec_get_power_role - Get the typec preferred role
+ * @dev: Device to get the property of
+ *
+ * This routine is used by typec hardware driver to read property default role
+ * from the device firmware description.
+ *
+ * Returns typec_role if success, otherwise negative error code.
+ */
+int typec_get_power_role(struct device *dev)
+{
+	const char *power_str;
+	int ret;
+
+	ret = device_property_read_string(dev, "default-role", &power_str);
+	if (ret < 0)
+		return ret;
+
+	return match_string(typec_roles, ARRAY_SIZE(typec_roles), power_str);
+}
+EXPORT_SYMBOL_GPL(typec_get_power_role);
 /* --------------------------------------- */
 
 /**
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index ffe7487..bfac685 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -243,5 +243,7 @@ void typec_set_data_role(struct typec_port *port, enum typec_data_role role);
 void typec_set_pwr_role(struct typec_port *port, enum typec_role role);
 void typec_set_vconn_role(struct typec_port *port, enum typec_role role);
 void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode);
+int typec_get_port_type(struct device *dev);
+int typec_get_power_role(struct device *dev);
 
 #endif /* __LINUX_USB_TYPEC_H */
-- 
2.6.6

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 02/12] usb: typec: add basic typec properties
       [not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
  2017-09-26  0:45   ` [PATCH 01/12] usb: typec: add API to get port type and preferred role Li Jun
@ 2017-09-26  0:45   ` Li Jun
       [not found]     ` <1506386727-16370-3-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
  2017-09-26  0:45   ` [PATCH 03/12] staging: typec: tcpci: add documentation for tcpci Li Jun
                     ` (9 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Li Jun @ 2017-09-26  0:45 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	jun.li-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

port-type is required for any typec port; default-role is only required
for drp; power source capable needs src-pdos; power sink capable needs
snk-pdos, max-snk-mv, max-snk-ma, op-snk-mw.

Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
---
 Documentation/devicetree/bindings/usb/typec.txt | 46 +++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/typec.txt b/Documentation/devicetree/bindings/usb/typec.txt
new file mode 100644
index 0000000..36d4467
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/typec.txt
@@ -0,0 +1,46 @@
+Generic typec and power delivery properties
+-------------------------------------------
+
+Required properties:
+- port-type:    should be one of "source", "sink" or "dual".
+- default-role: preferred power role if drp, should be "sink" or "source".
+- src-pdos:     An array of u32 with each entry providing supported power
+                source data object(PDO), the detailed bit definitions of
+                PDO can be found in "Universal Serial Bus Power Delivery
+                Specification" chapter 6.4.1.2 Source_Capabilities Message,
+                the order of each entry(PDO) should follow the PD spec chapter
+                6.4.1. Required only for power source and power dual role with
+                power delivery support.
+- snk-pdos:     An array of u32 with each entry providing supported power
+                sink data object(PDO), the detailed bit definitions of PDO
+                can be found in "Universal Serial Bus Power Delivery
+                Specification" chapter 6.4.1.3 Sink Capabilities Message,
+                the order of each entry(PDO) should follow the PD spec chapter
+                6.4.1. Required only for power sink and power dual role with
+                power delivery support.
+- max-snk-mv:   The max voltage the sink can support in millivoltage, required
+                only for power sink and power dual role with power delivery
+                support.
+- max-snk-ma:   The max current the sink can support in milliampere, required
+                only for power sink and power dual role with power delivery
+                support.
+- op-snk-mw:    Sink required operating power in milliwatts, if source offered
+                power is less then it, Capability Mismatch is set, required
+                only for power sink and power dual role with power delivery
+                support.
+
+Example:
+
+ptn5110@50 {
+	compatible = "usb,tcpci";
+	reg = <0x50>;
+	interrupt-parent = <&gpio3>;
+	interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
+	port-type = "dual";
+	default-role = "sink";
+	src-pdos = <0x380190c8>;
+	snk-pdos = <0x380190c8 0x3802d0c8>;
+	max-snk-mv = <9000>;
+	max-snk-ma = <1000>;
+	op-snk-mw = <9000>;
+};
-- 
2.6.6

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 03/12] staging: typec: tcpci: add documentation for tcpci
       [not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
  2017-09-26  0:45   ` [PATCH 01/12] usb: typec: add API to get port type and preferred role Li Jun
  2017-09-26  0:45   ` [PATCH 02/12] usb: typec: add basic typec properties Li Jun
@ 2017-09-26  0:45   ` Li Jun
  2017-09-26  0:45   ` [PATCH 04/12] staging: typec: tcpci: support port config passed via dt Li Jun
                     ` (8 subsequent siblings)
  11 siblings, 0 replies; 34+ messages in thread
From: Li Jun @ 2017-09-26  0:45 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	jun.li-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

TCPCI stands for typec port controller interface, its implementation
has full typec port control with power delivery support, it's a
standard i2c slave with GPIO input as irq interface, detail see spec
"Universal Serial Bus Type-C Port Controller Interface Specification
Revision 1.0, Version 1.1"

Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
---
 .../devicetree/bindings/usb/typec-tcpci.txt        | 36 ++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/typec-tcpci.txt b/Documentation/devicetree/bindings/usb/typec-tcpci.txt
new file mode 100644
index 0000000..9268440
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/typec-tcpci.txt
@@ -0,0 +1,36 @@
+TCPCI(Typec port cotroller interface) binding
+---------------------------------------------
+
+Required properties:
+- compatible:       should be "usb,tcpci".
+- reg:              the i2c slave address of typec port controller device.
+- interrupt-parent: the phandle to the interrupt controller which provides
+                    the interrupt.
+- interrupts:       interrupt specification for tcpci alert.
+- port-type:        typec port type.
+- default-role:     preferred power role if port type is "dual".
+
+Required properties only for power source or drp:
+- src-pdos
+
+Required properties only for power sink or drp:
+- snk-pdos
+- max-snk-mv
+- max-snk-ma
+- op-snk-mw
+
+Example:
+
+ptn5110@50 {
+	compatible = "usb,tcpci";
+	reg = <0x50>;
+	interrupt-parent = <&gpio3>;
+	interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
+	port-type = "dual";
+	default-role = "sink";
+	src-pdos = <0x380190c8>;
+	snk-pdos = <0x380190c8 0x3802d0c8>;
+	max-snk-mv = <9000>;
+	max-snk-ma = <1000>;
+	op-snk-mw = <9000>;
+};
-- 
2.6.6

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 04/12] staging: typec: tcpci: support port config passed via dt
       [not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
                     ` (2 preceding siblings ...)
  2017-09-26  0:45   ` [PATCH 03/12] staging: typec: tcpci: add documentation for tcpci Li Jun
@ 2017-09-26  0:45   ` Li Jun
       [not found]     ` <1506386727-16370-5-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
  2017-09-26  0:45   ` [PATCH 05/12] staging: typec: tcpci: register port before request irq Li Jun
                     ` (7 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Li Jun @ 2017-09-26  0:45 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	jun.li-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

User can define the typec port properties in tcpci node to setup
the port config.

Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
---
 drivers/staging/typec/tcpci.c | 89 +++++++++++++++++++++++++++++++++++++++----
 include/linux/usb/tcpm.h      |  6 +--
 2 files changed, 85 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
index 4636804..0119453 100644
--- a/drivers/staging/typec/tcpci.c
+++ b/drivers/staging/typec/tcpci.c
@@ -425,17 +425,92 @@ static const struct regmap_config tcpci_regmap_config = {
 	.max_register = 0x7F, /* 0x80 .. 0xFF are vendor defined */
 };
 
-static const struct tcpc_config tcpci_tcpc_config = {
-	.type = TYPEC_PORT_DFP,
-	.default_role = TYPEC_SINK,
-};
-
+/* Populate struct tcpc_config from device-tree */
 static int tcpci_parse_config(struct tcpci *tcpci)
 {
+	struct tcpc_config *tcfg;
+	int ret = -EINVAL;
+
 	tcpci->controls_vbus = true; /* XXX */
 
-	/* TODO: Populate struct tcpc_config from ACPI/device-tree */
-	tcpci->tcpc.config = &tcpci_tcpc_config;
+	tcpci->tcpc.config = devm_kzalloc(tcpci->dev, sizeof(*tcfg),
+					  GFP_KERNEL);
+	if (!tcpci->tcpc.config)
+		return -ENOMEM;
+
+	tcfg = tcpci->tcpc.config;
+
+	/* Get port-type */
+	ret = typec_get_port_type(tcpci->dev);
+	if (ret < 0) {
+		dev_err(tcpci->dev, "typec port type is NOT correct!\n");
+		return ret;
+	}
+	tcfg->type = ret;
+
+	if (tcfg->type == TYPEC_PORT_UFP)
+		goto sink;
+
+	/* Get source PDO */
+	tcfg->nr_src_pdo = device_property_read_u32_array(tcpci->dev,
+						"src-pdos", NULL, 0);
+	if (tcfg->nr_src_pdo <= 0) {
+		dev_err(tcpci->dev, "typec source pdo is missing!\n");
+		return -EINVAL;
+	}
+
+	tcfg->src_pdo = devm_kzalloc(tcpci->dev,
+		sizeof(*tcfg->src_pdo) * tcfg->nr_src_pdo, GFP_KERNEL);
+	if (!tcfg->src_pdo)
+		return -ENOMEM;
+
+	ret = device_property_read_u32_array(tcpci->dev, "src-pdos",
+				tcfg->src_pdo, tcfg->nr_src_pdo);
+	if (ret) {
+		dev_err(tcpci->dev, "Failed to read src pdo!\n");
+		return -EINVAL;
+	}
+
+	if (tcfg->type == TYPEC_PORT_DFP)
+		return 0;
+
+	/* Get the preferred power role for drp */
+	ret = typec_get_power_role(tcpci->dev);
+	if (ret < 0) {
+		dev_err(tcpci->dev, "typec preferred role is wrong!\n");
+		return ret;
+	}
+	tcfg->default_role = ret;
+sink:
+	/* Get sink power capability */
+	tcfg->nr_snk_pdo = device_property_read_u32_array(tcpci->dev,
+						"snk-pdos", NULL, 0);
+	if (tcfg->nr_snk_pdo <= 0) {
+		dev_err(tcpci->dev, "typec sink pdo is missing!\n");
+		return -EINVAL;
+	}
+
+	tcfg->snk_pdo = devm_kzalloc(tcpci->dev,
+		sizeof(*tcfg->snk_pdo) * tcfg->nr_snk_pdo, GFP_KERNEL);
+	if (!tcfg->snk_pdo)
+		return -ENOMEM;
+
+	ret = device_property_read_u32_array(tcpci->dev, "snk-pdos",
+				tcfg->snk_pdo, tcfg->nr_snk_pdo);
+	if (ret) {
+		dev_err(tcpci->dev, "Failed to read sink pdo!\n");
+		return -EINVAL;
+	}
+
+	if (device_property_read_u32(tcpci->dev, "max-snk-mv",
+				     &tcfg->max_snk_mv) ||
+		device_property_read_u32(tcpci->dev, "max-snk-ma",
+					 &tcfg->max_snk_ma) ||
+		device_property_read_u32(tcpci->dev, "op-snk-mw",
+					 &tcfg->operating_snk_mw)) {
+		dev_err(tcpci->dev, "Failed to read sink capability!\n");
+		return -EINVAL;
+	}
 
 	return 0;
 }
diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
index 073197f..a67cf77 100644
--- a/include/linux/usb/tcpm.h
+++ b/include/linux/usb/tcpm.h
@@ -76,10 +76,10 @@ enum tcpm_transmit_type {
  * @alt_modes:	List of supported alternate modes
  */
 struct tcpc_config {
-	const u32 *src_pdo;
+	u32 *src_pdo;
 	unsigned int nr_src_pdo;
 
-	const u32 *snk_pdo;
+	u32 *snk_pdo;
 	unsigned int nr_snk_pdo;
 
 	const u32 *snk_vdo;
@@ -154,7 +154,7 @@ struct tcpc_mux_dev {
  * @mux:	Pointer to multiplexer data
  */
 struct tcpc_dev {
-	const struct tcpc_config *config;
+	struct tcpc_config *config;
 
 	int (*init)(struct tcpc_dev *dev);
 	int (*get_vbus)(struct tcpc_dev *dev);
-- 
2.6.6

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 05/12] staging: typec: tcpci: register port before request irq
       [not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
                     ` (3 preceding siblings ...)
  2017-09-26  0:45   ` [PATCH 04/12] staging: typec: tcpci: support port config passed via dt Li Jun
@ 2017-09-26  0:45   ` Li Jun
       [not found]     ` <1506386727-16370-6-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
  2017-09-26  0:45   ` [PATCH 06/12] staging: typec: tcpci: enable vbus detection Li Jun
                     ` (6 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Li Jun @ 2017-09-26  0:45 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	jun.li-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

With that we can clear any pending events and the port is registered
so driver can be ready to handle typec events once we request irq.

Signed-off-by: Peter Chen <peter.chen-3arQi8VN3Tc@public.gmane.org>
Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
---
 drivers/staging/typec/tcpci.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
index 0119453..6d608b4 100644
--- a/drivers/staging/typec/tcpci.c
+++ b/drivers/staging/typec/tcpci.c
@@ -552,15 +552,14 @@ static int tcpci_probe(struct i2c_client *client,
 	/* Disable chip interrupts */
 	tcpci_write16(tcpci, TCPC_ALERT_MASK, 0);
 
-	err = devm_request_threaded_irq(tcpci->dev, client->irq, NULL,
+	tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
+	if (IS_ERR(tcpci->port))
+		return PTR_ERR(tcpci->port);
+
+	return devm_request_threaded_irq(tcpci->dev, client->irq, NULL,
 					tcpci_irq,
 					IRQF_ONESHOT | IRQF_TRIGGER_LOW,
 					dev_name(tcpci->dev), tcpci);
-	if (err < 0)
-		return err;
-
-	tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
-	return PTR_ERR_OR_ZERO(tcpci->port);
 }
 
 static int tcpci_remove(struct i2c_client *client)
-- 
2.6.6

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 06/12] staging: typec: tcpci: enable vbus detection
       [not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
                     ` (4 preceding siblings ...)
  2017-09-26  0:45   ` [PATCH 05/12] staging: typec: tcpci: register port before request irq Li Jun
@ 2017-09-26  0:45   ` Li Jun
       [not found]     ` <1506386727-16370-7-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
  2017-09-26  0:45   ` [PATCH 07/12] typec: tcpm: add starting value for drp toggling Li Jun
                     ` (5 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Li Jun @ 2017-09-26  0:45 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	jun.li-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

TCPCI implementation may need SW to enable VBUS detection to generate
power status events.

Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
---
 drivers/staging/typec/tcpci.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
index 6d608b4..851d026 100644
--- a/drivers/staging/typec/tcpci.c
+++ b/drivers/staging/typec/tcpci.c
@@ -313,6 +313,26 @@ static int tcpci_pd_transmit(struct tcpc_dev *tcpc,
 	return 0;
 }
 
+static int tcpci_vbus_detect(struct tcpc_dev *tcpc, bool enable)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+	int ret;
+
+	if (enable) {
+		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
+				   TCPC_CMD_ENABLE_VBUS_DETECT);
+		if (ret < 0)
+			return ret;
+	} else {
+		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
+				   TCPC_CMD_DISABLE_VBUS_DETECT);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int tcpci_init(struct tcpc_dev *tcpc)
 {
 	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
@@ -344,6 +364,9 @@ static int tcpci_init(struct tcpc_dev *tcpc)
 	if (ret < 0)
 		return ret;
 
+	/* Enable Vbus detection */
+	tcpci_vbus_detect(tcpc, true);
+
 	reg = TCPC_ALERT_TX_SUCCESS | TCPC_ALERT_TX_FAILED |
 		TCPC_ALERT_TX_DISCARDED | TCPC_ALERT_RX_STATUS |
 		TCPC_ALERT_RX_HARD_RST | TCPC_ALERT_CC_STATUS;
-- 
2.6.6

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 07/12] typec: tcpm: add starting value for drp toggling
       [not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
                     ` (5 preceding siblings ...)
  2017-09-26  0:45   ` [PATCH 06/12] staging: typec: tcpci: enable vbus detection Li Jun
@ 2017-09-26  0:45   ` Li Jun
       [not found]     ` <1506386727-16370-8-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
  2017-09-26  0:45   ` [PATCH 08/12] staging: typec: tcpci: correct " Li Jun
                     ` (4 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Li Jun @ 2017-09-26  0:45 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	jun.li-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

As DRP port autonomously toggles the Rp/Rd need a start value to
begin with, so add one parameter for it in tcpm_start_drp_toggling.

Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
---
 drivers/usb/typec/tcpm.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
index 8483d3e..38a6223 100644
--- a/drivers/usb/typec/tcpm.c
+++ b/drivers/usb/typec/tcpm.c
@@ -1839,15 +1839,15 @@ static int tcpm_set_charge(struct tcpm_port *port, bool charge)
 	return 0;
 }
 
-static bool tcpm_start_drp_toggling(struct tcpm_port *port)
+static bool tcpm_start_drp_toggling(struct tcpm_port *port,
+				    enum typec_cc_status cc)
 {
 	int ret;
 
 	if (port->tcpc->start_drp_toggling &&
 	    port->port_type == TYPEC_PORT_DRP) {
 		tcpm_log_force(port, "Start DRP toggling");
-		ret = port->tcpc->start_drp_toggling(port->tcpc,
-						     tcpm_rp_cc(port));
+		ret = port->tcpc->start_drp_toggling(port->tcpc, cc);
 		if (!ret)
 			return true;
 	}
@@ -2156,7 +2156,7 @@ static void run_state_machine(struct tcpm_port *port)
 		if (!port->non_pd_role_swap)
 			tcpm_swap_complete(port, -ENOTCONN);
 		tcpm_src_detach(port);
-		if (tcpm_start_drp_toggling(port)) {
+		if (tcpm_start_drp_toggling(port, tcpm_rp_cc(port))) {
 			tcpm_set_state(port, DRP_TOGGLING, 0);
 			break;
 		}
@@ -2328,7 +2328,7 @@ static void run_state_machine(struct tcpm_port *port)
 		if (!port->non_pd_role_swap)
 			tcpm_swap_complete(port, -ENOTCONN);
 		tcpm_snk_detach(port);
-		if (tcpm_start_drp_toggling(port)) {
+		if (tcpm_start_drp_toggling(port, TYPEC_CC_RD)) {
 			tcpm_set_state(port, DRP_TOGGLING, 0);
 			break;
 		}
-- 
2.6.6

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 08/12] staging: typec: tcpci: correct drp toggling
       [not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
                     ` (6 preceding siblings ...)
  2017-09-26  0:45   ` [PATCH 07/12] typec: tcpm: add starting value for drp toggling Li Jun
@ 2017-09-26  0:45   ` Li Jun
  2017-09-26  0:45   ` [PATCH 09/12] usb: typec: tcpm: only drives the connected cc line when attached Li Jun
                     ` (3 subsequent siblings)
  11 siblings, 0 replies; 34+ messages in thread
From: Li Jun @ 2017-09-26  0:45 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	jun.li-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

Per tcpci spec 4.4.5.2 ROLE_CONTROL description: "the TCPM shall
write B6 (DRP) =1b and the starting value of Rp/Rd to B3..0 (CC1/CC2)
to indicate DRP autonomous toggling mode to the TCPC", so add CC1/CC2
setting, also we should issue COMMAND.Look4Connection to start it.

Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
---
 drivers/staging/typec/tcpci.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
index 851d026..cea67f9 100644
--- a/drivers/staging/typec/tcpci.c
+++ b/drivers/staging/typec/tcpci.c
@@ -109,6 +109,7 @@ static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc,
 {
 	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
 	unsigned int reg = TCPC_ROLE_CTRL_DRP;
+	int ret;
 
 	switch (cc) {
 	default:
@@ -126,7 +127,19 @@ static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc,
 		break;
 	}
 
-	return regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
+	if (cc == TYPEC_CC_RD)
+		reg |= (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) |
+			(TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT);
+	else
+		reg |= (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) |
+			(TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT);
+
+	ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
+	if (ret < 0)
+		return ret;
+
+	return regmap_write(tcpci->regmap, TCPC_COMMAND,
+				TCPC_CMD_LOOK4CONNECTION);
 }
 
 static enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink)
-- 
2.6.6

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 09/12] usb: typec: tcpm: only drives the connected cc line when attached
       [not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
                     ` (7 preceding siblings ...)
  2017-09-26  0:45   ` [PATCH 08/12] staging: typec: tcpci: correct " Li Jun
@ 2017-09-26  0:45   ` Li Jun
       [not found]     ` <1506386727-16370-10-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
  2017-09-26  0:45   ` [PATCH 10/12] staging: typec: tcpci: update set_cc for different state Li Jun
                     ` (2 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Li Jun @ 2017-09-26  0:45 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	jun.li-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

As we should only drive connected cc line to be the right state when
attached, and keeps the other one to be open, so update the set_cc
interface for that.

Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
---
 drivers/usb/typec/tcpm.c | 12 +++++++++++-
 include/linux/usb/tcpm.h |  3 ++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
index 38a6223..c9966ee 100644
--- a/drivers/usb/typec/tcpm.c
+++ b/drivers/usb/typec/tcpm.c
@@ -1857,9 +1857,15 @@ static bool tcpm_start_drp_toggling(struct tcpm_port *port,
 
 static void tcpm_set_cc(struct tcpm_port *port, enum typec_cc_status cc)
 {
+	bool attached;
+
 	tcpm_log(port, "cc:=%d", cc);
 	port->cc_req = cc;
-	port->tcpc->set_cc(port->tcpc, cc);
+	if (port->state == SRC_ATTACHED || port->state == SNK_ATTACHED)
+		attached = true;
+	else
+		attached = false;
+	port->tcpc->set_cc(port->tcpc, cc, attached, port->polarity);
 }
 
 static int tcpm_init_vbus(struct tcpm_port *port)
@@ -1913,6 +1919,8 @@ static int tcpm_src_attach(struct tcpm_port *port)
 	if (ret < 0)
 		return ret;
 
+	tcpm_set_cc(port, tcpm_rp_cc(port));
+
 	ret = tcpm_set_roles(port, true, TYPEC_SOURCE, TYPEC_HOST);
 	if (ret < 0)
 		return ret;
@@ -2028,6 +2036,8 @@ static int tcpm_snk_attach(struct tcpm_port *port)
 	if (ret < 0)
 		return ret;
 
+	tcpm_set_cc(port, TYPEC_CC_RD);
+
 	ret = tcpm_set_roles(port, true, TYPEC_SINK, TYPEC_DEVICE);
 	if (ret < 0)
 		return ret;
diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
index a67cf77..a007e2a1 100644
--- a/include/linux/usb/tcpm.h
+++ b/include/linux/usb/tcpm.h
@@ -159,7 +159,8 @@ struct tcpc_dev {
 	int (*init)(struct tcpc_dev *dev);
 	int (*get_vbus)(struct tcpc_dev *dev);
 	int (*get_current_limit)(struct tcpc_dev *dev);
-	int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc);
+	int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc,
+			bool attached, enum typec_cc_polarity polarity);
 	int (*get_cc)(struct tcpc_dev *dev, enum typec_cc_status *cc1,
 		      enum typec_cc_status *cc2);
 	int (*set_polarity)(struct tcpc_dev *dev,
-- 
2.6.6

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 10/12] staging: typec: tcpci: update set_cc for different state
       [not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
                     ` (8 preceding siblings ...)
  2017-09-26  0:45   ` [PATCH 09/12] usb: typec: tcpm: only drives the connected cc line when attached Li Jun
@ 2017-09-26  0:45   ` Li Jun
       [not found]     ` <1506386727-16370-11-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
  2017-09-26  0:45   ` [PATCH 11/12] staging: typec: tcpci: Only touch target bit when enable vconn Li Jun
  2017-09-26  0:45   ` [PATCH 12/12] staging: typec: tcpci: move tcpci driver out of staging Li Jun
  11 siblings, 1 reply; 34+ messages in thread
From: Li Jun @ 2017-09-26  0:45 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	jun.li-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

As we should keep the disconnected cc line to be open when attached,
so update the set_cc interface accordingly for it.

Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
---
 drivers/staging/typec/tcpci.c | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
index cea67f9..c7c45da 100644
--- a/drivers/staging/typec/tcpci.c
+++ b/drivers/staging/typec/tcpci.c
@@ -57,10 +57,11 @@ static int tcpci_write16(struct tcpci *tcpci, unsigned int reg, u16 val)
 	return regmap_raw_write(tcpci->regmap, reg, &val, sizeof(u16));
 }
 
-static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)
+static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc,
+			bool attached, enum typec_cc_polarity polarity)
 {
 	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
-	unsigned int reg;
+	unsigned int reg = 0, reg_cc1 = 0, reg_cc2 = 0;
 	int ret;
 
 	switch (cc) {
@@ -69,26 +70,23 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)
 			(TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC2_SHIFT);
 		break;
 	case TYPEC_CC_RD:
-		reg = (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) |
-			(TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT);
+		reg_cc1 = TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT;
+		reg_cc2 = TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT;
 		break;
 	case TYPEC_CC_RP_DEF:
-		reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) |
-			(TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) |
-			(TCPC_ROLE_CTRL_RP_VAL_DEF <<
-			 TCPC_ROLE_CTRL_RP_VAL_SHIFT);
+		reg_cc1 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT;
+		reg_cc2 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT;
+		reg = TCPC_ROLE_CTRL_RP_VAL_DEF << TCPC_ROLE_CTRL_RP_VAL_SHIFT;
 		break;
 	case TYPEC_CC_RP_1_5:
-		reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) |
-			(TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) |
-			(TCPC_ROLE_CTRL_RP_VAL_1_5 <<
-			 TCPC_ROLE_CTRL_RP_VAL_SHIFT);
+		reg_cc1 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT;
+		reg_cc2 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT;
+		reg = TCPC_ROLE_CTRL_RP_VAL_1_5 << TCPC_ROLE_CTRL_RP_VAL_SHIFT;
 		break;
 	case TYPEC_CC_RP_3_0:
-		reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) |
-			(TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) |
-			(TCPC_ROLE_CTRL_RP_VAL_3_0 <<
-			 TCPC_ROLE_CTRL_RP_VAL_SHIFT);
+		reg_cc1 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT;
+		reg_cc2 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT;
+		reg = TCPC_ROLE_CTRL_RP_VAL_3_0 << TCPC_ROLE_CTRL_RP_VAL_SHIFT;
 		break;
 	case TYPEC_CC_OPEN:
 	default:
@@ -97,6 +95,13 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)
 		break;
 	}
 
+	if (!attached)
+		reg |= reg_cc1 | reg_cc2;
+	else if (polarity == TYPEC_POLARITY_CC1)
+		reg |= reg_cc1;
+	else
+		reg |= reg_cc2;
+
 	ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
 	if (ret < 0)
 		return ret;
-- 
2.6.6

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 11/12] staging: typec: tcpci: Only touch target bit when enable vconn
       [not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
                     ` (9 preceding siblings ...)
  2017-09-26  0:45   ` [PATCH 10/12] staging: typec: tcpci: update set_cc for different state Li Jun
@ 2017-09-26  0:45   ` Li Jun
  2017-09-26  0:45   ` [PATCH 12/12] staging: typec: tcpci: move tcpci driver out of staging Li Jun
  11 siblings, 0 replies; 34+ messages in thread
From: Li Jun @ 2017-09-26  0:45 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	jun.li-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

We need regmap_update_bits to avoid touch any other bits when
enable or disable vconn.

Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
---
 drivers/staging/typec/tcpci.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
index c7c45da..293a07c 100644
--- a/drivers/staging/typec/tcpci.c
+++ b/drivers/staging/typec/tcpci.c
@@ -202,14 +202,10 @@ static int tcpci_set_polarity(struct tcpc_dev *tcpc,
 static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)
 {
 	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
-	int ret;
 
-	ret = regmap_write(tcpci->regmap, TCPC_POWER_CTRL,
-			   enable ? TCPC_POWER_CTRL_VCONN_ENABLE : 0);
-	if (ret < 0)
-		return ret;

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 12/12] staging: typec: tcpci: move tcpci driver out of staging
       [not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
                     ` (10 preceding siblings ...)
  2017-09-26  0:45   ` [PATCH 11/12] staging: typec: tcpci: Only touch target bit when enable vconn Li Jun
@ 2017-09-26  0:45   ` Li Jun
       [not found]     ` <1506386727-16370-13-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
  11 siblings, 1 reply; 34+ messages in thread
From: Li Jun @ 2017-09-26  0:45 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	jun.li-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

Move TCPCI(Typec port controller interface) driver out of staging.

Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
---
 drivers/staging/Kconfig        |   2 -
 drivers/staging/Makefile       |   1 -
 drivers/staging/typec/Kconfig  |  14 -
 drivers/staging/typec/Makefile |   1 -
 drivers/staging/typec/TODO     |   5 -
 drivers/staging/typec/tcpci.c  | 637 -----------------------------------------
 drivers/staging/typec/tcpci.h  | 133 ---------
 drivers/usb/typec/Kconfig      |   7 +
 drivers/usb/typec/Makefile     |   1 +
 drivers/usb/typec/tcpci.c      | 637 +++++++++++++++++++++++++++++++++++++++++
 drivers/usb/typec/tcpci.h      | 133 +++++++++
 11 files changed, 778 insertions(+), 793 deletions(-)

diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 5546839..1e3d5d0 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -112,8 +112,6 @@ source "drivers/staging/vc04_services/Kconfig"
 
 source "drivers/staging/ccree/Kconfig"
 
-source "drivers/staging/typec/Kconfig"
-
 source "drivers/staging/vboxvideo/Kconfig"
 
 source "drivers/staging/pi433/Kconfig"
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 8951c37..4d1ccb4 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -1,7 +1,6 @@
 # Makefile for staging directory
 
 obj-y				+= media/
-obj-y				+= typec/
 obj-$(CONFIG_IRDA)		+= irda/net/
 obj-$(CONFIG_IRDA)		+= irda/drivers/
 obj-$(CONFIG_PRISM2_USB)	+= wlan-ng/
diff --git a/drivers/staging/typec/Kconfig b/drivers/staging/typec/Kconfig
deleted file mode 100644
index 5359f55..0000000
--- a/drivers/staging/typec/Kconfig
+++ /dev/null
@@ -1,14 +0,0 @@
-menu "USB Power Delivery and Type-C drivers"
-
-if TYPEC_TCPM
-
-config TYPEC_TCPCI
-	tristate "Type-C Port Controller Interface driver"
-	depends on I2C
-	select REGMAP_I2C
-	help
-	  Type-C Port Controller driver for TCPCI-compliant controller.
-
-endif
-
-endmenu
diff --git a/drivers/staging/typec/Makefile b/drivers/staging/typec/Makefile
deleted file mode 100644
index 53d649a..0000000
--- a/drivers/staging/typec/Makefile
+++ /dev/null
@@ -1 +0,0 @@
-obj-$(CONFIG_TYPEC_TCPCI)	+= tcpci.o
diff --git a/drivers/staging/typec/TODO b/drivers/staging/typec/TODO
deleted file mode 100644
index 53fe2f7..0000000
--- a/drivers/staging/typec/TODO
+++ /dev/null
@@ -1,5 +0,0 @@
-tcpci:
-- Test with real hardware
-
-Please send patches to Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org> and copy
-Heikki Krogerus <heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>.
diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
deleted file mode 100644
index 293a07c..0000000
--- a/drivers/staging/typec/tcpci.c
+++ /dev/null
@@ -1,637 +0,0 @@
-/*
- * Copyright 2015-2017 Google, Inc
- *
- * 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 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.
- *
- * USB Type-C Port Controller Interface.
- */
-
-#include <linux/delay.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/i2c.h>
-#include <linux/interrupt.h>
-#include <linux/regmap.h>
-#include <linux/usb/pd.h>
-#include <linux/usb/tcpm.h>
-#include <linux/usb/typec.h>
-
-#include "tcpci.h"
-
-#define PD_RETRY_COUNT 3
-
-struct tcpci {
-	struct device *dev;
-	struct i2c_client *client;
-
-	struct tcpm_port *port;
-
-	struct regmap *regmap;
-
-	bool controls_vbus;
-
-	struct tcpc_dev tcpc;
-};
-
-static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc)
-{
-	return container_of(tcpc, struct tcpci, tcpc);
-}
-
-static int tcpci_read16(struct tcpci *tcpci, unsigned int reg,
-			unsigned int *val)
-{
-	return regmap_raw_read(tcpci->regmap, reg, val, sizeof(u16));
-}
-
-static int tcpci_write16(struct tcpci *tcpci, unsigned int reg, u16 val)
-{
-	return regmap_raw_write(tcpci->regmap, reg, &val, sizeof(u16));
-}
-
-static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc,
-			bool attached, enum typec_cc_polarity polarity)
-{
-	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
-	unsigned int reg = 0, reg_cc1 = 0, reg_cc2 = 0;
-	int ret;
-
-	switch (cc) {
-	case TYPEC_CC_RA:
-		reg = (TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC1_SHIFT) |
-			(TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC2_SHIFT);
-		break;
-	case TYPEC_CC_RD:
-		reg_cc1 = TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT;
-		reg_cc2 = TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT;
-		break;
-	case TYPEC_CC_RP_DEF:
-		reg_cc1 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT;
-		reg_cc2 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT;
-		reg = TCPC_ROLE_CTRL_RP_VAL_DEF << TCPC_ROLE_CTRL_RP_VAL_SHIFT;
-		break;
-	case TYPEC_CC_RP_1_5:
-		reg_cc1 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT;
-		reg_cc2 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT;
-		reg = TCPC_ROLE_CTRL_RP_VAL_1_5 << TCPC_ROLE_CTRL_RP_VAL_SHIFT;
-		break;
-	case TYPEC_CC_RP_3_0:
-		reg_cc1 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT;
-		reg_cc2 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT;
-		reg = TCPC_ROLE_CTRL_RP_VAL_3_0 << TCPC_ROLE_CTRL_RP_VAL_SHIFT;
-		break;
-	case TYPEC_CC_OPEN:
-	default:
-		reg = (TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC1_SHIFT) |
-			(TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC2_SHIFT);
-		break;
-	}
-
-	if (!attached)
-		reg |= reg_cc1 | reg_cc2;
-	else if (polarity == TYPEC_POLARITY_CC1)
-		reg |= reg_cc1;
-	else
-		reg |= reg_cc2;
-
-	ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
-	if (ret < 0)
-		return ret;
-
-	return 0;
-}
-
-static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc,
-				    enum typec_cc_status cc)
-{
-	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
-	unsigned int reg = TCPC_ROLE_CTRL_DRP;
-	int ret;
-
-	switch (cc) {
-	default:
-	case TYPEC_CC_RP_DEF:
-		reg |= (TCPC_ROLE_CTRL_RP_VAL_DEF <<
-			TCPC_ROLE_CTRL_RP_VAL_SHIFT);
-		break;
-	case TYPEC_CC_RP_1_5:
-		reg |= (TCPC_ROLE_CTRL_RP_VAL_1_5 <<
-			TCPC_ROLE_CTRL_RP_VAL_SHIFT);
-		break;
-	case TYPEC_CC_RP_3_0:
-		reg |= (TCPC_ROLE_CTRL_RP_VAL_3_0 <<
-			TCPC_ROLE_CTRL_RP_VAL_SHIFT);
-		break;
-	}
-
-	if (cc == TYPEC_CC_RD)
-		reg |= (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) |
-			(TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT);
-	else
-		reg |= (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) |
-			(TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT);
-
-	ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
-	if (ret < 0)
-		return ret;
-
-	return regmap_write(tcpci->regmap, TCPC_COMMAND,
-				TCPC_CMD_LOOK4CONNECTION);
-}
-
-static enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink)
-{
-	switch (cc) {
-	case 0x1:
-		return sink ? TYPEC_CC_RP_DEF : TYPEC_CC_RA;
-	case 0x2:
-		return sink ? TYPEC_CC_RP_1_5 : TYPEC_CC_RD;
-	case 0x3:
-		if (sink)
-			return TYPEC_CC_RP_3_0;
-	case 0x0:
-	default:
-		return TYPEC_CC_OPEN;
-	}
-}
-
-static int tcpci_get_cc(struct tcpc_dev *tcpc,
-			enum typec_cc_status *cc1, enum typec_cc_status *cc2)
-{
-	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
-	unsigned int reg;
-	int ret;
-
-	ret = regmap_read(tcpci->regmap, TCPC_CC_STATUS, &reg);
-	if (ret < 0)
-		return ret;
-
-	*cc1 = tcpci_to_typec_cc((reg >> TCPC_CC_STATUS_CC1_SHIFT) &
-				 TCPC_CC_STATUS_CC1_MASK,
-				 reg & TCPC_CC_STATUS_TERM);
-	*cc2 = tcpci_to_typec_cc((reg >> TCPC_CC_STATUS_CC2_SHIFT) &
-				 TCPC_CC_STATUS_CC2_MASK,
-				 reg & TCPC_CC_STATUS_TERM);
-
-	return 0;
-}
-
-static int tcpci_set_polarity(struct tcpc_dev *tcpc,
-			      enum typec_cc_polarity polarity)
-{
-	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
-	int ret;
-
-	ret = regmap_write(tcpci->regmap, TCPC_TCPC_CTRL,
-			   (polarity == TYPEC_POLARITY_CC2) ?
-			   TCPC_TCPC_CTRL_ORIENTATION : 0);
-	if (ret < 0)
-		return ret;
-
-	return 0;
-}
-
-static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)
-{
-	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
-
-	return regmap_update_bits(tcpci->regmap, TCPC_POWER_CTRL,
-				TCPC_POWER_CTRL_VCONN_ENABLE,
-				enable ? TCPC_POWER_CTRL_VCONN_ENABLE : 0);
-}
-
-static int tcpci_set_roles(struct tcpc_dev *tcpc, bool attached,
-			   enum typec_role role, enum typec_data_role data)
-{
-	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
-	unsigned int reg;
-	int ret;
-
-	reg = PD_REV20 << TCPC_MSG_HDR_INFO_REV_SHIFT;
-	if (role == TYPEC_SOURCE)
-		reg |= TCPC_MSG_HDR_INFO_PWR_ROLE;
-	if (data == TYPEC_HOST)
-		reg |= TCPC_MSG_HDR_INFO_DATA_ROLE;
-	ret = regmap_write(tcpci->regmap, TCPC_MSG_HDR_INFO, reg);
-	if (ret < 0)
-		return ret;
-
-	return 0;
-}
-
-static int tcpci_set_pd_rx(struct tcpc_dev *tcpc, bool enable)
-{
-	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
-	unsigned int reg = 0;
-	int ret;
-
-	if (enable)
-		reg = TCPC_RX_DETECT_SOP | TCPC_RX_DETECT_HARD_RESET;
-	ret = regmap_write(tcpci->regmap, TCPC_RX_DETECT, reg);
-	if (ret < 0)
-		return ret;
-
-	return 0;
-}
-
-static int tcpci_get_vbus(struct tcpc_dev *tcpc)
-{
-	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
-	unsigned int reg;
-	int ret;
-
-	ret = regmap_read(tcpci->regmap, TCPC_POWER_STATUS, &reg);
-	if (ret < 0)
-		return ret;
-
-	return !!(reg & TCPC_POWER_STATUS_VBUS_PRES);
-}
-
-static int tcpci_set_vbus(struct tcpc_dev *tcpc, bool source, bool sink)
-{
-	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
-	int ret;
-
-	/* Disable both source and sink first before enabling anything */
-
-	if (!source) {
-		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
-				   TCPC_CMD_DISABLE_SRC_VBUS);
-		if (ret < 0)
-			return ret;
-	}
-
-	if (!sink) {
-		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
-				   TCPC_CMD_DISABLE_SINK_VBUS);
-		if (ret < 0)
-			return ret;
-	}
-
-	if (source) {
-		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
-				   TCPC_CMD_SRC_VBUS_DEFAULT);
-		if (ret < 0)
-			return ret;
-	}
-
-	if (sink) {
-		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
-				   TCPC_CMD_SINK_VBUS);
-		if (ret < 0)
-			return ret;
-	}
-
-	return 0;
-}
-
-static int tcpci_pd_transmit(struct tcpc_dev *tcpc,
-			     enum tcpm_transmit_type type,
-			     const struct pd_message *msg)
-{
-	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
-	unsigned int reg, cnt, header;
-	int ret;
-
-	cnt = msg ? pd_header_cnt(msg->header) * 4 : 0;
-	ret = regmap_write(tcpci->regmap, TCPC_TX_BYTE_CNT, cnt + 2);
-	if (ret < 0)
-		return ret;
-
-	header = msg ? msg->header : 0;
-	ret = tcpci_write16(tcpci, TCPC_TX_HDR, header);
-	if (ret < 0)
-		return ret;
-
-	if (cnt > 0) {
-		ret = regmap_raw_write(tcpci->regmap, TCPC_TX_DATA,
-				       &msg->payload, cnt);
-		if (ret < 0)
-			return ret;
-	}
-
-	reg = (PD_RETRY_COUNT << TCPC_TRANSMIT_RETRY_SHIFT) |
-		(type << TCPC_TRANSMIT_TYPE_SHIFT);
-	ret = regmap_write(tcpci->regmap, TCPC_TRANSMIT, reg);
-	if (ret < 0)
-		return ret;
-
-	return 0;
-}
-
-static int tcpci_vbus_detect(struct tcpc_dev *tcpc, bool enable)
-{
-	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
-	int ret;
-
-	if (enable) {
-		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
-				   TCPC_CMD_ENABLE_VBUS_DETECT);
-		if (ret < 0)
-			return ret;
-	} else {
-		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
-				   TCPC_CMD_DISABLE_VBUS_DETECT);
-		if (ret < 0)
-			return ret;
-	}
-
-	return 0;
-}
-
-static int tcpci_init(struct tcpc_dev *tcpc)
-{
-	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
-	unsigned long timeout = jiffies + msecs_to_jiffies(2000); /* XXX */
-	unsigned int reg;
-	int ret;
-
-	while (time_before_eq(jiffies, timeout)) {
-		ret = regmap_read(tcpci->regmap, TCPC_POWER_STATUS, &reg);
-		if (ret < 0)
-			return ret;
-		if (!(reg & TCPC_POWER_STATUS_UNINIT))
-			break;
-		usleep_range(10000, 20000);
-	}
-	if (time_after(jiffies, timeout))
-		return -ETIMEDOUT;
-
-	/* Clear all events */
-	ret = tcpci_write16(tcpci, TCPC_ALERT, 0xffff);
-	if (ret < 0)
-		return ret;
-
-	if (tcpci->controls_vbus)
-		reg = TCPC_POWER_STATUS_VBUS_PRES;
-	else
-		reg = 0;
-	ret = regmap_write(tcpci->regmap, TCPC_POWER_STATUS_MASK, reg);
-	if (ret < 0)
-		return ret;
-
-	/* Enable Vbus detection */
-	tcpci_vbus_detect(tcpc, true);
-
-	reg = TCPC_ALERT_TX_SUCCESS | TCPC_ALERT_TX_FAILED |
-		TCPC_ALERT_TX_DISCARDED | TCPC_ALERT_RX_STATUS |
-		TCPC_ALERT_RX_HARD_RST | TCPC_ALERT_CC_STATUS;
-	if (tcpci->controls_vbus)
-		reg |= TCPC_ALERT_POWER_STATUS;
-	return tcpci_write16(tcpci, TCPC_ALERT_MASK, reg);
-}
-
-static irqreturn_t tcpci_irq(int irq, void *dev_id)
-{
-	struct tcpci *tcpci = dev_id;
-	unsigned int status, reg;
-
-	tcpci_read16(tcpci, TCPC_ALERT, &status);
-
-	/*
-	 * Clear alert status for everything except RX_STATUS, which shouldn't
-	 * be cleared until we have successfully retrieved message.
-	 */
-	if (status & ~TCPC_ALERT_RX_STATUS)
-		tcpci_write16(tcpci, TCPC_ALERT,
-			      status & ~TCPC_ALERT_RX_STATUS);
-
-	if (status & TCPC_ALERT_CC_STATUS)
-		tcpm_cc_change(tcpci->port);
-
-	if (status & TCPC_ALERT_POWER_STATUS) {
-		regmap_read(tcpci->regmap, TCPC_POWER_STATUS_MASK, &reg);
-
-		/*
-		 * If power status mask has been reset, then the TCPC
-		 * has reset.
-		 */
-		if (reg == 0xff)
-			tcpm_tcpc_reset(tcpci->port);
-		else
-			tcpm_vbus_change(tcpci->port);
-	}
-
-	if (status & TCPC_ALERT_RX_STATUS) {
-		struct pd_message msg;
-		unsigned int cnt;
-
-		regmap_read(tcpci->regmap, TCPC_RX_BYTE_CNT, &cnt);
-
-		tcpci_read16(tcpci, TCPC_RX_HDR, &reg);
-		msg.header = reg;
-
-		if (WARN_ON(cnt > sizeof(msg.payload)))
-			cnt = sizeof(msg.payload);
-
-		if (cnt > 0)
-			regmap_raw_read(tcpci->regmap, TCPC_RX_DATA,
-					&msg.payload, cnt);
-
-		/* Read complete, clear RX status alert bit */
-		tcpci_write16(tcpci, TCPC_ALERT, TCPC_ALERT_RX_STATUS);
-
-		tcpm_pd_receive(tcpci->port, &msg);
-	}
-
-	if (status & TCPC_ALERT_RX_HARD_RST)
-		tcpm_pd_hard_reset(tcpci->port);
-
-	if (status & TCPC_ALERT_TX_SUCCESS)
-		tcpm_pd_transmit_complete(tcpci->port, TCPC_TX_SUCCESS);
-	else if (status & TCPC_ALERT_TX_DISCARDED)
-		tcpm_pd_transmit_complete(tcpci->port, TCPC_TX_DISCARDED);
-	else if (status & TCPC_ALERT_TX_FAILED)
-		tcpm_pd_transmit_complete(tcpci->port, TCPC_TX_FAILED);
-
-	return IRQ_HANDLED;
-}
-
-static const struct regmap_config tcpci_regmap_config = {
-	.reg_bits = 8,
-	.val_bits = 8,
-
-	.max_register = 0x7F, /* 0x80 .. 0xFF are vendor defined */
-};
-
-/* Populate struct tcpc_config from device-tree */
-static int tcpci_parse_config(struct tcpci *tcpci)
-{
-	struct tcpc_config *tcfg;
-	int ret = -EINVAL;
-
-	tcpci->controls_vbus = true; /* XXX */
-
-	tcpci->tcpc.config = devm_kzalloc(tcpci->dev, sizeof(*tcfg),
-					  GFP_KERNEL);
-	if (!tcpci->tcpc.config)
-		return -ENOMEM;
-
-	tcfg = tcpci->tcpc.config;
-
-	/* Get port-type */
-	ret = typec_get_port_type(tcpci->dev);
-	if (ret < 0) {
-		dev_err(tcpci->dev, "typec port type is NOT correct!\n");
-		return ret;
-	}
-	tcfg->type = ret;
-
-	if (tcfg->type == TYPEC_PORT_UFP)
-		goto sink;
-
-	/* Get source PDO */
-	tcfg->nr_src_pdo = device_property_read_u32_array(tcpci->dev,
-						"src-pdos", NULL, 0);
-	if (tcfg->nr_src_pdo <= 0) {
-		dev_err(tcpci->dev, "typec source pdo is missing!\n");
-		return -EINVAL;
-	}
-
-	tcfg->src_pdo = devm_kzalloc(tcpci->dev,
-		sizeof(*tcfg->src_pdo) * tcfg->nr_src_pdo, GFP_KERNEL);
-	if (!tcfg->src_pdo)
-		return -ENOMEM;
-
-	ret = device_property_read_u32_array(tcpci->dev, "src-pdos",
-				tcfg->src_pdo, tcfg->nr_src_pdo);
-	if (ret) {
-		dev_err(tcpci->dev, "Failed to read src pdo!\n");
-		return -EINVAL;
-	}
-
-	if (tcfg->type == TYPEC_PORT_DFP)
-		return 0;
-
-	/* Get the preferred power role for drp */
-	ret = typec_get_power_role(tcpci->dev);
-	if (ret < 0) {
-		dev_err(tcpci->dev, "typec preferred role is wrong!\n");
-		return ret;
-	}
-	tcfg->default_role = ret;
-sink:
-	/* Get sink power capability */
-	tcfg->nr_snk_pdo = device_property_read_u32_array(tcpci->dev,
-						"snk-pdos", NULL, 0);
-	if (tcfg->nr_snk_pdo <= 0) {
-		dev_err(tcpci->dev, "typec sink pdo is missing!\n");
-		return -EINVAL;
-	}
-
-	tcfg->snk_pdo = devm_kzalloc(tcpci->dev,
-		sizeof(*tcfg->snk_pdo) * tcfg->nr_snk_pdo, GFP_KERNEL);
-	if (!tcfg->snk_pdo)
-		return -ENOMEM;
-
-	ret = device_property_read_u32_array(tcpci->dev, "snk-pdos",
-				tcfg->snk_pdo, tcfg->nr_snk_pdo);
-	if (ret) {
-		dev_err(tcpci->dev, "Failed to read sink pdo!\n");
-		return -EINVAL;
-	}
-
-	if (device_property_read_u32(tcpci->dev, "max-snk-mv",
-				     &tcfg->max_snk_mv) ||
-		device_property_read_u32(tcpci->dev, "max-snk-ma",
-					 &tcfg->max_snk_ma) ||
-		device_property_read_u32(tcpci->dev, "op-snk-mw",
-					 &tcfg->operating_snk_mw)) {
-		dev_err(tcpci->dev, "Failed to read sink capability!\n");
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-static int tcpci_probe(struct i2c_client *client,
-		       const struct i2c_device_id *i2c_id)
-{
-	struct tcpci *tcpci;
-	int err;
-
-	tcpci = devm_kzalloc(&client->dev, sizeof(*tcpci), GFP_KERNEL);
-	if (!tcpci)
-		return -ENOMEM;
-
-	tcpci->client = client;
-	tcpci->dev = &client->dev;
-	i2c_set_clientdata(client, tcpci);
-	tcpci->regmap = devm_regmap_init_i2c(client, &tcpci_regmap_config);
-	if (IS_ERR(tcpci->regmap))
-		return PTR_ERR(tcpci->regmap);
-
-	tcpci->tcpc.init = tcpci_init;
-	tcpci->tcpc.get_vbus = tcpci_get_vbus;
-	tcpci->tcpc.set_vbus = tcpci_set_vbus;
-	tcpci->tcpc.set_cc = tcpci_set_cc;
-	tcpci->tcpc.get_cc = tcpci_get_cc;
-	tcpci->tcpc.set_polarity = tcpci_set_polarity;
-	tcpci->tcpc.set_vconn = tcpci_set_vconn;
-	tcpci->tcpc.start_drp_toggling = tcpci_start_drp_toggling;
-
-	tcpci->tcpc.set_pd_rx = tcpci_set_pd_rx;
-	tcpci->tcpc.set_roles = tcpci_set_roles;
-	tcpci->tcpc.pd_transmit = tcpci_pd_transmit;
-
-	err = tcpci_parse_config(tcpci);
-	if (err < 0)
-		return err;
-
-	/* Disable chip interrupts */
-	tcpci_write16(tcpci, TCPC_ALERT_MASK, 0);
-
-	tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
-	if (IS_ERR(tcpci->port))
-		return PTR_ERR(tcpci->port);
-
-	return devm_request_threaded_irq(tcpci->dev, client->irq, NULL,
-					tcpci_irq,
-					IRQF_ONESHOT | IRQF_TRIGGER_LOW,
-					dev_name(tcpci->dev), tcpci);
-}
-
-static int tcpci_remove(struct i2c_client *client)
-{
-	struct tcpci *tcpci = i2c_get_clientdata(client);
-
-	tcpm_unregister_port(tcpci->port);
-
-	return 0;
-}
-
-static const struct i2c_device_id tcpci_id[] = {
-	{ "tcpci", 0 },
-	{ }
-};
-MODULE_DEVICE_TABLE(i2c, tcpci_id);
-
-#ifdef CONFIG_OF
-static const struct of_device_id tcpci_of_match[] = {
-	{ .compatible = "usb,tcpci", },
-	{},
-};
-MODULE_DEVICE_TABLE(of, tcpci_of_match);
-#endif
-
-static struct i2c_driver tcpci_i2c_driver = {
-	.driver = {
-		.name = "tcpci",
-		.of_match_table = of_match_ptr(tcpci_of_match),
-	},
-	.probe = tcpci_probe,
-	.remove = tcpci_remove,
-	.id_table = tcpci_id,
-};
-module_i2c_driver(tcpci_i2c_driver);
-
-MODULE_DESCRIPTION("USB Type-C Port Controller Interface driver");
-MODULE_LICENSE("GPL");
diff --git a/drivers/staging/typec/tcpci.h b/drivers/staging/typec/tcpci.h
deleted file mode 100644
index 10b04c8..0000000
--- a/drivers/staging/typec/tcpci.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright 2015-2017 Google, Inc
- *
- * 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 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.
- *
- * USB Type-C Port Controller Interface.
- */
-
-#ifndef __LINUX_USB_TCPCI_H
-#define __LINUX_USB_TCPCI_H
-
-#define TCPC_VENDOR_ID			0x0
-#define TCPC_PRODUCT_ID			0x2
-#define TCPC_BCD_DEV			0x4
-#define TCPC_TC_REV			0x6
-#define TCPC_PD_REV			0x8
-#define TCPC_PD_INT_REV			0xa
-
-#define TCPC_ALERT			0x10
-#define TCPC_ALERT_VBUS_DISCNCT		BIT(11)
-#define TCPC_ALERT_RX_BUF_OVF		BIT(10)
-#define TCPC_ALERT_FAULT		BIT(9)
-#define TCPC_ALERT_V_ALARM_LO		BIT(8)
-#define TCPC_ALERT_V_ALARM_HI		BIT(7)
-#define TCPC_ALERT_TX_SUCCESS		BIT(6)
-#define TCPC_ALERT_TX_DISCARDED		BIT(5)
-#define TCPC_ALERT_TX_FAILED		BIT(4)
-#define TCPC_ALERT_RX_HARD_RST		BIT(3)
-#define TCPC_ALERT_RX_STATUS		BIT(2)
-#define TCPC_ALERT_POWER_STATUS		BIT(1)
-#define TCPC_ALERT_CC_STATUS		BIT(0)
-
-#define TCPC_ALERT_MASK			0x12
-#define TCPC_POWER_STATUS_MASK		0x14
-#define TCPC_FAULT_STATUS_MASK		0x15
-#define TCPC_CONFIG_STD_OUTPUT		0x18
-
-#define TCPC_TCPC_CTRL			0x19
-#define TCPC_TCPC_CTRL_ORIENTATION	BIT(0)
-
-#define TCPC_ROLE_CTRL			0x1a
-#define TCPC_ROLE_CTRL_DRP		BIT(6)
-#define TCPC_ROLE_CTRL_RP_VAL_SHIFT	4
-#define TCPC_ROLE_CTRL_RP_VAL_MASK	0x3
-#define TCPC_ROLE_CTRL_RP_VAL_DEF	0x0
-#define TCPC_ROLE_CTRL_RP_VAL_1_5	0x1
-#define TCPC_ROLE_CTRL_RP_VAL_3_0	0x2
-#define TCPC_ROLE_CTRL_CC2_SHIFT	2
-#define TCPC_ROLE_CTRL_CC2_MASK		0x3
-#define TCPC_ROLE_CTRL_CC1_SHIFT	0
-#define TCPC_ROLE_CTRL_CC1_MASK		0x3
-#define TCPC_ROLE_CTRL_CC_RA		0x0
-#define TCPC_ROLE_CTRL_CC_RP		0x1
-#define TCPC_ROLE_CTRL_CC_RD		0x2
-#define TCPC_ROLE_CTRL_CC_OPEN		0x3
-
-#define TCPC_FAULT_CTRL			0x1b
-
-#define TCPC_POWER_CTRL			0x1c
-#define TCPC_POWER_CTRL_VCONN_ENABLE	BIT(0)
-
-#define TCPC_CC_STATUS			0x1d
-#define TCPC_CC_STATUS_TERM		BIT(4)
-#define TCPC_CC_STATUS_CC2_SHIFT	2
-#define TCPC_CC_STATUS_CC2_MASK		0x3
-#define TCPC_CC_STATUS_CC1_SHIFT	0
-#define TCPC_CC_STATUS_CC1_MASK		0x3
-
-#define TCPC_POWER_STATUS		0x1e
-#define TCPC_POWER_STATUS_UNINIT	BIT(6)
-#define TCPC_POWER_STATUS_VBUS_DET	BIT(3)
-#define TCPC_POWER_STATUS_VBUS_PRES	BIT(2)
-
-#define TCPC_FAULT_STATUS		0x1f
-
-#define TCPC_COMMAND			0x23
-#define TCPC_CMD_WAKE_I2C		0x11
-#define TCPC_CMD_DISABLE_VBUS_DETECT	0x22
-#define TCPC_CMD_ENABLE_VBUS_DETECT	0x33
-#define TCPC_CMD_DISABLE_SINK_VBUS	0x44
-#define TCPC_CMD_SINK_VBUS		0x55
-#define TCPC_CMD_DISABLE_SRC_VBUS	0x66
-#define TCPC_CMD_SRC_VBUS_DEFAULT	0x77
-#define TCPC_CMD_SRC_VBUS_HIGH		0x88
-#define TCPC_CMD_LOOK4CONNECTION	0x99
-#define TCPC_CMD_RXONEMORE		0xAA
-#define TCPC_CMD_I2C_IDLE		0xFF
-
-#define TCPC_DEV_CAP_1			0x24
-#define TCPC_DEV_CAP_2			0x26
-#define TCPC_STD_INPUT_CAP		0x28
-#define TCPC_STD_OUTPUT_CAP		0x29
-
-#define TCPC_MSG_HDR_INFO		0x2e
-#define TCPC_MSG_HDR_INFO_DATA_ROLE	BIT(3)
-#define TCPC_MSG_HDR_INFO_PWR_ROLE	BIT(0)
-#define TCPC_MSG_HDR_INFO_REV_SHIFT	1
-#define TCPC_MSG_HDR_INFO_REV_MASK	0x3
-
-#define TCPC_RX_DETECT			0x2f
-#define TCPC_RX_DETECT_HARD_RESET	BIT(5)
-#define TCPC_RX_DETECT_SOP		BIT(0)
-
-#define TCPC_RX_BYTE_CNT		0x30
-#define TCPC_RX_BUF_FRAME_TYPE		0x31
-#define TCPC_RX_HDR			0x32
-#define TCPC_RX_DATA			0x34 /* through 0x4f */
-
-#define TCPC_TRANSMIT			0x50
-#define TCPC_TRANSMIT_RETRY_SHIFT	4
-#define TCPC_TRANSMIT_RETRY_MASK	0x3
-#define TCPC_TRANSMIT_TYPE_SHIFT	0
-#define TCPC_TRANSMIT_TYPE_MASK		0x7
-
-#define TCPC_TX_BYTE_CNT		0x51
-#define TCPC_TX_HDR			0x52
-#define TCPC_TX_DATA			0x54 /* through 0x6f */
-
-#define TCPC_VBUS_VOLTAGE			0x70
-#define TCPC_VBUS_SINK_DISCONNECT_THRESH	0x72
-#define TCPC_VBUS_STOP_DISCHARGE_THRESH		0x74
-#define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG		0x76
-#define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG		0x78
-
-#endif /* __LINUX_USB_TCPCI_H */
diff --git a/drivers/usb/typec/Kconfig b/drivers/usb/typec/Kconfig
index 819c0ed..33b04c4 100644
--- a/drivers/usb/typec/Kconfig
+++ b/drivers/usb/typec/Kconfig
@@ -14,6 +14,13 @@ config TYPEC_TCPM
 
 if TYPEC_TCPM
 
+config TYPEC_TCPCI
+	tristate "Type-C Port Controller Interface driver"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  Type-C Port Controller driver for TCPCI-compliant controller.
+
 source "drivers/usb/typec/fusb302/Kconfig"
 
 endif
diff --git a/drivers/usb/typec/Makefile b/drivers/usb/typec/Makefile
index b77688c..c2fbf17 100644
--- a/drivers/usb/typec/Makefile
+++ b/drivers/usb/typec/Makefile
@@ -3,3 +3,4 @@ obj-$(CONFIG_TYPEC_TCPM)	+= tcpm.o
 obj-y				+= fusb302/
 obj-$(CONFIG_TYPEC_WCOVE)	+= typec_wcove.o
 obj-$(CONFIG_TYPEC_UCSI)	+= ucsi/
+obj-$(CONFIG_TYPEC_TCPCI)	+= tcpci.o
diff --git a/drivers/usb/typec/tcpci.c b/drivers/usb/typec/tcpci.c
new file mode 100644
index 0000000..293a07c
--- /dev/null
+++ b/drivers/usb/typec/tcpci.c
@@ -0,0 +1,637 @@
+/*
+ * Copyright 2015-2017 Google, Inc
+ *
+ * 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 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.
+ *
+ * USB Type-C Port Controller Interface.
+ */
+
+#include <linux/delay.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/regmap.h>
+#include <linux/usb/pd.h>
+#include <linux/usb/tcpm.h>
+#include <linux/usb/typec.h>
+
+#include "tcpci.h"
+
+#define PD_RETRY_COUNT 3
+
+struct tcpci {
+	struct device *dev;
+	struct i2c_client *client;
+
+	struct tcpm_port *port;
+
+	struct regmap *regmap;
+
+	bool controls_vbus;
+
+	struct tcpc_dev tcpc;
+};
+
+static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc)
+{
+	return container_of(tcpc, struct tcpci, tcpc);
+}
+
+static int tcpci_read16(struct tcpci *tcpci, unsigned int reg,
+			unsigned int *val)
+{
+	return regmap_raw_read(tcpci->regmap, reg, val, sizeof(u16));
+}
+
+static int tcpci_write16(struct tcpci *tcpci, unsigned int reg, u16 val)
+{
+	return regmap_raw_write(tcpci->regmap, reg, &val, sizeof(u16));
+}
+
+static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc,
+			bool attached, enum typec_cc_polarity polarity)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+	unsigned int reg = 0, reg_cc1 = 0, reg_cc2 = 0;
+	int ret;
+
+	switch (cc) {
+	case TYPEC_CC_RA:
+		reg = (TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC1_SHIFT) |
+			(TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC2_SHIFT);
+		break;
+	case TYPEC_CC_RD:
+		reg_cc1 = TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT;
+		reg_cc2 = TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT;
+		break;
+	case TYPEC_CC_RP_DEF:
+		reg_cc1 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT;
+		reg_cc2 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT;
+		reg = TCPC_ROLE_CTRL_RP_VAL_DEF << TCPC_ROLE_CTRL_RP_VAL_SHIFT;
+		break;
+	case TYPEC_CC_RP_1_5:
+		reg_cc1 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT;
+		reg_cc2 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT;
+		reg = TCPC_ROLE_CTRL_RP_VAL_1_5 << TCPC_ROLE_CTRL_RP_VAL_SHIFT;
+		break;
+	case TYPEC_CC_RP_3_0:
+		reg_cc1 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT;
+		reg_cc2 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT;
+		reg = TCPC_ROLE_CTRL_RP_VAL_3_0 << TCPC_ROLE_CTRL_RP_VAL_SHIFT;
+		break;
+	case TYPEC_CC_OPEN:
+	default:
+		reg = (TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC1_SHIFT) |
+			(TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC2_SHIFT);
+		break;
+	}
+
+	if (!attached)
+		reg |= reg_cc1 | reg_cc2;
+	else if (polarity == TYPEC_POLARITY_CC1)
+		reg |= reg_cc1;
+	else
+		reg |= reg_cc2;
+
+	ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int tcpci_start_drp_toggling(struct tcpc_dev *tcpc,
+				    enum typec_cc_status cc)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+	unsigned int reg = TCPC_ROLE_CTRL_DRP;
+	int ret;
+
+	switch (cc) {
+	default:
+	case TYPEC_CC_RP_DEF:
+		reg |= (TCPC_ROLE_CTRL_RP_VAL_DEF <<
+			TCPC_ROLE_CTRL_RP_VAL_SHIFT);
+		break;
+	case TYPEC_CC_RP_1_5:
+		reg |= (TCPC_ROLE_CTRL_RP_VAL_1_5 <<
+			TCPC_ROLE_CTRL_RP_VAL_SHIFT);
+		break;
+	case TYPEC_CC_RP_3_0:
+		reg |= (TCPC_ROLE_CTRL_RP_VAL_3_0 <<
+			TCPC_ROLE_CTRL_RP_VAL_SHIFT);
+		break;
+	}
+
+	if (cc == TYPEC_CC_RD)
+		reg |= (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) |
+			(TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT);
+	else
+		reg |= (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) |
+			(TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT);
+
+	ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
+	if (ret < 0)
+		return ret;
+
+	return regmap_write(tcpci->regmap, TCPC_COMMAND,
+				TCPC_CMD_LOOK4CONNECTION);
+}
+
+static enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink)
+{
+	switch (cc) {
+	case 0x1:
+		return sink ? TYPEC_CC_RP_DEF : TYPEC_CC_RA;
+	case 0x2:
+		return sink ? TYPEC_CC_RP_1_5 : TYPEC_CC_RD;
+	case 0x3:
+		if (sink)
+			return TYPEC_CC_RP_3_0;
+	case 0x0:
+	default:
+		return TYPEC_CC_OPEN;
+	}
+}
+
+static int tcpci_get_cc(struct tcpc_dev *tcpc,
+			enum typec_cc_status *cc1, enum typec_cc_status *cc2)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+	unsigned int reg;
+	int ret;
+
+	ret = regmap_read(tcpci->regmap, TCPC_CC_STATUS, &reg);
+	if (ret < 0)
+		return ret;
+
+	*cc1 = tcpci_to_typec_cc((reg >> TCPC_CC_STATUS_CC1_SHIFT) &
+				 TCPC_CC_STATUS_CC1_MASK,
+				 reg & TCPC_CC_STATUS_TERM);
+	*cc2 = tcpci_to_typec_cc((reg >> TCPC_CC_STATUS_CC2_SHIFT) &
+				 TCPC_CC_STATUS_CC2_MASK,
+				 reg & TCPC_CC_STATUS_TERM);
+
+	return 0;
+}
+
+static int tcpci_set_polarity(struct tcpc_dev *tcpc,
+			      enum typec_cc_polarity polarity)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+	int ret;
+
+	ret = regmap_write(tcpci->regmap, TCPC_TCPC_CTRL,
+			   (polarity == TYPEC_POLARITY_CC2) ?
+			   TCPC_TCPC_CTRL_ORIENTATION : 0);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+
+	return regmap_update_bits(tcpci->regmap, TCPC_POWER_CTRL,
+				TCPC_POWER_CTRL_VCONN_ENABLE,
+				enable ? TCPC_POWER_CTRL_VCONN_ENABLE : 0);
+}
+
+static int tcpci_set_roles(struct tcpc_dev *tcpc, bool attached,
+			   enum typec_role role, enum typec_data_role data)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+	unsigned int reg;
+	int ret;
+
+	reg = PD_REV20 << TCPC_MSG_HDR_INFO_REV_SHIFT;
+	if (role == TYPEC_SOURCE)
+		reg |= TCPC_MSG_HDR_INFO_PWR_ROLE;
+	if (data == TYPEC_HOST)
+		reg |= TCPC_MSG_HDR_INFO_DATA_ROLE;
+	ret = regmap_write(tcpci->regmap, TCPC_MSG_HDR_INFO, reg);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int tcpci_set_pd_rx(struct tcpc_dev *tcpc, bool enable)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+	unsigned int reg = 0;
+	int ret;
+
+	if (enable)
+		reg = TCPC_RX_DETECT_SOP | TCPC_RX_DETECT_HARD_RESET;
+	ret = regmap_write(tcpci->regmap, TCPC_RX_DETECT, reg);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int tcpci_get_vbus(struct tcpc_dev *tcpc)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+	unsigned int reg;
+	int ret;
+
+	ret = regmap_read(tcpci->regmap, TCPC_POWER_STATUS, &reg);
+	if (ret < 0)
+		return ret;
+
+	return !!(reg & TCPC_POWER_STATUS_VBUS_PRES);
+}
+
+static int tcpci_set_vbus(struct tcpc_dev *tcpc, bool source, bool sink)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+	int ret;
+
+	/* Disable both source and sink first before enabling anything */
+
+	if (!source) {
+		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
+				   TCPC_CMD_DISABLE_SRC_VBUS);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (!sink) {
+		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
+				   TCPC_CMD_DISABLE_SINK_VBUS);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (source) {
+		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
+				   TCPC_CMD_SRC_VBUS_DEFAULT);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (sink) {
+		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
+				   TCPC_CMD_SINK_VBUS);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int tcpci_pd_transmit(struct tcpc_dev *tcpc,
+			     enum tcpm_transmit_type type,
+			     const struct pd_message *msg)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+	unsigned int reg, cnt, header;
+	int ret;
+
+	cnt = msg ? pd_header_cnt(msg->header) * 4 : 0;
+	ret = regmap_write(tcpci->regmap, TCPC_TX_BYTE_CNT, cnt + 2);
+	if (ret < 0)
+		return ret;
+
+	header = msg ? msg->header : 0;
+	ret = tcpci_write16(tcpci, TCPC_TX_HDR, header);
+	if (ret < 0)
+		return ret;
+
+	if (cnt > 0) {
+		ret = regmap_raw_write(tcpci->regmap, TCPC_TX_DATA,
+				       &msg->payload, cnt);
+		if (ret < 0)
+			return ret;
+	}
+
+	reg = (PD_RETRY_COUNT << TCPC_TRANSMIT_RETRY_SHIFT) |
+		(type << TCPC_TRANSMIT_TYPE_SHIFT);
+	ret = regmap_write(tcpci->regmap, TCPC_TRANSMIT, reg);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int tcpci_vbus_detect(struct tcpc_dev *tcpc, bool enable)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+	int ret;
+
+	if (enable) {
+		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
+				   TCPC_CMD_ENABLE_VBUS_DETECT);
+		if (ret < 0)
+			return ret;
+	} else {
+		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
+				   TCPC_CMD_DISABLE_VBUS_DETECT);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int tcpci_init(struct tcpc_dev *tcpc)
+{
+	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
+	unsigned long timeout = jiffies + msecs_to_jiffies(2000); /* XXX */
+	unsigned int reg;
+	int ret;
+
+	while (time_before_eq(jiffies, timeout)) {
+		ret = regmap_read(tcpci->regmap, TCPC_POWER_STATUS, &reg);
+		if (ret < 0)
+			return ret;
+		if (!(reg & TCPC_POWER_STATUS_UNINIT))
+			break;
+		usleep_range(10000, 20000);
+	}
+	if (time_after(jiffies, timeout))
+		return -ETIMEDOUT;
+
+	/* Clear all events */
+	ret = tcpci_write16(tcpci, TCPC_ALERT, 0xffff);
+	if (ret < 0)
+		return ret;
+
+	if (tcpci->controls_vbus)
+		reg = TCPC_POWER_STATUS_VBUS_PRES;
+	else
+		reg = 0;
+	ret = regmap_write(tcpci->regmap, TCPC_POWER_STATUS_MASK, reg);
+	if (ret < 0)
+		return ret;
+
+	/* Enable Vbus detection */
+	tcpci_vbus_detect(tcpc, true);
+
+	reg = TCPC_ALERT_TX_SUCCESS | TCPC_ALERT_TX_FAILED |
+		TCPC_ALERT_TX_DISCARDED | TCPC_ALERT_RX_STATUS |
+		TCPC_ALERT_RX_HARD_RST | TCPC_ALERT_CC_STATUS;
+	if (tcpci->controls_vbus)
+		reg |= TCPC_ALERT_POWER_STATUS;
+	return tcpci_write16(tcpci, TCPC_ALERT_MASK, reg);
+}
+
+static irqreturn_t tcpci_irq(int irq, void *dev_id)
+{
+	struct tcpci *tcpci = dev_id;
+	unsigned int status, reg;
+
+	tcpci_read16(tcpci, TCPC_ALERT, &status);
+
+	/*
+	 * Clear alert status for everything except RX_STATUS, which shouldn't
+	 * be cleared until we have successfully retrieved message.
+	 */
+	if (status & ~TCPC_ALERT_RX_STATUS)
+		tcpci_write16(tcpci, TCPC_ALERT,
+			      status & ~TCPC_ALERT_RX_STATUS);
+
+	if (status & TCPC_ALERT_CC_STATUS)
+		tcpm_cc_change(tcpci->port);
+
+	if (status & TCPC_ALERT_POWER_STATUS) {
+		regmap_read(tcpci->regmap, TCPC_POWER_STATUS_MASK, &reg);
+
+		/*
+		 * If power status mask has been reset, then the TCPC
+		 * has reset.
+		 */
+		if (reg == 0xff)
+			tcpm_tcpc_reset(tcpci->port);
+		else
+			tcpm_vbus_change(tcpci->port);
+	}
+
+	if (status & TCPC_ALERT_RX_STATUS) {
+		struct pd_message msg;
+		unsigned int cnt;
+
+		regmap_read(tcpci->regmap, TCPC_RX_BYTE_CNT, &cnt);
+
+		tcpci_read16(tcpci, TCPC_RX_HDR, &reg);
+		msg.header = reg;
+
+		if (WARN_ON(cnt > sizeof(msg.payload)))
+			cnt = sizeof(msg.payload);
+
+		if (cnt > 0)
+			regmap_raw_read(tcpci->regmap, TCPC_RX_DATA,
+					&msg.payload, cnt);
+
+		/* Read complete, clear RX status alert bit */
+		tcpci_write16(tcpci, TCPC_ALERT, TCPC_ALERT_RX_STATUS);
+
+		tcpm_pd_receive(tcpci->port, &msg);
+	}
+
+	if (status & TCPC_ALERT_RX_HARD_RST)
+		tcpm_pd_hard_reset(tcpci->port);
+
+	if (status & TCPC_ALERT_TX_SUCCESS)
+		tcpm_pd_transmit_complete(tcpci->port, TCPC_TX_SUCCESS);
+	else if (status & TCPC_ALERT_TX_DISCARDED)
+		tcpm_pd_transmit_complete(tcpci->port, TCPC_TX_DISCARDED);
+	else if (status & TCPC_ALERT_TX_FAILED)
+		tcpm_pd_transmit_complete(tcpci->port, TCPC_TX_FAILED);
+
+	return IRQ_HANDLED;
+}
+
+static const struct regmap_config tcpci_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+
+	.max_register = 0x7F, /* 0x80 .. 0xFF are vendor defined */
+};
+
+/* Populate struct tcpc_config from device-tree */
+static int tcpci_parse_config(struct tcpci *tcpci)
+{
+	struct tcpc_config *tcfg;
+	int ret = -EINVAL;
+
+	tcpci->controls_vbus = true; /* XXX */
+
+	tcpci->tcpc.config = devm_kzalloc(tcpci->dev, sizeof(*tcfg),
+					  GFP_KERNEL);
+	if (!tcpci->tcpc.config)
+		return -ENOMEM;
+
+	tcfg = tcpci->tcpc.config;
+
+	/* Get port-type */
+	ret = typec_get_port_type(tcpci->dev);
+	if (ret < 0) {
+		dev_err(tcpci->dev, "typec port type is NOT correct!\n");
+		return ret;
+	}
+	tcfg->type = ret;
+
+	if (tcfg->type == TYPEC_PORT_UFP)
+		goto sink;
+
+	/* Get source PDO */
+	tcfg->nr_src_pdo = device_property_read_u32_array(tcpci->dev,
+						"src-pdos", NULL, 0);
+	if (tcfg->nr_src_pdo <= 0) {
+		dev_err(tcpci->dev, "typec source pdo is missing!\n");
+		return -EINVAL;
+	}
+
+	tcfg->src_pdo = devm_kzalloc(tcpci->dev,
+		sizeof(*tcfg->src_pdo) * tcfg->nr_src_pdo, GFP_KERNEL);
+	if (!tcfg->src_pdo)
+		return -ENOMEM;
+
+	ret = device_property_read_u32_array(tcpci->dev, "src-pdos",
+				tcfg->src_pdo, tcfg->nr_src_pdo);
+	if (ret) {
+		dev_err(tcpci->dev, "Failed to read src pdo!\n");
+		return -EINVAL;
+	}
+
+	if (tcfg->type == TYPEC_PORT_DFP)
+		return 0;
+
+	/* Get the preferred power role for drp */
+	ret = typec_get_power_role(tcpci->dev);
+	if (ret < 0) {
+		dev_err(tcpci->dev, "typec preferred role is wrong!\n");
+		return ret;
+	}
+	tcfg->default_role = ret;
+sink:
+	/* Get sink power capability */
+	tcfg->nr_snk_pdo = device_property_read_u32_array(tcpci->dev,
+						"snk-pdos", NULL, 0);
+	if (tcfg->nr_snk_pdo <= 0) {
+		dev_err(tcpci->dev, "typec sink pdo is missing!\n");
+		return -EINVAL;
+	}
+
+	tcfg->snk_pdo = devm_kzalloc(tcpci->dev,
+		sizeof(*tcfg->snk_pdo) * tcfg->nr_snk_pdo, GFP_KERNEL);
+	if (!tcfg->snk_pdo)
+		return -ENOMEM;
+
+	ret = device_property_read_u32_array(tcpci->dev, "snk-pdos",
+				tcfg->snk_pdo, tcfg->nr_snk_pdo);
+	if (ret) {
+		dev_err(tcpci->dev, "Failed to read sink pdo!\n");
+		return -EINVAL;
+	}
+
+	if (device_property_read_u32(tcpci->dev, "max-snk-mv",
+				     &tcfg->max_snk_mv) ||
+		device_property_read_u32(tcpci->dev, "max-snk-ma",
+					 &tcfg->max_snk_ma) ||
+		device_property_read_u32(tcpci->dev, "op-snk-mw",
+					 &tcfg->operating_snk_mw)) {
+		dev_err(tcpci->dev, "Failed to read sink capability!\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int tcpci_probe(struct i2c_client *client,
+		       const struct i2c_device_id *i2c_id)
+{
+	struct tcpci *tcpci;
+	int err;
+
+	tcpci = devm_kzalloc(&client->dev, sizeof(*tcpci), GFP_KERNEL);
+	if (!tcpci)
+		return -ENOMEM;
+
+	tcpci->client = client;
+	tcpci->dev = &client->dev;
+	i2c_set_clientdata(client, tcpci);
+	tcpci->regmap = devm_regmap_init_i2c(client, &tcpci_regmap_config);
+	if (IS_ERR(tcpci->regmap))
+		return PTR_ERR(tcpci->regmap);
+
+	tcpci->tcpc.init = tcpci_init;
+	tcpci->tcpc.get_vbus = tcpci_get_vbus;
+	tcpci->tcpc.set_vbus = tcpci_set_vbus;
+	tcpci->tcpc.set_cc = tcpci_set_cc;
+	tcpci->tcpc.get_cc = tcpci_get_cc;
+	tcpci->tcpc.set_polarity = tcpci_set_polarity;
+	tcpci->tcpc.set_vconn = tcpci_set_vconn;
+	tcpci->tcpc.start_drp_toggling = tcpci_start_drp_toggling;
+
+	tcpci->tcpc.set_pd_rx = tcpci_set_pd_rx;
+	tcpci->tcpc.set_roles = tcpci_set_roles;
+	tcpci->tcpc.pd_transmit = tcpci_pd_transmit;
+
+	err = tcpci_parse_config(tcpci);
+	if (err < 0)
+		return err;
+
+	/* Disable chip interrupts */
+	tcpci_write16(tcpci, TCPC_ALERT_MASK, 0);
+
+	tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
+	if (IS_ERR(tcpci->port))
+		return PTR_ERR(tcpci->port);
+
+	return devm_request_threaded_irq(tcpci->dev, client->irq, NULL,
+					tcpci_irq,
+					IRQF_ONESHOT | IRQF_TRIGGER_LOW,
+					dev_name(tcpci->dev), tcpci);
+}
+
+static int tcpci_remove(struct i2c_client *client)
+{
+	struct tcpci *tcpci = i2c_get_clientdata(client);
+
+	tcpm_unregister_port(tcpci->port);
+
+	return 0;
+}
+
+static const struct i2c_device_id tcpci_id[] = {
+	{ "tcpci", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, tcpci_id);
+
+#ifdef CONFIG_OF
+static const struct of_device_id tcpci_of_match[] = {
+	{ .compatible = "usb,tcpci", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, tcpci_of_match);
+#endif
+
+static struct i2c_driver tcpci_i2c_driver = {
+	.driver = {
+		.name = "tcpci",
+		.of_match_table = of_match_ptr(tcpci_of_match),
+	},
+	.probe = tcpci_probe,
+	.remove = tcpci_remove,
+	.id_table = tcpci_id,
+};
+module_i2c_driver(tcpci_i2c_driver);
+
+MODULE_DESCRIPTION("USB Type-C Port Controller Interface driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/usb/typec/tcpci.h b/drivers/usb/typec/tcpci.h
new file mode 100644
index 0000000..10b04c8
--- /dev/null
+++ b/drivers/usb/typec/tcpci.h
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2015-2017 Google, Inc
+ *
+ * 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 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.
+ *
+ * USB Type-C Port Controller Interface.
+ */
+
+#ifndef __LINUX_USB_TCPCI_H
+#define __LINUX_USB_TCPCI_H
+
+#define TCPC_VENDOR_ID			0x0
+#define TCPC_PRODUCT_ID			0x2
+#define TCPC_BCD_DEV			0x4
+#define TCPC_TC_REV			0x6
+#define TCPC_PD_REV			0x8
+#define TCPC_PD_INT_REV			0xa
+
+#define TCPC_ALERT			0x10
+#define TCPC_ALERT_VBUS_DISCNCT		BIT(11)
+#define TCPC_ALERT_RX_BUF_OVF		BIT(10)
+#define TCPC_ALERT_FAULT		BIT(9)
+#define TCPC_ALERT_V_ALARM_LO		BIT(8)
+#define TCPC_ALERT_V_ALARM_HI		BIT(7)
+#define TCPC_ALERT_TX_SUCCESS		BIT(6)
+#define TCPC_ALERT_TX_DISCARDED		BIT(5)
+#define TCPC_ALERT_TX_FAILED		BIT(4)
+#define TCPC_ALERT_RX_HARD_RST		BIT(3)
+#define TCPC_ALERT_RX_STATUS		BIT(2)
+#define TCPC_ALERT_POWER_STATUS		BIT(1)
+#define TCPC_ALERT_CC_STATUS		BIT(0)
+
+#define TCPC_ALERT_MASK			0x12
+#define TCPC_POWER_STATUS_MASK		0x14
+#define TCPC_FAULT_STATUS_MASK		0x15
+#define TCPC_CONFIG_STD_OUTPUT		0x18
+
+#define TCPC_TCPC_CTRL			0x19
+#define TCPC_TCPC_CTRL_ORIENTATION	BIT(0)
+
+#define TCPC_ROLE_CTRL			0x1a
+#define TCPC_ROLE_CTRL_DRP		BIT(6)
+#define TCPC_ROLE_CTRL_RP_VAL_SHIFT	4
+#define TCPC_ROLE_CTRL_RP_VAL_MASK	0x3
+#define TCPC_ROLE_CTRL_RP_VAL_DEF	0x0
+#define TCPC_ROLE_CTRL_RP_VAL_1_5	0x1
+#define TCPC_ROLE_CTRL_RP_VAL_3_0	0x2
+#define TCPC_ROLE_CTRL_CC2_SHIFT	2
+#define TCPC_ROLE_CTRL_CC2_MASK		0x3
+#define TCPC_ROLE_CTRL_CC1_SHIFT	0
+#define TCPC_ROLE_CTRL_CC1_MASK		0x3
+#define TCPC_ROLE_CTRL_CC_RA		0x0
+#define TCPC_ROLE_CTRL_CC_RP		0x1
+#define TCPC_ROLE_CTRL_CC_RD		0x2
+#define TCPC_ROLE_CTRL_CC_OPEN		0x3
+
+#define TCPC_FAULT_CTRL			0x1b
+
+#define TCPC_POWER_CTRL			0x1c
+#define TCPC_POWER_CTRL_VCONN_ENABLE	BIT(0)
+
+#define TCPC_CC_STATUS			0x1d
+#define TCPC_CC_STATUS_TERM		BIT(4)
+#define TCPC_CC_STATUS_CC2_SHIFT	2
+#define TCPC_CC_STATUS_CC2_MASK		0x3
+#define TCPC_CC_STATUS_CC1_SHIFT	0
+#define TCPC_CC_STATUS_CC1_MASK		0x3
+
+#define TCPC_POWER_STATUS		0x1e
+#define TCPC_POWER_STATUS_UNINIT	BIT(6)
+#define TCPC_POWER_STATUS_VBUS_DET	BIT(3)
+#define TCPC_POWER_STATUS_VBUS_PRES	BIT(2)
+
+#define TCPC_FAULT_STATUS		0x1f
+
+#define TCPC_COMMAND			0x23
+#define TCPC_CMD_WAKE_I2C		0x11
+#define TCPC_CMD_DISABLE_VBUS_DETECT	0x22
+#define TCPC_CMD_ENABLE_VBUS_DETECT	0x33
+#define TCPC_CMD_DISABLE_SINK_VBUS	0x44
+#define TCPC_CMD_SINK_VBUS		0x55
+#define TCPC_CMD_DISABLE_SRC_VBUS	0x66
+#define TCPC_CMD_SRC_VBUS_DEFAULT	0x77
+#define TCPC_CMD_SRC_VBUS_HIGH		0x88
+#define TCPC_CMD_LOOK4CONNECTION	0x99
+#define TCPC_CMD_RXONEMORE		0xAA
+#define TCPC_CMD_I2C_IDLE		0xFF
+
+#define TCPC_DEV_CAP_1			0x24
+#define TCPC_DEV_CAP_2			0x26
+#define TCPC_STD_INPUT_CAP		0x28
+#define TCPC_STD_OUTPUT_CAP		0x29
+
+#define TCPC_MSG_HDR_INFO		0x2e
+#define TCPC_MSG_HDR_INFO_DATA_ROLE	BIT(3)
+#define TCPC_MSG_HDR_INFO_PWR_ROLE	BIT(0)
+#define TCPC_MSG_HDR_INFO_REV_SHIFT	1
+#define TCPC_MSG_HDR_INFO_REV_MASK	0x3
+
+#define TCPC_RX_DETECT			0x2f
+#define TCPC_RX_DETECT_HARD_RESET	BIT(5)
+#define TCPC_RX_DETECT_SOP		BIT(0)
+
+#define TCPC_RX_BYTE_CNT		0x30
+#define TCPC_RX_BUF_FRAME_TYPE		0x31
+#define TCPC_RX_HDR			0x32
+#define TCPC_RX_DATA			0x34 /* through 0x4f */
+
+#define TCPC_TRANSMIT			0x50
+#define TCPC_TRANSMIT_RETRY_SHIFT	4
+#define TCPC_TRANSMIT_RETRY_MASK	0x3
+#define TCPC_TRANSMIT_TYPE_SHIFT	0
+#define TCPC_TRANSMIT_TYPE_MASK		0x7
+
+#define TCPC_TX_BYTE_CNT		0x51
+#define TCPC_TX_HDR			0x52
+#define TCPC_TX_DATA			0x54 /* through 0x6f */
+
+#define TCPC_VBUS_VOLTAGE			0x70
+#define TCPC_VBUS_SINK_DISCONNECT_THRESH	0x72
+#define TCPC_VBUS_STOP_DISCHARGE_THRESH		0x74
+#define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG		0x76
+#define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG		0x78
+
+#endif /* __LINUX_USB_TCPCI_H */
-- 
2.6.6

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [PATCH 12/12] staging: typec: tcpci: move tcpci driver out of staging
       [not found]     ` <1506386727-16370-13-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
@ 2017-09-26  6:57       ` Greg KH
       [not found]         ` <20170926065749.GE6250-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 34+ messages in thread
From: Greg KH @ 2017-09-26  6:57 UTC (permalink / raw)
  To: Li Jun
  Cc: linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA,
	yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On Tue, Sep 26, 2017 at 08:45:27AM +0800, Li Jun wrote:
> Move TCPCI(Typec port controller interface) driver out of staging.
> 
> Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
> ---
>  drivers/staging/Kconfig        |   2 -
>  drivers/staging/Makefile       |   1 -
>  drivers/staging/typec/Kconfig  |  14 -
>  drivers/staging/typec/Makefile |   1 -
>  drivers/staging/typec/TODO     |   5 -
>  drivers/staging/typec/tcpci.c  | 637 -----------------------------------------
>  drivers/staging/typec/tcpci.h  | 133 ---------
>  drivers/usb/typec/Kconfig      |   7 +
>  drivers/usb/typec/Makefile     |   1 +
>  drivers/usb/typec/tcpci.c      | 637 +++++++++++++++++++++++++++++++++++++++++
>  drivers/usb/typec/tcpci.h      | 133 +++++++++
>  11 files changed, 778 insertions(+), 793 deletions(-)


Creating patches like this with "-M" to git format-patch is nice, that
way we see the rename as just a rename, and not a big delete/add patch.

Can you do that instead and resend this series?

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* RE: [PATCH 12/12] staging: typec: tcpci: move tcpci driver out of staging
       [not found]         ` <20170926065749.GE6250-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
@ 2017-09-26  7:16           ` Jun Li
  0 siblings, 0 replies; 34+ messages in thread
From: Jun Li @ 2017-09-26  7:16 UTC (permalink / raw)
  To: Greg KH
  Cc: linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA,
	yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	Peter Chen, A.s. Dong, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

Hi,

> -----Original Message-----
> From: Greg KH [mailto:gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org]
> Sent: Tuesday, September 26, 2017 2:58 PM
> To: Jun Li <jun.li-3arQi8VN3Tc@public.gmane.org>
> Cc: linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org; robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org; mark.rutland-5wv7dgnIgG8@public.gmane.org;
> heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org; yueyao-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org; o_leveque-1tsiiZ//OF9QFI55V6+gNQ@public.gmane.org;
> Peter Chen <peter.chen-3arQi8VN3Tc@public.gmane.org>; A.s. Dong <aisheng.dong-3arQi8VN3Tc@public.gmane.org>; linux-
> usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> Subject: Re: [PATCH 12/12] staging: typec: tcpci: move tcpci driver out of
> staging
> 
> On Tue, Sep 26, 2017 at 08:45:27AM +0800, Li Jun wrote:
> > Move TCPCI(Typec port controller interface) driver out of staging.
> >
> > Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
> > ---
> >  drivers/staging/Kconfig        |   2 -
> >  drivers/staging/Makefile       |   1 -
> >  drivers/staging/typec/Kconfig  |  14 -
> >  drivers/staging/typec/Makefile |   1 -
> >  drivers/staging/typec/TODO     |   5 -
> >  drivers/staging/typec/tcpci.c  | 637
> > -----------------------------------------
> >  drivers/staging/typec/tcpci.h  | 133 ---------
> >  drivers/usb/typec/Kconfig      |   7 +
> >  drivers/usb/typec/Makefile     |   1 +
> >  drivers/usb/typec/tcpci.c      | 637
> +++++++++++++++++++++++++++++++++++++++++
> >  drivers/usb/typec/tcpci.h      | 133 +++++++++
> >  11 files changed, 778 insertions(+), 793 deletions(-)
> 
> 
> Creating patches like this with "-M" to git format-patch is nice, that way we see
> the rename as just a rename, and not a big delete/add patch.
> 
> Can you do that instead and resend this series?

Thanks, I will do that and resend.

Li Jun
> 
> thanks,
> 
> greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 09/12] usb: typec: tcpm: only drives the connected cc line when attached
       [not found]     ` <1506386727-16370-10-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
@ 2017-09-26  7:16       ` Guenter Roeck
       [not found]         ` <9c461105-fa96-3989-5a95-b9f82b154ea2-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
  0 siblings, 1 reply; 34+ messages in thread
From: Guenter Roeck @ 2017-09-26  7:16 UTC (permalink / raw)
  To: Li Jun, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On 09/25/2017 05:45 PM, Li Jun wrote:
> As we should only drive connected cc line to be the right state when
> attached, and keeps the other one to be open, so update the set_cc
> interface for that.
> 
> Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
> ---
>   drivers/usb/typec/tcpm.c | 12 +++++++++++-
>   include/linux/usb/tcpm.h |  3 ++-
>   2 files changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
> index 38a6223..c9966ee 100644
> --- a/drivers/usb/typec/tcpm.c
> +++ b/drivers/usb/typec/tcpm.c
> @@ -1857,9 +1857,15 @@ static bool tcpm_start_drp_toggling(struct tcpm_port *port,
>   
>   static void tcpm_set_cc(struct tcpm_port *port, enum typec_cc_status cc)
>   {
> +	bool attached;
> +
>   	tcpm_log(port, "cc:=%d", cc);
>   	port->cc_req = cc;
> -	port->tcpc->set_cc(port->tcpc, cc);
> +	if (port->state == SRC_ATTACHED || port->state == SNK_ATTACHED)
> +		attached = true;
> +	else
> +		attached = false;
> +	port->tcpc->set_cc(port->tcpc, cc, attached, port->polarity);

Polarity should be set with set_polarity(). Is it necessary to duplicate that ?

>   }
>   
>   static int tcpm_init_vbus(struct tcpm_port *port)
> @@ -1913,6 +1919,8 @@ static int tcpm_src_attach(struct tcpm_port *port)
>   	if (ret < 0)
>   		return ret;
>   
> +	tcpm_set_cc(port, tcpm_rp_cc(port));
> +
>   	ret = tcpm_set_roles(port, true, TYPEC_SOURCE, TYPEC_HOST);
>   	if (ret < 0)
>   		return ret;
> @@ -2028,6 +2036,8 @@ static int tcpm_snk_attach(struct tcpm_port *port)
>   	if (ret < 0)
>   		return ret;
>   
> +	tcpm_set_cc(port, TYPEC_CC_RD);
> +
>   	ret = tcpm_set_roles(port, true, TYPEC_SINK, TYPEC_DEVICE);
>   	if (ret < 0)
>   		return ret;
> diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
> index a67cf77..a007e2a1 100644
> --- a/include/linux/usb/tcpm.h
> +++ b/include/linux/usb/tcpm.h
> @@ -159,7 +159,8 @@ struct tcpc_dev {
>   	int (*init)(struct tcpc_dev *dev);
>   	int (*get_vbus)(struct tcpc_dev *dev);
>   	int (*get_current_limit)(struct tcpc_dev *dev);
> -	int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc);
> +	int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc,
> +			bool attached, enum typec_cc_polarity polarity);
>   	int (*get_cc)(struct tcpc_dev *dev, enum typec_cc_status *cc1,
>   		      enum typec_cc_status *cc2);
>   	int (*set_polarity)(struct tcpc_dev *dev,
> 

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 01/12] usb: typec: add API to get port type and preferred role
       [not found]     ` <1506386727-16370-2-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
@ 2017-09-26  8:02       ` Heikki Krogerus
       [not found]         ` <20170926080231.GB14296-FZxXFokcWpatqXYlAKuG4QC/G2K4zDHf@public.gmane.org>
  2017-09-26 13:20       ` Guenter Roeck
  1 sibling, 1 reply; 34+ messages in thread
From: Heikki Krogerus @ 2017-09-26  8:02 UTC (permalink / raw)
  To: Li Jun
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, yueyao-hpIqsD4AKlfQT0dZR+AlfA,
	o_leveque-1tsiiZ//OF9QFI55V6+gNQ, peter.chen-3arQi8VN3Tc,
	aisheng.dong-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

Hi,

On Tue, Sep 26, 2017 at 08:45:16AM +0800, Li Jun wrote:
> This patch add 2 APIs to get port type and preferred role from firmware
> description.
> 
> Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
> ---
>  drivers/usb/typec/typec.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/usb/typec.h |  2 ++
>  2 files changed, 47 insertions(+)
> 
> diff --git a/drivers/usb/typec/typec.c b/drivers/usb/typec/typec.c
> index 24e355b..0c77cc4 100644
> --- a/drivers/usb/typec/typec.c
> +++ b/drivers/usb/typec/typec.c
> @@ -12,6 +12,7 @@
>  #include <linux/device.h>
>  #include <linux/module.h>
>  #include <linux/mutex.h>
> +#include <linux/of.h>

Not needed.

>  #include <linux/slab.h>
>  #include <linux/usb/typec.h>
>  
> @@ -1249,6 +1250,50 @@ void typec_set_pwr_opmode(struct typec_port *port,
>  }
>  EXPORT_SYMBOL_GPL(typec_set_pwr_opmode);
>  
> +/**
> + * typec_get_port_type - Get the typec port type
> + * @dev: Device to get the property of
> + *
> + * This routine is used by typec hardware driver to read property port type
> + * from the device firmware description.
> + *
> + * Returns typec_port_type if success, otherwise negative error code.
> + */
> +int typec_get_port_type(struct device *dev)
> +{
> +	const char *type_str;
> +	int ret;
> +
> +	ret = device_property_read_string(dev, "port-type", &type_str);
> +	if (ret < 0)
> +		return ret;
> +
> +	return match_string(typec_port_types, ARRAY_SIZE(typec_port_types),
> +								 type_str);
> +}
> +EXPORT_SYMBOL_GPL(typec_get_port_type);
> +
> +/**
> + * typec_get_power_role - Get the typec preferred role
> + * @dev: Device to get the property of
> + *
> + * This routine is used by typec hardware driver to read property default role
> + * from the device firmware description.
> + *
> + * Returns typec_role if success, otherwise negative error code.
> + */
> +int typec_get_power_role(struct device *dev)
> +{
> +	const char *power_str;
> +	int ret;
> +
> +	ret = device_property_read_string(dev, "default-role", &power_str);
> +	if (ret < 0)
> +		return ret;
> +
> +	return match_string(typec_roles, ARRAY_SIZE(typec_roles), power_str);
> +}
> +EXPORT_SYMBOL_GPL(typec_get_power_role);
>  /* --------------------------------------- */
>  
>  /**
> diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> index ffe7487..bfac685 100644
> --- a/include/linux/usb/typec.h
> +++ b/include/linux/usb/typec.h
> @@ -243,5 +243,7 @@ void typec_set_data_role(struct typec_port *port, enum typec_data_role role);
>  void typec_set_pwr_role(struct typec_port *port, enum typec_role role);
>  void typec_set_vconn_role(struct typec_port *port, enum typec_role role);
>  void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode);
> +int typec_get_port_type(struct device *dev);
> +int typec_get_power_role(struct device *dev);
>  
>  #endif /* __LINUX_USB_TYPEC_H */
> -- 
> 2.6.6

Thanks,

-- 
heikki
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 02/12] usb: typec: add basic typec properties
       [not found]     ` <1506386727-16370-3-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
@ 2017-09-26  8:23       ` Heikki Krogerus
       [not found]         ` <20170926082300.GC14296-FZxXFokcWpatqXYlAKuG4QC/G2K4zDHf@public.gmane.org>
  0 siblings, 1 reply; 34+ messages in thread
From: Heikki Krogerus @ 2017-09-26  8:23 UTC (permalink / raw)
  To: Li Jun
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, yueyao-hpIqsD4AKlfQT0dZR+AlfA,
	o_leveque-1tsiiZ//OF9QFI55V6+gNQ, peter.chen-3arQi8VN3Tc,
	aisheng.dong-3arQi8VN3Tc, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On Tue, Sep 26, 2017 at 08:45:17AM +0800, Li Jun wrote:
> port-type is required for any typec port; default-role is only required
> for drp; power source capable needs src-pdos; power sink capable needs
> snk-pdos, max-snk-mv, max-snk-ma, op-snk-mw.
> 
> Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
> ---
>  Documentation/devicetree/bindings/usb/typec.txt | 46 +++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/usb/typec.txt b/Documentation/devicetree/bindings/usb/typec.txt
> new file mode 100644
> index 0000000..36d4467
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/usb/typec.txt
> @@ -0,0 +1,46 @@
> +Generic typec and power delivery properties
> +-------------------------------------------
> +
> +Required properties:
> +- port-type:    should be one of "source", "sink" or "dual".
> +- default-role: preferred power role if drp, should be "sink" or "source".
> +- src-pdos:     An array of u32 with each entry providing supported power
> +                source data object(PDO), the detailed bit definitions of
> +                PDO can be found in "Universal Serial Bus Power Delivery
> +                Specification" chapter 6.4.1.2 Source_Capabilities Message,
> +                the order of each entry(PDO) should follow the PD spec chapter
> +                6.4.1. Required only for power source and power dual role with
> +                power delivery support.
> +- snk-pdos:     An array of u32 with each entry providing supported power
> +                sink data object(PDO), the detailed bit definitions of PDO
> +                can be found in "Universal Serial Bus Power Delivery
> +                Specification" chapter 6.4.1.3 Sink Capabilities Message,
> +                the order of each entry(PDO) should follow the PD spec chapter
> +                6.4.1. Required only for power sink and power dual role with
> +                power delivery support.

Wouldn't it be better to supply a property per detail and let the
drivers construct the pdos as needed?

> +- max-snk-mv:   The max voltage the sink can support in millivoltage, required
> +                only for power sink and power dual role with power delivery
> +                support.
> +- max-snk-ma:   The max current the sink can support in milliampere, required
> +                only for power sink and power dual role with power delivery
> +                support.
> +- op-snk-mw:    Sink required operating power in milliwatts, if source offered
> +                power is less then it, Capability Mismatch is set, required
> +                only for power sink and power dual role with power delivery
> +                support.

I'm a little bit concerned about these. Has any OF/DT guys reviewed
them?

We should also keep in mind that the same properties should also be
possible to use with ACPI. That may not be a problem as such, but we
should consult the ACPI guys as well.


Thanks,

-- 
heikki
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* RE: [PATCH 09/12] usb: typec: tcpm: only drives the connected cc line when attached
       [not found]         ` <9c461105-fa96-3989-5a95-b9f82b154ea2-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
@ 2017-09-26  9:53           ` Jun Li
       [not found]             ` <DB4PR04MB07689A95430FA6F4AA219539897B0-tLF+feb1Bz6HC8XOQgzeLs9NdZoXdze2vxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 34+ messages in thread
From: Jun Li @ 2017-09-26  9:53 UTC (permalink / raw)
  To: Guenter Roeck, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	Peter Chen, A.s. Dong, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 3825 bytes --]

Hi,

> -----Original Message-----
> From: Guenter Roeck [mailto:groeck7@gmail.com] On Behalf Of Guenter Roeck
> Sent: Tuesday, September 26, 2017 3:17 PM
> To: Jun Li <jun.li@nxp.com>; gregkh@linuxfoundation.org; robh+dt@kernel.org;
> mark.rutland@arm.com; heikki.krogerus@linux.intel.com
> Cc: yueyao@google.com; o_leveque@orange.fr; Peter Chen
> <peter.chen@nxp.com>; A.s. Dong <aisheng.dong@nxp.com>; linux-
> usb@vger.kernel.org; devicetree@vger.kernel.org
> Subject: Re: [PATCH 09/12] usb: typec: tcpm: only drives the connected cc line
> when attached
> 
> On 09/25/2017 05:45 PM, Li Jun wrote:
> > As we should only drive connected cc line to be the right state when
> > attached, and keeps the other one to be open, so update the set_cc
> > interface for that.
> >
> > Signed-off-by: Li Jun <jun.li@nxp.com>
> > ---
> >   drivers/usb/typec/tcpm.c | 12 +++++++++++-
> >   include/linux/usb/tcpm.h |  3 ++-
> >   2 files changed, 13 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c index
> > 38a6223..c9966ee 100644
> > --- a/drivers/usb/typec/tcpm.c
> > +++ b/drivers/usb/typec/tcpm.c
> > @@ -1857,9 +1857,15 @@ static bool tcpm_start_drp_toggling(struct
> > tcpm_port *port,
> >
> >   static void tcpm_set_cc(struct tcpm_port *port, enum typec_cc_status cc)
> >   {
> > +	bool attached;
> > +
> >   	tcpm_log(port, "cc:=%d", cc);
> >   	port->cc_req = cc;
> > -	port->tcpc->set_cc(port->tcpc, cc);
> > +	if (port->state == SRC_ATTACHED || port->state == SNK_ATTACHED)
> > +		attached = true;
> > +	else
> > +		attached = false;
> > +	port->tcpc->set_cc(port->tcpc, cc, attached, port->polarity);
> 
> Polarity should be set with set_polarity(). Is it necessary to duplicate that ?

In tcpci case, set_polarity only sets Plug Orientation bit:
" 0b: When Vconn is enabled, apply it to the CC2 pin. Monitor the CC1 pin for
BMC communications if PD messaging is enabled.
1b: When Vconn is enabled, apply it to the CC1 pin. Monitor the CC2 pin for
BMC communications if PD messaging is enabled."

There is no duplication for tcpci, or you think I should do this in set_polarity
of tcpci driver internally? looks better from my point view as I may don't
need change tcpm set_cc interface.

thanks
Li Jun
> 
> >   }
> >
> >   static int tcpm_init_vbus(struct tcpm_port *port) @@ -1913,6 +1919,8
> > @@ static int tcpm_src_attach(struct tcpm_port *port)
> >   	if (ret < 0)
> >   		return ret;
> >
> > +	tcpm_set_cc(port, tcpm_rp_cc(port));
> > +
> >   	ret = tcpm_set_roles(port, true, TYPEC_SOURCE, TYPEC_HOST);
> >   	if (ret < 0)
> >   		return ret;
> > @@ -2028,6 +2036,8 @@ static int tcpm_snk_attach(struct tcpm_port *port)
> >   	if (ret < 0)
> >   		return ret;
> >
> > +	tcpm_set_cc(port, TYPEC_CC_RD);
> > +
> >   	ret = tcpm_set_roles(port, true, TYPEC_SINK, TYPEC_DEVICE);
> >   	if (ret < 0)
> >   		return ret;
> > diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h index
> > a67cf77..a007e2a1 100644
> > --- a/include/linux/usb/tcpm.h
> > +++ b/include/linux/usb/tcpm.h
> > @@ -159,7 +159,8 @@ struct tcpc_dev {
> >   	int (*init)(struct tcpc_dev *dev);
> >   	int (*get_vbus)(struct tcpc_dev *dev);
> >   	int (*get_current_limit)(struct tcpc_dev *dev);
> > -	int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc);
> > +	int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc,
> > +			bool attached, enum typec_cc_polarity polarity);
> >   	int (*get_cc)(struct tcpc_dev *dev, enum typec_cc_status *cc1,
> >   		      enum typec_cc_status *cc2);
> >   	int (*set_polarity)(struct tcpc_dev *dev,
> >

N‹§²æìr¸›yúèšØb²X¬¶Ç§vØ^–)Þº{.nÇ+‰·¥Š{±ºÆâžØ^n‡r¡ö¦zË\x1aëh™¨è­Ú&¢îý»\x05ËÛÔØï¦v¬Îf\x1dp)¹¹br	šê+€Ê+zf£¢·hšˆ§~†­†Ûiÿûàz¹\x1e®w¥¢¸?™¨è­Ú&¢)ߢ^[f

^ permalink raw reply	[flat|nested] 34+ messages in thread

* RE: [PATCH 01/12] usb: typec: add API to get port type and preferred role
       [not found]         ` <20170926080231.GB14296-FZxXFokcWpatqXYlAKuG4QC/G2K4zDHf@public.gmane.org>
@ 2017-09-26  9:55           ` Jun Li
  0 siblings, 0 replies; 34+ messages in thread
From: Jun Li @ 2017-09-26  9:55 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, yueyao-hpIqsD4AKlfQT0dZR+AlfA,
	o_leveque-1tsiiZ//OF9QFI55V6+gNQ, Peter Chen, A.s. Dong,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA



> -----Original Message-----
> From: Heikki Krogerus [mailto:heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org]
> Sent: Tuesday, September 26, 2017 4:03 PM
> To: Jun Li <jun.li-3arQi8VN3Tc@public.gmane.org>
> Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org; linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org; robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org;
> mark.rutland-5wv7dgnIgG8@public.gmane.org; yueyao-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org; o_leveque-1tsiiZ//OF9QFI55V6+gNQ@public.gmane.org; Peter
> Chen <peter.chen-3arQi8VN3Tc@public.gmane.org>; A.s. Dong <aisheng.dong-3arQi8VN3Tc@public.gmane.org>; linux-
> usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> Subject: Re: [PATCH 01/12] usb: typec: add API to get port type and preferred
> role
> 
> Hi,
> 
> On Tue, Sep 26, 2017 at 08:45:16AM +0800, Li Jun wrote:
> > This patch add 2 APIs to get port type and preferred role from
> > firmware description.
> >
> > Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
> > ---
> >  drivers/usb/typec/typec.c | 45
> > +++++++++++++++++++++++++++++++++++++++++++++
> >  include/linux/usb/typec.h |  2 ++
> >  2 files changed, 47 insertions(+)
> >
> > diff --git a/drivers/usb/typec/typec.c b/drivers/usb/typec/typec.c
> > index 24e355b..0c77cc4 100644
> > --- a/drivers/usb/typec/typec.c
> > +++ b/drivers/usb/typec/typec.c
> > @@ -12,6 +12,7 @@
> >  #include <linux/device.h>
> >  #include <linux/module.h>
> >  #include <linux/mutex.h>
> > +#include <linux/of.h>
> 
> Not needed.

I will change to #include <linux/property.h>

> 
> >  #include <linux/slab.h>
> >  #include <linux/usb/typec.h>
> >
> > @@ -1249,6 +1250,50 @@ void typec_set_pwr_opmode(struct typec_port
> > *port,  }  EXPORT_SYMBOL_GPL(typec_set_pwr_opmode);
> >
> > +/**
> > + * typec_get_port_type - Get the typec port type
> > + * @dev: Device to get the property of
> > + *
> > + * This routine is used by typec hardware driver to read property
> > +port type
> > + * from the device firmware description.
> > + *
> > + * Returns typec_port_type if success, otherwise negative error code.
> > + */
> > +int typec_get_port_type(struct device *dev) {
> > +	const char *type_str;
> > +	int ret;
> > +
> > +	ret = device_property_read_string(dev, "port-type", &type_str);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	return match_string(typec_port_types, ARRAY_SIZE(typec_port_types),
> > +								 type_str);
> > +}
> > +EXPORT_SYMBOL_GPL(typec_get_port_type);
> > +
> > +/**
> > + * typec_get_power_role - Get the typec preferred role
> > + * @dev: Device to get the property of
> > + *
> > + * This routine is used by typec hardware driver to read property
> > +default role
> > + * from the device firmware description.
> > + *
> > + * Returns typec_role if success, otherwise negative error code.
> > + */
> > +int typec_get_power_role(struct device *dev) {
> > +	const char *power_str;
> > +	int ret;
> > +
> > +	ret = device_property_read_string(dev, "default-role", &power_str);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	return match_string(typec_roles, ARRAY_SIZE(typec_roles),
> > +power_str); } EXPORT_SYMBOL_GPL(typec_get_power_role);
> >  /* --------------------------------------- */
> >
> >  /**
> > diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> > index ffe7487..bfac685 100644
> > --- a/include/linux/usb/typec.h
> > +++ b/include/linux/usb/typec.h
> > @@ -243,5 +243,7 @@ void typec_set_data_role(struct typec_port *port,
> > enum typec_data_role role);  void typec_set_pwr_role(struct typec_port
> > *port, enum typec_role role);  void typec_set_vconn_role(struct
> > typec_port *port, enum typec_role role);  void
> > typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode
> > mode);
> > +int typec_get_port_type(struct device *dev); int
> > +typec_get_power_role(struct device *dev);
> >
> >  #endif /* __LINUX_USB_TYPEC_H */
> > --
> > 2.6.6
> 
> Thanks,
> 
> --
> heikki
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* RE: [PATCH 02/12] usb: typec: add basic typec properties
       [not found]         ` <20170926082300.GC14296-FZxXFokcWpatqXYlAKuG4QC/G2K4zDHf@public.gmane.org>
@ 2017-09-26 10:09           ` Jun Li
  0 siblings, 0 replies; 34+ messages in thread
From: Jun Li @ 2017-09-26 10:09 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-0h96xk9xTtrk1uMJSBkQmQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, yueyao-hpIqsD4AKlfQT0dZR+AlfA,
	o_leveque-1tsiiZ//OF9QFI55V6+gNQ, Peter Chen, A.s. Dong,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

Hi,

> -----Original Message-----
> From: Heikki Krogerus [mailto:heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org]
> Sent: Tuesday, September 26, 2017 4:23 PM
> To: Jun Li <jun.li-3arQi8VN3Tc@public.gmane.org>
> Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org; linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org; robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org;
> mark.rutland-5wv7dgnIgG8@public.gmane.org; yueyao-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org; o_leveque-1tsiiZ//OF9QFI55V6+gNQ@public.gmane.org; Peter
> Chen <peter.chen-3arQi8VN3Tc@public.gmane.org>; A.s. Dong <aisheng.dong-3arQi8VN3Tc@public.gmane.org>; linux-
> usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> Subject: Re: [PATCH 02/12] usb: typec: add basic typec properties
> 
> On Tue, Sep 26, 2017 at 08:45:17AM +0800, Li Jun wrote:
> > port-type is required for any typec port; default-role is only
> > required for drp; power source capable needs src-pdos; power sink
> > capable needs snk-pdos, max-snk-mv, max-snk-ma, op-snk-mw.
> >
> > Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
> > ---
> >  Documentation/devicetree/bindings/usb/typec.txt | 46
> > +++++++++++++++++++++++++
> >  1 file changed, 46 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/usb/typec.txt
> > b/Documentation/devicetree/bindings/usb/typec.txt
> > new file mode 100644
> > index 0000000..36d4467
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/usb/typec.txt
> > @@ -0,0 +1,46 @@
> > +Generic typec and power delivery properties
> > +-------------------------------------------
> > +
> > +Required properties:
> > +- port-type:    should be one of "source", "sink" or "dual".
> > +- default-role: preferred power role if drp, should be "sink" or "source".
> > +- src-pdos:     An array of u32 with each entry providing supported power
> > +                source data object(PDO), the detailed bit definitions of
> > +                PDO can be found in "Universal Serial Bus Power Delivery
> > +                Specification" chapter 6.4.1.2 Source_Capabilities Message,
> > +                the order of each entry(PDO) should follow the PD spec chapter
> > +                6.4.1. Required only for power source and power dual role with
> > +                power delivery support.
> > +- snk-pdos:     An array of u32 with each entry providing supported power
> > +                sink data object(PDO), the detailed bit definitions of PDO
> > +                can be found in "Universal Serial Bus Power Delivery
> > +                Specification" chapter 6.4.1.3 Sink Capabilities Message,
> > +                the order of each entry(PDO) should follow the PD spec chapter
> > +                6.4.1. Required only for power sink and power dual role with
> > +                power delivery support.
> 
> Wouldn't it be better to supply a property per detail and let the drivers construct
> the pdos as needed?

This is my original idea, but different kind of PDOs have so many detail attributes for
different config, we will have a very long properties list, for simple, maybe it's easier
for user to check the standard PD spec and construct it by hand in this case.

> 
> > +- max-snk-mv:   The max voltage the sink can support in millivoltage, required
> > +                only for power sink and power dual role with power delivery
> > +                support.
> > +- max-snk-ma:   The max current the sink can support in milliampere, required
> > +                only for power sink and power dual role with power delivery
> > +                support.
> > +- op-snk-mw:    Sink required operating power in milliwatts, if source offered
> > +                power is less then it, Capability Mismatch is set, required
> > +                only for power sink and power dual role with power delivery
> > +                support.
> 
> I'm a little bit concerned about these. Has any OF/DT guys reviewed them?
> 
> We should also keep in mind that the same properties should also be possible to
> use with ACPI. That may not be a problem as such, but we should consult the
> ACPI guys as well.
> 

Ok, let's wait DT guys comments.

Li Jun
> 
> Thanks,
> 
> --
> heikki
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 09/12] usb: typec: tcpm: only drives the connected cc line when attached
       [not found]             ` <DB4PR04MB07689A95430FA6F4AA219539897B0-tLF+feb1Bz6HC8XOQgzeLs9NdZoXdze2vxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2017-09-26 13:20               ` Guenter Roeck
       [not found]                 ` <e79d8143-1187-f3c4-6030-ecf28e3d2fff-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
  0 siblings, 1 reply; 34+ messages in thread
From: Guenter Roeck @ 2017-09-26 13:20 UTC (permalink / raw)
  To: Jun Li, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	Peter Chen, A.s. Dong, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On 09/26/2017 02:53 AM, Jun Li wrote:
> Hi,
> 
>> -----Original Message-----
>> From: Guenter Roeck [mailto:groeck7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org] On Behalf Of Guenter Roeck
>> Sent: Tuesday, September 26, 2017 3:17 PM
>> To: Jun Li <jun.li-3arQi8VN3Tc@public.gmane.org>; gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org; robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org;
>> mark.rutland-5wv7dgnIgG8@public.gmane.org; heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org
>> Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org; o_leveque-1tsiiZ//OF9QFI55V6+gNQ@public.gmane.org; Peter Chen
>> <peter.chen-3arQi8VN3Tc@public.gmane.org>; A.s. Dong <aisheng.dong-3arQi8VN3Tc@public.gmane.org>; linux-
>> usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>> Subject: Re: [PATCH 09/12] usb: typec: tcpm: only drives the connected cc line
>> when attached
>>
>> On 09/25/2017 05:45 PM, Li Jun wrote:
>>> As we should only drive connected cc line to be the right state when
>>> attached, and keeps the other one to be open, so update the set_cc
>>> interface for that.
>>>
>>> Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
>>> ---
>>>    drivers/usb/typec/tcpm.c | 12 +++++++++++-
>>>    include/linux/usb/tcpm.h |  3 ++-
>>>    2 files changed, 13 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c index
>>> 38a6223..c9966ee 100644
>>> --- a/drivers/usb/typec/tcpm.c
>>> +++ b/drivers/usb/typec/tcpm.c
>>> @@ -1857,9 +1857,15 @@ static bool tcpm_start_drp_toggling(struct
>>> tcpm_port *port,
>>>
>>>    static void tcpm_set_cc(struct tcpm_port *port, enum typec_cc_status cc)
>>>    {
>>> +	bool attached;
>>> +
>>>    	tcpm_log(port, "cc:=%d", cc);
>>>    	port->cc_req = cc;
>>> -	port->tcpc->set_cc(port->tcpc, cc);
>>> +	if (port->state == SRC_ATTACHED || port->state == SNK_ATTACHED)
>>> +		attached = true;
>>> +	else
>>> +		attached = false;
>>> +	port->tcpc->set_cc(port->tcpc, cc, attached, port->polarity);
>>
>> Polarity should be set with set_polarity(). Is it necessary to duplicate that ?
> 
> In tcpci case, set_polarity only sets Plug Orientation bit:
> " 0b: When Vconn is enabled, apply it to the CC2 pin. Monitor the CC1 pin for
> BMC communications if PD messaging is enabled.
> 1b: When Vconn is enabled, apply it to the CC1 pin. Monitor the CC2 pin for
> BMC communications if PD messaging is enabled."
> 
Yes, but the driver should know about the flag already.

I have two more concerns:

Setting CC is logically independent from the state machine "active" state.
I don't recall that the USB PD state machine talks about CC pin changes upon
entering and exiting READY states. Why is it necessary to pass the state
to the driver ?

Also, your patch changes the API, but you don't change the driver, meaning there
should be compile failures after this patch. You need to change the calling code
in the same patch to keep the build clean.

Guenter

> There is no duplication for tcpci, or you think I should do this in set_polarity
> of tcpci driver internally? looks better from my point view as I may don't
> need change tcpm set_cc interface.
> 
> thanks
> Li Jun
>>
>>>    }
>>>
>>>    static int tcpm_init_vbus(struct tcpm_port *port) @@ -1913,6 +1919,8
>>> @@ static int tcpm_src_attach(struct tcpm_port *port)
>>>    	if (ret < 0)
>>>    		return ret;
>>>
>>> +	tcpm_set_cc(port, tcpm_rp_cc(port));
>>> +
>>>    	ret = tcpm_set_roles(port, true, TYPEC_SOURCE, TYPEC_HOST);
>>>    	if (ret < 0)
>>>    		return ret;
>>> @@ -2028,6 +2036,8 @@ static int tcpm_snk_attach(struct tcpm_port *port)
>>>    	if (ret < 0)
>>>    		return ret;
>>>
>>> +	tcpm_set_cc(port, TYPEC_CC_RD);
>>> +
>>>    	ret = tcpm_set_roles(port, true, TYPEC_SINK, TYPEC_DEVICE);
>>>    	if (ret < 0)
>>>    		return ret;
>>> diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h index
>>> a67cf77..a007e2a1 100644
>>> --- a/include/linux/usb/tcpm.h
>>> +++ b/include/linux/usb/tcpm.h
>>> @@ -159,7 +159,8 @@ struct tcpc_dev {
>>>    	int (*init)(struct tcpc_dev *dev);
>>>    	int (*get_vbus)(struct tcpc_dev *dev);
>>>    	int (*get_current_limit)(struct tcpc_dev *dev);
>>> -	int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc);
>>> +	int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc,
>>> +			bool attached, enum typec_cc_polarity polarity);
>>>    	int (*get_cc)(struct tcpc_dev *dev, enum typec_cc_status *cc1,
>>>    		      enum typec_cc_status *cc2);
>>>    	int (*set_polarity)(struct tcpc_dev *dev,
>>>
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 01/12] usb: typec: add API to get port type and preferred role
       [not found]     ` <1506386727-16370-2-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
  2017-09-26  8:02       ` Heikki Krogerus
@ 2017-09-26 13:20       ` Guenter Roeck
  1 sibling, 0 replies; 34+ messages in thread
From: Guenter Roeck @ 2017-09-26 13:20 UTC (permalink / raw)
  To: Li Jun, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On 09/25/2017 05:45 PM, Li Jun wrote:
> This patch add 2 APIs to get port type and preferred role from firmware
> description.
> 
> Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
> ---
>   drivers/usb/typec/typec.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
>   include/linux/usb/typec.h |  2 ++
>   2 files changed, 47 insertions(+)
> 
> diff --git a/drivers/usb/typec/typec.c b/drivers/usb/typec/typec.c
> index 24e355b..0c77cc4 100644
> --- a/drivers/usb/typec/typec.c
> +++ b/drivers/usb/typec/typec.c
> @@ -12,6 +12,7 @@
>   #include <linux/device.h>
>   #include <linux/module.h>
>   #include <linux/mutex.h>
> +#include <linux/of.h>
>   #include <linux/slab.h>
>   #include <linux/usb/typec.h>
>   
> @@ -1249,6 +1250,50 @@ void typec_set_pwr_opmode(struct typec_port *port,
>   }
>   EXPORT_SYMBOL_GPL(typec_set_pwr_opmode);
>   
> +/**
> + * typec_get_port_type - Get the typec port type
> + * @dev: Device to get the property of
> + *
> + * This routine is used by typec hardware driver to read property port type
> + * from the device firmware description.
> + *
> + * Returns typec_port_type if success, otherwise negative error code.
> + */
> +int typec_get_port_type(struct device *dev)
> +{
> +	const char *type_str;
> +	int ret;
> +
> +	ret = device_property_read_string(dev, "port-type", &type_str);
> +	if (ret < 0)
> +		return ret;
> +
> +	return match_string(typec_port_types, ARRAY_SIZE(typec_port_types),
> +								 type_str);
> +}
> +EXPORT_SYMBOL_GPL(typec_get_port_type);
> +
> +/**
> + * typec_get_power_role - Get the typec preferred role
> + * @dev: Device to get the property of
> + *
> + * This routine is used by typec hardware driver to read property default role
> + * from the device firmware description.
> + *
> + * Returns typec_role if success, otherwise negative error code.
> + */
> +int typec_get_power_role(struct device *dev)
> +{
> +	const char *power_str;
> +	int ret;
> +
> +	ret = device_property_read_string(dev, "default-role", &power_str);
> +	if (ret < 0)
> +		return ret;
> +
> +	return match_string(typec_roles, ARRAY_SIZE(typec_roles), power_str);
> +}
> +EXPORT_SYMBOL_GPL(typec_get_power_role);

Add empty line

>   /* --------------------------------------- */
>   
>   /**
> diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> index ffe7487..bfac685 100644
> --- a/include/linux/usb/typec.h
> +++ b/include/linux/usb/typec.h
> @@ -243,5 +243,7 @@ void typec_set_data_role(struct typec_port *port, enum typec_data_role role);
>   void typec_set_pwr_role(struct typec_port *port, enum typec_role role);
>   void typec_set_vconn_role(struct typec_port *port, enum typec_role role);
>   void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode);
> +int typec_get_port_type(struct device *dev);
> +int typec_get_power_role(struct device *dev);
>   
>   #endif /* __LINUX_USB_TYPEC_H */
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 04/12] staging: typec: tcpci: support port config passed via dt
       [not found]     ` <1506386727-16370-5-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
@ 2017-09-26 13:32       ` Guenter Roeck
       [not found]         ` <bb854ecf-fad7-2c2a-1972-5c4cabb970f2-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
  0 siblings, 1 reply; 34+ messages in thread
From: Guenter Roeck @ 2017-09-26 13:32 UTC (permalink / raw)
  To: Li Jun, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On 09/25/2017 05:45 PM, Li Jun wrote:
> User can define the typec port properties in tcpci node to setup
> the port config.
> 
> Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
> ---
>   drivers/staging/typec/tcpci.c | 89 +++++++++++++++++++++++++++++++++++++++----
>   include/linux/usb/tcpm.h      |  6 +--
>   2 files changed, 85 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
> index 4636804..0119453 100644
> --- a/drivers/staging/typec/tcpci.c
> +++ b/drivers/staging/typec/tcpci.c
> @@ -425,17 +425,92 @@ static const struct regmap_config tcpci_regmap_config = {
>   	.max_register = 0x7F, /* 0x80 .. 0xFF are vendor defined */
>   };
>   
> -static const struct tcpc_config tcpci_tcpc_config = {
> -	.type = TYPEC_PORT_DFP,
> -	.default_role = TYPEC_SINK,
> -};
> -
> +/* Populate struct tcpc_config from device-tree */
>   static int tcpci_parse_config(struct tcpci *tcpci)
>   {
> +	struct tcpc_config *tcfg;
> +	int ret = -EINVAL;
> +
>   	tcpci->controls_vbus = true; /* XXX */
>   
> -	/* TODO: Populate struct tcpc_config from ACPI/device-tree */
> -	tcpci->tcpc.config = &tcpci_tcpc_config;
> +	tcpci->tcpc.config = devm_kzalloc(tcpci->dev, sizeof(*tcfg),
> +					  GFP_KERNEL);
> +	if (!tcpci->tcpc.config)
> +		return -ENOMEM;
> +
> +	tcfg = tcpci->tcpc.config;
> +
> +	/* Get port-type */
> +	ret = typec_get_port_type(tcpci->dev);
> +	if (ret < 0) {
> +		dev_err(tcpci->dev, "typec port type is NOT correct!\n");

Are all those exclamation marks necessary ?

> +		return ret;
> +	}
> +	tcfg->type = ret;
> +
> +	if (tcfg->type == TYPEC_PORT_UFP)
> +		goto sink;
> +
> +	/* Get source PDO */
> +	tcfg->nr_src_pdo = device_property_read_u32_array(tcpci->dev,
> +						"src-pdos", NULL, 0);

I personally prefer continuation line alignment to '(', but that is up to Greg to decide.

> +	if (tcfg->nr_src_pdo <= 0) {
> +		dev_err(tcpci->dev, "typec source pdo is missing!\n");
> +		return -EINVAL;
> +	}
> +
> +	tcfg->src_pdo = devm_kzalloc(tcpci->dev,
> +		sizeof(*tcfg->src_pdo) * tcfg->nr_src_pdo, GFP_KERNEL);

devm_kcalloc

> +	if (!tcfg->src_pdo)
> +		return -ENOMEM;
> +
> +	ret = device_property_read_u32_array(tcpci->dev, "src-pdos",
> +				tcfg->src_pdo, tcfg->nr_src_pdo);
> +	if (ret) {
> +		dev_err(tcpci->dev, "Failed to read src pdo!\n");
> +		return -EINVAL;
> +	}
> +
> +	if (tcfg->type == TYPEC_PORT_DFP)
> +		return 0;
> +
> +	/* Get the preferred power role for drp */
> +	ret = typec_get_power_role(tcpci->dev);

Maybe this should be named typec_get_preferred_role(). The generic function
names are a bit misleading; they suggest they would return the current role,
and don't indicate that the data is from device properties.
I am also not sure about the mix of using typec infra functions and
direct device_property calls.

> +	if (ret < 0) {
> +		dev_err(tcpci->dev, "typec preferred role is wrong!\n");

Wrong or missing ?

> +		return ret;
> +	}
> +	tcfg->default_role = ret;
> +sink:
> +	/* Get sink power capability */
> +	tcfg->nr_snk_pdo = device_property_read_u32_array(tcpci->dev,
> +						"snk-pdos", NULL, 0);
> +	if (tcfg->nr_snk_pdo <= 0) {
> +		dev_err(tcpci->dev, "typec sink pdo is missing!\n");
> +		return -EINVAL;
> +	}
> +
> +	tcfg->snk_pdo = devm_kzalloc(tcpci->dev,
> +		sizeof(*tcfg->snk_pdo) * tcfg->nr_snk_pdo, GFP_KERNEL);
> +	if (!tcfg->snk_pdo)
> +		return -ENOMEM;
> +
> +	ret = device_property_read_u32_array(tcpci->dev, "snk-pdos",
> +				tcfg->snk_pdo, tcfg->nr_snk_pdo);
> +	if (ret) {
> +		dev_err(tcpci->dev, "Failed to read sink pdo!\n");

There is a mix of "Failed to read" and "missing" messages. What is the difference ?

> +		return -EINVAL;
> +	}
> +
> +	if (device_property_read_u32(tcpci->dev, "max-snk-mv",
> +				     &tcfg->max_snk_mv) ||
> +		device_property_read_u32(tcpci->dev, "max-snk-ma",
> +					 &tcfg->max_snk_ma) ||
> +		device_property_read_u32(tcpci->dev, "op-snk-mw",
> +					 &tcfg->operating_snk_mw)) {
> +		dev_err(tcpci->dev, "Failed to read sink capability!\n");
> +		return -EINVAL;
> +	}
>   
>   	return 0;
>   }
> diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
> index 073197f..a67cf77 100644
> --- a/include/linux/usb/tcpm.h
> +++ b/include/linux/usb/tcpm.h
> @@ -76,10 +76,10 @@ enum tcpm_transmit_type {
>    * @alt_modes:	List of supported alternate modes
>    */
>   struct tcpc_config {
> -	const u32 *src_pdo;
> +	u32 *src_pdo;
>   	unsigned int nr_src_pdo;
>   
> -	const u32 *snk_pdo;
> +	u32 *snk_pdo;
>   	unsigned int nr_snk_pdo;
>   
>   	const u32 *snk_vdo;
> @@ -154,7 +154,7 @@ struct tcpc_mux_dev {
>    * @mux:	Pointer to multiplexer data
>    */
>   struct tcpc_dev {
> -	const struct tcpc_config *config;
> +	struct tcpc_config *config;
>   
>   	int (*init)(struct tcpc_dev *dev);
>   	int (*get_vbus)(struct tcpc_dev *dev);
> 

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 05/12] staging: typec: tcpci: register port before request irq
       [not found]     ` <1506386727-16370-6-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
@ 2017-09-26 13:33       ` Guenter Roeck
       [not found]         ` <da64a379-f9bc-5ad8-44a5-f61c4419e1e7-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
  0 siblings, 1 reply; 34+ messages in thread
From: Guenter Roeck @ 2017-09-26 13:33 UTC (permalink / raw)
  To: Li Jun, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On 09/25/2017 05:45 PM, Li Jun wrote:
> With that we can clear any pending events and the port is registered
> so driver can be ready to handle typec events once we request irq.
> 
> Signed-off-by: Peter Chen <peter.chen-3arQi8VN3Tc@public.gmane.org>
> Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
> ---
>   drivers/staging/typec/tcpci.c | 11 +++++------
>   1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
> index 0119453..6d608b4 100644
> --- a/drivers/staging/typec/tcpci.c
> +++ b/drivers/staging/typec/tcpci.c
> @@ -552,15 +552,14 @@ static int tcpci_probe(struct i2c_client *client,
>   	/* Disable chip interrupts */
>   	tcpci_write16(tcpci, TCPC_ALERT_MASK, 0);
>   
> -	err = devm_request_threaded_irq(tcpci->dev, client->irq, NULL,
> +	tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
> +	if (IS_ERR(tcpci->port))
> +		return PTR_ERR(tcpci->port);
> +
> +	return devm_request_threaded_irq(tcpci->dev, client->irq, NULL,
>   					tcpci_irq,
>   					IRQF_ONESHOT | IRQF_TRIGGER_LOW,
>   					dev_name(tcpci->dev), tcpci);
> -	if (err < 0)
> -		return err;
> -
> -	tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
> -	return PTR_ERR_OR_ZERO(tcpci->port);

This leaves the port registered if registering the irq fails.

>   }
>   
>   static int tcpci_remove(struct i2c_client *client)
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 06/12] staging: typec: tcpci: enable vbus detection
       [not found]     ` <1506386727-16370-7-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
@ 2017-09-26 13:37       ` Guenter Roeck
       [not found]         ` <6cbb9cb2-206d-64e3-9e91-77edce855fdd-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
  0 siblings, 1 reply; 34+ messages in thread
From: Guenter Roeck @ 2017-09-26 13:37 UTC (permalink / raw)
  To: Li Jun, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On 09/25/2017 05:45 PM, Li Jun wrote:
> TCPCI implementation may need SW to enable VBUS detection to generate
> power status events.
> 
> Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
> ---
>   drivers/staging/typec/tcpci.c | 23 +++++++++++++++++++++++
>   1 file changed, 23 insertions(+)
> 
> diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
> index 6d608b4..851d026 100644
> --- a/drivers/staging/typec/tcpci.c
> +++ b/drivers/staging/typec/tcpci.c
> @@ -313,6 +313,26 @@ static int tcpci_pd_transmit(struct tcpc_dev *tcpc,
>   	return 0;
>   }
>   
> +static int tcpci_vbus_detect(struct tcpc_dev *tcpc, bool enable)
> +{
> +	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
> +	int ret;
> +
> +	if (enable) {
> +		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
> +				   TCPC_CMD_ENABLE_VBUS_DETECT);
> +		if (ret < 0)
> +			return ret;
> +	} else {
> +		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
> +				   TCPC_CMD_DISABLE_VBUS_DETECT);
> +		if (ret < 0)
> +			return ret;
> +	}

This could be simplified to something like

         u8 cmd = enabled ? TCPC_CMD_ENABLE_VBUS_DETECT : TCPC_CMD_DISABLE_VBUS_DETECT;

	return regmap_write(tcpci->regmap, TCPC_COMMAND, cmd);

though the question is why not just add a function named tcpci_vbus_detect_enable()
since it is never disabled, at least not in this patch.

> +
> +	return 0;
> +}
> +
>   static int tcpci_init(struct tcpc_dev *tcpc)
>   {
>   	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
> @@ -344,6 +364,9 @@ static int tcpci_init(struct tcpc_dev *tcpc)
>   	if (ret < 0)
>   		return ret;
>   
> +	/* Enable Vbus detection */
> +	tcpci_vbus_detect(tcpc, true);
> +
>   	reg = TCPC_ALERT_TX_SUCCESS | TCPC_ALERT_TX_FAILED |
>   		TCPC_ALERT_TX_DISCARDED | TCPC_ALERT_RX_STATUS |
>   		TCPC_ALERT_RX_HARD_RST | TCPC_ALERT_CC_STATUS;
> 

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 07/12] typec: tcpm: add starting value for drp toggling
       [not found]     ` <1506386727-16370-8-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
@ 2017-09-26 13:42       ` Guenter Roeck
       [not found]         ` <ceae0f45-5d14-8e7f-3258-aa2e28fcf9bc-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
  0 siblings, 1 reply; 34+ messages in thread
From: Guenter Roeck @ 2017-09-26 13:42 UTC (permalink / raw)
  To: Li Jun, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On 09/25/2017 05:45 PM, Li Jun wrote:
> As DRP port autonomously toggles the Rp/Rd need a start value to
> begin with, so add one parameter for it in tcpm_start_drp_toggling.
> 

It does have a starting value. The patch changes the starting value to TYPEC_CC_RD
(from currently one of the RP states) when entering the SNK_UNATTACHED state.
Please provide a matching description.

> Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
> ---
>   drivers/usb/typec/tcpm.c | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
> index 8483d3e..38a6223 100644
> --- a/drivers/usb/typec/tcpm.c
> +++ b/drivers/usb/typec/tcpm.c
> @@ -1839,15 +1839,15 @@ static int tcpm_set_charge(struct tcpm_port *port, bool charge)
>   	return 0;
>   }
>   
> -static bool tcpm_start_drp_toggling(struct tcpm_port *port)
> +static bool tcpm_start_drp_toggling(struct tcpm_port *port,
> +				    enum typec_cc_status cc)
>   {
>   	int ret;
>   
>   	if (port->tcpc->start_drp_toggling &&
>   	    port->port_type == TYPEC_PORT_DRP) {
>   		tcpm_log_force(port, "Start DRP toggling");
> -		ret = port->tcpc->start_drp_toggling(port->tcpc,
> -						     tcpm_rp_cc(port));
> +		ret = port->tcpc->start_drp_toggling(port->tcpc, cc);
>   		if (!ret)
>   			return true;
>   	}
> @@ -2156,7 +2156,7 @@ static void run_state_machine(struct tcpm_port *port)
>   		if (!port->non_pd_role_swap)
>   			tcpm_swap_complete(port, -ENOTCONN);
>   		tcpm_src_detach(port);
> -		if (tcpm_start_drp_toggling(port)) {
> +		if (tcpm_start_drp_toggling(port, tcpm_rp_cc(port))) {
>   			tcpm_set_state(port, DRP_TOGGLING, 0);
>   			break;
>   		}
> @@ -2328,7 +2328,7 @@ static void run_state_machine(struct tcpm_port *port)
>   		if (!port->non_pd_role_swap)
>   			tcpm_swap_complete(port, -ENOTCONN);
>   		tcpm_snk_detach(port);
> -		if (tcpm_start_drp_toggling(port)) {
> +		if (tcpm_start_drp_toggling(port, TYPEC_CC_RD)) {
>   			tcpm_set_state(port, DRP_TOGGLING, 0);
>   			break;
>   		}
> 

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 10/12] staging: typec: tcpci: update set_cc for different state
       [not found]     ` <1506386727-16370-11-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
@ 2017-09-26 13:49       ` Guenter Roeck
       [not found]         ` <8ef676a1-4c2b-cea7-ad79-c50fb8d091fb-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
  0 siblings, 1 reply; 34+ messages in thread
From: Guenter Roeck @ 2017-09-26 13:49 UTC (permalink / raw)
  To: Li Jun, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	peter.chen-3arQi8VN3Tc, aisheng.dong-3arQi8VN3Tc,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On 09/25/2017 05:45 PM, Li Jun wrote:
> As we should keep the disconnected cc line to be open when attached,
> so update the set_cc interface accordingly for it.
> 
> Signed-off-by: Li Jun <jun.li-3arQi8VN3Tc@public.gmane.org>
> ---
>   drivers/staging/typec/tcpci.c | 37 +++++++++++++++++++++----------------
>   1 file changed, 21 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
> index cea67f9..c7c45da 100644
> --- a/drivers/staging/typec/tcpci.c
> +++ b/drivers/staging/typec/tcpci.c
> @@ -57,10 +57,11 @@ static int tcpci_write16(struct tcpci *tcpci, unsigned int reg, u16 val)
>   	return regmap_raw_write(tcpci->regmap, reg, &val, sizeof(u16));
>   }
>   
> -static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)
> +static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc,
> +			bool attached, enum typec_cc_polarity polarity)
>   {
>   	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
> -	unsigned int reg;
> +	unsigned int reg = 0, reg_cc1 = 0, reg_cc2 = 0;
>   	int ret;
>   
>   	switch (cc) {
> @@ -69,26 +70,23 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)
>   			(TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC2_SHIFT);
>   		break;
>   	case TYPEC_CC_RD:
> -		reg = (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) |
> -			(TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT);
> +		reg_cc1 = TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT;
> +		reg_cc2 = TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT;
>   		break;
>   	case TYPEC_CC_RP_DEF:
> -		reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) |
> -			(TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) |
> -			(TCPC_ROLE_CTRL_RP_VAL_DEF <<
> -			 TCPC_ROLE_CTRL_RP_VAL_SHIFT);
> +		reg_cc1 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT;
> +		reg_cc2 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT;
> +		reg = TCPC_ROLE_CTRL_RP_VAL_DEF << TCPC_ROLE_CTRL_RP_VAL_SHIFT;
>   		break;
>   	case TYPEC_CC_RP_1_5:
> -		reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) |
> -			(TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) |
> -			(TCPC_ROLE_CTRL_RP_VAL_1_5 <<
> -			 TCPC_ROLE_CTRL_RP_VAL_SHIFT);
> +		reg_cc1 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT;
> +		reg_cc2 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT;
> +		reg = TCPC_ROLE_CTRL_RP_VAL_1_5 << TCPC_ROLE_CTRL_RP_VAL_SHIFT;
>   		break;
>   	case TYPEC_CC_RP_3_0:
> -		reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) |
> -			(TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) |
> -			(TCPC_ROLE_CTRL_RP_VAL_3_0 <<
> -			 TCPC_ROLE_CTRL_RP_VAL_SHIFT);
> +		reg_cc1 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT;
> +		reg_cc2 = TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT;
> +		reg = TCPC_ROLE_CTRL_RP_VAL_3_0 << TCPC_ROLE_CTRL_RP_VAL_SHIFT;
>   		break;
>   	case TYPEC_CC_OPEN:
>   	default:
> @@ -97,6 +95,13 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)
>   		break;
>   	}
>   
> +	if (!attached)
> +		reg |= reg_cc1 | reg_cc2;
> +	else if (polarity == TYPEC_POLARITY_CC1)
> +		reg |= reg_cc1;
> +	else
> +		reg |= reg_cc2;
> +

I think this is wrong. The value of CC pins should not depend on the state of
the state machine. What if the state machine knows the polarity but is in a
transient state ?.

I am also not sure if the chip should ever set both CC lines at the same time.

Guenter

>   	ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
>   	if (ret < 0)
>   		return ret;
> 

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* RE: [PATCH 09/12] usb: typec: tcpm: only drives the connected cc line when attached
       [not found]                 ` <e79d8143-1187-f3c4-6030-ecf28e3d2fff-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
@ 2017-09-26 13:57                   ` Jun Li
  0 siblings, 0 replies; 34+ messages in thread
From: Jun Li @ 2017-09-26 13:57 UTC (permalink / raw)
  To: Guenter Roeck, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	Peter Chen, A.s. Dong, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA



> -----Original Message-----
> From: Guenter Roeck [mailto:groeck7@gmail.com] On Behalf Of Guenter Roeck
> Sent: Tuesday, September 26, 2017 9:20 PM
> To: Jun Li <jun.li@nxp.com>; gregkh@linuxfoundation.org; robh+dt@kernel.org;
> mark.rutland@arm.com; heikki.krogerus@linux.intel.com
> Cc: yueyao@google.com; o_leveque@orange.fr; Peter Chen
> <peter.chen@nxp.com>; A.s. Dong <aisheng.dong@nxp.com>; linux-
> usb@vger.kernel.org; devicetree@vger.kernel.org
> Subject: Re: [PATCH 09/12] usb: typec: tcpm: only drives the connected cc line
> when attached
> 
> On 09/26/2017 02:53 AM, Jun Li wrote:
> > Hi,
> >
> >> -----Original Message-----
> >> From: Guenter Roeck [mailto:groeck7@gmail.com] On Behalf Of Guenter
> >> Roeck
> >> Sent: Tuesday, September 26, 2017 3:17 PM
> >> To: Jun Li <jun.li@nxp.com>; gregkh@linuxfoundation.org;
> >> robh+dt@kernel.org; mark.rutland@arm.com;
> >> heikki.krogerus@linux.intel.com
> >> Cc: yueyao@google.com; o_leveque@orange.fr; Peter Chen
> >> <peter.chen@nxp.com>; A.s. Dong <aisheng.dong@nxp.com>; linux-
> >> usb@vger.kernel.org; devicetree@vger.kernel.org
> >> Subject: Re: [PATCH 09/12] usb: typec: tcpm: only drives the
> >> connected cc line when attached
> >>
> >> On 09/25/2017 05:45 PM, Li Jun wrote:
> >>> As we should only drive connected cc line to be the right state when
> >>> attached, and keeps the other one to be open, so update the set_cc
> >>> interface for that.
> >>>
> >>> Signed-off-by: Li Jun <jun.li@nxp.com>
> >>> ---
> >>>    drivers/usb/typec/tcpm.c | 12 +++++++++++-
> >>>    include/linux/usb/tcpm.h |  3 ++-
> >>>    2 files changed, 13 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
> >>> index 38a6223..c9966ee 100644
> >>> --- a/drivers/usb/typec/tcpm.c
> >>> +++ b/drivers/usb/typec/tcpm.c
> >>> @@ -1857,9 +1857,15 @@ static bool tcpm_start_drp_toggling(struct
> >>> tcpm_port *port,
> >>>
> >>>    static void tcpm_set_cc(struct tcpm_port *port, enum typec_cc_status cc)
> >>>    {
> >>> +	bool attached;
> >>> +
> >>>    	tcpm_log(port, "cc:=%d", cc);
> >>>    	port->cc_req = cc;
> >>> -	port->tcpc->set_cc(port->tcpc, cc);
> >>> +	if (port->state == SRC_ATTACHED || port->state == SNK_ATTACHED)
> >>> +		attached = true;
> >>> +	else
> >>> +		attached = false;
> >>> +	port->tcpc->set_cc(port->tcpc, cc, attached, port->polarity);
> >>
> >> Polarity should be set with set_polarity(). Is it necessary to duplicate that ?
> >
> > In tcpci case, set_polarity only sets Plug Orientation bit:
> > " 0b: When Vconn is enabled, apply it to the CC2 pin. Monitor the CC1
> > pin for BMC communications if PD messaging is enabled.
> > 1b: When Vconn is enabled, apply it to the CC1 pin. Monitor the CC2
> > pin for BMC communications if PD messaging is enabled."
> >
> Yes, but the driver should know about the flag already.
> 
> I have two more concerns:
> 
> Setting CC is logically independent from the state machine "active" state.
> I don't recall that the USB PD state machine talks about CC pin changes upon
> entering and exiting READY states. Why is it necessary to pass the state to the
> driver ?

Here the CC pin changes only for un-touched one between look for connection
and attached, so when attach(before entering READY), the un-touch cc pin
should be changed from Pd/Rp to open(e.g. see typec spec Table 4-6 Source
Perspective). as my question below, I can adding it into tcpci_set_polarity()
for tcpci case if it's reasonable, with that tcpm API don't need change.
  
> 
> Also, your patch changes the API, but you don't change the driver, meaning
> there should be compile failures after this patch. You need to change the calling
> code in the same patch to keep the build clean.

Sorry, I didn’t realize there is already a user of tcpm, I will update the calling
driver accordingly for hanged tcpm API in next version.

Li Jun

> 
> Guenter
> 
> > There is no duplication for tcpci, or you think I should do this in
> > set_polarity of tcpci driver internally? looks better from my point
> > view as I may don't need change tcpm set_cc interface.
> >
> > thanks
> > Li Jun
> >>
> >>>    }
> >>>
> >>>    static int tcpm_init_vbus(struct tcpm_port *port) @@ -1913,6
> >>> +1919,8 @@ static int tcpm_src_attach(struct tcpm_port *port)
> >>>    	if (ret < 0)
> >>>    		return ret;
> >>>
> >>> +	tcpm_set_cc(port, tcpm_rp_cc(port));
> >>> +
> >>>    	ret = tcpm_set_roles(port, true, TYPEC_SOURCE, TYPEC_HOST);
> >>>    	if (ret < 0)
> >>>    		return ret;
> >>> @@ -2028,6 +2036,8 @@ static int tcpm_snk_attach(struct tcpm_port
> *port)
> >>>    	if (ret < 0)
> >>>    		return ret;
> >>>
> >>> +	tcpm_set_cc(port, TYPEC_CC_RD);
> >>> +
> >>>    	ret = tcpm_set_roles(port, true, TYPEC_SINK, TYPEC_DEVICE);
> >>>    	if (ret < 0)
> >>>    		return ret;
> >>> diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
> >>> index
> >>> a67cf77..a007e2a1 100644
> >>> --- a/include/linux/usb/tcpm.h
> >>> +++ b/include/linux/usb/tcpm.h
> >>> @@ -159,7 +159,8 @@ struct tcpc_dev {
> >>>    	int (*init)(struct tcpc_dev *dev);
> >>>    	int (*get_vbus)(struct tcpc_dev *dev);
> >>>    	int (*get_current_limit)(struct tcpc_dev *dev);
> >>> -	int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc);
> >>> +	int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc,
> >>> +			bool attached, enum typec_cc_polarity polarity);
> >>>    	int (*get_cc)(struct tcpc_dev *dev, enum typec_cc_status *cc1,
> >>>    		      enum typec_cc_status *cc2);
> >>>    	int (*set_polarity)(struct tcpc_dev *dev,
> >>>
> >


^ permalink raw reply	[flat|nested] 34+ messages in thread

* RE: [PATCH 04/12] staging: typec: tcpci: support port config passed via dt
       [not found]         ` <bb854ecf-fad7-2c2a-1972-5c4cabb970f2-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
@ 2017-09-26 14:14           ` Jun Li
  0 siblings, 0 replies; 34+ messages in thread
From: Jun Li @ 2017-09-26 14:14 UTC (permalink / raw)
  To: Guenter Roeck, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	Peter Chen, A.s. Dong, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

Hi

> -----Original Message-----
> From: Guenter Roeck [mailto:groeck7@gmail.com] On Behalf Of Guenter Roeck
> Sent: Tuesday, September 26, 2017 9:33 PM
> To: Jun Li <jun.li@nxp.com>; gregkh@linuxfoundation.org; robh+dt@kernel.org;
> mark.rutland@arm.com; heikki.krogerus@linux.intel.com
> Cc: yueyao@google.com; o_leveque@orange.fr; Peter Chen
> <peter.chen@nxp.com>; A.s. Dong <aisheng.dong@nxp.com>; linux-
> usb@vger.kernel.org; devicetree@vger.kernel.org
> Subject: Re: [PATCH 04/12] staging: typec: tcpci: support port config passed via
> dt
> 
> On 09/25/2017 05:45 PM, Li Jun wrote:
> > User can define the typec port properties in tcpci node to setup the
> > port config.
> >
> > Signed-off-by: Li Jun <jun.li@nxp.com>
> > ---
> >   drivers/staging/typec/tcpci.c | 89
> +++++++++++++++++++++++++++++++++++++++----
> >   include/linux/usb/tcpm.h      |  6 +--
> >   2 files changed, 85 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/staging/typec/tcpci.c
> > b/drivers/staging/typec/tcpci.c index 4636804..0119453 100644
> > --- a/drivers/staging/typec/tcpci.c
> > +++ b/drivers/staging/typec/tcpci.c
> > @@ -425,17 +425,92 @@ static const struct regmap_config
> tcpci_regmap_config = {
> >   	.max_register = 0x7F, /* 0x80 .. 0xFF are vendor defined */
> >   };
> >
> > -static const struct tcpc_config tcpci_tcpc_config = {
> > -	.type = TYPEC_PORT_DFP,
> > -	.default_role = TYPEC_SINK,
> > -};
> > -
> > +/* Populate struct tcpc_config from device-tree */
> >   static int tcpci_parse_config(struct tcpci *tcpci)
> >   {
> > +	struct tcpc_config *tcfg;
> > +	int ret = -EINVAL;
> > +
> >   	tcpci->controls_vbus = true; /* XXX */
> >
> > -	/* TODO: Populate struct tcpc_config from ACPI/device-tree */
> > -	tcpci->tcpc.config = &tcpci_tcpc_config;
> > +	tcpci->tcpc.config = devm_kzalloc(tcpci->dev, sizeof(*tcfg),
> > +					  GFP_KERNEL);
> > +	if (!tcpci->tcpc.config)
> > +		return -ENOMEM;
> > +
> > +	tcfg = tcpci->tcpc.config;
> > +
> > +	/* Get port-type */
> > +	ret = typec_get_port_type(tcpci->dev);
> > +	if (ret < 0) {
> > +		dev_err(tcpci->dev, "typec port type is NOT correct!\n");
> 
> Are all those exclamation marks necessary ?

I will remove it.

> 
> > +		return ret;
> > +	}
> > +	tcfg->type = ret;
> > +
> > +	if (tcfg->type == TYPEC_PORT_UFP)
> > +		goto sink;
> > +
> > +	/* Get source PDO */
> > +	tcfg->nr_src_pdo = device_property_read_u32_array(tcpci->dev,
> > +						"src-pdos", NULL, 0);
> 
> I personally prefer continuation line alignment to '(', but that is up to Greg to
> decide.
> 
> > +	if (tcfg->nr_src_pdo <= 0) {
> > +		dev_err(tcpci->dev, "typec source pdo is missing!\n");
> > +		return -EINVAL;
> > +	}
> > +
> > +	tcfg->src_pdo = devm_kzalloc(tcpci->dev,
> > +		sizeof(*tcfg->src_pdo) * tcfg->nr_src_pdo, GFP_KERNEL);
> 
> devm_kcalloc

Will change.

> 
> > +	if (!tcfg->src_pdo)
> > +		return -ENOMEM;
> > +
> > +	ret = device_property_read_u32_array(tcpci->dev, "src-pdos",
> > +				tcfg->src_pdo, tcfg->nr_src_pdo);
> > +	if (ret) {
> > +		dev_err(tcpci->dev, "Failed to read src pdo!\n");
> > +		return -EINVAL;
> > +	}
> > +
> > +	if (tcfg->type == TYPEC_PORT_DFP)
> > +		return 0;
> > +
> > +	/* Get the preferred power role for drp */
> > +	ret = typec_get_power_role(tcpci->dev);
> 
> Maybe this should be named typec_get_preferred_role(). The generic function
> names are a bit misleading; they suggest they would return the current role, and
> don't indicate that the data is from device properties.

Thanks,  typec_get_preferred_role() looks more precise, I will change.

> I am also not sure about the mix of using typec infra functions and direct
> device_property calls.

OK, I will try to also use typec infra functions for those device_property
calls(some may be grouped).	

> 
> > +	if (ret < 0) {
> > +		dev_err(tcpci->dev, "typec preferred role is wrong!\n");
> 
> Wrong or missing ?

Both wrong and missing will return negative error code, I will refine it.

> 
> > +		return ret;
> > +	}
> > +	tcfg->default_role = ret;
> > +sink:
> > +	/* Get sink power capability */
> > +	tcfg->nr_snk_pdo = device_property_read_u32_array(tcpci->dev,
> > +						"snk-pdos", NULL, 0);
> > +	if (tcfg->nr_snk_pdo <= 0) {
> > +		dev_err(tcpci->dev, "typec sink pdo is missing!\n");
> > +		return -EINVAL;
> > +	}
> > +
> > +	tcfg->snk_pdo = devm_kzalloc(tcpci->dev,
> > +		sizeof(*tcfg->snk_pdo) * tcfg->nr_snk_pdo, GFP_KERNEL);
> > +	if (!tcfg->snk_pdo)
> > +		return -ENOMEM;
> > +
> > +	ret = device_property_read_u32_array(tcpci->dev, "snk-pdos",
> > +				tcfg->snk_pdo, tcfg->nr_snk_pdo);
> > +	if (ret) {
> > +		dev_err(tcpci->dev, "Failed to read sink pdo!\n");
> 
> There is a mix of "Failed to read" and "missing" messages. What is the
> difference ?

I will refine the error message.

> 
> > +		return -EINVAL;
> > +	}
> > +
> > +	if (device_property_read_u32(tcpci->dev, "max-snk-mv",
> > +				     &tcfg->max_snk_mv) ||
> > +		device_property_read_u32(tcpci->dev, "max-snk-ma",
> > +					 &tcfg->max_snk_ma) ||
> > +		device_property_read_u32(tcpci->dev, "op-snk-mw",
> > +					 &tcfg->operating_snk_mw)) {
> > +		dev_err(tcpci->dev, "Failed to read sink capability!\n");
> > +		return -EINVAL;
> > +	}
> >
> >   	return 0;
> >   }
> > diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h index
> > 073197f..a67cf77 100644
> > --- a/include/linux/usb/tcpm.h
> > +++ b/include/linux/usb/tcpm.h
> > @@ -76,10 +76,10 @@ enum tcpm_transmit_type {
> >    * @alt_modes:	List of supported alternate modes
> >    */
> >   struct tcpc_config {
> > -	const u32 *src_pdo;
> > +	u32 *src_pdo;
> >   	unsigned int nr_src_pdo;
> >
> > -	const u32 *snk_pdo;
> > +	u32 *snk_pdo;
> >   	unsigned int nr_snk_pdo;
> >
> >   	const u32 *snk_vdo;
> > @@ -154,7 +154,7 @@ struct tcpc_mux_dev {
> >    * @mux:	Pointer to multiplexer data
> >    */
> >   struct tcpc_dev {
> > -	const struct tcpc_config *config;
> > +	struct tcpc_config *config;
> >
> >   	int (*init)(struct tcpc_dev *dev);
> >   	int (*get_vbus)(struct tcpc_dev *dev);
> >


^ permalink raw reply	[flat|nested] 34+ messages in thread

* RE: [PATCH 05/12] staging: typec: tcpci: register port before request irq
       [not found]         ` <da64a379-f9bc-5ad8-44a5-f61c4419e1e7-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
@ 2017-09-26 14:16           ` Jun Li
  0 siblings, 0 replies; 34+ messages in thread
From: Jun Li @ 2017-09-26 14:16 UTC (permalink / raw)
  To: Guenter Roeck, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	Peter Chen, A.s. Dong, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

Hi

> -----Original Message-----
> From: Guenter Roeck [mailto:groeck7@gmail.com] On Behalf Of Guenter Roeck
> Sent: Tuesday, September 26, 2017 9:34 PM
> To: Jun Li <jun.li@nxp.com>; gregkh@linuxfoundation.org; robh+dt@kernel.org;
> mark.rutland@arm.com; heikki.krogerus@linux.intel.com
> Cc: yueyao@google.com; o_leveque@orange.fr; Peter Chen
> <peter.chen@nxp.com>; A.s. Dong <aisheng.dong@nxp.com>; linux-
> usb@vger.kernel.org; devicetree@vger.kernel.org
> Subject: Re: [PATCH 05/12] staging: typec: tcpci: register port before request irq
> 
> On 09/25/2017 05:45 PM, Li Jun wrote:
> > With that we can clear any pending events and the port is registered
> > so driver can be ready to handle typec events once we request irq.
> >
> > Signed-off-by: Peter Chen <peter.chen@nxp.com>
> > Signed-off-by: Li Jun <jun.li@nxp.com>
> > ---
> >   drivers/staging/typec/tcpci.c | 11 +++++------
> >   1 file changed, 5 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/staging/typec/tcpci.c
> > b/drivers/staging/typec/tcpci.c index 0119453..6d608b4 100644
> > --- a/drivers/staging/typec/tcpci.c
> > +++ b/drivers/staging/typec/tcpci.c
> > @@ -552,15 +552,14 @@ static int tcpci_probe(struct i2c_client *client,
> >   	/* Disable chip interrupts */
> >   	tcpci_write16(tcpci, TCPC_ALERT_MASK, 0);
> >
> > -	err = devm_request_threaded_irq(tcpci->dev, client->irq, NULL,
> > +	tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
> > +	if (IS_ERR(tcpci->port))
> > +		return PTR_ERR(tcpci->port);
> > +
> > +	return devm_request_threaded_irq(tcpci->dev, client->irq, NULL,
> >   					tcpci_irq,
> >   					IRQF_ONESHOT | IRQF_TRIGGER_LOW,
> >   					dev_name(tcpci->dev), tcpci);
> > -	if (err < 0)
> > -		return err;
> > -
> > -	tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
> > -	return PTR_ERR_OR_ZERO(tcpci->port);
> 
> This leaves the port registered if registering the irq fails.

I will add an error handling with tcpm_unregister_port().

> 
> >   }
> >
> >   static int tcpci_remove(struct i2c_client *client)
> >


^ permalink raw reply	[flat|nested] 34+ messages in thread

* RE: [PATCH 06/12] staging: typec: tcpci: enable vbus detection
       [not found]         ` <6cbb9cb2-206d-64e3-9e91-77edce855fdd-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
@ 2017-09-26 14:17           ` Jun Li
  0 siblings, 0 replies; 34+ messages in thread
From: Jun Li @ 2017-09-26 14:17 UTC (permalink / raw)
  To: Guenter Roeck, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	Peter Chen, A.s. Dong, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 2720 bytes --]



> -----Original Message-----
> From: Guenter Roeck [mailto:groeck7@gmail.com] On Behalf Of Guenter Roeck
> Sent: Tuesday, September 26, 2017 9:37 PM
> To: Jun Li <jun.li@nxp.com>; gregkh@linuxfoundation.org; robh+dt@kernel.org;
> mark.rutland@arm.com; heikki.krogerus@linux.intel.com
> Cc: yueyao@google.com; o_leveque@orange.fr; Peter Chen
> <peter.chen@nxp.com>; A.s. Dong <aisheng.dong@nxp.com>; linux-
> usb@vger.kernel.org; devicetree@vger.kernel.org
> Subject: Re: [PATCH 06/12] staging: typec: tcpci: enable vbus detection
> 
> On 09/25/2017 05:45 PM, Li Jun wrote:
> > TCPCI implementation may need SW to enable VBUS detection to generate
> > power status events.
> >
> > Signed-off-by: Li Jun <jun.li@nxp.com>
> > ---
> >   drivers/staging/typec/tcpci.c | 23 +++++++++++++++++++++++
> >   1 file changed, 23 insertions(+)
> >
> > diff --git a/drivers/staging/typec/tcpci.c
> > b/drivers/staging/typec/tcpci.c index 6d608b4..851d026 100644
> > --- a/drivers/staging/typec/tcpci.c
> > +++ b/drivers/staging/typec/tcpci.c
> > @@ -313,6 +313,26 @@ static int tcpci_pd_transmit(struct tcpc_dev *tcpc,
> >   	return 0;
> >   }
> >
> > +static int tcpci_vbus_detect(struct tcpc_dev *tcpc, bool enable) {
> > +	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
> > +	int ret;
> > +
> > +	if (enable) {
> > +		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
> > +				   TCPC_CMD_ENABLE_VBUS_DETECT);
> > +		if (ret < 0)
> > +			return ret;
> > +	} else {
> > +		ret = regmap_write(tcpci->regmap, TCPC_COMMAND,
> > +				   TCPC_CMD_DISABLE_VBUS_DETECT);
> > +		if (ret < 0)
> > +			return ret;
> > +	}
> 
> This could be simplified to something like
> 
>          u8 cmd = enabled ? TCPC_CMD_ENABLE_VBUS_DETECT :
> TCPC_CMD_DISABLE_VBUS_DETECT;
> 
> 	return regmap_write(tcpci->regmap, TCPC_COMMAND, cmd);
> 
> though the question is why not just add a function named
> tcpci_vbus_detect_enable() since it is never disabled, at least not in this patch.

Will change to be tcpci_vbus_detect_enable().

> 
> > +
> > +	return 0;
> > +}
> > +
> >   static int tcpci_init(struct tcpc_dev *tcpc)
> >   {
> >   	struct tcpci *tcpci = tcpc_to_tcpci(tcpc); @@ -344,6 +364,9 @@
> > static int tcpci_init(struct tcpc_dev *tcpc)
> >   	if (ret < 0)
> >   		return ret;
> >
> > +	/* Enable Vbus detection */
> > +	tcpci_vbus_detect(tcpc, true);
> > +
> >   	reg = TCPC_ALERT_TX_SUCCESS | TCPC_ALERT_TX_FAILED |
> >   		TCPC_ALERT_TX_DISCARDED | TCPC_ALERT_RX_STATUS |
> >   		TCPC_ALERT_RX_HARD_RST | TCPC_ALERT_CC_STATUS;
> >

N‹§²æìr¸›yúèšØb²X¬¶Ç§vØ^–)Þº{.nÇ+‰·zøœzÚÞz)í…æèw*\x1fjg¬±¨\x1e¶‰šŽŠÝ¢j.ïÛ°\½½MŽúgjÌæa×\x02››–' ™©Þ¢¸\f¢·¦j:+v‰¨ŠwèjØm¶Ÿÿ¾\a«‘êçzZ+ƒùšŽŠÝ¢j"ú!¶i

^ permalink raw reply	[flat|nested] 34+ messages in thread

* RE: [PATCH 07/12] typec: tcpm: add starting value for drp toggling
       [not found]         ` <ceae0f45-5d14-8e7f-3258-aa2e28fcf9bc-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
@ 2017-09-26 14:25           ` Jun Li
  0 siblings, 0 replies; 34+ messages in thread
From: Jun Li @ 2017-09-26 14:25 UTC (permalink / raw)
  To: Guenter Roeck, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	Peter Chen, A.s. Dong, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

Hi

> -----Original Message-----
> From: Guenter Roeck [mailto:groeck7@gmail.com] On Behalf Of Guenter Roeck
> Sent: Tuesday, September 26, 2017 9:43 PM
> To: Jun Li <jun.li@nxp.com>; gregkh@linuxfoundation.org; robh+dt@kernel.org;
> mark.rutland@arm.com; heikki.krogerus@linux.intel.com
> Cc: yueyao@google.com; o_leveque@orange.fr; Peter Chen
> <peter.chen@nxp.com>; A.s. Dong <aisheng.dong@nxp.com>; linux-
> usb@vger.kernel.org; devicetree@vger.kernel.org
> Subject: Re: [PATCH 07/12] typec: tcpm: add starting value for drp toggling
> 
> On 09/25/2017 05:45 PM, Li Jun wrote:
> > As DRP port autonomously toggles the Rp/Rd need a start value to begin
> > with, so add one parameter for it in tcpm_start_drp_toggling.
> >
> 
> It does have a starting value. The patch changes the starting value to
> TYPEC_CC_RD (from currently one of the RP states) when entering the
> SNK_UNATTACHED state.
> Please provide a matching description.

Yes, actually it's a mismatch, when entering the SNK_UNATTACHED,
we should start from Rd, see TCPCI spec:
Figure 4-11. TCPC State Diagram before a Connection

> 
> > Signed-off-by: Li Jun <jun.li@nxp.com>
> > ---
> >   drivers/usb/typec/tcpm.c | 10 +++++-----
> >   1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c index
> > 8483d3e..38a6223 100644
> > --- a/drivers/usb/typec/tcpm.c
> > +++ b/drivers/usb/typec/tcpm.c
> > @@ -1839,15 +1839,15 @@ static int tcpm_set_charge(struct tcpm_port
> *port, bool charge)
> >   	return 0;
> >   }
> >
> > -static bool tcpm_start_drp_toggling(struct tcpm_port *port)
> > +static bool tcpm_start_drp_toggling(struct tcpm_port *port,
> > +				    enum typec_cc_status cc)
> >   {
> >   	int ret;
> >
> >   	if (port->tcpc->start_drp_toggling &&
> >   	    port->port_type == TYPEC_PORT_DRP) {
> >   		tcpm_log_force(port, "Start DRP toggling");
> > -		ret = port->tcpc->start_drp_toggling(port->tcpc,
> > -						     tcpm_rp_cc(port));
> > +		ret = port->tcpc->start_drp_toggling(port->tcpc, cc);
> >   		if (!ret)
> >   			return true;
> >   	}
> > @@ -2156,7 +2156,7 @@ static void run_state_machine(struct tcpm_port
> *port)
> >   		if (!port->non_pd_role_swap)
> >   			tcpm_swap_complete(port, -ENOTCONN);
> >   		tcpm_src_detach(port);
> > -		if (tcpm_start_drp_toggling(port)) {
> > +		if (tcpm_start_drp_toggling(port, tcpm_rp_cc(port))) {
> >   			tcpm_set_state(port, DRP_TOGGLING, 0);
> >   			break;
> >   		}
> > @@ -2328,7 +2328,7 @@ static void run_state_machine(struct tcpm_port
> *port)
> >   		if (!port->non_pd_role_swap)
> >   			tcpm_swap_complete(port, -ENOTCONN);
> >   		tcpm_snk_detach(port);
> > -		if (tcpm_start_drp_toggling(port)) {
> > +		if (tcpm_start_drp_toggling(port, TYPEC_CC_RD)) {
> >   			tcpm_set_state(port, DRP_TOGGLING, 0);
> >   			break;
> >   		}
> >


^ permalink raw reply	[flat|nested] 34+ messages in thread

* RE: [PATCH 10/12] staging: typec: tcpci: update set_cc for different state
       [not found]         ` <8ef676a1-4c2b-cea7-ad79-c50fb8d091fb-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
@ 2017-09-26 14:39           ` Jun Li
  0 siblings, 0 replies; 34+ messages in thread
From: Jun Li @ 2017-09-26 14:39 UTC (permalink / raw)
  To: Guenter Roeck, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	heikki.krogerus-VuQAYsv1563Yd54FQh9/CA
  Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA, o_leveque-1tsiiZ//OF9QFI55V6+gNQ,
	Peter Chen, A.s. Dong, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 4766 bytes --]

Hi

> -----Original Message-----
> From: Guenter Roeck [mailto:groeck7@gmail.com] On Behalf Of Guenter Roeck
> Sent: Tuesday, September 26, 2017 9:50 PM
> To: Jun Li <jun.li@nxp.com>; gregkh@linuxfoundation.org; robh+dt@kernel.org;
> mark.rutland@arm.com; heikki.krogerus@linux.intel.com
> Cc: yueyao@google.com; o_leveque@orange.fr; Peter Chen
> <peter.chen@nxp.com>; A.s. Dong <aisheng.dong@nxp.com>; linux-
> usb@vger.kernel.org; devicetree@vger.kernel.org
> Subject: Re: [PATCH 10/12] staging: typec: tcpci: update set_cc for different
> state
> 
> On 09/25/2017 05:45 PM, Li Jun wrote:
> > As we should keep the disconnected cc line to be open when attached,
> > so update the set_cc interface accordingly for it.
> >
> > Signed-off-by: Li Jun <jun.li@nxp.com>
> > ---
> >   drivers/staging/typec/tcpci.c | 37 +++++++++++++++++++++----------------
> >   1 file changed, 21 insertions(+), 16 deletions(-)
> >
> > diff --git a/drivers/staging/typec/tcpci.c
> > b/drivers/staging/typec/tcpci.c index cea67f9..c7c45da 100644
> > --- a/drivers/staging/typec/tcpci.c
> > +++ b/drivers/staging/typec/tcpci.c
> > @@ -57,10 +57,11 @@ static int tcpci_write16(struct tcpci *tcpci, unsigned int
> reg, u16 val)
> >   	return regmap_raw_write(tcpci->regmap, reg, &val, sizeof(u16));
> >   }
> >
> > -static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status
> > cc)
> > +static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc,
> > +			bool attached, enum typec_cc_polarity polarity)
> >   {
> >   	struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
> > -	unsigned int reg;
> > +	unsigned int reg = 0, reg_cc1 = 0, reg_cc2 = 0;
> >   	int ret;
> >
> >   	switch (cc) {
> > @@ -69,26 +70,23 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum
> typec_cc_status cc)
> >   			(TCPC_ROLE_CTRL_CC_RA <<
> TCPC_ROLE_CTRL_CC2_SHIFT);
> >   		break;
> >   	case TYPEC_CC_RD:
> > -		reg = (TCPC_ROLE_CTRL_CC_RD <<
> TCPC_ROLE_CTRL_CC1_SHIFT) |
> > -			(TCPC_ROLE_CTRL_CC_RD <<
> TCPC_ROLE_CTRL_CC2_SHIFT);
> > +		reg_cc1 = TCPC_ROLE_CTRL_CC_RD <<
> TCPC_ROLE_CTRL_CC1_SHIFT;
> > +		reg_cc2 = TCPC_ROLE_CTRL_CC_RD <<
> TCPC_ROLE_CTRL_CC2_SHIFT;
> >   		break;
> >   	case TYPEC_CC_RP_DEF:
> > -		reg = (TCPC_ROLE_CTRL_CC_RP <<
> TCPC_ROLE_CTRL_CC1_SHIFT) |
> > -			(TCPC_ROLE_CTRL_CC_RP <<
> TCPC_ROLE_CTRL_CC2_SHIFT) |
> > -			(TCPC_ROLE_CTRL_RP_VAL_DEF <<
> > -			 TCPC_ROLE_CTRL_RP_VAL_SHIFT);
> > +		reg_cc1 = TCPC_ROLE_CTRL_CC_RP <<
> TCPC_ROLE_CTRL_CC1_SHIFT;
> > +		reg_cc2 = TCPC_ROLE_CTRL_CC_RP <<
> TCPC_ROLE_CTRL_CC2_SHIFT;
> > +		reg = TCPC_ROLE_CTRL_RP_VAL_DEF <<
> TCPC_ROLE_CTRL_RP_VAL_SHIFT;
> >   		break;
> >   	case TYPEC_CC_RP_1_5:
> > -		reg = (TCPC_ROLE_CTRL_CC_RP <<
> TCPC_ROLE_CTRL_CC1_SHIFT) |
> > -			(TCPC_ROLE_CTRL_CC_RP <<
> TCPC_ROLE_CTRL_CC2_SHIFT) |
> > -			(TCPC_ROLE_CTRL_RP_VAL_1_5 <<
> > -			 TCPC_ROLE_CTRL_RP_VAL_SHIFT);
> > +		reg_cc1 = TCPC_ROLE_CTRL_CC_RP <<
> TCPC_ROLE_CTRL_CC1_SHIFT;
> > +		reg_cc2 = TCPC_ROLE_CTRL_CC_RP <<
> TCPC_ROLE_CTRL_CC2_SHIFT;
> > +		reg = TCPC_ROLE_CTRL_RP_VAL_1_5 <<
> TCPC_ROLE_CTRL_RP_VAL_SHIFT;
> >   		break;
> >   	case TYPEC_CC_RP_3_0:
> > -		reg = (TCPC_ROLE_CTRL_CC_RP <<
> TCPC_ROLE_CTRL_CC1_SHIFT) |
> > -			(TCPC_ROLE_CTRL_CC_RP <<
> TCPC_ROLE_CTRL_CC2_SHIFT) |
> > -			(TCPC_ROLE_CTRL_RP_VAL_3_0 <<
> > -			 TCPC_ROLE_CTRL_RP_VAL_SHIFT);
> > +		reg_cc1 = TCPC_ROLE_CTRL_CC_RP <<
> TCPC_ROLE_CTRL_CC1_SHIFT;
> > +		reg_cc2 = TCPC_ROLE_CTRL_CC_RP <<
> TCPC_ROLE_CTRL_CC2_SHIFT;
> > +		reg = TCPC_ROLE_CTRL_RP_VAL_3_0 <<
> TCPC_ROLE_CTRL_RP_VAL_SHIFT;
> >   		break;
> >   	case TYPEC_CC_OPEN:
> >   	default:
> > @@ -97,6 +95,13 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum
> typec_cc_status cc)
> >   		break;
> >   	}
> >
> > +	if (!attached)
> > +		reg |= reg_cc1 | reg_cc2;
> > +	else if (polarity == TYPEC_POLARITY_CC1)
> > +		reg |= reg_cc1;
> > +	else
> > +		reg |= reg_cc2;
> > +
> 
> I think this is wrong. The value of CC pins should not depend on the state of the
> state machine. What if the state machine knows the polarity but is in a transient
> state ?.
> 

Agree with you this API change will make set_cc somehow independent. 
tcpci_set_polarity() maybe the right place to cover this.

> I am also not sure if the chip should ever set both CC lines at the same time.

To look for connection, both CC lines should be set at the same time for possible
contact.

> 
> Guenter
> 
> >   	ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg);
> >   	if (ret < 0)
> >   		return ret;
> >

N‹§²æìr¸›yúèšØb²X¬¶Ç§vØ^–)Þº{.nÇ+‰·zøœzÚÞz)í…æèw*\x1fjg¬±¨\x1e¶‰šŽŠÝ¢j.ïÛ°\½½MŽúgjÌæa×\x02››–' ™©Þ¢¸\f¢·¦j:+v‰¨ŠwèjØm¶Ÿÿ¾\a«‘êçzZ+ƒùšŽŠÝ¢j"ú!¶i

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2017-09-26 14:39 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-26  0:45 [PATCH 00/12] staging: typec: tcpci: move out of staging Li Jun
     [not found] ` <1506386727-16370-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26  0:45   ` [PATCH 01/12] usb: typec: add API to get port type and preferred role Li Jun
     [not found]     ` <1506386727-16370-2-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26  8:02       ` Heikki Krogerus
     [not found]         ` <20170926080231.GB14296-FZxXFokcWpatqXYlAKuG4QC/G2K4zDHf@public.gmane.org>
2017-09-26  9:55           ` Jun Li
2017-09-26 13:20       ` Guenter Roeck
2017-09-26  0:45   ` [PATCH 02/12] usb: typec: add basic typec properties Li Jun
     [not found]     ` <1506386727-16370-3-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26  8:23       ` Heikki Krogerus
     [not found]         ` <20170926082300.GC14296-FZxXFokcWpatqXYlAKuG4QC/G2K4zDHf@public.gmane.org>
2017-09-26 10:09           ` Jun Li
2017-09-26  0:45   ` [PATCH 03/12] staging: typec: tcpci: add documentation for tcpci Li Jun
2017-09-26  0:45   ` [PATCH 04/12] staging: typec: tcpci: support port config passed via dt Li Jun
     [not found]     ` <1506386727-16370-5-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 13:32       ` Guenter Roeck
     [not found]         ` <bb854ecf-fad7-2c2a-1972-5c4cabb970f2-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2017-09-26 14:14           ` Jun Li
2017-09-26  0:45   ` [PATCH 05/12] staging: typec: tcpci: register port before request irq Li Jun
     [not found]     ` <1506386727-16370-6-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 13:33       ` Guenter Roeck
     [not found]         ` <da64a379-f9bc-5ad8-44a5-f61c4419e1e7-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2017-09-26 14:16           ` Jun Li
2017-09-26  0:45   ` [PATCH 06/12] staging: typec: tcpci: enable vbus detection Li Jun
     [not found]     ` <1506386727-16370-7-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 13:37       ` Guenter Roeck
     [not found]         ` <6cbb9cb2-206d-64e3-9e91-77edce855fdd-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2017-09-26 14:17           ` Jun Li
2017-09-26  0:45   ` [PATCH 07/12] typec: tcpm: add starting value for drp toggling Li Jun
     [not found]     ` <1506386727-16370-8-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 13:42       ` Guenter Roeck
     [not found]         ` <ceae0f45-5d14-8e7f-3258-aa2e28fcf9bc-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2017-09-26 14:25           ` Jun Li
2017-09-26  0:45   ` [PATCH 08/12] staging: typec: tcpci: correct " Li Jun
2017-09-26  0:45   ` [PATCH 09/12] usb: typec: tcpm: only drives the connected cc line when attached Li Jun
     [not found]     ` <1506386727-16370-10-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26  7:16       ` Guenter Roeck
     [not found]         ` <9c461105-fa96-3989-5a95-b9f82b154ea2-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2017-09-26  9:53           ` Jun Li
     [not found]             ` <DB4PR04MB07689A95430FA6F4AA219539897B0-tLF+feb1Bz6HC8XOQgzeLs9NdZoXdze2vxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-09-26 13:20               ` Guenter Roeck
     [not found]                 ` <e79d8143-1187-f3c4-6030-ecf28e3d2fff-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2017-09-26 13:57                   ` Jun Li
2017-09-26  0:45   ` [PATCH 10/12] staging: typec: tcpci: update set_cc for different state Li Jun
     [not found]     ` <1506386727-16370-11-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26 13:49       ` Guenter Roeck
     [not found]         ` <8ef676a1-4c2b-cea7-ad79-c50fb8d091fb-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2017-09-26 14:39           ` Jun Li
2017-09-26  0:45   ` [PATCH 11/12] staging: typec: tcpci: Only touch target bit when enable vconn Li Jun
2017-09-26  0:45   ` [PATCH 12/12] staging: typec: tcpci: move tcpci driver out of staging Li Jun
     [not found]     ` <1506386727-16370-13-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org>
2017-09-26  6:57       ` Greg KH
     [not found]         ` <20170926065749.GE6250-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2017-09-26  7:16           ` Jun Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.