nvmem-provider.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * nvmem framework provider.
  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_PROVIDER_H
  12. #define _LINUX_NVMEM_PROVIDER_H
  13. #include <linux/err.h>
  14. #include <linux/errno.h>
  15. struct nvmem_device;
  16. struct nvmem_cell_info;
  17. typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
  18. void *val, size_t bytes);
  19. typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
  20. void *val, size_t bytes);
  21. /**
  22. * struct nvmem_config - NVMEM device configuration
  23. *
  24. * @dev: Parent device.
  25. * @name: Optional name.
  26. * @id: Optional device ID used in full name. Ignored if name is NULL.
  27. * @owner: Pointer to exporter module. Used for refcounting.
  28. * @cells: Optional array of pre-defined NVMEM cells.
  29. * @ncells: Number of elements in cells.
  30. * @read_only: Device is read-only.
  31. * @root_only: Device is accessibly to root only.
  32. * @reg_read: Callback to read data.
  33. * @reg_write: Callback to write data.
  34. * @size: Device size.
  35. * @word_size: Minimum read/write access granularity.
  36. * @stride: Minimum read/write access stride.
  37. * @priv: User context passed to read/write callbacks.
  38. *
  39. * Note: A default "nvmem<id>" name will be assigned to the device if
  40. * no name is specified in its configuration. In such case "<id>" is
  41. * generated with ida_simple_get() and provided id field is ignored.
  42. *
  43. * Note: Specifying name and setting id to -1 implies a unique device
  44. * whose name is provided as-is (kept unaltered).
  45. */
  46. struct nvmem_config {
  47. struct device *dev;
  48. const char *name;
  49. int id;
  50. struct module *owner;
  51. const struct nvmem_cell_info *cells;
  52. int ncells;
  53. bool read_only;
  54. bool root_only;
  55. nvmem_reg_read_t reg_read;
  56. nvmem_reg_write_t reg_write;
  57. int size;
  58. int word_size;
  59. int stride;
  60. void *priv;
  61. /* To be only used by old driver/misc/eeprom drivers */
  62. bool compat;
  63. struct device *base_dev;
  64. };
  65. #if IS_ENABLED(CONFIG_NVMEM)
  66. struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
  67. int nvmem_unregister(struct nvmem_device *nvmem);
  68. struct nvmem_device *devm_nvmem_register(struct device *dev,
  69. const struct nvmem_config *cfg);
  70. int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
  71. int nvmem_add_cells(struct nvmem_device *nvmem,
  72. const struct nvmem_cell_info *info,
  73. int ncells);
  74. #else
  75. static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
  76. {
  77. return ERR_PTR(-ENOSYS);
  78. }
  79. static inline int nvmem_unregister(struct nvmem_device *nvmem)
  80. {
  81. return -ENOSYS;
  82. }
  83. static inline struct nvmem_device *
  84. devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
  85. {
  86. return nvmem_register(c);
  87. }
  88. static inline int
  89. devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
  90. {
  91. return nvmem_unregister(nvmem);
  92. }
  93. static inline int nvmem_add_cells(struct nvmem_device *nvmem,
  94. const struct nvmem_cell_info *info,
  95. int ncells)
  96. {
  97. return -ENOSYS;
  98. }
  99. #endif /* CONFIG_NVMEM */
  100. #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */