Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp422904pxb; Wed, 6 Oct 2021 07:50:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4kmUN5xRk76W12XoujXJIwJOkgNX0BD8j1EI+pXR90H4SRjP9Xu3iwznDy+T2xiIM0zf+ X-Received: by 2002:a50:d80d:: with SMTP id o13mr35088180edj.204.1633531811698; Wed, 06 Oct 2021 07:50:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633531811; cv=none; d=google.com; s=arc-20160816; b=AZQqnnvweC+gVd8z/541husEZY2RF2/oeLeIcZRc6NwfY7cCYgcad2y/Whf/lhX3pX wB0wCPm8Y636pQY6QaZIlQ4iDhlv7Y7DoflQhcUY+hGvKKrL+m2DdrEkReIyIbZNasGF de+Z82FKv7bDRiJnE6Fj5p2LtqELxLbNiCT481MxumQsGqhX1uW6494DaM97gorDzKaE uNBwXiR5hmtyXmksf2EPizKDN2iwig31zQMBKYRMBUOS7B9xAjgzpFEcnr0qUkGStDVZ uFoWUNjzeUk19w1VJsfHoeP2pAbUSIEPthN/OfykLQa5ADYEIV3RDX8JoTQAdzZuxDHk IhmA== 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=8FsxkcadEsB0KvX5OVsbse2HvnnQsUaBCJfhIJAhFGE=; b=VXIeaCr0fu9KsFyLa653Y9gMH1Mq01rLbAcft8BPP34qK4/IVpLiKMQBUwStG/5FVR FiSCSyX/YHPi/t/f6/Bp57kDNv9NhZuwikFCME7FR+90QEt0LIA/1aHBEzHpNXoLRdRj atm9W98fy3q4WFfIPcvbtjqZUIdIyxNCADS3FfDMe8/FGErHMSlKRiWsSM0vj2UmTyiA rAUNDUDWxikR822fbHYYCg/hQ1x2k6azpoGr4eqKvQTC8BkKLnWEd0DDJ+pkgQoeCFCM ahqrqtHiGEwaA/KT3h3RA8OGF+8OoG2fWLynTr3p3ejkiMjtPf4KoToM7SgG29nMxK3a otmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xaNyii8N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m17si37421066edc.78.2021.10.06.07.49.47; Wed, 06 Oct 2021 07:50:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xaNyii8N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239093AbhJFOtj (ORCPT + 99 others); Wed, 6 Oct 2021 10:49:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239070AbhJFOtg (ORCPT ); Wed, 6 Oct 2021 10:49:36 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D30E0C061749 for ; Wed, 6 Oct 2021 07:47:43 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id e12so9635732wra.4 for ; Wed, 06 Oct 2021 07:47:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8FsxkcadEsB0KvX5OVsbse2HvnnQsUaBCJfhIJAhFGE=; b=xaNyii8NWBMrYt0y7RytBqtx7mpDLu3DIUxxFb2gClMrfocpLaeqz8NgZHztKH7Cfm oZSCGAPxDSerTf+6ZyRxDbhSR7GDiBAnfOk33Guot4OOiNluxL05DQqosYXvpoMUvBgU /BKVvL18gx9uK2LiF/BSfSrNu8ySctgIrbRT3J3cg2LacVRJaGcnqaIuVn8Uutos0uAZ E95s5CriUQD+SJ9tI1SS3XBQvkNB6hnIS+0BHRtwX21aJLynvmLrVCsPWbxklpZrBPob +Tv4oIQD8XU1VqREP8McNI+n2VbR1AoqpEAZ/Gxjqa6mJSnK7reF7aAYx1dXf+IoMO7Y NzZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8FsxkcadEsB0KvX5OVsbse2HvnnQsUaBCJfhIJAhFGE=; b=bS/R6+gv6nB7PTK2XXdqbtF6yG5Mma2zyes8u6v0JI7iBFpKyQo20XlQiH55kNeykF gRHAGKuY16/wbkLFOiHRjbsRIx0KPKCQwZ2PX11bolmtBqRgA1zoLJfOfPrnhDYHDYaq o2wT8Dd6cL6LlIKr3JRcftGNn4SbdWOKIqe0e5pMBtuj9hL9O2oQuRDrP8LxyVgbWWLy oqsjsU869i6yBA2qG9SAXJfS+IWe4MpXRc9ON2HdxQqbYgww1dsLJxL/16p1dgjrVoUH MC+qLXpletW1g1KJM1dn2eqLCgZCQRscpq0NkVKzrpjL8RCrGbHzMAVtXBDh8Qp2jo/F +b3w== X-Gm-Message-State: AOAM531ic/b2YsBWyP/gUnAwRDTwhKLoRTW5iidQ0blLGvrVMRw2mqCS xcQmimn2HFpBlI6md2/X0I0UdA== X-Received: by 2002:a05:6000:18aa:: with SMTP id b10mr1971598wri.270.1633531662509; Wed, 06 Oct 2021 07:47:42 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id z18sm14589340wro.25.2021.10.06.07.47.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Oct 2021 07:47:42 -0700 (PDT) From: Srinivas Kandagatla To: srini@kernel.org Cc: linux-kernel@vger.kernel.org, qiangqing.zhang@nxp.com, linux-imx@nxp.com, Srinivas Kandagatla Subject: [PATCH 3/3] nvmem: imx-ocotp: add support for post processing Date: Wed, 6 Oct 2021 15:47:29 +0100 Message-Id: <20211006144729.15268-4-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211006144729.15268-1-srinivas.kandagatla@linaro.org> References: <20211006144729.15268-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add .cell_post_process callback for imx-ocotp to deal with MAC address, since MAC address need to be reversed byte for some i.MX SoCs. Signed-off-by: Srinivas Kandagatla Signed-off-by: Joakim Zhang --- drivers/nvmem/imx-ocotp.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index 08f41328cc71..89fd4d3eb649 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -97,6 +97,7 @@ struct ocotp_params { unsigned int bank_address_words; void (*set_timing)(struct ocotp_priv *priv); struct ocotp_ctrl_reg ctrl; + bool reverse_mac_address; }; static int imx_ocotp_wait_for_busy(struct ocotp_priv *priv, u32 flags) @@ -221,6 +222,25 @@ static int imx_ocotp_read(void *context, unsigned int offset, return ret; } +static int imx_ocotp_cell_pp(void *context, const char *id, unsigned int offset, + void *data, size_t bytes) +{ + struct ocotp_priv *priv = context; + + /* Deal with some post processing of nvmem cell data */ + if (!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]); + } + } + + return 0; +} + static void imx_ocotp_set_imx6_timing(struct ocotp_priv *priv) { unsigned long clk_rate; @@ -468,6 +488,7 @@ 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 = { @@ -530,6 +551,7 @@ static const struct ocotp_params imx8mq_params = { .bank_address_words = 0, .set_timing = imx_ocotp_set_imx6_timing, .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT, + .reverse_mac_address = true, }; static const struct ocotp_params imx8mm_params = { @@ -537,6 +559,7 @@ static const struct ocotp_params imx8mm_params = { .bank_address_words = 0, .set_timing = imx_ocotp_set_imx6_timing, .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT, + .reverse_mac_address = true, }; static const struct ocotp_params imx8mn_params = { @@ -544,6 +567,7 @@ static const struct ocotp_params imx8mn_params = { .bank_address_words = 0, .set_timing = imx_ocotp_set_imx6_timing, .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT, + .reverse_mac_address = true, }; static const struct ocotp_params imx8mp_params = { @@ -551,6 +575,7 @@ static const struct ocotp_params imx8mp_params = { .bank_address_words = 0, .set_timing = imx_ocotp_set_imx6_timing, .ctrl = IMX_OCOTP_BM_CTRL_8MP, + .reverse_mac_address = true, }; static const struct of_device_id imx_ocotp_dt_ids[] = { -- 2.21.0