linux/include/linux/nvmem-consumer.h
<<
>>
Prefs
   1/*
   2 * nvmem framework consumer.
   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_CONSUMER_H
  13#define _LINUX_NVMEM_CONSUMER_H
  14
  15struct device;
  16struct device_node;
  17/* consumer cookie */
  18struct nvmem_cell;
  19struct nvmem_device;
  20
  21struct nvmem_cell_info {
  22        const char              *name;
  23        unsigned int            offset;
  24        unsigned int            bytes;
  25        unsigned int            bit_offset;
  26        unsigned int            nbits;
  27};
  28
  29#if IS_ENABLED(CONFIG_NVMEM)
  30
  31/* Cell based interface */
  32struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *name);
  33struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *name);
  34void nvmem_cell_put(struct nvmem_cell *cell);
  35void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
  36void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
  37int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
  38
  39/* direct nvmem device read/write interface */
  40struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
  41struct nvmem_device *devm_nvmem_device_get(struct device *dev,
  42                                           const char *name);
  43void nvmem_device_put(struct nvmem_device *nvmem);
  44void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
  45int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
  46                      size_t bytes, void *buf);
  47int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
  48                       size_t bytes, void *buf);
  49ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
  50                           struct nvmem_cell_info *info, void *buf);
  51int nvmem_device_cell_write(struct nvmem_device *nvmem,
  52                            struct nvmem_cell_info *info, void *buf);
  53
  54#else
  55
  56static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
  57                                                const char *name)
  58{
  59        return ERR_PTR(-ENOSYS);
  60}
  61
  62static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
  63                                       const char *name)
  64{
  65        return ERR_PTR(-ENOSYS);
  66}
  67
  68static inline void devm_nvmem_cell_put(struct device *dev,
  69                                       struct nvmem_cell *cell)
  70{
  71
  72}
  73static inline void nvmem_cell_put(struct nvmem_cell *cell)
  74{
  75}
  76
  77static inline char *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
  78{
  79        return ERR_PTR(-ENOSYS);
  80}
  81
  82static inline int nvmem_cell_write(struct nvmem_cell *cell,
  83                                    const char *buf, size_t len)
  84{
  85        return -ENOSYS;
  86}
  87
  88static inline struct nvmem_device *nvmem_device_get(struct device *dev,
  89                                                    const char *name)
  90{
  91        return ERR_PTR(-ENOSYS);
  92}
  93
  94static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
  95                                                         const char *name)
  96{
  97        return ERR_PTR(-ENOSYS);
  98}
  99
 100static inline void nvmem_device_put(struct nvmem_device *nvmem)
 101{
 102}
 103
 104static inline void devm_nvmem_device_put(struct device *dev,
 105                                         struct nvmem_device *nvmem)
 106{
 107}
 108
 109static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
 110                                         struct nvmem_cell_info *info,
 111                                         void *buf)
 112{
 113        return -ENOSYS;
 114}
 115
 116static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
 117                                          struct nvmem_cell_info *info,
 118                                          void *buf)
 119{
 120        return -ENOSYS;
 121}
 122
 123static inline int nvmem_device_read(struct nvmem_device *nvmem,
 124                                    unsigned int offset, size_t bytes,
 125                                    void *buf)
 126{
 127        return -ENOSYS;
 128}
 129
 130static inline int nvmem_device_write(struct nvmem_device *nvmem,
 131                                     unsigned int offset, size_t bytes,
 132                                     void *buf)
 133{
 134        return -ENOSYS;
 135}
 136#endif /* CONFIG_NVMEM */
 137
 138#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
 139struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
 140                                     const char *name);
 141struct nvmem_device *of_nvmem_device_get(struct device_node *np,
 142                                         const char *name);
 143#else
 144static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
 145                                     const char *name)
 146{
 147        return ERR_PTR(-ENOSYS);
 148}
 149
 150static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
 151                                                       const char *name)
 152{
 153        return ERR_PTR(-ENOSYS);
 154}
 155#endif /* CONFIG_NVMEM && CONFIG_OF */
 156
 157#endif  /* ifndef _LINUX_NVMEM_CONSUMER_H */
 158