mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-25 06:46:00 +00:00
regmap: Add raw read/write functions
The regmap functions currently assume that all register map accesses have a data width of 32 bits, but there are maps that have different widths. To rectify this, implement the regmap_raw_read and regmap_raw_write functions from the Linux kernel API that specify the width of a desired read or write operation on a regmap. Implement the regmap_read and regmap_write functions using these raw functions in a backwards-compatible manner. Reviewed-by: Anatolij Gustschin <agust@denx.de> Signed-off-by: Mario Six <mario.six@gdsys.cc> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
4d9ada54a2
commit
84ff8f622d
2 changed files with 115 additions and 7 deletions
|
@ -188,22 +188,72 @@ int regmap_uninit(struct regmap *map)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t val_len)
|
||||||
|
{
|
||||||
|
void *ptr;
|
||||||
|
|
||||||
|
ptr = map_physmem(map->ranges[0].start + offset, val_len, MAP_NOCACHE);
|
||||||
|
|
||||||
|
switch (val_len) {
|
||||||
|
case REGMAP_SIZE_8:
|
||||||
|
*((u8 *)valp) = readb((u8 *)ptr);
|
||||||
|
break;
|
||||||
|
case REGMAP_SIZE_16:
|
||||||
|
*((u16 *)valp) = readw((u16 *)ptr);
|
||||||
|
break;
|
||||||
|
case REGMAP_SIZE_32:
|
||||||
|
*((u32 *)valp) = readl((u32 *)ptr);
|
||||||
|
break;
|
||||||
|
#if defined(readq)
|
||||||
|
case REGMAP_SIZE_64:
|
||||||
|
*((u64 *)valp) = readq((u64 *)ptr);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
debug("%s: regmap size %zu unknown\n", __func__, val_len);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int regmap_read(struct regmap *map, uint offset, uint *valp)
|
int regmap_read(struct regmap *map, uint offset, uint *valp)
|
||||||
{
|
{
|
||||||
u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE);
|
return regmap_raw_read(map, offset, valp, REGMAP_SIZE_32);
|
||||||
|
}
|
||||||
|
|
||||||
*valp = le32_to_cpu(readl(ptr));
|
int regmap_raw_write(struct regmap *map, uint offset, const void *val,
|
||||||
|
size_t val_len)
|
||||||
|
{
|
||||||
|
void *ptr;
|
||||||
|
|
||||||
|
ptr = map_physmem(map->ranges[0].start + offset, val_len, MAP_NOCACHE);
|
||||||
|
|
||||||
|
switch (val_len) {
|
||||||
|
case REGMAP_SIZE_8:
|
||||||
|
writeb(*((u8 *)val), (u8 *)ptr);
|
||||||
|
break;
|
||||||
|
case REGMAP_SIZE_16:
|
||||||
|
writew(*((u16 *)val), (u16 *)ptr);
|
||||||
|
break;
|
||||||
|
case REGMAP_SIZE_32:
|
||||||
|
writel(*((u32 *)val), (u32 *)ptr);
|
||||||
|
break;
|
||||||
|
#if defined(writeq)
|
||||||
|
case REGMAP_SIZE_64:
|
||||||
|
writeq(*((u64 *)val), (u64 *)ptr);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
debug("%s: regmap size %zu unknown\n", __func__, val_len);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int regmap_write(struct regmap *map, uint offset, uint val)
|
int regmap_write(struct regmap *map, uint offset, uint val)
|
||||||
{
|
{
|
||||||
u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE);
|
return regmap_raw_write(map, offset, &val, REGMAP_SIZE_32);
|
||||||
|
|
||||||
writel(cpu_to_le32(val), ptr);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val)
|
int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val)
|
||||||
|
|
|
@ -7,6 +7,21 @@
|
||||||
#ifndef __REGMAP_H
|
#ifndef __REGMAP_H
|
||||||
#define __REGMAP_H
|
#define __REGMAP_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct regmap_range - a register map range
|
* struct regmap_range - a register map range
|
||||||
*
|
*
|
||||||
|
@ -41,6 +56,10 @@ struct regmap {
|
||||||
* @offset: Offset in the regmap to write to
|
* @offset: Offset in the regmap to write to
|
||||||
* @val: Data to write to the regmap at the specified offset
|
* @val: Data to write to the regmap at the specified offset
|
||||||
*
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
* Return: 0 if OK, -ve on error
|
* Return: 0 if OK, -ve on error
|
||||||
*/
|
*/
|
||||||
int regmap_write(struct regmap *map, uint offset, uint val);
|
int regmap_write(struct regmap *map, uint offset, uint val);
|
||||||
|
@ -53,10 +72,49 @@ int regmap_write(struct regmap *map, uint offset, uint val);
|
||||||
* @valp: Pointer to the buffer to receive the data read from the regmap
|
* @valp: Pointer to the buffer to receive the data read from the regmap
|
||||||
* at the specified offset
|
* at the specified offset
|
||||||
*
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
* Return: 0 if OK, -ve on error
|
* Return: 0 if OK, -ve on error
|
||||||
*/
|
*/
|
||||||
int regmap_read(struct regmap *map, uint offset, uint *valp);
|
int regmap_read(struct regmap *map, uint offset, uint *valp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
|
||||||
#define regmap_write32(map, ptr, member, val) \
|
#define regmap_write32(map, ptr, member, val) \
|
||||||
regmap_write(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), val)
|
regmap_write(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), val)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue