From patchwork Tue Nov 7 06:33:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?U3RhbmxleSBDaGFuZ1vmmIzogrLlvrdd?= X-Patchwork-Id: 162282 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp50910vqo; Mon, 6 Nov 2023 22:37:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmNNGyF77EVhzGgggnlYQl7Wqf1/YsSlyJ1PrGjwFnvRLWCaD8/1IgPGHYk1adfG8G1Bls X-Received: by 2002:a17:903:124a:b0:1cc:4625:74e2 with SMTP id u10-20020a170903124a00b001cc462574e2mr2671221plh.24.1699339068087; Mon, 06 Nov 2023 22:37:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699339068; cv=none; d=google.com; s=arc-20160816; b=G7L7gzQfVBuAlxr/FMndEOjNJF9y5I9Q7x+Bc1aTDugBHyA4Nkd3hYEhOV46Pta8JD XqD/R5kafNii0J614JOZY33PnUoKVgUso0fbQWlMFQsam4VBdqordG2m9CU0exeC49k0 qPQhFlSCGZgiY08LPNgLcVenqbIVy6SW25ilVBgl/6xQyIP1AOCs03yFdgbSt7QCF5oZ 4X+aPDZYfOLcd6MOQrz9uklWHe3wsynTt8bv9TgLtzES30UP43x0q5CeP0UTdj2Dikvi U3f+cr9gAMxxl3vrGP6RZtvGxuePru+A/HJjsrwtkkrc5AhSizuOkhSXMCa3G7FfqEoy S1Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=3g/AinVXa1BjYDKTz6UQ7pV0H3puht/xNCv8PRkwf6I=; fh=rdyVzzLC+YAcK8TQHyYIhWSiE3owbOhOozYZhRL+T20=; b=IDhkXweAF2r+FW4wBH3lLHeDkO18tS1v5ZTTpjXzD/VdreyJmWs86eOas3BiXsjSJw hUrsNgHIgciIyzc76ew/VkcPLS/4fLQF2+ADWEIOpqbW1DEkSfPGqbduowTcuWiIm/S6 DxIa//Cx6oFUfmEZz85d3cf9cyxbJrTtE+KtJKkOTr+BblTcMQVemwH1Roi3pBbps5/J 7KikXEoMDh8BoEE0M4sErvBgq7DLB7f5wxt3iqQVkU79UywqkVLMymOcFHEjllQuLU5H 30G17NCTgKFR3XPluM3F7Ilfg2L+BIq7ttJUhQWBK6udFb6Psv00J77gcMuuu+/pIguK KKdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u1-20020a170902e80100b001cc2a0618f4si10433954plg.199.2023.11.06.22.37.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 22:37:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 281C881121E5; Mon, 6 Nov 2023 22:37:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233578AbjKGGhi (ORCPT + 33 others); Tue, 7 Nov 2023 01:37:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229559AbjKGGhb (ORCPT ); Tue, 7 Nov 2023 01:37:31 -0500 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 766B2119; Mon, 6 Nov 2023 22:37:27 -0800 (PST) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 3A76ZJYm84026363, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36505.realtek.com.tw[172.21.6.25]) by rtits2.realtek.com.tw (8.15.2/2.95/5.92) with ESMTPS id 3A76ZJYm84026363 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 7 Nov 2023 14:35:19 +0800 Received: from RTEXMBS01.realtek.com.tw (172.21.6.94) by RTEXH36505.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.32; Tue, 7 Nov 2023 14:35:19 +0800 Received: from RTEXH36505.realtek.com.tw (172.21.6.25) by RTEXMBS01.realtek.com.tw (172.21.6.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Tue, 7 Nov 2023 14:35:19 +0800 Received: from localhost.localdomain (172.21.252.101) by RTEXH36505.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server id 15.1.2375.32 via Frontend Transport; Tue, 7 Nov 2023 14:35:19 +0800 From: Stanley Chang To: Greg Kroah-Hartman CC: Stanley Chang , Vinod Koul , Johan Hovold , Kishon Vijay Abraham I , Rob Herring , Jinjie Ruan , "Alan Stern" , Yang Yingliang , =?utf-8?q?Ricardo_Ca=C3=B1uelo?= , Roy Luo , Heikki Krogerus , Ray Chi , , , Subject: [PATCH v1 1/4] phy: core: add notify_connect and notify_disconnect callback Date: Tue, 7 Nov 2023 14:33:44 +0800 Message-ID: <20231107063518.27824-1-stanley_chang@realtek.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-KSE-ServerInfo: RTEXMBS01.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-ServerInfo: RTEXH36505.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 22:37:47 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781886162800482952 X-GMAIL-MSGID: 1781886162800482952 In Realtek SoC, the parameter of usb phy is designed to can dynamic tuning base on port status. Therefore, add a notify callback of phy driver when usb connection/disconnection change. Signed-off-by: Stanley Chang --- drivers/phy/phy-core.c | 47 +++++++++++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 18 ++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 96a0b1e111f3..a84ad4896b7f 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -489,6 +489,53 @@ int phy_calibrate(struct phy *phy) } EXPORT_SYMBOL_GPL(phy_calibrate); +/** + * phy_notify_connect() - phy connect notify + * @phy: the phy returned by phy_get() + * @port: the port index for connect + * + * If phy need the get connection status, the callback can be used. + * Returns: %0 if successful, a negative error code otherwise + */ +int phy_notify_connect(struct phy *phy, int port) +{ + int ret; + + if (!phy || !phy->ops->connect) + return 0; + + mutex_lock(&phy->mutex); + ret = phy->ops->connect(phy, port); + mutex_unlock(&phy->mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(phy_notify_connect); + +/** + * phy_notify_disconnect() - phy disconnect notify + * @phy: the phy returned by phy_get() + * @port: the port index for disconnect + * + * If phy need the get disconnection status, the callback can be used. + * + * Returns: %0 if successful, a negative error code otherwise + */ +int phy_notify_disconnect(struct phy *phy, int port) +{ + int ret; + + if (!phy || !phy->ops->disconnect) + return 0; + + mutex_lock(&phy->mutex); + ret = phy->ops->disconnect(phy, port); + mutex_unlock(&phy->mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(phy_notify_disconnect); + /** * phy_configure() - Changes the phy parameters * @phy: the phy returned by phy_get() diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h index f6d607ef0e80..cf98cb29ddaa 100644 --- a/include/linux/phy/phy.h +++ b/include/linux/phy/phy.h @@ -122,6 +122,8 @@ struct phy_ops { union phy_configure_opts *opts); int (*reset)(struct phy *phy); int (*calibrate)(struct phy *phy); + int (*connect)(struct phy *phy, int port); + int (*disconnect)(struct phy *phy, int port); void (*release)(struct phy *phy); struct module *owner; }; @@ -243,6 +245,8 @@ static inline enum phy_mode phy_get_mode(struct phy *phy) } int phy_reset(struct phy *phy); int phy_calibrate(struct phy *phy); +int phy_notify_connect(struct phy *phy, int port); +int phy_notify_disconnect(struct phy *phy, int port); static inline int phy_get_bus_width(struct phy *phy) { return phy->attrs.bus_width; @@ -396,6 +400,20 @@ static inline int phy_calibrate(struct phy *phy) return -ENOSYS; } +static inline int phy_notify_connect(struct phy *phy, int index) +{ + if (!phy) + return 0; + return -ENOSYS; +} + +static inline int phy_notify_disconnect(struct phy *phy, int index) +{ + if (!phy) + return 0; + return -ENOSYS; +} + static inline int phy_configure(struct phy *phy, union phy_configure_opts *opts) {