nvmem-consumer.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. #ifndef _LINUX_NVMEM_CONSUMER_H
  12. #define _LINUX_NVMEM_CONSUMER_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. };
  25. #if IS_ENABLED(CONFIG_NVMEM)
  26. /* Cell based interface */
  27. struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *name);
  28. struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *name);
  29. void nvmem_cell_put(struct nvmem_cell *cell);
  30. void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
  31. void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
  32. int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
  33. /* direct nvmem device read/write interface */
  34. struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
  35. struct nvmem_device *devm_nvmem_device_get(struct device *dev,
  36. const char *name);
  37. void nvmem_device_put(struct nvmem_device *nvmem);
  38. void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem);
  39. int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset,
  40. size_t bytes, void *buf);
  41. int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset,
  42. size_t bytes, void *buf);
  43. ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
  44. struct nvmem_cell_info *info, void *buf);
  45. int nvmem_device_cell_write(struct nvmem_device *nvmem,
  46. struct nvmem_cell_info *info, void *buf);
  47. #else
  48. static inline struct nvmem_cell *nvmem_cell_get(struct device *dev,
  49. const char *name)
  50. {
  51. return ERR_PTR(-ENOSYS);
  52. }
  53. static inline struct nvmem_cell *devm_nvmem_cell_get(struct device *dev,
  54. const char *name)
  55. {
  56. return ERR_PTR(-ENOSYS);
  57. }
  58. static inline void devm_nvmem_cell_put(struct device *dev,
  59. struct nvmem_cell *cell)
  60. {
  61. }
  62. static inline void nvmem_cell_put(struct nvmem_cell *cell)
  63. {
  64. }
  65. static inline void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
  66. {
  67. return ERR_PTR(-ENOSYS);
  68. }
  69. static inline int nvmem_cell_write(struct nvmem_cell *cell,
  70. const char *buf, size_t len)
  71. {
  72. return -ENOSYS;
  73. }
  74. static inline struct nvmem_device *nvmem_device_get(struct device *dev,
  75. const char *name)
  76. {
  77. return ERR_PTR(-ENOSYS);
  78. }
  79. static inline struct nvmem_device *devm_nvmem_device_get(struct device *dev,
  80. const char *name)
  81. {
  82. return ERR_PTR(-ENOSYS);
  83. }
  84. static inline void nvmem_device_put(struct nvmem_device *nvmem)
  85. {
  86. }
  87. static inline void devm_nvmem_device_put(struct device *dev,
  88. struct nvmem_device *nvmem)
  89. {
  90. }
  91. static inline ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
  92. struct nvmem_cell_info *info,
  93. void *buf)
  94. {
  95. return -ENOSYS;
  96. }
  97. static inline int nvmem_device_cell_write(struct nvmem_device *nvmem,
  98. struct nvmem_cell_info *info,
  99. void *buf)
  100. {
  101. return -ENOSYS;
  102. }
  103. static inline int nvmem_device_read(struct nvmem_device *nvmem,
  104. unsigned int offset, size_t bytes,
  105. void *buf)
  106. {
  107. return -ENOSYS;
  108. }
  109. static inline int nvmem_device_write(struct nvmem_device *nvmem,
  110. unsigned int offset, size_t bytes,
  111. void *buf)
  112. {
  113. return -ENOSYS;
  114. }
  115. #endif /* CONFIG_NVMEM */
  116. #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
  117. struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
  118. const char *name);
  119. struct nvmem_device *of_nvmem_device_get(struct device_node *np,
  120. const char *name);
  121. #else
  122. static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
  123. const char *name)
  124. {
  125. return ERR_PTR(-ENOSYS);
  126. }
  127. static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
  128. const char *name)
  129. {
  130. return ERR_PTR(-ENOSYS);
  131. }
  132. #endif /* CONFIG_NVMEM && CONFIG_OF */
  133. #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */