regmap.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * Configuration for the register map of a device.
  21. *
  22. * @reg_bits: Number of bits in a register address, mandatory.
  23. * @val_bits: Number of bits in a register value, mandatory.
  24. *
  25. * @max_register: Optional, specifies the maximum valid register index.
  26. * @writeable_register: Optional callback returning true if the register
  27. * can be written to.
  28. * @readable_register: Optional callback returning true if the register
  29. * can be read from.
  30. * @volatile_register: Optional callback returning true if the register
  31. * value can't be cached.
  32. */
  33. struct regmap_config {
  34. int reg_bits;
  35. int val_bits;
  36. unsigned int max_register;
  37. bool (*writeable_reg)(struct device *dev, unsigned int reg);
  38. bool (*readable_reg)(struct device *dev, unsigned int reg);
  39. bool (*volatile_reg)(struct device *dev, unsigned int reg);
  40. };
  41. typedef int (*regmap_hw_write)(struct device *dev, const void *data,
  42. size_t count);
  43. typedef int (*regmap_hw_gather_write)(struct device *dev,
  44. const void *reg, size_t reg_len,
  45. const void *val, size_t val_len);
  46. typedef int (*regmap_hw_read)(struct device *dev,
  47. const void *reg_buf, size_t reg_size,
  48. void *val_buf, size_t val_size);
  49. /**
  50. * Description of a hardware bus for the register map infrastructure.
  51. *
  52. * @list: Internal use.
  53. * @type: Bus type, used to identify bus to be used for a device.
  54. * @write: Write operation.
  55. * @gather_write: Write operation with split register/value, return -ENOTSUPP
  56. * if not implemented on a given device.
  57. * @read: Read operation. Data is returned in the buffer used to transmit
  58. * data.
  59. * @owner: Module with the bus implementation, used to pin the implementation
  60. * in memory.
  61. * @read_flag_mask: Mask to be set in the top byte of the register when doing
  62. * a read.
  63. */
  64. struct regmap_bus {
  65. struct list_head list;
  66. struct bus_type *type;
  67. regmap_hw_write write;
  68. regmap_hw_gather_write gather_write;
  69. regmap_hw_read read;
  70. struct module *owner;
  71. u8 read_flag_mask;
  72. };
  73. struct regmap *regmap_init(struct device *dev,
  74. const struct regmap_bus *bus,
  75. const struct regmap_config *config);
  76. struct regmap *regmap_init_i2c(struct i2c_client *i2c,
  77. const struct regmap_config *config);
  78. struct regmap *regmap_init_spi(struct spi_device *dev,
  79. const struct regmap_config *config);
  80. void regmap_exit(struct regmap *map);
  81. int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
  82. int regmap_raw_write(struct regmap *map, unsigned int reg,
  83. const void *val, size_t val_len);
  84. int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
  85. int regmap_raw_read(struct regmap *map, unsigned int reg,
  86. void *val, size_t val_len);
  87. int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
  88. size_t val_count);
  89. int regmap_update_bits(struct regmap *map, unsigned int reg,
  90. unsigned int mask, unsigned int val);
  91. #endif