From patchwork Thu Jun 21 15:17:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timur Tabi X-Patchwork-Id: 10480035 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 B8D2F602CB for ; Thu, 21 Jun 2018 15:19:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6603280CF for ; Thu, 21 Jun 2018 15:19:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AF262902D; Thu, 21 Jun 2018 15:19:58 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable 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 3E4D1280CF for ; Thu, 21 Jun 2018 15:19:58 +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=JP28Hm7S06iLMrA6wxYrAaTkfqxzE2jddwqJNMjSPlQ=; b=khQbuKiFwObx2M175iKmrJklyr v+o+oQUzhUK7Gg1NaxT+k8P9B0cF14cJVWpxHL+M+LTS/XpsX7NYhsz+LBW+NmHgfWaKB4YYYbAAq 3Gd/ODrxEafE1IWbFUSYYFbdfizHdE10l2EH6D3YOFiKh9WgIbNAqONG5GYyIljCpn8IXEmTLbsnG XntoZdxIXyIjTlXvKbMZYEapVyyHtt3P3FvbYR8SFHyp150tB/9FmSEKuz+OAaQJ9jfl43PgWJrYf zeu/MyMDxgEnIrysBq6gNj/syggGxMJyAampQd9d+GYDQlamEuGcggGX4pJ8Qdnny06N4je2axeDf gSFkFPaw==; 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 1fW1NG-0000tJ-N3; Thu, 21 Jun 2018 15:19:50 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fW1Lg-00009f-6v for linux-arm-kernel@lists.infradead.org; Thu, 21 Jun 2018 15:18:47 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 191F560AD8; Thu, 21 Jun 2018 15:18:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1529594282; bh=C/ESjEBul0hkfDWrjUFBa9/oOtKwiJKB2Rs3smLPwg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QgjnPfOVbqhyyHHqSyLwQ+lRX6uV7Esq0Ag5UKvNwdWEU7tZav/gOwO9TTMJ4IbNM aVmIwpuH7StmZTQ72QeIOuS6zEswPvd6r/EOOIg306Ktxw6I5vFkKrK6J2fW+D92Xv F10EVOMWXh5xdA1RmpQSOiP6IcKgZpOARlVPMgOE= Received: from timur-ubuntu.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: timur@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 9013C60376; Thu, 21 Jun 2018 15:18:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1529594281; bh=C/ESjEBul0hkfDWrjUFBa9/oOtKwiJKB2Rs3smLPwg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LSfxIdNlUZh4YoPh12Mu2kL8zfYMkcXqYY+Cev7HxZpG17+fzGg0OeCKrfpqOecxe cFrIa+R/MG1358ku9tKlUZM8Omhdxyhu9HWlBXWxGNwhjIhM+JtutzIOgzzoiBIfXB zWf+hJUjnneB2eCWJzHMEwBFDTIl65C7pnW2mV0o= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 9013C60376 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=timur@codeaurora.org From: Timur Tabi To: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, vinod.koul@linaro.org, Matt Mackall , swboyd@chromium.org, linux-arm-msm@vger.kernel.org, timur@kernel.org Subject: [PATCH 2/2] hwrng: msm: add ACPI support Date: Thu, 21 Jun 2018 10:17:56 -0500 Message-Id: <1529594276-12210-2-git-send-email-timur@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1529594276-12210-1-git-send-email-timur@codeaurora.org> References: <1529594276-12210-1-git-send-email-timur@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180621_081812_330548_375E5FAA X-CRM114-Status: GOOD ( 16.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: timur@codeaurora.org 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 Add support for probing on ACPI systems, with ACPI HID QCOM8160. On ACPI systems, clocks are always enabled, the PRNG should already be enabled, and the register region is read-only. The driver only verifies that the hardware is already enabled never tries to disable or configure it. Signed-off-by: Timur Tabi --- drivers/char/hw_random/msm-rng.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/drivers/char/hw_random/msm-rng.c b/drivers/char/hw_random/msm-rng.c index 44580588b938..f34713d23d77 100644 --- a/drivers/char/hw_random/msm-rng.c +++ b/drivers/char/hw_random/msm-rng.c @@ -20,6 +20,7 @@ #include #include #include +#include /* Device specific register offsets */ #define PRNG_DATA_OUT 0x0000 @@ -186,16 +187,32 @@ static int msm_rng_probe(struct platform_device *pdev) if (IS_ERR(rng->base)) return PTR_ERR(rng->base); - rng->clk = devm_clk_get(&pdev->dev, "core"); - if (IS_ERR(rng->clk)) - return PTR_ERR(rng->clk); - rng->hwrng.name = KBUILD_MODNAME; - rng->hwrng.init = msm_rng_init; - rng->hwrng.cleanup = msm_rng_cleanup; rng->hwrng.read = msm_rng_read; spin_lock_init(&rng->lock); + /* + * ACPI systems have v2 hardware. The clocks are always enabled, + * the PRNG register space is read-only, and the PRNG should + * already be enabled. + */ + if (has_acpi_companion(&pdev->dev)) { + u32 val; + + val = readl(rng->base + PRNG_CONFIG); + if (!(val & PRNG_CONFIG_HW_ENABLE)) { + dev_err(&pdev->dev, "device is not enabled\n"); + return -ENODEV; + } + } else { + rng->clk = devm_clk_get(&pdev->dev, "core"); + if (IS_ERR(rng->clk)) + return PTR_ERR(rng->clk); + + rng->hwrng.init = msm_rng_init; + rng->hwrng.cleanup = msm_rng_cleanup; + } + ret = devm_hwrng_register(&pdev->dev, &rng->hwrng); if (ret) { dev_err(&pdev->dev, "failed to register hwrng\n"); @@ -211,11 +228,22 @@ static int msm_rng_probe(struct platform_device *pdev) }; MODULE_DEVICE_TABLE(of, msm_rng_of_match); +#if IS_ENABLED(CONFIG_ACPI) +static const struct acpi_device_id msm_rng_acpi_match[] = { + { + .id = "QCOM8160", /* v2 PRNG */ + }, + {} +}; +MODULE_DEVICE_TABLE(acpi, msm_rng_acpi_match); +#endif + static struct platform_driver msm_rng_driver = { .probe = msm_rng_probe, .driver = { .name = KBUILD_MODNAME, .of_match_table = of_match_ptr(msm_rng_of_match), + .acpi_match_table = ACPI_PTR(msm_rng_acpi_match), } }; module_platform_driver(msm_rng_driver);