devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/6] phy: rockchip-typec: deprecate some DT properties for various register fields.
@ 2018-02-14 16:54 Enric Balletbo i Serra
  2018-02-14 16:54 ` [PATCH v2 2/6] dt-bindings: phy-rockchip-typec: deprecate some register properties Enric Balletbo i Serra
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Enric Balletbo i Serra @ 2018-02-14 16:54 UTC (permalink / raw)
  To: Rob Herring, Kishon Vijay Abraham I, Brian Norris
  Cc: Heiko Stuebner, dianders-F7+t8E8rja9g9hUCZPvPmw, Chris Zhong,
	William wu, hl-TNX95d0MmH7DzftRWevZcw,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	kernel-ZGY8ohtN/8qB+jHODAdFcQ

Adding properties for various register fields in the DT doesn't scale and
this information should be in the driver instead.

Before this patch these registers (description below) were specified in
the DT, every register node contained 3 sections: offset, enable bit,
write mask bit.

 - rockchip,typec-conn-dir : the register of type-c connector direction,
   for type-c phy0, it must be <0xe580 0 16>;
   for type-c phy1, it must be <0xe58c 0 16>;
 - rockchip,usb3tousb2-en : the register of type-c force usb3 to usb2 enable
   control.
   for type-c phy0, it must be <0xe580 3 19>;
   for type-c phy1, it must be <0xe58c 3 19>;
 - rockchip,external-psm : the register of type-c phy external psm clock
   selection.
   for type-c phy0, it must be <0xe588 14 30>;
   for type-c phy1, it must be <0xe594 14 30>;
 - rockchip,pipe-status : the register of type-c phy pipe status.
   for type-c phy0, it must be <0xe5c0 0 0>;
   for type-c phy1, it must be <0xe5c0 16 16>;

After this patch these register definitions are in the driver. So can be
removed from the DT. Note that there are 2 type-c phys for RK3399 with
different offsets, the driver checks the phy base address of the running
instance and applies the right offsets.

Signed-off-by: Enric Balletbo i Serra <enric.balletbo-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
---
Changes since v1:
- This patch is new in this series to accomplish the purpose of get rid
  of some registers from the DT. Suggested by Rob Herring.

 drivers/phy/rockchip/phy-rockchip-typec.c | 74 ++++++++++++-------------------
 1 file changed, 28 insertions(+), 46 deletions(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-typec.c b/drivers/phy/rockchip/phy-rockchip-typec.c
index 7492c8978217..291493d9e9b6 100644
--- a/drivers/phy/rockchip/phy-rockchip-typec.c
+++ b/drivers/phy/rockchip/phy-rockchip-typec.c
@@ -349,6 +349,9 @@
 #define MODE_DFP_USB			BIT(1)
 #define MODE_DFP_DP			BIT(2)
 
+#define TYPEC_PHY0_BASE_ADDRESS		0xff7c0000
+#define TYPEC_PHY1_BASE_ADDRESS		0xff800000
+
 struct usb3phy_reg {
 	u32 offset;
 	u32 enable_bit;
@@ -362,6 +365,20 @@ struct rockchip_usb3phy_port_cfg {
 	struct usb3phy_reg pipe_status;
 };
 
+static const struct rockchip_usb3phy_port_cfg tcphy0_port_cfg = {
+	.typec_conn_dir	= { 0xe580, 0, 16 },
+	.usb3tousb2_en	= { 0xe580, 3, 19 },
+	.external_psm	= { 0xe588, 14, 30 },
+	.pipe_status	= { 0xe5c0, 0, 0 },
+};
+
+static const struct rockchip_usb3phy_port_cfg tcphy1_port_cfg = {
+	.typec_conn_dir	= { 0xe58c, 0, 16 },
+	.usb3tousb2_en	= { 0xe58c, 3, 19 },
+	.external_psm	= { 0xe594, 14, 30 },
+	.pipe_status	= { 0xe5c0, 16, 16 },
+};
+
 struct rockchip_typec_phy {
 	struct device *dev;
 	void __iomem *base;
@@ -372,7 +389,7 @@ struct rockchip_typec_phy {
 	struct reset_control *uphy_rst;
 	struct reset_control *pipe_rst;
 	struct reset_control *tcphy_rst;
-	struct rockchip_usb3phy_port_cfg port_cfgs;
+	const struct rockchip_usb3phy_port_cfg *port_cfgs;
 	/* mutex to protect access to individual PHYs */
 	struct mutex lock;
 
@@ -691,7 +708,7 @@ static void tcphy_dp_aux_calibration(struct rockchip_typec_phy *tcphy)
 
 static int tcphy_phy_init(struct rockchip_typec_phy *tcphy, u8 mode)
 {
-	struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs;
+	const struct rockchip_usb3phy_port_cfg *cfg = tcphy->port_cfgs;
 	int ret, i;
 	u32 val;
 
@@ -821,7 +838,7 @@ static int tcphy_get_mode(struct rockchip_typec_phy *tcphy)
 static int rockchip_usb3_phy_power_on(struct phy *phy)
 {
 	struct rockchip_typec_phy *tcphy = phy_get_drvdata(phy);
-	struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs;
+	const struct rockchip_usb3phy_port_cfg *cfg = tcphy->port_cfgs;
 	const struct usb3phy_reg *reg = &cfg->pipe_status;
 	int timeout, new_mode, ret = 0;
 	u32 val;
@@ -984,51 +1001,9 @@ static const struct phy_ops rockchip_dp_phy_ops = {
 	.owner		= THIS_MODULE,
 };
 
-static int tcphy_get_param(struct device *dev,
-			   struct usb3phy_reg *reg,
-			   const char *name)
-{
-	u32 buffer[3];
-	int ret;
-
-	ret = of_property_read_u32_array(dev->of_node, name, buffer, 3);
-	if (ret) {
-		dev_err(dev, "Can not parse %s\n", name);
-		return ret;
-	}
-
-	reg->offset = buffer[0];
-	reg->enable_bit = buffer[1];
-	reg->write_enable = buffer[2];
-	return 0;
-}
-
 static int tcphy_parse_dt(struct rockchip_typec_phy *tcphy,
 			  struct device *dev)
 {
-	struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs;
-	int ret;
-
-	ret = tcphy_get_param(dev, &cfg->typec_conn_dir,
-			      "rockchip,typec-conn-dir");
-	if (ret)
-		return ret;
-
-	ret = tcphy_get_param(dev, &cfg->usb3tousb2_en,
-			      "rockchip,usb3tousb2-en");
-	if (ret)
-		return ret;
-
-	ret = tcphy_get_param(dev, &cfg->external_psm,
-			      "rockchip,external-psm");
-	if (ret)
-		return ret;
-
-	ret = tcphy_get_param(dev, &cfg->pipe_status,
-			      "rockchip,pipe-status");
-	if (ret)
-		return ret;
-
 	tcphy->grf_regs = syscon_regmap_lookup_by_phandle(dev->of_node,
 							  "rockchip,grf");
 	if (IS_ERR(tcphy->grf_regs)) {
@@ -1071,7 +1046,7 @@ static int tcphy_parse_dt(struct rockchip_typec_phy *tcphy,
 
 static void typec_phy_pre_init(struct rockchip_typec_phy *tcphy)
 {
-	struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs;
+	const struct rockchip_usb3phy_port_cfg *cfg = tcphy->port_cfgs;
 
 	reset_control_assert(tcphy->tcphy_rst);
 	reset_control_assert(tcphy->uphy_rst);
@@ -1103,6 +1078,13 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)
 	if (IS_ERR(tcphy->base))
 		return PTR_ERR(tcphy->base);
 
+	if (res->start == TYPEC_PHY0_BASE_ADDRESS)
+		tcphy->port_cfgs = &tcphy0_port_cfg;
+	else if (res->start == TYPEC_PHY1_BASE_ADDRESS)
+		tcphy->port_cfgs = &tcphy1_port_cfg;
+	else
+		return -EINVAL;
+
 	ret = tcphy_parse_dt(tcphy, dev);
 	if (ret)
 		return ret;
-- 
2.15.1

--
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] 8+ messages in thread

* [PATCH v2 2/6] dt-bindings: phy-rockchip-typec: deprecate some register properties.
  2018-02-14 16:54 [PATCH v2 1/6] phy: rockchip-typec: deprecate some DT properties for various register fields Enric Balletbo i Serra
@ 2018-02-14 16:54 ` Enric Balletbo i Serra
       [not found]   ` <20180214165447.12181-2-enric.balletbo-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
  2018-02-14 16:54 ` [PATCH v2 3/6] phy: rockchip-typec: enable usb3 host during usb3 phy power on Enric Balletbo i Serra
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: Enric Balletbo i Serra @ 2018-02-14 16:54 UTC (permalink / raw)
  To: Rob Herring, Kishon Vijay Abraham I, Brian Norris
  Cc: Heiko Stuebner, dianders, Chris Zhong, William wu, hl,
	devicetree, linux-arm-kernel, linux-rockchip, linux-kernel,
	kernel

