internal.h 5.1 KB

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