linux/drivers/nvmem/core.c

// SPDX-License-Identifier: GPL-2.0
/*
 * nvmem framework core.
 *
 * Copyright (C) 2015 Srinivas Kandagatla <[email protected]>
 * Copyright (C) 2013 Maxime Ripard <[email protected]>
 */

#include <linux/device.h>
#include <linux/export.h>
#include <linux/fs.h>
#include <linux/idr.h>
#include <linux/init.h>
#include <linux/kref.h>
#include <linux/module.h>
#include <linux/nvmem-consumer.h>
#include <linux/nvmem-provider.h>
#include <linux/gpio/consumer.h>
#include <linux/of.h>
#include <linux/slab.h>

#include "internals.h"

#define to_nvmem_device(d)

#define FLAG_COMPAT
struct nvmem_cell_entry {};

struct nvmem_cell {};

static DEFINE_MUTEX(nvmem_mutex);
static DEFINE_IDA(nvmem_ida);

static DEFINE_MUTEX(nvmem_cell_mutex);
static LIST_HEAD(nvmem_cell_tables);

static DEFINE_MUTEX(nvmem_lookup_mutex);
static LIST_HEAD(nvmem_lookup_list);

static BLOCKING_NOTIFIER_HEAD(nvmem_notifier);

static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset,
			    void *val, size_t bytes)
{}

static int __nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
			     void *val, size_t bytes)
{}

static int nvmem_access_with_keepouts(struct nvmem_device *nvmem,
				      unsigned int offset, void *val,
				      size_t bytes, int write)
{}

static int nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset,
			  void *val, size_t bytes)
{}

static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
			   void *val, size_t bytes)
{}

#ifdef CONFIG_NVMEM_SYSFS
static const char * const nvmem_type_str[] =;

#ifdef CONFIG_DEBUG_LOCK_ALLOC
static struct lock_class_key eeprom_lock_key;
#endif

static ssize_t type_show(struct device *dev,
			 struct device_attribute *attr, char *buf)
{}

static DEVICE_ATTR_RO(type);

static ssize_t force_ro_show(struct device *dev, struct device_attribute *attr,
			     char *buf)
{}

static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr,
			      const char *buf, size_t count)
{}

static DEVICE_ATTR_RW(force_ro);

static struct attribute *nvmem_attrs[] =;

static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
				   struct bin_attribute *attr, char *buf,
				   loff_t pos, size_t count)
{}

static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
				    struct bin_attribute *attr, char *buf,
				    loff_t pos, size_t count)
{}

static umode_t nvmem_bin_attr_get_umode(struct nvmem_device *nvmem)
{}

static umode_t nvmem_bin_attr_is_visible(struct kobject *kobj,
					 struct bin_attribute *attr, int i)
{}

static umode_t nvmem_attr_is_visible(struct kobject *kobj,
				     struct attribute *attr, int i)
{}

static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry,
					    const char *id, int index);

static ssize_t nvmem_cell_attr_read(struct file *filp, struct kobject *kobj,
				    struct bin_attribute *attr, char *buf,
				    loff_t pos, size_t count)
{}

/* default read/write permissions */
static struct bin_attribute bin_attr_rw_nvmem =;

static struct bin_attribute *nvmem_bin_attributes[] =;

static const struct attribute_group nvmem_bin_group =;

static const struct attribute_group *nvmem_dev_groups[] =;

static struct bin_attribute bin_attr_nvmem_eeprom_compat =;

/*
 * nvmem_setup_compat() - Create an additional binary entry in
 * drivers sys directory, to be backwards compatible with the older
 * drivers/misc/eeprom drivers.
 */
static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem,
				    const struct nvmem_config *config)
{}

static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem,
			      const struct nvmem_config *config)
{}

static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
{}

#else /* CONFIG_NVMEM_SYSFS */

static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem,
				    const struct nvmem_config *config)
{
	return -ENOSYS;
}
static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem,
				      const struct nvmem_config *config)
{
}

