Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1486821rdb; Wed, 6 Dec 2023 23:41:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGH9GTIHMBKSEaxybpjGrR4/nnGGzUHB7fjgzHf1noko4bTekhZ7CQF+7PO3g2Dhd7p9zD X-Received: by 2002:a05:6870:f6a9:b0:1fb:75b:2b89 with SMTP id el41-20020a056870f6a900b001fb075b2b89mr2069811oab.69.1701934912549; Wed, 06 Dec 2023 23:41:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701934912; cv=none; d=google.com; s=arc-20160816; b=U79qLfyhfI2BVpOVaVQNvYcjGT0JEm6oUprkv07jUUTWguSmE0kK0G89dBEbkqTXae vjSuE/X4GN3fTT9nlF04QIO2oxIHgqTvtcXyMzWOwI8r/69r0crZp2bIlqLq7C+oUa9J 4Apq8WEaxgcAFg2T7b04MQK+HmD39LQAKT3+CHXtyio8/JPk9yiFwXb5bclF1tTIWL9k ybSMw2QsKzU+6GU9liSFmtxpT51c1GL8suoPGhAs5EWsksauks4oiGvVb1YSLEMHaCUi E+++VaLMMKwn85SlFWkVXFSQHRGOefVdqi/zVgTyGeQM6tc/AShc1kepy5w6gdrVq1DY XsZA== 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=INGSaGbddqxMsRjAsGT+95ooVtRCP/qfUJTNkThEnEc=; fh=TnBftcBBYXJV91/imYvc9j9VPtUHPAYYr+v4GBy2m2I=; b=NEk3diCiJEl8zvvWAmFPQB6A4GZlhayHAkU35rHFsRSlxdJxzVQIqhufJafl1BRPqI ZIChOvd+RpN4CeW9elL1F/CvG+hg64ATnocHO4JOrVl3mx0J68gLMyh/4kDg5/expMYs tETDvAOxLAP+t2aYAZhxR8KzAFfm0XaFrm1iPuRsLGPw9qofD+vMbksy78uq0qqwP/yg N/H08y7GH0jl7YR0BL4xfKoMC/vaNVd0GLwdTumvO7AYz8/oEKoD1HcbMIOlQiuMdmij lV0k0bjZHZV9Lrc9kIYIwMYrOKpY1EQ/UpcLmhR5C9e/q8JPm0SM7N7csG++yhhRZgRP 0img== 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:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id 138-20020a630190000000b005c663eae37fsi707667pgb.295.2023.12.06.23.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 23:41:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 8E40280DF98E; Wed, 6 Dec 2023 23:41:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377921AbjLGHl3 (ORCPT + 99 others); Thu, 7 Dec 2023 02:41:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbjLGHl2 (ORCPT ); Thu, 7 Dec 2023 02:41:28 -0500 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F144137; Wed, 6 Dec 2023 23:41:34 -0800 (PST) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 3B77eMLW1005290, 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 3B77eMLW1005290 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Dec 2023 15:40:22 +0800 Received: from RTEXDAG01.realtek.com.tw (172.21.6.100) 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; Thu, 7 Dec 2023 15:40:23 +0800 Received: from RTEXH36506.realtek.com.tw (172.21.6.27) by RTEXDAG01.realtek.com.tw (172.21.6.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Thu, 7 Dec 2023 15:40:22 +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; Thu, 7 Dec 2023 15:40:22 +0800 From: Stanley Chang To: Greg Kroah-Hartman CC: Stanley Chang , Vinod Koul , Johan Hovold , Kishon Vijay Abraham I , Geert Uytterhoeven , Jinjie Ruan , Rob Herring , Alan Stern , Heikki Krogerus , Flavio Suligoi , =?UTF-8?q?Ricardo=20Ca=C3=B1uelo?= , , , Subject: [PATCH v3 RESEND 1/4] phy: core: add notify_connect and notify_disconnect callback Date: Thu, 7 Dec 2023 15:38:04 +0800 Message-ID: <20231207074022.14116-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: RTEXDAG01.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=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Wed, 06 Dec 2023 23:41:49 -0800 (PST) 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 --- RESEND: Because there is no extcon device provided in the USB framework to notify connect and disconnect. Therefore, I added the notification connection/disconnection based on the generic phy. So I no use the EXTCON framework for notifying connect/disconnect. v2 to v3: No change v1 to v2: No change --- 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) { -- 2.34.1