From patchwork Mon Dec 5 14:13:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 9461031 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 F00916022E for ; Mon, 5 Dec 2016 14:15:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E589D22BF1 for ; Mon, 5 Dec 2016 14:15:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA0A124B44; Mon, 5 Dec 2016 14:15:48 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3D97522BF1 for ; Mon, 5 Dec 2016 14:15:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cDu27-0004AP-PE; Mon, 05 Dec 2016 14:14:19 +0000 Received: from mail-wj0-x229.google.com ([2a00:1450:400c:c01::229]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cDu1z-0003yc-8o for linux-arm-kernel@lists.infradead.org; Mon, 05 Dec 2016 14:14:13 +0000 Received: by mail-wj0-x229.google.com with SMTP id v7so291512476wjy.2 for ; Mon, 05 Dec 2016 06:13:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=aRpZ+OxCFZLc0WT9ciyWpyZap897bM+nogdtVbY/NBI=; b=ADMkRz/z+xcEi+pn+igPqzINSOw6ox2J9+rbmz6F1FID6Y7NpOffoYu3uVnb4qLUrA hML1utBTVJ5gOaT/GGxZNnneaS3sDGYsQGSht4iA4dWz2yOMzkJn+t1p5HaUu0G8/uow l2TYRtgW57haY225cyVRS5FNEqGJW1LgaoWoYwUR18/N9eEYIgH6YO+NtjNly3KKo3lY fnYKMSql2Jd+8NMWrGnZp7e3WCAwdSyIcrbsRvBsHi+xptWeYb9V578SY4y3RCYnUgtY kf43tc4AL/tAYIRHn+ZFLN86lHvSf0MZSHzXI2w9BUrqm5YSwiTZHeZedzjNmUi+KwtO HNMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=aRpZ+OxCFZLc0WT9ciyWpyZap897bM+nogdtVbY/NBI=; b=KLxP1eZKmw0ZPOlx6EoqMP+/SPZW3LNCoGIGmI2MCeEv1brf3mGMWlPZJQM+pKAoAw YtfnG0z8VRFLqtgN3y5z4hSv+DeYZPfkH9W6hsLLVYdiAPJLAQ87I7OWAunutoWpbeXb Jo3bKo3mPkYHGUURR/Pl/03SLDxeAT8e+aX5csDRO23+82dvpNDKjTgcpUlIvPzUGKh4 HziJZsQcKVd0ET/Rd84jHN5IauamVI94b8fY/3QBjYZ1lOfTX7xilsJHb0SRbtD39769 4tC/Ab0ec4LTOf304mRDIvj0NEl2mMmMIsDIhsjKNA43hY71wT/m+AGAgEEz4pntkKJV 8l8Q== X-Gm-Message-State: AKaTC01GUuLF3T8Y/yuhJzqWirTW/9EawDLlYSdH8QPa7g2+G3alUU09DgcBzpNfdgkV4dLY X-Received: by 10.194.26.170 with SMTP id m10mr50027766wjg.152.1480947228773; Mon, 05 Dec 2016 06:13:48 -0800 (PST) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id 63sm369553wmg.2.2016.12.05.06.13.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Dec 2016 06:13:48 -0800 (PST) From: Alexandre Bailon To: nsekhar@ti.com Subject: [PATCH v5] ARM: davinci: da8xx: Fix sleeping function called from invalid context Date: Mon, 5 Dec 2016 15:13:44 +0100 Message-Id: <1480947224-26222-1-git-send-email-abailon@baylibre.com> X-Mailer: git-send-email 2.7.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161205_061411_569935_F5D65E37 X-CRM114-Status: GOOD ( 14.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: arnd@arndb.de, ahaslam@baylibre.com, khilman@baylibre.com, Alexandre Bailon , ptitiano@baylibre.com, linux-arm-kernel@lists.infradead.org, david@lechnology.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Everytime the usb20 phy is enabled, there is a "sleeping function called from invalid context" BUG. clk_enable() from arch/arm/mach-davinci/clock.c uses spin_lock_irqsave() before to invoke the callback usb20_phy_clk_enable(). usb20_phy_clk_enable() uses clk_get() and clk_enable_prepapre() which may sleep. Move clk_get() to da8xx_register_usb20_phy_clk() and replace clk_prepare_enable() by clk_enable(). Signed-off-by: Alexandre Bailon --- arch/arm/mach-davinci/usb-da8xx.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/arch/arm/mach-davinci/usb-da8xx.c b/arch/arm/mach-davinci/usb-da8xx.c index b010e5f..f62f9c2 100644 --- a/arch/arm/mach-davinci/usb-da8xx.c +++ b/arch/arm/mach-davinci/usb-da8xx.c @@ -22,6 +22,8 @@ #define DA8XX_USB0_BASE 0x01e00000 #define DA8XX_USB1_BASE 0x01e25000 +static struct clk *usb20_clk; + static struct platform_device da8xx_usb_phy = { .name = "da8xx-usb-phy", .id = -1, @@ -158,24 +160,16 @@ int __init da8xx_register_usb_refclkin(int rate) static void usb20_phy_clk_enable(struct clk *clk) { - struct clk *usb20_clk; int err; u32 val; u32 timeout = 500000; /* 500 msec */ val = readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG)); - usb20_clk = clk_get(&da8xx_usb20_dev.dev, "usb20"); - if (IS_ERR(usb20_clk)) { - pr_err("could not get usb20 clk: %ld\n", PTR_ERR(usb20_clk)); - return; - } - /* The USB 2.O PLL requires that the USB 2.O PSC is enabled as well. */ - err = clk_prepare_enable(usb20_clk); + err = clk_enable(usb20_clk); if (err) { pr_err("failed to enable usb20 clk: %d\n", err); - clk_put(usb20_clk); return; } @@ -197,8 +191,7 @@ static void usb20_phy_clk_enable(struct clk *clk) pr_err("Timeout waiting for USB 2.0 PHY clock good\n"); done: - clk_disable_unprepare(usb20_clk); - clk_put(usb20_clk); + clk_disable(usb20_clk); } static void usb20_phy_clk_disable(struct clk *clk) @@ -285,11 +278,19 @@ static struct clk_lookup usb20_phy_clk_lookup = int __init da8xx_register_usb20_phy_clk(bool use_usb_refclkin) { struct clk *parent; - int ret = 0; + int ret; + + usb20_clk = clk_get(&da8xx_usb20_dev.dev, "usb20"); + ret = PTR_ERR_OR_ZERO(usb20_clk); + if (ret) + return ret; parent = clk_get(NULL, use_usb_refclkin ? "usb_refclkin" : "pll0_aux"); - if (IS_ERR(parent)) - return PTR_ERR(parent); + ret = PTR_ERR_OR_ZERO(parent); + if (ret) { + clk_put(usb20_clk); + return ret; + } usb20_phy_clk.parent = parent; ret = clk_register(&usb20_phy_clk);