From patchwork Wed Apr 18 19:39:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10348831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1E9AA60244 for ; Wed, 18 Apr 2018 19:40:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E85E28831 for ; Wed, 18 Apr 2018 19:40:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0323F28837; Wed, 18 Apr 2018 19:40:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C12728831 for ; Wed, 18 Apr 2018 19:40:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752689AbeDRTkQ (ORCPT ); Wed, 18 Apr 2018 15:40:16 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:38684 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752613AbeDRTkO (ORCPT ); Wed, 18 Apr 2018 15:40:14 -0400 Received: by mail-wr0-f195.google.com with SMTP id h3-v6so7857751wrh.5 for ; Wed, 18 Apr 2018 12:40:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JZ1kMbOVNU80RaBYVmvtc7lMW5mpjcIc/jcKpS6arYc=; b=cGpLvuV59ne2/j4aje6KeR4Sty55rb4jLGzHkv/4/hWpxm+AR53PXZ5a2Q5GX4Y/G4 30ozTvo63yiSiCX2C34XgyOvoR/u6x2y1WepITWXtQ6tugF78nYTQRy8qT2Uw/PP4Ex6 dHNZi4HJIyyVoff7HT8gRE+IrnmfyryLVCs+f/MQ5WGcSTxMf4ynITNePFC3U6Y4dduJ LyFJE9JdrLv032M/4BueZxfyTaz78sS6TO3YfrgxZPAXgyP24QAU49v14ZOpGL+mGhk7 mmCkMfyU9i9+xOUufN7227d2zo7SBcIjQNFBGr+mJHlVTgunB0aueyZQKpmlYwgdIzF6 01qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JZ1kMbOVNU80RaBYVmvtc7lMW5mpjcIc/jcKpS6arYc=; b=k91DSDRIJMNJVlFofYp6C38GfqSGeCVHiwumma885PWwv5XwIgMfxPWwF+AD4QyHRH ZhiVfuQJTr6F5FTNBRXpGCepKONdN4/6zNmbwXvqa5bI6w4o/b3/NKtvmI5hwX0FVhTS LX4OS0QMIA3cUphqsjJPmarTBpK1lMPVGuXrGT+ZBZxw4MsYshAYSuOIzMaPYxNGJ2vQ eVYtzLnhWuH3hOlh3EK3BMmhaFrIoh96URYJcjIz+jobqpT3xaSuz8WY2EsAxFn/IS2C AM1PW4ttNO5aQrtWseOhowPEKEbwFp/ZbU4jyzqf8ko1nRmHbA+Knu2Zqj4fxw6g+hHF eSQw== X-Gm-Message-State: ALQs6tCuxxi4Z8CAYpOPULNUxIJ3dInMurdmotsUDtvzKrpExqlXxzA+ olvfleqyNMHqc3EBkskpx7kdwBK4 X-Google-Smtp-Source: AIpwx49UPo35y8VtQLJvNp71RNDhoHkPngnQ3pNONdXiy6EtGubuYiwLht2j62d/rpvm/pdHGBYWSQ== X-Received: by 2002:adf:bd03:: with SMTP id j3-v6mr1958159wrh.138.1524080412616; Wed, 18 Apr 2018 12:40:12 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD743A504F9143C002217B8ED.dip0.t-ipconnect.de. [2003:dc:d743:a504:f914:3c00:2217:b8ed]) by smtp.googlemail.com with ESMTPSA id 60-v6sm1871990wrj.62.2018.04.18.12.40.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Apr 2018 12:40:12 -0700 (PDT) From: Martin Blumenstingl To: linux-usb@vger.kernel.org, gregkh@linuxfoundation.org Cc: matthias.bgg@gmail.com, stern@rowland.harvard.edu, rogerq@ti.com, linux-mediatek@lists.infradead.org, linux-amlogic@lists.infradead.org, j-keerthy@ti.com, d-gerlach@ti.com, kishon@ti.com, chunfeng.yun@mediatek.com, linux-rpi-kernel@lists.infradead.org, eric@anholt.net, yamada.masahiro@socionext.com, Martin Blumenstingl Subject: [PATCH usb v6 2/6] usb: core: split usb_phy_roothub_{init,alloc} Date: Wed, 18 Apr 2018 21:39:47 +0200 Message-Id: <20180418193951.17922-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180418193951.17922-1-martin.blumenstingl@googlemail.com> References: <20180418193951.17922-1-martin.blumenstingl@googlemail.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before this patch usb_phy_roothub_init served two purposes (from a caller's point of view - like hcd.c): - parsing the PHYs and allocating the list entries - calling phy_init on each list entry While this worked so far it has one disadvantage: if we need to call phy_init for each PHY instance then the existing code cannot be re-used. Solve this by splitting off usb_phy_roothub_alloc which only parses the PHYs and allocates the list entries. usb_phy_roothub_init then gets a struct usb_phy_roothub and only calls phy_init on each PHY instance (along with the corresponding cleanup if that failed somewhere). This is a preparation step for adding proper suspend support for some hardware that requires phy_exit to be called during suspend and phy_init to be called during resume. Signed-off-by: Martin Blumenstingl Tested-by: Chunfeng Yun Reviewed-by: Roger Quadros Tested-by: Keerthy --- drivers/usb/core/hcd.c | 10 +++++--- drivers/usb/core/phy.c | 53 +++++++++++++++++++++--------------------- drivers/usb/core/phy.h | 4 +++- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 777036ae6367..15b0418e3b6a 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -2758,12 +2758,16 @@ int usb_add_hcd(struct usb_hcd *hcd, } if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) { - hcd->phy_roothub = usb_phy_roothub_init(hcd->self.sysdev); + hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev); if (IS_ERR(hcd->phy_roothub)) { retval = PTR_ERR(hcd->phy_roothub); - goto err_phy_roothub_init; + goto err_phy_roothub_alloc; } + retval = usb_phy_roothub_init(hcd->phy_roothub); + if (retval) + goto err_phy_roothub_alloc; + retval = usb_phy_roothub_power_on(hcd->phy_roothub); if (retval) goto err_usb_phy_roothub_power_on; @@ -2936,7 +2940,7 @@ int usb_add_hcd(struct usb_hcd *hcd, usb_phy_roothub_power_off(hcd->phy_roothub); err_usb_phy_roothub_power_on: usb_phy_roothub_exit(hcd->phy_roothub); -err_phy_roothub_init: +err_phy_roothub_alloc: if (hcd->remove_phy && hcd->usb_phy) { usb_phy_shutdown(hcd->usb_phy); usb_put_phy(hcd->usb_phy); diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c index f19aaa3c899c..44f008cda7a8 100644 --- a/drivers/usb/core/phy.c +++ b/drivers/usb/core/phy.c @@ -19,19 +19,6 @@ struct usb_phy_roothub { struct list_head list; }; -static struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev) -{ - struct usb_phy_roothub *roothub_entry; - - roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), GFP_KERNEL); - if (!roothub_entry) - return ERR_PTR(-ENOMEM); - - INIT_LIST_HEAD(&roothub_entry->list); - - return roothub_entry; -} - static int usb_phy_roothub_add_phy(struct device *dev, int index, struct list_head *list) { @@ -45,9 +32,11 @@ static int usb_phy_roothub_add_phy(struct device *dev, int index, return PTR_ERR(phy); } - roothub_entry = usb_phy_roothub_alloc(dev); - if (IS_ERR(roothub_entry)) - return PTR_ERR(roothub_entry); + roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), GFP_KERNEL); + if (!roothub_entry) + return -ENOMEM; + + INIT_LIST_HEAD(&roothub_entry->list); roothub_entry->phy = phy; @@ -56,11 +45,9 @@ static int usb_phy_roothub_add_phy(struct device *dev, int index, return 0; } -struct usb_phy_roothub *usb_phy_roothub_init(struct device *dev) +struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev) { struct usb_phy_roothub *phy_roothub; - struct usb_phy_roothub *roothub_entry; - struct list_head *head; int i, num_phys, err; num_phys = of_count_phandle_with_args(dev->of_node, "phys", @@ -68,16 +55,31 @@ struct usb_phy_roothub *usb_phy_roothub_init(struct device *dev) if (num_phys <= 0) return NULL; - phy_roothub = usb_phy_roothub_alloc(dev); - if (IS_ERR(phy_roothub)) - return phy_roothub; + phy_roothub = devm_kzalloc(dev, sizeof(*phy_roothub), GFP_KERNEL); + if (!phy_roothub) + return ERR_PTR(-ENOMEM); + + INIT_LIST_HEAD(&phy_roothub->list); for (i = 0; i < num_phys; i++) { err = usb_phy_roothub_add_phy(dev, i, &phy_roothub->list); if (err) - goto err_out; + return ERR_PTR(err); } + return phy_roothub; +} +EXPORT_SYMBOL_GPL(usb_phy_roothub_alloc); + +int usb_phy_roothub_init(struct usb_phy_roothub *phy_roothub) +{ + struct usb_phy_roothub *roothub_entry; + struct list_head *head; + int err; + + if (!phy_roothub) + return 0; + head = &phy_roothub->list; list_for_each_entry(roothub_entry, head, list) { @@ -86,14 +88,13 @@ struct usb_phy_roothub *usb_phy_roothub_init(struct device *dev) goto err_exit_phys; } - return phy_roothub; + return 0; err_exit_phys: list_for_each_entry_continue_reverse(roothub_entry, head, list) phy_exit(roothub_entry->phy); -err_out: - return ERR_PTR(err); + return err; } EXPORT_SYMBOL_GPL(usb_phy_roothub_init); diff --git a/drivers/usb/core/phy.h b/drivers/usb/core/phy.h index 6fde59bfbff8..eb31253201ad 100644 --- a/drivers/usb/core/phy.h +++ b/drivers/usb/core/phy.h @@ -1,6 +1,8 @@ struct usb_phy_roothub; -struct usb_phy_roothub *usb_phy_roothub_init(struct device *dev); +struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev); + +int usb_phy_roothub_init(struct usb_phy_roothub *phy_roothub); int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub); int usb_phy_roothub_power_on(struct usb_phy_roothub *phy_roothub);