Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp424768pxb; Wed, 6 Oct 2021 07:52:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQYjFtjKzHJuoc9yG61XH4JqfGKUQ4nZyYAniedHQl7eVpCwOgsduCyb9qknvB+dJgZSV9 X-Received: by 2002:a17:906:1901:: with SMTP id a1mr33457130eje.129.1633531955892; Wed, 06 Oct 2021 07:52:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633531955; cv=none; d=google.com; s=arc-20160816; b=eSTzN79fbgL6DkyvB1r7cZ0HthHpiTX6mEiCAy1iZwdGZC5idSResIiCXkups4prgh tXgItpwXdNnt22saZB6lmIsieADtl5J6I+yIz014s7qj3qnz+fzV/fOhAFVyl/vwg36Q EBst+JES5XHcduXGoR2OyCHfs1Vrmt7a0nf/StbYAe7w3qPIqVDTINRFi/27yPbvozmf bvE+QJ2ILgzFhuq8viLxbtQiJJx5bneV/YAZiFLUNJHykgLrOhjywAThNSfzSHY+taog LPSjWr5MZPMZjb/P4rXeGiuAyX7/NBNIgL9x4LrvsfGd6Bc20nCDNEOWBH5g6MbPmUR4 C3fQ== 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=iaPDGFDXlBzajv88h+tMAL1sMQfhj6LEIZT5x3IDzr0=; b=YZjtIipRI6+00ko9my8OUfRwAv6eMG7IepRxg8D5NBX77MC6PZ0ZUDURTQxM1CzgCl MflBMGZJv0Rt77fkTPazlM5hAWaidfK5GC+tfMkYVQevp9m9H+7ZTmgl0ABJDlJr5dlk tUbp4QMjsY3dV2atrPA9YO7vOUOMCIg1pws6p2KCOt+FjAvs9dQZRcfUREwvpdZbmQUE oAfob0hhiIEVfNSbnp18orCi4emBkk1o7mV6kFJYkUPxoot79Oo4WQO+4JOu/J84EPo4 3kj2tBr6q4IjeUW6LPpHCjIBK22tz2ScDXuikAzR+63Bn9BASkHQKuBRKHLLmTHOySff Wb+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T3PR6JXg; 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 28si22644115ejb.18.2021.10.06.07.52.09; Wed, 06 Oct 2021 07:52:35 -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=T3PR6JXg; 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 S239077AbhJFOth (ORCPT + 99 others); Wed, 6 Oct 2021 10:49:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239047AbhJFOtf (ORCPT ); Wed, 6 Oct 2021 10:49:35 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06AF7C061749 for ; Wed, 6 Oct 2021 07:47:42 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id k7so9506354wrd.13 for ; Wed, 06 Oct 2021 07:47:42 -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=iaPDGFDXlBzajv88h+tMAL1sMQfhj6LEIZT5x3IDzr0=; b=T3PR6JXg6Wn8WiTrKJSBX3xMc2ueX8a2a8ZKdsJRFYWnLdwmAF88qLkCiqEYywAty9 EhF7xxERYSIDe7gKR/5oy/Zxfm7B5+NdHIxghE4Hi9gOqCXKCWCQs+erp2YO8aZmyrDk 5PT3hoTs35ILQ+DGuFSl0wDoxiYIYPxfBpz/OpVsXULIQsLbWaPhYTRPUVAy/i0J+/+2 vamcOf7vAk7p1qDoLY0iMgBciDQw8DPpTQ/eR578pYjbhoZg8o4sLz8graRKn/wxQa+V bOj7zO9VjAVMqMrlzx4lvd1G9+cSVJ9C2pwAfkSLNkXfE+0enypjMZxGdN20bGTpPJFN //Qg== 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=iaPDGFDXlBzajv88h+tMAL1sMQfhj6LEIZT5x3IDzr0=; b=kJz+5AErlVVlBYNTHVdSgfHT2usvy1MVnLXOElnJ0CUCN9g9aqO8M4eesscFlxNeLg rlUuH+OtYERhaLsktUiLG318VA6yBAcgp4wW1OlxfZC8V4bn5yvLriY29lhEuqXbd626 0jFeVRqP9E55r6FmvPNAtm2r2CJFbOvsrBYaksh5lRBarIH3URtyxw3UH7Ld6vmu3KED ElKvyag+0lxTqIbsU3ZLl4XvE+obu8Icb8Ldk6EURlJrBZ3SW2vK69Ow0QOwVvl+UImr H7BAlfETJue6TXaervjPLSFO0GHKY7LXOFu/ZveVBgekLbCPyeQsxBvLoVwNu4fbgOo2 OeeQ== X-Gm-Message-State: AOAM5332ZtDTAJ1F0xaEBvFGxoeMibl1+wcPPe45Y3SKmZSRdag+pgvo hb7s9QVvDXLw5O0xDyTtHS7Crg== X-Received: by 2002:adf:ab46:: with SMTP id r6mr6393996wrc.71.1633531661551; Wed, 06 Oct 2021 07:47:41 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Oct 2021 07:47:41 -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 2/3] nvmem: core: add nvmem cell post processing callback Date: Wed, 6 Oct 2021 15:47:28 +0100 Message-Id: <20211006144729.15268-3-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 Some NVMEM providers have certain nvmem cells encoded, which requires post processing before actually using it. For example mac-address is stored in either in ascii or delimited or reverse-order. Having a post-process callback hook to provider drivers would enable them to do this vendor specific post processing before nvmem consumers see it. Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 9 +++++++++ include/linux/nvmem-provider.h | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 9da4e8f42d86..108960aa49ab 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -38,6 +38,7 @@ struct nvmem_device { unsigned int nkeepout; nvmem_reg_read_t reg_read; nvmem_reg_write_t reg_write; + nvmem_cell_post_process_t cell_post_process; struct gpio_desc *wp_gpio; void *priv; }; @@ -798,6 +799,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->type = config->type; nvmem->reg_read = config->reg_read; nvmem->reg_write = config->reg_write; + nvmem->cell_post_process = config->cell_post_process; nvmem->keepout = config->keepout; nvmem->nkeepout = config->nkeepout; if (config->of_node) @@ -1441,6 +1443,13 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, if (cell->bit_offset || cell->nbits) nvmem_shift_read_buffer_in_place(cell, buf); + if (nvmem->cell_post_process) { + rc = nvmem->cell_post_process(nvmem->priv, id, + cell->offset, buf, cell->bytes); + if (rc) + return rc; + } + if (len) *len = cell->bytes; diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 104505e9028f..98efb7b5660d 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -19,6 +19,9 @@ typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset, void *val, size_t bytes); typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset, void *val, size_t bytes); +/* used for vendor specific post processing of cell data */ +typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, unsigned int offset, + void *buf, size_t bytes); enum nvmem_type { NVMEM_TYPE_UNKNOWN = 0, @@ -62,6 +65,7 @@ struct nvmem_keepout { * @no_of_node: Device should not use the parent's of_node even if it's !NULL. * @reg_read: Callback to read data. * @reg_write: Callback to write data. + * @cell_post_process: Callback for vendor specific post processing of cell data * @size: Device size. * @word_size: Minimum read/write access granularity. * @stride: Minimum read/write access stride. @@ -92,6 +96,7 @@ struct nvmem_config { bool no_of_node; nvmem_reg_read_t reg_read; nvmem_reg_write_t reg_write; + nvmem_cell_post_process_t cell_post_process; int size; int word_size; int stride; -- 2.21.0