#endif /* CONFIG_NVMEM_SYSFS */

static void nvmem_release(struct device *dev)
{}

static const struct device_type nvmem_provider_type =;

static struct bus_type nvmem_bus_type =;

static void nvmem_cell_entry_drop(struct nvmem_cell_entry *cell)
{}

static void nvmem_device_remove_all_cells(const struct nvmem_device *nvmem)
{}

static void nvmem_cell_entry_add(struct nvmem_cell_entry *cell)
{}

static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
						     const struct nvmem_cell_info *info,
						     struct nvmem_cell_entry *cell)
{}

static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem,
					       const struct nvmem_cell_info *info,
					       struct nvmem_cell_entry *cell)
{}

/**
 * nvmem_add_one_cell() - Add one cell information to an nvmem device
 *
 * @nvmem: nvmem device to add cells to.
 * @info: nvmem cell info to add to the device
 *
 * Return: 0 or negative error code on failure.
 */
int nvmem_add_one_cell(struct nvmem_device *nvmem,
		       const struct nvmem_cell_info *info)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_add_cells() - Add cell information to an nvmem device
 *
 * @nvmem: nvmem device to add cells to.
 * @info: nvmem cell info to add to the device
 * @ncells: number of cells in info
 *
 * Return: 0 or negative error code on failure.
 */
static int nvmem_add_cells(struct nvmem_device *nvmem,
		    const struct nvmem_cell_info *info,
		    int ncells)
{}

/**
 * nvmem_register_notifier() - Register a notifier block for nvmem events.
 *
 * @nb: notifier block to be called on nvmem events.
 *
 * Return: 0 on success, negative error number on failure.
 */
int nvmem_register_notifier(struct notifier_block *nb)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_unregister_notifier() - Unregister a notifier block for nvmem events.
 *
 * @nb: notifier block to be unregistered.
 *
 * Return: 0 on success, negative error number on failure.
 */
int nvmem_unregister_notifier(struct notifier_block *nb)
{}
EXPORT_SYMBOL_GPL();

static int nvmem_add_cells_from_table(struct nvmem_device *nvmem)
{}

static struct nvmem_cell_entry *
nvmem_find_cell_entry_by_name(struct nvmem_device *nvmem, const char *cell_id)
{}

static int nvmem_validate_keepouts(struct nvmem_device *nvmem)
{}

static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
{}

static int nvmem_add_cells_from_legacy_of(struct nvmem_device *nvmem)
{}

static int nvmem_add_cells_from_fixed_layout(struct nvmem_device *nvmem)
{}

int nvmem_layout_register(struct nvmem_layout *layout)
{}
EXPORT_SYMBOL_GPL();

void nvmem_layout_unregister(struct nvmem_layout *layout)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_register() - Register a nvmem device for given nvmem_config.
 * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
 *
 * @config: nvmem device configuration with which nvmem device is created.
 *
 * Return: Will be an ERR_PTR() on error or a valid pointer to nvmem_device
 * on success.
 */

struct nvmem_device *nvmem_register(const struct nvmem_config *config)
{}
EXPORT_SYMBOL_GPL();

static void nvmem_device_release(struct kref *kref)
{}

/**
 * nvmem_unregister() - Unregister previously registered nvmem device
 *
 * @nvmem: Pointer to previously registered nvmem device.
 */
void nvmem_unregister(struct nvmem_device *nvmem)
{}
EXPORT_SYMBOL_GPL();

static void devm_nvmem_unregister(void *nvmem)
{}

/**
 * devm_nvmem_register() - Register a managed nvmem device for given
 * nvmem_config.
 * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
 *
 * @dev: Device that uses the nvmem device.
 * @config: nvmem device configuration with which nvmem device is created.
 *
 * Return: Will be an ERR_PTR() on error or a valid pointer to nvmem_device
 * on success.
 */
struct nvmem_device *devm_nvmem_register(struct device *dev,
					 const struct nvmem_config *config)
{}
EXPORT_SYMBOL_GPL();

