From patchwork Mon Feb 20 17:49:29 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: 59580 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1439031wrn; Mon, 20 Feb 2023 10:00:01 -0800 (PST) X-Google-Smtp-Source: AK7set+y+IrB7r8cF6r/hocxmWzx5mlkEeN5di04855pAwJpKj37aF2Cugi6FRou/trjuAEIEoft X-Received: by 2002:a17:902:ecc1:b0:19a:8680:ba86 with SMTP id a1-20020a170902ecc100b0019a8680ba86mr2052937plh.50.1676916001289; Mon, 20 Feb 2023 10:00:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676916001; cv=none; d=google.com; s=arc-20160816; b=WHUgg6W8rfrFG1s/h6vgS69XaDq3I5bTAWe88hfHT+KybWzdi1d9wk29iR1bKxjU91 OEc1vjd3z6Rq5rfelJ5ge4FobnLpg8ssZWhzldm7BrOT1pGQ8ojmLJWyxDec3+LLmZwI EPR5IZ8a+dWqoDawBDV2W0F3IJ3+50+sx8XUy0pg0/3Ld+8qXybc17HcPbKpPz0ccg2n i5zG8wUiWExWtpMU4VfNIUCxla736a4tEiL9heO8yUINI+zzekGN+9c/1LiYOwGdu9Aw hIn6uyBvEmEhIV20in+5dhBPP3ZN7MiLCV4vL7D5I3Oj6T3pWxnXJrAJTZG1AMrNRxnj Zvug== 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=BFDJegi5uTYwdkZXr42aNBwxRD/vvuGUyK4suapHfLE=; b=bCKpP/DOhgIpKReunBdTUH/GR6GCjPjgTKLMuTL39dksJ4ykpvSqCCIzDioYeDVHSd ejCPpC97FTo2yUuML/vS0BL7B7pMC6n7isxkfYrCWpCZNecqIoIwYZ0eYF/n63f4R7Pk jSuivgOrQqJOQQidd112UDVuanpclktW4FQuKb79rGsukQ5DTAAItw8xvDAhNN/q4Ms5 rQIhQdLVM94YLsE2JmJtSqEE7nd9PKfPBvJ9Kfqf2UgiqfGqcAul0hPtwp2c8ncOpGdL L7fo/yqznMCSiJMv9A5fxbrrRpUhTiWIB06e3gJ7eKHH1jlSQN5staMf30j4L6gGNTbE 4MRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pNp4F+WC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a11-20020a170902eccb00b00196be53dde9si4046774plh.114.2023.02.20.09.59.48; Mon, 20 Feb 2023 10:00:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pNp4F+WC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232466AbjBTRtt (ORCPT + 99 others); Mon, 20 Feb 2023 12:49:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232467AbjBTRtr (ORCPT ); Mon, 20 Feb 2023 12:49:47 -0500 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 714371EBF8; Mon, 20 Feb 2023 09:49:42 -0800 (PST) Received: by mail-lj1-x234.google.com with SMTP id u15so3007718ljo.5; Mon, 20 Feb 2023 09:49:42 -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=BFDJegi5uTYwdkZXr42aNBwxRD/vvuGUyK4suapHfLE=; b=pNp4F+WC3OYbrn5ogI5MzgDCG/M7DsThUP1JveuJQchDIP5pr5gJjrONCAEm5MCqJ6 0mBiEWGY46umgI+IlFdYRaS5MTRSpJUFNUe+xvnDAl+8vDi99y8Q2A1AZG1xHQzYz2x3 hR6HOaZ1fdpqnGjv9Sm46+HtmEffVa4Be2BeaVcJw/5LHmzf61gj0dY+KkLayoJkSyNa oyfyQCi+vLKoWyAqNd6ZSxZ6+z2jrLoW9p3dBXdVm+zc6ddqsGfAp8zkX7utEKpQ4MIp KpYDrFrUx4v9+fRGS/N3FEAHWFq1KIKJ9pr6VVjYuhjomasoHeKG0VDVwE94iWwKTEMh QHTQ== 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=BFDJegi5uTYwdkZXr42aNBwxRD/vvuGUyK4suapHfLE=; b=qVswGQXkdPrisN07Wf5/Pne/rsAxnN/4m2H5JhVXr8m1l80tVNuhPUHmvfmwRgQyiN lJjaKD8YOiKW+J4qSHXGD2M/XjdE5187TtvmUZDWQk0oxecx84S5wbxvf4bDJyCvOpCn 5lg0R4GB0ZNNkdanKAvIl6hUj4ITvt1Y1MwePiaZJj5VnyJobXssDwbLBNoTJO2tkEQ6 +cmrIrKdWQN3hVyCuOdMv3NZ9qkjDWConViukkdyNp6jd1/AhB2v5+LfjX5SmpMZkmqw vi/vXOV0eOHz9YcyUkQ4Z8jbGAzdAe8tadmgY+HAGHOqDbrjLc13XLWZjqav0ZYwFOrU xNhA== X-Gm-Message-State: AO0yUKXMCCu04YnOl9GGcIlBw58wpwMNPbVl7tN2fRv805i6zihFXja5 oFz6bvoQyCWUVCyBeFI/y5c= X-Received: by 2002:a05:651c:10aa:b0:28e:a8aa:6f95 with SMTP id k10-20020a05651c10aa00b0028ea8aa6f95mr832063ljn.8.1676915380580; Mon, 20 Feb 2023 09:49:40 -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 u22-20020a2e9f16000000b0029353491df6sm294695ljk.48.2023.02.20.09.49.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 09:49:40 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski Cc: Matthias Brugger , Kunihiko Hayashi , Masami Hiramatsu , linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V3 1/2] dt-bindings: nvmem: mmio: new binding for MMIO accessible NVMEM devices Date: Mon, 20 Feb 2023 18:49:29 +0100 Message-Id: <20230220174930.7440-2-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220174930.7440-1-zajec5@gmail.com> References: <20230220174930.7440-1-zajec5@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758373872882112654?= X-GMAIL-MSGID: =?utf-8?q?1758373872882112654?= From: Rafał Miłecki Content of some NVMEM devices can be read using MMIO. Some of them (probably very few though) may be also programmable that way. Add generic binding to allow describing such hardware. This *doesn't* apply to any more complicated devices that need more complex interface e.g. for writing. While such devices could be supported for reading purposes by the same driver - they should get their own binding. This binding will gain even more usability once we fully support NVMEM layouts (describing content of NVMEM devices in an independent way). Signed-off-by: Rafał Miłecki Reviewed-by: Rob Herring --- V3: Make it clear this binding should NOT be used for more complex devices --- .../devicetree/bindings/nvmem/mmio.yaml | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/nvmem/mmio.yaml diff --git a/Documentation/devicetree/bindings/nvmem/mmio.yaml b/Documentation/devicetree/bindings/nvmem/mmio.yaml new file mode 100644 index 000000000000..9ca96b7a4856 --- /dev/null +++ b/Documentation/devicetree/bindings/nvmem/mmio.yaml @@ -0,0 +1,50 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/nvmem/mmio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MMIO access based NVMEM + +description: | + This binding describes simple NVMEM devices with content that can be accessed + using MMIO (memory-mapped I/O access). + + More complex devices that support any other access than a simple memory + mapping should use a custom binding. In such cases this binding's compatible + should NOT be used even as a fallback. + + This binding is designed to describe just an NVMEM content access method. The + way of handling actual content should be described independently (on top of + this binding). + +maintainers: + - Rafał Miłecki + +allOf: + - $ref: nvmem.yaml# + +properties: + compatible: + const: mmio-nvmem + + reg: + maxItems: 1 + + reg-io-width: + description: | + The size (in bytes) of the IO accesses that should be performed + on the device. + enum: [1, 2, 4, 8] + +required: + - reg + +unevaluatedProperties: false + +examples: + - | + nvmem@10000 { + compatible = "mmio-nvmem"; + reg = <0x10000000 0x10000>; + }; From patchwork Mon Feb 20 17:49: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: 59581 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1439469wrn; Mon, 20 Feb 2023 10:00:50 -0800 (PST) X-Google-Smtp-Source: AK7set/sQGJ+ddujlw7TO3jI60TUJ87zn4cKGEJJhHM/sILmg8SRXbUeL9UBIfeSzlSZZQJfGOMe X-Received: by 2002:a17:906:9692:b0:8b1:3c99:76c0 with SMTP id w18-20020a170906969200b008b13c9976c0mr6283155ejx.64.1676916050433; Mon, 20 Feb 2023 10:00:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676916050; cv=none; d=google.com; s=arc-20160816; b=Eb9kPLgFpTV642e4yE8ltGrcj4lnvrKrq2DbmmhKBKKOC6/ie/A3rCrS+NuKiLgezs l8Qapg6tXl2p1WaYqpqPAnAs3a15CBk3djp6FfDyZNFX+OVBoe706xc2SaHDfIvnfhef VlN8XBuF7sbYPlXU/uC+voc2hN14WiPC+CSlcfgoRnD1rHRnxzyTKy8WQo8J7HkxJuUm xE6IgaJOK5Mc1n05wmauFaVaPPASiaH9ht30DzHFIxTajz4uap0+qpNOlEt5+EcAMbCW pDFRFa8oWIKr6Zar7HEn7cEKblkt7mRTvS+KWl2vjxUxXFkvZ8KoYkNHXnUSuPiI1OuO JJFw== 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=JhssXeqm+u6yl3pDx1ZAyAVMMEL8ZFFRhcJTQvtxCBI=; b=skInvdL6jpdvoZVdo1M5X/ZT+DdxcGEYGp6pMk3C/5mwHIb+0cVVlWHLJdcE9J7aCx JfDJMGhNPNIesICcungK7M24VAPXIlHIGOnzXIC9PmDoLFKau37tjAHvVMRCbbQjL3/r WNwE5Vp2/8mepNS0rM8oSSUODM/VfD0AcYAK06EczmpHLAFlPgI9axs3XcI9uxVsTz9t zrdr5+5hyYemV4QzQRB+Wj/YOxDHPmDd7hqdGIOTCTuPdfDJaFh6F2v6pv7yO/AOjkDQ cvCWkCK+2svZ8GVUyV8d2WBz7SVLVFefHxx729zBmoO675qNViYYCxkl0EswdJxzybo8 gfCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hSUvjOtM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fx16-20020a1709069e9000b008d14edd7552si4285281ejc.538.2023.02.20.10.00.26; Mon, 20 Feb 2023 10:00:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hSUvjOtM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232478AbjBTRtv (ORCPT + 99 others); Mon, 20 Feb 2023 12:49:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232473AbjBTRts (ORCPT ); Mon, 20 Feb 2023 12:49:48 -0500 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B5A41BAD5; Mon, 20 Feb 2023 09:49:44 -0800 (PST) Received: by mail-lj1-x22a.google.com with SMTP id b13so2911609ljf.6; Mon, 20 Feb 2023 09:49:44 -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=JhssXeqm+u6yl3pDx1ZAyAVMMEL8ZFFRhcJTQvtxCBI=; b=hSUvjOtME4HgSAQKag2+v/BtCpNfKz8hzOD5kqu+liLI1J5DuDG1cxlX9HU0ru5HyJ zH8YRWlNlsUQbzDU19zR0XPL+wan25qyhe5DOVV1Hu4xB5v5m0LgViiEvxHh1OWVlQ0O NsflWNicEeMBKj5DDTWTAyM+A/O9Q/Fe6tXslTKRq4++1sRvgUZbfSJPpx0IKiHo6oh/ nVgUmmDbiSZZ4l2V6BOOt/xkAxUgSNcfl+5kfnkD5VZYV5nj4f3SZ/YxU8X+Vx/I9p91 dIjoEC3tFzjfnYF/Fxnhj7DwnuHVvxzvBwscxKsi3Lnmwmz8r81KxPn3p3k5R8GlR9xE o0OA== 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=JhssXeqm+u6yl3pDx1ZAyAVMMEL8ZFFRhcJTQvtxCBI=; b=dFB6YB++j0sUXrHdQGr97KOaBt6mxQdwWWBu0CrOwinLZKSK5NMYV1d/xTGZlSj5IB 8PTvueCe5FDCKZCN++6Kp/CEb43WYjPvffjOBoFgpjrcYXFw0BNCrd1aU+9CjvuRaEwN 0fl/R82OnKXHAkTtyjrD9UZyjC57z+rRFTqjEJB7FFFbYwMf3L2WvzViefKy/OCLFe1K 15tm5tsWJP78lD4DK8EBAC+fXcm5zY5sU79Rqg8I/QoSUKm1rGeC4tPDF8mPKj5zKn6S dV2rIVYAArrO1HgT+obsBqIMPT6rhQJYwadu0zUlF/I2BR7FaSO8hmtxb9TwgB6r3q3q jXag== X-Gm-Message-State: AO0yUKUdtQpGRoGNMQhPGRnO81EK14+w77S0XSqDObZEHLR4YmXBBRHd S26Mz6lHEDdVNLBukDgAyi4= X-Received: by 2002:a05:651c:1505:b0:293:341f:a62 with SMTP id e5-20020a05651c150500b00293341f0a62mr962640ljf.21.1676915382724; Mon, 20 Feb 2023 09:49: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 u22-20020a2e9f16000000b0029353491df6sm294695ljk.48.2023.02.20.09.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 09:49:42 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski Cc: Matthias Brugger , Kunihiko Hayashi , Masami Hiramatsu , linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V3 2/2] nvmem: add generic driver for devices with MMIO access Date: Mon, 20 Feb 2023 18:49:30 +0100 Message-Id: <20230220174930.7440-3-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220174930.7440-1-zajec5@gmail.com> References: <20230220174930.7440-1-zajec5@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758373923969053371?= X-GMAIL-MSGID: =?utf-8?q?1758373923969053371?= From: Rafał Miłecki Some NVMEM devices can be accessed by simply mapping memory and reading from / writing to it. This driver adds support for a generic "mmio-nvmem" DT binding used by such devices. One of such devices is Broadcom's NVRAM. It's already supported (see NVMEM_BRCM_NVRAM) but existing driver covers both: 1. NVMEM device access 2. NVMEM content parsing Once we get support for NVMEM layouts then existing NVRAM driver will get converted into a layout and generic driver will take over responsibility for data access. That's why it claims "brcm,nvram" (conditionally for now). Signed-off-by: Rafał Miłecki --- V3: Support "reg-io-width", basic writing & "brcm,nvram" string --- drivers/nvmem/Kconfig | 10 ++++ drivers/nvmem/Makefile | 2 + drivers/nvmem/mmio.c | 125 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 drivers/nvmem/mmio.c diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 6dec38805041..189ea85bd67d 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -166,6 +166,16 @@ config NVMEM_MICROCHIP_OTPC This driver enable the OTP controller available on Microchip SAMA7G5 SoCs. It controls the access to the OTP memory connected to it. +config NVMEM_MMIO + tristate "MMIO access based NVMEM support" + depends on HAS_IOMEM + help + This driver provides support for NVMEM devices that can be accessed + using MMIO. + + This driver can also be built as a module. If so, the module + will be called nvmem-mmio. + config NVMEM_MTK_EFUSE tristate "Mediatek SoCs EFUSE support" depends on ARCH_MEDIATEK || COMPILE_TEST diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 6a1efffa88f0..767a9db2bfc1 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -35,6 +35,8 @@ obj-$(CONFIG_NVMEM_MESON_MX_EFUSE) += nvmem_meson_mx_efuse.o nvmem_meson_mx_efuse-y := meson-mx-efuse.o obj-$(CONFIG_NVMEM_MICROCHIP_OTPC) += nvmem-microchip-otpc.o nvmem-microchip-otpc-y := microchip-otpc.o +obj-$(CONFIG_NVMEM_MMIO) += nvmem-mmio.o +nvmem-mmio-y := mmio.o obj-$(CONFIG_NVMEM_MTK_EFUSE) += nvmem_mtk-efuse.o nvmem_mtk-efuse-y := mtk-efuse.o obj-$(CONFIG_NVMEM_MXS_OCOTP) += nvmem-mxs-ocotp.o diff --git a/drivers/nvmem/mmio.c b/drivers/nvmem/mmio.c new file mode 100644 index 000000000000..e247c943eea2 --- /dev/null +++ b/drivers/nvmem/mmio.c @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 Rafał Miłecki + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct mmio_nvmem { + void __iomem *base; + u32 io_width; +}; + +static int mmio_nvmem_read(void *context, unsigned int offset, void *val, size_t bytes) +{ + struct mmio_nvmem *priv = context; + u32 *dst32; + u16 *dst16; + u8 *dst8; + + if (priv->io_width && WARN_ON(bytes % priv->io_width)) + return -EINVAL; + + switch (priv->io_width) { + case 1: + for (dst8 = val; bytes; bytes -= 1, offset += 1) + *dst8++ = readb(priv->base + offset); + break; + case 2: + for (dst16 = val; bytes; bytes -= 2, offset += 2) + *dst16++ = readw(priv->base + offset); + break; + case 4: + for (dst32 = val; bytes; bytes -= 4, offset += 4) + *dst32++ = readl(priv->base + offset); + break; + default: + memcpy_fromio(val, priv->base + offset, bytes); + } + + return 0; +} + +static int mmio_nvmem_write(void *context, unsigned int offset, void *val, size_t bytes) +{ + struct mmio_nvmem *priv = context; + + switch (priv->io_width) { + case 1: + case 2: + case 4: + return -EOPNOTSUPP; + default: + memcpy_toio(priv->base + offset, val, bytes); + } + + return 0; +} + +static int mmio_nvmem_probe(struct platform_device *pdev) +{ + struct nvmem_config config = { + .name = "mmio-nvmem", + .id = NVMEM_DEVID_AUTO, + .read_only = true, + .reg_read = mmio_nvmem_read, + }; + struct device *dev = &pdev->dev; + struct mmio_nvmem *priv; + struct resource *res; + + 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); + + of_property_read_u32(dev->of_node, "reg-io-width", &priv->io_width); + + config.dev = dev; + config.size = resource_size(res); + config.word_size = priv->io_width; + config.stride = priv->io_width; + config.priv = priv; + if (!device_property_present(dev, "read-only")) + config.reg_write = mmio_nvmem_write; + + return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config)); +} + +static const struct of_device_id mmio_nvmem_of_match_table[] = { + { .compatible = "mmio-nvmem", }, + /* Custom bindings */ +#if !IS_ENABLED(CONFIG_NVMEM_BRCM_NVRAM) + { .compatible = "brcm,nvram", }, +#endif + {}, +}; + +static struct platform_driver mmio_nvmem_driver = { + .probe = mmio_nvmem_probe, + .driver = { + .name = "mmio_nvmem", + .of_match_table = mmio_nvmem_of_match_table, + }, +}; + +static int __init mmio_nvmem_init(void) +{ + return platform_driver_register(&mmio_nvmem_driver); +} + +subsys_initcall_sync(mmio_nvmem_init); + +MODULE_AUTHOR("Rafał Miłecki"); +MODULE_LICENSE("GPL"); +MODULE_DEVICE_TABLE(of, mmio_nvmem_of_match_table);