As now the following register properties are in the driver, document as
deprecated these properties and recommend to not use them on new bindings.

The deprecated properties are:

- rockchip,typec-conn-dir : the register of type-c connector direction
- rockchip,usb3tousb2-en : the register of type-c force usb3 to usb2
                           enable control.
- rockchip,external-psm : the register of type-c phy external psm clock
                          selection.
- rockchip,pipe-status : the register of type-c phy pipe status.

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---
Changes since v1:
- This patch is new on these series and is just a documentation update
  due patch [1/6]

 .../devicetree/bindings/phy/phy-rockchip-typec.txt | 33 +++++-----------------
 1 file changed, 7 insertions(+), 26 deletions(-)

diff --git a/Documentation/devicetree/bindings/phy/phy-rockchip-typec.txt b/Documentation/devicetree/bindings/phy/phy-rockchip-typec.txt
index 6ea867e3176f..bc44d6abe283 100644
--- a/Documentation/devicetree/bindings/phy/phy-rockchip-typec.txt
+++ b/Documentation/devicetree/bindings/phy/phy-rockchip-typec.txt
@@ -16,24 +16,6 @@ Required properties:
 		 "uphy", "uphy-pipe", "uphy-tcphy"
  - extcon : extcon specifier for the Power Delivery
 
-Note, there are 2 type-c phys for RK3399, and they are almost identical, except
-these registers(description below), every register node contains 3 sections:
-offset, enable bit, write mask bit.
- - rockchip,typec-conn-dir : the register of type-c connector direction,
-   for type-c phy0, it must be <0xe580 0 16>;
-   for type-c phy1, it must be <0xe58c 0 16>;
- - rockchip,usb3tousb2-en : the register of type-c force usb3 to usb2 enable
-   control.
-   for type-c phy0, it must be <0xe580 3 19>;
-   for type-c phy1, it must be <0xe58c 3 19>;
- - rockchip,external-psm : the register of type-c phy external psm clock
-   selection.
-   for type-c phy0, it must be <0xe588 14 30>;
-   for type-c phy1, it must be <0xe594 14 30>;
- - rockchip,pipe-status : the register of type-c phy pipe status.
-   for type-c phy0, it must be <0xe5c0 0 0>;
-   for type-c phy1, it must be <0xe5c0 16 16>;
-
 Required nodes : a sub-node is required for each port the phy provides.
 		 The sub-node name is used to identify dp or usb3 port,
 		 and shall be the following entries:
