From patchwork Tue May 11 13:29:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 434207 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp3831881jao; Tue, 11 May 2021 06:29:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx86Pmto4GveoHKakfZzf2EUzjMJJ5mRJq5UvTL5PeTCRFw+oIcyyiah36BXurCw/ckT4VJ X-Received: by 2002:a2e:87cb:: with SMTP id v11mr6405794ljj.113.1620739786968; Tue, 11 May 2021 06:29:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620739786; cv=none; d=google.com; s=arc-20160816; b=EgysnLxqcLqh7+kDQsFIFSz1C9jTWzpqqrifMAeGcLPd3mNMjkuxk2eelHYcY1L4Aj 5iQz5tsBxMbpBAXMu13ABxbSNRvFos8euAOfri3kjoNfnqp++MA63rB35x0BSypbKowK 4iC5Z+hXuG/twtt5qf2gt7DYezaFJHAgzD1QTqH3CIjNxdsBVdTwnjh9lEVp2BsbuyrI hr+vuws3Y/W5rid4dj8bKwA6TdZGwKa07prD6lT3lbkvs4vCWffVxAy9jB1vA5cFcETi DQfzRIOozM/A1rGqxqhL7vzaxn9wNeqXrgMPX+IvFC+HZNiqVgzQrlI4uD6xcuNoCbJQ 4uBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0kH9GejFwRKEAZVnNqAOcSajeuUIKWFZ2mSCj9ztQJ4=; b=gJMNcKtnrIzW3kk/7FYAH1n8lB2FDu/RvhUBopLvqa96ioJqfHcPjBJwpCPqxosJeU 7qMqwDtlkw72JTF6WMq3oaxXfPwsggWCjq2aVcT3XZ1JO0JCZPiLN/eFN+aMN1jShgZE Oa+IdschLZQtfwjkKMe96W6o/AqZTPeV5jCIaxT+YnpeVUSxoCEfkv8ErfJIlDTZbW/T qPApB3l7oPl1eyH5sNIuq1DyTtgsGy/OY7dGaFNNkWl/U4Yy1hbZRfw5qjJ5635BX2p6 2j+HyOQlc1zAUUq4gadbAqhKY6B8njLbFobSZhcea+qkS8h/44YnPWwqme5xFXHn1ucQ 9hhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uAGW7Wix; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c13si22261866ljn.228.2021.05.11.06.29.46; Tue, 11 May 2021 06:29:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uAGW7Wix; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231443AbhEKNaw (ORCPT + 3 others); Tue, 11 May 2021 09:30:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231465AbhEKNas (ORCPT ); Tue, 11 May 2021 09:30:48 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AB46C061574 for ; Tue, 11 May 2021 06:29:41 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id a2so7642182lfc.9 for ; Tue, 11 May 2021 06:29:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0kH9GejFwRKEAZVnNqAOcSajeuUIKWFZ2mSCj9ztQJ4=; b=uAGW7Wix3B9nYc4qK57H9E8J1wBIayQBT+GL+0GNNbSPwzbK+A7EAyH1BrvQYIV/Y/ XNKH1GgPPM/Vf1yTRR39ymsNaZTcsLejdvqVW9NgZ93zgGGtTE/oPlRAPwAmiEaQtMdv whrhHzW0cVNRxx9uRfodABWVSQXNGdskS6NIQBtbbGQB7R4UAs/s62tzAb/82BUQf5Mj dLxZ/w1woEFAziK4bXbX8hkSgkN94bu6+p5inWrH1hGG+/VvE3y6OCOE2G3aTZNLEc2y Bak25Qi+Ayi+SOMgrisdmtqPNZygmR9Isa7MgrL+VDxSV7cX6aiwKT24XmrSIrYYrb3X csbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0kH9GejFwRKEAZVnNqAOcSajeuUIKWFZ2mSCj9ztQJ4=; b=V3UQs4qO32/QUqaMescWDHvRuINjhvjrxYCTLKbVKEsWqRflbwylKJ1FzBIv3vOiaW fk0vMHMwdZbn/No1xTaqIjDzZ1YkvuewnzLgI7rK+tkIM44FVJxyGHKsUhMouszjkdg/ NULmNrjBPmICL4u9SaFEIzZOOI0fLSXjTp8pzgGxX25KhCM0Y7wUoPHDnLhb9CxgK+h1 m/8GW9JL5tPehBMQW1Zlns4lXeYpuqHV06KxXhaHyPmWAK9WZUZ/5vX+ei71WMsYvs8U ZgzXaWjmUCYnuQK7INX3rbiXv+iqoLfOUq+KkTn9QnPzmgfcLqjEkZo2TMToUrf1xWOv DPUQ== X-Gm-Message-State: AOAM5332vppnC1jdONQyEbnKyDIKfLuS4NHHSkpB68hVFT8WNUzVgQlX bwAeK9Ol7qXhtIjhAOqm0jcb+A== X-Received: by 2002:a05:6512:358c:: with SMTP id m12mr20504720lfr.289.1620739779939; Tue, 11 May 2021 06:29:39 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id m4sm3699740ljc.20.2021.05.11.06.29.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 06:29:39 -0700 (PDT) From: Linus Walleij To: Matt Mackall , Herbert Xu , Deepak Saxena Cc: linux-crypto@vger.kernel.org, Arnd Bergmann , Linus Walleij Subject: [PATCH 3/5] hw_random: ixp4xx: Turn into a module Date: Tue, 11 May 2021 15:29:26 +0200 Message-Id: <20210511132928.814697-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511132928.814697-1-linus.walleij@linaro.org> References: <20210511132928.814697-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instead of just initializing always, which will invariably create problems on multiplatform builds, turn this driver into a module and pass a resource with the memory location. The device only exist on the IXP46x so we only register the device for the IXP46x SoC. Cc: Deepak Saxena Signed-off-by: Linus Walleij --- The idea is to apply this through the ARM SoC tree along with other IXP4xx refactorings. Please tell me if you prefer another solution. --- arch/arm/mach-ixp4xx/common.c | 24 ++++++++++++++++++- drivers/char/hw_random/ixp4xx-rng.c | 37 +++++++++++++---------------- 2 files changed, 40 insertions(+), 21 deletions(-) -- 2.30.2 Acked-by: Herbert Xu diff --git a/arch/arm/mach-ixp4xx/common.c b/arch/arm/mach-ixp4xx/common.c index f86c1bf34eea..a10aa14d09b1 100644 --- a/arch/arm/mach-ixp4xx/common.c +++ b/arch/arm/mach-ixp4xx/common.c @@ -237,6 +237,27 @@ static struct resource ixp46x_i2c_resources[] = { } }; +/* A single 32-bit register on IXP46x */ +#define IXP4XX_HWRANDOM_BASE_PHYS 0x70002100 + +static struct resource ixp46x_hwrandom_resource[] = { + { + .start = IXP4XX_HWRANDOM_BASE_PHYS, + .end = IXP4XX_HWRANDOM_BASE_PHYS + 0x3, + .flags = IORESOURCE_MEM, + }, +}; + +static struct platform_device ixp46x_hwrandom_device = { + .name = "ixp4xx-hwrandom", + .id = -1, + .dev = { + .coherent_dma_mask = DMA_BIT_MASK(32), + }, + .resource = ixp46x_hwrandom_resource, + .num_resources = ARRAY_SIZE(ixp46x_hwrandom_resource), +}; + /* * I2C controller. The IXP46x uses the same block as the IOP3xx, so * we just use the same device name. @@ -249,7 +270,8 @@ static struct platform_device ixp46x_i2c_controller = { }; static struct platform_device *ixp46x_devices[] __initdata = { - &ixp46x_i2c_controller + &ixp46x_hwrandom_device, + &ixp46x_i2c_controller, }; unsigned long ixp4xx_exp_bus_size; diff --git a/drivers/char/hw_random/ixp4xx-rng.c b/drivers/char/hw_random/ixp4xx-rng.c index defd8176cb68..8b59aeefd4a4 100644 --- a/drivers/char/hw_random/ixp4xx-rng.c +++ b/drivers/char/hw_random/ixp4xx-rng.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -36,35 +37,31 @@ static struct hwrng ixp4xx_rng_ops = { .data_read = ixp4xx_rng_data_read, }; -static int __init ixp4xx_rng_init(void) +static int ixp4xx_rng_probe(struct platform_device *pdev) { void __iomem * rng_base; - int err; + struct device *dev = &pdev->dev; + struct resource *res; if (!cpu_is_ixp46x()) /* includes IXP455 */ return -ENOSYS; - rng_base = ioremap(0x70002100, 4); - if (!rng_base) - return -ENOMEM; - ixp4xx_rng_ops.priv = (unsigned long)rng_base; - err = hwrng_register(&ixp4xx_rng_ops); - if (err) - iounmap(rng_base); - - return err; -} + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + rng_base = devm_ioremap_resource(dev, res); + if (IS_ERR(rng_base)) + return PTR_ERR(rng_base); -static void __exit ixp4xx_rng_exit(void) -{ - void __iomem * rng_base = (void __iomem *)ixp4xx_rng_ops.priv; - - hwrng_unregister(&ixp4xx_rng_ops); - iounmap(rng_base); + ixp4xx_rng_ops.priv = (unsigned long)rng_base; + return devm_hwrng_register(dev, &ixp4xx_rng_ops); } -module_init(ixp4xx_rng_init); -module_exit(ixp4xx_rng_exit); +static struct platform_driver ixp4xx_rng_driver = { + .driver = { + .name = "ixp4xx-hwrandom", + }, + .probe = ixp4xx_rng_probe, +}; +module_platform_driver(ixp4xx_rng_driver); MODULE_AUTHOR("Deepak Saxena "); MODULE_DESCRIPTION("H/W Pseudo-Random Number Generator (RNG) driver for IXP45x/46x");