1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
11 * enum regmap_size_t - Access sizes for regmap reads and writes
13 * @REGMAP_SIZE_8: 8-bit read/write access size
14 * @REGMAP_SIZE_16: 16-bit read/write access size
15 * @REGMAP_SIZE_32: 32-bit read/write access size
16 * @REGMAP_SIZE_64: 64-bit read/write access size
26 * struct regmap_range - a register map range
28 * @start: Start address
29 * @size: Size in bytes
37 * struct regmap - a way of accessing hardware/bus registers
39 * @range_count: Number of ranges available within the map
40 * @ranges: Array of ranges
44 struct regmap_range ranges[0];
48 * Interface to provide access to registers either through a direct memory
49 * bus or through a peripheral bus like I2C, SPI.
53 * regmap_write() - Write a 32-bit value to a regmap
55 * @map: Regmap to write to
56 * @offset: Offset in the regmap to write to
57 * @val: Data to write to the regmap at the specified offset
59 * Note that this function will only write values of 32 bit width to the
60 * regmap; if the size of data to be read is different, the regmap_raw_write
61 * function can be used.
63 * Return: 0 if OK, -ve on error
65 int regmap_write(struct regmap *map, uint offset, uint val);
68 * regmap_read() - Read a 32-bit value from a regmap
70 * @map: Regmap to read from
71 * @offset: Offset in the regmap to read from
72 * @valp: Pointer to the buffer to receive the data read from the regmap
73 * at the specified offset
75 * Note that this function will only read values of 32 bit width from the
76 * regmap; if the size of data to be read is different, the regmap_raw_read
77 * function can be used.
79 * Return: 0 if OK, -ve on error
81 int regmap_read(struct regmap *map, uint offset, uint *valp);
84 * regmap_raw_write() - Write a value of specified length to a regmap
86 * @map: Regmap to write to
87 * @offset: Offset in the regmap to write to
88 * @val: Value to write to the regmap at the specified offset
89 * @val_len: Length of the data to be written to the regmap
91 * Note that this function will, as opposed to regmap_write, write data of
92 * arbitrary length to the regmap, and not just 32-bit values, and is thus a
93 * generalized version of regmap_write.
95 * Return: 0 if OK, -ve on error
97 int regmap_raw_write(struct regmap *map, uint offset, const void *val,
101 * regmap_raw_read() - Read a value of specified length from a regmap
103 * @map: Regmap to read from
104 * @offset: Offset in the regmap to read from
105 * @valp: Pointer to the buffer to receive the data read from the regmap
106 * at the specified offset
107 * @val_len: Length of the data to be read from the regmap
109 * Note that this function will, as opposed to regmap_read, read data of
110 * arbitrary length from the regmap, and not just 32-bit values, and is thus a
111 * generalized version of regmap_read.
113 * Return: 0 if OK, -ve on error
115 int regmap_raw_read(struct regmap *map, uint offset, void *valp,
119 * regmap_raw_write_range() - Write a value of specified length to a range of a
122 * @map: Regmap to write to
123 * @range_num: Number of the range in the regmap to write to
124 * @offset: Offset in the regmap to write to
125 * @val: Value to write to the regmap at the specified offset
126 * @val_len: Length of the data to be written to the regmap
128 * Return: 0 if OK, -ve on error
130 int regmap_raw_write_range(struct regmap *map, uint range_num, uint offset,
131 const void *val, size_t val_len);
134 * regmap_raw_read_range() - Read a value of specified length from a range of a
137 * @map: Regmap to read from
138 * @range_num: Number of the range in the regmap to write to
139 * @offset: Offset in the regmap to read from
140 * @valp: Pointer to the buffer to receive the data read from the regmap
141 * at the specified offset
142 * @val_len: Length of the data to be read from the regmap
144 * Return: 0 if OK, -ve on error
146 int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset,
147 void *valp, size_t val_len);
149 #define regmap_write32(map, ptr, member, val) \
150 regmap_write(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), val)
152 #define regmap_read32(map, ptr, member, valp) \
153 regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp)
156 * regmap_update_bits() - Perform a read/modify/write using a mask
158 * @map: The map returned by regmap_init_mem*()
159 * @offset: Offset of the memory
160 * @mask: Mask to apply to the read value
161 * @val: Value to apply to the value to write
162 * Return: 0 if OK, -ve on error
164 int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val);
167 * regmap_init_mem() - Set up a new register map that uses memory access
169 * @node: Device node that uses this map
170 * @mapp: Returns allocated map
171 * Return: 0 if OK, -ve on error
173 * Use regmap_uninit() to free it.
175 int regmap_init_mem(ofnode node, struct regmap **mapp);
178 * regmap_init_mem_platdata() - Set up a new memory register map for
181 * @dev: Device that uses this map
182 * @reg: List of address, size pairs
183 * @count: Number of pairs (e.g. 1 if the regmap has a single entry)
184 * @mapp: Returns allocated map
185 * Return: 0 if OK, -ve on error
187 * This creates a new regmap with a list of regions passed in, rather than
188 * using the device tree. It only supports 32-bit machines.
190 * Use regmap_uninit() to free it.
193 int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,
194 struct regmap **mapp);
197 * regmap_get_range() - Obtain the base memory address of a regmap range
199 * @map: Regmap to query
200 * @range_num: Range to look up
201 * Return: Pointer to the range in question if OK, NULL on error
203 void *regmap_get_range(struct regmap *map, unsigned int range_num);
206 * regmap_uninit() - free a previously inited regmap
208 * @map: Regmap to free
209 * Return: 0 if OK, -ve on error
211 int regmap_uninit(struct regmap *map);