Skip to content

Commit 5037d36

Browse files
afaerbergregkh
authored andcommitted
nvmem: core: Add nvmem_cell_read_u8()
Complement the u16, u32 and u64 helpers with a u8 variant to ease accessing byte-sized values. This helper will be useful for Realtek Digital Home Center platforms, which store some byte and sub-byte sized values in non-volatile memory. Signed-off-by: Andreas Färber <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3a75807 commit 5037d36

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

drivers/nvmem/core.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,21 @@ static int nvmem_cell_read_common(struct device *dev, const char *cell_id,
13741374
return 0;
13751375
}
13761376

1377+
/**
1378+
* nvmem_cell_read_u8() - Read a cell value as a u8
1379+
*
1380+
* @dev: Device that requests the nvmem cell.
1381+
* @cell_id: Name of nvmem cell to read.
1382+
* @val: pointer to output value.
1383+
*
1384+
* Return: 0 on success or negative errno.
1385+
*/
1386+
int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val)
1387+
{
1388+
return nvmem_cell_read_common(dev, cell_id, val, sizeof(*val));
1389+
}
1390+
EXPORT_SYMBOL_GPL(nvmem_cell_read_u8);
1391+
13771392
/**
13781393
* nvmem_cell_read_u16() - Read a cell value as a u16
13791394
*

include/linux/nvmem-consumer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void nvmem_cell_put(struct nvmem_cell *cell);
6161
void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
6262
void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
6363
int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
64+
int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val);
6465
int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val);
6566
int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
6667
int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val);

0 commit comments

Comments
 (0)