regmap.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 regmap_config {
  19. int reg_bits;
  20. int val_bits;
  21. };
  22. typedef int (*regmap_hw_write)(struct device *dev, const void *data,
  23. size_t count);
  24. typedef int (*regmap_hw_gather_write)(struct device *dev,
  25. const void *reg, size_t reg_len,
  26. const void *val, size_t val_len);
  27. typedef int (*regmap_hw_read)(struct device *dev,
  28. const void *reg_buf, size_t reg_size,
  29. void *val_buf, size_t val_size);
  30. /**
  31. * Description of a hardware bus for the register map infrastructure.
  32. *
  33. * @list: Internal use.
  34. * @type: Bus type, used to identify bus to be used for a device.
  35. * @write: Write operation.
  36. * @gather_write: Write operation with split register/value, return -ENOTSUPP
  37. * if not implemented on a given device.
  38. * @read: Read operation. Data is returned in the buffer used to transmit
  39. * data.
  40. * @owner: Module with the bus implementation, used to pin the implementation
  41. * in memory.
  42. * @read_flag_mask: Mask to be set in the top byte of the register when doing
  43. * a read.
  44. */
  45. struct regmap_bus {
  46. struct list_head list;
  47. struct bus_type *type;
  48. regmap_hw_write write;
  49. regmap_hw_gather_write gather_write;
  50. regmap_hw_read read;
  51. struct module *owner;
  52. u8 read_flag_mask;
  53. };
  54. struct regmap *regmap_init(struct device *dev,
  55. const struct regmap_bus *bus,
  56. const struct regmap_config *config);
  57. struct regmap *regmap_init_i2c(struct i2c_client *i2c,
  58. const struct regmap_config *config);
  59. void regmap_exit(struct regmap *map);
  60. int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
  61. int regmap_raw_write(struct regmap *map, unsigned int reg,
  62. const void *val, size_t val_len);
  63. int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
  64. int regmap_raw_read(struct regmap *map, unsigned int reg,
  65. void *val, size_t val_len);
  66. int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
  67. size_t val_count);
  68. int regmap_update_bits(struct regmap *map, unsigned int reg,
  69. unsigned int mask, unsigned int val);
  70. #endif