From patchwork Tue Mar 7 16:53:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65733 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2543943wrd; Tue, 7 Mar 2023 09:03:47 -0800 (PST) X-Google-Smtp-Source: AK7set9XBnKJXGdHfMDNQF1CiEVR/LSgePAMLD7K1xdLIxnOxfpGFhjWUT12QCTMjrV1ce8acuza X-Received: by 2002:aa7:d796:0:b0:4ac:d2bc:4695 with SMTP id s22-20020aa7d796000000b004acd2bc4695mr14583246edq.33.1678208627507; Tue, 07 Mar 2023 09:03:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208627; cv=none; d=google.com; s=arc-20160816; b=gLQwTyBe1s7IH3J8dpG/Vo2eWhBIjEku1ftGIAS/r4EbhEPVIK/Cz+NlJsPj/KRbYm qjoALYLTHEL95HwiKk3o1FyFxbhBeE8eu44UikQGFpRGndWiagBTKlkKg0dlEwvtFHjZ vD53NE4q1cu+eeZIM83YR4p/O7M7ZaETcvrctkKeHCJnhmpHryMQGKxlSGIPTE9d4s9d NQdQd2QW+px9JDPCfF/ecafKDkMsbdZvLKGXupF8LYPbO5/JbxBhIzVNWxlh1py/aTO/ Cuue37ytUpR8TYUjWxbNdzV1HolbbxT3g3XfcoNKOVxLf7sxJs64qh8tIpmwFvI6Dr1n uMZw== 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=+8KBJRUvcteGrcXB2dPcvKQXMIPPTo96B4W8ORMytWg=; b=V79vKNxfpabwmO6+iAfbT0lAB+Sr9yllPUWO0EY3MmfpG3KIlnzREVh6i7qJBWgAZN Eoko4nzrYUos/q85BiJeXqKQYgiJQKBKiRuxFHgxvaHDunE7mtMaeO6NcIQVgace57CT j7n00ZYSl1bf0/e+BYRZUkK2dgQXkrulpizrd/RhN6R+s7j7DwFbYOnEsAmaMNrXlB8W S7/y6+fZQjjqLfSOgPm9IVjGLd3duibDHqikg3QtOiKzE7VW8gsqA/GOihxf9z2mZ6JY 8neMfP4HC8DsMAvJ+vQCGIR0eNJJje3Oyt4mlmS+xwPSxIsDWE3j3fV3D2hYiwZIscoM NMEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Yr3FZKIm; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gu25-20020a170906f29900b008d65603e880si858469ejb.583.2023.03.07.09.03.23; Tue, 07 Mar 2023 09:03:47 -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=@bootlin.com header.s=gm1 header.b=Yr3FZKIm; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231298AbjCGQ7t (ORCPT + 99 others); Tue, 7 Mar 2023 11:59:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230496AbjCGQ6M (ORCPT ); Tue, 7 Mar 2023 11:58:12 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F95190096; Tue, 7 Mar 2023 08:54:58 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id B623EC0009; Tue, 7 Mar 2023 16:54:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208096; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+8KBJRUvcteGrcXB2dPcvKQXMIPPTo96B4W8ORMytWg=; b=Yr3FZKImd9D4HbqsfoBk+mm8YZ/3s9YDFloLhooDu8S0DJb9p7XI3IyDJhfleAo+qg35Bi 8/K6+gW/14Vf/d6aLcW+pC00XS2IKd44eMKPluCRRysIVFfQt54WzmosQ3goHCY8TC0k+Z MFpqlpp1klW8YbDHfdetOf5/r7t+oynKqp+8+VzPOb20UNl/SgrvJWyx6gRphzsJtPCoXZ 4vchA9z9vNyXyviwQjM6R8uuyONisbqDI9ZTFLQIdJxM/2lqSRnVXOJZlOwaUKzTdAhd8a yI41jVNW5w2ay/TGDE/7uKUjjj3tTl5u7+H2GoLS7KZGeKSDSrm17r0XM5qbEQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 15/21] nvmem: imx-ocotp: replace global post processing with layouts Date: Tue, 7 Mar 2023 17:53:53 +0100 Message-Id: <20230307165359.225361-16-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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?1759729289630094429?= X-GMAIL-MSGID: =?utf-8?q?1759729289630094429?= From: Michael Walle In preparation of retiring the global post processing hook change this driver to use layouts. The layout will be supplied during registration and will be used to add the post processing hook to all added cells. Signed-off-by: Michael Walle Tested-by: Michael Walle # on kontron-pitx-imx8m Signed-off-by: Miquel Raynal --- drivers/nvmem/imx-ocotp.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index e9b52ecb3f72..ac0edb6398f1 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -225,18 +225,13 @@ static int imx_ocotp_read(void *context, unsigned int offset, static int imx_ocotp_cell_pp(void *context, const char *id, int index, unsigned int offset, void *data, size_t bytes) { - struct ocotp_priv *priv = context; + u8 *buf = data; + int i; /* Deal with some post processing of nvmem cell data */ - if (id && !strcmp(id, "mac-address")) { - if (priv->params->reverse_mac_address) { - u8 *buf = data; - int i; - - for (i = 0; i < bytes/2; i++) - swap(buf[i], buf[bytes - i - 1]); - } - } + if (id && !strcmp(id, "mac-address")) + for (i = 0; i < bytes / 2; i++) + swap(buf[i], buf[bytes - i - 1]); return 0; } @@ -488,7 +483,6 @@ static struct nvmem_config imx_ocotp_nvmem_config = { .stride = 1, .reg_read = imx_ocotp_read, .reg_write = imx_ocotp_write, - .cell_post_process = imx_ocotp_cell_pp, }; static const struct ocotp_params imx6q_params = { @@ -595,6 +589,17 @@ static const struct of_device_id imx_ocotp_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids); +static void imx_ocotp_fixup_cell_info(struct nvmem_device *nvmem, + struct nvmem_layout *layout, + struct nvmem_cell_info *cell) +{ + cell->read_post_process = imx_ocotp_cell_pp; +} + +struct nvmem_layout imx_ocotp_layout = { + .fixup_cell_info = imx_ocotp_fixup_cell_info, +}; + static int imx_ocotp_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -619,6 +624,9 @@ static int imx_ocotp_probe(struct platform_device *pdev) imx_ocotp_nvmem_config.size = 4 * priv->params->nregs; imx_ocotp_nvmem_config.dev = dev; imx_ocotp_nvmem_config.priv = priv; + if (priv->params->reverse_mac_address) + imx_ocotp_nvmem_config.layout = &imx_ocotp_layout; + priv->config = &imx_ocotp_nvmem_config; clk_prepare_enable(priv->clk);