internal.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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);
  26. void (*format_val)(void *buf, unsigned int val);
  27. unsigned int (*parse_val)(void *buf);
  28. };
  29. typedef void (*regmap_lock)(struct regmap *map);
  30. typedef void (*regmap_unlock)(struct regmap *map);
  31. struct regmap {
  32. struct mutex mutex;
  33. spinlock_t spinlock;
  34. regmap_lock lock;
  35. regmap_unlock unlock;
  36. struct device *dev; /* Device we do I/O on */
  37. void *work_buf; /* Scratch buffer used to format I/O */
  38. struct regmap_format format; /* Buffer format */
  39. const struct regmap_bus *bus;
  40. void *bus_context;
  41. #ifdef CONFIG_DEBUG_FS
  42. struct dentry *debugfs;
  43. #endif
  44. unsigned int max_register;
  45. bool (*writeable_reg)(struct device *dev, unsigned int reg);
  46. bool (*readable_reg)(struct device *dev, unsigned int reg);
  47. bool (*volatile_reg)(struct device *dev, unsigned int reg);
  48. bool (*precious_reg)(struct device *dev, unsigned int reg);
  49. u8 read_flag_mask;
  50. u8 write_flag_mask;
  51. /* regcache specific members */
  52. const struct regcache_ops *cache_ops;
  53. enum regcache_type cache_type;
  54. /* number of bytes in reg_defaults_raw */
  55. unsigned int cache_size_raw;
  56. /* number of bytes per word in reg_defaults_raw */
  57. unsigned int cache_word_size;
  58. /* number of entries in reg_defaults */
  59. unsigned int num_reg_defaults;
  60. /* number of entries in reg_defaults_raw */
  61. unsigned int num_reg_defaults_raw;
  62. /* if set, only the cache is modified not the HW */
  63. u32 cache_only;
  64. /* if set, only the HW is modified not the cache */
  65. u32 cache_bypass;
  66. /* if set, remember to free reg_defaults_raw */
  67. bool cache_free;
  68. struct reg_default *reg_defaults;
  69. const void *reg_defaults_raw;
  70. void *cache;
  71. u32 cache_dirty;
  72. struct reg_default *patch;
  73. int patch_regs;
  74. };
  75. struct regcache_ops {
  76. const char *name;
  77. enum regcache_type type;
  78. int (*init)(struct regmap *map);
  79. int (*exit)(struct regmap *map);
  80. int (*read)(struct regmap *map, unsigned int reg, unsigned int *value);
  81. int (*write)(struct regmap *map, unsigned int reg, unsigned int value);
  82. int (*sync)(struct regmap *map, unsigned int min, unsigned int max);
  83. };
  84. bool regmap_writeable(struct regmap *map, unsigned int reg);
  85. bool regmap_readable(struct regmap *map, unsigned int reg);
  86. bool regmap_volatile(struct regmap *map, unsigned int reg);
  87. bool regmap_precious(struct regmap *map, unsigned int reg);
  88. int _regmap_write(struct regmap *map, unsigned int reg,
  89. unsigned int val);
  90. #ifdef CONFIG_DEBUG_FS
  91. extern void regmap_debugfs_initcall(void);
  92. extern void regmap_debugfs_init(struct regmap *map);
  93. extern void regmap_debugfs_exit(struct regmap *map);
  94. #else
  95. static inline void regmap_debugfs_initcall(void) { }
  96. static inline void regmap_debugfs_init(struct regmap *map) { }
  97. static inline void regmap_debugfs_exit(struct regmap *map) { }
  98. #endif
  99. /* regcache core declarations */
  100. int regcache_init(struct regmap *map, const struct regmap_config *config);
  101. void regcache_exit(struct regmap *map);
  102. int regcache_read(struct regmap *map,
  103. unsigned int reg, unsigned int *value);
  104. int regcache_write(struct regmap *map,
  105. unsigned int reg, unsigned int value);
  106. int regcache_sync(struct regmap *map);
  107. unsigned int regcache_get_val(const void *base, unsigned int idx,
  108. unsigned int word_size);
  109. bool regcache_set_val(void *base, unsigned int idx,
  110. unsigned int val, unsigned int word_size);
  111. int regcache_lookup_reg(struct regmap *map, unsigned int reg);
  112. extern struct regcache_ops regcache_rbtree_ops;
  113. extern struct regcache_ops regcache_lzo_ops;
  114. #endif