From patchwork Thu Nov 25 10:41:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Stein X-Patchwork-Id: 12693626 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 33A8BC433F5 for ; Thu, 25 Nov 2021 10:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=soXNZACt0dCDcTx4haGAvghzbaEQmOFPGeVOJLI3rlI=; b=drk7uTQBNDNZAy pDcSxQ9yLECDUGKhtTp6kaeoUzkEYRMduWPoOSyLMPqgGoxKJz28LNGL6M7WBu7A9rZrIJtMghMTr XnhPw+lldbowrrJZZBRw9wXQ/hksy7TpwuMFiRBKi6YpJGcf40BP/7sALerjswCJh4NrZHclGUKs9 1tw1TcwdUdoc2JhyjfX1O+xqz3vo8exqTHgtFJqFWcJ67XZh9o1QpyEIyT5aSfV+bI8GIiCNXUm1l 9Db4t4gywkvJU4qO25O8A72IcnMruCCiDEiZ57iVm8oYTp55ehm3cUxBMgZMLJ1AExddzH+LOMPkW CEOXhqGyfqpvJwfO9YsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqCCD-0076Ne-Sl; Thu, 25 Nov 2021 10:41:42 +0000 Received: from mx1.tq-group.com ([93.104.207.81]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqCC1-0076Lc-Mt for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 10:41:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1637836889; x=1669372889; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L0nqttDteHJvl4andTbKyX8dJHJhMtjIdjqk4reSbmk=; b=Ro+/jrdvLdtjcSKh4IX1GCkB07fWiEQimIFJa4Ael5AnmSkYVc0YWN0e tcrV39q2NRrgx4jTxiQuHRp3odWPaniMVqkQI0eGZwUopKr378ZtA5kl1 gDjngPJQtRIEdgQqBhoBRCI30/sWoEpB26Y6dmZxYJmqqLZhSwGTSwVt1 UixjNtsHE7P9wLujw4KQOZyeCGZy1e4MZDJjwtEqh5MzOdpI/uI9Y4XSN HRceWDfg5j8+1tYiubHSb+0gR30s0A53cEDgpk9udXMkDPFA0LFeMzjRP 62swn8smHTefcbGnwU+a+d71jwrhecBgJExeKJ9JfYB8/57IQqRas7jjh Q==; X-IronPort-AV: E=Sophos;i="5.87,263,1631570400"; d="scan'208";a="20673122" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 25 Nov 2021 11:41:14 +0100 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Thu, 25 Nov 2021 11:41:14 +0100 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Thu, 25 Nov 2021 11:41:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1637836874; x=1669372874; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L0nqttDteHJvl4andTbKyX8dJHJhMtjIdjqk4reSbmk=; b=KFisRx1FJTpvEqxdca9z/2mGYGZF6bLUv14sz3bMqgStc+gJfASwTgpG tshhm72bZ6WvF5vnZYmwXZ9mMOb/Zym+Y2CH9w+aQ3Eidl9mDIOsZqlh4 6h4H+jN5WXKgjg3pTrrZfCRzbjrlLlX6sroPxvgBv4ENlG1qVt6sXIe3F pxGpjgltj1OIcW8R6xc2gWdetCA17zI0vhFjyq7L0d9MeqTqR2BkAJuVP I1U+aRSma3FG3TyqYYGeuFivCuXFwFEWVgseln5heUqjO1sBWQ7Dn5/Jy vKWJxVPyMSjmaJVq3PE6RWcZCXNFy6eLrHx4EkGwrG5jd86JfYv6JX0+b A==; X-IronPort-AV: E=Sophos;i="5.87,263,1631570400"; d="scan'208";a="20673121" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 25 Nov 2021 11:41:13 +0100 Received: from steina-w.tq-net.de (unknown [10.123.49.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by vtuxmail01.tq-net.de (Postfix) with ESMTPSA id D4854280075; Thu, 25 Nov 2021 11:41:13 +0100 (CET) From: Alexander Stein To: Shawn Guo , Sascha Hauer Cc: Alexander Stein , linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Subject: [RFC PATCH 1/2] phy: fsl-imx8mq-usb: Add support for setting fsl specific flags Date: Thu, 25 Nov 2021 11:41:03 +0100 Message-Id: <20211125104104.1416523-2-alexander.stein@ew.tq-group.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211125104104.1416523-1-alexander.stein@ew.tq-group.com> References: <20211125104104.1416523-1-alexander.stein@ew.tq-group.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_024130_258236_666670D0 X-CRM114-Status: GOOD ( 19.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The i.MX8MP glue layer has support for the following flags: * over-current polarity * PWR pad polarity * controlling PPC flag in HCCPARAMS register * parmanent port attach for usb2 & usb3 port Allow setting these flags by supporting specific flags in the glue node. In order to get this to work an additional IORESOURCE_MEM is necessary actually pointing to the glue layer. For backward compatibility this is purely optional. Signed-off-by: Alexander Stein --- drivers/phy/freescale/phy-fsl-imx8mq-usb.c | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/drivers/phy/freescale/phy-fsl-imx8mq-usb.c b/drivers/phy/freescale/phy-fsl-imx8mq-usb.c index a29b4a6f7c24..2e9297951132 100644 --- a/drivers/phy/freescale/phy-fsl-imx8mq-usb.c +++ b/drivers/phy/freescale/phy-fsl-imx8mq-usb.c @@ -11,6 +11,18 @@ #include #include +/* USB glue registers */ +#define USB_CTRL0 0x00 +#define USB_CTRL1 0x04 + +#define USB_CTRL0_PORTPWR_EN BIT(12) /* 1 - PPC enabled (default) */ +#define USB_CTRL0_USB3_FIXED BIT(22) /* 1 - USB3 permanent attached */ +#define USB_CTRL0_USB2_FIXED BIT(23) /* 1 - USB2 permanent attached */ + +#define USB_CTRL1_OC_POLARITY BIT(16) /* 0 - HIGH / 1 - LOW */ +#define USB_CTRL1_PWR_POLARITY BIT(17) /* 0 - HIGH / 1 - LOW */ + +/* USB phy registers */ #define PHY_CTRL0 0x0 #define PHY_CTRL0_REF_SSP_EN BIT(2) #define PHY_CTRL0_FSEL_MASK GENMASK(10, 5) @@ -35,9 +47,46 @@ struct imx8mq_usb_phy { struct phy *phy; struct clk *clk; void __iomem *base; + void __iomem *glue_base; struct regulator *vbus; }; +static void imx8mp_configure_glue(struct imx8mq_usb_phy *dwc3_imx) +{ + struct device *dev = &dwc3_imx->phy->dev; + u32 value; + + if (!dwc3_imx->glue_base) + return; + + value = readl(dwc3_imx->glue_base + USB_CTRL0); + + if (device_property_read_bool(dev, "fsl,permanent_attached")) + value |= (USB_CTRL0_USB2_FIXED | USB_CTRL0_USB3_FIXED); + else + value &= ~(USB_CTRL0_USB2_FIXED | USB_CTRL0_USB3_FIXED); + + if (device_property_read_bool(dev, "fsl,disable-ppc")) + value &= ~(USB_CTRL0_PORTPWR_EN); + else + value |= USB_CTRL0_PORTPWR_EN; + + writel(value, dwc3_imx->glue_base + USB_CTRL0); + + value = readl(dwc3_imx->glue_base + USB_CTRL1); + if (device_property_read_bool(dev, "fsl,oc_low_active")) + value |= USB_CTRL1_OC_POLARITY; + else + value &= ~USB_CTRL1_OC_POLARITY; + + if (device_property_read_bool(dev, "fsl,pwr_low_active")) + value |= USB_CTRL1_PWR_POLARITY; + else + value &= ~USB_CTRL1_PWR_POLARITY; + + writel(value, dwc3_imx->glue_base + USB_CTRL1); +} + static int imx8mq_usb_phy_init(struct phy *phy) { struct imx8mq_usb_phy *imx_phy = phy_get_drvdata(phy); @@ -69,6 +118,8 @@ static int imx8mp_usb_phy_init(struct phy *phy) struct imx8mq_usb_phy *imx_phy = phy_get_drvdata(phy); u32 value; + imx8mp_configure_glue(imx_phy); + /* USB3.0 PHY signal fsel for 24M ref */ value = readl(imx_phy->base + PHY_CTRL0); value &= ~PHY_CTRL0_FSEL_MASK; @@ -168,6 +219,15 @@ static int imx8mq_usb_phy_probe(struct platform_device *pdev) if (IS_ERR(imx_phy->base)) return PTR_ERR(imx_phy->base); + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + if (!res) { + dev_warn(dev, "Base address for glue layer missing. Continuing without, some features are missing though."); + } else { + imx_phy->glue_base = devm_ioremap_resource(dev, res); + if (IS_ERR(imx_phy->glue_base)) + return PTR_ERR(imx_phy->glue_base); + } + phy_ops = of_device_get_match_data(dev); if (!phy_ops) return -EINVAL;