nvmem-consumer.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * nvmem framework consumer.
  4. *
  5. * Copyright (C) 2015 Srinivas Kandagatla <[email protected]>
  6. * Copyright (C) 2013 Maxime Ripard <[email protected]>
  7. */
  8. #ifndef _LINUX_NVMEM_CONSUMER_H
  9. #define _LINUX_NVMEM_CONSUMER_H
  10. #include <linux/err.h>
  11. #include <linux/errno.h>
  12. #include <linux/notifier.h>
  13. struct device;
  14. struct device_node;
  15. /* consumer cookie */
  16. struct nvmem_cell;
  17. struct nvmem_device;
  18. struct nvmem_cell_info {
  19. const char *name;
  20. unsigned int offset;
  21. unsigned int bytes;
  22. unsigned int bit_offset;
  23. unsigned int nbits;
  24. struct device_node *np;
  25. };
  26. /**
  27. * struct nvmem_cell_lookup - cell lookup entry
  28. *
  29. * @nvmem_name: Name of the provider.
  30. * @cell_name: Name of the nvmem cell as defined in the name field of
  31. * struct nvmem_cell_info.
  32. * @dev_id: Name of the consumer device that will be associated with
  33. * this cell.
  34. * @con_id: Connector id for this cell lookup.
  35. */
  36. struct nvmem_cell_lookup {
  37. const char *nvmem_name;
  38. const char *cell_name;
  39. const char *dev_id;
  40. const char *con_id;
  41. struct list_head node;
  42. };
  43. enum {
  44. NVMEM_ADD = 1,
  45. NVMEM_REMOVE,
  46. NVMEM_CELL_ADD,
  47. NVMEM_CELL_REMOVE,
  48. };
  49. #if IS_ENABLED(CONFIG_NVMEM)
  50. /* Cell based interface */
  51. struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id);
  52. struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id);
  53. void nvmem_cell_put(struct nvmem_cell *cell);
  54. void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
  55. void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
  56. int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
  57. int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val);
  58. int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val);
  59. int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
  60. int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val);
  61. int nvmem_cell_read_variable_le_u32(struct device *dev, const char *cell_id,
  62. u32 *val);
  63. int nvmem_cell_read_variable_le_u64(struct device *dev, const char *cell_id,
  64. u64 *val);
  65. /* direct nvmem device read/write interface */
  66. struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
  67. struct nvmem_device *devm_nvmem_device_get(struct device *dev,
  68. const char *name);
  69. void nvmem_device_put(struct nvmem_device *nvmem);
  70. void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
  71. int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
  72. size_t bytes, void *buf);
  73. int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
  74. size_t bytes, void *buf);
  75. ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
  76. struct nvmem_cell_info *info, void *buf);
  77. int nvmem_device_cell_write(struct nvmem_device *nvmem,
  78. struct nvmem_cell_info *info, void *buf);
  79. const char *nvmem_dev_name(struct nvmem_device *nvmem);
  80. void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries,
  81. size_t nentries);
  82. void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries,
  83. size_t nentries);
  84. int nvmem_register_notifier(struct notifier_block *nb);
  85. int nvmem_unregister_notifier(struct notifier_block *nb);
  86. struct nvmem_device *nvmem_device_find(void *data,
  87. int (*match)(struct device *dev, const void *data));
  88. #else
  89. static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
  90. const char *id)
  91. {
  92. return ERR_PTR(-EOPNOTSUPP);
  93. }
  94. static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
  95. const char *id)
  96. {
  97. return ERR_PTR(-EOPNOTSUPP);
  98. }
  99. static inline void devm_nvmem_cell_put(struct device *dev,
  100. struct nvmem_cell *cell)
  101. {
  102. }
  103. static inline void nvmem_cell_put(struct nvmem_cell *cell)
  104. {
  105. }
  106. static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
  107. {
  108. return ERR_PTR(-EOPNOTSUPP);
  109. }
  110. static inline int nvmem_cell_write(struct nvmem_cell *cell,
  111. void *buf, size_t len)
  112. {
  113. return -EOPNOTSUPP;
  114. }
  115. static inline int nvmem_cell_read_u16(struct device *dev,
  116. const char *cell_id, u16 *val)
  117. {
  118. return -EOPNOTSUPP;
  119. }
  120. static inline int nvmem_cell_read_u32(struct device *dev,
  121. const char *cell_id, u32 *val)
  122. {
  123. return -EOPNOTSUPP;
  124. }
  125. static inline int nvmem_cell_read_u64(struct device *dev,
  126. const char *cell_id, u64 *val)
  127. {
  128. return -EOPNOTSUPP;
  129. }
  130. static inline int nvmem_cell_read_variable_le_u32(struct device *dev,
  131. const char *cell_id,
  132. u32 *val)
  133. {
  134. return -EOPNOTSUPP;
  135. }
  136. static inline int nvmem_cell_read_variable_le_u64(struct device *dev,
  137. const char *cell_id,
  138. u64 *val)
  139. {
  140. return -EOPNOTSUPP;
  141. }
  142. static inline struct nvmem_device *nvmem_device_get(struct device *dev,
  143. const char *name)
  144. {
  145. return ERR_PTR(-EOPNOTSUPP);
  146. }
  147. static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
  148. const char *name)
  149. {
  150. return ERR_PTR(-EOPNOTSUPP);
  151. }
  152. static inline void nvmem_device_put(struct nvmem_device *nvmem)
  153. {
  154. }
  155. static inline void devm_nvmem_device_put(struct device *dev,
  156. struct nvmem_device *nvmem)
  157. {
  158. }
  159. static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
  160. struct nvmem_cell_info *info,
  161. void *buf)
  162. {
  163. return -EOPNOTSUPP;
  164. }
  165. static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
  166. struct nvmem_cell_info *info,
  167. void *buf)
  168. {
  169. return -EOPNOTSUPP;
  170. }
  171. static inline int nvmem_device_read(struct nvmem_device *nvmem,
  172. unsigned int offset, size_t bytes,
  173. void *buf)
  174. {
  175. return -EOPNOTSUPP;
  176. }
  177. static inline int nvmem_device_write(struct nvmem_device *nvmem,
  178. unsigned int offset, size_t bytes,
  179. void *buf)
  180. {
  181. return -EOPNOTSUPP;
  182. }
  183. static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
  184. {
  185. return NULL;
  186. }
  187. static inline void
  188. nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
  189. static inline void
  190. nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) {}
  191. static inline int nvmem_register_notifier(struct notifier_block *nb)
  192. {
  193. return -EOPNOTSUPP;
  194. }
  195. static inline int nvmem_unregister_notifier(struct notifier_block *nb)
  196. {
  197. return -EOPNOTSUPP;
  198. }
  199. static inline struct nvmem_device *nvmem_device_find(void *data,
  200. int (*match)(struct device *dev, const void *data))
  201. {
  202. return NULL;
  203. }
  204. #endif /* CONFIG_NVMEM */
  205. #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
  206. struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
  207. const char *id);
  208. struct nvmem_device *of_nvmem_device_get(struct device_node *np,
  209. const char *name);
  210. #else
  211. static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
  212. const char *id)
  213. {
  214. return ERR_PTR(-EOPNOTSUPP);
  215. }
  216. static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
  217. const char *name)
  218. {
  219. return ERR_PTR(-EOPNOTSUPP);
  220. }
  221. #endif /* CONFIG_NVMEM && CONFIG_OF */
  222. #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */