blob: 497706f5adcacc5db666a3099931bb45d0fbfc28 [file] [log] [blame]
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +01001/*
2 * nvmem framework provider.
3 *
4 * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
5 * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com>
6 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10 */
11
12#ifndef _LINUX_NVMEM_PROVIDER_H
13#define _LINUX_NVMEM_PROVIDER_H
14
Arnd Bergmann42a6e092017-07-10 13:22:50 +020015#include <linux/err.h>
16#include <linux/errno.h>
17
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +010018struct nvmem_device;
19struct nvmem_cell_info;
Srinivas Kandagatla795ddd12016-04-24 20:28:05 +010020typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
21 void *val, size_t bytes);
22typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
23 void *val, size_t bytes);
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +010024
25struct nvmem_config {
26 struct device *dev;
27 const char *name;
28 int id;
29 struct module *owner;
30 const struct nvmem_cell_info *cells;
31 int ncells;
32 bool read_only;
Andrew Lunn811b0d62016-02-26 20:59:18 +010033 bool root_only;
Srinivas Kandagatla795ddd12016-04-24 20:28:05 +010034 nvmem_reg_read_t reg_read;
35 nvmem_reg_write_t reg_write;
36 int size;
37 int word_size;
38 int stride;
39 void *priv;
Andrew Lunnb6c217a2016-02-26 20:59:19 +010040 /* To be only used by old driver/misc/eeprom drivers */
41 bool compat;
42 struct device *base_dev;
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +010043};
44
45#if IS_ENABLED(CONFIG_NVMEM)
46
47struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
48int nvmem_unregister(struct nvmem_device *nvmem);
49
50#else
51
52static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
53{
54 return ERR_PTR(-ENOSYS);
55}
56
57static inline int nvmem_unregister(struct nvmem_device *nvmem)
58{
59 return -ENOSYS;
60}
61
62#endif /* CONFIG_NVMEM */
Srinivas Kandagatlaeace75c2015-07-27 12:13:19 +010063#endif /* ifndef _LINUX_NVMEM_PROVIDER_H */