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: 9585563 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 A6AF1600CA for ; Tue, 21 Feb 2017 20:26:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A78A28610 for ; Tue, 21 Feb 2017 20:26:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F12E28635; Tue, 21 Feb 2017 20:26: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=-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 6A03F28610 for ; Tue, 21 Feb 2017 20:26:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751294AbdBUU0c (ORCPT ); Tue, 21 Feb 2017 15:26:32 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33900 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751161AbdBUU0b (ORCPT ); Tue, 21 Feb 2017 15:26:31 -0500 Received: by mail-wm0-f66.google.com with SMTP id c85so21709047wmi.1; 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=qiBfNsi6FIWQf6p0k5GueWc4E1h22XDizn5zaKar/um5HCQEJcBnRpTJMLak8n68vG 9kxGAX1C4Qak4OOAqjEHlU67mH1kqJajFuN6JSs+BJRHkrsxPo/xc22uUfMN0/6CU1Zf M0U63rM70tR9So6X+1IEWbEDSoJAGdbtdN/zZzoZrRz2/iFikLAoRs2lxUhqioswCDZW 2MNI4wrqIjG6KZheX25YtXj8CQjdVdBxRa4FpacMAay3OiUbddUwshlyO4ewUdHYcz6U XtSDrXpwLc1ELmFxfvq+FV+ocBxTK+1KkKzMgKg8N1jFr6jlYW3vrJsfIJGWxmj1rgeu Z7HA== X-Gm-Message-State: AMke39mYbQLxXqE8EthtK2VD1N1CfBs/phVdoGgaQikKO+xT73PZG8t2hF82VJ7pgSyafQ== 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: Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org 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: 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 --- 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;