internal.h 3.9 KB

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