internal.h 3.8 KB

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