Skip to content

Commit aa37902

Browse files
alexandrebellonipopcornmix
authored andcommitted
nvmem: add type attribute
commit 1668845 upstream. 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 <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent bd9250c commit aa37902

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
@@ -36,6 +36,7 @@ struct nvmem_device {
3636
size_t size;
3737
bool read_only;
3838
int flags;
39+
enum nvmem_type type;
3940
struct bin_attribute eeprom;
4041
struct device *base_dev;
4142
nvmem_reg_read_t reg_read;
@@ -84,6 +85,21 @@ static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
8485
return -EINVAL;
8586
}
8687

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

170186
static const struct attribute_group nvmem_bin_rw_group = {
171187
.bin_attrs = nvmem_bin_rw_attributes,
188+
.attrs = nvmem_attrs,
172189
};
173190

174191
static const struct attribute_group *nvmem_rw_dev_groups[] = {
@@ -192,6 +209,7 @@ static struct bin_attribute *nvmem_bin_ro_attributes[] = {
192209

193210
static const struct attribute_group nvmem_bin_ro_group = {
194211
.bin_attrs = nvmem_bin_ro_attributes,
212+
.attrs = nvmem_attrs,
195213
};
196214

197215
static const struct attribute_group *nvmem_ro_dev_groups[] = {
@@ -216,6 +234,7 @@ static struct bin_attribute *nvmem_bin_rw_root_attributes[] = {
216234

217235
static const struct attribute_group nvmem_bin_rw_root_group = {
218236
.bin_attrs = nvmem_bin_rw_root_attributes,
237+
.attrs = nvmem_attrs,
219238
};
220239

221240
static const struct attribute_group *nvmem_rw_root_dev_groups[] = {
@@ -239,6 +258,7 @@ static struct bin_attribute *nvmem_bin_ro_root_attributes[] = {
239258

240259
static const struct attribute_group nvmem_bin_ro_root_group = {
241260
.bin_attrs = nvmem_bin_ro_root_attributes,
261+
.attrs = nvmem_attrs,
242262
};
243263

244264
static const struct attribute_group *nvmem_ro_root_dev_groups[] = {
@@ -478,6 +498,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
478498
nvmem->dev.bus = &nvmem_bus_type;
479499
nvmem->dev.parent = config->dev;
480500
nvmem->priv = config->priv;
501+
nvmem->type = config->type;
481502
nvmem->reg_read = config->reg_read;
482503
nvmem->reg_write = config->reg_write;
483504
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
@@ -22,6 +22,20 @@ typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
2222
typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
2323
void *val, size_t bytes);
2424

25+
enum nvmem_type {
26+
NVMEM_TYPE_UNKNOWN = 0,
27+
NVMEM_TYPE_EEPROM,
28+
NVMEM_TYPE_OTP,
29+
NVMEM_TYPE_BATTERY_BACKED,
30+
};
31+
32+
static const char * const nvmem_type_str[] = {
33+
[NVMEM_TYPE_UNKNOWN] = "Unknown",
34+
[NVMEM_TYPE_EEPROM] = "EEPROM",
35+
[NVMEM_TYPE_OTP] = "OTP",
36+
[NVMEM_TYPE_BATTERY_BACKED] = "Battery backed",
37+
};
38+
2539
/**
2640
* struct nvmem_config - NVMEM device configuration
2741
*
@@ -31,6 +45,7 @@ typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
3145
* @owner: Pointer to exporter module. Used for refcounting.
3246
* @cells: Optional array of pre-defined NVMEM cells.
3347
* @ncells: Number of elements in cells.
48+
* @type: Type of the nvmem storage
3449
* @read_only: Device is read-only.
3550
* @root_only: Device is accessibly to root only.
3651
* @reg_read: Callback to read data.
@@ -54,6 +69,7 @@ struct nvmem_config {
5469
struct module *owner;
5570
const struct nvmem_cell_info *cells;
5671
int ncells;
72+
enum nvmem_type type;
5773
bool read_only;
5874
bool root_only;
5975
nvmem_reg_read_t reg_read;

0 commit comments

Comments
 (0)