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 15 struct device; 16 struct device_node; 17 /* consumer cookie */ 18 struct nvmem_cell; 19 struct nvmem_device; 20 21 struct 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 */ 32 struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *name); 33 struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *name); 34 void nvmem_cell_put(struct nvmem_cell *cell); 35 void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); 36 void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len); 37 int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len); 38 39 /* direct nvmem device read/write interface */ 40 struct nvmem_device *nvmem_device_get(struct device *dev, const char *name); 41 struct nvmem_device *devm_nvmem_device_get(struct device *dev, 42 const char *name); 43 void nvmem_device_put(struct nvmem_device *nvmem); 44 void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem); 45 int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset, 46 size_t bytes, void *buf); 47 int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset, 48 size_t bytes, void *buf); 49 ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, 50 struct nvmem_cell_info *info, void *buf); 51 int nvmem_device_cell_write(struct nvmem_device *nvmem, 52 struct nvmem_cell_info *info, void *buf); 53 54 #else 55 56 static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, 57 const char *name) 58 { 59 return ERR_PTR(-ENOSYS); 60 } 61 62 static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, 63 const char *name) 64 { 65 return ERR_PTR(-ENOSYS); 66 } 67 68 static inline void devm_nvmem_cell_put(struct device *dev, 69 struct nvmem_cell *cell) 70 { 71 72 } 73 static inline void nvmem_cell_put(struct nvmem_cell *cell) 74 { 75 } 76 77 static inline char *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) 78 { 79 return ERR_PTR(-ENOSYS); 80 } 81 82 static inline int nvmem_cell_write(struct nvmem_cell *cell, 83 const char *buf, size_t len) 84 { 85 return -ENOSYS; 86 } 87 88 static inline struct nvmem_device *nvmem_device_get(struct device *dev, 89 const char *name) 90 { 91 return ERR_PTR(-ENOSYS); 92 } 93 94 static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev, 95 const char *name) 96 { 97 return ERR_PTR(-ENOSYS); 98 } 99 100 static inline void nvmem_device_put(struct nvmem_device *nvmem) 101 { 102 } 103 104 static inline void devm_nvmem_device_put(struct device *dev, 105 struct nvmem_device *nvmem) 106 { 107 } 108 109 static 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 116 static 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 123 static 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 130 static 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) 139 struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, 140 const char *name); 141 struct nvmem_device *of_nvmem_device_get(struct device_node *np, 142 const char *name); 143 #else 144 static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, 145 const char *name) 146 { 147 return ERR_PTR(-ENOSYS); 148 } 149 150 static 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