Message ID | 20230421080333.18681-1-stanley_chang@realtek.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp913867vqo; Fri, 21 Apr 2023 01:39:56 -0700 (PDT) X-Google-Smtp-Source: AKy350YKrZS+7ILoOVw3vqvHkuLv8iP8uLmJJ5UQ1QuJ/sME6vdn97YNFvNgNlsKiJHdCeNTmLMm X-Received: by 2002:a17:90a:4812:b0:23b:4439:4179 with SMTP id a18-20020a17090a481200b0023b44394179mr4652712pjh.28.1682066396369; Fri, 21 Apr 2023 01:39:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682066396; cv=none; d=google.com; s=arc-20160816; b=mg6NBmmtyajf9tC1F9wUPNvWmklVo/wvH8WUB/btkjKMObvt1Y3hFb9RNRmnsU4dm3 yrOrSsmRu147IgYb5RK6CpnNn8v7nabtJ6kn6Gv/V4XHwhdv0j611OlvwIeOyaCuw4BX /hEBgopnA3fE6Elblw7KeU4LAakfc/IhhFUYvVjZQ1SI6+lyZJEHHQFUhIdlwJimPgep d0JgeEOHPNceC/PsYKxhF7uXNK9ubEACFHxIhTL/Sz6re0SBo1Vi0k6EilqOIS8nQv2G n1ZXAbjvbV3mSJQ2gwyGGSf96MsgYJFXhRiAbSWPTsP4cmYXMDCBRbLfcFSlygQ0Uqhm tX2A== 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:authenticated-by; bh=57Yb7YF2I+/KqOIopg0L5ompYl/TA5xgFthAnEwC5Yo=; b=iZ6UccybKdTFmekz83ibkscdq19n/8WkYjLod+319HHacVjt5/Pw/+eYBJumpfVD2B SKnG4TGOLuM/jknb5rEcJhtVLarzNFKksEDNC1wAvOYqQWyUBlRXh3WcTmOpyZ7Z6NOi APEDBGTmKPOYAmKZ7YXvhVZ6PRnLebYZrmqRSgmSKiwi3Cm91kJ6Tr7udJr+7hTVVLU2 10eJYAH6OQjav1Omx0Ds20V/TvW+gTW1z7s0X//VdWhpG7kEx5u3tUcxozltFIfrqh1p vRLmrtRcNIEVN7BgeMz7EHki1m8rAqcHZDIN5YMujuAbOcS59OE0svscF7/jnRo5Mcgy /flg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lb5-20020a17090b4a4500b00246fe4e326dsi7292443pjb.81.2023.04.21.01.39.40; Fri, 21 Apr 2023 01:39:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231492AbjDUIEh (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Fri, 21 Apr 2023 04:04:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229900AbjDUIE2 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 21 Apr 2023 04:04:28 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AACC58A62; Fri, 21 Apr 2023 01:04:25 -0700 (PDT) Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.77 with qID 33L83YGD0021724, 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.81/5.90) with ESMTPS id 33L83YGD0021724 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK); Fri, 21 Apr 2023 16:03:34 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) 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; Fri, 21 Apr 2023 16:03:34 +0800 Received: from RTEXH36506.realtek.com.tw (172.21.6.27) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 21 Apr 2023 16:03:33 +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; Fri, 21 Apr 2023 16:03:33 +0800 From: Stanley Chang <stanley_chang@realtek.com> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org> CC: Stanley Chang <stanley_chang@realtek.com>, Alan Stern <stern@rowland.harvard.edu>, Douglas Anderson <dianders@chromium.org>, Vincent Mailhol <mailhol.vincent@wanadoo.fr>, Bhuvanesh Surachari <Bhuvanesh_Surachari@mentor.com>, Mathias Nyman <mathias.nyman@linux.intel.com>, Flavio Suligoi <f.suligoi@asem.it>, Ray Chi <raychi@google.com>, Michael Grzeschik <m.grzeschik@pengutronix.de>, <linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org> Subject: [PATCH v1] usb: phy: add usb phy notify port status API Date: Fri, 21 Apr 2023 16:03:31 +0800 Message-ID: <20230421080333.18681-1-stanley_chang@realtek.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-KSE-ServerInfo: RTEXMBS04.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,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763773944406537846?= X-GMAIL-MSGID: =?utf-8?q?1763774453878601366?= |
Series |
[v1] usb: phy: add usb phy notify port status API
|
|
Commit Message
Stanley Chang[昌育德]
April 21, 2023, 8:03 a.m. UTC
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 port status change.
Signed-off-by: Stanley Chang <stanley_chang@realtek.com>
---
drivers/usb/core/hub.c | 13 +++++++++++++
include/linux/usb/phy.h | 14 ++++++++++++++
2 files changed, 27 insertions(+)
Comments
On Fri, Apr 21, 2023 at 04:03:31PM +0800, Stanley Chang wrote: > 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 port status change. > > Signed-off-by: Stanley Chang <stanley_chang@realtek.com> > --- > drivers/usb/core/hub.c | 13 +++++++++++++ > include/linux/usb/phy.h | 14 ++++++++++++++ > 2 files changed, 27 insertions(+) > > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c > index 97a0f8faea6e..b4fbbeae1927 100644 > --- a/drivers/usb/core/hub.c > +++ b/drivers/usb/core/hub.c > @@ -614,6 +614,19 @@ static int hub_ext_port_status(struct usb_hub *hub, int port1, int type, > ret = 0; > } > mutex_unlock(&hub->status_mutex); > + > + if (!ret) { > + struct usb_device *hdev = hub->hdev; > + > + if (hdev && !hdev->parent) { How can you have a device without a parent? And why does it matter? And how could hdev be NULL? And if it can change to be NULL, what prevents it from changing right after you checked for it? thanks, greg k-h
> > On Fri, Apr 21, 2023 at 04:03:31PM +0800, Stanley Chang wrote: > > 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 port status change. > > > > Signed-off-by: Stanley Chang <stanley_chang@realtek.com> > > --- > > drivers/usb/core/hub.c | 13 +++++++++++++ include/linux/usb/phy.h | > > 14 ++++++++++++++ > > 2 files changed, 27 insertions(+) > > We can not add callbacks in the kernel that are not actually used, otherwise > they will just be instantly removed. > > Please submit any drivers that need this change at the same time so that we > can verify that the callback is actually correct and needed, otherwise we can > not take this change. > In this stage, we usb phy driver is not at linux upstream. For the android GKI, we have to add this callback to upstream or use the vendor hook of android. I will plan to upstream the realtek usb phy driver. Thanks, Stanley
> > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index > > 97a0f8faea6e..b4fbbeae1927 100644 > > --- a/drivers/usb/core/hub.c > > +++ b/drivers/usb/core/hub.c > > @@ -614,6 +614,19 @@ static int hub_ext_port_status(struct usb_hub *hub, > int port1, int type, > > ret = 0; > > } > > mutex_unlock(&hub->status_mutex); > > + > > + if (!ret) { > > + struct usb_device *hdev = hub->hdev; > > + > > + if (hdev && !hdev->parent) { > > How can you have a device without a parent? And why does it matter? If the hub is a root hub, the parent of hub will be NULL. And we only send the port status to phy driver for root hub. > > And how could hdev be NULL? And if it can change to be NULL, what prevents > it from changing right after you checked for it? > It is right. hdev is never NULL, this is a redundant check. Thanks, Stanley
On Fri, Apr 21, 2023 at 08:32:19AM +0000, Stanley Chang[昌育德] wrote: > > > > On Fri, Apr 21, 2023 at 04:03:31PM +0800, Stanley Chang wrote: > > > 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 port status change. > > > > > > Signed-off-by: Stanley Chang <stanley_chang@realtek.com> > > > --- > > > drivers/usb/core/hub.c | 13 +++++++++++++ include/linux/usb/phy.h | > > > 14 ++++++++++++++ > > > 2 files changed, 27 insertions(+) > > > > We can not add callbacks in the kernel that are not actually used, otherwise > > they will just be instantly removed. > > > > Please submit any drivers that need this change at the same time so that we > > can verify that the callback is actually correct and needed, otherwise we can > > not take this change. > > > > In this stage, we usb phy driver is not at linux upstream. Then obviously we can not take this change (nor would you want us to.) > For the android GKI, we have to add this callback to upstream or use the vendor hook of android. > I will plan to upstream the realtek usb phy driver. As you already have this driver, why not send it to us now? thanks, greg k-h
> > > We can not add callbacks in the kernel that are not actually used, > > > otherwise they will just be instantly removed. > > > > > > Please submit any drivers that need this change at the same time so > > > that we can verify that the callback is actually correct and needed, > > > otherwise we can not take this change. > > > > > > > In this stage, we usb phy driver is not at linux upstream. > > Then obviously we can not take this change (nor would you want us to.) I will prepare a complete driver for review. > > For the android GKI, we have to add this callback to upstream or use the > vendor hook of android. > > I will plan to upstream the realtek usb phy driver. > > As you already have this driver, why not send it to us now? > Now the driver doesn't match the coding style. After I refactor it, I will send this driver upstream. Thanks, Stanley
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 97a0f8faea6e..b4fbbeae1927 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -614,6 +614,19 @@ static int hub_ext_port_status(struct usb_hub *hub, int port1, int type, ret = 0; } mutex_unlock(&hub->status_mutex); + + if (!ret) { + struct usb_device *hdev = hub->hdev; + + if (hdev && !hdev->parent) { + struct usb_hcd *hcd = bus_to_hcd(hdev->bus); + + if (hcd->usb_phy) + usb_phy_notify_port_status(hcd->usb_phy, + port1 - 1, *status, *change); + } + } + return ret; } diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index e4de6bc1f69b..53bf3540098f 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -144,6 +144,10 @@ struct usb_phy { */ int (*set_wakeup)(struct usb_phy *x, bool enabled); + /* notify phy port status change */ + int (*notify_port_status)(struct usb_phy *x, + int port, u16 portstatus, u16 portchange); + /* notify phy connect status change */ int (*notify_connect)(struct usb_phy *x, enum usb_device_speed speed); @@ -316,6 +320,16 @@ usb_phy_set_wakeup(struct usb_phy *x, bool enabled) return 0; } +static inline int +usb_phy_notify_port_status(struct usb_phy *x, int port, u16 portstatus, + u16 portchange) +{ + if (x && x->notify_port_status) + return x->notify_port_status(x, port, portstatus, portchange); + else + return 0; +} + static inline int usb_phy_notify_connect(struct usb_phy *x, enum usb_device_speed speed) {