From: Vinod Koul <vkoul@kernel.org>
To: Sebastian Reichel <sebastian.reichel@collabora.com>
Cc: Kishon Vijay Abraham I <kishon@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Heiko Stuebner <heiko@sntech.de>,
linux-phy@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, kernel@collabora.com
Subject: Re: [PATCHv2 5/7] phy: phy-rockchip-inno-usb2: add rk3588 phy tuning support
Date: Wed, 12 Apr 2023 22:14:08 +0530 [thread overview]
Message-ID: <ZDbf2At0EakD09af@matsya> (raw)
In-Reply-To: <20230403202307.120562-6-sebastian.reichel@collabora.com>
On 03-04-23, 22:23, Sebastian Reichel wrote:
> On RK3588 some registers need to be tweaked to support waking up from
> suspend when a USB device is plugged into a port from a suspended PHY.
> Without this change USB devices only work when they are plugged at
> boot time.
>
> Apart from that it optimizes settings to avoid devices toggling
> between fullspeed and highspeed mode.
>
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> ---
> drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 63 +++++++++++++++++++
> 1 file changed, 63 insertions(+)
>
> diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> index 3a78c5bf11d4..9f6d09da7fbd 100644
> --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> @@ -33,6 +33,8 @@
> #define SCHEDULE_DELAY (60 * HZ)
> #define OTG_SCHEDULE_DELAY (2 * HZ)
>
> +struct rockchip_usb2phy;
> +
> enum rockchip_usb2phy_port_id {
> USB2PHY_PORT_OTG,
> USB2PHY_PORT_HOST,
> @@ -163,6 +165,7 @@ struct rockchip_usb2phy_port_cfg {
> * struct rockchip_usb2phy_cfg - usb-phy configuration.
> * @reg: the address offset of grf for usb-phy config.
> * @num_ports: specify how many ports that the phy has.
> + * @phy_tuning: phy default parameters tuning.
> * @clkout_ctl: keep on/turn off output clk of phy.
> * @port_cfgs: usb-phy port configurations.
> * @chg_det: charger detection registers.
> @@ -170,6 +173,7 @@ struct rockchip_usb2phy_port_cfg {
> struct rockchip_usb2phy_cfg {
> unsigned int reg;
> unsigned int num_ports;
> + int (*phy_tuning)(struct rockchip_usb2phy *rphy);
> struct usb2phy_reg clkout_ctl;
> const struct rockchip_usb2phy_port_cfg port_cfgs[USB2PHY_NUM_PORTS];
> const struct rockchip_chg_det_reg chg_det;
> @@ -1400,6 +1404,12 @@ static int rockchip_usb2phy_probe(struct platform_device *pdev)
> goto disable_clks;
> }
>
> + if (rphy->phy_cfg->phy_tuning) {
> + ret = rphy->phy_cfg->phy_tuning(rphy);
> + if (ret)
> + goto disable_clks;
> + }
> +
> index = 0;
> for_each_available_child_of_node(np, child_np) {
> struct rockchip_usb2phy_port *rport = &rphy->ports[index];
> @@ -1468,6 +1478,55 @@ static int rockchip_usb2phy_probe(struct platform_device *pdev)
> return ret;
> }
>
> +static int rk3588_usb2phy_tuning(struct rockchip_usb2phy *rphy)
> +{
> + int ret = 0;
superfluous init
> + bool usb3otg = false;
> + /*
> + * utmi_termselect = 1'b1 (en FS terminations)
> + * utmi_xcvrselect = 2'b01 (FS transceiver)
> + */
> + int suspend_cfg = 0x14;
> +
> + if (rphy->phy_cfg->reg == 0x0000 || rphy->phy_cfg->reg == 0x4000) {
> + /* USB2 config for USB3_0 and USB3_1 */
> + suspend_cfg |= 0x01; /* utmi_opmode = 2'b01 (no-driving) */
> + usb3otg = true;
> + } else if (rphy->phy_cfg->reg == 0x8000 || rphy->phy_cfg->reg == 0xc000) {
> + /* USB2 config for USB2_0 and USB2_1 */
> + suspend_cfg |= 0x00; /* utmi_opmode = 2'b00 (normal) */
> + } else {
> + return -EINVAL;
> + }
> +
> + /* Deassert SIDDQ to power on analog block */
> + ret = regmap_write(rphy->grf, 0x0008, GENMASK(29, 29) | 0x0000);
> + if (ret)
> + return ret;
> +
> + /* Do reset after exit IDDQ mode */
> + ret = rockchip_usb2phy_reset(rphy);
> + if (ret)
> + return ret;
> +
> + /* suspend configuration */
> + ret |= regmap_write(rphy->grf, 0x000c, GENMASK(20, 16) | suspend_cfg);
> +
> + /* HS DC Voltage Level Adjustment 4'b1001 : +5.89% */
> + ret |= regmap_write(rphy->grf, 0x0004, GENMASK(27, 24) | 0x0900);
> +
> + /* HS Transmitter Pre-Emphasis Current Control 2'b10 : 2x */
> + ret |= regmap_write(rphy->grf, 0x0008, GENMASK(20, 19) | 0x0010);
> +
> + if (!usb3otg)
> + return ret;
> +
> + /* Pullup iddig pin for USB3_0 OTG mode */
> + ret |= regmap_write(rphy->grf, 0x0010, GENMASK(17, 16) | 0x0003);
> +
> + return ret;
> +}
> +
> static const struct rockchip_usb2phy_cfg rk3228_phy_cfgs[] = {
> {
> .reg = 0x760,
> @@ -1785,6 +1844,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0x0000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_OTG] = {
> @@ -1821,6 +1881,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0x4000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_OTG] = {
> @@ -1857,6 +1918,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0x8000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_HOST] = {
> @@ -1877,6 +1939,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0xc000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_HOST] = {
> --
> 2.39.2
--
~Vinod
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
WARNING: multiple messages have this Message-ID (diff)
From: Vinod Koul <vkoul@kernel.org>
To: Sebastian Reichel <sebastian.reichel@collabora.com>
Cc: Kishon Vijay Abraham I <kishon@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Heiko Stuebner <heiko@sntech.de>,
linux-phy@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, kernel@collabora.com
Subject: Re: [PATCHv2 5/7] phy: phy-rockchip-inno-usb2: add rk3588 phy tuning support
Date: Wed, 12 Apr 2023 22:14:08 +0530 [thread overview]
Message-ID: <ZDbf2At0EakD09af@matsya> (raw)
In-Reply-To: <20230403202307.120562-6-sebastian.reichel@collabora.com>
On 03-04-23, 22:23, Sebastian Reichel wrote:
> On RK3588 some registers need to be tweaked to support waking up from
> suspend when a USB device is plugged into a port from a suspended PHY.
> Without this change USB devices only work when they are plugged at
> boot time.
>
> Apart from that it optimizes settings to avoid devices toggling
> between fullspeed and highspeed mode.
>
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> ---
> drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 63 +++++++++++++++++++
> 1 file changed, 63 insertions(+)
>
> diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> index 3a78c5bf11d4..9f6d09da7fbd 100644
> --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> @@ -33,6 +33,8 @@
> #define SCHEDULE_DELAY (60 * HZ)
> #define OTG_SCHEDULE_DELAY (2 * HZ)
>
> +struct rockchip_usb2phy;
> +
> enum rockchip_usb2phy_port_id {
> USB2PHY_PORT_OTG,
> USB2PHY_PORT_HOST,
> @@ -163,6 +165,7 @@ struct rockchip_usb2phy_port_cfg {
> * struct rockchip_usb2phy_cfg - usb-phy configuration.
> * @reg: the address offset of grf for usb-phy config.
> * @num_ports: specify how many ports that the phy has.
> + * @phy_tuning: phy default parameters tuning.
> * @clkout_ctl: keep on/turn off output clk of phy.
> * @port_cfgs: usb-phy port configurations.
> * @chg_det: charger detection registers.
> @@ -170,6 +173,7 @@ struct rockchip_usb2phy_port_cfg {
> struct rockchip_usb2phy_cfg {
> unsigned int reg;
> unsigned int num_ports;
> + int (*phy_tuning)(struct rockchip_usb2phy *rphy);
> struct usb2phy_reg clkout_ctl;
> const struct rockchip_usb2phy_port_cfg port_cfgs[USB2PHY_NUM_PORTS];
> const struct rockchip_chg_det_reg chg_det;
> @@ -1400,6 +1404,12 @@ static int rockchip_usb2phy_probe(struct platform_device *pdev)
> goto disable_clks;
> }
>
> + if (rphy->phy_cfg->phy_tuning) {
> + ret = rphy->phy_cfg->phy_tuning(rphy);
> + if (ret)
> + goto disable_clks;
> + }
> +
> index = 0;
> for_each_available_child_of_node(np, child_np) {
> struct rockchip_usb2phy_port *rport = &rphy->ports[index];
> @@ -1468,6 +1478,55 @@ static int rockchip_usb2phy_probe(struct platform_device *pdev)
> return ret;
> }
>
> +static int rk3588_usb2phy_tuning(struct rockchip_usb2phy *rphy)
> +{
> + int ret = 0;
superfluous init
> + bool usb3otg = false;
> + /*
> + * utmi_termselect = 1'b1 (en FS terminations)
> + * utmi_xcvrselect = 2'b01 (FS transceiver)
> + */
> + int suspend_cfg = 0x14;
> +
> + if (rphy->phy_cfg->reg == 0x0000 || rphy->phy_cfg->reg == 0x4000) {
> + /* USB2 config for USB3_0 and USB3_1 */
> + suspend_cfg |= 0x01; /* utmi_opmode = 2'b01 (no-driving) */
> + usb3otg = true;
> + } else if (rphy->phy_cfg->reg == 0x8000 || rphy->phy_cfg->reg == 0xc000) {
> + /* USB2 config for USB2_0 and USB2_1 */
> + suspend_cfg |= 0x00; /* utmi_opmode = 2'b00 (normal) */
> + } else {
> + return -EINVAL;
> + }
> +
> + /* Deassert SIDDQ to power on analog block */
> + ret = regmap_write(rphy->grf, 0x0008, GENMASK(29, 29) | 0x0000);
> + if (ret)
> + return ret;
> +
> + /* Do reset after exit IDDQ mode */
> + ret = rockchip_usb2phy_reset(rphy);
> + if (ret)
> + return ret;
> +
> + /* suspend configuration */
> + ret |= regmap_write(rphy->grf, 0x000c, GENMASK(20, 16) | suspend_cfg);
> +
> + /* HS DC Voltage Level Adjustment 4'b1001 : +5.89% */
> + ret |= regmap_write(rphy->grf, 0x0004, GENMASK(27, 24) | 0x0900);
> +
> + /* HS Transmitter Pre-Emphasis Current Control 2'b10 : 2x */
> + ret |= regmap_write(rphy->grf, 0x0008, GENMASK(20, 19) | 0x0010);
> +
> + if (!usb3otg)
> + return ret;
> +
> + /* Pullup iddig pin for USB3_0 OTG mode */
> + ret |= regmap_write(rphy->grf, 0x0010, GENMASK(17, 16) | 0x0003);
> +
> + return ret;
> +}
> +
> static const struct rockchip_usb2phy_cfg rk3228_phy_cfgs[] = {
> {
> .reg = 0x760,
> @@ -1785,6 +1844,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0x0000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_OTG] = {
> @@ -1821,6 +1881,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0x4000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_OTG] = {
> @@ -1857,6 +1918,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0x8000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_HOST] = {
> @@ -1877,6 +1939,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0xc000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_HOST] = {
> --
> 2.39.2
--
~Vinod
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
WARNING: multiple messages have this Message-ID (diff)
From: Vinod Koul <vkoul@kernel.org>
To: Sebastian Reichel <sebastian.reichel@collabora.com>
Cc: Kishon Vijay Abraham I <kishon@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Heiko Stuebner <heiko@sntech.de>,
linux-phy@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, kernel@collabora.com
Subject: Re: [PATCHv2 5/7] phy: phy-rockchip-inno-usb2: add rk3588 phy tuning support
Date: Wed, 12 Apr 2023 22:14:08 +0530 [thread overview]
Message-ID: <ZDbf2At0EakD09af@matsya> (raw)
In-Reply-To: <20230403202307.120562-6-sebastian.reichel@collabora.com>
On 03-04-23, 22:23, Sebastian Reichel wrote:
> On RK3588 some registers need to be tweaked to support waking up from
> suspend when a USB device is plugged into a port from a suspended PHY.
> Without this change USB devices only work when they are plugged at
> boot time.
>
> Apart from that it optimizes settings to avoid devices toggling
> between fullspeed and highspeed mode.
>
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> ---
> drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 63 +++++++++++++++++++
> 1 file changed, 63 insertions(+)
>
> diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> index 3a78c5bf11d4..9f6d09da7fbd 100644
> --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> @@ -33,6 +33,8 @@
> #define SCHEDULE_DELAY (60 * HZ)
> #define OTG_SCHEDULE_DELAY (2 * HZ)
>
> +struct rockchip_usb2phy;
> +
> enum rockchip_usb2phy_port_id {
> USB2PHY_PORT_OTG,
> USB2PHY_PORT_HOST,
> @@ -163,6 +165,7 @@ struct rockchip_usb2phy_port_cfg {
> * struct rockchip_usb2phy_cfg - usb-phy configuration.
> * @reg: the address offset of grf for usb-phy config.
> * @num_ports: specify how many ports that the phy has.
> + * @phy_tuning: phy default parameters tuning.
> * @clkout_ctl: keep on/turn off output clk of phy.
> * @port_cfgs: usb-phy port configurations.
> * @chg_det: charger detection registers.
> @@ -170,6 +173,7 @@ struct rockchip_usb2phy_port_cfg {
> struct rockchip_usb2phy_cfg {
> unsigned int reg;
> unsigned int num_ports;
> + int (*phy_tuning)(struct rockchip_usb2phy *rphy);
> struct usb2phy_reg clkout_ctl;
> const struct rockchip_usb2phy_port_cfg port_cfgs[USB2PHY_NUM_PORTS];
> const struct rockchip_chg_det_reg chg_det;
> @@ -1400,6 +1404,12 @@ static int rockchip_usb2phy_probe(struct platform_device *pdev)
> goto disable_clks;
> }
>
> + if (rphy->phy_cfg->phy_tuning) {
> + ret = rphy->phy_cfg->phy_tuning(rphy);
> + if (ret)
> + goto disable_clks;
> + }
> +
> index = 0;
> for_each_available_child_of_node(np, child_np) {
> struct rockchip_usb2phy_port *rport = &rphy->ports[index];
> @@ -1468,6 +1478,55 @@ static int rockchip_usb2phy_probe(struct platform_device *pdev)
> return ret;
> }
>
> +static int rk3588_usb2phy_tuning(struct rockchip_usb2phy *rphy)
> +{
> + int ret = 0;
superfluous init
> + bool usb3otg = false;
> + /*
> + * utmi_termselect = 1'b1 (en FS terminations)
> + * utmi_xcvrselect = 2'b01 (FS transceiver)
> + */
> + int suspend_cfg = 0x14;
> +
> + if (rphy->phy_cfg->reg == 0x0000 || rphy->phy_cfg->reg == 0x4000) {
> + /* USB2 config for USB3_0 and USB3_1 */
> + suspend_cfg |= 0x01; /* utmi_opmode = 2'b01 (no-driving) */
> + usb3otg = true;
> + } else if (rphy->phy_cfg->reg == 0x8000 || rphy->phy_cfg->reg == 0xc000) {
> + /* USB2 config for USB2_0 and USB2_1 */
> + suspend_cfg |= 0x00; /* utmi_opmode = 2'b00 (normal) */
> + } else {
> + return -EINVAL;
> + }
> +
> + /* Deassert SIDDQ to power on analog block */
> + ret = regmap_write(rphy->grf, 0x0008, GENMASK(29, 29) | 0x0000);
> + if (ret)
> + return ret;
> +
> + /* Do reset after exit IDDQ mode */
> + ret = rockchip_usb2phy_reset(rphy);
> + if (ret)
> + return ret;
> +
> + /* suspend configuration */
> + ret |= regmap_write(rphy->grf, 0x000c, GENMASK(20, 16) | suspend_cfg);
> +
> + /* HS DC Voltage Level Adjustment 4'b1001 : +5.89% */
> + ret |= regmap_write(rphy->grf, 0x0004, GENMASK(27, 24) | 0x0900);
> +
> + /* HS Transmitter Pre-Emphasis Current Control 2'b10 : 2x */
> + ret |= regmap_write(rphy->grf, 0x0008, GENMASK(20, 19) | 0x0010);
> +
> + if (!usb3otg)
> + return ret;
> +
> + /* Pullup iddig pin for USB3_0 OTG mode */
> + ret |= regmap_write(rphy->grf, 0x0010, GENMASK(17, 16) | 0x0003);
> +
> + return ret;
> +}
> +
> static const struct rockchip_usb2phy_cfg rk3228_phy_cfgs[] = {
> {
> .reg = 0x760,
> @@ -1785,6 +1844,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0x0000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_OTG] = {
> @@ -1821,6 +1881,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0x4000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_OTG] = {
> @@ -1857,6 +1918,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0x8000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_HOST] = {
> @@ -1877,6 +1939,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0xc000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_HOST] = {
> --
> 2.39.2
--
~Vinod
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
WARNING: multiple messages have this Message-ID (diff)
From: Vinod Koul <vkoul@kernel.org>
To: Sebastian Reichel <sebastian.reichel@collabora.com>
Cc: Kishon Vijay Abraham I <kishon@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Heiko Stuebner <heiko@sntech.de>,
linux-phy@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, kernel@collabora.com
Subject: Re: [PATCHv2 5/7] phy: phy-rockchip-inno-usb2: add rk3588 phy tuning support
Date: Wed, 12 Apr 2023 22:14:08 +0530 [thread overview]
Message-ID: <ZDbf2At0EakD09af@matsya> (raw)
In-Reply-To: <20230403202307.120562-6-sebastian.reichel@collabora.com>
On 03-04-23, 22:23, Sebastian Reichel wrote:
> On RK3588 some registers need to be tweaked to support waking up from
> suspend when a USB device is plugged into a port from a suspended PHY.
> Without this change USB devices only work when they are plugged at
> boot time.
>
> Apart from that it optimizes settings to avoid devices toggling
> between fullspeed and highspeed mode.
>
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> ---
> drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 63 +++++++++++++++++++
> 1 file changed, 63 insertions(+)
>
> diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> index 3a78c5bf11d4..9f6d09da7fbd 100644
> --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
> @@ -33,6 +33,8 @@
> #define SCHEDULE_DELAY (60 * HZ)
> #define OTG_SCHEDULE_DELAY (2 * HZ)
>
> +struct rockchip_usb2phy;
> +
> enum rockchip_usb2phy_port_id {
> USB2PHY_PORT_OTG,
> USB2PHY_PORT_HOST,
> @@ -163,6 +165,7 @@ struct rockchip_usb2phy_port_cfg {
> * struct rockchip_usb2phy_cfg - usb-phy configuration.
> * @reg: the address offset of grf for usb-phy config.
> * @num_ports: specify how many ports that the phy has.
> + * @phy_tuning: phy default parameters tuning.
> * @clkout_ctl: keep on/turn off output clk of phy.
> * @port_cfgs: usb-phy port configurations.
> * @chg_det: charger detection registers.
> @@ -170,6 +173,7 @@ struct rockchip_usb2phy_port_cfg {
> struct rockchip_usb2phy_cfg {
> unsigned int reg;
> unsigned int num_ports;
> + int (*phy_tuning)(struct rockchip_usb2phy *rphy);
> struct usb2phy_reg clkout_ctl;
> const struct rockchip_usb2phy_port_cfg port_cfgs[USB2PHY_NUM_PORTS];
> const struct rockchip_chg_det_reg chg_det;
> @@ -1400,6 +1404,12 @@ static int rockchip_usb2phy_probe(struct platform_device *pdev)
> goto disable_clks;
> }
>
> + if (rphy->phy_cfg->phy_tuning) {
> + ret = rphy->phy_cfg->phy_tuning(rphy);
> + if (ret)
> + goto disable_clks;
> + }
> +
> index = 0;
> for_each_available_child_of_node(np, child_np) {
> struct rockchip_usb2phy_port *rport = &rphy->ports[index];
> @@ -1468,6 +1478,55 @@ static int rockchip_usb2phy_probe(struct platform_device *pdev)
> return ret;
> }
>
> +static int rk3588_usb2phy_tuning(struct rockchip_usb2phy *rphy)
> +{
> + int ret = 0;
superfluous init
> + bool usb3otg = false;
> + /*
> + * utmi_termselect = 1'b1 (en FS terminations)
> + * utmi_xcvrselect = 2'b01 (FS transceiver)
> + */
> + int suspend_cfg = 0x14;
> +
> + if (rphy->phy_cfg->reg == 0x0000 || rphy->phy_cfg->reg == 0x4000) {
> + /* USB2 config for USB3_0 and USB3_1 */
> + suspend_cfg |= 0x01; /* utmi_opmode = 2'b01 (no-driving) */
> + usb3otg = true;
> + } else if (rphy->phy_cfg->reg == 0x8000 || rphy->phy_cfg->reg == 0xc000) {
> + /* USB2 config for USB2_0 and USB2_1 */
> + suspend_cfg |= 0x00; /* utmi_opmode = 2'b00 (normal) */
> + } else {
> + return -EINVAL;
> + }
> +
> + /* Deassert SIDDQ to power on analog block */
> + ret = regmap_write(rphy->grf, 0x0008, GENMASK(29, 29) | 0x0000);
> + if (ret)
> + return ret;
> +
> + /* Do reset after exit IDDQ mode */
> + ret = rockchip_usb2phy_reset(rphy);
> + if (ret)
> + return ret;
> +
> + /* suspend configuration */
> + ret |= regmap_write(rphy->grf, 0x000c, GENMASK(20, 16) | suspend_cfg);
> +
> + /* HS DC Voltage Level Adjustment 4'b1001 : +5.89% */
> + ret |= regmap_write(rphy->grf, 0x0004, GENMASK(27, 24) | 0x0900);
> +
> + /* HS Transmitter Pre-Emphasis Current Control 2'b10 : 2x */
> + ret |= regmap_write(rphy->grf, 0x0008, GENMASK(20, 19) | 0x0010);
> +
> + if (!usb3otg)
> + return ret;
> +
> + /* Pullup iddig pin for USB3_0 OTG mode */
> + ret |= regmap_write(rphy->grf, 0x0010, GENMASK(17, 16) | 0x0003);
> +
> + return ret;
> +}
> +
> static const struct rockchip_usb2phy_cfg rk3228_phy_cfgs[] = {
> {
> .reg = 0x760,
> @@ -1785,6 +1844,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0x0000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_OTG] = {
> @@ -1821,6 +1881,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0x4000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_OTG] = {
> @@ -1857,6 +1918,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0x8000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_HOST] = {
> @@ -1877,6 +1939,7 @@ static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = {
> {
> .reg = 0xc000,
> .num_ports = 1,
> + .phy_tuning = rk3588_usb2phy_tuning,
> .clkout_ctl = { 0x0000, 0, 0, 1, 0 },
> .port_cfgs = {
> [USB2PHY_PORT_HOST] = {
> --
> 2.39.2
--
~Vinod
next prev parent reply other threads:[~2023-04-12 16:44 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-03 20:23 [PATCHv2 0/7] phy-rockchip-inno-usb2: add RK3588 support Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` [PATCHv2 1/7] dt-bindings: soc: rockchip: add rk3588 usb2phy syscon Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-04 14:26 ` Rob Herring
2023-04-04 14:26 ` Rob Herring
2023-04-04 14:26 ` Rob Herring
2023-04-04 14:26 ` Rob Herring
2023-04-03 20:23 ` [PATCHv2 2/7] dt-bindings: phy: rockchip,inno-usb2phy: add rk3588 Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-04 14:27 ` Rob Herring
2023-04-04 14:27 ` Rob Herring
2023-04-04 14:27 ` Rob Herring
2023-04-04 14:27 ` Rob Herring
2023-04-03 20:23 ` [PATCHv2 3/7] phy: phy-rockchip-inno-usb2: add rk3588 support Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` [PATCHv2 4/7] phy: phy-rockchip-inno-usb2: add reset support Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` [PATCHv2 5/7] phy: phy-rockchip-inno-usb2: add rk3588 phy tuning support Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-12 16:44 ` Vinod Koul [this message]
2023-04-12 16:44 ` Vinod Koul
2023-04-12 16:44 ` Vinod Koul
2023-04-12 16:44 ` Vinod Koul
2023-04-03 20:23 ` [PATCHv2 6/7] phy: phy-rockchip-inno-usb2: simplify phy clock handling Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` [PATCHv2 7/7] phy: phy-rockchip-inno-usb2: simplify getting match data Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-04-03 20:23 ` Sebastian Reichel
2023-05-02 9:37 ` (subset) [PATCHv2 0/7] phy-rockchip-inno-usb2: add RK3588 support Heiko Stuebner
2023-05-02 9:37 ` Heiko Stuebner
2023-05-02 9:37 ` Heiko Stuebner
2023-05-02 9:37 ` 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=ZDbf2At0EakD09af@matsya \
--to=vkoul@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=heiko@sntech.de \
--cc=kernel@collabora.com \
--cc=kishon@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-kernel@lists.infradead.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 \
/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 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.