internal.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 regmap *map;
  42. void *work_buf;
  43. };
  44. struct regmap {
  45. union {
  46. struct mutex mutex;
  47. struct {
  48. spinlock_t spinlock;
  49. unsigned long spinlock_flags;
  50. };
  51. };
  52. regmap_lock lock;
  53. regmap_unlock unlock;
  54. void *lock_arg; /* This is passed to lock/unlock functions */
  55. struct device *dev; /* Device we do I/O on */
  56. void *work_buf; /* Scratch buffer used to format I/O */
  57. struct regmap_format format; /* Buffer format */
  58. const struct regmap_bus *bus;
  59. void *bus_context;
  60. const char *name;
  61. bool async;
  62. spinlock_t async_lock;
  63. wait_queue_head_t async_waitq;
  64. struct list_head async_list;
  65. struct list_head async_free;
  66. int async_ret;
  67. #ifdef CONFIG_DEBUG_FS
  68. struct dentry *debugfs;
  69. const char *debugfs_name;
  70. unsigned int debugfs_reg_len;
  71. unsigned int debugfs_val_len;
  72. unsigned int debugfs_tot_len;
  73. struct list_head debugfs_off_cache;
  74. struct mutex cache_lock;
  75. #endif
  76. unsigned int max_register;
  77. bool (*writeable_reg)(struct device *dev, unsigned int reg);
  78. bool (*readable_reg)(struct device *dev, unsigned int reg);
  79. bool (*volatile_reg)(struct device *dev, unsigned int reg);
  80. bool (*precious_reg)(struct device *dev, unsigned int reg);
  81. const struct regmap_access_table *wr_table;
  82. const struct regmap_access_table *rd_table;
  83. const struct regmap_access_table *volatile_table;
  84. const struct regmap_access_table *precious_table;
  85. int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
  86. int (*reg_write)(void *context, unsigned int reg, unsigned int val);
  87. int (*reg_update_bits)(void *context, unsigned int reg,
  88. unsigned int mask, unsigned int val);
  89. bool defer_caching;
  90. u8 read_flag_mask;
  91. u8 write_flag_mask;
  92. /* number of bits to (left) shift the reg value when formatting*/
  93. int reg_shift;
  94. int reg_stride;
  95. /* regcache specific members */
  96. const struct regcache_ops *cache_ops;
  97. enum regcache_type cache_type;
  98. /* number of bytes in reg_defaults_raw */
  99. unsigned int cache_size_raw;
  100. /* number of bytes per word in reg_defaults_raw */
  101. unsigned int cache_word_size;
  102. /* number of entries in reg_defaults */
  103. unsigned int num_reg_defaults;
  104. /* number of entries in reg_defaults_raw */
  105. unsigned int num_reg_defaults_raw;
  106. /* if set, only the cache is modified not the HW */
  107. u32 cache_only;
  108. /* if set, only the HW is modified not the cache */
  109. u32 cache_bypass;
  110. /* if set, remember to free reg_defaults_raw */
  111. bool cache_free;
  112. struct reg_default *reg_defaults;
  113. const void *reg_defaults_raw;
  114. void *cache;
  115. /* if set, the cache contains newer data than the HW */
  116. u32 cache_dirty;
  117. /* if set, the HW registers are known to match map->reg_defaults */
  118. bool no_sync_defaults;
  119. struct reg_sequence *patch;
  120. int patch_regs;
  121. /* if set, converts bulk read to single read */
  122. bool use_single_read;
  123. /* if set, converts bulk read to single read */
  124. bool use_single_write;
  125. /* if set, the device supports multi write mode */
  126. bool can_multi_write;
  127. /* if set, raw reads/writes are limited to this size */
  128. size_t max_raw_read;
  129. size_t max_raw_write;
  130. struct rb_root range_tree;
  131. void *selector_work_buf; /* Scratch buffer used for selector */
  132. };
  133. struct regcache_ops {
  134. const char *name;
  135. enum regcache_type type;
  136. int (*init)(struct regmap *map);
  137. int (*exit)(struct regmap *map);
  138. #ifdef CONFIG_DEBUG_FS
  139. void (*debugfs_init)(struct regmap *map);
  140. #endif
  141. int (*read)(struct regmap *map, unsigned int reg, unsigned int *value);
  142. int (*write)(struct regmap *map, unsigned int reg, unsigned int value);
  143. int (*sync)(struct regmap *map, unsigned int min, unsigned int max);
  144. int (*drop)(struct regmap *map, unsigned int min, unsigned int max);
  145. };
  146. bool regmap_writeable(struct regmap *map, unsigned int reg);
  147. bool regmap_readable(struct regmap *map, unsigned int reg);
  148. bool regmap_volatile(struct regmap *map, unsigned int reg);
  149. bool regmap_precious(struct regmap *map, unsigned int reg);
  150. int _regmap_write(struct regmap *map, unsigned int reg,
  151. unsigned int val);
  152. struct regmap_range_node {
  153. struct rb_node node;
  154. const char *name;
  155. struct regmap *map;
  156. unsigned int range_min;
  157. unsigned int range_max;
  158. unsigned int selector_reg;
  159. unsigned int selector_mask;
  160. int selector_shift;
  161. unsigned int window_start;
  162. unsigned int window_len;
  163. };
  164. struct regmap_field {
  165. struct regmap *regmap;
  166. unsigned int mask;
  167. /* lsb */
  168. unsigned int shift;
  169. unsigned int reg;
  170. unsigned int id_size;
  171. unsigned int id_offset;
  172. };
  173. #ifdef CONFIG_DEBUG_FS
  174. extern void regmap_debugfs_initcall(void);
  175. extern void regmap_debugfs_init(struct regmap *map, const char *name);
  176. extern void regmap_debugfs_exit(struct regmap *map);
  177. #else
  178. static inline void regmap_debugfs_initcall(void) { }
  179. static inline void regmap_debugfs_init(struct regmap *map, const char *name) { }
  180. static inline void regmap_debugfs_exit(struct regmap *map) { }
  181. #endif
  182. /* regcache core declarations */
  183. int regcache_init(struct regmap *map, const struct regmap_config *config);
  184. void regcache_exit(struct regmap *map);
  185. int regcache_read(struct regmap *map,
  186. unsigned int reg, unsigned int *value);
  187. int regcache_write(struct regmap *map,
  188. unsigned int reg, unsigned int value);
  189. int regcache_sync(struct regmap *map);
  190. int regcache_sync_block(struct regmap *map, void *block,
  191. unsigned long *cache_present,
  192. unsigned int block_base, unsigned int start,
  193. unsigned int end);
  194. static inline const void *regcache_get_val_addr(struct regmap *map,
  195. const void *base,
  196. unsigned int idx)
  197. {
  198. return base + (map->cache_word_size * idx);
  199. }
  200. unsigned int regcache_get_val(struct regmap *map, const void *base,
  201. unsigned int idx);
  202. bool regcache_set_val(struct regmap *map, void *base, unsigned int idx,
  203. unsigned int val);
  204. int regcache_lookup_reg(struct regmap *map, unsigned int reg);
  205. int _regmap_raw_write(struct regmap *map, unsigned int reg,
  206. const void *val, size_t val_len);
  207. void regmap_async_complete_cb(struct regmap_async *async, int ret);
  208. enum regmap_endian regmap_get_val_endian(struct device *dev,
  209. const struct regmap_bus *bus,
  210. const struct regmap_config *config);
  211. extern struct regcache_ops regcache_rbtree_ops;
  212. extern struct regcache_ops regcache_lzo_ops;
  213. extern struct regcache_ops regcache_flat_ops;
  214. static inline const char *regmap_name(const struct regmap *map)
  215. {
  216. if (map->dev)
  217. return dev_name(map->dev);
  218. return map->name;
  219. }
  220. #endif