1 From c9e76146066660a2884e61216c1ce227cf509bf8 Mon Sep 17 00:00:00 2001
2 From: Alexandre Belloni <alexandre.belloni@bootlin.com>
3 Date: Fri, 30 Nov 2018 11:53:20 +0000
4 Subject: [PATCH] nvmem: add type attribute
6 commit 16688453661b6d5159be558a1f8c1f54463a420f upstream.
8 Add a type attribute so userspace is able to know how the data is stored as
9 this can help taking the correct decision when selecting which device to
10 use. This will also help program display the proper warnings when burning
13 Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
14 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
15 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
17 drivers/nvmem/core.c | 21 +++++++++++++++++++++
18 include/linux/nvmem-provider.h | 16 ++++++++++++++++
19 2 files changed, 37 insertions(+)
21 --- a/drivers/nvmem/core.c
22 +++ b/drivers/nvmem/core.c
23 @@ -36,6 +36,7 @@ struct nvmem_device {
27 + enum nvmem_type type;
28 struct bin_attribute eeprom;
29 struct device *base_dev;
30 nvmem_reg_read_t reg_read;
31 @@ -84,6 +85,21 @@ static int nvmem_reg_write(struct nvmem_
35 +static ssize_t type_show(struct device *dev,
36 + struct device_attribute *attr, char *buf)
38 + struct nvmem_device *nvmem = to_nvmem_device(dev);
40 + return sprintf(buf, "%s\n", nvmem_type_str[nvmem->type]);
43 +static DEVICE_ATTR_RO(type);
45 +static struct attribute *nvmem_attrs[] = {
46 + &dev_attr_type.attr,
50 static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
51 struct bin_attribute *attr,
52 char *buf, loff_t pos, size_t count)
53 @@ -169,6 +185,7 @@ static struct bin_attribute *nvmem_bin_r
55 static const struct attribute_group nvmem_bin_rw_group = {
56 .bin_attrs = nvmem_bin_rw_attributes,
57 + .attrs = nvmem_attrs,
60 static const struct attribute_group *nvmem_rw_dev_groups[] = {
61 @@ -192,6 +209,7 @@ static struct bin_attribute *nvmem_bin_r
63 static const struct attribute_group nvmem_bin_ro_group = {
64 .bin_attrs = nvmem_bin_ro_attributes,
65 + .attrs = nvmem_attrs,
68 static const struct attribute_group *nvmem_ro_dev_groups[] = {
69 @@ -216,6 +234,7 @@ static struct bin_attribute *nvmem_bin_r
71 static const struct attribute_group nvmem_bin_rw_root_group = {
72 .bin_attrs = nvmem_bin_rw_root_attributes,
73 + .attrs = nvmem_attrs,
76 static const struct attribute_group *nvmem_rw_root_dev_groups[] = {
77 @@ -239,6 +258,7 @@ static struct bin_attribute *nvmem_bin_r
79 static const struct attribute_group nvmem_bin_ro_root_group = {
80 .bin_attrs = nvmem_bin_ro_root_attributes,
81 + .attrs = nvmem_attrs,
84 static const struct attribute_group *nvmem_ro_root_dev_groups[] = {
85 @@ -485,6 +505,7 @@ struct nvmem_device *nvmem_register(cons
86 nvmem->dev.bus = &nvmem_bus_type;
87 nvmem->dev.parent = config->dev;
88 nvmem->priv = config->priv;
89 + nvmem->type = config->type;
90 nvmem->reg_read = config->reg_read;
91 nvmem->reg_write = config->reg_write;
92 nvmem->dev.of_node = config->dev->of_node;
93 --- a/include/linux/nvmem-provider.h
94 +++ b/include/linux/nvmem-provider.h
95 @@ -22,6 +22,20 @@ typedef int (*nvmem_reg_read_t)(void *pr
96 typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
97 void *val, size_t bytes);
100 + NVMEM_TYPE_UNKNOWN = 0,
103 + NVMEM_TYPE_BATTERY_BACKED,
106 +static const char * const nvmem_type_str[] = {
107 + [NVMEM_TYPE_UNKNOWN] = "Unknown",
108 + [NVMEM_TYPE_EEPROM] = "EEPROM",
109 + [NVMEM_TYPE_OTP] = "OTP",
110 + [NVMEM_TYPE_BATTERY_BACKED] = "Battery backed",
114 * struct nvmem_config - NVMEM device configuration
116 @@ -31,6 +45,7 @@ typedef int (*nvmem_reg_write_t)(void *p
117 * @owner: Pointer to exporter module. Used for refcounting.
118 * @cells: Optional array of pre-defined NVMEM cells.
119 * @ncells: Number of elements in cells.
120 + * @type: Type of the nvmem storage
121 * @read_only: Device is read-only.
122 * @root_only: Device is accessibly to root only.
123 * @reg_read: Callback to read data.
124 @@ -54,6 +69,7 @@ struct nvmem_config {
125 struct module *owner;
126 const struct nvmem_cell_info *cells;
128 + enum nvmem_type type;
131 nvmem_reg_read_t reg_read;