Merge tag 'f2fs-for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk...
[sfrench/cifs-2.6.git] / include / linux / nvmem-provider.h
1 /*
2  * nvmem framework provider.
3  *
4  * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
5  * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com>
6  *
7  * This file is licensed under the terms of the GNU General Public
8  * License version 2.  This program is licensed "as is" without any
9  * warranty of any kind, whether express or implied.
10  */
11
12 #ifndef _LINUX_NVMEM_PROVIDER_H
13 #define _LINUX_NVMEM_PROVIDER_H
14
15 #include <linux/err.h>
16 #include <linux/errno.h>
17
18 struct nvmem_device;
19 struct nvmem_cell_info;
20 typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
21                                 void *val, size_t bytes);
22 typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
23                                  void *val, size_t bytes);
24
25 /**
26  * struct nvmem_config - NVMEM device configuration
27  *
28  * @dev:        Parent device.
29  * @name:       Optional name.
30  * @id:         Optional device ID used in full name. Ignored if name is NULL.
31  * @owner:      Pointer to exporter module. Used for refcounting.
32  * @cells:      Optional array of pre-defined NVMEM cells.
33  * @ncells:     Number of elements in cells.
34  * @read_only:  Device is read-only.
35  * @root_only:  Device is accessibly to root only.
36  * @reg_read:   Callback to read data.
37  * @reg_write:  Callback to write data.
38  * @size:       Device size.
39  * @word_size:  Minimum read/write access granularity.
40  * @stride:     Minimum read/write access stride.
41  * @priv:       User context passed to read/write callbacks.
42  *
43  * Note: A default "nvmem<id>" name will be assigned to the device if
44  * no name is specified in its configuration. In such case "<id>" is
45  * generated with ida_simple_get() and provided id field is ignored.
46  *
47  * Note: Specifying name and setting id to -1 implies a unique device
48  * whose name is provided as-is (kept unaltered).
49  */
50 struct nvmem_config {
51         struct device           *dev;
52         const char              *name;
53         int                     id;
54         struct module           *owner;
55         const struct nvmem_cell_info    *cells;
56         int                     ncells;
57         bool                    read_only;
58         bool                    root_only;
59         nvmem_reg_read_t        reg_read;
60         nvmem_reg_write_t       reg_write;
61         int     size;
62         int     word_size;
63         int     stride;
64         void    *priv;
65         /* To be only used by old driver/misc/eeprom drivers */
66         bool                    compat;
67         struct device           *base_dev;
68 };
69
70 #if IS_ENABLED(CONFIG_NVMEM)
71
72 struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
73 int nvmem_unregister(struct nvmem_device *nvmem);
74
75 struct nvmem_device *devm_nvmem_register(struct device *dev,
76                                          const struct nvmem_config *cfg);
77
78 int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
79
80 int nvmem_add_cells(struct nvmem_device *nvmem,
81                     const struct nvmem_cell_info *info,
82                     int ncells);
83 #else
84
85 static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
86 {
87         return ERR_PTR(-ENOSYS);
88 }
89
90 static inline int nvmem_unregister(struct nvmem_device *nvmem)
91 {
92         return -ENOSYS;
93 }
94
95 static inline struct nvmem_device *
96 devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
97 {
98         return nvmem_register(c);
99 }
100
101 static inline int
102 devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
103 {
104         return nvmem_unregister(nvmem);
105
106 }
107
108 static inline int nvmem_add_cells(struct nvmem_device *nvmem,
109                                   const struct nvmem_cell_info *info,
110                                   int ncells)
111 {
112         return -ENOSYS;
113 }
114
115 #endif /* CONFIG_NVMEM */
116 #endif  /* ifndef _LINUX_NVMEM_PROVIDER_H */