brcm2708: add linux 4.19 support
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.19 / 950-0398-nvmem-add-type-attribute.patch
1 From 8d82ada47578fd867da43108fadcd77e3f57f056 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 398/703] nvmem: add type attribute
5
6 commit 16688453661b6d5159be558a1f8c1f54463a420f upstream.
7
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
11 fuses for example.
12
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>
16 ---
17 drivers/nvmem/core.c | 21 +++++++++++++++++++++
18 include/linux/nvmem-provider.h | 16 ++++++++++++++++
19 2 files changed, 37 insertions(+)
20
21 --- a/drivers/nvmem/core.c
22 +++ b/drivers/nvmem/core.c
23 @@ -36,6 +36,7 @@ struct nvmem_device {
24 size_t size;
25 bool read_only;
26 int flags;
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_
32 return -EINVAL;
33 }
34
35 +static ssize_t type_show(struct device *dev,
36 + struct device_attribute *attr, char *buf)
37 +{
38 + struct nvmem_device *nvmem = to_nvmem_device(dev);
39 +
40 + return sprintf(buf, "%s\n", nvmem_type_str[nvmem->type]);
41 +}
42 +
43 +static DEVICE_ATTR_RO(type);
44 +
45 +static struct attribute *nvmem_attrs[] = {
46 + &dev_attr_type.attr,
47 + NULL,
48 +};
49 +
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
54
55 static const struct attribute_group nvmem_bin_rw_group = {
56 .bin_attrs = nvmem_bin_rw_attributes,
57 + .attrs = nvmem_attrs,
58 };
59
60 static const struct attribute_group *nvmem_rw_dev_groups[] = {
61 @@ -192,6 +209,7 @@ static struct bin_attribute *nvmem_bin_r
62
63 static const struct attribute_group nvmem_bin_ro_group = {
64 .bin_attrs = nvmem_bin_ro_attributes,
65 + .attrs = nvmem_attrs,
66 };
67
68 static const struct attribute_group *nvmem_ro_dev_groups[] = {
69 @@ -216,6 +234,7 @@ static struct bin_attribute *nvmem_bin_r
70
71 static const struct attribute_group nvmem_bin_rw_root_group = {
72 .bin_attrs = nvmem_bin_rw_root_attributes,
73 + .attrs = nvmem_attrs,
74 };
75
76 static const struct attribute_group *nvmem_rw_root_dev_groups[] = {
77 @@ -239,6 +258,7 @@ static struct bin_attribute *nvmem_bin_r
78
79 static const struct attribute_group nvmem_bin_ro_root_group = {
80 .bin_attrs = nvmem_bin_ro_root_attributes,
81 + .attrs = nvmem_attrs,
82 };
83
84 static const struct attribute_group *nvmem_ro_root_dev_groups[] = {
85 @@ -478,6 +498,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);
98
99 +enum nvmem_type {
100 + NVMEM_TYPE_UNKNOWN = 0,
101 + NVMEM_TYPE_EEPROM,
102 + NVMEM_TYPE_OTP,
103 + NVMEM_TYPE_BATTERY_BACKED,
104 +};
105 +
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",
111 +};
112 +
113 /**
114 * struct nvmem_config - NVMEM device configuration
115 *
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;
127 int ncells;
128 + enum nvmem_type type;
129 bool read_only;
130 bool root_only;
131 nvmem_reg_read_t reg_read;