| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * nvmem framework provider. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org> |
|---|
| 5 | 6 | * 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 | 7 | */ |
|---|
| 11 | 8 | |
|---|
| 12 | 9 | #ifndef _LINUX_NVMEM_PROVIDER_H |
|---|
| .. | .. |
|---|
| 14 | 11 | |
|---|
| 15 | 12 | #include <linux/err.h> |
|---|
| 16 | 13 | #include <linux/errno.h> |
|---|
| 14 | +#include <linux/gpio/consumer.h> |
|---|
| 17 | 15 | |
|---|
| 18 | 16 | struct nvmem_device; |
|---|
| 19 | 17 | struct nvmem_cell_info; |
|---|
| .. | .. |
|---|
| 21 | 19 | void *val, size_t bytes); |
|---|
| 22 | 20 | typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset, |
|---|
| 23 | 21 | void *val, size_t bytes); |
|---|
| 22 | + |
|---|
| 23 | +enum nvmem_type { |
|---|
| 24 | + NVMEM_TYPE_UNKNOWN = 0, |
|---|
| 25 | + NVMEM_TYPE_EEPROM, |
|---|
| 26 | + NVMEM_TYPE_OTP, |
|---|
| 27 | + NVMEM_TYPE_BATTERY_BACKED, |
|---|
| 28 | +}; |
|---|
| 29 | + |
|---|
| 30 | +#define NVMEM_DEVID_NONE (-1) |
|---|
| 31 | +#define NVMEM_DEVID_AUTO (-2) |
|---|
| 24 | 32 | |
|---|
| 25 | 33 | /** |
|---|
| 26 | 34 | * struct nvmem_config - NVMEM device configuration |
|---|
| .. | .. |
|---|
| 31 | 39 | * @owner: Pointer to exporter module. Used for refcounting. |
|---|
| 32 | 40 | * @cells: Optional array of pre-defined NVMEM cells. |
|---|
| 33 | 41 | * @ncells: Number of elements in cells. |
|---|
| 42 | + * @type: Type of the nvmem storage |
|---|
| 34 | 43 | * @read_only: Device is read-only. |
|---|
| 35 | 44 | * @root_only: Device is accessibly to root only. |
|---|
| 45 | + * @no_of_node: Device should not use the parent's of_node even if it's !NULL. |
|---|
| 36 | 46 | * @reg_read: Callback to read data. |
|---|
| 37 | 47 | * @reg_write: Callback to write data. |
|---|
| 38 | 48 | * @size: Device size. |
|---|
| 39 | 49 | * @word_size: Minimum read/write access granularity. |
|---|
| 40 | 50 | * @stride: Minimum read/write access stride. |
|---|
| 41 | 51 | * @priv: User context passed to read/write callbacks. |
|---|
| 52 | + * @wp-gpio: Write protect pin |
|---|
| 42 | 53 | * |
|---|
| 43 | 54 | * Note: A default "nvmem<id>" name will be assigned to the device if |
|---|
| 44 | 55 | * no name is specified in its configuration. In such case "<id>" is |
|---|
| .. | .. |
|---|
| 52 | 63 | const char *name; |
|---|
| 53 | 64 | int id; |
|---|
| 54 | 65 | struct module *owner; |
|---|
| 66 | + struct gpio_desc *wp_gpio; |
|---|
| 55 | 67 | const struct nvmem_cell_info *cells; |
|---|
| 56 | 68 | int ncells; |
|---|
| 69 | + enum nvmem_type type; |
|---|
| 57 | 70 | bool read_only; |
|---|
| 58 | 71 | bool root_only; |
|---|
| 72 | + bool no_of_node; |
|---|
| 59 | 73 | nvmem_reg_read_t reg_read; |
|---|
| 60 | 74 | nvmem_reg_write_t reg_write; |
|---|
| 61 | 75 | int size; |
|---|
| .. | .. |
|---|
| 89 | 103 | #if IS_ENABLED(CONFIG_NVMEM) |
|---|
| 90 | 104 | |
|---|
| 91 | 105 | struct nvmem_device *nvmem_register(const struct nvmem_config *cfg); |
|---|
| 92 | | -int nvmem_unregister(struct nvmem_device *nvmem); |
|---|
| 106 | +void nvmem_unregister(struct nvmem_device *nvmem); |
|---|
| 93 | 107 | |
|---|
| 94 | 108 | struct nvmem_device *devm_nvmem_register(struct device *dev, |
|---|
| 95 | 109 | const struct nvmem_config *cfg); |
|---|
| .. | .. |
|---|
| 103 | 117 | |
|---|
| 104 | 118 | static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c) |
|---|
| 105 | 119 | { |
|---|
| 106 | | - return ERR_PTR(-ENOSYS); |
|---|
| 120 | + return ERR_PTR(-EOPNOTSUPP); |
|---|
| 107 | 121 | } |
|---|
| 108 | 122 | |
|---|
| 109 | | -static inline int nvmem_unregister(struct nvmem_device *nvmem) |
|---|
| 110 | | -{ |
|---|
| 111 | | - return -ENOSYS; |
|---|
| 112 | | -} |
|---|
| 123 | +static inline void nvmem_unregister(struct nvmem_device *nvmem) {} |
|---|
| 113 | 124 | |
|---|
| 114 | 125 | static inline struct nvmem_device * |
|---|
| 115 | 126 | devm_nvmem_register(struct device *dev, const struct nvmem_config *c) |
|---|
| .. | .. |
|---|
| 120 | 131 | static inline int |
|---|
| 121 | 132 | devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem) |
|---|
| 122 | 133 | { |
|---|
| 123 | | - return nvmem_unregister(nvmem); |
|---|
| 124 | | - |
|---|
| 134 | + return -EOPNOTSUPP; |
|---|
| 125 | 135 | } |
|---|
| 126 | 136 | |
|---|
| 127 | 137 | static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {} |
|---|