From patchwork Sun Apr 8 21:27:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10328619 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 D069D604D4 for ; Sun, 8 Apr 2018 21:28:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB32B287A6 for ; Sun, 8 Apr 2018 21:28:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE57C28807; Sun, 8 Apr 2018 21:28:35 +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=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 69B31287A6 for ; Sun, 8 Apr 2018 21:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=IXQ084jLKrylt0ThD6J2E8DzzmejAMyMgY2iABB/xZE=; b=WQDwBlr9tjIOLhlKJbza3oLtuU qpO5rtFrcIfztmUc4wdlVrw/Z1hNAilhoAQ7GCRpZ8+lp8yLOiFoLXUr3gufckRD/FskAYPKtUfdi 98kvpQg2ZNcZJ6xFMfpFDmYO4iR6BA/nbcDBG0oVnOwaATHMGhhg5LUbHGbGoGHGs3qZTojrS+fcl w5/rAlfwNDK+TNwuoPlZKkVoQUKSO1FzPbF+UaWJ728wM2LPV9InaEyox7BViu2HKmq4fBIB83/H7 vOXYcqxrtq60KPUcylElbUyy9yCL5cCN1cezlBy2CJCtpgUOWneqv1VuVOZYucUpp9eor4Stz7RCi dR1rvnsQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5HrT-0006G4-9g; Sun, 08 Apr 2018 21:28:31 +0000 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5Hr8-0005yV-Uv; Sun, 08 Apr 2018 21:28:12 +0000 Received: by mail-wr0-x244.google.com with SMTP id d19so2906452wre.1; Sun, 08 Apr 2018 14:28:00 -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=zGEZRyIAkxwvuY33Q+8xuuMCQ5hhzIZC6q9uQpxGz8c=; b=Ty3FPy4KOrU1e+tZjrwSDY8WDo6TIjY9etz+WA8AzKB0OBN2UMLYLpJQ+I80Ifpoc6 SBf9hldjEsSc2iOSfe2bBZsi9av8e80PbLFcLObqGdVmux6yRXY2B5PgzY5nWv7s5eyf v9IYLltgTFiExw0HneKrO2E5ddn7BQTgjB45ZA+xXHxVCrpUK4EbblkqgYxX5+6dltka lYqW7zYZfzXAnqSM5QXvyevQo5YvOWqEeuAlFGRKIDRKa3gK9bH2afa3lwo0OMgaS2xf rZgoOCq2MPXTRUqqu1ah7isKzGm0aArdXFpsOWuMjuCfsM0mECsNIGUwxIDEEcK1ESfZ 7Ukg== 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=zGEZRyIAkxwvuY33Q+8xuuMCQ5hhzIZC6q9uQpxGz8c=; b=rX9l/78iT4tKrls5t+2S/Wcy5mBfQhPqNKTiHB5OL5DqcmOJJgG3s42ffJBIAR11z6 Te5aER8g9RgV7mzbTNTTVCHSIOvZMoTpfYapQtCBkpwohlD0MXuLuw32mPS9XbFYhiva bD5+HNCx/58F+Rrk1n4JZiZf9YoiOVyW4+qxNJZ/ma5jS+q87k84NDm4sWH5zGyTqPrx cC2W12vCbcvUkgSAglv+einMxbZX5j7JF8dNFwudZ8vVcAcyNmmYzocljuj+H6ozhLdm u11eitpybxiLAE1O5kmXs85s7cP/AuvqU23BnwVAdHgRlgMxmz4sCBgr1fydUtLCMOqA ALBg== X-Gm-Message-State: AElRT7GX5FgT9/70oUSW42U54nSSKrBDcpvz4Kj3oHBfPPAbGBXAVfG/ 1cMPqWV3q+XnRTkGszZF/WE= X-Google-Smtp-Source: AIpwx4/5a/KEdsT5FAngEGKuosX/Ia9hXIXPl715+qF/hw36af68p/f5QS3fxlL0rM+37pZOEAGwwA== X-Received: by 10.223.184.35 with SMTP id h32mr25834973wrf.209.1523222879048; Sun, 08 Apr 2018 14:27:59 -0700 (PDT) Received: from blackbox.darklights.net (p5B056562.dip0.t-ipconnect.de. [91.5.101.98]) by smtp.googlemail.com with ESMTPSA id j21sm18476370wrb.49.2018.04.08.14.27.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Apr 2018 14:27:58 -0700 (PDT) From: Martin Blumenstingl To: linux-usb@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH usb v5 2/6] usb: core: split usb_phy_roothub_{init,alloc} Date: Sun, 8 Apr 2018 23:27:39 +0200 Message-Id: <20180408212743.22934-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180408212743.22934-1-martin.blumenstingl@googlemail.com> References: <20180408212743.22934-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180408_142811_015072_7CE43EE3 X-CRM114-Status: GOOD ( 17.57 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: d-gerlach@ti.com, eric@anholt.net, j-keerthy@ti.com, stern@rowland.harvard.edu, chunfeng.yun@mediatek.com, yamada.masahiro@socionext.com, linux-mediatek@lists.infradead.org, linux-rpi-kernel@lists.infradead.org, matthias.bgg@gmail.com, linux-amlogic@lists.infradead.org, kishon@ti.com, Martin Blumenstingl , rogerq@ti.com MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.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 --- 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);