internal.h 4.7 KB

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