internal.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. };
  26. struct regmap_format {
  27. size_t buf_size;
  28. size_t reg_bytes;
  29. size_t pad_bytes;
  30. size_t val_bytes;
  31. void (*format_write)(struct regmap *map,
  32. unsigned int reg, unsigned int val);
  33. void (*format_reg)(void *buf, unsigned int reg, unsigned int shift);
  34. void (*format_val)(void *buf, unsigned int val, unsigned int shift);
  35. unsigned int (*parse_val)(void *buf);
  36. };
  37. struct regmap_async {
  38. struct list_head list;
  39. struct work_struct cleanup;
  40. struct regmap *map;
  41. void *work_buf;
  42. };
  43. struct regmap {
  44. struct mutex mutex;
  45. spinlock_t spinlock;
  46. regmap_lock lock;
  47. regmap_unlock unlock;
  48. void *lock_arg; /* This is passed to lock/unlock functions */
  49. struct device *dev; /* Device we do I/O on */
  50. void *work_buf; /* Scratch buffer used to format I/O */
  51. struct regmap_format format; /* Buffer format */
  52. const struct regmap_bus *bus;
  53. void *bus_context;
  54. const char *name;
  55. spinlock_t async_lock;
  56. wait_queue_head_t async_waitq;
  57. struct list_head async_list;
  58. int async_ret;
  59. #ifdef CONFIG_DEBUG_FS
  60. struct dentry *debugfs;
  61. const char *debugfs_name;
  62. unsigned int debugfs_reg_len;
  63. unsigned int debugfs_val_len;
  64. unsigned int debugfs_tot_len;
  65. struct list_head debugfs_off_cache;
  66. #endif
  67. unsigned int max_register;
  68. bool (*writeable_reg)(struct device *dev, unsigned int reg);
  69. bool (*readable_reg)(struct device *dev, unsigned int reg);
  70. bool (*volatile_reg)(struct device *dev, unsigned int reg);
  71. bool (*precious_reg)(struct device *dev, unsigned int reg);
  72. const struct regmap_access_table *wr_table;
  73. const struct regmap_access_table *rd_table;
  74. const struct regmap_access_table *volatile_table;
  75. const struct regmap_access_table *precious_table;
  76. int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
  77. int (*reg_write)(void *context, unsigned int reg, unsigned int val);
  78. u8 read_flag_mask;
  79. u8 write_flag_mask;
  80. /* number of bits to (left) shift the reg value when formatting*/
  81. int reg_shift;
  82. int reg_stride;
  83. /* regcache specific members */
  84. const struct regcache_ops *cache_ops;
  85. enum regcache_type cache_type;
  86. /* number of bytes in reg_defaults_raw */
  87. unsigned int cache_size_raw;
  88. /* number of bytes per word in reg_defaults_raw */
  89. unsigned int cache_word_size;
  90. /* number of entries in reg_defaults */
  91. unsigned int num_reg_defaults;
  92. /* number of entries in reg_defaults_raw */
  93. unsigned int num_reg_defaults_raw;
  94. /* if set, only the cache is modified not the HW */
  95. u32 cache_only;
  96. /* if set, only the HW is modified not the cache */
  97. u32 cache_bypass;
  98. /* if set, remember to free reg_defaults_raw */
  99. bool cache_free;
  100. struct reg_default *reg_defaults;
  101. const void *reg_defaults_raw;
  102. void *cache;
  103. u32 cache_dirty;
  104. struct reg_default *patch;
  105. int patch_regs;
  106. /* if set, converts bulk rw to single rw */
  107. bool use_single_rw;
  108. struct rb_root range_tree;
  109. void *selector_work_buf; /* Scratch buffer used for selector */
  110. };
  111. struct regcache_ops {
  112. const char *name;
  113. enum regcache_type type;
  114. int (*init)(struct regmap *map);
  115. int (*exit)(struct regmap *map);
  116. int (*read)(struct regmap *map, unsigned int reg, unsigned int *value);
  117. int (*write)(struct regmap *map, unsigned int reg, unsigned int value);
  118. int (*sync)(struct regmap *map, unsigned int min, unsigned int max);
  119. };
  120. bool regmap_writeable(struct regmap *map, unsigned int reg);
  121. bool regmap_readable(struct regmap *map, unsigned int reg);
  122. bool regmap_volatile(struct regmap *map, unsigned int reg);
  123. bool regmap_precious(struct regmap *map, unsigned int reg);
  124. int _regmap_write(struct regmap *map, unsigned int reg,
  125. unsigned int val);
  126. struct regmap_range_node {
  127. struct rb_node node;
  128. const char *name;
  129. struct regmap *map;
  130. unsigned int range_min;
  131. unsigned int range_max;
  132. unsigned int selector_reg;
  133. unsigned int selector_mask;
  134. int selector_shift;
  135. unsigned int window_start;
  136. unsigned int window_len;
  137. };
  138. #ifdef CONFIG_DEBUG_FS
  139. extern void regmap_debugfs_initcall(void);
  140. extern void regmap_debugfs_init(struct regmap *map, const char *name);
  141. extern void regmap_debugfs_exit(struct regmap *map);
  142. #else
  143. static inline void regmap_debugfs_initcall(void) { }
  144. static inline void regmap_debugfs_init(struct regmap *map, const char *name) { }
  145. static inline void regmap_debugfs_exit(struct regmap *map) { }
  146. #endif
  147. /* regcache core declarations */
  148. int regcache_init(struct regmap *map, const struct regmap_config *config);
  149. void regcache_exit(struct regmap *map);
  150. int regcache_read(struct regmap *map,
  151. unsigned int reg, unsigned int *value);
  152. int regcache_write(struct regmap *map,
  153. unsigned int reg, unsigned int value);
  154. int regcache_sync(struct regmap *map);
  155. unsigned int regcache_get_val(const void *base, unsigned int idx,
  156. unsigned int word_size);
  157. bool regcache_set_val(void *base, unsigned int idx,
  158. unsigned int val, unsigned int word_size);
  159. int regcache_lookup_reg(struct regmap *map, unsigned int reg);
  160. void regmap_async_complete_cb(struct regmap_async *async, int ret);
  161. extern struct regcache_ops regcache_rbtree_ops;
  162. extern struct regcache_ops regcache_lzo_ops;
  163. #endif