a5d4ace4e53d5e6a97b09dd5474087b6bf013c5a
[openwrt/staging/jow.git] /
1 From 5008062f1c3f5af3acf86164aa6fcc77b0c7bdce Mon Sep 17 00:00:00 2001
2 From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
3 Date: Wed, 13 Oct 2021 14:19:56 +0100
4 Subject: [PATCH] nvmem: core: add nvmem cell post processing callback
5
6 Some NVMEM providers have certain nvmem cells encoded, which requires
7 post processing before actually using it.
8
9 For example mac-address is stored in either in ascii or delimited or reverse-order.
10
11 Having a post-process callback hook to provider drivers would enable them to
12 do this vendor specific post processing before nvmem consumers see it.
13
14 Tested-by: Joakim Zhang <qiangqing.zhang@nxp.com>
15 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
16 Link: https://lore.kernel.org/r/20211013131957.30271-3-srinivas.kandagatla@linaro.org
17 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
18 ---
19 drivers/nvmem/core.c | 9 +++++++++
20 include/linux/nvmem-provider.h | 5 +++++
21 2 files changed, 14 insertions(+)
22
23 --- a/drivers/nvmem/core.c
24 +++ b/drivers/nvmem/core.c
25 @@ -38,6 +38,7 @@ struct nvmem_device {
26 unsigned int nkeepout;
27 nvmem_reg_read_t reg_read;
28 nvmem_reg_write_t reg_write;
29 + nvmem_cell_post_process_t cell_post_process;
30 struct gpio_desc *wp_gpio;
31 void *priv;
32 };
33 @@ -799,6 +800,7 @@ struct nvmem_device *nvmem_register(cons
34 nvmem->type = config->type;
35 nvmem->reg_read = config->reg_read;
36 nvmem->reg_write = config->reg_write;
37 + nvmem->cell_post_process = config->cell_post_process;
38 nvmem->keepout = config->keepout;
39 nvmem->nkeepout = config->nkeepout;
40 if (config->of_node)
41 @@ -1443,6 +1445,13 @@ static int __nvmem_cell_read(struct nvme
42 if (cell->bit_offset || cell->nbits)
43 nvmem_shift_read_buffer_in_place(cell, buf);
44
45 + if (nvmem->cell_post_process) {
46 + rc = nvmem->cell_post_process(nvmem->priv, id,
47 + cell->offset, buf, cell->bytes);
48 + if (rc)
49 + return rc;
50 + }
51 +
52 if (len)
53 *len = cell->bytes;
54
55 --- a/include/linux/nvmem-provider.h
56 +++ b/include/linux/nvmem-provider.h
57 @@ -19,6 +19,9 @@ typedef int (*nvmem_reg_read_t)(void *pr
58 void *val, size_t bytes);
59 typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
60 void *val, size_t bytes);
61 +/* used for vendor specific post processing of cell data */
62 +typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, unsigned int offset,
63 + void *buf, size_t bytes);
64
65 enum nvmem_type {
66 NVMEM_TYPE_UNKNOWN = 0,
67 @@ -62,6 +65,7 @@ struct nvmem_keepout {
68 * @no_of_node: Device should not use the parent's of_node even if it's !NULL.
69 * @reg_read: Callback to read data.
70 * @reg_write: Callback to write data.
71 + * @cell_post_process: Callback for vendor specific post processing of cell data
72 * @size: Device size.
73 * @word_size: Minimum read/write access granularity.
74 * @stride: Minimum read/write access stride.
75 @@ -94,6 +98,7 @@ struct nvmem_config {
76 bool no_of_node;
77 nvmem_reg_read_t reg_read;
78 nvmem_reg_write_t reg_write;
79 + nvmem_cell_post_process_t cell_post_process;
80 int size;
81 int word_size;
82 int stride;