internal.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Register map access API internal header
  3. *
  4. * Copyright 2011 Wolfson Microelectronics plc
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #ifndef _REGMAP_INTERNAL_H
  13. #define _REGMAP_INTERNAL_H
  14. #include <linux/regmap.h>
  15. #include <linux/fs.h>
  16. #include <linux/list.h>
  17. #include <linux/wait.h>
  18. struct regmap;
  19. struct regcache_ops;
  20. struct regmap_debugfs_off_cache {
  21. struct list_head list;
  22. off_t min;
  23. off_t max;
  24. unsigned int base_reg;
  25. unsigned int max_reg;
  26. };
  27. struct regmap_format {
  28. size_t buf_size;
  29. size_t reg_bytes;
  30. size_t pad_bytes;
  31. size_t val_bytes;
  32. void (*format_write)(struct regmap *map,
  33. unsigned int reg, unsigned int val);
  34. void (*format_reg)(void *buf, unsigned int reg, unsigned int shift);
  35. void (*format_val)(void *buf, unsigned int val, unsigned int shift);
  36. unsigned int (*parse_val)(const void *buf);
  37. void (*parse_inplace)(void *buf);
  38. };
  39. struct regmap_async {
  40. struct list_head list;
  41. struct work_struct cleanup;
  42. struct regmap *map;
  43. void *work_buf;
  44. };
  45. struct regmap {
  46. struct mutex mutex;
  47. spinlock_t spinlock;
  48. unsigned long spinlock_flags;
  49. regmap_lock lock;
  50. regmap_unlock unlock;
  51. void *lock_arg; /* This is passed to lock/unlock functions */
  52. struct device *dev; /* Device we do I/O on */
  53. void *work_buf; /* Scratch buffer used to format I/O */
  54. struct regmap_format format; /* Buffer format */
  55. const struct regmap_bus *bus;
  56. void *bus_context;
  57. const char *name;
  58. spinlock_t async_lock;
  59. wait_queue_head_t async_waitq;
  60. struct list_head async_list;
  61. int async_ret;
  62. #ifdef CONFIG_DEBUG_FS
  63. struct dentry *debugfs;
  64. const char *debugfs_name;
  65. unsigned int debugfs_reg_len;
  66. unsigned int debugfs_val_len;
  67. unsigned int debugfs_tot_len;
  68. struct list_head debugfs_off_cache;
  69. struct mutex cache_lock;
  70. #endif
  71. unsigned int max_register;
  72. bool (*writeable_reg)(struct device *dev, unsigned int reg);
  73. bool (*readable_reg)(struct device *dev, unsigned int reg);
  74. bool (*volatile_reg)(struct device *dev, unsigned int reg);
  75. bool (*precious_reg)(struct device *dev, unsigned int reg);
  76. const struct regmap_access_table *wr_table;
  77. const struct regmap_access_table *rd_table;
  78. const struct regmap_access_table *volatile_table;
  79. const struct regmap_access_table *precious_table;
  80. int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
  81. int (*reg_write)(void *context, unsigned int reg, unsigned int val);
  82. bool defer_caching;
  83. u8 read_flag_mask;
  84. u8 write_flag_mask;
  85. /* number of bits to (left) shift the reg value when formatting*/
  86. int reg_shift;
  87. int reg_stride;
  88. /* regcache specific members */
  89. const struct regcache_ops *cache_ops;
  90. enum regcache_type cache_type;
  91. /* number of bytes in reg_defaults_raw */
  92. unsigned int cache_size_raw;
  93. /* number of bytes per word in reg_defaults_raw */
  94. unsigned int cache_word_size;
  95. /* number of entries in reg_defaults */
  96. unsigned int num_reg_defaults;
  97. /* number of entries in reg_defaults_raw */
  98. unsigned int num_reg_defaults_raw;
  99. /* if set, only the cache is modified not the HW */
  100. u32 cache_only;
  101. /* if set, only the HW is modified not the cache */
  102. u32 cache_bypass;
  103. /* if set, remember to free reg_defaults_raw */
  104. bool cache_free;
  105. struct reg_default *reg_defaults;
  106. const void *reg_defaults_raw;
  107. void *cache;
  108. u32 cache_dirty;
  109. unsigned long *cache_present;
  110. unsigned int cache_present_nbits;
  111. struct reg_default *patch;
  112. int patch_regs;
  113. /* if set, converts bulk rw to single rw */
  114. bool use_single_rw;
  115. struct rb_root range_tree;
  116. void *selector_work_buf; /* Scratch buffer used for selector */
  117. };
  118. struct regcache_ops {
  119. const char *name;
  120. enum regcache_type type;
  121. int (*init)(struct regmap *map);
  122. int (*exit)(struct regmap *map);
  123. int (*read)(struct regmap *map, unsigned int reg, unsigned int *value);
  124. int (*write)(struct regmap *map, unsigned int reg, unsigned int value);
  125. int (*sync)(struct regmap *map, unsigned int min, unsigned int max);
  126. int (*drop)(struct regmap *map, unsigned int min, unsigned int max);
  127. };
  128. bool regmap_writeable(struct regmap *map, unsigned int reg);
  129. bool regmap_readable(struct regmap *map, unsigned int reg);
  130. bool regmap_volatile(struct regmap *map, unsigned int reg);
  131. bool regmap_precious(struct regmap *map, unsigned int reg);
  132. int _regmap_write(struct regmap *map, unsigned int reg,
  133. unsigned int val);
  134. struct regmap_range_node {
  135. struct rb_node node;
  136. const char *name;
  137. struct regmap *map;
  138. unsigned int range_min;
  139. unsigned int range_max;
  140. unsigned int selector_reg;
  141. unsigned int selector_mask;
  142. int selector_shift;
  143. unsigned int window_start;
  144. unsigned int window_len;
  145. };
  146. struct regmap_field {
  147. struct regmap *regmap;
  148. unsigned int mask;
  149. /* lsb */
  150. unsigned int shift;
  151. unsigned int reg;
  152. };
  153. #ifdef CONFIG_DEBUG_FS
  154. extern void regmap_debugfs_initcall(void);
  155. extern void regmap_debugfs_init(struct regmap *map, const char *name);
  156. extern void regmap_debugfs_exit(struct regmap *map);
  157. #else
  158. static inline void regmap_debugfs_initcall(void) { }
  159. static inline void regmap_debugfs_init(struct regmap *map, const char *name) { }
  160. static inline void regmap_debugfs_exit(struct regmap *map) { }
  161. #endif
  162. /* regcache core declarations */
  163. int regcache_init(struct regmap *map, const struct regmap_config *config);
  164. void regcache_exit(struct regmap *map);
  165. int regcache_read(struct regmap *map,
  166. unsigned int reg, unsigned int *value);
  167. int regcache_write(struct regmap *map,
  168. unsigned int reg, unsigned int value);
  169. int regcache_sync(struct regmap *map);
  170. int regcache_sync_block(struct regmap *map, void *block,
  171. unsigned int block_base, unsigned int start,
  172. unsigned int end);
  173. static inline const void *regcache_get_val_addr(struct regmap *map,
  174. const void *base,
  175. unsigned int idx)
  176. {
  177. return base + (map->cache_word_size * idx);
  178. }
  179. unsigned int regcache_get_val(struct regmap *map, const void *base,
  180. unsigned int idx);
  181. bool regcache_set_val(struct regmap *map, void *base, unsigned int idx,
  182. unsigned int val);
  183. int regcache_lookup_reg(struct regmap *map, unsigned int reg);
  184. int regcache_set_reg_present(struct regmap *map, unsigned int reg);
  185. static inline bool regcache_reg_present(struct regmap *map, unsigned int reg)
  186. {
  187. if (!map->cache_present)
  188. return true;
  189. if (reg > map->cache_present_nbits)
  190. return false;
  191. return map->cache_present[BIT_WORD(reg)] & BIT_MASK(reg);
  192. }
  193. int _regmap_raw_write(struct regmap *map, unsigned int reg,
  194. const void *val, size_t val_len, bool async);
  195. void regmap_async_complete_cb(struct regmap_async *async, int ret);
  196. extern struct regcache_ops regcache_rbtree_ops;
  197. extern struct regcache_ops regcache_lzo_ops;
  198. extern struct regcache_ops regcache_flat_ops;
  199. #endif