static struct nvmem_device *__nvmem_device_get(void *data,
			int (*match)(struct device *dev, const void *data))
{}

static void __nvmem_device_put(struct nvmem_device *nvmem)
{}

#if IS_ENABLED(CONFIG_OF)
/**
 * of_nvmem_device_get() - Get nvmem device from a given id
 *
 * @np: Device tree node that uses the nvmem device.
 * @id: nvmem name from nvmem-names property.
 *
 * Return: ERR_PTR() on error or a valid pointer to a struct nvmem_device
 * on success.
 */
struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *id)
{}
EXPORT_SYMBOL_GPL();
#endif

/**
 * nvmem_device_get() - Get nvmem device from a given id
 *
 * @dev: Device that uses the nvmem device.
 * @dev_name: name of the requested nvmem device.
 *
 * Return: ERR_PTR() on error or a valid pointer to a struct nvmem_device
 * on success.
 */
struct nvmem_device *nvmem_device_get(struct device *dev, const char *dev_name)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_device_find() - Find nvmem device with matching function
 *
 * @data: Data to pass to match function
 * @match: Callback function to check device
 *
 * Return: ERR_PTR() on error or a valid pointer to a struct nvmem_device
 * on success.
 */
struct nvmem_device *nvmem_device_find(void *data,
			int (*match)(struct device *dev, const void *data))
{}
EXPORT_SYMBOL_GPL();

static int devm_nvmem_device_match(struct device *dev, void *res, void *data)
{}

static void devm_nvmem_device_release(struct device *dev, void *res)
{}

/**
 * devm_nvmem_device_put() - put alredy got nvmem device
 *
 * @dev: Device that uses the nvmem device.
 * @nvmem: pointer to nvmem device allocated by devm_nvmem_cell_get(),
 * that needs to be released.
 */
void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_device_put() - put alredy got nvmem device
 *
 * @nvmem: pointer to nvmem device that needs to be released.
 */
void nvmem_device_put(struct nvmem_device *nvmem)
{}
EXPORT_SYMBOL_GPL();

/**
 * devm_nvmem_device_get() - Get nvmem cell of device form a given id
 *
 * @dev: Device that requests the nvmem device.
 * @id: name id for the requested nvmem device.
 *
 * Return: ERR_PTR() on error or a valid pointer to a struct nvmem_cell
 * on success.  The nvmem_cell will be freed by the automatically once the
 * device is freed.
 */
struct nvmem_device *devm_nvmem_device_get(struct device *dev, const char *id)
{}
EXPORT_SYMBOL_GPL();

static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry,
					    const char *id, int index)
{}

static struct nvmem_cell *
nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
{}

static void nvmem_layout_module_put(struct nvmem_device *nvmem)
{}

#if IS_ENABLED(CONFIG_OF)
static struct nvmem_cell_entry *
nvmem_find_cell_entry_by_node(struct nvmem_device *nvmem, struct device_node *np)
{}

static int nvmem_layout_module_get_optional(struct nvmem_device *nvmem)
{}

/**
 * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id
 *
 * @np: Device tree node that uses the nvmem cell.
 * @id: nvmem cell name from nvmem-cell-names property, or NULL
 *      for the cell at index 0 (the lone cell with no accompanying
 *      nvmem-cell-names property).
 *
 * Return: Will be an ERR_PTR() on error or a valid pointer
 * to a struct nvmem_cell.  The nvmem_cell will be freed by the
 * nvmem_cell_put().
 */
struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
{}
EXPORT_SYMBOL_GPL();
#endif

/**
 * nvmem_cell_get() - Get nvmem cell of device form a given cell name
 *
 * @dev: Device that requests the nvmem cell.
 * @id: nvmem cell name to get (this corresponds with the name from the
 *      nvmem-cell-names property for DT systems and with the con_id from
 *      the lookup entry for non-DT systems).
 *
 * Return: Will be an ERR_PTR() on error or a valid pointer
 * to a struct nvmem_cell.  The nvmem_cell will be freed by the
 * nvmem_cell_put().
 */
struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id)
{}
EXPORT_SYMBOL_GPL();

static void devm_nvmem_cell_release(struct device *dev, void *res)
{}

/**
 * devm_nvmem_cell_get() - Get nvmem cell of device form a given id
 *
 * @dev: Device that requests the nvmem cell.
 * @id: nvmem cell name id to get.
 *
 * Return: Will be an ERR_PTR() on error or a valid pointer
 * to a struct nvmem_cell.  The nvmem_cell will be freed by the
 * automatically once the device is freed.
 */
struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id)
{}
EXPORT_SYMBOL_GPL();

static int devm_nvmem_cell_match(struct device *dev, void *res, void *data)
{}

/**
 * devm_nvmem_cell_put() - Release previously allocated nvmem cell
 * from devm_nvmem_cell_get.
 *
 * @dev: Device that requests the nvmem cell.
 * @cell: Previously allocated nvmem cell by devm_nvmem_cell_get().
 */
void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell)
{}
EXPORT_SYMBOL();

/**
 * nvmem_cell_put() - Release previously allocated nvmem cell.
 *
 * @cell: Previously allocated nvmem cell by nvmem_cell_get().
 */
void nvmem_cell_put(struct nvmem_cell *cell)
{}
EXPORT_SYMBOL_GPL();

static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void *buf)
{}

static int __nvmem_cell_read(struct nvmem_device *nvmem,
			     struct nvmem_cell_entry *cell,
			     void *buf, size_t *len, const char *id, int index)
{}

/**
 * nvmem_cell_read() - Read a given nvmem cell
 *
 * @cell: nvmem cell to be read.
 * @len: pointer to length of cell which will be populated on successful read;
 *	 can be NULL.
 *
 * Return: ERR_PTR() on error or a valid pointer to a buffer on success. The
 * buffer should be freed by the consumer with a kfree().
 */
void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
{}
EXPORT_SYMBOL_GPL();

static void *nvmem_cell_prepare_write_buffer(struct nvmem_cell_entry *cell,
					     u8 *_buf, int len)
{}

static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, size_t len)
{}

/**
 * nvmem_cell_write() - Write to a given nvmem cell
 *
 * @cell: nvmem cell to be written.
 * @buf: Buffer to be written.
 * @len: length of buffer to be written to nvmem cell.
 *
 * Return: length of bytes written or negative on failure.
 */
int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len)
{}

EXPORT_SYMBOL_GPL();

static int nvmem_cell_read_common(struct device *dev, const char *cell_id,
				  void *val, size_t count)
{}

/**
 * nvmem_cell_read_u8() - Read a cell value as a u8
 *
 * @dev: Device that requests the nvmem cell.
 * @cell_id: Name of nvmem cell to read.
 * @val: pointer to output value.
 *
 * Return: 0 on success or negative errno.
 */
int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_cell_read_u16() - Read a cell value as a u16
 *
 * @dev: Device that requests the nvmem cell.
 * @cell_id: Name of nvmem cell to read.
 * @val: pointer to output value.
 *
 * Return: 0 on success or negative errno.
 */
int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_cell_read_u32() - Read a cell value as a u32
 *
 * @dev: Device that requests the nvmem cell.
 * @cell_id: Name of nvmem cell to read.
 * @val: pointer to output value.
 *
 * Return: 0 on success or negative errno.
 */
int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_cell_read_u64() - Read a cell value as a u64
 *
 * @dev: Device that requests the nvmem cell.
 * @cell_id: Name of nvmem cell to read.
 * @val: pointer to output value.
 *
 * Return: 0 on success or negative errno.
 */
int nvmem_cell_read_u64(struct device *dev, const char *cell_id, u64 *val)
{}
EXPORT_SYMBOL_GPL();

static const void *nvmem_cell_read_variable_common(struct device *dev,
						   const char *cell_id,
						   size_t max_len, size_t *len)
{}

