From patchwork Sat Jan 18 10:22:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Simons X-Patchwork-Id: 13944107 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 5BA93C02185 for ; Sat, 18 Jan 2025 10:22:30 +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:Message-ID:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=LDWMc0vAnQNzxpDbyoqU5SHa6R5eZgC/ILf0KUsy2F8=; b=2d28OvF1kpJwPg dJMxMn1kFAxfZa29omCKOB6aIedBKaJGacp2wcz7yCQAqi7nag7wxslC0qQEJSmvwDUlU71I7Lad/ kriImb1ifJoEveYb34+kCucK60zKYjlLcRoF6+78F++bQF3XBCst3qppsNODT1RSNq2kmlFWhywY5 BJa3ncw/UdM9Aqpx02iIZBhxVz0Pvq6R2tyIHxyoUZ74sji9ofirW/UDKQj7fDA92l7D0YMTmGxRF 3k7Q7JKJsS6VRuHyzxXbLhXAq+R1xg5JqL9m5qXIBYjGdq9rWHWFI0MG2hRhL6DtLBaYr8nmaf3JY RNJiooAnJXnC+IuXv6cA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tZ5yH-00000002B2r-3xzt; Sat, 18 Jan 2025 10:22:29 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tZ5yF-00000002B2G-21YZ; Sat, 18 Jan 2025 10:22:28 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-436326dcb1cso19450865e9.0; Sat, 18 Jan 2025 02:22:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737195745; x=1737800545; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=g7KYYLVYAzSjQ+OOEOBYCeT9uSdwa/8OaOS+anJ2pbk=; b=XrAR79iG2V6nkQYCiarSmznvkLE72SaPFg3lrNyoF0fpsJw4F2RsEKBOtrJUjU4Rzz 0zVVUZk9JWBZO28nIxREcJqQinK/yhxkDONrPEd6xihPR5atX2qNGJACSU8u+T5ALqrD kmiGWIbHlp6Bfv3AGT2f8vLW6DoeAaL2Ky1wFiL8Zi1on+GwRIPJoyAJtOyPYZAZpd9d h1UGIz4n+kq2iRg4XwDwXvcUel9K7fseBBCrfN1hhfZuPZacsqiTVSDKeeagCE4UNQRy gmi0BscpHY47Dxhq4tTQmnH3xdq+0b5TGKqxClHr94/Otf6r2QCO3QDCP6XhMJHzdeKR fQzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737195745; x=1737800545; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=g7KYYLVYAzSjQ+OOEOBYCeT9uSdwa/8OaOS+anJ2pbk=; b=dUGYkaoieYtibOVqDQYKec5DsITbIK8nh+BtNSVjGNWtVW9zlWGLaNAsElP1oRDL+D lzYmRbhyYtm+pu0T5lNXkhB8Hll8pfMQS9vWi2FejYKDUywDXze/rK1i/ZHddlWknlIs gIJjIDgX0tUOXDkQG4DYM6W0dRmdtG07ITAShBdHSHly+LeHbO9DYhkVKR2KpJNXd3fX ajKX2KvIOBcci+5DVhpOxcTVmGaanCnPMgMuHuMnDiHJ8GfH6cQ7K1FQBtRnHVk49fXw COsAKRiuVm/ark0d2oXWR+UjEfzFCJDFpjIZkF6oz18lzTZIyef+L3cwdL4g4u0Rtr9/ IliQ== X-Forwarded-Encrypted: i=1; AJvYcCUAQcUyucieoXzBK316KBecz6xpcVJ8zw9CGPXmu5IulqcGF1y4gzPSEhoTA1KCC85B6CHNbuW+fV0q@lists.infradead.org, AJvYcCWztO1IXPaZsmNyhzO/PK+IDnBVyR3PjiK0HBiynNgcKRXj36SZOYydsy7/NKyLau7A29mCZSjwzkWgoxCWCKGQ@lists.infradead.org X-Gm-Message-State: AOJu0YzPJOkUDuGHny4i05e6/RdzpOXM/NcnkeV09kVJhIRW+5gnvZ5e 6BYD3+EeyzA2GMR019OU8CFVj7q1UsMWAuuRmlfP/8RxvtOoK0ke X-Gm-Gg: ASbGncudmuhOEQk1oZNGF4xDcwjqTmtK75PQIoAuguwfqQWu1pSRGFNJxp9rLf1I9Fh bOz8eAA1jYv2uh+JQyRcVt2PkGAjdZKGRLf9y/BHRRGGMrqFZkGj/0VTZh5IYQEYg1jbGEslaUD Ml19k2p9Zkk9KMncFRErziX/9LsZeUvFnI8a6SsCb3u5kvJ1lvVOodaC4FL0b37taGwDjhnGrVB 8Gfbn73W2tsP4uW5RmN+i1KwbWw9L6ROZIDx1cy2iaAmZuXj1hnOa4ObKIqGgrBU9Ny83UkgAgT IPM56XscoR8EK3l4P5UxnY5uJguHS4YNpD4eSqBaKbm1Clf5Lj72gIdY X-Google-Smtp-Source: AGHT+IEC8wg+03HMOeCQYRjaEL4hVw0Oam/RePsv5fuRPjO3sBxgUEwi9m+wMgy/eMHl2a2vGkenKA== X-Received: by 2002:a7b:c8c9:0:b0:436:fb02:e68 with SMTP id 5b1f17b1804b1-438913bdd6cmr55694025e9.2.1737195744926; Sat, 18 Jan 2025 02:22:24 -0800 (PST) Received: from localhost.localdomain (146.10-240-81.adsl-dyn.isp.belgacom.be. [81.240.10.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438904625f5sm64954515e9.28.2025.01.18.02.22.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jan 2025 02:22:24 -0800 (PST) From: Philippe Simons To: Vinod Koul , Kishon Vijay Abraham I , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Philippe Simons , linux-phy@lists.infradead.org (open list:GENERIC PHY FRAMEWORK), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Allwinner sunXi SoC support), linux-sunxi@lists.linux.dev (open list:ARM/Allwinner sunXi SoC support), linux-kernel@vger.kernel.org (open list) Subject: [RFC PATCH 1/3] phy: don't let controllers change vbus reg Date: Sat, 18 Jan 2025 11:22:04 +0100 Message-ID: <20250118102207.9339-1-simons.philippe@gmail.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250118_022227_541357_20A9012A X-CRM114-Status: GOOD ( 13.32 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org Allwinners SoCs share phy0 between the MUSB controller and HCI controller. If we let these controllers independently power on the vbus on that phy, peripheral mode is dangerous because HCI never power down the phy, resulting in 5v being applied against the host 5v. Override power_on/off for phy0 in that case, and let regulator be enabled/disabled based on id_det only. Signed-off-by: Philippe Simons --- drivers/phy/allwinner/phy-sun4i-usb.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c index b0f19e950..24fbabe7a 100644 --- a/drivers/phy/allwinner/phy-sun4i-usb.c +++ b/drivers/phy/allwinner/phy-sun4i-usb.c @@ -465,6 +465,10 @@ static int sun4i_usb_phy_power_on(struct phy *_phy) struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); int ret; + /* phy0 power is controlled by sun4i_usb_phy0_reroute and id_det state */ + if (phy->index == 0 && data->cfg->phy0_dual_route) + return 0; + if (!phy->vbus || phy->regulator_on) return 0; @@ -493,6 +497,10 @@ static int sun4i_usb_phy_power_off(struct phy *_phy) struct sun4i_usb_phy *phy = phy_get_drvdata(_phy); struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); + /* phy0 power is controlled by sun4i_usb_phy0_reroute and id_det state */ + if (phy->index == 0 && data->cfg->phy0_dual_route) + return 0; + if (!phy->vbus || !phy->regulator_on) return 0; @@ -573,9 +581,21 @@ static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, int id_det) if (id_det == 0) { /* Host mode. Route phy0 to EHCI/OHCI */ regval &= ~OTGCTL_ROUTE_MUSB; + + /* Enable VBUS reg */ + if (phy->vbus && !phy->regulator_on) { + regulator_enable(phy->vbus); + phy->regulator_on = true; + } } else { /* Peripheral mode. Route phy0 to MUSB */ regval |= OTGCTL_ROUTE_MUSB; + + /* Disable VBUS reg */ + if (phy->vbus && phy->regulator_on) { + regulator_disable(phy->vbus); + phy->regulator_on = false; + } } writel(regval, data->base + REG_PHY_OTGCTL); } @@ -603,6 +623,12 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work) return; } + /* Disable internal VBUS reg if there is an external VBUS */ + if (vbus_det != 0 && phy->vbus && phy->regulator_on) { + regulator_disable(phy->vbus); + phy->regulator_on = false; + } + force_session_end = data->force_session_end; data->force_session_end = false; From patchwork Sat Jan 18 10:22:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Simons X-Patchwork-Id: 13944108 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 68153C02185 for ; Sat, 18 Jan 2025 10:23:47 +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:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ieLnw+2DIbL4SAM5PHDIAHp2T4Y9I+1bN01tZS9x5+A=; b=GywXtfLRuN1CGH wsfRPlZHlFQQqJEkZbxKc82hs0D8G+9Xohpfh7eNfNFs2a9Dm/OpsPtLjwg1OA9CHnNM1gl+qyTKJ De5xq6WkHhdOAqvcIbnSRJSVlogwBv6D21VyHuIqRgIeqy/HYr7AZF5B5ZtgL0hxZH/MJt7PX8EX9 T9kqnyK1AcuJrk37Wq3HvUKuuOlRvsiiarpdhYKhQ7QvnxXX/pTsAyKNtDlU7IneN0zYDkTU0+C14 f1jdB0PWHA/QyqHKJEbgORcylT8QFJCRVMsdIwfpNZIBczRPMILvMg8TV5XIz0B4qdlHioLmFMrBz BzUoftaGzYEvmbg4/d4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tZ5zX-00000002BIg-0Bge; Sat, 18 Jan 2025 10:23:47 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tZ5yK-00000002B3F-1nBj; Sat, 18 Jan 2025 10:22:33 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-43621d27adeso19245055e9.2; Sat, 18 Jan 2025 02:22:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737195751; x=1737800551; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=nC9ffH/nTNUFv6K8T3S/PFYpK8wABX0lQdic/jOeTiU=; b=WcAwtKEvV6dUw9tOzueX7AuZjhzKPt3fwlk1Rk3wPDbS4co7qpFX5zGakxo5lyo4A7 zBROxrWxniNx2wHqoF6ReoyoYLvPiEAq6f5bOu8tuPpmTZvzBHz3uNC8H3DQ9ZLOw6qn fnDG8oOtii5mDjTKRmoS3FWlMhOsU19zM2zOpcth/h7/tJtkQRwPCGYR7pinoYRfjOjs 8z5wsE7OjxTqJL+c/nR7skcqRK4RzCUGm7XETuYenO7b+Z1AXglRlVscb9MbEN6vXgD7 Ge/qvHm9O21XUobMMRr+iZv5rmu0oTF/KEzXxXBLGqa+3YEYYJXp7PvZptTDTk68QneS pRSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737195751; x=1737800551; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nC9ffH/nTNUFv6K8T3S/PFYpK8wABX0lQdic/jOeTiU=; b=N8+NyYT4kgVkSzcdWNmMfIQAo6QZb0+MBtKe8t70SxbFnkCkRBd4xtljgicWHSkq5u At5ItwR8HTZJqQZUg73UIQISfiWDjFPdjlUXfGHRjrpXPx5eZ7OwBMv4zaYspR54DED7 vhGA4tQPTOe3k31BN1+eddWZGII1NtPuQv39BlsEeySQr/O0rFNUXv7LvWjdk+IUCGFt db3QmfYhqWauw2ZFgDeTwHMLYwLKTJRveB/d5xfDHDrIxa65LTOJq01sw1SUQMIiT1yr ijcULpD4GIfWxspekTtBbnxKqoQjXjRE5LkSBQ20hdrQsSS3bf30B+TmJE0HsL1KJpY4 S/eA== X-Forwarded-Encrypted: i=1; AJvYcCWssA3sDrVBggD79wXTDQMPY1CLWXpxfzJru1qQJriL7VOMA+SwA0JumQbS405yj9GwJ2jMFESPQYZ5hvtMHtWj@lists.infradead.org, AJvYcCXSuXratiZvro2s1Ep2Vz/inhNyNr/x9nmBncUAtf0zWAgd9gE1MSzy1WXH/ZuQ2iTSOmRSEFCwnUe8@lists.infradead.org X-Gm-Message-State: AOJu0YzUjO2pHSbfHold1AQDZtcuMG/egi1KlkxGVr9T+3i6SgT+PIAj XrksdnQgU45B4M+0kgIqttIHyOUwSOl8PkPA0KCGEoXCws1DWdN1 X-Gm-Gg: ASbGncudpJcmHPkuUHh9SntTrzpVje7aRqS8Lkruj9qWT7KO6c2Y1dKQHxvqJ/9byDy 3Xgrvz5U5y+aN/VixDZ0RgO1hNiezMAwZTQX2r1n7RnePuUODhwcMPJRr5kQ8p/wEZqTzJ/xmuV 0zj8qE//Jrg66mIK2XQpyVnMdWN27wjJ/UoRlUR5bnS01j48gdn1VsXua7cmpvZuWww2Tl+bIyZ qK7YPidyzUG8K6LZ2KNxniBIDNsQR3mRUJbJUQh0Oy5NQpfRCY4vGr7Xf/FsaHYtzn8Xdvd8QqU wZSuEQWDc28IrIAEJb2ln0HtRmSPjOV3FwX5DmJDldB2NB1aEoYM3NY5/GoGj3swlY4= X-Google-Smtp-Source: AGHT+IEzVhZwb9RUCfq/ONUwCHiNJip3Q45A/4YRARL89NaJTkSBtQ24v5vFGO4m8bxs52aAynsUuQ== X-Received: by 2002:a05:600c:5101:b0:434:f925:f5c9 with SMTP id 5b1f17b1804b1-438913c85e0mr55777645e9.6.1737195750502; Sat, 18 Jan 2025 02:22:30 -0800 (PST) Received: from localhost.localdomain (146.10-240-81.adsl-dyn.isp.belgacom.be. [81.240.10.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438904625f5sm64954515e9.28.2025.01.18.02.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jan 2025 02:22:30 -0800 (PST) From: Philippe Simons To: Vinod Koul , Kishon Vijay Abraham I , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Philippe Simons , linux-phy@lists.infradead.org (open list:GENERIC PHY FRAMEWORK), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Allwinner sunXi SoC support), linux-sunxi@lists.linux.dev (open list:ARM/Allwinner sunXi SoC support), linux-kernel@vger.kernel.org (open list) Subject: [RFC PATCH 2/3] phy: override dr_mode for phy0 Date: Sat, 18 Jan 2025 11:22:05 +0100 Message-ID: <20250118102207.9339-2-simons.philippe@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250118102207.9339-1-simons.philippe@gmail.com> References: <20250118102207.9339-1-simons.philippe@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250118_022232_467403_B9C19DF4 X-CRM114-Status: GOOD ( 11.74 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org PHY0 mode is fully determined by the selected mux route. Ignore changes requests from controllers. Signed-off-by: Philippe Simons --- drivers/phy/allwinner/phy-sun4i-usb.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c index 24fbabe7a..f163b355e 100644 --- a/drivers/phy/allwinner/phy-sun4i-usb.c +++ b/drivers/phy/allwinner/phy-sun4i-usb.c @@ -544,6 +544,18 @@ static int sun4i_usb_phy_set_mode(struct phy *_phy, return -EINVAL; } + if (data->cfg->phy0_dual_route) { + /* + For SoCs with dual route the PHY mode is fully determined by + the selected mux route (i.e. USB controller to use). + As both host (EHCI/OHCI) and peripheral (MUSB) controllers uses + the same PHY, both drivers can try to set PHY mode. + We need to ignore this requests, but not report error in case + of valid mode values. + */ + return 0; + } + if (new_mode != data->dr_mode) { dev_info(&_phy->dev, "Changing dr_mode to %d\n", new_mode); data->dr_mode = new_mode;