From patchwork Sat Mar 24 14:21:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10306061 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 4E072600F6 for ; Sat, 24 Mar 2018 14:21:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DA3A292E7 for ; Sat, 24 Mar 2018 14:21:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31CB8292E9; Sat, 24 Mar 2018 14:21:57 +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=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham 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 A12FA292E7 for ; Sat, 24 Mar 2018 14:21:56 +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=7qqgDV+5Itp2/KuW+nCnNYlgIw1SoVTCP2BSK+CXPaQ=; b=PLj8d7T7of4Vjd1nwiiMwL3U2d jbx67t3vGD0m68Ijp73byz68/+YH2erZvkZPFz8kb5WT4UkxlNO4WUH07PlWrC8c7Z9jLkPxGmN6p p6WcC2AjgwBxmkrvMNYeqcRvKLWH0vMk7FBt15EZ6KNOqEsaB1BJBtGbd8XO7u57wb22U5n133nMz EZPc1rtj7ZNzy0Xpr/frqFaoc7gIPrNNIAcABdlVTlzKUNPWs/PRSCj9KmxV9wDBQkgcmWOKpguCj ji9Fb4rZGaqmSI8d+IZxVAaL/FRb5rY+IViRC6uOChmcv1mjdR7OmUp4Bsw1lyCUxCpPqI0x0l9fE QiRYiyPA==; 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 1ezk3O-0005sr-IL; Sat, 24 Mar 2018 14:21:54 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ezk3F-0005nU-Mr; Sat, 24 Mar 2018 14:21:48 +0000 Received: by mail-wm0-x244.google.com with SMTP id v21so8213797wmc.1; Sat, 24 Mar 2018 07:21:35 -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=nGT97DaCp02xMBMUH2JjITy0fnqEAwaS0z5LtU8ANpI=; b=eGbu0spHf/Rknwz/rUbeQVOyvIEFri2i879y86e3UVm5KhodftdtpXgkYZI/p0fyQv 0Ft5ClkW1boWE1WDSN2Uy94E1hMVlbCozjn7qZQ5p+xi2EzB9DIxD6VpQ0u5nnDaVcpG e3hlV2P3380tatigFhyxIDlxWXnARl38JBZlZh6In0ixlxw/TiIzrwQ0AHEDNgwqysYy TMcgtI81+7HPxsawyt7lRk4myA4LqN9DSs7jhb3d3M83TcbqiWfLQSFln0iXyZ6Kso/q WtpslFp0w4GnaSywurVP/ktGM0OX5V9jDsoUhCLNsh5mVLCPdrG+EF/FZY30BOLicbYB RuXQ== 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=nGT97DaCp02xMBMUH2JjITy0fnqEAwaS0z5LtU8ANpI=; b=uQfAEVHCQPpsd5yfffvuqwr7jDyBaSge61jWwqB8U7cyjVBL6+wAjs57+WtIgsNqWi zSboD292NPqs9cYybkbx63LgkBClpkjYVC7JXdXowNHxHCOQ3OtJg0DL6yjeNIOpgw2C 2LE7e2oRilVl9aU3eS9kbiCoSLa98nJ0MgksGFXtlev9qk5XG+ARMXEjx/iIIq0oEJGh c/5AgP/6bQguVE5Cv5AlyxxWCCh+3q7oI8w14Ha+y3TDNK2JOnUlmnJSp5z5nlLRofhg GIIvtgZgOKlMsgcgRzZYqAD742HVggm0XKdwc89pylppQezmZ/rVyeZBmg4hDvnwVQfr 9Vnw== X-Gm-Message-State: AElRT7HHoSkkHhjOgIL9snAwoX+0BkLLSnHtJhQZksUXWA/3av4t34sj fI+NMychFRg+0pBa6Q8gCaw= X-Google-Smtp-Source: AIpwx4+tzoQOGP4NcBnerjp6vsBixWogyU78UWUNccr5N6qKj79kyRZyRPG8KpJ5DeSj5in1L5JoHQ== X-Received: by 10.28.10.195 with SMTP id 186mr9077928wmk.136.1521901293887; Sat, 24 Mar 2018 07:21:33 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD7416504613646B2A165589A.dip0.t-ipconnect.de. [2003:dc:d741:6504:6136:46b2:a165:589a]) by smtp.googlemail.com with ESMTPSA id n64sm11132247wmd.11.2018.03.24.07.21.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 07:21:33 -0700 (PDT) From: Martin Blumenstingl To: linux-usb@vger.kernel.org Subject: [RFC usb-next v2 1/2] usb: core: split usb_phy_roothub_{init, alloc} Date: Sat, 24 Mar 2018 15:21:20 +0100 Message-Id: <20180324142121.8618-2-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180324142121.8618-1-martin.blumenstingl@googlemail.com> References: <20180324142121.8618-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180324_072145_820871_AC3145D8 X-CRM114-Status: GOOD ( 17.53 ) X-BeenThere: linux-mediatek@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, Martin Blumenstingl , gregkh@linuxfoundation.org, stern@rowland.harvard.edu, chunfeng.yun@mediatek.com, linux-mediatek@lists.infradead.org, j-keerthy@ti.com, matthias.bgg@gmail.com, linux-amlogic@lists.infradead.org, kishon@ti.com, rogerq@ti.com MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=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 --- drivers/usb/core/hcd.c | 10 +++++++--- drivers/usb/core/phy.c | 51 +++++++++++++++++++++++++------------------------- drivers/usb/core/phy.h | 4 +++- 3 files changed, 35 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..d1861c5a74de 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,9 @@ 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; roothub_entry->phy = phy; @@ -56,11 +43,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 +53,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 +86,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);