regmap.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #ifndef __LINUX_REGMAP_H
  2. #define __LINUX_REGMAP_H
  3. /*
  4. * Register map access API
  5. *
  6. * Copyright 2011 Wolfson Microelectronics plc
  7. *
  8. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/device.h>
  15. #include <linux/list.h>
  16. #include <linux/module.h>
  17. struct i2c_client;
  18. struct spi_device;
  19. /**
  20. * Default value for a register. We use an array of structs rather
  21. * than a simple array as many modern devices have very sparse
  22. * register maps.
  23. *
  24. * @reg: Register address.
  25. * @def: Register default value.
  26. */
  27. struct reg_default {
  28. unsigned int reg;
  29. unsigned int def;
  30. };
  31. /**
  32. * Configuration for the register map of a device.
  33. *
  34. * @reg_bits: Number of bits in a register address, mandatory.
  35. * @val_bits: Number of bits in a register value, mandatory.
  36. *
  37. * @writeable_reg: Optional callback returning true if the register
  38. * can be written to.
  39. * @readable_reg: Optional callback returning true if the register
  40. * can be read from.
  41. * @volatile_reg: Optional callback returning true if the register
  42. * value can't be cached.
  43. * @precious_reg: Optional callback returning true if the rgister
  44. * should not be read outside of a call from the driver
  45. * (eg, a clear on read interrupt status register).
  46. *
  47. * @max_register: Optional, specifies the maximum valid register index.
  48. * @reg_defaults: Power on reset values for registers (for use with
  49. * register cache support).
  50. * @num_reg_defaults: Number of elements in reg_defaults.
  51. *
  52. * @read_flag_mask: Mask to be set in the top byte of the register when doing
  53. * a read.
  54. * @write_flag_mask: Mask to be set in the top byte of the register when doing
  55. * a write. If both read_flag_mask and write_flag_mask are
  56. * empty the regmap_bus default masks are used.
  57. */
  58. struct regmap_config {
  59. int reg_bits;
  60. int val_bits;
  61. bool (*writeable_reg)(struct device *dev, unsigned int reg);
  62. bool (*readable_reg)(struct device *dev, unsigned int reg);
  63. bool (*volatile_reg)(struct device *dev, unsigned int reg);
  64. bool (*precious_reg)(struct device *dev, unsigned int reg);
  65. unsigned int max_register;
  66. struct reg_default *reg_defaults;
  67. int num_reg_defaults;
  68. u8 read_flag_mask;
  69. u8 write_flag_mask;
  70. };
  71. typedef int (*regmap_hw_write)(struct device *dev, const void *data,
  72. size_t count);
  73. typedef int (*regmap_hw_gather_write)(struct device *dev,
  74. const void *reg, size_t reg_len,
  75. const void *val, size_t val_len);
  76. typedef int (*regmap_hw_read)(struct device *dev,
  77. const void *reg_buf, size_t reg_size,
  78. void *val_buf, size_t val_size);
  79. /**
  80. * Description of a hardware bus for the register map infrastructure.
  81. *
  82. * @list: Internal use.
  83. * @type: Bus type, used to identify bus to be used for a device.
  84. * @write: Write operation.
  85. * @gather_write: Write operation with split register/value, return -ENOTSUPP
  86. * if not implemented on a given device.
  87. * @read: Read operation. Data is returned in the buffer used to transmit
  88. * data.
  89. * @owner: Module with the bus implementation, used to pin the implementation
  90. * in memory.
  91. * @read_flag_mask: Mask to be set in the top byte of the register when doing
  92. * a read.
  93. */
  94. struct regmap_bus {
  95. struct list_head list;
  96. struct bus_type *type;
  97. regmap_hw_write write;
  98. regmap_hw_gather_write gather_write;
  99. regmap_hw_read read;
  100. struct module *owner;
  101. u8 read_flag_mask;
  102. };
  103. struct regmap *regmap_init(struct device *dev,
  104. const struct regmap_bus *bus,
  105. const struct regmap_config *config);
  106. struct regmap *regmap_init_i2c(struct i2c_client *i2c,
  107. const struct regmap_config *config);
  108. struct regmap *regmap_init_spi(struct spi_device *dev,
  109. const struct regmap_config *config);
  110. void regmap_exit(struct regmap *map);
  111. int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
  112. int regmap_raw_write(struct regmap *map, unsigned int reg,
  113. const void *val, size_t val_len);
  114. int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
  115. int regmap_raw_read(struct regmap *map, unsigned int reg,
  116. void *val, size_t val_len);
  117. int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
  118. size_t val_count);
  119. int regmap_update_bits(struct regmap *map, unsigned int reg,
  120. unsigned int mask, unsigned int val);
  121. #endif