Lines Matching +full:nvmem +full:- +full:cells

1 // SPDX-License-Identifier: GPL-2.0
3 * nvmem framework core.
6 * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com>
16 #include <linux/nvmem-consumer.h>
17 #include <linux/nvmem-provider.h>
37 struct nvmem_device *nvmem; member
58 static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, in __nvmem_reg_read() argument
61 if (nvmem->reg_read) in __nvmem_reg_read()
62 return nvmem->reg_read(nvmem->priv, offset, val, bytes); in __nvmem_reg_read()
64 return -EINVAL; in __nvmem_reg_read()
67 static int __nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset, in __nvmem_reg_write() argument
72 if (nvmem->reg_write) { in __nvmem_reg_write()
73 gpiod_set_value_cansleep(nvmem->wp_gpio, 0); in __nvmem_reg_write()
74 ret = nvmem->reg_write(nvmem->priv, offset, val, bytes); in __nvmem_reg_write()
75 gpiod_set_value_cansleep(nvmem->wp_gpio, 1); in __nvmem_reg_write()
79 return -EINVAL; in __nvmem_reg_write()
82 static int nvmem_access_with_keepouts(struct nvmem_device *nvmem, in nvmem_access_with_keepouts() argument
89 const struct nvmem_keepout *keepout = nvmem->keepout; in nvmem_access_with_keepouts()
90 const struct nvmem_keepout *keepoutend = keepout + nvmem->nkeepout; in nvmem_access_with_keepouts()
97 while ((keepout < keepoutend) && (keepout->end <= offset)) in nvmem_access_with_keepouts()
102 if (offset < keepout->start) { in nvmem_access_with_keepouts()
103 kend = min(end, keepout->start); in nvmem_access_with_keepouts()
104 ksize = kend - offset; in nvmem_access_with_keepouts()
106 rc = __nvmem_reg_write(nvmem, offset, val, ksize); in nvmem_access_with_keepouts()
108 rc = __nvmem_reg_read(nvmem, offset, val, ksize); in nvmem_access_with_keepouts()
121 kend = min(end, keepout->end); in nvmem_access_with_keepouts()
122 ksize = kend - offset; in nvmem_access_with_keepouts()
124 memset(val, keepout->value, ksize); in nvmem_access_with_keepouts()
136 ksize = end - offset; in nvmem_access_with_keepouts()
138 return __nvmem_reg_write(nvmem, offset, val, ksize); in nvmem_access_with_keepouts()
140 return __nvmem_reg_read(nvmem, offset, val, ksize); in nvmem_access_with_keepouts()
146 static int nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, in nvmem_reg_read() argument
149 if (!nvmem->nkeepout) in nvmem_reg_read()
150 return __nvmem_reg_read(nvmem, offset, val, bytes); in nvmem_reg_read()
152 return nvmem_access_with_keepouts(nvmem, offset, val, bytes, false); in nvmem_reg_read()
155 static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset, in nvmem_reg_write() argument
158 if (!nvmem->nkeepout) in nvmem_reg_write()
159 return __nvmem_reg_write(nvmem, offset, val, bytes); in nvmem_reg_write()
161 return nvmem_access_with_keepouts(nvmem, offset, val, bytes, true); in nvmem_reg_write()
180 struct nvmem_device *nvmem = to_nvmem_device(dev); in type_show() local
182 return sysfs_emit(buf, "%s\n", nvmem_type_str[nvmem->type]); in type_show()
190 struct nvmem_device *nvmem = to_nvmem_device(dev); in force_ro_show() local
192 return sysfs_emit(buf, "%d\n", nvmem->read_only); in force_ro_show()
198 struct nvmem_device *nvmem = to_nvmem_device(dev); in force_ro_store() local
199 int ret = kstrtobool(buf, &nvmem->read_only); in force_ro_store()
220 struct nvmem_device *nvmem; in bin_attr_nvmem_read() local
223 if (attr->private) in bin_attr_nvmem_read()
224 dev = attr->private; in bin_attr_nvmem_read()
227 nvmem = to_nvmem_device(dev); in bin_attr_nvmem_read()
229 if (!IS_ALIGNED(pos, nvmem->stride)) in bin_attr_nvmem_read()
230 return -EINVAL; in bin_attr_nvmem_read()
232 if (count < nvmem->word_size) in bin_attr_nvmem_read()
233 return -EINVAL; in bin_attr_nvmem_read()
235 count = round_down(count, nvmem->word_size); in bin_attr_nvmem_read()
237 if (!nvmem->reg_read) in bin_attr_nvmem_read()
238 return -EPERM; in bin_attr_nvmem_read()
240 rc = nvmem_reg_read(nvmem, pos, buf, count); in bin_attr_nvmem_read()
253 struct nvmem_device *nvmem; in bin_attr_nvmem_write() local
256 if (attr->private) in bin_attr_nvmem_write()
257 dev = attr->private; in bin_attr_nvmem_write()
260 nvmem = to_nvmem_device(dev); in bin_attr_nvmem_write()
262 if (!IS_ALIGNED(pos, nvmem->stride)) in bin_attr_nvmem_write()
263 return -EINVAL; in bin_attr_nvmem_write()
265 if (count < nvmem->word_size) in bin_attr_nvmem_write()
266 return -EINVAL; in bin_attr_nvmem_write()
268 count = round_down(count, nvmem->word_size); in bin_attr_nvmem_write()
270 if (!nvmem->reg_write || nvmem->read_only) in bin_attr_nvmem_write()
271 return -EPERM; in bin_attr_nvmem_write()
273 rc = nvmem_reg_write(nvmem, pos, buf, count); in bin_attr_nvmem_write()
281 static umode_t nvmem_bin_attr_get_umode(struct nvmem_device *nvmem) in nvmem_bin_attr_get_umode() argument
285 if (!nvmem->root_only) in nvmem_bin_attr_get_umode()
288 if (!nvmem->read_only) in nvmem_bin_attr_get_umode()
291 if (!nvmem->reg_write) in nvmem_bin_attr_get_umode()
294 if (!nvmem->reg_read) in nvmem_bin_attr_get_umode()
305 struct nvmem_device *nvmem = to_nvmem_device(dev); in nvmem_bin_attr_is_visible() local
307 return nvmem_bin_attr_get_umode(nvmem); in nvmem_bin_attr_is_visible()
315 struct nvmem_device *nvmem = to_nvmem_device(dev); in nvmem_bin_attr_size() local
317 return nvmem->size; in nvmem_bin_attr_size()
324 struct nvmem_device *nvmem = to_nvmem_device(dev); in nvmem_attr_is_visible() local
328 * configuration as read-write. in nvmem_attr_is_visible()
329 * If the device is set as read-only by configuration, it in nvmem_attr_is_visible()
330 * can be forced into read-write mode using the 'force_ro' in nvmem_attr_is_visible()
333 if (attr == &dev_attr_force_ro.attr && !nvmem->reg_write) in nvmem_attr_is_visible()
336 return attr->mode; in nvmem_attr_is_visible()
351 entry = attr->private; in nvmem_cell_attr_read()
352 cell = nvmem_create_cell(entry, entry->name, 0); in nvmem_cell_attr_read()
357 return -EINVAL; in nvmem_cell_attr_read()
365 read_len = min_t(unsigned int, cell_sz - pos, count); in nvmem_cell_attr_read()
370 kfree_const(cell->id); in nvmem_cell_attr_read()
379 .name = "nvmem",
413 * nvmem_setup_compat() - Create an additional binary entry in
417 static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem, in nvmem_sysfs_setup_compat() argument
422 if (!config->compat) in nvmem_sysfs_setup_compat()
425 if (!config->base_dev) in nvmem_sysfs_setup_compat()
426 return -EINVAL; in nvmem_sysfs_setup_compat()
428 nvmem->eeprom = bin_attr_nvmem_eeprom_compat; in nvmem_sysfs_setup_compat()
429 if (config->type == NVMEM_TYPE_FRAM) in nvmem_sysfs_setup_compat()
430 nvmem->eeprom.attr.name = "fram"; in nvmem_sysfs_setup_compat()
431 nvmem->eeprom.attr.mode = nvmem_bin_attr_get_umode(nvmem); in nvmem_sysfs_setup_compat()
432 nvmem->eeprom.size = nvmem->size; in nvmem_sysfs_setup_compat()
434 nvmem->eeprom.attr.key = &eeprom_lock_key; in nvmem_sysfs_setup_compat()
436 nvmem->eeprom.private = &nvmem->dev; in nvmem_sysfs_setup_compat()
437 nvmem->base_dev = config->base_dev; in nvmem_sysfs_setup_compat()
439 rval = device_create_bin_file(nvmem->base_dev, &nvmem->eeprom); in nvmem_sysfs_setup_compat()
441 dev_err(&nvmem->dev, in nvmem_sysfs_setup_compat()
446 nvmem->flags |= FLAG_COMPAT; in nvmem_sysfs_setup_compat()
451 static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem, in nvmem_sysfs_remove_compat() argument
454 if (config->compat) in nvmem_sysfs_remove_compat()
455 device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); in nvmem_sysfs_remove_compat()
458 static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) in nvmem_populate_sysfs_cells() argument
461 .name = "cells", in nvmem_populate_sysfs_cells()
471 if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated) in nvmem_populate_sysfs_cells()
475 ncells = list_count_nodes(&nvmem->cells); in nvmem_populate_sysfs_cells()
476 pattrs = devm_kcalloc(&nvmem->dev, ncells + 1, in nvmem_populate_sysfs_cells()
479 ret = -ENOMEM; in nvmem_populate_sysfs_cells()
483 attrs = devm_kcalloc(&nvmem->dev, ncells, sizeof(struct bin_attribute), GFP_KERNEL); in nvmem_populate_sysfs_cells()
485 ret = -ENOMEM; in nvmem_populate_sysfs_cells()
490 list_for_each_entry(entry, &nvmem->cells, node) { in nvmem_populate_sysfs_cells()
492 attrs[i].attr.name = devm_kasprintf(&nvmem->dev, GFP_KERNEL, in nvmem_populate_sysfs_cells()
493 "%s@%x,%x", entry->name, in nvmem_populate_sysfs_cells()
494 entry->offset, in nvmem_populate_sysfs_cells()
495 entry->bit_offset); in nvmem_populate_sysfs_cells()
496 attrs[i].attr.mode = 0444 & nvmem_bin_attr_get_umode(nvmem); in nvmem_populate_sysfs_cells()
497 attrs[i].size = entry->bytes; in nvmem_populate_sysfs_cells()
501 ret = -ENOMEM; in nvmem_populate_sysfs_cells()
511 ret = device_add_group(&nvmem->dev, &group); in nvmem_populate_sysfs_cells()
515 nvmem->sysfs_cells_populated = true; in nvmem_populate_sysfs_cells()
525 static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem, in nvmem_sysfs_setup_compat() argument
528 return -ENOSYS; in nvmem_sysfs_setup_compat()
530 static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem, in nvmem_sysfs_remove_compat() argument
539 struct nvmem_device *nvmem = to_nvmem_device(dev); in nvmem_release() local
541 ida_free(&nvmem_ida, nvmem->id); in nvmem_release()
542 gpiod_put(nvmem->wp_gpio); in nvmem_release()
543 kfree(nvmem); in nvmem_release()
551 .name = "nvmem",
558 list_del(&cell->node); in nvmem_cell_entry_drop()
560 of_node_put(cell->np); in nvmem_cell_entry_drop()
561 kfree_const(cell->name); in nvmem_cell_entry_drop()
565 static void nvmem_device_remove_all_cells(const struct nvmem_device *nvmem) in nvmem_device_remove_all_cells() argument
569 list_for_each_entry_safe(cell, p, &nvmem->cells, node) in nvmem_device_remove_all_cells()
576 list_add_tail(&cell->node, &cell->nvmem->cells); in nvmem_cell_entry_add()
581 static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, in nvmem_cell_info_to_nvmem_cell_entry_nodup() argument
585 cell->nvmem = nvmem; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
586 cell->offset = info->offset; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
587 cell->raw_len = info->raw_len ?: info->bytes; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
588 cell->bytes = info->bytes; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
589 cell->name = info->name; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
590 cell->read_post_process = info->read_post_process; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
591 cell->priv = info->priv; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
593 cell->bit_offset = info->bit_offset; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
594 cell->nbits = info->nbits; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
595 cell->np = info->np; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
597 if (cell->nbits) { in nvmem_cell_info_to_nvmem_cell_entry_nodup()
598 cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset, in nvmem_cell_info_to_nvmem_cell_entry_nodup()
600 cell->raw_len = ALIGN(cell->bytes, nvmem->word_size); in nvmem_cell_info_to_nvmem_cell_entry_nodup()
603 if (!IS_ALIGNED(cell->offset, nvmem->stride)) { in nvmem_cell_info_to_nvmem_cell_entry_nodup()
604 dev_err(&nvmem->dev, in nvmem_cell_info_to_nvmem_cell_entry_nodup()
605 "cell %s unaligned to nvmem stride %d\n", in nvmem_cell_info_to_nvmem_cell_entry_nodup()
606 cell->name ?: "<unknown>", nvmem->stride); in nvmem_cell_info_to_nvmem_cell_entry_nodup()
607 return -EINVAL; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
610 if (!IS_ALIGNED(cell->raw_len, nvmem->word_size)) { in nvmem_cell_info_to_nvmem_cell_entry_nodup()
611 dev_err(&nvmem->dev, in nvmem_cell_info_to_nvmem_cell_entry_nodup()
612 "cell %s raw len %zd unaligned to nvmem word size %d\n", in nvmem_cell_info_to_nvmem_cell_entry_nodup()
613 cell->name ?: "<unknown>", cell->raw_len, in nvmem_cell_info_to_nvmem_cell_entry_nodup()
614 nvmem->word_size); in nvmem_cell_info_to_nvmem_cell_entry_nodup()
616 if (info->raw_len) in nvmem_cell_info_to_nvmem_cell_entry_nodup()
617 return -EINVAL; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
619 cell->raw_len = ALIGN(cell->raw_len, nvmem->word_size); in nvmem_cell_info_to_nvmem_cell_entry_nodup()
625 static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem, in nvmem_cell_info_to_nvmem_cell_entry() argument
631 err = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, cell); in nvmem_cell_info_to_nvmem_cell_entry()
635 cell->name = kstrdup_const(info->name, GFP_KERNEL); in nvmem_cell_info_to_nvmem_cell_entry()
636 if (!cell->name) in nvmem_cell_info_to_nvmem_cell_entry()
637 return -ENOMEM; in nvmem_cell_info_to_nvmem_cell_entry()
643 * nvmem_add_one_cell() - Add one cell information to an nvmem device
645 * @nvmem: nvmem device to add cells to.
646 * @info: nvmem cell info to add to the device
650 int nvmem_add_one_cell(struct nvmem_device *nvmem, in nvmem_add_one_cell() argument
658 return -ENOMEM; in nvmem_add_one_cell()
660 rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell); in nvmem_add_one_cell()
673 * nvmem_add_cells() - Add cell information to an nvmem device
675 * @nvmem: nvmem device to add cells to.
676 * @info: nvmem cell info to add to the device
677 * @ncells: number of cells in info
681 static int nvmem_add_cells(struct nvmem_device *nvmem, in nvmem_add_cells() argument
688 rval = nvmem_add_one_cell(nvmem, &info[i]); in nvmem_add_cells()
697 * nvmem_register_notifier() - Register a notifier block for nvmem events.
699 * @nb: notifier block to be called on nvmem events.
710 * nvmem_unregister_notifier() - Unregister a notifier block for nvmem events.
722 static int nvmem_add_cells_from_table(struct nvmem_device *nvmem) in nvmem_add_cells_from_table() argument
731 if (strcmp(nvmem_dev_name(nvmem), table->nvmem_name) == 0) { in nvmem_add_cells_from_table()
732 for (i = 0; i < table->ncells; i++) { in nvmem_add_cells_from_table()
733 info = &table->cells[i]; in nvmem_add_cells_from_table()
737 rval = -ENOMEM; in nvmem_add_cells_from_table()
741 rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell); in nvmem_add_cells_from_table()
758 nvmem_find_cell_entry_by_name(struct nvmem_device *nvmem, const char *cell_id) in nvmem_find_cell_entry_by_name() argument
763 list_for_each_entry(iter, &nvmem->cells, node) { in nvmem_find_cell_entry_by_name()
764 if (strcmp(cell_id, iter->name) == 0) { in nvmem_find_cell_entry_by_name()
774 static int nvmem_validate_keepouts(struct nvmem_device *nvmem) in nvmem_validate_keepouts() argument
777 const struct nvmem_keepout *keepout = nvmem->keepout; in nvmem_validate_keepouts()
778 const struct nvmem_keepout *keepoutend = keepout + nvmem->nkeepout; in nvmem_validate_keepouts()
782 if (keepout->start < cur) { in nvmem_validate_keepouts()
783 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
786 return -ERANGE; in nvmem_validate_keepouts()
789 if (keepout->end < keepout->start) { in nvmem_validate_keepouts()
790 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
793 return -EINVAL; in nvmem_validate_keepouts()
800 if ((keepout->end - keepout->start < nvmem->word_size) || in nvmem_validate_keepouts()
801 ((keepout->start != cur) && in nvmem_validate_keepouts()
802 (keepout->start - cur < nvmem->word_size))) { in nvmem_validate_keepouts()
804 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
807 return -ERANGE; in nvmem_validate_keepouts()
811 if (!IS_ALIGNED(keepout->start, nvmem->stride) || in nvmem_validate_keepouts()
812 !IS_ALIGNED(keepout->end, nvmem->stride)) { in nvmem_validate_keepouts()
814 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
817 return -EINVAL; in nvmem_validate_keepouts()
820 cur = keepout->end; in nvmem_validate_keepouts()
827 static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np) in nvmem_add_cells_from_dt() argument
829 struct device *dev = &nvmem->dev; in nvmem_add_cells_from_dt()
841 dev_err(dev, "nvmem: invalid reg on %pOF\n", child); in nvmem_add_cells_from_dt()
843 return -EINVAL; in nvmem_add_cells_from_dt()
857 dev_err(dev, "nvmem: invalid bits on %pOF\n", child); in nvmem_add_cells_from_dt()
859 return -EINVAL; in nvmem_add_cells_from_dt()
865 if (nvmem->fixup_dt_cell_info) in nvmem_add_cells_from_dt()
866 nvmem->fixup_dt_cell_info(nvmem, &info); in nvmem_add_cells_from_dt()
868 ret = nvmem_add_one_cell(nvmem, &info); in nvmem_add_cells_from_dt()
879 static int nvmem_add_cells_from_legacy_of(struct nvmem_device *nvmem) in nvmem_add_cells_from_legacy_of() argument
881 return nvmem_add_cells_from_dt(nvmem, nvmem->dev.of_node); in nvmem_add_cells_from_legacy_of()
884 static int nvmem_add_cells_from_fixed_layout(struct nvmem_device *nvmem) in nvmem_add_cells_from_fixed_layout() argument
889 layout_np = of_nvmem_layout_get_container(nvmem); in nvmem_add_cells_from_fixed_layout()
893 if (of_device_is_compatible(layout_np, "fixed-layout")) in nvmem_add_cells_from_fixed_layout()
894 err = nvmem_add_cells_from_dt(nvmem, layout_np); in nvmem_add_cells_from_fixed_layout()
905 if (!layout->add_cells) in nvmem_layout_register()
906 return -EINVAL; in nvmem_layout_register()
908 /* Populate the cells */ in nvmem_layout_register()
909 ret = layout->add_cells(layout); in nvmem_layout_register()
914 ret = nvmem_populate_sysfs_cells(layout->nvmem); in nvmem_layout_register()
916 nvmem_device_remove_all_cells(layout->nvmem); in nvmem_layout_register()
932 * nvmem_register() - Register a nvmem device for given nvmem_config.
933 * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
935 * @config: nvmem device configuration with which nvmem device is created.
943 struct nvmem_device *nvmem; in nvmem_register() local
946 if (!config->dev) in nvmem_register()
947 return ERR_PTR(-EINVAL); in nvmem_register()
949 if (!config->reg_read && !config->reg_write) in nvmem_register()
950 return ERR_PTR(-EINVAL); in nvmem_register()
952 nvmem = kzalloc(sizeof(*nvmem), GFP_KERNEL); in nvmem_register()
953 if (!nvmem) in nvmem_register()
954 return ERR_PTR(-ENOMEM); in nvmem_register()
958 kfree(nvmem); in nvmem_register()
962 nvmem->id = rval; in nvmem_register()
964 nvmem->dev.type = &nvmem_provider_type; in nvmem_register()
965 nvmem->dev.bus = &nvmem_bus_type; in nvmem_register()
966 nvmem->dev.parent = config->dev; in nvmem_register()
968 device_initialize(&nvmem->dev); in nvmem_register()
970 if (!config->ignore_wp) in nvmem_register()
971 nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", in nvmem_register()
973 if (IS_ERR(nvmem->wp_gpio)) { in nvmem_register()
974 rval = PTR_ERR(nvmem->wp_gpio); in nvmem_register()
975 nvmem->wp_gpio = NULL; in nvmem_register()
979 kref_init(&nvmem->refcnt); in nvmem_register()
980 INIT_LIST_HEAD(&nvmem->cells); in nvmem_register()
981 nvmem->fixup_dt_cell_info = config->fixup_dt_cell_info; in nvmem_register()
983 nvmem->owner = config->owner; in nvmem_register()
984 if (!nvmem->owner && config->dev->driver) in nvmem_register()
985 nvmem->owner = config->dev->driver->owner; in nvmem_register()
986 nvmem->stride = config->stride ?: 1; in nvmem_register()
987 nvmem->word_size = config->word_size ?: 1; in nvmem_register()
988 nvmem->size = config->size; in nvmem_register()
989 nvmem->root_only = config->root_only; in nvmem_register()
990 nvmem->priv = config->priv; in nvmem_register()
991 nvmem->type = config->type; in nvmem_register()
992 nvmem->reg_read = config->reg_read; in nvmem_register()
993 nvmem->reg_write = config->reg_write; in nvmem_register()
994 nvmem->keepout = config->keepout; in nvmem_register()
995 nvmem->nkeepout = config->nkeepout; in nvmem_register()
996 if (config->of_node) in nvmem_register()
997 nvmem->dev.of_node = config->of_node; in nvmem_register()
999 nvmem->dev.of_node = config->dev->of_node; in nvmem_register()
1001 switch (config->id) { in nvmem_register()
1003 rval = dev_set_name(&nvmem->dev, "%s", config->name); in nvmem_register()
1006 rval = dev_set_name(&nvmem->dev, "%s%d", config->name, nvmem->id); in nvmem_register()
1009 rval = dev_set_name(&nvmem->dev, "%s%d", in nvmem_register()
1010 config->name ? : "nvmem", in nvmem_register()
1011 config->name ? config->id : nvmem->id); in nvmem_register()
1018 nvmem->read_only = device_property_present(config->dev, "read-only") || in nvmem_register()
1019 config->read_only || !nvmem->reg_write; in nvmem_register()
1022 nvmem->dev.groups = nvmem_dev_groups; in nvmem_register()
1025 if (nvmem->nkeepout) { in nvmem_register()
1026 rval = nvmem_validate_keepouts(nvmem); in nvmem_register()
1031 if (config->compat) { in nvmem_register()
1032 rval = nvmem_sysfs_setup_compat(nvmem, config); in nvmem_register()
1037 if (config->cells) { in nvmem_register()
1038 rval = nvmem_add_cells(nvmem, config->cells, config->ncells); in nvmem_register()
1043 rval = nvmem_add_cells_from_table(nvmem); in nvmem_register()
1047 if (config->add_legacy_fixed_of_cells) { in nvmem_register()
1048 rval = nvmem_add_cells_from_legacy_of(nvmem); in nvmem_register()
1053 rval = nvmem_add_cells_from_fixed_layout(nvmem); in nvmem_register()
1057 dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); in nvmem_register()
1059 rval = device_add(&nvmem->dev); in nvmem_register()
1063 rval = nvmem_populate_layout(nvmem); in nvmem_register()
1068 rval = nvmem_populate_sysfs_cells(nvmem); in nvmem_register()
1073 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); in nvmem_register()
1075 return nvmem; in nvmem_register()
1079 nvmem_destroy_layout(nvmem); in nvmem_register()
1082 device_del(&nvmem->dev); in nvmem_register()
1084 nvmem_device_remove_all_cells(nvmem); in nvmem_register()
1085 if (config->compat) in nvmem_register()
1086 nvmem_sysfs_remove_compat(nvmem, config); in nvmem_register()
1088 put_device(&nvmem->dev); in nvmem_register()
1096 struct nvmem_device *nvmem; in nvmem_device_release() local
1098 nvmem = container_of(kref, struct nvmem_device, refcnt); in nvmem_device_release()
1100 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_REMOVE, nvmem); in nvmem_device_release()
1102 if (nvmem->flags & FLAG_COMPAT) in nvmem_device_release()
1103 device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); in nvmem_device_release()
1105 nvmem_device_remove_all_cells(nvmem); in nvmem_device_release()
1106 nvmem_destroy_layout(nvmem); in nvmem_device_release()
1107 device_unregister(&nvmem->dev); in nvmem_device_release()
1111 * nvmem_unregister() - Unregister previously registered nvmem device
1113 * @nvmem: Pointer to previously registered nvmem device.
1115 void nvmem_unregister(struct nvmem_device *nvmem) in nvmem_unregister() argument
1117 if (nvmem) in nvmem_unregister()
1118 kref_put(&nvmem->refcnt, nvmem_device_release); in nvmem_unregister()
1122 static void devm_nvmem_unregister(void *nvmem) in devm_nvmem_unregister() argument
1124 nvmem_unregister(nvmem); in devm_nvmem_unregister()
1128 * devm_nvmem_register() - Register a managed nvmem device for given
1130 * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
1132 * @dev: Device that uses the nvmem device.
1133 * @config: nvmem device configuration with which nvmem device is created.
1141 struct nvmem_device *nvmem; in devm_nvmem_register() local
1144 nvmem = nvmem_register(config); in devm_nvmem_register()
1145 if (IS_ERR(nvmem)) in devm_nvmem_register()
1146 return nvmem; in devm_nvmem_register()
1148 ret = devm_add_action_or_reset(dev, devm_nvmem_unregister, nvmem); in devm_nvmem_register()
1152 return nvmem; in devm_nvmem_register()
1159 struct nvmem_device *nvmem = NULL; in __nvmem_device_get() local
1165 nvmem = to_nvmem_device(dev); in __nvmem_device_get()
1167 if (!nvmem) in __nvmem_device_get()
1168 return ERR_PTR(-EPROBE_DEFER); in __nvmem_device_get()
1170 if (!try_module_get(nvmem->owner)) { in __nvmem_device_get()
1171 dev_err(&nvmem->dev, in __nvmem_device_get()
1173 nvmem_dev_name(nvmem)); in __nvmem_device_get()
1175 put_device(&nvmem->dev); in __nvmem_device_get()
1176 return ERR_PTR(-EINVAL); in __nvmem_device_get()
1179 kref_get(&nvmem->refcnt); in __nvmem_device_get()
1181 return nvmem; in __nvmem_device_get()
1184 static void __nvmem_device_put(struct nvmem_device *nvmem) in __nvmem_device_put() argument
1186 put_device(&nvmem->dev); in __nvmem_device_put()
1187 module_put(nvmem->owner); in __nvmem_device_put()
1188 kref_put(&nvmem->refcnt, nvmem_device_release); in __nvmem_device_put()
1193 * of_nvmem_device_get() - Get nvmem device from a given id
1195 * @np: Device tree node that uses the nvmem device.
1196 * @id: nvmem name from nvmem-names property.
1205 struct nvmem_device *nvmem; in of_nvmem_device_get() local
1209 index = of_property_match_string(np, "nvmem-names", id); in of_nvmem_device_get()
1211 nvmem_np = of_parse_phandle(np, "nvmem", index); in of_nvmem_device_get()
1213 return ERR_PTR(-ENOENT); in of_nvmem_device_get()
1215 nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); in of_nvmem_device_get()
1217 return nvmem; in of_nvmem_device_get()
1223 * nvmem_device_get() - Get nvmem device from a given id
1225 * @dev: Device that uses the nvmem device.
1226 * @dev_name: name of the requested nvmem device.
1233 if (dev->of_node) { /* try dt first */ in nvmem_device_get()
1234 struct nvmem_device *nvmem; in nvmem_device_get() local
1236 nvmem = of_nvmem_device_get(dev->of_node, dev_name); in nvmem_device_get()
1238 if (!IS_ERR(nvmem) || PTR_ERR(nvmem) == -EPROBE_DEFER) in nvmem_device_get()
1239 return nvmem; in nvmem_device_get()
1248 * nvmem_device_find() - Find nvmem device with matching function
1265 struct nvmem_device **nvmem = res; in devm_nvmem_device_match() local
1267 if (WARN_ON(!nvmem || !*nvmem)) in devm_nvmem_device_match()
1270 return *nvmem == data; in devm_nvmem_device_match()
1279 * devm_nvmem_device_put() - put already got nvmem device
1281 * @dev: Device that uses the nvmem device.
1282 * @nvmem: pointer to nvmem device allocated by devm_nvmem_cell_get(),
1285 void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem) in devm_nvmem_device_put() argument
1290 devm_nvmem_device_match, nvmem); in devm_nvmem_device_put()
1297 * nvmem_device_put() - put already got nvmem device
1299 * @nvmem: pointer to nvmem device that needs to be released.
1301 void nvmem_device_put(struct nvmem_device *nvmem) in nvmem_device_put() argument
1303 __nvmem_device_put(nvmem); in nvmem_device_put()
1308 * devm_nvmem_device_get() - Get nvmem device of device form a given id
1310 * @dev: Device that requests the nvmem device.
1311 * @id: name id for the requested nvmem device.
1319 struct nvmem_device **ptr, *nvmem; in devm_nvmem_device_get() local
1323 return ERR_PTR(-ENOMEM); in devm_nvmem_device_get()
1325 nvmem = nvmem_device_get(dev, id); in devm_nvmem_device_get()
1326 if (!IS_ERR(nvmem)) { in devm_nvmem_device_get()
1327 *ptr = nvmem; in devm_nvmem_device_get()
1333 return nvmem; in devm_nvmem_device_get()
1345 return ERR_PTR(-ENOMEM); in nvmem_create_cell()
1351 return ERR_PTR(-ENOMEM); in nvmem_create_cell()
1355 cell->id = name; in nvmem_create_cell()
1356 cell->entry = entry; in nvmem_create_cell()
1357 cell->index = index; in nvmem_create_cell()
1366 struct nvmem_cell *cell = ERR_PTR(-ENOENT); in nvmem_cell_get_from_lookup()
1368 struct nvmem_device *nvmem; in nvmem_cell_get_from_lookup() local
1372 return ERR_PTR(-EINVAL); in nvmem_cell_get_from_lookup()
1379 if ((strcmp(lookup->dev_id, dev_id) == 0) && in nvmem_cell_get_from_lookup()
1380 (strcmp(lookup->con_id, con_id) == 0)) { in nvmem_cell_get_from_lookup()
1382 nvmem = __nvmem_device_get((void *)lookup->nvmem_name, in nvmem_cell_get_from_lookup()
1384 if (IS_ERR(nvmem)) { in nvmem_cell_get_from_lookup()
1386 cell = ERR_CAST(nvmem); in nvmem_cell_get_from_lookup()
1390 cell_entry = nvmem_find_cell_entry_by_name(nvmem, in nvmem_cell_get_from_lookup()
1391 lookup->cell_name); in nvmem_cell_get_from_lookup()
1393 __nvmem_device_put(nvmem); in nvmem_cell_get_from_lookup()
1394 cell = ERR_PTR(-ENOENT); in nvmem_cell_get_from_lookup()
1398 __nvmem_device_put(nvmem); in nvmem_cell_get_from_lookup()
1408 static void nvmem_layout_module_put(struct nvmem_device *nvmem) in nvmem_layout_module_put() argument
1410 if (nvmem->layout && nvmem->layout->dev.driver) in nvmem_layout_module_put()
1411 module_put(nvmem->layout->dev.driver->owner); in nvmem_layout_module_put()
1416 nvmem_find_cell_entry_by_node(struct nvmem_device *nvmem, struct device_node *np) in nvmem_find_cell_entry_by_node() argument
1421 list_for_each_entry(iter, &nvmem->cells, node) { in nvmem_find_cell_entry_by_node()
1422 if (np == iter->np) { in nvmem_find_cell_entry_by_node()
1432 static int nvmem_layout_module_get_optional(struct nvmem_device *nvmem) in nvmem_layout_module_get_optional() argument
1434 if (!nvmem->layout) in nvmem_layout_module_get_optional()
1437 if (!nvmem->layout->dev.driver || in nvmem_layout_module_get_optional()
1438 !try_module_get(nvmem->layout->dev.driver->owner)) in nvmem_layout_module_get_optional()
1439 return -EPROBE_DEFER; in nvmem_layout_module_get_optional()
1445 * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id
1447 * @np: Device tree node that uses the nvmem cell.
1448 * @id: nvmem cell name from nvmem-cell-names property, or NULL
1450 * nvmem-cell-names property).
1459 struct nvmem_device *nvmem; in of_nvmem_cell_get() local
1469 index = of_property_match_string(np, "nvmem-cell-names", id); in of_nvmem_cell_get()
1471 ret = of_parse_phandle_with_optional_args(np, "nvmem-cells", in of_nvmem_cell_get()
1472 "#nvmem-cell-cells", in of_nvmem_cell_get()
1475 return ERR_PTR(-ENOENT); in of_nvmem_cell_get()
1478 return ERR_PTR(-EINVAL); in of_nvmem_cell_get()
1487 return ERR_PTR(-EINVAL); in of_nvmem_cell_get()
1490 /* nvmem layouts produce cells within the nvmem-layout container */ in of_nvmem_cell_get()
1491 if (of_node_name_eq(nvmem_np, "nvmem-layout")) { in of_nvmem_cell_get()
1495 return ERR_PTR(-EINVAL); in of_nvmem_cell_get()
1499 nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); in of_nvmem_cell_get()
1501 if (IS_ERR(nvmem)) { in of_nvmem_cell_get()
1503 return ERR_CAST(nvmem); in of_nvmem_cell_get()
1506 ret = nvmem_layout_module_get_optional(nvmem); in of_nvmem_cell_get()
1509 __nvmem_device_put(nvmem); in of_nvmem_cell_get()
1513 cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np); in of_nvmem_cell_get()
1516 __nvmem_device_put(nvmem); in of_nvmem_cell_get()
1517 nvmem_layout_module_put(nvmem); in of_nvmem_cell_get()
1518 if (nvmem->layout) in of_nvmem_cell_get()
1519 return ERR_PTR(-EPROBE_DEFER); in of_nvmem_cell_get()
1521 return ERR_PTR(-ENOENT); in of_nvmem_cell_get()
1526 __nvmem_device_put(nvmem); in of_nvmem_cell_get()
1527 nvmem_layout_module_put(nvmem); in of_nvmem_cell_get()
1536 * nvmem_cell_get() - Get nvmem cell of device form a given cell name
1538 * @dev: Device that requests the nvmem cell.
1539 * @id: nvmem cell name to get (this corresponds with the name from the
1540 * nvmem-cell-names property for DT systems and with the con_id from
1541 * the lookup entry for non-DT systems).
1551 if (dev->of_node) { /* try dt first */ in nvmem_cell_get()
1552 cell = of_nvmem_cell_get(dev->of_node, id); in nvmem_cell_get()
1553 if (!IS_ERR(cell) || PTR_ERR(cell) == -EPROBE_DEFER) in nvmem_cell_get()
1559 return ERR_PTR(-EINVAL); in nvmem_cell_get()
1571 * devm_nvmem_cell_get() - Get nvmem cell of device form a given id
1573 * @dev: Device that requests the nvmem cell.
1574 * @id: nvmem cell name id to get.
1586 return ERR_PTR(-ENOMEM); in devm_nvmem_cell_get()
1611 * devm_nvmem_cell_put() - Release previously allocated nvmem cell
1614 * @dev: Device that requests the nvmem cell.
1615 * @cell: Previously allocated nvmem cell by devm_nvmem_cell_get().
1629 * nvmem_cell_put() - Release previously allocated nvmem cell.
1631 * @cell: Previously allocated nvmem cell by nvmem_cell_get().
1635 struct nvmem_device *nvmem = cell->entry->nvmem; in nvmem_cell_put() local
1637 if (cell->id) in nvmem_cell_put()
1638 kfree_const(cell->id); in nvmem_cell_put()
1641 __nvmem_device_put(nvmem); in nvmem_cell_put()
1642 nvmem_layout_module_put(nvmem); in nvmem_cell_put()
1650 int bit_offset = cell->bit_offset; in nvmem_shift_read_buffer_in_place()
1663 for (i = 1; i < cell->bytes; i++) { in nvmem_shift_read_buffer_in_place()
1665 *p++ |= *b << (BITS_PER_BYTE - bit_offset); in nvmem_shift_read_buffer_in_place()
1670 memmove(p, b, cell->bytes - bytes_offset); in nvmem_shift_read_buffer_in_place()
1671 p += cell->bytes - 1; in nvmem_shift_read_buffer_in_place()
1674 p += cell->bytes - 1; in nvmem_shift_read_buffer_in_place()
1678 extra = cell->bytes - DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE); in nvmem_shift_read_buffer_in_place()
1679 while (--extra >= 0) in nvmem_shift_read_buffer_in_place()
1680 *p-- = 0; in nvmem_shift_read_buffer_in_place()
1683 if (cell->nbits % BITS_PER_BYTE) in nvmem_shift_read_buffer_in_place()
1684 *p &= GENMASK((cell->nbits % BITS_PER_BYTE) - 1, 0); in nvmem_shift_read_buffer_in_place()
1687 static int __nvmem_cell_read(struct nvmem_device *nvmem, in __nvmem_cell_read() argument
1693 rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->raw_len); in __nvmem_cell_read()
1698 /* shift bits in-place */ in __nvmem_cell_read()
1699 if (cell->bit_offset || cell->nbits) in __nvmem_cell_read()
1702 if (cell->read_post_process) { in __nvmem_cell_read()
1703 rc = cell->read_post_process(cell->priv, id, index, in __nvmem_cell_read()
1704 cell->offset, buf, cell->raw_len); in __nvmem_cell_read()
1710 *len = cell->bytes; in __nvmem_cell_read()
1716 * nvmem_cell_read() - Read a given nvmem cell
1718 * @cell: nvmem cell to be read.
1727 struct nvmem_cell_entry *entry = cell->entry; in nvmem_cell_read()
1728 struct nvmem_device *nvmem = entry->nvmem; in nvmem_cell_read() local
1732 if (!nvmem) in nvmem_cell_read()
1733 return ERR_PTR(-EINVAL); in nvmem_cell_read()
1735 buf = kzalloc(max_t(size_t, entry->raw_len, entry->bytes), GFP_KERNEL); in nvmem_cell_read()
1737 return ERR_PTR(-ENOMEM); in nvmem_cell_read()
1739 rc = __nvmem_cell_read(nvmem, cell->entry, buf, len, cell->id, cell->index); in nvmem_cell_read()
1752 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_prepare_write_buffer() local
1753 int i, rc, nbits, bit_offset = cell->bit_offset; in nvmem_cell_prepare_write_buffer()
1756 nbits = cell->nbits; in nvmem_cell_prepare_write_buffer()
1757 buf = kzalloc(cell->bytes, GFP_KERNEL); in nvmem_cell_prepare_write_buffer()
1759 return ERR_PTR(-ENOMEM); in nvmem_cell_prepare_write_buffer()
1768 /* setup the first byte with lsb bits from nvmem */ in nvmem_cell_prepare_write_buffer()
1769 rc = nvmem_reg_read(nvmem, cell->offset, &v, 1); in nvmem_cell_prepare_write_buffer()
1772 *b++ |= GENMASK(bit_offset - 1, 0) & v; in nvmem_cell_prepare_write_buffer()
1775 for (i = 1; i < cell->bytes; i++) { in nvmem_cell_prepare_write_buffer()
1777 pbits = pbyte >> (BITS_PER_BYTE - 1 - bit_offset); in nvmem_cell_prepare_write_buffer()
1787 /* setup the last byte with msb bits from nvmem */ in nvmem_cell_prepare_write_buffer()
1788 rc = nvmem_reg_read(nvmem, in nvmem_cell_prepare_write_buffer()
1789 cell->offset + cell->bytes - 1, &v, 1); in nvmem_cell_prepare_write_buffer()
1804 struct nvmem_device *nvmem = cell->nvmem; in __nvmem_cell_entry_write() local
1807 if (!nvmem || nvmem->read_only || in __nvmem_cell_entry_write()
1808 (cell->bit_offset == 0 && len != cell->bytes)) in __nvmem_cell_entry_write()
1809 return -EINVAL; in __nvmem_cell_entry_write()
1812 * Any cells which have a read_post_process hook are read-only because in __nvmem_cell_entry_write()
1813 * we cannot reverse the operation and it might affect other cells, in __nvmem_cell_entry_write()
1816 if (cell->read_post_process) in __nvmem_cell_entry_write()
1817 return -EINVAL; in __nvmem_cell_entry_write()
1819 if (cell->bit_offset || cell->nbits) { in __nvmem_cell_entry_write()
1820 if (len != BITS_TO_BYTES(cell->nbits) && len != cell->bytes) in __nvmem_cell_entry_write()
1821 return -EINVAL; in __nvmem_cell_entry_write()
1827 rc = nvmem_reg_write(nvmem, cell->offset, buf, cell->bytes); in __nvmem_cell_entry_write()
1830 if (cell->bit_offset || cell->nbits) in __nvmem_cell_entry_write()
1840 * nvmem_cell_write() - Write to a given nvmem cell
1842 * @cell: nvmem cell to be written.
1844 * @len: length of buffer to be written to nvmem cell.
1850 return __nvmem_cell_entry_write(cell->entry, buf, len); in nvmem_cell_write()
1874 return -EINVAL; in nvmem_cell_read_common()
1884 * nvmem_cell_read_u8() - Read a cell value as a u8
1886 * @dev: Device that requests the nvmem cell.
1887 * @cell_id: Name of nvmem cell to read.
1899 * nvmem_cell_read_u16() - Read a cell value as a u16
1901 * @dev: Device that requests the nvmem cell.
1902 * @cell_id: Name of nvmem cell to read.
1914 * nvmem_cell_read_u32() - Read a cell value as a u32
1916 * @dev: Device that requests the nvmem cell.
1917 * @cell_id: Name of nvmem cell to read.
1929 * nvmem_cell_read_u64() - Read a cell value as a u64
1931 * @dev: Device that requests the nvmem cell.
1932 * @cell_id: Name of nvmem cell to read.
1955 nbits = cell->entry->nbits; in nvmem_cell_read_variable_common()
1970 return ERR_PTR(-ERANGE); in nvmem_cell_read_variable_common()
1977 * nvmem_cell_read_variable_le_u32() - Read up to 32-bits of data as a little endian number.
1979 * @dev: Device that requests the nvmem cell.
1980 * @cell_id: Name of nvmem cell to read.
2008 * nvmem_cell_read_variable_le_u64() - Read up to 64-bits of data as a little endian number.
2010 * @dev: Device that requests the nvmem cell.
2011 * @cell_id: Name of nvmem cell to read.
2039 * nvmem_device_cell_read() - Read a given nvmem device and cell
2041 * @nvmem: nvmem device to read from.
2042 * @info: nvmem cell info to be read.
2048 ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, in nvmem_device_cell_read() argument
2055 if (!nvmem) in nvmem_device_cell_read()
2056 return -EINVAL; in nvmem_device_cell_read()
2058 rc = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, &cell); in nvmem_device_cell_read()
2062 rc = __nvmem_cell_read(nvmem, &cell, buf, &len, NULL, 0); in nvmem_device_cell_read()
2071 * nvmem_device_cell_write() - Write cell to a given nvmem device
2073 * @nvmem: nvmem device to be written to.
2074 * @info: nvmem cell info to be written.
2079 int nvmem_device_cell_write(struct nvmem_device *nvmem, in nvmem_device_cell_write() argument
2085 if (!nvmem) in nvmem_device_cell_write()
2086 return -EINVAL; in nvmem_device_cell_write()
2088 rc = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, &cell); in nvmem_device_cell_write()
2097 * nvmem_device_read() - Read from a given nvmem device
2099 * @nvmem: nvmem device to read from.
2100 * @offset: offset in nvmem device.
2107 int nvmem_device_read(struct nvmem_device *nvmem, in nvmem_device_read() argument
2113 if (!nvmem) in nvmem_device_read()
2114 return -EINVAL; in nvmem_device_read()
2116 rc = nvmem_reg_read(nvmem, offset, buf, bytes); in nvmem_device_read()
2126 * nvmem_device_write() - Write cell to a given nvmem device
2128 * @nvmem: nvmem device to be written to.
2129 * @offset: offset in nvmem device.
2135 int nvmem_device_write(struct nvmem_device *nvmem, in nvmem_device_write() argument
2141 if (!nvmem) in nvmem_device_write()
2142 return -EINVAL; in nvmem_device_write()
2144 rc = nvmem_reg_write(nvmem, offset, buf, bytes); in nvmem_device_write()
2155 * nvmem_add_cell_table() - register a table of cell info entries
2162 list_add_tail(&table->node, &nvmem_cell_tables); in nvmem_add_cell_table()
2168 * nvmem_del_cell_table() - remove a previously registered cell info table
2175 list_del(&table->node); in nvmem_del_cell_table()
2181 * nvmem_add_cell_lookups() - register a list of cell lookup entries
2198 * nvmem_del_cell_lookups() - remove a list of previously added cell lookup
2216 * nvmem_dev_name() - Get the name of a given nvmem device.
2218 * @nvmem: nvmem device.
2220 * Return: name of the nvmem device.
2222 const char *nvmem_dev_name(struct nvmem_device *nvmem) in nvmem_dev_name() argument
2224 return dev_name(&nvmem->dev); in nvmem_dev_name()
2229 * nvmem_dev_size() - Get the size of a given nvmem device.
2231 * @nvmem: nvmem device.
2233 * Return: size of the nvmem device.
2235 size_t nvmem_dev_size(struct nvmem_device *nvmem) in nvmem_dev_size() argument
2237 return nvmem->size; in nvmem_dev_size()
2266 MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com");
2267 MODULE_DESCRIPTION("nvmem Driver Core");