46b30a2ed90417ddef819dd47b13d3e61c91525b
[openwrt/staging/981213.git] /
1 From 8a134fd9f9323f4c39ec27055b3d3723cfb5c1e9 Mon Sep 17 00:00:00 2001
2 From: Michael Walle <michael@walle.cc>
3 Date: Tue, 4 Apr 2023 18:21:28 +0100
4 Subject: [PATCH] nvmem: core: provide own priv pointer in post process
5 callback
6
7 It doesn't make any more sense to have a opaque pointer set up by the
8 nvmem device. Usually, the layout isn't associated with a particular
9 nvmem device. Instead, let the caller who set the post process callback
10 provide the priv pointer.
11
12 Signed-off-by: Michael Walle <michael@walle.cc>
13 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
14 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
15 Link: https://lore.kernel.org/r/20230404172148.82422-21-srinivas.kandagatla@linaro.org
16 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
17 ---
18 drivers/nvmem/core.c | 4 +++-
19 include/linux/nvmem-provider.h | 5 ++++-
20 2 files changed, 7 insertions(+), 2 deletions(-)
21
22 --- a/drivers/nvmem/core.c
23 +++ b/drivers/nvmem/core.c
24 @@ -54,6 +54,7 @@ struct nvmem_cell_entry {
25 int bit_offset;
26 int nbits;
27 nvmem_cell_post_process_t read_post_process;
28 + void *priv;
29 struct device_node *np;
30 struct nvmem_device *nvmem;
31 struct list_head node;
32 @@ -471,6 +472,7 @@ static int nvmem_cell_info_to_nvmem_cell
33 cell->bytes = info->bytes;
34 cell->name = info->name;
35 cell->read_post_process = info->read_post_process;
36 + cell->priv = info->priv;
37
38 cell->bit_offset = info->bit_offset;
39 cell->nbits = info->nbits;
40 @@ -1568,7 +1570,7 @@ static int __nvmem_cell_read(struct nvme
41 nvmem_shift_read_buffer_in_place(cell, buf);
42
43 if (cell->read_post_process) {
44 - rc = cell->read_post_process(nvmem->priv, id, index,
45 + rc = cell->read_post_process(cell->priv, id, index,
46 cell->offset, buf, cell->bytes);
47 if (rc)
48 return rc;
49 --- a/include/linux/nvmem-provider.h
50 +++ b/include/linux/nvmem-provider.h
51 @@ -20,7 +20,8 @@ typedef int (*nvmem_reg_write_t)(void *p
52 void *val, size_t bytes);
53 /* used for vendor specific post processing of cell data */
54 typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index,
55 - unsigned int offset, void *buf, size_t bytes);
56 + unsigned int offset, void *buf,
57 + size_t bytes);
58
59 enum nvmem_type {
60 NVMEM_TYPE_UNKNOWN = 0,
61 @@ -56,6 +57,7 @@ struct nvmem_keepout {
62 * @np: Optional device_node pointer.
63 * @read_post_process: Callback for optional post processing of cell data
64 * on reads.
65 + * @priv: Opaque data passed to the read_post_process hook.
66 */
67 struct nvmem_cell_info {
68 const char *name;
69 @@ -65,6 +67,7 @@ struct nvmem_cell_info {
70 unsigned int nbits;
71 struct device_node *np;
72 nvmem_cell_post_process_t read_post_process;
73 + void *priv;
74 };
75
76 /**