/**
 * nvmem_cell_read_variable_le_u32() - Read up to 32-bits of data as a little endian number.
 *
 * @dev: Device that requests the nvmem cell.
 * @cell_id: Name of nvmem cell to read.
 * @val: pointer to output value.
 *
 * Return: 0 on success or negative errno.
 */
int nvmem_cell_read_variable_le_u32(struct device *dev, const char *cell_id,
				    u32 *val)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_cell_read_variable_le_u64() - Read up to 64-bits of data as a little endian number.
 *
 * @dev: Device that requests the nvmem cell.
 * @cell_id: Name of nvmem cell to read.
 * @val: pointer to output value.
 *
 * Return: 0 on success or negative errno.
 */
int nvmem_cell_read_variable_le_u64(struct device *dev, const char *cell_id,
				    u64 *val)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_device_cell_read() - Read a given nvmem device and cell
 *
 * @nvmem: nvmem device to read from.
 * @info: nvmem cell info to be read.
 * @buf: buffer pointer which will be populated on successful read.
 *
 * Return: length of successful bytes read on success and negative
 * error code on error.
 */
ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
			   struct nvmem_cell_info *info, void *buf)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_device_cell_write() - Write cell to a given nvmem device
 *
 * @nvmem: nvmem device to be written to.
 * @info: nvmem cell info to be written.
 * @buf: buffer to be written to cell.
 *
 * Return: length of bytes written or negative error code on failure.
 */
int nvmem_device_cell_write(struct nvmem_device *nvmem,
			    struct nvmem_cell_info *info, void *buf)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_device_read() - Read from a given nvmem device
 *
 * @nvmem: nvmem device to read from.
 * @offset: offset in nvmem device.
 * @bytes: number of bytes to read.
 * @buf: buffer pointer which will be populated on successful read.
 *
 * Return: length of successful bytes read on success and negative
 * error code on error.
 */
int nvmem_device_read(struct nvmem_device *nvmem,
		      unsigned int offset,
		      size_t bytes, void *buf)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_device_write() - Write cell to a given nvmem device
 *
 * @nvmem: nvmem device to be written to.
 * @offset: offset in nvmem device.
 * @bytes: number of bytes to write.
 * @buf: buffer to be written.
 *
 * Return: length of bytes written or negative error code on failure.
 */
int nvmem_device_write(struct nvmem_device *nvmem,
		       unsigned int offset,
		       size_t bytes, void *buf)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_add_cell_table() - register a table of cell info entries
 *
 * @table: table of cell info entries
 */
void nvmem_add_cell_table(struct nvmem_cell_table *table)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_del_cell_table() - remove a previously registered cell info table
 *
 * @table: table of cell info entries
 */
void nvmem_del_cell_table(struct nvmem_cell_table *table)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_add_cell_lookups() - register a list of cell lookup entries
 *
 * @entries: array of cell lookup entries
 * @nentries: number of cell lookup entries in the array
 */
void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_del_cell_lookups() - remove a list of previously added cell lookup
 *                            entries
 *
 * @entries: array of cell lookup entries
 * @nentries: number of cell lookup entries in the array
 */
void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_dev_name() - Get the name of a given nvmem device.
 *
 * @nvmem: nvmem device.
 *
 * Return: name of the nvmem device.
 */
const char *nvmem_dev_name(struct nvmem_device *nvmem)
{}
EXPORT_SYMBOL_GPL();

/**
 * nvmem_dev_size() - Get the size of a given nvmem device.
 *
 * @nvmem: nvmem device.
 *
 * Return: size of the nvmem device.
 */
size_t nvmem_dev_size(struct nvmem_device *nvmem)
{}
EXPORT_SYMBOL_GPL();

static int __init nvmem_init(void)
{}

static void __exit nvmem_exit(void)
{}

subsys_initcall(nvmem_init);
module_exit(nvmem_exit);

MODULE_AUTHOR();
MODULE_AUTHOR();
MODULE_DESCRIPTION();