From patchwork Wed Aug 21 10:59:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Dahl X-Patchwork-Id: 13771244 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 3440FC52D6F for ; Wed, 21 Aug 2024 11:09:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7R+I3eWvRMVL77L44Gt897N18NavS4Wc92V6aQKadT8=; b=d4RxBnGm9K1N5JskBs/HLEGl9R OYny3sm37ZX5V0j89XMt6w9OckaBuDGYDALX5Hs+ENo2CS5qLNiSmIp9q90g7MTrRN2glMciOoI0q ihms2Gc5k6wbXSxkZ9uMsyVuxO1kY8xfRX8E4avk4yAeUwZe+awnnK8LhNq8uY1IytLNesrENJUS+ ZaizXImKCllQaTNG+YiHXXI4ZecR4hvW+ZWipx4ALKlKd3XPvYADxZvS7ZTqfZzzcD99vLaGRsyll ZMGLiJnsS9n5M7Ez8NDbFC1b4TNTgUKIoS4DFV6smKU9JlypOWYZ3imDrpRSNppQugFpG4hhZ3RJT Y6SW1tmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgjD2-00000008awD-0tU7; Wed, 21 Aug 2024 11:09:00 +0000 Received: from mail.thorsis.com ([2003:a:e28:26e4::10]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgj4N-00000008XXt-41Wh for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 11:00:11 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 8F3A11483DF3; Wed, 21 Aug 2024 12:59:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thorsis.com; s=dkim; t=1724237999; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=7R+I3eWvRMVL77L44Gt897N18NavS4Wc92V6aQKadT8=; b=KVp4uR8Ro7N7VsYnYCe7XQW9iovUZvzIxkjmraWg6QtT5tIdFvmg1TaDL2MdPL5cco68jN nQWP5krf94zjpxKBG/OF5ZZkvbJ4mkLHaZebnUVJ1k4QIpc1jCnj3ERK0O4thIb2bJMHhq j3HJBWWtGCGna5vefOmbNA/TMj6GlsJnBRDWRrrR0lU1l7z6pFRYusz/b++dYL4IJj08ay 0/YQmSPtbGij9AmB6NNTPT5pRZ1vXHBXwHh/hZc/PC3FvNTKThDGiOjedgeufu5lPbUJ0y yjTDVY7XPPJYoDXOkECg5awvIbh02hRaqhAWPNbmDbS84fs6UndhWNDiwaNHYA== From: Alexander Dahl To: Claudiu Beznea Cc: Christian Melki , Srinivas Kandagatla , linux-arm-kernel@lists.infradead.org (moderated list:MICROCHIP OTPC DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v1 12/12] nvmem: microchip-otpc: Expose UID registers as 2nd nvmem device Date: Wed, 21 Aug 2024 12:59:43 +0200 Message-Id: <20240821105943.230281-13-ada@thorsis.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240821105943.230281-1-ada@thorsis.com> References: <20240821105943.230281-1-ada@thorsis.com> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_040004_909673_007D106A X-CRM114-Status: GOOD ( 13.78 ) 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 For SAM9X60 the Product UID x Register containing the Unique Product ID is part of the OTPC registers. We have everything at hand here to just create a trivial nvmem device for those. Signed-off-by: Alexander Dahl --- drivers/nvmem/microchip-otpc.c | 41 +++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/microchip-otpc.c b/drivers/nvmem/microchip-otpc.c index 047ca5ac6407..52af4c137204 100644 --- a/drivers/nvmem/microchip-otpc.c +++ b/drivers/nvmem/microchip-otpc.c @@ -45,6 +45,9 @@ #define MCHP_OTPC_NAME "mchp-otpc" #define MCHP_OTPC_SIZE (11 * 1024) +#define MCHP_OTPC_UID_NAME "mchp-uid" +#define MCHP_OTPC_UID_SIZE 16 + /** * struct mchp_otpc - OTPC private data structure * @base: base address @@ -249,6 +252,16 @@ static int mchp_otpc_init_packets_list(struct mchp_otpc *otpc, u32 *size) return 0; } +static int mchp_otpc_uid_read(void *priv, unsigned int offset, + void *val, size_t bytes) +{ + struct mchp_otpc *otpc = priv; + + memcpy_fromio(val, otpc->base + MCHP_OTPC_UID0R + offset, bytes); + + return 0; +} + static struct nvmem_config mchp_nvmem_config = { .name = MCHP_OTPC_NAME, .type = NVMEM_TYPE_OTP, @@ -258,6 +271,15 @@ static struct nvmem_config mchp_nvmem_config = { .reg_read = mchp_otpc_read, }; +static struct nvmem_config mchp_otpc_uid_nvmem_config = { + .name = MCHP_OTPC_UID_NAME, + .read_only = true, + .word_size = 4, + .stride = 4, + .size = MCHP_OTPC_UID_SIZE, + .reg_read = mchp_otpc_uid_read, +}; + static int mchp_otpc_probe(struct platform_device *pdev) { struct nvmem_device *nvmem; @@ -303,8 +325,25 @@ static int mchp_otpc_probe(struct platform_device *pdev) mchp_nvmem_config.size = size; mchp_nvmem_config.priv = otpc; nvmem = devm_nvmem_register(&pdev->dev, &mchp_nvmem_config); + if (IS_ERR(nvmem)) { + dev_err(&pdev->dev, + "Error (%ld) registering OTP as nvmem device\n", + PTR_ERR(nvmem)); + return PTR_ERR(nvmem); + } - return PTR_ERR_OR_ZERO(nvmem); + mchp_otpc_uid_nvmem_config.dev = otpc->dev; + mchp_otpc_uid_nvmem_config.priv = otpc; + + nvmem = devm_nvmem_register(&pdev->dev, &mchp_otpc_uid_nvmem_config); + if (IS_ERR(nvmem)) { + dev_err(&pdev->dev, + "Error (%ld) registering UIDxR as nvmem device\n", + PTR_ERR(nvmem)); + return PTR_ERR(nvmem); + } + + return 0; } static const struct of_device_id __maybe_unused mchp_otpc_ids[] = {