From patchwork Tue Mar 19 12:14:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 781077 Delivered-To: patch@linaro.org Received: by 2002:a5d:46c1:0:b0:33e:7753:30bd with SMTP id g1csp1892201wrs; Tue, 19 Mar 2024 05:14:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUYL6XhdVby7CznaMwLZpo3HUEVw0QSAHo/K7Oijsp8nBnAGf9LaN/MBcIvi6H32J6Qk206UeXIwQNyCWIcA3FH X-Google-Smtp-Source: AGHT+IE2TLEHNNsnU56valmCGbs4CHc1BNyZsV4DQgf7IW+UY6q00syBLHT6hiweikgkVJgVMhmP X-Received: by 2002:a05:600c:46d0:b0:413:feb4:d76c with SMTP id q16-20020a05600c46d000b00413feb4d76cmr10640104wmo.20.1710850496148; Tue, 19 Mar 2024 05:14:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710850496; cv=none; d=google.com; s=arc-20160816; b=fSTND0BN8HjzWz/OP2cyiiulagL/U3nxp/6HRqqdjIP+1D1z8OJdiQfc2nfk5Ge9HO kMKjIbIYyWxzhSB+ARTw+vJ++Xrem3pZek0DL9CpGU0ucF4B3YCovUsKpiYd8b3VXnMO lt8SJ/xKstYfqpVlhMNRvPRGQWGGS7sVf0qLXmMwM3eJoMnMgYPJdS3NZ9P7FSMtvWb9 MNsW7C4fsihTAmCySOpIs6Y8lKME185ygIXaCC5IlBlZBxG4M9o9yQh7MWBqY+ShblxJ hWvJkRj3Of1tO2TDk3V6fE9mzSu4TELcWpHWAt72HpOCqKsqp+rRCJHCxdvozfKiaGXx 2+yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=IfzPwLOX3gt0THn+CH2zX4p2cqGEx8YFAQy2omwRDQY=; fh=UJLfQHigVNNxRTyupVH3iuVYJLWMjRXGBkTXuIfaL+0=; b=Cq3exuND/IuN8oGKX+8k9UKZvYS3wW9NIkFfIYHaLcWuiuzLrI7g7qI2qrJIHUCRXi yYO0KxxuZVKObnUrAjjMVTXE3DwYJKH+5tArVa5EAnwF5fK3GBXVoi55+2Uka3pthfUe UtNPoBZVBwGT57uogqQ7FPE6okNoO+Z0VdOHVxxhnd/Dkb63z49cWoPJ0AGJotnlTrRo 7mUyADdBRc46Ca77H2qEbfXawij1fP7y/3OvKyqgK6XfzTyw5X8TrKf7pjvFjugEm4ND xls/WtsjaD0Cj1UxDjIG0y1sPuZKyM/xNRu0RxU1AjfxEccic+8hwmNwUdt7rmbApXEg SYtw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TWgpa72j; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 18-20020a05600c22d200b00414092b2172si3644063wmg.118.2024.03.19.05.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 05:14:56 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TWgpa72j; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4361288044; Tue, 19 Mar 2024 13:14:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="TWgpa72j"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0F1E487F88; Tue, 19 Mar 2024 13:14:46 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 25DD187F8C for ; Tue, 19 Mar 2024 13:14:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=caleb.connolly@linaro.org Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-513e25afabaso2875007e87.2 for ; Tue, 19 Mar 2024 05:14:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710850481; x=1711455281; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=IfzPwLOX3gt0THn+CH2zX4p2cqGEx8YFAQy2omwRDQY=; b=TWgpa72jSDN+Yk+JoK40kKIsnEOVAsMIUNC40I2dwdSTo5m3Ngmd+huyvpyaFDwogi Yx5dB3IjQrbDpIZ3aNxjwjEQapakQ2snJcS//Vu1sQsriBgXYEC5Yy+L1L4/igcFasUf UBYL7HuGujwhkGjwL0N5+33zrQF0yfhuug/aVAu/du6dJL3MdkSnHrwTvE4MOpJFEtMh oktMALJOVZPt0aL9eUgtDXiQdL3BtgXjIiUekAEGnoNPWfbjwi+qYBKqMJSHADkzDzrb fwLzo21Nhxsc7INdc8Jr7cAQLPa5T2F7VViUA2/JIBwicDSoCLuiNSeHj65+iu35tbvK WlwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710850481; x=1711455281; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IfzPwLOX3gt0THn+CH2zX4p2cqGEx8YFAQy2omwRDQY=; b=Xsa8osaAnpOa0Oll4Qz1WUQKWsY8q8CdvUiEfeYpyOfb/lUi+pe+bgfhqzGjA9Ufln XLjUDmapEtcJfeIC2yWejgaf/eVOG6kqtYJnFug7++njMr2Or7gz2z5E0cNCI3Xwy9rj nCmFdxb4GmiBckoRoGot1PaIZu6aeNAamMJe1D3Eux/SVPnzN4Wjru7+zUKxttl5a6Cr 4K99bmnNp9kt2nJaWyUM/aQ037zs2KYbUme8JYnztWtfKDU95JopS/OjaFt4QbS3SBd7 rx/Cqi09KmC6pe5H0rFERBKeluLHnWlLmiLmq4867CcSl0LgrbvUxRyLqDtTtsEKBbXE iNMw== X-Gm-Message-State: AOJu0Yx6Fra10Ule7msuNAo0mDe002ORk7esADi/MnydN4ajtDmIBBDp cMjefq9hjAK2lKxU6Wp4Emr7+DsobRmGJlVlzBBlpI8OG3YKnabisLlHugBwoVOOSAgnRyPwUwV e X-Received: by 2002:a2e:3c18:0:b0:2d4:5321:9daf with SMTP id j24-20020a2e3c18000000b002d453219dafmr8692281lja.44.1710850481335; Tue, 19 Mar 2024 05:14:41 -0700 (PDT) Received: from lion.localdomain (host-92-17-96-232.as13285.net. [92.17.96.232]) by smtp.gmail.com with ESMTPSA id u8-20020a5d4688000000b0033e3c4e600asm12345792wrq.7.2024.03.19.05.14.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 05:14:40 -0700 (PDT) From: Caleb Connolly Date: Tue, 19 Mar 2024 12:14:24 +0000 Subject: [PATCH v3 1/5] usb: dwc3-generic: implement Qualcomm wrapper MIME-Version: 1.0 Message-Id: <20240319-b4-qcom-usb-v3-1-09ba1f86d259@linaro.org> References: <20240319-b4-qcom-usb-v3-0-09ba1f86d259@linaro.org> In-Reply-To: <20240319-b4-qcom-usb-v3-0-09ba1f86d259@linaro.org> To: Marek Vasut , Tom Rini , Lukasz Majewski , Mattijs Korpershoek , Caleb Connolly , Neil Armstrong , Sumit Garg Cc: u-boot@lists.denx.de X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4313; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=Zb3uEMmWe4RzGwHrxJVrzpQg4bHURtPcRw4NigykBUc=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhtSfjev+vQ9csMxvVurc2Z9q33+8eTL1wqontTU+f9LZF yz54Mowr6OUhUGQg0FWTJFF/MQyy6a1l+01ti+4ADOHlQlkCAMXpwBMpKma4Z+uvNSuv7yxH5zN klx2+h64yc3PyDZ5muG52VW6P+4prlvPyLDt047as/13hfmjxC9lC5v2XjHcHqnesPXOtNkByff nbFsMAA== X-Developer-Key: i=caleb.connolly@linaro.org; a=openpgp; fpr=83B24DA7FE145076BC38BB250CD904EB673A7C47 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The Qualcomm specific dwc3 wrapper isn't hugely complicated, implemented the missing initialisation for host and gadget mode. Reviewed-by: Mattijs Korpershoek Reviewed-by: Marek Vasut Reviewed-by: Neil Armstrong Signed-off-by: Caleb Connolly --- drivers/usb/dwc3/dwc3-generic.c | 81 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index a379a0002e77..36b6c5306d64 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -424,8 +424,79 @@ enum dwc3_omap_utmi_mode { struct dwc3_glue_ops ti_ops = { .glue_configure = dwc3_ti_glue_configure, }; +/* USB QSCRATCH Hardware registers */ +#define QSCRATCH_GENERAL_CFG 0x08 +#define PIPE_UTMI_CLK_SEL BIT(0) +#define PIPE3_PHYSTATUS_SW BIT(3) +#define PIPE_UTMI_CLK_DIS BIT(8) + +#define QSCRATCH_HS_PHY_CTRL 0x10 +#define UTMI_OTG_VBUS_VALID BIT(20) +#define SW_SESSVLD_SEL BIT(28) + +#define QSCRATCH_SS_PHY_CTRL 0x30 +#define LANE0_PWR_PRESENT BIT(24) + +#define PWR_EVNT_IRQ_STAT_REG 0x58 +#define PWR_EVNT_LPM_IN_L2_MASK BIT(4) +#define PWR_EVNT_LPM_OUT_L2_MASK BIT(5) + +#define SDM845_QSCRATCH_BASE_OFFSET 0xf8800 +#define SDM845_QSCRATCH_SIZE 0x400 +#define SDM845_DWC3_CORE_SIZE 0xcd00 + +static void dwc3_qcom_vbus_override_enable(void __iomem *qscratch_base, bool enable) +{ + if (enable) { + setbits_le32(qscratch_base + QSCRATCH_SS_PHY_CTRL, + LANE0_PWR_PRESENT); + setbits_le32(qscratch_base + QSCRATCH_HS_PHY_CTRL, + UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL); + } else { + clrbits_le32(qscratch_base + QSCRATCH_SS_PHY_CTRL, + LANE0_PWR_PRESENT); + clrbits_le32(qscratch_base + QSCRATCH_HS_PHY_CTRL, + UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL); + } +} + +/* For controllers running without superspeed PHYs */ +static void dwc3_qcom_select_utmi_clk(void __iomem *qscratch_base) +{ + /* Configure dwc3 to use UTMI clock as PIPE clock not present */ + setbits_le32(qscratch_base + QSCRATCH_GENERAL_CFG, + PIPE_UTMI_CLK_DIS); + + setbits_le32(qscratch_base + QSCRATCH_GENERAL_CFG, + PIPE_UTMI_CLK_SEL | PIPE3_PHYSTATUS_SW); + + clrbits_le32(qscratch_base + QSCRATCH_GENERAL_CFG, + PIPE_UTMI_CLK_DIS); +} + +static void dwc3_qcom_glue_configure(struct udevice *dev, int index, + enum usb_dr_mode mode) +{ + struct dwc3_glue_data *glue = dev_get_plat(dev); + void __iomem *qscratch_base = (void __iomem *)glue->regs; + if (IS_ERR_OR_NULL(qscratch_base)) { + log_err("%s: Invalid qscratch base address\n", dev->name); + return; + } + + if (dev_read_bool(dev, "qcom,select-utmi-as-pipe-clk")) + dwc3_qcom_select_utmi_clk(qscratch_base); + + if (mode != USB_DR_MODE_HOST) + dwc3_qcom_vbus_override_enable(qscratch_base, true); +} + +struct dwc3_glue_ops qcom_ops = { + .glue_configure = dwc3_qcom_glue_configure, +}; + static int dwc3_rk_glue_get_ctrl_dev(struct udevice *dev, ofnode *node) { *node = dev_ofnode(dev); if (!ofnode_valid(*node)) @@ -511,8 +582,16 @@ static int dwc3_glue_reset_init(struct udevice *dev, return 0; else if (ret) return ret; + if (device_is_compatible(dev, "qcom,dwc3")) { + reset_assert_bulk(&glue->resets); + /* We should wait at least 6 sleep clock cycles, that's + * (6 / 32764) * 1000000 ~= 200us. But some platforms + * have slower sleep clocks so we'll play it safe. + */ + udelay(500); + } ret = reset_deassert_bulk(&glue->resets); if (ret) { reset_release_bulk(&glue->resets); return ret; @@ -628,9 +707,9 @@ static const struct udevice_id dwc3_glue_ids[] = { { .compatible = "rockchip,rk3328-dwc3", .data = (ulong)&rk_ops }, { .compatible = "rockchip,rk3399-dwc3" }, { .compatible = "rockchip,rk3568-dwc3", .data = (ulong)&rk_ops }, { .compatible = "rockchip,rk3588-dwc3", .data = (ulong)&rk_ops }, - { .compatible = "qcom,dwc3" }, + { .compatible = "qcom,dwc3", .data = (ulong)&qcom_ops }, { .compatible = "fsl,imx8mp-dwc3", .data = (ulong)&imx8mp_ops }, { .compatible = "fsl,imx8mq-dwc3" }, { .compatible = "intel,tangier-dwc3" }, { }