From patchwork Wed Feb 22 07:02:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9586297 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 AEE89600CA for ; Wed, 22 Feb 2017 07:02:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94F8C28560 for ; Wed, 22 Feb 2017 07:02:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 872CF28684; Wed, 22 Feb 2017 07:02:47 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 10F8928560 for ; Wed, 22 Feb 2017 07:02:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751613AbdBVHCm (ORCPT ); Wed, 22 Feb 2017 02:02:42 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:34463 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751192AbdBVHCl (ORCPT ); Wed, 22 Feb 2017 02:02:41 -0500 Received: by mail-wr0-f195.google.com with SMTP id 89so290036wrr.1; Tue, 21 Feb 2017 23:02:40 -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=gczTT8GjGPqlJcRNKNeNFV1QEVKg+vwa4HoRNGw7j0M=; b=mIzCsFjbYawv5cCkSJNifMW3OxZmonA0tlIZKVunSXQPj7O4ekkug/HhnBE667ntHn XTainYI6ZAn44OVK4XmaqOqeOSQ6Ujfqkx2u09x8iIsRIHz1pwZWCqiruYTl1YfLINk9 SP4B5UjrtzSSN15nmqiNXfCbTs8Ia3bA8lWoJDsmQSh3i1KsJgDP9mri7mqXupa28fJN 1WXtbt1tnu3KVROBmNuyaq7bC6XNh1ydRgZKwcEIK/FbySgacVMIu8dugOvxe/6Qg4T7 ar/WQP092zqK6U0JYhS0fPxrFw6EhdOOgVn5jckbuQRkwksHXRcphFzWntro5fdYaE6j kWiw== 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=gczTT8GjGPqlJcRNKNeNFV1QEVKg+vwa4HoRNGw7j0M=; b=MmBPTSjkviRdycFFaCwd4vWhsVzai8mTwnAGVPyIJ/xV7XsFEq08rOGVyaMNnv4vWY aY3kzRLosXM2svqtgdl0V2XakpBySwT1wUmgQj5Wzh/nypNPJclHBcB/biM5FTqt0jQ4 p4/JXxO7X5zoPt1SJHbd2pJX3XVzukuqqGCl+pNCxoe0JE+ma1jxpeyIpFAh5ZiS52Ny meyWpAoXdrnNoikS9luVo9avRV96X3qKOdo6or+0TcY5nSL+3ytDtEeuRvV6tROUYVHu 1+eVhtyzaTmuMv2UpQzqTjhNTl6xvMnBiXjMvMTWZYzPH561+krUBK/z6PpgvZM0UmsJ MH0A== X-Gm-Message-State: AMke39lUGYjFNmGuSEFIAGm6nzHL5v1x+s48CzT5hvu8KUO9+QmCIqA83jcfBusnx/FVYQ== X-Received: by 10.223.133.131 with SMTP id 3mr22907553wrt.161.1487746959873; Tue, 21 Feb 2017 23:02:39 -0800 (PST) Received: from ?IPv6:2003:c6:ebdc:4000:4dac:58d5:169c:6ecb? (p200300C6EBDC40004DAC58D5169C6ECB.dip0.t-ipconnect.de. [2003:c6:ebdc:4000:4dac:58d5:169c:6ecb]) by smtp.googlemail.com with ESMTPSA id q1sm830630wmd.6.2017.02.21.23.02.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Feb 2017 23:02:39 -0800 (PST) Subject: [PATCH v3 4/4] 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: <4e2d12e5-f75b-3ac6-a3f7-18e8a8b7283b@gmail.com> Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org From: Heiner Kallweit Message-ID: Date: Wed, 22 Feb 2017 08:02:31 +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: <4e2d12e5-f75b-3ac6-a3f7-18e8a8b7283b@gmail.com> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.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 v3: - no changes --- 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 *data) +{ + clk_disable_unprepare(data); +} + 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;