@@ -43,6 +25,13 @@ Required nodes : a sub-node is required for each port the phy provides.
 Required properties (port (child) node):
 - #phy-cells : must be 0, See ./phy-bindings.txt for details.
 
+Deprecated properties, do not use in new device tree sources, these
+properties are now in the driver:
+ - rockchip,typec-conn-dir
+ - rockchip,usb3tousb2-en
+ - rockchip,external-psm
+ - rockchip,pipe-status
+
 Example:
 	tcphy0: phy@ff7c0000 {
 		compatible = "rockchip,rk3399-typec-phy";
@@ -58,10 +47,6 @@ Example:
 			 <&cru SRST_UPHY0_PIPE_L00>,
 			 <&cru SRST_P_UPHY0_TCPHY>;
 		reset-names = "uphy", "uphy-pipe", "uphy-tcphy";
-		rockchip,typec-conn-dir = <0xe580 0 16>;
-		rockchip,usb3tousb2-en = <0xe580 3 19>;
-		rockchip,external-psm = <0xe588 14 30>;
-		rockchip,pipe-status = <0xe5c0 0 0>;
 
 		tcphy0_dp: dp-port {
 			#phy-cells = <0>;
@@ -86,10 +71,6 @@ Example:
 			 <&cru SRST_UPHY1_PIPE_L00>,
 			 <&cru SRST_P_UPHY1_TCPHY>;
 		reset-names = "uphy", "uphy-pipe", "uphy-tcphy";
-		rockchip,typec-conn-dir = <0xe58c 0 16>;
-		rockchip,usb3tousb2-en = <0xe58c 3 19>;
-		rockchip,external-psm = <0xe594 14 30>;
-		rockchip,pipe-status = <0xe5c0 16 16>;
 
 		tcphy1_dp: dp-port {
 			#phy-cells = <0>;
-- 
2.15.1

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

* [PATCH v2 3/6] phy: rockchip-typec: enable usb3 host during usb3 phy power on
  2018-02-14 16:54 [PATCH v2 1/6] phy: rockchip-typec: deprecate some DT properties for various register fields Enric Balletbo i Serra
  2018-02-14 16:54 ` [PATCH v2 2/6] dt-bindings: phy-rockchip-typec: deprecate some register properties Enric Balletbo i Serra
@ 2018-02-14 16:54 ` Enric Balletbo i Serra
  2018-02-14 16:54 ` [PATCH v2 4/6] phy: rockchip-typec: force to USB2 if DP at 4 lanes mode Enric Balletbo i Serra
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Enric Balletbo i Serra @ 2018-02-14 16:54 UTC (permalink / raw)
  To: Rob Herring, Kishon Vijay Abraham I, Brian Norris
  Cc: Heiko Stuebner, dianders, Chris Zhong, William wu, hl,
	devicetree, linux-arm-kernel, linux-rockchip, linux-kernel,
	kernel

From: William wu <wulf@rock-chips.com>

We have forced usb3 to work in usb2 only mode in firmware by setting
usb3tousb2_en (bit3 of GRF_USB3PHY0/1_CON0) to 1, and setting
host_u3_port_disable (bit0 of GRF_USB3OTG0/1_CON1) to 1 and host_u3_port
(bit15~12 of GRF_USB3OTG0/1_CON1) to 0. So we need to re-enable usb3
host.

Note that the RK3399 TRM suggests that we should keep the whole usb3
controller in reset for the duration of the Type-C PHY initialization.
However, it's hard to assert the reset in the current framework of
reset. And according to the TRM, it doesn't require that we should
clear the usb3tousb2 bit before pipe ready. So let's enable the usb3
host after pipe ready to avoid the Type-C PHY initialization failure.

Signed-off-by: William wu <wulf@rock-chips.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---
Changes since v1:
- Use the registers offsets from the driver not the DT.

 drivers/phy/rockchip/phy-rockchip-typec.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/phy/rockchip/phy-rockchip-typec.c b/drivers/phy/rockchip/phy-rockchip-typec.c
index 291493d9e9b6..40c5e7d6b5cb 100644
--- a/drivers/phy/rockchip/phy-rockchip-typec.c
+++ b/drivers/phy/rockchip/phy-rockchip-typec.c
@@ -363,6 +363,8 @@ struct rockchip_usb3phy_port_cfg {
 	struct usb3phy_reg usb3tousb2_en;
 	struct usb3phy_reg external_psm;
 	struct usb3phy_reg pipe_status;
+	struct usb3phy_reg usb3_host_disable;
+	struct usb3phy_reg usb3_host_port;
 };
 
 static const struct rockchip_usb3phy_port_cfg tcphy0_port_cfg = {
@@ -370,6 +372,8 @@ static const struct rockchip_usb3phy_port_cfg tcphy0_port_cfg = {
 	.usb3tousb2_en	= { 0xe580, 3, 19 },
 	.external_psm	= { 0xe588, 14, 30 },
 	.pipe_status	= { 0xe5c0, 0, 0 },
+	.usb3_host_disable = { 0x2434, 0, 16 },
+	.usb3_host_port = { 0x2434, 12, 28 },
 };
 
 static const struct rockchip_usb3phy_port_cfg tcphy1_port_cfg = {
@@ -377,6 +381,8 @@ static const struct rockchip_usb3phy_port_cfg tcphy1_port_cfg = {
 	.usb3tousb2_en	= { 0xe58c, 3, 19 },
 	.external_psm	= { 0xe594, 14, 30 },
 	.pipe_status	= { 0xe5c0, 16, 16 },
+	.usb3_host_disable = { 0x2444, 0, 16 },
+	.usb3_host_port = { 0x2444, 12, 28 },
 };
 
 struct rockchip_typec_phy {
@@ -869,6 +875,9 @@ static int rockchip_usb3_phy_power_on(struct phy *phy)
 		regmap_read(tcphy->grf_regs, reg->offset, &val);
 		if (!(val & BIT(reg->enable_bit))) {
 			tcphy->mode |= new_mode & (MODE_DFP_USB | MODE_UFP_USB);
+			/* enable usb3 host */
+			property_enable(tcphy, &cfg->usb3_host_disable, 0);
+			property_enable(tcphy, &cfg->usb3_host_port, 1);
 			goto unlock_ret;
 		}
 		usleep_range(10, 20);
-- 
2.15.1

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

* [PATCH v2 4/6] phy: rockchip-typec: force to USB2 if DP at 4 lanes mode
  2018-02-14 16:54 [PATCH v2 1/6] phy: rockchip-typec: deprecate some DT properties for various register fields Enric Balletbo i Serra
  2018-02-14 16:54 ` [PATCH v2 2/6] dt-bindings: phy-rockchip-typec: deprecate some register properties Enric Balletbo i Serra
  2018-02-14 16:54 ` [PATCH v2 3/6] phy: rockchip-typec: enable usb3 host during usb3 phy power on Enric Balletbo i Serra
@ 2018-02-14 16:54 ` Enric Balletbo i Serra
  2018-02-14 16:54 ` [PATCH v2 5/6] phy: rockchip-typec: support DP phy switch Enric Balletbo i Serra
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Enric Balletbo i Serra @ 2018-02-14 16:54 UTC (permalink / raw)
  To: Rob Herring, Kishon Vijay Abraham I, Brian Norris
  Cc: devicetree, hl, dianders, linux-kernel, linux-rockchip,
	Chris Zhong, William wu, kernel, linux-arm-kernel,
	Heiko Stuebner

From: Chris Zhong <zyw@rock-chips.com>

The usb3tousb2_en BIT will be clear to 0 in probe(), it make USB
controller work at USB3 mode, and if the USB phy is turned on with DP
only mode(4 lanes DP), the rockchip_usb3_phy_power_on() will return
directly, so usb3_host_disable and usb3_host_port these 2 BIT will keep
a same value as coreboot. In coreboot, these 3 BITs are set as USB2
mode, but now one of the bits is changed to USB3, it make USB controller
work at a unknown status.

These 3 BITs should be changed to USB2, if the Type-C works at 4 lanes
mode, and then switch it back to USB3 mode, when USB disconnect.

Signed-off-by: Chris Zhong <zyw@rock-chips.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---
Changes since v1:
- Use the registers offsets from the driver not the DT.

 drivers/phy/rockchip/phy-rockchip-typec.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-typec.c b/drivers/phy/rockchip/phy-rockchip-typec.c
index 40c5e7d6b5cb..95cd5db5c910 100644
--- a/drivers/phy/rockchip/phy-rockchip-typec.c
+++ b/drivers/phy/rockchip/phy-rockchip-typec.c
@@ -841,6 +841,18 @@ static int tcphy_get_mode(struct rockchip_typec_phy *tcphy)
 	return mode;
 }
 
+static int tcphy_cfg_usb3_to_usb2_only(struct rockchip_typec_phy *tcphy,
+				       bool value)
+{
+	struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs;
+
+	property_enable(tcphy, &cfg->usb3tousb2_en, value);
+	property_enable(tcphy, &cfg->usb3_host_disable, value);
+	property_enable(tcphy, &cfg->usb3_host_port, !value);
+
+	return 0;
+}
+
 static int rockchip_usb3_phy_power_on(struct phy *phy)
 {
 	struct rockchip_typec_phy *tcphy = phy_get_drvdata(phy);
@@ -858,8 +870,10 @@ static int rockchip_usb3_phy_power_on(struct phy *phy)
 	}
 
 	/* DP-only mode; fall back to USB2 */
-	if (!(new_mode & (MODE_DFP_USB | MODE_UFP_USB)))
+	if (!(new_mode & (MODE_DFP_USB | MODE_UFP_USB))) {
+		tcphy_cfg_usb3_to_usb2_only(tcphy, true);
 		goto unlock_ret;
+	}
 
 	if (tcphy->mode == new_mode)
 		goto unlock_ret;
@@ -875,9 +889,9 @@ static int rockchip_usb3_phy_power_on(struct phy *phy)
 		regmap_read(tcphy->grf_regs, reg->offset, &val);
 		if (!(val & BIT(reg->enable_bit))) {
 			tcphy->mode |= new_mode & (MODE_DFP_USB | MODE_UFP_USB);
+
 			/* enable usb3 host */
-			property_enable(tcphy, &cfg->usb3_host_disable, 0);
-			property_enable(tcphy, &cfg->usb3_host_port, 1);
+			tcphy_cfg_usb3_to_usb2_only(tcphy, false);
 			goto unlock_ret;
 		}
 		usleep_range(10, 20);
@@ -898,6 +912,7 @@ static int rockchip_usb3_phy_power_off(struct phy *phy)
 	struct rockchip_typec_phy *tcphy = phy_get_drvdata(phy);
 
 	mutex_lock(&tcphy->lock);
+	tcphy_cfg_usb3_to_usb2_only(tcphy, false);
 
 	if (tcphy->mode == MODE_DISCONNECT)
 		goto unlock;
-- 
2.15.1

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

* [PATCH v2 5/6] phy: rockchip-typec: support DP phy switch
  2018-02-14 16:54 [PATCH v2 1/6] phy: rockchip-typec: deprecate some DT properties for various register fields Enric Balletbo i Serra
                   ` (2 preceding siblings ...)
  2018-02-14 16:54 ` [PATCH v2 4/6] phy: rockchip-typec: force to USB2 if DP at 4 lanes mode Enric Balletbo i Serra
@ 2018-02-14 16:54 ` Enric Balletbo i Serra
       [not found] ` <20180214165447.12181-1-enric.balletbo-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
  2018-02-15 16:06 ` [PATCH v2 1/6] phy: rockchip-typec: deprecate some DT properties for various register fields Heiko Stuebner
  5 siblings, 0 replies; 8+ messages in thread
From: Enric Balletbo i Serra @ 2018-02-14 16:54 UTC (permalink / raw)
  To: Rob Herring, Kishon Vijay Abraham I, Brian Norris
  Cc: Heiko Stuebner, dianders, Chris Zhong, William wu, hl,
	devicetree, linux-arm-kernel, linux-rockchip, linux-kernel,
	kernel

From: Chris Zhong <zyw@rock-chips.com>

There are 2 Type-c PHYs in RK3399, but only one DP controller. Hence
only one PHY can connect to DP controller at one time, the other should
be disconnected. The GRF_SOC_CON26 register has a switch bit to do it,
set this bit means enable PHY 1, clear this bit means enable PHY 0.

Signed-off-by: Chris Zhong <zyw@rock-chips.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---
Changes since v1:
- This patch is new on these series but as a consequence of the work
  done need to be reworked. The patch was send some time ago [1] but
  got stuck, so it's also and attempt to revive it.

[1] https://lkml.org/lkml/2017/2/10/74 

 drivers/phy/rockchip/phy-rockchip-typec.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-typec.c b/drivers/phy/rockchip/phy-rockchip-typec.c
index 95cd5db5c910..e68bcc93e359 100644
--- a/drivers/phy/rockchip/phy-rockchip-typec.c
+++ b/drivers/phy/rockchip/phy-rockchip-typec.c
@@ -365,6 +365,7 @@ struct rockchip_usb3phy_port_cfg {
 	struct usb3phy_reg pipe_status;
 	struct usb3phy_reg usb3_host_disable;
 	struct usb3phy_reg usb3_host_port;
+	struct usb3phy_reg uphy_dp_sel;
 };
 
 static const struct rockchip_usb3phy_port_cfg tcphy0_port_cfg = {
@@ -374,6 +375,7 @@ static const struct rockchip_usb3phy_port_cfg tcphy0_port_cfg = {
 	.pipe_status	= { 0xe5c0, 0, 0 },
 	.usb3_host_disable = { 0x2434, 0, 16 },
 	.usb3_host_port = { 0x2434, 12, 28 },
+	.uphy_dp_sel	= { 0x6268, 19, 19 },
 };
 
 static const struct rockchip_usb3phy_port_cfg tcphy1_port_cfg = {
@@ -383,6 +385,7 @@ static const struct rockchip_usb3phy_port_cfg tcphy1_port_cfg = {
 	.pipe_status	= { 0xe5c0, 16, 16 },
 	.usb3_host_disable = { 0x2444, 0, 16 },
 	.usb3_host_port = { 0x2444, 12, 28 },
+	.uphy_dp_sel	= { 0x6268, 3, 19 },
 };
 
 struct rockchip_typec_phy {
@@ -844,7 +847,7 @@ static int tcphy_get_mode(struct rockchip_typec_phy *tcphy)
 static int tcphy_cfg_usb3_to_usb2_only(struct rockchip_typec_phy *tcphy,
 				       bool value)
 {
-	struct rockchip_usb3phy_port_cfg *cfg = &tcphy->port_cfgs;
+	const struct rockchip_usb3phy_port_cfg *cfg = tcphy->port_cfgs;
 
 	property_enable(tcphy, &cfg->usb3tousb2_en, value);
 	property_enable(tcphy, &cfg->usb3_host_disable, value);
@@ -935,6 +938,7 @@ static const struct phy_ops rockchip_usb3_phy_ops = {
 static int rockchip_dp_phy_power_on(struct phy *phy)
 {
 	struct rockchip_typec_phy *tcphy = phy_get_drvdata(phy);
+	const struct rockchip_usb3phy_port_cfg *cfg = tcphy->port_cfgs;
 	int new_mode, ret = 0;
 	u32 val;
 
@@ -967,6 +971,8 @@ static int rockchip_dp_phy_power_on(struct phy *phy)
 	if (ret)
 		goto unlock_ret;
 
+	property_enable(tcphy, &cfg->uphy_dp_sel, 1);
+
 	ret = readx_poll_timeout(readl, tcphy->base + DP_MODE_CTL,
 				 val, val & DP_MODE_A2, 1000,
 				 PHY_MODE_SET_TIMEOUT);
-- 
2.15.1

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

* [PATCH v2 6/6] drm/rockchip: cdn-dp: remove the DP phy switch
       [not found] ` <20180214165447.12181-1-enric.balletbo-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
@ 2018-02-14 16:54   ` Enric Balletbo i Serra
  0 siblings, 0 replies; 8+ messages in thread
From: Enric Balletbo i Serra @ 2018-02-14 16:54 UTC (permalink / raw)
  To: Rob Herring, Kishon Vijay Abraham I, Brian Norris
  Cc: Heiko Stuebner, dianders-F7+t8E8rja9g9hUCZPvPmw, Chris Zhong,
	William wu, hl-TNX95d0MmH7DzftRWevZcw,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	kernel-ZGY8ohtN/8qB+jHODAdFcQ

From: Chris Zhong <zyw-TNX95d0MmH7DzftRWevZcw@public.gmane.org>

There are 2 Type-c PHYs in RK3399, but only one DP controller. Hence
only one PHY can connect to DP controller at one time, the other should
be disconnected. The GRF_SOC_CON26 register has a switch bit to do it,
set this bit means enable PHY 1, clear this bit means enable PHY 0.

If the board has 2 Type-C ports, the DP driver get the phy id from
devm_of_phy_get_by_index, and then control this switch according to
this id. But some others board only has one Type-C port, it may be PHY 0
or PHY 1. The dts node id can not tell us the correct PHY id. Hence move
this switch to PHY driver, the PHY driver can distinguish between PHY 0
and PHY 1, and then write the correct register bit.

Signed-off-by: Chris Zhong <zyw-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
---
Changes since v1:
- This patch is new on these series and is related to [5/6] so I
  included to this series. Like [5/6] the patch was send some time ago [1]
  but got stuck, so it's also and attempt to revive it.

[1] https://lkml.org/lkml/2017/2/10/74

 drivers/gpu/drm/rockchip/cdn-dp-core.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/cdn-dp-core.c b/drivers/gpu/drm/rockchip/cdn-dp-core.c
index ec999d9f15f6..c6fbdcd87c16 100644
--- a/drivers/gpu/drm/rockchip/cdn-dp-core.c
+++ b/drivers/gpu/drm/rockchip/cdn-dp-core.c
@@ -43,8 +43,6 @@
 #define GRF_SOC_CON9		0x6224
 #define DP_SEL_VOP_LIT		BIT(12)
 #define GRF_SOC_CON26		0x6268
-#define UPHY_SEL_BIT		3
-#define UPHY_SEL_MASK		BIT(19)
 #define DPTX_HPD_SEL		(3 << 12)
 #define DPTX_HPD_DEL		(2 << 12)
 #define DPTX_HPD_SEL_MASK	(3 << 28)
@@ -394,11 +392,6 @@ static int cdn_dp_enable_phy(struct cdn_dp_device *dp, struct cdn_dp_port *port)
 	union extcon_property_value property;
 	int ret;
 
-	ret = cdn_dp_grf_write(dp, GRF_SOC_CON26,
-			       (port->id << UPHY_SEL_BIT) | UPHY_SEL_MASK);
-	if (ret)
-		return ret;
-
 	if (!port->phy_enabled) {
 		ret = phy_power_on(port->phy);
 		if (ret) {
-- 
2.15.1

--
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] 8+ messages in thread

* Re: [PATCH v2 1/6] phy: rockchip-typec: deprecate some DT properties for various register fields.
  2018-02-14 16:54 [PATCH v2 1/6] phy: rockchip-typec: deprecate some DT properties for various register fields Enric Balletbo i Serra
                   ` (4 preceding siblings ...)
       [not found] ` <20180214165447.12181-1-enric.balletbo-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
@ 2018-02-15 16:06 ` Heiko Stuebner
  5 siblings, 0 replies; 8+ messages in thread
From: Heiko Stuebner @ 2018-02-15 16:06 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Rob Herring, Kishon Vijay Abraham I, Brian Norris, dianders,
	Chris Zhong, William wu, hl, devicetree, linux-arm-kernel,
	linux-rockchip, linux-kernel, kernel

Hi Enric,

Am Mittwoch, 14. Februar 2018, 17:54:42 CET schrieb Enric Balletbo i Serra:
> Adding properties for various register fields in the DT doesn't scale and
> this information should be in the driver instead.
> 
> Before this patch these registers (description below) were specified in
> the DT, every register node contained 3 sections: offset, enable bit,
> write mask bit.
> 
>  - rockchip,typec-conn-dir : the register of type-c connector direction,
>    for type-c phy0, it must be <0xe580 0 16>;
>    for type-c phy1, it must be <0xe58c 0 16>;
>  - rockchip,usb3tousb2-en : the register of type-c force usb3 to usb2 enable
>    control.
>    for type-c phy0, it must be <0xe580 3 19>;
>    for type-c phy1, it must be <0xe58c 3 19>;
>  - rockchip,external-psm : the register of type-c phy external psm clock
>    selection.
>    for type-c phy0, it must be <0xe588 14 30>;
>    for type-c phy1, it must be <0xe594 14 30>;
>  - rockchip,pipe-status : the register of type-c phy pipe status.
>    for type-c phy0, it must be <0xe5c0 0 0>;
>    for type-c phy1, it must be <0xe5c0 16 16>;
> 
> After this patch these register definitions are in the driver. So can be
> removed from the DT. Note that there are 2 type-c phys for RK3399 with
> different offsets, the driver checks the phy base address of the running
> instance and applies the right offsets.
> 
> Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>

Generally I really support moving that stuff back into the driver and
judging by the recent mail conversations with Rob and Brian, this also
seems to be a consensus of sorts.

The one but I see here is, that the newly added things represent
rk3399-specific values and should be prefixed accordingly and also
already be flexible enough for the next soc using it.

Examples below.


> @@ -349,6 +349,9 @@
>  #define MODE_DFP_USB			BIT(1)
>  #define MODE_DFP_DP			BIT(2)
>  
> +#define TYPEC_PHY0_BASE_ADDRESS		0xff7c0000
> +#define TYPEC_PHY1_BASE_ADDRESS		0xff800000

RK3399_TYPEC_PHY0_ADDRESS etc ?

> @@ -362,6 +365,20 @@ struct rockchip_usb3phy_port_cfg {
>  	struct usb3phy_reg pipe_status;
>  };
>  
> +static const struct rockchip_usb3phy_port_cfg tcphy0_port_cfg = {
> +	.typec_conn_dir	= { 0xe580, 0, 16 },
> +	.usb3tousb2_en	= { 0xe580, 3, 19 },
> +	.external_psm	= { 0xe588, 14, 30 },
> +	.pipe_status	= { 0xe5c0, 0, 0 },
> +};
> +
> +static const struct rockchip_usb3phy_port_cfg tcphy1_port_cfg = {
> +	.typec_conn_dir	= { 0xe58c, 0, 16 },
> +	.usb3tousb2_en	= { 0xe58c, 3, 19 },
> +	.external_psm	= { 0xe594, 14, 30 },
> +	.pipe_status	= { 0xe5c0, 16, 16 },
> +};

rk3399_tcphy1_port_cfg. Especially important as these are GRF-registers
(general register files = a dumping ground for random settings bits)
and nothing ever stays the same in the GRF between chips.


> @@ -1103,6 +1078,13 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)
>  	if (IS_ERR(tcphy->base))
>  		return PTR_ERR(tcphy->base);
>  
> +	if (res->start == TYPEC_PHY0_BASE_ADDRESS)
> +		tcphy->port_cfgs = &tcphy0_port_cfg;
> +	else if (res->start == TYPEC_PHY1_BASE_ADDRESS)
> +		tcphy->port_cfgs = &tcphy1_port_cfg;
> +	else
> +		return -EINVAL;

should be selected according to the compatible.
Like just create a struct similar to things like the inno-usb2-phy.
That way you can also just write down the address itself in a reg
property and do not need specific constants like the ones at the top.


Heiko

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

* Re: [PATCH v2 2/6] dt-bindings: phy-rockchip-typec: deprecate some register properties.
       [not found]   ` <20180214165447.12181-2-enric.balletbo-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
@ 2018-02-15 16:10     ` Heiko Stuebner
  0 siblings, 0 replies; 8+ messages in thread
From: Heiko Stuebner @ 2018-02-15 16:10 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Rob Herring, Kishon Vijay Abraham I, Brian Norris,
	dianders-F7+t8E8rja9g9hUCZPvPmw, Chris Zhong, William wu,
	hl-TNX95d0MmH7DzftRWevZcw, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	kernel-ZGY8ohtN/8qB+jHODAdFcQ

Am Mittwoch, 14. Februar 2018, 17:54:43 CET schrieb Enric Balletbo i Serra:
> As now the following register properties are in the driver, document as
> deprecated these properties and recommend to not use them on new bindings.
> 
> The deprecated properties are:
> 
> - rockchip,typec-conn-dir : the register of type-c connector direction
> - rockchip,usb3tousb2-en : the register of type-c force usb3 to usb2
>                            enable control.
> - rockchip,external-psm : the register of type-c phy external psm clock
>                           selection.
> - rockchip,pipe-status : the register of type-c phy pipe status.
> 
> Signed-off-by: Enric Balletbo i Serra <enric.balletbo-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
> ---
> Changes since v1:
> - This patch is new on these series and is just a documentation update
>   due patch [1/6]
> 
>  .../devicetree/bindings/phy/phy-rockchip-typec.txt | 33 +++++-----------------
>  1 file changed, 7 insertions(+), 26 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/phy/phy-rockchip-typec.txt b/Documentation/devicetree/bindings/phy/phy-rockchip-typec.txt
> index 6ea867e3176f..bc44d6abe283 100644
> --- a/Documentation/devicetree/bindings/phy/phy-rockchip-typec.txt
> +++ b/Documentation/devicetree/bindings/phy/phy-rockchip-typec.txt
> @@ -16,24 +16,6 @@ Required properties:
>  		 "uphy", "uphy-pipe", "uphy-tcphy"
>   - extcon : extcon specifier for the Power Delivery
>  
> -Note, there are 2 type-c phys for RK3399, and they are almost identical, except
> -these registers(description below), every register node contains 3 sections:
> -offset, enable bit, write mask bit.
> - - rockchip,typec-conn-dir : the register of type-c connector direction,
> -   for type-c phy0, it must be <0xe580 0 16>;
> -   for type-c phy1, it must be <0xe58c 0 16>;
> - - rockchip,usb3tousb2-en : the register of type-c force usb3 to usb2 enable
> -   control.
> -   for type-c phy0, it must be <0xe580 3 19>;
> -   for type-c phy1, it must be <0xe58c 3 19>;
> - - rockchip,external-psm : the register of type-c phy external psm clock
> -   selection.
> -   for type-c phy0, it must be <0xe588 14 30>;
> -   for type-c phy1, it must be <0xe594 14 30>;
> - - rockchip,pipe-status : the register of type-c phy pipe status.
> -   for type-c phy0, it must be <0xe5c0 0 0>;
> -   for type-c phy1, it must be <0xe5c0 16 16>;
> -
>  Required nodes : a sub-node is required for each port the phy provides.
>  		 The sub-node name is used to identify dp or usb3 port,
>  		 and shall be the following entries:
> @@ -43,6 +25,13 @@ Required nodes : a sub-node is required for each port the phy provides.
>  Required properties (port (child) node):
>  - #phy-cells : must be 0, See ./phy-bindings.txt for details.
>  
> +Deprecated properties, do not use in new device tree sources, these
> +properties are now in the driver:

nit: "[...] these properties are determined by the compatible value" ?

A dt-binding does not care about drivers ;-)


Heiko
--
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] 8+ messages in thread

end of thread, other threads:[~2018-02-15 16:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-14 16:54 [PATCH v2 1/6] phy: rockchip-typec: deprecate some DT properties for various register fields Enric Balletbo i Serra
2018-02-14 16:54 ` [PATCH v2 2/6] dt-bindings: phy-rockchip-typec: deprecate some register properties Enric Balletbo i Serra
     [not found]   ` <20180214165447.12181-2-enric.balletbo-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
2018-02-15 16:10     ` Heiko Stuebner
2018-02-14 16:54 ` [PATCH v2 3/6] phy: rockchip-typec: enable usb3 host during usb3 phy power on Enric Balletbo i Serra
2018-02-14 16:54 ` [PATCH v2 4/6] phy: rockchip-typec: force to USB2 if DP at 4 lanes mode Enric Balletbo i Serra
2018-02-14 16:54 ` [PATCH v2 5/6] phy: rockchip-typec: support DP phy switch Enric Balletbo i Serra
     [not found] ` <20180214165447.12181-1-enric.balletbo-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
2018-02-14 16:54   ` [PATCH v2 6/6] drm/rockchip: cdn-dp: remove the " Enric Balletbo i Serra
2018-02-15 16:06 ` [PATCH v2 1/6] phy: rockchip-typec: deprecate some DT properties for various register fields Heiko Stuebner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).