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
|
|
|
|
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
|
|
|
|
2018-10-15 07:24:15 +00:00
|
|
|
/**
|
|
|
|
* DOC: Overview
|
|
|
|
*
|
|
|
|
* Regmaps are an abstraction mechanism that allows device drivers to access
|
|
|
|
* register maps irrespective of the underlying bus architecture. This entails
|
|
|
|
* that for devices that support multiple busses (e.g. I2C and SPI for a GPIO
|
|
|
|
* expander chip) only one driver has to be written. This driver will
|
|
|
|
* instantiate a regmap with a backend depending on the bus the device is
|
|
|
|
* attached to, and use the regmap API to access the register map through that
|
|
|
|
* bus transparently.
|
|
|
|
*
|
|
|
|
* Read and write functions are supplied, which can read/write data of
|
|
|
|
* arbitrary length from/to the regmap.
|
|
|
|
*
|
|
|
|
* The endianness of regmap accesses is selectable for each map through device
|
|
|
|
* tree settings via the boolean "little-endian", "big-endian", and
|
|
|
|
* "native-endian" properties.
|
|
|
|
*
|
|
|
|
* Furthermore, the register map described by a regmap can be split into
|
|
|
|
* multiple disjoint areas called ranges. In this way, register maps with
|
|
|
|
* "holes", i.e. areas of addressable memory that are not part of the register
|
|
|
|
* map, can be accessed in a concise manner.
|
|
|
|
*
|
|
|
|
* Currently, only a bare "mem" backend for regmaps is supported, which
|
|
|
|
* accesses the register map as regular IO-mapped memory.
|
|
|
|
*/
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2018-10-15 07:24:14 +00:00
|
|
|
/**
|
|
|
|
* enum regmap_endianness_t - Endianness for regmap reads and writes
|
|
|
|
*
|
|
|
|
* @REGMAP_NATIVE_ENDIAN: Native endian read/write accesses
|
|
|
|
* @REGMAP_LITTLE_ENDIAN: Little endian read/write accesses
|
|
|
|
* @REGMAP_BIG_ENDIAN: Big endian read/write accesses
|
|
|
|
*/
|
|
|
|
enum regmap_endianness_t {
|
|
|
|
REGMAP_NATIVE_ENDIAN,
|
|
|
|
REGMAP_LITTLE_ENDIAN,
|
|
|
|
REGMAP_BIG_ENDIAN,
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2020-09-24 04:34:10 +00:00
|
|
|
struct regmap_bus;
|
2020-09-24 04:34:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct regmap_config - Configure the behaviour of a regmap
|
|
|
|
*
|
|
|
|
* @width: Width of the read/write operations. Defaults to
|
|
|
|
* REGMAP_SIZE_32 if set to 0.
|
2020-09-24 04:34:13 +00:00
|
|
|
* @reg_offset_shift Left shift the register offset by this value before
|
|
|
|
* performing read or write.
|
2020-09-24 04:34:15 +00:00
|
|
|
* @r_start: If specified, the regmap is created with one range
|
|
|
|
* which starts at this address, instead of finding the
|
|
|
|
* start from device tree.
|
|
|
|
* @r_size: Same as above for the range size
|
2020-09-24 04:34:12 +00:00
|
|
|
*/
|
|
|
|
struct regmap_config {
|
|
|
|
enum regmap_size_t width;
|
2020-09-24 04:34:13 +00:00
|
|
|
u32 reg_offset_shift;
|
2020-09-24 04:34:15 +00:00
|
|
|
ulong r_start;
|
|
|
|
ulong r_size;
|
2020-09-24 04:34:12 +00:00
|
|
|
};
|
2020-09-24 04:34:10 +00:00
|
|
|
|
2015-06-23 21:38:42 +00:00
|
|
|
/**
|
|
|
|
* struct regmap - a way of accessing hardware/bus registers
|
|
|
|
*
|
2020-09-24 04:34:12 +00:00
|
|
|
* @width: Width of the read/write operations. Defaults to
|
|
|
|
* REGMAP_SIZE_32 if set to 0.
|
2020-09-24 04:34:13 +00:00
|
|
|
* @reg_offset_shift Left shift the register offset by this value before
|
|
|
|
* performing read or write.
|
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 {
|
2018-10-15 07:24:14 +00:00
|
|
|
enum regmap_endianness_t endianness;
|
2020-09-24 04:34:12 +00:00
|
|
|
enum regmap_size_t width;
|
2020-09-24 04:34:13 +00:00
|
|
|
u32 reg_offset_shift;
|
2015-06-23 21:38:42 +00:00
|
|
|
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
|
|
|
|
|
|
|
/**
|
2020-09-24 04:34:12 +00:00
|
|
|
* regmap_write() - Write a value to a regmap
|
2018-10-04 07:00:41 +00:00
|
|
|
*
|
|
|
|
* @map: Regmap to write to
|
|
|
|
* @offset: Offset in the regmap to write to
|
|
|
|
* @val: Data to write to the regmap at the specified offset
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
/**
|
2020-09-24 04:34:12 +00:00
|
|
|
* regmap_read() - Read a value from a regmap
|
2018-10-04 07:00:41 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*
|
|
|
|
* 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
|
2020-09-24 04:34:12 +00:00
|
|
|
* arbitrary length to the regmap, and not just the size configured in the
|
|
|
|
* regmap (defaults to 32-bit) and is thus a generalized version of
|
|
|
|
* regmap_write.
|
2018-10-15 07:24:10 +00:00
|
|
|
*
|
|
|
|
* 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
|
2020-09-24 04:34:12 +00:00
|
|
|
* arbitrary length from the regmap, and not just the size configured in the
|
|
|
|
* regmap (defaults to 32-bit) and is thus a generalized version of
|
|
|
|
* regmap_read.
|
2018-10-15 07:24:10 +00:00
|
|
|
*
|
|
|
|
* 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-11-22 10:01:03 +00:00
|
|
|
/**
|
|
|
|
* regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
|
|
|
|
*
|
|
|
|
* @map: Regmap to read from
|
|
|
|
* @addr: Offset to poll
|
|
|
|
* @val: Unsigned integer variable to read the value into
|
|
|
|
* @cond: Break condition (usually involving @val)
|
|
|
|
* @sleep_us: Maximum time to sleep between reads in us (0 tight-loops).
|
|
|
|
* @timeout_ms: Timeout in ms, 0 means never timeout
|
2018-12-10 00:11:10 +00:00
|
|
|
* @test_add_time: Used for sandbox testing - amount of time to add after
|
|
|
|
* starting the loop (0 if not testing)
|
2018-11-22 10:01:03 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
|
|
|
|
* error return value in case of a error read. In the two former cases,
|
|
|
|
* the last read value at @addr is stored in @val. Must not be called
|
|
|
|
* from atomic context if sleep_us or timeout_us are used.
|
|
|
|
*
|
|
|
|
* This is modelled after the regmap_read_poll_timeout macros in linux but
|
|
|
|
* with millisecond timeout.
|
2018-12-10 00:11:10 +00:00
|
|
|
*
|
|
|
|
* The _test version is for sandbox testing only. Do not use this in normal
|
|
|
|
* code as it advances the timer.
|
2018-11-22 10:01:03 +00:00
|
|
|
*/
|
2018-12-10 00:11:10 +00:00
|
|
|
#define regmap_read_poll_timeout_test(map, addr, val, cond, sleep_us, \
|
|
|
|
timeout_ms, test_add_time) \
|
2018-11-22 10:01:03 +00:00
|
|
|
({ \
|
|
|
|
unsigned long __start = get_timer(0); \
|
|
|
|
int __ret; \
|
|
|
|
for (;;) { \
|
|
|
|
__ret = regmap_read((map), (addr), &(val)); \
|
|
|
|
if (__ret) \
|
|
|
|
break; \
|
|
|
|
if (cond) \
|
|
|
|
break; \
|
2018-12-10 00:11:10 +00:00
|
|
|
if (IS_ENABLED(CONFIG_SANDBOX) && test_add_time) \
|
regmap: fix regmap_read_poll_timeout warning about sandbox_timer_add_offset
When fixing sandbox test for regmap_read_poll_timeout(), the
sandbox_timer_add_offset was introduced but only defined in sandbox code
thus generating warnings when used out of sandbox :
include/regmap.h:289:2: note: in expansion of macro 'regmap_read_poll_timeout_test'
regmap_read_poll_timeout_test(map, addr, val, cond, sleep_us, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/spi/meson_spifc.c:169:8: note: in expansion of macro 'regmap_read_poll_timeout'
ret = regmap_read_poll_timeout(spifc->regmap, REG_SLAVE, data,
^~~~~~~~~~~~~~~~~~~~~~~~
drivers/spi/meson_spifc.c: In function 'meson_spifc_txrx':
include/regmap.h:277:4: warning: implicit declaration of function 'sandbox_timer_add_offset' [-Wimplicit-function-declaration]
This fix adds a timer_test_add_offset() only defined in sandbox, and
renames the previous sandbox_timer_add_offset() to it.
Cc: Simon Glass <sjg@chromium.org>
Reported-by: Tom Rini <trini@konsulko.com>
Fixes: df9cf1cc08 ("test: dm: regmap: Fix the long test delay")
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2019-04-11 15:01:23 +00:00
|
|
|
timer_test_add_offset(test_add_time); \
|
2018-11-22 10:01:03 +00:00
|
|
|
if ((timeout_ms) && get_timer(__start) > (timeout_ms)) { \
|
|
|
|
__ret = regmap_read((map), (addr), &(val)); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
if ((sleep_us)) \
|
|
|
|
udelay((sleep_us)); \
|
|
|
|
} \
|
|
|
|
__ret ?: ((cond) ? 0 : -ETIMEDOUT); \
|
|
|
|
})
|
|
|
|
|
2018-12-10 00:11:10 +00:00
|
|
|
#define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_ms) \
|
|
|
|
regmap_read_poll_timeout_test(map, addr, val, cond, sleep_us, \
|
|
|
|
timeout_ms, 0) \
|
|
|
|
|
2020-09-24 04:34:16 +00:00
|
|
|
/**
|
|
|
|
* regmap_field_read_poll_timeout - Poll until a condition is met or a timeout
|
|
|
|
* occurs
|
|
|
|
*
|
|
|
|
* @field: Regmap field to read from
|
|
|
|
* @val: Unsigned integer variable to read the value into
|
|
|
|
* @cond: Break condition (usually involving @val)
|
|
|
|
* @sleep_us: Maximum time to sleep between reads in us (0 tight-loops).
|
|
|
|
* @timeout_ms: Timeout in ms, 0 means never timeout
|
|
|
|
*
|
|
|
|
* Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_field_read
|
|
|
|
* error return value in case of a error read. In the two former cases,
|
|
|
|
* the last read value at @addr is stored in @val.
|
|
|
|
*
|
|
|
|
* This is modelled after the regmap_read_poll_timeout macros in linux but
|
|
|
|
* with millisecond timeout.
|
|
|
|
*/
|
|
|
|
#define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_ms) \
|
|
|
|
({ \
|
|
|
|
unsigned long __start = get_timer(0); \
|
|
|
|
int __ret; \
|
|
|
|
for (;;) { \
|
|
|
|
__ret = regmap_field_read((field), &(val)); \
|
|
|
|
if (__ret) \
|
|
|
|
break; \
|
|
|
|
if (cond) \
|
|
|
|
break; \
|
|
|
|
if ((timeout_ms) && get_timer(__start) > (timeout_ms)) { \
|
|
|
|
__ret = regmap_field_read((field), &(val)); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
if ((sleep_us)) \
|
|
|
|
udelay((sleep_us)); \
|
|
|
|
} \
|
|
|
|
__ret ?: ((cond) ? 0 : -ETIMEDOUT); \
|
|
|
|
})
|
|
|
|
|
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
|
2019-10-11 22:16:49 +00:00
|
|
|
* @val: Value to OR with the read value after masking. Note that any
|
|
|
|
* bits set in @val which are not set in @mask are ignored
|
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
|
|
|
/**
|
2020-12-03 23:55:23 +00:00
|
|
|
* regmap_init_mem_plat() - Set up a new memory register map for
|
2018-10-04 07:00:41 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
2020-12-03 23:55:23 +00:00
|
|
|
int regmap_init_mem_plat(struct udevice *dev, fdt_val_t *reg, int count,
|
|
|
|
struct regmap **mapp);
|
2016-07-04 17:57:59 +00:00
|
|
|
|
2019-06-10 19:13:33 +00:00
|
|
|
int regmap_init_mem_index(ofnode node, struct regmap **mapp, int index);
|
|
|
|
|
2020-09-24 04:34:14 +00:00
|
|
|
/**
|
|
|
|
* regmap_init_mem_range() - Set up a new memory region for ofnode with the
|
|
|
|
* specified range.
|
|
|
|
*
|
|
|
|
* @node: The ofnode for the map.
|
|
|
|
* @r_start: Start of the range.
|
|
|
|
* @r_size: Size of the range.
|
|
|
|
* @mapp: Returns allocated map.
|
|
|
|
*
|
|
|
|
* Return: 0 in success, -errno otherwise
|
|
|
|
*
|
|
|
|
* This creates a regmap with one range where instead of extracting the range
|
|
|
|
* from 'node', it is created based on the parameters specified. This is
|
|
|
|
* useful when a driver needs to calculate the base of the regmap at runtime,
|
|
|
|
* and can't specify it in device tree.
|
|
|
|
*/
|
|
|
|
int regmap_init_mem_range(ofnode node, ulong r_start, ulong r_size,
|
|
|
|
struct regmap **mapp);
|
|
|
|
|
2020-09-24 04:34:10 +00:00
|
|
|
/**
|
|
|
|
* devm_regmap_init() - Initialise register map (device managed)
|
|
|
|
*
|
|
|
|
* @dev: Device that will be interacted with
|
|
|
|
* @bus: Bus-specific callbacks to use with device (IGNORED)
|
|
|
|
* @bus_context: Data passed to bus-specific callbacks (IGNORED)
|
2020-09-24 04:34:12 +00:00
|
|
|
* @config: Configuration for register map
|
2020-09-24 04:34:10 +00:00
|
|
|
*
|
|
|
|
* @Return a valid pointer to a struct regmap or a ERR_PTR() on error.
|
|
|
|
* The structure is automatically freed when the device is unbound
|
|
|
|
*/
|
|
|
|
struct regmap *devm_regmap_init(struct udevice *dev,
|
|
|
|
const struct regmap_bus *bus,
|
|
|
|
void *bus_context,
|
|
|
|
const struct regmap_config *config);
|
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);
|
|
|
|
|
2020-09-24 04:34:16 +00:00
|
|
|
/**
|
|
|
|
* struct reg_field - Description of an register field
|
|
|
|
*
|
|
|
|
* @reg: Offset of the register within the regmap bank
|
|
|
|
* @lsb: lsb of the register field.
|
|
|
|
* @msb: msb of the register field.
|
|
|
|
*/
|
|
|
|
struct reg_field {
|
|
|
|
unsigned int reg;
|
|
|
|
unsigned int lsb;
|
|
|
|
unsigned int msb;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct regmap_field;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* REG_FIELD() - A convenient way to initialize a 'struct reg_feild'.
|
|
|
|
*
|
|
|
|
* @_reg: Offset of the register within the regmap bank
|
|
|
|
* @_lsb: lsb of the register field.
|
|
|
|
* @_msb: msb of the register field.
|
|
|
|
*
|
|
|
|
* Register fields are often described in terms of 3 things: the register it
|
|
|
|
* belongs to, its LSB, and its MSB. This macro can be used by drivers to
|
|
|
|
* clearly and easily initialize a 'struct regmap_field'.
|
|
|
|
*
|
|
|
|
* For example, say a device has a register at offset DEV_REG1 (0x100) and a
|
|
|
|
* field of DEV_REG1 is on bits [7:3]. So a driver can initialize a regmap
|
|
|
|
* field for this by doing:
|
|
|
|
* struct reg_field field = REG_FIELD(DEV_REG1, 3, 7);
|
|
|
|
*/
|
|
|
|
#define REG_FIELD(_reg, _lsb, _msb) { \
|
|
|
|
.reg = _reg, \
|
|
|
|
.lsb = _lsb, \
|
|
|
|
.msb = _msb, \
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* devm_regmap_field_alloc() - Allocate and initialise a register field.
|
|
|
|
*
|
|
|
|
* @dev: Device that will be interacted with
|
|
|
|
* @regmap: regmap bank in which this register field is located.
|
|
|
|
* @reg_field: Register field with in the bank.
|
|
|
|
*
|
|
|
|
* The return value will be an ERR_PTR() on error or a valid pointer
|
|
|
|
* to a struct regmap_field. The regmap_field will be automatically freed
|
|
|
|
* by the device management code.
|
|
|
|
*/
|
|
|
|
struct regmap_field *devm_regmap_field_alloc(struct udevice *dev,
|
|
|
|
struct regmap *regmap,
|
|
|
|
struct reg_field reg_field);
|
|
|
|
/**
|
|
|
|
* devm_regmap_field_free() - Free a register field allocated using
|
|
|
|
* devm_regmap_field_alloc.
|
|
|
|
*
|
|
|
|
* @dev: Device that will be interacted with
|
|
|
|
* @field: regmap field which should be freed.
|
|
|
|
*
|
|
|
|
* Free register field allocated using devm_regmap_field_alloc(). Usually
|
|
|
|
* drivers need not call this function, as the memory allocated via devm
|
|
|
|
* will be freed as per device-driver life-cyle.
|
|
|
|
*/
|
|
|
|
void devm_regmap_field_free(struct udevice *dev, struct regmap_field *field);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* regmap_field_write() - Write a value to a regmap field
|
|
|
|
*
|
|
|
|
* @field: Regmap field to write to
|
|
|
|
* @val: Data to write to the regmap at the specified offset
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int regmap_field_write(struct regmap_field *field, unsigned int val);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* regmap_read() - Read a 32-bit value from a regmap
|
|
|
|
*
|
|
|
|
* @field: Regmap field to write to
|
|
|
|
* @valp: Pointer to the buffer to receive the data read from the regmap
|
|
|
|
* field
|
|
|
|
*
|
|
|
|
* Return: 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int regmap_field_read(struct regmap_field *field, unsigned int *val);
|
|
|
|
|
2015-06-23 21:38:42 +00:00
|
|
|
#endif
|