Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5067777rdb; Tue, 12 Dec 2023 19:13:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFD8g0WdkOmyIKGC14HRL49Oi09XHOgcHyoTbFvcJjVcCcYR74rn24IrokpKzAtbXghacIh X-Received: by 2002:a17:90a:1d4e:b0:28a:e89f:5f9d with SMTP id u14-20020a17090a1d4e00b0028ae89f5f9dmr144271pju.5.1702437212951; Tue, 12 Dec 2023 19:13:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702437212; cv=none; d=google.com; s=arc-20160816; b=V2egX8Ya+LZrXlGunRCfpic+ry39x8+6m714CNYp3+mqGy3+acD2cbmy4c7mCM3Tu8 r4AhhxEdZeX9k85YzbZM6uppaIzK54/+j9TyRb4qEj+oMRSig0rp+A6nIgTAJQxESelM ORrzyGuilMMMp5Leltr9xNnkHoP4VS3Z7Qvcn7iUF6QSRZNuo1NdIHwZ6Xk8IJr2crr2 0c4iaWRB9wzGJ6FWottSzUlwLf1XncoE75gmlEsLQSDetGA0pprDQ2uLSwPbKV2QJUeu 9LKGwcf0Zg/YrlsrC1XHkTtb+QPNc8EHPhrl/dcu0Mg2RWbrmJTohBF+s+af7sVsbweG D0VA== 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=jTw5Im7rrAYjHKmypAwm+pE/APBsgMWEvNA3Mikfj+M=; fh=NYsNXvXkh6K2c8i48t4rRdazv6q0meb+wGK9M5L2pfg=; b=AqwLhVsHnmVlKg06qFIXzF65iig+CuKYplMEcuY+i/i9sHagwnJfqfuUBgv7rnCN9k S5uTPGYoHgZiuO0ZBlVM50uoazwj3aK2XBgq+iA7sSm3WJJ+1aLmNzdKEuh/DrfjFiyk ht3oqhAwXuMxcnQIWJq/FpZpj+OsBDFZ4OiltivQR8kSixdGoAg6mYBcQay8l56Ya9rW E9JzxvwkIKbhIla6GhIVIJO9x+DqURDGaXqo94oHXnzfx7jxLa3Oj81Wo5uOfY3y2LnN RhyyVqaygKBNYhl3GVCEb8W0Vm5TlCsrWjUVln0sg4bTtouVcCGPydm3y8kShbbYTA37 avhQ== 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 Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u15-20020a17090a450f00b00286e9a6f92fsi9952277pjg.63.2023.12.12.19.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 19:13:32 -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 741A080B8E52; Tue, 12 Dec 2023 19:13:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378381AbjLMDNW (ORCPT + 99 others); Tue, 12 Dec 2023 22:13:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230510AbjLMDNV (ORCPT ); Tue, 12 Dec 2023 22:13:21 -0500 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0862CB2; Tue, 12 Dec 2023 19:13:23 -0800 (PST) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 3BD3C6prC3944118, 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 3BD3C6prC3944118 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Dec 2023 11:12:06 +0800 Received: from RTEXMBS02.realtek.com.tw (172.21.6.95) 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; Wed, 13 Dec 2023 11:12:06 +0800 Received: from RTEXH36506.realtek.com.tw (172.21.6.27) by RTEXMBS02.realtek.com.tw (172.21.6.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 13 Dec 2023 11:12:03 +0800 Received: from localhost.localdomain (172.21.252.101) by RTEXH36506.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server id 15.1.2507.17 via Frontend Transport; Wed, 13 Dec 2023 11:12:03 +0800 From: Stanley Chang To: Greg Kroah-Hartman CC: Stanley Chang , Vinod Koul , Kishon Vijay Abraham I , Johan Hovold , Geert Uytterhoeven , Jinjie Ruan , Rob Herring , "Alan Stern" , Roy Luo , =?UTF-8?q?Ricardo=20Ca=C3=B1uelo?= , "Heikki Krogerus" , , , Subject: [PATCH v4 1/4] phy: core: add notify_connect and notify_disconnect callback Date: Wed, 13 Dec 2023 11:10:06 +0800 Message-ID: <20231213031203.4911-1-stanley_chang@realtek.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-KSE-ServerInfo: RTEXMBS02.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]); Tue, 12 Dec 2023 19:13:31 -0800 (PST) In Realtek SoC, the parameter of usb phy is designed to be able to do dynamic tuning based in the port status. Therefore, add a notify callback of phy driver when usb connection/disconnection change. Signed-off-by: Stanley Chang --- v3 to v4 change: 1. Modified some phrasing. 2. Add the description for callback function. v2 to v3: No change v1 to v2: No change --- drivers/phy/phy-core.c | 47 +++++++++++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 21 ++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 96a0b1e111f3..acfa408a3ca5 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 notification + * @phy: the phy returned by phy_get() + * @port: the port index for connect + * + * If the phy needs to 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 notification + * @phy: the phy returned by phy_get() + * @port: the port index for disconnect + * + * If the phy needs to get connection 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..aa76609ba258 100644 --- a/include/linux/phy/phy.h +++ b/include/linux/phy/phy.h @@ -122,6 +122,11 @@ struct phy_ops { union phy_configure_opts *opts); int (*reset)(struct phy *phy); int (*calibrate)(struct phy *phy); + + /* notify phy connect status change */ + int (*connect)(struct phy *phy, int port); + int (*disconnect)(struct phy *phy, int port); + void (*release)(struct phy *phy); struct module *owner; }; @@ -243,6 +248,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 +403,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) { -- 2.34.1