From patchwork Tue Feb 21 20:26:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9585565 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 242BB600CA for ; Tue, 21 Feb 2017 20:27:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 078B7205A4 for ; Tue, 21 Feb 2017 20:27:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EDD74237A5; Tue, 21 Feb 2017 20:27:01 +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=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 7B41A205A4 for ; Tue, 21 Feb 2017 20:27:01 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8KxyyW+YjfiVeceVdz3xMCppWx0aqDpMxvFUWJIxhn0=; b=EKsO2xCtCrraYG v8Pcp5LEFVssz8PQPqRiTYJHDfXa7c60TnVh6uOlYi8tXMNXFr1qHYlNrCIUHsedhVOZuDOQIw2Dv iZXOQT+lzt1dCei4yxeFce540bvUtb1HsrWd+QX1pocXg4EV/SQAGFq239qqr00HkrpbdhDD346CB vEe6ZDYOEYk+x9Maqdnxv57VdbgbeSGIRaB3dHBoQAKDKHUYEL5/IsYg4t6nrnL1x5kaLEj9WuUGn 5nl0TFh3vo/JVtf0DS30pifX0YYl4NzMe/OUkEtA+HrdWkzchBdptbiHlgUzePtU682TGlCClLdFH zoSIKFB2IeZ11ctwSRTg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cgH1S-0002qY-D8; Tue, 21 Feb 2017 20:26:54 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cgH1P-0002nm-BI for linux-amlogic@lists.infradead.org; Tue, 21 Feb 2017 20:26:53 +0000 Received: by mail-wm0-x244.google.com with SMTP id c85so21709046wmi.1 for ; Tue, 21 Feb 2017 12:26:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=+QhxF+ud699hnp+6IuyrAdsIqNmByVtMYaNqQC5/GXY=; b=tBBC0e7dSBypLVxfZcKHQcuiAu2C0AqV5NidwQzQYZzJr2DSU40CIfU3rSka8SgKkq 4Xaiu8y0oFBwc2XtFrpI802F1VcLksfEkHnlmLv6reViaOlFLN5TbK7w9TU7kxSKiXCF d7jVJULpWSb+q5QjaLIayjIgNl+b925gQ67YD2aN0Xahzo56MiHtt0rKrrj1mLYMG1Ee 4/q5+GN0ToceUS5dASV+wyTYR4XIq/E8nmQYqBnonTX6FDLwROdshTaTa1BzTG+egTbg Z1zhTWOVq0AoNjj2yFU4hSsGxIlcNQtpCA6INasDe38XcojOs7L+9ozY5JNizooufllZ hKNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=+QhxF+ud699hnp+6IuyrAdsIqNmByVtMYaNqQC5/GXY=; b=ZH9ZjExOoCuo5MbhKI4FGeoSxL60APKpUOKGjmdi9vUbp8kXso8TG2WT15PR+T/tdf UQEvDsFXvkck7Ze6XsB0JhtInhMQZs3o6GJh0evSs8tLZnQmBK7ODCNwW2ih91pFYFcN 7HBTN73u5ICMJSnO9hdbm11tJ1XkRU6Ya2naYyW7ZcBrcJiyrIg9hQFuLzt38TpQFY5E z2q92mK/UMjAx+8+ZcCgVDJyWf3oZtyJHtl3OSyjx6NsoYqYtpiRfgORYe0MKBszHkXL MKc3+xCf5vzAK/G6e0BBkef8XI2n/9LphKZIKyvii2/aSuvHLPOhwA0+LsfPnK0zA7cq X8gA== X-Gm-Message-State: AMke39n5gnhChPPU4mnjW/NLhUKjgLzA5VlRn/Nnr9igQpVtzYuRvGzUhfUZR7PdM7OFxA== X-Received: by 10.28.148.66 with SMTP id w63mr16118124wmd.43.1487708789708; Tue, 21 Feb 2017 12:26:29 -0800 (PST) Received: from ?IPv6:2003:c6:ebdc:4000:bd34:27cb:45ef:f408? (p200300C6EBDC4000BD3427CB45EFF408.dip0.t-ipconnect.de. [2003:c6:ebdc:4000:bd34:27cb:45ef:f408]) by smtp.googlemail.com with ESMTPSA id r19sm30080864wrr.44.2017.02.21.12.26.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Feb 2017 12:26:29 -0800 (PST) Subject: [PATCH v2 3/3] hwrng: meson: add clock handling to driver To: Jerome Brunet , Kevin Hilman , Herbert Xu , Neil Armstrong , linux-amlogic@lists.infradead.org, linux-crypto@vger.kernel.org, Stephen Boyd , Michael Turquette References: From: Heiner Kallweit Message-ID: <989cf7bf-b7ea-0b41-510b-6eab403f0185@gmail.com> Date: Tue, 21 Feb 2017 21:26:20 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170221_122651_548727_23CBD782 X-CRM114-Status: GOOD ( 10.66 ) 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: devicetree@vger.kernel.org, linux-clk@vger.kernel.org Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add handling of RNG0 clock to the driver. Signed-off-by: Heiner Kallweit --- v2: - consider that clock is optional - use managed call to clk_disable_unprepare to ensure that cleaning up is done in the right order if driver is removed --- drivers/char/hw_random/meson-rng.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/char/hw_random/meson-rng.c b/drivers/char/hw_random/meson-rng.c index 119d6984..2e23be80 100644 --- a/drivers/char/hw_random/meson-rng.c +++ b/drivers/char/hw_random/meson-rng.c @@ -62,6 +62,7 @@ #include #include #include +#include #define RNG_DATA 0x00 @@ -69,6 +70,7 @@ struct meson_rng_data { void __iomem *base; struct platform_device *pdev; struct hwrng rng; + struct clk *core_clk; }; static int meson_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) @@ -81,11 +83,17 @@ static int meson_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) return sizeof(u32); } +static void meson_rng_clk_disable(void *clk) +{ + clk_disable_unprepare(clk); +} + static int meson_rng_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct meson_rng_data *data; struct resource *res; + int ret; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) @@ -98,6 +106,20 @@ static int meson_rng_probe(struct platform_device *pdev) if (IS_ERR(data->base)) return PTR_ERR(data->base); + data->core_clk = devm_clk_get(dev, "core"); + if (IS_ERR(data->core_clk)) + data->core_clk = NULL; + + if (data->core_clk) { + ret = clk_prepare_enable(data->core_clk); + if (ret) + return ret; + ret = devm_add_action_or_reset(dev, meson_rng_clk_disable, + data->core_clk); + if (ret) + return ret; + } + data->rng.name = pdev->name; data->rng.read = meson_rng_read;