From patchwork Fri Jan 27 17:58:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 13119135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D64B3C61D97 for ; Fri, 27 Jan 2023 17:59:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=5cwhxDX8An7oo52g4TgpD4BodiDhRIyGR5FQnbK4e9Q=; b=pRUNHjuCJZesP9 3ZtTqHsdVrosHkBYwEMr/RzM1ZRL7mMQ9/xc7Sq9/ZAC/kGnrgZ8w3DsecK0moRZ6nKEDY15hFVA0 il5xATSFqvedPrPTnTvr2an6Gvp4RUAa5hbsea3FKfDnSJR+JWMt0Hre3aeoNrXpAVQ8N9Onl1Tc+ 1WQTWD6b9tSJYSiqlvhFgt7XNT2NaUXIKKmKR3pLQS2Z+r+H8wMagaodFw0ulo7raO66foVqR+bcA zia4hdd6kSGsMrVub1qNChxB2oEVYdFYf9Pv14hFM4afFBlKBbYwL0Lyh41sbdC82dbHNR1lmErKl i1dKnucm4QZLi62lsXCA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLSzx-00Fxjq-IM; Fri, 27 Jan 2023 17:58:49 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLSzr-00Fxi6-T1; Fri, 27 Jan 2023 17:58:45 +0000 Received: by mail-ej1-x636.google.com with SMTP id m2so15350905ejb.8; Fri, 27 Jan 2023 09:58:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AkTXtXZvSlyW7dhrOhtl54a2x6aLLDzgCZF3MBO2yT4=; b=D45urjwlLOqJ5oEWUBgdQkmsYbSjvXmkD1jToywten5PtNhUD9c8awHO3NHAzmQl46 2Ay7kmFQRTQ8cZlB/KTtUw4eoj7fQiY6CGXuax+YXRwNWSVSiw4757N6Bzx17MKeSu01 k0IehkZHiqWzWobRDv3JZXtZ9P1YJv/2yildPxCacxYjqdIGstP2wDmIpbjXyE9fpa5s nWgSHzL5YwOsqCngAEOjpzySj8hclwm0nOaStOt0f2qt9S/Lo7ONKJyFSQxx8nap4w29 /WrsHxbyuxSN7wYTpEZKcbmqp9cceq8uzA+byVq4aZffRa2Q/oB/VixxOTb4yuoN/UrI kkAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AkTXtXZvSlyW7dhrOhtl54a2x6aLLDzgCZF3MBO2yT4=; b=Tiv6RW4apF7OhdQ7CFhLxkPjg96QfvZ7worE2Et5S1Lv98Dccw9t/iHnxo4/4SKwon uEvYu3ON/TUtVyO7z3hAfdJzH0eN0noydpx9Wgj8/8QO7evwKFboL3sZiIj8GBzPSdVn cEsHE/YyYY/eZFUTomjMtXiyXUHWOL+baJqSOlUT1/0rKY3QtLtDWSu2BOJHotT0uzYG ET7aN5aBRxzO8hR1ZUWyPOsINFmkx70btzhtvTqBqXi2BDl7iroNY6Of3af7IkGhfEZd fIe3wYMniE/IWsXAv+aQWvKPeemldv8P5aVXDN81p5afItY1w+NBqgoAyXXLOJJ67hlr 06+Q== X-Gm-Message-State: AO0yUKUYEOoF27ogEyKgBKyTbtzbcsIKTTA9y9eVeeIv12l/sb3KTBNS jUWx0JDm9lBjWcoyk/8YSyo= X-Google-Smtp-Source: AK7set9YFRj0WFfdzKw45ndnfLNVXHirfZXQPMiwuSaPd2a9SuM0Yn0MHy2+hb2rKxYyINLcUmX2FA== X-Received: by 2002:a17:907:c26:b0:878:53a5:70a1 with SMTP id ga38-20020a1709070c2600b0087853a570a1mr10777796ejc.50.1674842321108; Fri, 27 Jan 2023 09:58:41 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id z22-20020a1709067e5600b0087276f66c6asm2600508ejr.115.2023.01.27.09.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 09:58:40 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski Cc: Michael Walle , devicetree@vger.kernel.org, linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH 1/2] dt-bindings: nvmem: io: new binding for IO accessible NVMEM devices Date: Fri, 27 Jan 2023 18:58:30 +0100 Message-Id: <20230127175831.26753-1-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230127_095843_978097_EF7CA721 X-CRM114-Status: GOOD ( 13.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Rafał Miłecki With the NVMEM layouts binding in place we should now use: 1. NVMEM device access bindings 2. NVMEM content description bindings This binding allows describing NVMEM devices that can be accessed using IO mappings. Signed-off-by: Rafał Miłecki --- .../devicetree/bindings/nvmem/io.yaml | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Documentation/devicetree/bindings/nvmem/io.yaml diff --git a/Documentation/devicetree/bindings/nvmem/io.yaml b/Documentation/devicetree/bindings/nvmem/io.yaml new file mode 100644 index 000000000000..67e0aae9cd94 --- /dev/null +++ b/Documentation/devicetree/bindings/nvmem/io.yaml @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/nvmem/io.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: IO access based NVMEM + +description: | + This binding describes simple NVMEM devices that can be accessed by simply + mapping a predefined IO address. + + It's a generic solution for providing NVMEM content access. The way of + handling actual content may be device specific and can be described using a + proper layout. + +maintainers: + - Rafał Miłecki + +allOf: + - $ref: nvmem.yaml# + +properties: + compatible: + const: io-nvmem + + reg: + maxItems: 1 + +unevaluatedProperties: false + +examples: + - | + nvmem@10000 { + compatible = "io-nvmem"; + reg = <0x10000000 0x10000>; + }; From patchwork Fri Jan 27 17:58:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 13119136 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A33C0C61DA4 for ; Fri, 27 Jan 2023 18:00:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wfxEc+kzRlwswtxoOdI1ARNqOkGlyTpVv1WdktKNjHU=; b=eP0I1oX3JxLArJ CGvwg6p8IUxGJFElQx91PhQG8mPO7b9+8UZcsWdbNwjFKD3dq3Vgrw6sMoB9rAMnG+v0tQH+ydDQV lPdImyE/UbGduIkpXRBXXIINA1K0dDmBLkPl6AxtdXPcHS+ScOZPo6YHLKrWBhgBPaKv6MKEFGhdN fLxauxot8m6EB76me7YcUny0XWGYDW38taFVE/WVix6vXfz/dtvXnvYUefQkxYAdEcbDZFYdP/sAx 3aYfvn/HuGn+hS/dZOniZO50fyGlDY+jYvg+lKivo3ZQCFldNnY1/N52ZhR2r1xNDzQMhX3i97upX ObjU3PwSf3czkIWQRZig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLT08-00Fxm1-Dq; Fri, 27 Jan 2023 17:59:03 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLSzt-00FxiE-6C; Fri, 27 Jan 2023 17:58:46 +0000 Received: by mail-ed1-x531.google.com with SMTP id u21so5441363edv.3; Fri, 27 Jan 2023 09:58:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=17/xEWC1WmOjlte8h0eDRTmEFdiv+lS1lWx2rWU4nVc=; b=lXG0lVpDyWFmskbnUS03gA72O+I5FXCzECuk+XOYf33HOHpv1AvKHBp9VBTv52jA+W GRxq7EP4pkvXeZYbXpRaMUJGxqtrDItw0c1t0Fij7ny/38Pm8a0Ex94EEkQZwYvwyCJn VBnFdRJbGmNfyBH3XZ6Obni3BhSmC4Tc+QLIx97O1rUBmIPG5vRn8YkVKRIIPN+NgZ+O x8/MHATBonft0FENTqEz2wZcWPywNNLy7DwbFFf6ywJHVSxVsp/mbhPmfy2T4iqyCM63 MVfnBzjA3GOMIfg7WPnzSZd/QRPqty4Vg9iOtDIlAi3hHcOUykPfjqhQDs213I+6dS+c Rkvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=17/xEWC1WmOjlte8h0eDRTmEFdiv+lS1lWx2rWU4nVc=; b=cW+/xQkH+zDUqhqkFbONNc6VQKEk/WI3+xqu9XDUolAg1kKUfH5LrzZg/lEPPrxu5l BXEg0x75+TPCF0ZCU2GkT0PSTvbV/9CmjrWA5AqfmimaxB9OZcUg+XN3kHMWIxjewUip IsyJKzneKGLV212y6ucAT6ADiaXvSvy86sZDnAKtcK4sXv9ipzfShfO8dozTdDphv8M0 rwpqe795PCoAO0tzjN3tCEPRJ/D522NObhf+u40dEqM/McwGWip26z3gKS2z9fW4ZOtZ 5sVwRPFOsnNyQc8LR5aZyeCEhPHdzqrkZlSevhGBh5eQ/DzunptNHssgOy6AQerC+rNY 4ojg== X-Gm-Message-State: AFqh2krPKq3aX8MHoITyo2J4fvfAgDio4ao57CmYJojv7C+tTihCEuPI RvjZUjvvGRklJ4E6wz37PBw= X-Google-Smtp-Source: AMrXdXthBjfeJGbjwTfS/yY7ImMNDD+PXI0nFRdpjGlUGxb66VhdMue8cgJPy/yV/1yZEzlOg/ya0g== X-Received: by 2002:aa7:cc81:0:b0:47e:eaae:9a5b with SMTP id p1-20020aa7cc81000000b0047eeaae9a5bmr41321458edt.42.1674842322849; Fri, 27 Jan 2023 09:58:42 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id z22-20020a1709067e5600b0087276f66c6asm2600508ejr.115.2023.01.27.09.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 09:58:42 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski Cc: Michael Walle , devicetree@vger.kernel.org, linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH 2/2] nvmem: add generic driver for devices with I/O based access Date: Fri, 27 Jan 2023 18:58:31 +0100 Message-Id: <20230127175831.26753-2-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127175831.26753-1-zajec5@gmail.com> References: <20230127175831.26753-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230127_095845_253760_C5B72214 X-CRM114-Status: GOOD ( 20.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Rafał Miłecki With nvmem layouts in place we should now work on plain content access NVMEM drivers (e.g. IO one). Actual NVMEM content handling should go to layout drivers. Signed-off-by: Rafał Miłecki --- drivers/nvmem/Kconfig | 7 ++++ drivers/nvmem/Makefile | 2 ++ drivers/nvmem/io.c | 79 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 drivers/nvmem/io.c diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 789729ff7e50..e77bfe6eb52e 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -90,6 +90,13 @@ config NVMEM_IMX_OCOTP_SCU This is a driver for the SCU On-Chip OTP Controller (OCOTP) available on i.MX8 SoCs. +config NVMEM_IO + tristate "IO access based NVMEM support" + depends on HAS_IOMEM + help + This driver provides support for NVMEM devices that can be accessed + using I/O mapping. + config NVMEM_JZ4780_EFUSE tristate "JZ4780 EFUSE Memory Support" depends on MACH_INGENIC || COMPILE_TEST diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 442f9a4876a5..82db0a89c4d6 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -20,6 +20,8 @@ obj-$(CONFIG_NVMEM_IMX_OCOTP) += nvmem-imx-ocotp.o nvmem-imx-ocotp-y := imx-ocotp.o obj-$(CONFIG_NVMEM_IMX_OCOTP_SCU) += nvmem-imx-ocotp-scu.o nvmem-imx-ocotp-scu-y := imx-ocotp-scu.o +obj-$(CONFIG_NVMEM_IO) += nvmem-io.o +nvmem-io-y := io.o obj-$(CONFIG_NVMEM_JZ4780_EFUSE) += nvmem_jz4780_efuse.o nvmem_jz4780_efuse-y := jz4780-efuse.o obj-$(CONFIG_NVMEM_LAN9662_OTPC) += nvmem-lan9662-otpc.o diff --git a/drivers/nvmem/io.c b/drivers/nvmem/io.c new file mode 100644 index 000000000000..307526fda036 --- /dev/null +++ b/drivers/nvmem/io.c @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 Rafał Miłecki + */ + +#include +#include +#include +#include +#include +#include +#include + +struct io_nvmem { + void __iomem *base; +}; + +static int io_nvmem_read(void *context, unsigned int offset, void *val, size_t bytes) +{ + struct io_nvmem *priv = context; + u8 *dst = val; + + while (bytes--) + *dst++ = readb(priv->base + offset++); + + return 0; +} + +static int io_nvmem_probe(struct platform_device *pdev) +{ + struct nvmem_config config = { + .name = "io-nvmem", + .reg_read = io_nvmem_read, + }; + struct device *dev = &pdev->dev; + struct resource *res; + struct io_nvmem *priv; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + + config.dev = dev; + config.priv = priv; + config.size = resource_size(res); + + if (!device_property_present(dev, "read-only")) + dev_warn(dev, "Writing is not supported yet"); + + return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config)); +} + +static const struct of_device_id io_nvmem_of_match_table[] = { + { .compatible = "io-nvmem", }, + {}, +}; + +static struct platform_driver io_nvmem_driver = { + .probe = io_nvmem_probe, + .driver = { + .name = "io_nvmem", + .of_match_table = io_nvmem_of_match_table, + }, +}; + +static int __init io_nvmem_init(void) +{ + return platform_driver_register(&io_nvmem_driver); +} + +subsys_initcall_sync(io_nvmem_init); + +MODULE_AUTHOR("Rafał Miłecki"); +MODULE_LICENSE("GPL"); +MODULE_DEVICE_TABLE(of, io_nvmem_of_match_table);