2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2015-06-23 21:38:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Google, Inc
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __REGMAP_H
|
|
|
|
#define __REGMAP_H
|
|
|
|
|
2018-10-15 07:24:10 +00:00
|
|
|
/**
|
|
|
|
* enum regmap_size_t - Access sizes for regmap reads and writes
|
|
|
|
*
|
|
|
|
* @REGMAP_SIZE_8: 8-bit read/write access size
|
|
|
|
* @REGMAP_SIZE_16: 16-bit read/write access size
|
|
|
|
* @REGMAP_SIZE_32: 32-bit read/write access size
|
|
|
|
* @REGMAP_SIZE_64: 64-bit read/write access size
|
|
|
|
*/
|
|
|
|
enum regmap_size_t {
|
|
|
|
REGMAP_SIZE_8 = 1,
|
|
|
|
REGMAP_SIZE_16 = 2,
|
|
|
|
REGMAP_SIZE_32 = 4,
|
|
|
|
REGMAP_SIZE_64 = 8,
|
|
|
|
};
|
|
|
|
|
2015-06-23 21:38:42 +00:00
|
|
|
/**
|
|
|
|
* struct regmap_range - a register map range
|
|
|
|
*
|
|
|
|
* @start: Start address
|
|
|
|
* @size: Size in bytes
|
|
|
|
*/
|
|
|
|
struct regmap_range {
|
|
|
|
ulong start;
|
|
|
|
ulong size;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct regmap - a way of accessing hardware/bus registers
|
|
|
|
*
|
2018-10-04 07:00:41 +00:00
|
|
|
* @range_count: Number of ranges available within the map
|
|
|
|
* @ranges: Array of ranges
|
2015-06-23 21:38:42 +00:00
|
|
|
*/
|
|
|
|
struct regmap {
|
|
|
|
int range_count;
|
2018-04-19 03:14:01 +00:00
|
|
|
struct regmap_range ranges[0];
|
2015-06-23 21:38:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interface to provide access to registers either through a direct memory
|
|
|
|
* bus or through a peripheral bus like I2C, SPI.
|
|
|
|
*/
|
2018-10-04 07:00:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* regmap_write() - Write a 32-bit value to a regmap
|
|
|
|
*
|
|
|
|
* @map: Regmap to write to
|
|
|
|
* @offset: Offset in the regmap to write to
|
|
|
|
* @val: Data to write to the regmap at the specified offset
|
|
|
|
*
|
2018-10-15 07:24:10 +00:00
|
|
|
* Note that this function will only write values of 32 bit width to the
|
|
|
|
* regmap; if the size of data to be read is different, the regmap_raw_write
|
|
|
|
* function can be used.
|
|
|
|
*
|
2018-10-04 07:00:41 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
|
|
|
*/
|
2015-06-23 21:38:42 +00:00
|
|
|
int regmap_write(struct regmap *map, uint offset, uint val);
|
2018-10-04 07:00:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* regmap_read() - Read a 32-bit value from a regmap
|
|
|
|
*
|
|
|
|
* @map: Regmap to read from
|
|
|
|
* @offset: Offset in the regmap to read from
|
|
|
|
* @valp: Pointer to the buffer to receive the data read from the regmap
|
|
|
|
* at the specified offset
|
|
|
|
*
|
2018-10-15 07:24:10 +00:00
|
|
|
* Note that this function will only read values of 32 bit width from the
|
|
|
|
* regmap; if the size of data to be read is different, the regmap_raw_read
|
|
|
|
* function can be used.
|
|
|
|
*
|
2018-10-04 07:00:41 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
|
|
|
*/
|
2015-06-23 21:38:42 +00:00
|
|
|
int regmap_read(struct regmap *map, uint offset, uint *valp);
|
|
|
|
|
2018-10-15 07:24:10 +00:00
|
|
|
/**
|
|
|
|
* regmap_raw_write() - Write a value of specified length to a regmap
|
|
|
|
*
|
|
|
|
* @map: Regmap to write to
|
|
|
|
* @offset: Offset in the regmap to write to
|
|
|
|
* @val: Value to write to the regmap at the specified offset
|
|
|
|
* @val_len: Length of the data to be written to the regmap
|
|
|
|
*
|
|
|
|
* Note that this function will, as opposed to regmap_write, write data of
|
|
|
|
* arbitrary length to the regmap, and not just 32-bit values, and is thus a
|
|
|
|
* generalized version of regmap_write.
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int regmap_raw_write(struct regmap *map, uint offset, const void *val,
|
|
|
|
size_t val_len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* regmap_raw_read() - Read a value of specified length from a regmap
|
|
|
|
*
|
|
|
|
* @map: Regmap to read from
|
|
|
|
* @offset: Offset in the regmap to read from
|
|
|
|
* @valp: Pointer to the buffer to receive the data read from the regmap
|
|
|
|
* at the specified offset
|
|
|
|
* @val_len: Length of the data to be read from the regmap
|
|
|
|
*
|
|
|
|
* Note that this function will, as opposed to regmap_read, read data of
|
|
|
|
* arbitrary length from the regmap, and not just 32-bit values, and is thus a
|
|
|
|
* generalized version of regmap_read.
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int regmap_raw_read(struct regmap *map, uint offset, void *valp,
|
|
|
|
size_t val_len);
|
|
|
|
|
2018-10-15 07:24:11 +00:00
|
|
|
/**
|
|
|
|
* regmap_raw_write_range() - Write a value of specified length to a range of a
|
|
|
|
* regmap
|
|
|
|
*
|
|
|
|
* @map: Regmap to write to
|
|
|
|
* @range_num: Number of the range in the regmap to write to
|
|
|
|
* @offset: Offset in the regmap to write to
|
|
|
|
* @val: Value to write to the regmap at the specified offset
|
|
|
|
* @val_len: Length of the data to be written to the regmap
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int regmap_raw_write_range(struct regmap *map, uint range_num, uint offset,
|
|
|
|
const void *val, size_t val_len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* regmap_raw_read_range() - Read a value of specified length from a range of a
|
|
|
|
* regmap
|
|
|
|
*
|
|
|
|
* @map: Regmap to read from
|
|
|
|
* @range_num: Number of the range in the regmap to write to
|
|
|
|
* @offset: Offset in the regmap to read from
|
|
|
|
* @valp: Pointer to the buffer to receive the data read from the regmap
|
|
|
|
* at the specified offset
|
|
|
|
* @val_len: Length of the data to be read from the regmap
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset,
|
|
|
|
void *valp, size_t val_len);
|
|
|
|
|
2018-10-15 07:24:12 +00:00
|
|
|
/**
|
|
|
|
* regmap_range_set() - Set a value in a regmap range described by a struct
|
|
|
|
* @map: Regmap in which a value should be set
|
|
|
|
* @range: Range of the regmap in which a value should be set
|
|
|
|
* @type: Structure type that describes the memory layout of the regmap range
|
|
|
|
* @member: Member of the describing structure that should be set in the regmap
|
|
|
|
* range
|
|
|
|
* @val: Value which should be written to the regmap range
|
|
|
|
*/
|
|
|
|
#define regmap_range_set(map, range, type, member, val) \
|
|
|
|
do { \
|
|
|
|
typeof(((type *)0)->member) __tmp = val; \
|
|
|
|
regmap_raw_write_range(map, range, offsetof(type, member), \
|
|
|
|
&__tmp, sizeof(((type *)0)->member)); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* regmap_set() - Set a value in a regmap described by a struct
|
|
|
|
* @map: Regmap in which a value should be set
|
|
|
|
* @type: Structure type that describes the memory layout of the regmap
|
|
|
|
* @member: Member of the describing structure that should be set in the regmap
|
|
|
|
* @val: Value which should be written to the regmap
|
|
|
|
*/
|
|
|
|
#define regmap_set(map, type, member, val) \
|
|
|
|
regmap_range_set(map, 0, type, member, val)
|
2015-06-23 21:38:42 +00:00
|
|
|
|
2018-10-15 07:24:12 +00:00
|
|
|
/**
|
|
|
|
* regmap_range_get() - Get a value from a regmap range described by a struct
|
|
|
|
* @map: Regmap from which a value should be read
|
|
|
|
* @range: Range of the regmap from which a value should be read
|
|
|
|
* @type: Structure type that describes the memory layout of the regmap
|
|
|
|
* range
|
|
|
|
* @member: Member of the describing structure that should be read in the
|
|
|
|
* regmap range
|
|
|
|
* @valp: Variable that receives the value read from the regmap range
|
|
|
|
*/
|
|
|
|
#define regmap_range_get(map, range, type, member, valp) \
|
|
|
|
regmap_raw_read_range(map, range, offsetof(type, member), \
|
|
|
|
(void *)valp, sizeof(((type *)0)->member))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* regmap_get() - Get a value from a regmap described by a struct
|
|
|
|
* @map: Regmap from which a value should be read
|
|
|
|
* @type: Structure type that describes the memory layout of the regmap
|
|
|
|
* range
|
|
|
|
* @member: Member of the describing structure that should be read in the
|
|
|
|
* regmap
|
|
|
|
* @valp: Variable that receives the value read from the regmap
|
|
|
|
*/
|
|
|
|
#define regmap_get(map, type, member, valp) \
|
|
|
|
regmap_range_get(map, 0, type, member, valp)
|
2015-06-23 21:38:42 +00:00
|
|
|
|
2018-04-27 09:56:14 +00:00
|
|
|
/**
|
|
|
|
* regmap_update_bits() - Perform a read/modify/write using a mask
|
|
|
|
*
|
|
|
|
* @map: The map returned by regmap_init_mem*()
|
|
|
|
* @offset: Offset of the memory
|
|
|
|
* @mask: Mask to apply to the read value
|
|
|
|
* @val: Value to apply to the value to write
|
2018-10-04 07:00:41 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2018-04-27 09:56:14 +00:00
|
|
|
*/
|
|
|
|
int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val);
|
|
|
|
|
2015-06-23 21:38:42 +00:00
|
|
|
/**
|
|
|
|
* regmap_init_mem() - Set up a new register map that uses memory access
|
|
|
|
*
|
2018-04-19 03:14:03 +00:00
|
|
|
* @node: Device node that uses this map
|
2015-06-23 21:38:42 +00:00
|
|
|
* @mapp: Returns allocated map
|
2018-10-04 07:00:41 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
|
|
|
*
|
|
|
|
* Use regmap_uninit() to free it.
|
2015-06-23 21:38:42 +00:00
|
|
|
*/
|
2018-04-19 03:14:03 +00:00
|
|
|
int regmap_init_mem(ofnode node, struct regmap **mapp);
|
2015-06-23 21:38:42 +00:00
|
|
|
|
2016-07-04 17:58:22 +00:00
|
|
|
/**
|
2018-10-04 07:00:41 +00:00
|
|
|
* regmap_init_mem_platdata() - Set up a new memory register map for
|
|
|
|
* of-platdata
|
|
|
|
*
|
|
|
|
* @dev: Device that uses this map
|
|
|
|
* @reg: List of address, size pairs
|
|
|
|
* @count: Number of pairs (e.g. 1 if the regmap has a single entry)
|
|
|
|
* @mapp: Returns allocated map
|
|
|
|
* Return: 0 if OK, -ve on error
|
2016-07-04 17:58:22 +00:00
|
|
|
*
|
|
|
|
* This creates a new regmap with a list of regions passed in, rather than
|
|
|
|
* using the device tree. It only supports 32-bit machines.
|
|
|
|
*
|
|
|
|
* Use regmap_uninit() to free it.
|
|
|
|
*
|
|
|
|
*/
|
2017-08-29 20:15:50 +00:00
|
|
|
int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,
|
2016-07-04 17:57:59 +00:00
|
|
|
struct regmap **mapp);
|
|
|
|
|
2015-06-23 21:38:42 +00:00
|
|
|
/**
|
|
|
|
* regmap_get_range() - Obtain the base memory address of a regmap range
|
|
|
|
*
|
|
|
|
* @map: Regmap to query
|
|
|
|
* @range_num: Range to look up
|
2018-10-04 07:00:41 +00:00
|
|
|
* Return: Pointer to the range in question if OK, NULL on error
|
2015-06-23 21:38:42 +00:00
|
|
|
*/
|
|
|
|
void *regmap_get_range(struct regmap *map, unsigned int range_num);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* regmap_uninit() - free a previously inited regmap
|
2018-10-04 07:00:41 +00:00
|
|
|
*
|
|
|
|
* @map: Regmap to free
|
|
|
|
* Return: 0 if OK, -ve on error
|
2015-06-23 21:38:42 +00:00
|
|
|
*/
|
|
|
|
int regmap_uninit(struct regmap *map);
|
|
|
|
|
|
|
|
#endif
|