1
linux/drivers/nvmem/internals.h
Miquel Raynal 0331c61194 nvmem: core: Expose cells through sysfs
The binary content of nvmem devices is available to the user so in the
easiest cases, finding the content of a cell is rather easy as it is
just a matter of looking at a known and fixed offset. However, nvmem
layouts have been recently introduced to cope with more advanced
situations, where the offset and size of the cells is not known in
advance or is dynamic. When using layouts, more advanced parsers are
used by the kernel in order to give direct access to the content of each
cell, regardless of its position/size in the underlying
device. Unfortunately, these information are not accessible by users,
unless by fully re-implementing the parser logic in userland.

Let's expose the cells and their content through sysfs to avoid these
situations. Of course the relevant NVMEM sysfs Kconfig option must be
enabled for this support to be available.

Not all nvmem devices expose cells. Indeed, the .bin_attrs attribute
group member will be filled at runtime only when relevant and will
remain empty otherwise. In this case, as the cells attribute group will
be empty, it will not lead to any additional folder/file creation.

Exposed cells are read-only. There is, in practice, everything in the
core to support a write path, but as I don't see any need for that, I
prefer to keep the interface simple (and probably safer). The interface
is documented as being in the "testing" state which means we can later
add a write attribute if though relevant.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Tested-by: Rafał Miłecki <rafal@milecki.pl>
Tested-by: Chen-Yu Tsai <wenst@chromium.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20231215111536.316972-9-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-12-15 13:30:08 +01:00

60 lines
1.4 KiB
C

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_NVMEM_INTERNALS_H
#define _LINUX_NVMEM_INTERNALS_H
#include <linux/device.h>
#include <linux/nvmem-consumer.h>
#include <linux/nvmem-provider.h>
struct nvmem_device {
struct module *owner;
struct device dev;
struct list_head node;
int stride;
int word_size;
int id;
struct kref refcnt;
size_t size;
bool read_only;
bool root_only;
int flags;
enum nvmem_type type;
struct bin_attribute eeprom;
struct device *base_dev;
struct list_head cells;
void (*fixup_dt_cell_info)(struct nvmem_device *nvmem,
struct nvmem_cell_info *cell);
const struct nvmem_keepout *keepout;
unsigned int nkeepout;
nvmem_reg_read_t reg_read;
nvmem_reg_write_t reg_write;
struct gpio_desc *wp_gpio;
struct nvmem_layout *layout;
void *priv;
bool sysfs_cells_populated;
};
#if IS_ENABLED(CONFIG_OF)
int nvmem_layout_bus_register(void);
void nvmem_layout_bus_unregister(void);
int nvmem_populate_layout(struct nvmem_device *nvmem);
void nvmem_destroy_layout(struct nvmem_device *nvmem);
#else /* CONFIG_OF */
static inline int nvmem_layout_bus_register(void)
{
return 0;
}
static inline void nvmem_layout_bus_unregister(void) {}
static inline int nvmem_populate_layout(struct nvmem_device *nvmem)
{
return 0;
}
static inline void nvmem_destroy_layout(struct nvmem_device *nvmem) { }
#endif /* CONFIG_OF */
#endif /* ifndef _LINUX_NVMEM_INTERNALS_H */