Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4292514pxv; Tue, 27 Jul 2021 03:52:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1TL+a+7Y9gZkoYZHJCCzkQAuemTW9IeV82mK9fey3gvlil1Uvh43YiFQqcovfloNsEfii X-Received: by 2002:a17:906:c1d0:: with SMTP id bw16mr21767766ejb.146.1627383177294; Tue, 27 Jul 2021 03:52:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627383177; cv=none; d=google.com; s=arc-20160816; b=AwN0tjWXAPAlgZ3VNb6HpcHzHiaSz25qpURIsxFAsw4bAQ0BgmiMlk8gTUbA2VFiFi HS9TdkDDRJqqSazOVu8X7J8qEisNoJ29RinYhweTxhsIK3iGtEv6rCKT7Sk0IBLENq7I kVP+1PylQz7iWPTVSwwNZB+2bcZh7fJ6duIJroCKyaOmPGxrUdf9oRJ065I4MZckKw79 IyEEELyw4wAX1nit8BuPg4/lPxe1NbZCZnsoUgdDpe/+2cVxgmkrBlA7Ypq6YgqW8C99 v26i18fIIksRj6gtcv+RynWAi/HSRJZV+PhIB7OnEyNt8i0v4APCT7AVmh+D7vSHcDZq IT+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=DOyKqL0iB+7jKShWcVFFXDDLIHHI1RGIiM/1QqlmiRE=; b=O+4MB+EL9GDrvJQ2bNKAbTWCS+KKeAeIBxnWi9VlCWq7I2i5cxoVqhHOc2XiK/35Hp bCazIbsJMYtYD9KFLuUhetDxTZsH5o24ZCfIAwzfpr241UCrpfzHzu1j0NArohrWqMOo EkewB8fWtijFtVdDp7wefp5AnnL54gY624Ob9j+XXdhn7MjJpoIP7O7/x5/2ndpN6FYb rtP2Z66CcRq1fDcuuFzsytSrwEriWu0586m1WN//KCz0nM2EJBpkkodZuoK1oV5ZLvYq 8IHMUwaXhKMsujUgRxOTw83HjGCjG2JPQkRr484YBbbpb0x0ymtan2SADQzlSq3MRsiy 8K/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k16si2588122edv.498.2021.07.27.03.52.34; Tue, 27 Jul 2021 03:52:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236421AbhG0Kuu (ORCPT + 99 others); Tue, 27 Jul 2021 06:50:50 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:52686 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S236293AbhG0Kuu (ORCPT ); Tue, 27 Jul 2021 06:50:50 -0400 X-UUID: cbe704db5b144178a1a6b3101c4e9843-20210727 X-UUID: cbe704db5b144178a1a6b3101c4e9843-20210727 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1000917277; Tue, 27 Jul 2021 18:50:45 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs06n2.mediatek.inc (172.21.101.130) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 27 Jul 2021 18:50:44 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 27 Jul 2021 18:50:44 +0800 From: Macpaul Lin To: , Chunfeng Yun , Kishon Vijay Abraham I , Vinod Koul , Matthias Brugger CC: Ainge Hsu , Eddie Hung , Kuohong Wang , Mediatek WSD Upstream , Macpaul Lin , Macpaul Lin , , , , Subject: [PATCH 1/2] phy: introduce phy mode PHY_MODE_UART and phy_get_mode_ext() Date: Tue, 27 Jul 2021 18:50:12 +0800 Message-ID: <1627383013-4535-1-git-send-email-macpaul.lin@mediatek.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some embedded platform shared PINs between USB and UART. For example, some phone will use special cable detection in boot loader to switch USB port function into UART mode. Hence Kernel need to query the hardware state from PHY registers to confirm the initialzation flow for PHY and USB driver. To support this kind of PIN switch, new PHY MODE and query API is required. Here we introduce a new PHY mode: PHY_MODE_UART. API phy_get_mode_ext() can be used to query the MODE from hardware instead of reading it from phy attributes. Signed-off-by: Macpaul Lin --- drivers/phy/phy-core.c | 17 +++++++++++++++++ include/linux/phy/phy.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index ccb575b..b8f6539 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -373,6 +373,23 @@ int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode) } EXPORT_SYMBOL_GPL(phy_set_mode_ext); +int phy_get_mode_ext(struct phy *phy) +{ + int ret; + + if (!phy || !phy->ops->get_mode_ext) + return 0; + + mutex_lock(&phy->mutex); + ret = phy->ops->get_mode_ext(phy); + if (!ret) + ret = phy->attrs.mode; + mutex_unlock(&phy->mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(phy_get_mode_ext); + int phy_set_media(struct phy *phy, enum phy_media media) { int ret; diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h index 0ed434d..7d32c6b 100644 --- a/include/linux/phy/phy.h +++ b/include/linux/phy/phy.h @@ -34,6 +34,7 @@ enum phy_mode { PHY_MODE_USB_DEVICE_HS, PHY_MODE_USB_DEVICE_SS, PHY_MODE_USB_OTG, + PHY_MODE_UART, PHY_MODE_UFS_HS_A, PHY_MODE_UFS_HS_B, PHY_MODE_PCIE, @@ -70,6 +71,7 @@ enum phy_media { * @power_on: powering on the phy * @power_off: powering off the phy * @set_mode: set the mode of the phy + * @get_mode_ext: get the extented mode of the phy * @set_media: set the media type of the phy (optional) * @set_speed: set the speed of the phy (optional) * @reset: resetting the phy @@ -83,6 +85,7 @@ struct phy_ops { int (*power_on)(struct phy *phy); int (*power_off)(struct phy *phy); int (*set_mode)(struct phy *phy, enum phy_mode mode, int submode); + int (*get_mode_ext)(struct phy *phy); int (*set_media)(struct phy *phy, enum phy_media media); int (*set_speed)(struct phy *phy, int speed); -- 1.7.9.5