Linux-PHY Archive mirror
 help / color / mirror / Atom feed
From: Vinod Koul <vkoul@kernel.org>
To: Sebastian Reichel <sebastian.reichel@collabora.com>
Cc: Heiko Stuebner <heiko@sntech.de>,
	Kishon Vijay Abraham I <kishon@kernel.org>,
	linux-rockchip@lists.infradead.org,
	linux-phy@lists.infradead.org, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Frank Wang <frank.wang@rock-chips.com>,
	Kever Yang <kever.yang@rock-chips.com>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel@collabora.com, Zhang Yubing <yubing.zhang@rock-chips.com>
Subject: Re: [PATCH v2 04/12] phy: rockchip: add usbdp combo phy driver
Date: Fri, 16 Feb 2024 12:17:32 +0530	[thread overview]
Message-ID: <Zc8FBJbMeLng9DjS@matsya> (raw)
In-Reply-To: <20240213163609.44930-5-sebastian.reichel@collabora.com>

On 13-02-24, 17:32, Sebastian Reichel wrote:
> This adds a new USBDP combo PHY with Samsung IP block driver.
> 
> The driver get lane mux and mapping info in 2 ways, supporting
> DisplayPort alternate mode or parsing from DT. When parsing from DT,
> the property "rockchip,dp-lane-mux" provide the DP mux and mapping
> info. This is needed when the PHY is not used with TypeC Alt-Mode.
> For example if the USB3 interface of the PHY is connected to a USB
> Type A connector and the DP interface is connected to a DisplayPort
> connector.
> 
> When do DP link training, need to set lane number, link rate, swing,
> and pre-emphasis via PHY configure interface.
> 
> Co-developed-by: Heiko Stuebner <heiko@sntech.de>
> Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> Co-developed-by: Zhang Yubing <yubing.zhang@rock-chips.com>
> Signed-off-by: Zhang Yubing <yubing.zhang@rock-chips.com>
> Co-developed-by: Frank Wang <frank.wang@rock-chips.com>
> Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> ---
>  drivers/phy/rockchip/Kconfig              |   12 +
>  drivers/phy/rockchip/Makefile             |    1 +
>  drivers/phy/rockchip/phy-rockchip-usbdp.c | 1639 +++++++++++++++++++++
>  3 files changed, 1652 insertions(+)
>  create mode 100644 drivers/phy/rockchip/phy-rockchip-usbdp.c
> 
> diff --git a/drivers/phy/rockchip/Kconfig b/drivers/phy/rockchip/Kconfig
> index 94360fc96a6f..d21b458c1d18 100644
> --- a/drivers/phy/rockchip/Kconfig
> +++ b/drivers/phy/rockchip/Kconfig
> @@ -107,3 +107,15 @@ config PHY_ROCKCHIP_USB
>  	select GENERIC_PHY
>  	help
>  	  Enable this to support the Rockchip USB 2.0 PHY.
> +
> +config PHY_ROCKCHIP_USBDP
> +	tristate "Rockchip USBDP COMBO PHY Driver"
> +	depends on ARCH_ROCKCHIP && OF
> +	select GENERIC_PHY
> +	select TYPEC
> +	help
> +	  Enable this to support the Rockchip USB3.0/DP combo PHY with
> +	  Samsung IP block. This is required for USB3 support on RK3588.
> +
> +	  To compile this driver as a module, choose M here: the module
> +	  will be called phy-rockchip-usbdp
> diff --git a/drivers/phy/rockchip/Makefile b/drivers/phy/rockchip/Makefile
> index 7eab129230d1..25d2e1355db7 100644
> --- a/drivers/phy/rockchip/Makefile
> +++ b/drivers/phy/rockchip/Makefile
> @@ -11,3 +11,4 @@ obj-$(CONFIG_PHY_ROCKCHIP_PCIE)		+= phy-rockchip-pcie.o
>  obj-$(CONFIG_PHY_ROCKCHIP_SNPS_PCIE3)	+= phy-rockchip-snps-pcie3.o
>  obj-$(CONFIG_PHY_ROCKCHIP_TYPEC)	+= phy-rockchip-typec.o
>  obj-$(CONFIG_PHY_ROCKCHIP_USB)		+= phy-rockchip-usb.o
> +obj-$(CONFIG_PHY_ROCKCHIP_USBDP)	+= phy-rockchip-usbdp.o
> diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
> new file mode 100644
> index 000000000000..8b1ace2aaa98
> --- /dev/null
> +++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c
> @@ -0,0 +1,1639 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Rockchip USBDP Combo PHY with Samsung IP block driver
> + *
> + * Copyright (C) 2021 Rockchip Electronics Co., Ltd
> + */
> +
> +#include <linux/bitfield.h>
> +#include <linux/bits.h>
> +#include <linux/clk.h>
> +#include <linux/clk-provider.h>
> +#include <linux/delay.h>
> +#include <linux/gpio.h>
> +#include <linux/io.h>
> +#include <linux/iopoll.h>
> +#include <linux/kernel.h>
> +#include <linux/mfd/syscon.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/of.h>
> +#include <linux/phy/phy.h>
> +#include <linux/platform_device.h>
> +#include <linux/property.h>
> +#include <linux/regmap.h>
> +#include <linux/reset.h>
> +#include <linux/usb/ch9.h>
> +#include <linux/usb/typec_dp.h>
> +#include <linux/usb/typec_mux.h>

