NVMEM API

The NVMEM subsystem is a "meta-uclass" in that it abstracts over several different uclasses all with read/write APIs. One approach to implementing this could be to add a new sub-device for each nvmem-style device of UCLASS_NVMEM. This subsystem has taken the approach of using the existing access methods (i2c_eeprom_write, misc_write, etc.) directly. This has the advantage of not requiring an extra device/driver, saving on binary size and runtime memory usage. On the other hand, it is not idiomatic. Similar efforts should generally use a new uclass.

structnvmem_cell

One datum within non-volatile memory

Definition

struct nvmem_cell {
 struct udevice *nvmem;
 unsigned int offset;
 size_t size;
};

Members

nvmem

The backing storage device

offset

The offset of the cell from the start of nvmem

size

The size of the cell, in bytes

intnvmem_cell_read(structnvmem_cell *cell, void*buf, size_tsize)

Read the value of an nvmem cell

Parameters

struct nvmem_cell *cell

The nvmem cell to read

void *buf

The buffer to read into

size_t size

The size of buf

Return

  • 0 on success

  • -EINVAL if buf is not the same size as cell.

  • -ENOSYS if CONFIG_NVMEM is disabled

  • A negative error if there was a problem reading the underlying storage

intnvmem_cell_write(structnvmem_cell *cell, constvoid*buf, size_tsize)

Write a value to an nvmem cell

Parameters

struct nvmem_cell *cell

The nvmem cell to write

const void *buf

The buffer to write from

size_t size

The size of buf

Return

  • 0 on success

  • -EINVAL if buf is not the same size as cell

  • -ENOSYS if cell is read-only, or if CONFIG_NVMEM is disabled

  • A negative error if there was a problem writing the underlying storage

intnvmem_cell_get_by_index(structudevice *dev, intindex, structnvmem_cell *cell)

Get an nvmem cell from a given device and index

Parameters

struct udevice *dev

The device that uses the nvmem cell

int index

The index of the cell in nvmem-cells

struct nvmem_cell *cell

The cell to initialize

Description

Look up the nvmem cell referenced by the phandle at index in nvmem-cells in dev.

Return

  • 0 on success

  • -EINVAL if the regs property is missing, empty, or undersized

  • -ENODEV if the nvmem device is missing or unimplemented

  • -ENOSYS if CONFIG_NVMEM is disabled

  • A negative error if there was a problem reading nvmem-cells or getting the device

intnvmem_cell_get_by_name(structudevice *dev, constchar*name, structnvmem_cell *cell)

Get an nvmem cell from a given device and name

Parameters

struct udevice *dev

The device that uses the nvmem cell

const char *name

The name of the nvmem cell

struct nvmem_cell *cell

The cell to initialize

Description

Look up the nvmem cell referenced by name in the nvmem-cell-names property of dev.

Return

  • 0 on success

  • -EINVAL if the regs property is missing, empty, or undersized

  • -ENODEV if the nvmem device is missing or unimplemented

  • -ENODATA if name is not in nvmem-cell-names

  • -ENOSYS if CONFIG_NVMEM is disabled

  • A negative error if there was a problem reading nvmem-cell-names, nvmem-cells, or getting the device