regmap.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2015 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #ifndef __REGMAP_H
  7. #define __REGMAP_H
  8. /**
  9. * struct regmap_range - a register map range
  10. *
  11. * @start: Start address
  12. * @size: Size in bytes
  13. */
  14. struct regmap_range {
  15. ulong start;
  16. ulong size;
  17. };
  18. /**
  19. * struct regmap - a way of accessing hardware/bus registers
  20. *
  21. * @range_count: Number of ranges available within the map
  22. * @ranges: Array of ranges
  23. */
  24. struct regmap {
  25. int range_count;
  26. struct regmap_range ranges[0];
  27. };
  28. /*
  29. * Interface to provide access to registers either through a direct memory
  30. * bus or through a peripheral bus like I2C, SPI.
  31. */
  32. int regmap_write(struct regmap *map, uint offset, uint val);
  33. int regmap_read(struct regmap *map, uint offset, uint *valp);
  34. #define regmap_write32(map, ptr, member, val) \
  35. regmap_write(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), val)
  36. #define regmap_read32(map, ptr, member, valp) \
  37. regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp)
  38. /**
  39. * regmap_update_bits() - Perform a read/modify/write using a mask
  40. *
  41. * @map: The map returned by regmap_init_mem*()
  42. * @offset: Offset of the memory
  43. * @mask: Mask to apply to the read value
  44. * @val: Value to apply to the value to write
  45. */
  46. int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val);
  47. /**
  48. * regmap_init_mem() - Set up a new register map that uses memory access
  49. *
  50. * Use regmap_uninit() to free it.
  51. *
  52. * @node: Device node that uses this map
  53. * @mapp: Returns allocated map
  54. */
  55. int regmap_init_mem(ofnode node, struct regmap **mapp);
  56. /**
  57. * regmap_init_mem_platdata() - Set up a new memory register map for of-platdata
  58. *
  59. * This creates a new regmap with a list of regions passed in, rather than
  60. * using the device tree. It only supports 32-bit machines.
  61. *
  62. * Use regmap_uninit() to free it.
  63. *
  64. * @dev: Device that uses this map
  65. * @reg: List of address, size pairs
  66. * @count: Number of pairs (e.g. 1 if the regmap has a single entry)
  67. * @mapp: Returns allocated map
  68. */
  69. int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,
  70. struct regmap **mapp);
  71. /**
  72. * regmap_get_range() - Obtain the base memory address of a regmap range
  73. *
  74. * @map: Regmap to query
  75. * @range_num: Range to look up
  76. */
  77. void *regmap_get_range(struct regmap *map, unsigned int range_num);
  78. /**
  79. * regmap_uninit() - free a previously inited regmap
  80. */
  81. int regmap_uninit(struct regmap *map);
  82. #endif