From patchwork Wed Mar 8 15:31:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66299 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp404007wrd; Wed, 8 Mar 2023 07:35:32 -0800 (PST) X-Google-Smtp-Source: AK7set+Y1YkcO6+1SHqvtWImvBFkt17oXHMhU/SlJr0JbhrBFYbVSPZM4bGJ7eYVAsuQU26opnoQ X-Received: by 2002:a17:902:c407:b0:19e:7490:c93e with SMTP id k7-20020a170902c40700b0019e7490c93emr26058766plk.63.1678289731943; Wed, 08 Mar 2023 07:35:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289731; cv=none; d=google.com; s=arc-20160816; b=ML6Il94ES6MQXidfIZ6u3EC+wy/iZNHHBbQCMWLVCSDPiCRUcyIekh91mN3bB7mksf 0hd2986rF4TF8+xITBLsDuOkKUCOqGx7POfGOQZ7SW59jHKMe0HSasY9W6+RcPyUoa5V EjGd9H/ayITu8rt+/DTs8G76rekpuuIl43mNTCPVyYiMk95aP3gEBJoOWTw+4vLQd7Hx gtOiQEHouN2HJySp17w1AzJRANjJIpWZ8eEebQSgYJXoNnKbapGG0CuC7bUiz3h2wm2d 2m9RAXtfZkYecB6qcsL2U4YhA54/NNJ9OaDnu4gA1a29D6v71wO5EVuA7JsK0il1Kmd7 Ggaw== 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=nG6vQgRR/gmol0kxbPZIEUsI9U7FwZQTwLIYizn6r+wRgxrPYgeJim3IJu4HThx6VP 9o2l0TkXAPCk187YpujTEReQGshk7TcY1mQ8t9gmoem0Xzz3CJbhCDd9+g21pRhX0qBr RBMzU3N7YEL/5/zyJGpaPfHncKphy5+Ew5SBiURCfMdG0oxmGX9ebybpOT7BiHmYnrC9 suWUADasWnJqeG9e+cKsW5Ub2vSFAV4+nu6GQ2mahSMe7d3r37wi6xTGuoPJ85o5WL8p YoyB47jqs4y7PlloDijUdDVQ7X4wTKZjBqt1f9zaGL4srYcChdKrtv+G/G3aTMTDwsfS xuKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=UXr4mxc1; 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 km11-20020a17090327cb00b0019e68e4e472si14358691plb.378.2023.03.08.07.35.14; Wed, 08 Mar 2023 07:35:31 -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=UXr4mxc1; 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 S231951AbjCHPdj (ORCPT + 99 others); Wed, 8 Mar 2023 10:33:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232215AbjCHPc4 (ORCPT ); Wed, 8 Mar 2023 10:32:56 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD61D5D24B; Wed, 8 Mar 2023 07:32:29 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 19777FF80C; Wed, 8 Mar 2023 15:32:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289548; 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=UXr4mxc1WU2zTuHUxkiT/b+F/1Sm4X8kCt2rAXYFwnBjQ/Hyf6T0CnzLDuuFBgIHE4sw/M 0t9tX4L/SGZE10HfBJlbeLiqAcpp0lwC8qvYknzOOKLUql0Yl1xohknLVaIuGI09j0S31E zwOREGgvVF1ULdl4t2bnOQki5Ltd3sAJq6r1QOghNUzjEmizj9FSwLDnjWC4OuKlzbo4v3 QwinXMOPkj80IWcb0eNPwHuAP29M7UpE7OAt4FIKqhW0TZxHy17DJdfxfuF5SwhR4JTUmE zaTsAjZRW/QUPzuj0ftfSGz8o8rH05A//HMPNkjUmUmFs5cziMbmEs3L3PE9Pg== 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 v3 14/20] nvmem: imx-ocotp: replace global post processing with layouts Date: Wed, 8 Mar 2023 16:31:54 +0100 Message-Id: <20230308153200.682248-15-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-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, RCVD_IN_MSPIKE_H2,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?1759814333850109623?= X-GMAIL-MSGID: =?utf-8?q?1759814333850109623?= 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);