Skip to content

Commit 1668845

Browse files
alexandrebellonigregkh
authored andcommitted
nvmem: add type attribute
Add a type attribute so userspace is able to know how the data is stored as this can help taking the correct decision when selecting which device to use. This will also help program display the proper warnings when burning fuses for example. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ecd589d commit 1668845

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

drivers/nvmem/core.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct nvmem_device {
2828
size_t size;
2929
bool read_only;
3030
int flags;
31+
enum nvmem_type type;
3132
struct bin_attribute eeprom;
3233
struct device *base_dev;
3334
struct list_head cells;
@@ -83,6 +84,21 @@ static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
8384
return -EINVAL;
8485
}
8586

87+
static ssize_t type_show(struct device *dev,
88+
struct device_attribute *attr, char *buf)
89+
{
90+
struct nvmem_device *nvmem = to_nvmem_device(dev);
91+
92+
return sprintf(buf, "%s\n", nvmem_type_str[nvmem->type]);
93+
}
94+
95+
static DEVICE_ATTR_RO(type);
96+
97+
static struct attribute *nvmem_attrs[] = {
98+
&dev_attr_type.attr,
99+
NULL,
100+
};
101+
86102
static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
87103
struct bin_attribute *attr,
88104
char *buf, loff_t pos, size_t count)
@@ -168,6 +184,7 @@ static struct bin_attribute *nvmem_bin_rw_attributes[] = {
168184

169185
static const struct attribute_group nvmem_bin_rw_group = {
170186
.bin_attrs = nvmem_bin_rw_attributes,
187+
.attrs = nvmem_attrs,
171188
};
172189

173190
static const struct attribute_group *nvmem_rw_dev_groups[] = {
@@ -191,6 +208,7 @@ static struct bin_attribute *nvmem_bin_ro_attributes[] = {
191208

192209
static const struct attribute_group nvmem_bin_ro_group = {
193210
.bin_attrs = nvmem_bin_ro_attributes,
211+
.attrs = nvmem_attrs,
194212
};
195213

196214
static const struct attribute_group *nvmem_ro_dev_groups[] = {
@@ -215,6 +233,7 @@ static struct bin_attribute *nvmem_bin_rw_root_attributes[] = {
215233

216234
static const struct attribute_group nvmem_bin_rw_root_group = {
217235
.bin_attrs = nvmem_bin_rw_root_attributes,
236+
.attrs = nvmem_attrs,
218237
};
219238

220239
static const struct attribute_group *nvmem_rw_root_dev_groups[] = {
@@ -238,6 +257,7 @@ static struct bin_attribute *nvmem_bin_ro_root_attributes[] = {
238257

239258
static const struct attribute_group nvmem_bin_ro_root_group = {
240259
.bin_attrs = nvmem_bin_ro_root_attributes,
260+
.attrs = nvmem_attrs,
241261
};
242262

243263
static const struct attribute_group *nvmem_ro_root_dev_groups[] = {
@@ -605,6 +625,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
605625
nvmem->dev.bus = &nvmem_bus_type;
606626
nvmem->dev.parent = config->dev;
607627
nvmem->priv = config->priv;
628+
nvmem->type = config->type;
608629
nvmem->reg_read = config->reg_read;
609630
nvmem->reg_write = config->reg_write;
610631
nvmem->dev.of_node = config->dev->of_node;

include/linux/nvmem-provider.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
1919
typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
2020
void *val, size_t bytes);
2121

22+
enum nvmem_type {
23+
NVMEM_TYPE_UNKNOWN = 0,
24+
NVMEM_TYPE_EEPROM,
25+
NVMEM_TYPE_OTP,
26+
NVMEM_TYPE_BATTERY_BACKED,
27+
};
28+
29+
static const char * const nvmem_type_str[] = {
30+
[NVMEM_TYPE_UNKNOWN] = "Unknown",
31+
[NVMEM_TYPE_EEPROM] = "EEPROM",
32+
[NVMEM_TYPE_OTP] = "OTP",
33+
[NVMEM_TYPE_BATTERY_BACKED] = "Battery backed",
34+
};
35+
2236
/**
2337
* struct nvmem_config - NVMEM device configuration
2438
*
@@ -28,6 +42,7 @@ typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
2842
* @owner: Pointer to exporter module. Used for refcounting.
2943
* @cells: Optional array of pre-defined NVMEM cells.
3044
* @ncells: Number of elements in cells.
45+
* @type: Type of the nvmem storage
3146
* @read_only: Device is read-only.
3247
* @root_only: Device is accessibly to root only.
3348
* @reg_read: Callback to read data.
@@ -51,6 +66,7 @@ struct nvmem_config {
5166
struct module *owner;
5267
const struct nvmem_cell_info *cells;
5368
int ncells;
69+
enum nvmem_type type;
5470
bool read_only;
5571
bool root_only;
5672
nvmem_reg_read_t reg_read;

0 commit comments

Comments
 (0)