Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * nvmem framework consumer.
0004  *
0005  * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
0006  * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com>
0007  */
0008 
0009 #ifndef _LINUX_NVMEM_CONSUMER_H
0010 #define _LINUX_NVMEM_CONSUMER_H
0011 
0012 #include <linux/err.h>
0013 #include <linux/errno.h>
0014 #include <linux/notifier.h>
0015 
0016 struct device;
0017 struct device_node;
0018 /* consumer cookie */
0019 struct nvmem_cell;
0020 struct nvmem_device;
0021 
0022 struct nvmem_cell_info {
0023     const char      *name;
0024     unsigned int        offset;
0025     unsigned int        bytes;
0026     unsigned int        bit_offset;
0027     unsigned int        nbits;
0028     struct device_node  *np;
0029 };
0030 
0031 /**
0032  * struct nvmem_cell_lookup - cell lookup entry
0033  *
0034  * @nvmem_name: Name of the provider.
0035  * @cell_name:  Name of the nvmem cell as defined in the name field of
0036  *      struct nvmem_cell_info.
0037  * @dev_id: Name of the consumer device that will be associated with
0038  *      this cell.
0039  * @con_id: Connector id for this cell lookup.
0040  */
0041 struct nvmem_cell_lookup {
0042     const char      *nvmem_name;
0043     const char      *cell_name;
0044     const char      *dev_id;
0045     const char      *con_id;
0046     struct list_head    node;
0047 };
0048 
0049 enum {
0050     NVMEM_ADD = 1,
0051     NVMEM_REMOVE,
0052     NVMEM_CELL_ADD,
0053     NVMEM_CELL_REMOVE,
0054 };
0055 
0056 #if IS_ENABLED(CONFIG_NVMEM)
0057 
0058 /* Cell based interface */
0059 struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id);
0060 struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id);
0061 void nvmem_cell_put(struct nvmem_cell *cell);
0062 void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
0063 void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
0064 int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
0065 int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val);
0066 int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val);
0067 int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
0068 int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val);
0069 int nvmem_cell_read_variable_le_u32(struct device *dev, const char *cell_id,
0070                     u32 *val);
0071 int nvmem_cell_read_variable_le_u64(struct device *dev, const char *cell_id,
0072                     u64 *val);
0073 
0074 /* direct nvmem device read/write interface */
0075 struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
0076 struct nvmem_device *devm_nvmem_device_get(struct device *dev,
0077                        const char *name);
0078 void nvmem_device_put(struct nvmem_device *nvmem);
0079 void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
0080 int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
0081               size_t bytes, void *buf);
0082 int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
0083                size_t bytes, void *buf);
0084 ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
0085                struct nvmem_cell_info *info, void *buf);
0086 int nvmem_device_cell_write(struct nvmem_device *nvmem,
0087                 struct nvmem_cell_info *info, void *buf);
0088 
0089 const char *nvmem_dev_name(struct nvmem_device *nvmem);
0090 
0091 void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries,
0092                 size_t nentries);
0093 void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries,
0094                 size_t nentries);
0095 
0096 int nvmem_register_notifier(struct notifier_block *nb);
0097 int nvmem_unregister_notifier(struct notifier_block *nb);
0098 
0099 struct nvmem_device *nvmem_device_find(void *data,
0100             int (*match)(struct device *dev, const void *data));
0101 
0102 #else
0103 
0104 static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
0105                         const char *id)
0106 {
0107     return ERR_PTR(-EOPNOTSUPP);
0108 }
0109 
0110 static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
0111                              const char *id)
0112 {
0113     return ERR_PTR(-EOPNOTSUPP);
0114 }
0115 
0116 static inline void devm_nvmem_cell_put(struct device *dev,
0117                        struct nvmem_cell *cell)
0118 {
0119 
0120 }
0121 static inline void nvmem_cell_put(struct nvmem_cell *cell)
0122 {
0123 }
0124 
0125 static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
0126 {
0127     return ERR_PTR(-EOPNOTSUPP);
0128 }
0129 
0130 static inline int nvmem_cell_write(struct nvmem_cell *cell,
0131                    void *buf, size_t len)
0132 {
0133     return -EOPNOTSUPP;
0134 }
0135 
0136 static inline int nvmem_cell_read_u16(struct device *dev,
0137                       const char *cell_id, u16 *val)
0138 {
0139     return -EOPNOTSUPP;
0140 }
0141 
0142 static inline int nvmem_cell_read_u32(struct device *dev,
0143                       const char *cell_id, u32 *val)
0144 {
0145     return -EOPNOTSUPP;
0146 }
0147 
0148 static inline int nvmem_cell_read_u64(struct device *dev,
0149                       const char *cell_id, u64 *val)
0150 {
0151     return -EOPNOTSUPP;
0152 }
0153 
0154 static inline int nvmem_cell_read_variable_le_u32(struct device *dev,
0155                          const char *cell_id,
0156                          u32 *val)
0157 {
0158     return -EOPNOTSUPP;
0159 }
0160 
0161 static inline int nvmem_cell_read_variable_le_u64(struct device *dev,
0162                           const char *cell_id,
0163                           u64 *val)
0164 {
0165     return -EOPNOTSUPP;
0166 }
0167 
0168 static inline struct nvmem_device *nvmem_device_get(struct device *dev,
0169                             const char *name)
0170 {
0171     return ERR_PTR(-EOPNOTSUPP);
0172 }
0173 
0174 static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
0175                              const char *name)
0176 {
0177     return ERR_PTR(-EOPNOTSUPP);
0178 }
0179 
0180 static inline void nvmem_device_put(struct nvmem_device *nvmem)
0181 {
0182 }
0183 
0184 static inline void devm_nvmem_device_put(struct device *dev,
0185                      struct nvmem_device *nvmem)
0186 {
0187 }
0188 
0189 static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
0190                      struct nvmem_cell_info *info,
0191                      void *buf)
0192 {
0193     return -EOPNOTSUPP;
0194 }
0195 
0196 static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
0197                       struct nvmem_cell_info *info,
0198                       void *buf)
0199 {
0200     return -EOPNOTSUPP;
0201 }
0202 
0203 static inline int nvmem_device_read(struct nvmem_device *nvmem,
0204                     unsigned int offset, size_t bytes,
0205                     void *buf)
0206 {
0207     return -EOPNOTSUPP;
0208 }
0209 
0210 static inline int nvmem_device_write(struct nvmem_device *nvmem,
0211                      unsigned int offset, size_t bytes,
0212                      void *buf)
0213 {
0214     return -EOPNOTSUPP;
0215 }
0216 
0217 static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
0218 {
0219     return NULL;
0220 }
0221 
0222 static inline void
0223 nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
0224 static inline void
0225 nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
0226 
0227 static inline int nvmem_register_notifier(struct notifier_block *nb)
0228 {
0229     return -EOPNOTSUPP;
0230 }
0231 
0232 static inline int nvmem_unregister_notifier(struct notifier_block *nb)
0233 {
0234     return -EOPNOTSUPP;
0235 }
0236 
0237 static inline struct nvmem_device *nvmem_device_find(void *data,
0238             int (*match)(struct device *dev, const void *data))
0239 {
0240     return NULL;
0241 }
0242 
0243 #endif /* CONFIG_NVMEM */
0244 
0245 #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
0246 struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
0247                      const char *id);
0248 struct nvmem_device *of_nvmem_device_get(struct device_node *np,
0249                      const char *name);
0250 #else
0251 static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
0252                            const char *id)
0253 {
0254     return ERR_PTR(-EOPNOTSUPP);
0255 }
0256 
0257 static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
0258                                const char *name)
0259 {
0260     return ERR_PTR(-EOPNOTSUPP);
0261 }
0262 #endif /* CONFIG_NVMEM && CONFIG_OF */
0263 
0264 #endif  /* ifndef _LINUX_NVMEM_CONSUMER_H */