Thats a lot of headers, do you need all?

> +static inline int rk_udphy_grfreg_write(struct regmap *base,
> +					const struct rk_udphy_grf_reg *reg, bool en)
> +{
> +	u32 val, mask, tmp;
> +
> +	tmp = en ? reg->enable : reg->disable;
> +	mask = GENMASK(reg->bitend, reg->bitstart);
> +	val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT);

Perhaps FIELD_PREP|GET for these?

> +static int rk_udphy_dplane_get(struct rk_udphy *udphy)
> +{
> +	int dp_lanes;
> +
> +	switch (udphy->mode) {
> +	case UDPHY_MODE_DP:
> +		dp_lanes = 4;
> +		break;

empty line after break makes it more readable

> +	case UDPHY_MODE_DP_USB:
> +		dp_lanes = 2;
> +		break;
> +	case UDPHY_MODE_USB:
> +		fallthrough;
> +	default:
> +		dp_lanes = 0;
> +		break;
> +	}
> +
> +	return dp_lanes;
> +}
> +
> +static int rk_udphy_dplane_enable(struct rk_udphy *udphy, int dp_lanes)
> +{
> +	u32 val = 0;
> +	int i;
> +
> +	for (i = 0; i < dp_lanes; i++)
> +		val |= BIT(udphy->dp_lane_sel[i]);
> +
> +	regmap_update_bits(udphy->pma_regmap, CMN_LANE_MUX_AND_EN_OFFSET, CMN_DP_LANE_EN_ALL,
> +			   FIELD_PREP(CMN_DP_LANE_EN_ALL, val));
> +
> +	if (!dp_lanes)
> +		regmap_update_bits(udphy->pma_regmap, CMN_DP_RSTN_OFFSET,
> +				   CMN_DP_CMN_RSTN, FIELD_PREP(CMN_DP_CMN_RSTN, 0x0));
> +
> +	return 0;

there is no error generation in the fn, these kind of fn should really
be not returning anything

> +static int rk_udphy_usb3_phy_init(struct phy *phy)
> +{
> +	struct rk_udphy *udphy = phy_get_drvdata(phy);
> +	int ret = 0;
> +
> +	mutex_lock(&udphy->mutex);
> +	/* DP only or high-speed, disable U3 port */
> +	if (!(udphy->mode & UDPHY_MODE_USB) || udphy->hs) {
> +		rk_udphy_u3_port_disable(udphy, true);
> +		goto unlock;

no power up in that case?

> +	}
> +
> +	ret = rk_udphy_power_on(udphy, UDPHY_MODE_USB);
> +
> +unlock:
> +	mutex_unlock(&udphy->mutex);
> +	return ret;
> +}
-- 
~Vinod

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

  reply	other threads:[~2024-02-16  6:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-13 16:32 [PATCH v2 00/12] RK3588 USBDP support Sebastian Reichel
2024-02-13 16:32 ` [PATCH v2 01/12] dt-bindings: soc: rockchip: add clock to RK3588 VO grf Sebastian Reichel
2024-02-13 16:32 ` [PATCH v2 02/12] dt-bindings: soc: rockchip: add rk3588 USB3 syscon Sebastian Reichel
2024-02-13 16:32 ` [PATCH v2 03/12] dt-bindings: phy: add rockchip usbdp combo phy document Sebastian Reichel
2024-02-14 18:25   ` Conor Dooley
2024-02-15 12:31   ` Rob Herring
2024-02-13 16:32 ` [PATCH v2 04/12] phy: rockchip: add usbdp combo phy driver Sebastian Reichel
2024-02-16  6:47   ` Vinod Koul [this message]
2024-02-13 16:32 ` [PATCH v2 05/12] arm64: defconfig: enable Rockchip Samsung USBDP PHY Sebastian Reichel
2024-02-13 16:32 ` [PATCH v2 06/12] arm64: dts: rockchip: Fix usb2phy nodename for rk3588 Sebastian Reichel
2024-02-13 16:32 ` [PATCH v2 07/12] arm64: dts: rockchip: reorder usb2phy properties " Sebastian Reichel
2024-02-13 16:32 ` [PATCH v2 08/12] arm64: dts: rockchip: add USBDP phys on rk3588 Sebastian Reichel
2024-02-13 16:32 ` [PATCH v2 09/12] arm64: dts: rockchip: add USB3 DRD controllers " Sebastian Reichel
2024-02-13 16:32 ` [PATCH v2 10/12] arm64: dts: rockchip: add USB3 to rk3588-evb1 Sebastian Reichel
2024-02-13 16:32 ` [PATCH v2 11/12] arm64: dts: rockchip: add upper USB3 port to rock-5a Sebastian Reichel
2024-02-13 16:32 ` [PATCH v2 12/12] arm64: dts: rockchip: add lower USB3 port to rock-5b Sebastian Reichel
2024-02-13 19:16 ` (subset) [PATCH v2 00/12] RK3588 USBDP support Heiko Stuebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zc8FBJbMeLng9DjS@matsya \
    --to=vkoul@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=frank.wang@rock-chips.com \
    --cc=heiko@sntech.de \
    --cc=kernel@collabora.com \
    --cc=kever.yang@rock-chips.com \
    --cc=kishon@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=robh+dt@kernel.org \
    --cc=sebastian.reichel@collabora.com \
    --cc=yubing.zhang@rock-chips.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).