]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - include/linux/nvmem-provider.h
Merge branch 'for-5.0' of https://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[thirdparty/kernel/stable.git] / include / linux / nvmem-provider.h
CommitLineData
b1c1db98 1/* SPDX-License-Identifier: GPL-2.0 */
eace75cf
SK
2/*
3 * nvmem framework provider.
4 *
5 * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
6 * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com>
eace75cf
SK
7 */
8
9#ifndef _LINUX_NVMEM_PROVIDER_H
10#define _LINUX_NVMEM_PROVIDER_H
11
42a6e099
AB
12#include <linux/err.h>
13#include <linux/errno.h>
14
eace75cf
SK
15struct nvmem_device;
16struct nvmem_cell_info;
795ddd18
SK
17typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
18 void *val, size_t bytes);
19typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
20 void *val, size_t bytes);
eace75cf 21
16688453
AB
22enum nvmem_type {
23 NVMEM_TYPE_UNKNOWN = 0,
24 NVMEM_TYPE_EEPROM,
25 NVMEM_TYPE_OTP,
26 NVMEM_TYPE_BATTERY_BACKED,
27};
28
0b2ed745
AS
29/**
30 * struct nvmem_config - NVMEM device configuration
31 *
32 * @dev: Parent device.
33 * @name: Optional name.
34 * @id: Optional device ID used in full name. Ignored if name is NULL.
35 * @owner: Pointer to exporter module. Used for refcounting.
36 * @cells: Optional array of pre-defined NVMEM cells.
37 * @ncells: Number of elements in cells.
16688453 38 * @type: Type of the nvmem storage
0b2ed745
AS
39 * @read_only: Device is read-only.
40 * @root_only: Device is accessibly to root only.
517f14d9 41 * @no_of_node: Device should not use the parent's of_node even if it's !NULL.
0b2ed745
AS
42 * @reg_read: Callback to read data.
43 * @reg_write: Callback to write data.
44 * @size: Device size.
45 * @word_size: Minimum read/write access granularity.
46 * @stride: Minimum read/write access stride.
47 * @priv: User context passed to read/write callbacks.
48 *
49 * Note: A default "nvmem<id>" name will be assigned to the device if
50 * no name is specified in its configuration. In such case "<id>" is
51 * generated with ida_simple_get() and provided id field is ignored.
fd0f4906
AS
52 *
53 * Note: Specifying name and setting id to -1 implies a unique device
54 * whose name is provided as-is (kept unaltered).
0b2ed745 55 */
eace75cf
SK
56struct nvmem_config {
57 struct device *dev;
58 const char *name;
59 int id;
60 struct module *owner;
61 const struct nvmem_cell_info *cells;
62 int ncells;
16688453 63 enum nvmem_type type;
eace75cf 64 bool read_only;
811b0d65 65 bool root_only;
517f14d9 66 bool no_of_node;
795ddd18
SK
67 nvmem_reg_read_t reg_read;
68 nvmem_reg_write_t reg_write;
69 int size;
70 int word_size;
71 int stride;
72 void *priv;
b6c217ab
AL
73 /* To be only used by old driver/misc/eeprom drivers */
74 bool compat;
75 struct device *base_dev;
eace75cf
SK
76};
77
b985f4cb
BG
78/**
79 * struct nvmem_cell_table - NVMEM cell definitions for given provider
80 *
81 * @nvmem_name: Provider name.
82 * @cells: Array of cell definitions.
83 * @ncells: Number of cell definitions in the array.
84 * @node: List node.
85 *
86 * This structure together with related helper functions is provided for users
87 * that don't can't access the nvmem provided structure but wish to register
88 * cell definitions for it e.g. board files registering an EEPROM device.
89 */
90struct nvmem_cell_table {
91 const char *nvmem_name;
92 const struct nvmem_cell_info *cells;
93 size_t ncells;
94 struct list_head node;
95};
96
eace75cf
SK
97#if IS_ENABLED(CONFIG_NVMEM)
98
99struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
bf58e882 100void nvmem_unregister(struct nvmem_device *nvmem);
eace75cf 101
f1f50eca
AS
102struct nvmem_device *devm_nvmem_register(struct device *dev,
103 const struct nvmem_config *cfg);
104
105int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
106
b985f4cb
BG
107void nvmem_add_cell_table(struct nvmem_cell_table *table);
108void nvmem_del_cell_table(struct nvmem_cell_table *table);
109
eace75cf
SK
110#else
111
112static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
113{
20167b70 114 return ERR_PTR(-EOPNOTSUPP);
eace75cf
SK
115}
116
bf58e882 117static inline void nvmem_unregister(struct nvmem_device *nvmem) {}
eace75cf 118
f1f50eca
AS
119static inline struct nvmem_device *
120devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
121{
122 return nvmem_register(c);
123}
124
125static inline int
126devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
127{
20167b70 128 return -EOPNOTSUPP;
b3db17e4
AL
129}
130
b985f4cb
BG
131static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {}
132static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
f1f50eca 133
eace75cf 134#endif /* CONFIG_NVMEM */
eace75cf 135#endif /* ifndef _LINUX_NVMEM_PROVIDER_H */