Lines Matching full:nvmem

3  * nvmem framework core.
16 #include <linux/nvmem-consumer.h>
17 #include <linux/nvmem-provider.h>
37 struct nvmem_device *nvmem; member
55 static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, in __nvmem_reg_read() argument
58 if (nvmem->reg_read) in __nvmem_reg_read()
59 return nvmem->reg_read(nvmem->priv, offset, val, bytes); in __nvmem_reg_read()
64 static int __nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset, in __nvmem_reg_write() argument
69 if (nvmem->reg_write) { in __nvmem_reg_write()
70 gpiod_set_value_cansleep(nvmem->wp_gpio, 0); in __nvmem_reg_write()
71 ret = nvmem->reg_write(nvmem->priv, offset, val, bytes); in __nvmem_reg_write()
72 gpiod_set_value_cansleep(nvmem->wp_gpio, 1); in __nvmem_reg_write()
79 static int nvmem_access_with_keepouts(struct nvmem_device *nvmem, in nvmem_access_with_keepouts() argument
86 const struct nvmem_keepout *keepout = nvmem->keepout; in nvmem_access_with_keepouts()
87 const struct nvmem_keepout *keepoutend = keepout + nvmem->nkeepout; in nvmem_access_with_keepouts()
103 rc = __nvmem_reg_write(nvmem, offset, val, ksize); in nvmem_access_with_keepouts()
105 rc = __nvmem_reg_read(nvmem, offset, val, ksize); in nvmem_access_with_keepouts()
135 return __nvmem_reg_write(nvmem, offset, val, ksize); in nvmem_access_with_keepouts()
137 return __nvmem_reg_read(nvmem, offset, val, ksize); in nvmem_access_with_keepouts()
143 static int nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, in nvmem_reg_read() argument
146 if (!nvmem->nkeepout) in nvmem_reg_read()
147 return __nvmem_reg_read(nvmem, offset, val, bytes); in nvmem_reg_read()
149 return nvmem_access_with_keepouts(nvmem, offset, val, bytes, false); in nvmem_reg_read()
152 static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset, in nvmem_reg_write() argument
155 if (!nvmem->nkeepout) in nvmem_reg_write()
156 return __nvmem_reg_write(nvmem, offset, val, bytes); in nvmem_reg_write()
158 return nvmem_access_with_keepouts(nvmem, offset, val, bytes, true); in nvmem_reg_write()
177 struct nvmem_device *nvmem = to_nvmem_device(dev); in type_show() local
179 return sysfs_emit(buf, "%s\n", nvmem_type_str[nvmem->type]); in type_show()
187 struct nvmem_device *nvmem = to_nvmem_device(dev); in force_ro_show() local
189 return sysfs_emit(buf, "%d\n", nvmem->read_only); in force_ro_show()
195 struct nvmem_device *nvmem = to_nvmem_device(dev); in force_ro_store() local
196 int ret = kstrtobool(buf, &nvmem->read_only); in force_ro_store()
217 struct nvmem_device *nvmem; in bin_attr_nvmem_read() local
224 nvmem = to_nvmem_device(dev); in bin_attr_nvmem_read()
226 if (!IS_ALIGNED(pos, nvmem->stride)) in bin_attr_nvmem_read()
229 if (count < nvmem->word_size) in bin_attr_nvmem_read()
232 count = round_down(count, nvmem->word_size); in bin_attr_nvmem_read()
234 if (!nvmem->reg_read) in bin_attr_nvmem_read()
237 rc = nvmem_reg_read(nvmem, pos, buf, count); in bin_attr_nvmem_read()
250 struct nvmem_device *nvmem; in bin_attr_nvmem_write() local
257 nvmem = to_nvmem_device(dev); in bin_attr_nvmem_write()
259 if (!IS_ALIGNED(pos, nvmem->stride)) in bin_attr_nvmem_write()
262 if (count < nvmem->word_size) in bin_attr_nvmem_write()
265 count = round_down(count, nvmem->word_size); in bin_attr_nvmem_write()
267 if (!nvmem->reg_write || nvmem->read_only) in bin_attr_nvmem_write()
270 rc = nvmem_reg_write(nvmem, pos, buf, count); in bin_attr_nvmem_write()
278 static umode_t nvmem_bin_attr_get_umode(struct nvmem_device *nvmem) in nvmem_bin_attr_get_umode() argument
282 if (!nvmem->root_only) in nvmem_bin_attr_get_umode()
285 if (!nvmem->read_only) in nvmem_bin_attr_get_umode()
288 if (!nvmem->reg_write) in nvmem_bin_attr_get_umode()
291 if (!nvmem->reg_read) in nvmem_bin_attr_get_umode()
302 struct nvmem_device *nvmem = to_nvmem_device(dev); in nvmem_bin_attr_is_visible() local
304 return nvmem_bin_attr_get_umode(nvmem); in nvmem_bin_attr_is_visible()
312 struct nvmem_device *nvmem = to_nvmem_device(dev); in nvmem_bin_attr_size() local
314 return nvmem->size; in nvmem_bin_attr_size()
321 struct nvmem_device *nvmem = to_nvmem_device(dev); in nvmem_attr_is_visible() local
330 if (attr == &dev_attr_force_ro.attr && !nvmem->reg_write) in nvmem_attr_is_visible()
376 .name = "nvmem",
414 static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem, in nvmem_sysfs_setup_compat() argument
425 nvmem->eeprom = bin_attr_nvmem_eeprom_compat; in nvmem_sysfs_setup_compat()
427 nvmem->eeprom.attr.name = "fram"; in nvmem_sysfs_setup_compat()
428 nvmem->eeprom.attr.mode = nvmem_bin_attr_get_umode(nvmem); in nvmem_sysfs_setup_compat()
429 nvmem->eeprom.size = nvmem->size; in nvmem_sysfs_setup_compat()
431 nvmem->eeprom.attr.key = &eeprom_lock_key; in nvmem_sysfs_setup_compat()
433 nvmem->eeprom.private = &nvmem->dev; in nvmem_sysfs_setup_compat()
434 nvmem->base_dev = config->base_dev; in nvmem_sysfs_setup_compat()
436 rval = device_create_bin_file(nvmem->base_dev, &nvmem->eeprom); in nvmem_sysfs_setup_compat()
438 dev_err(&nvmem->dev, in nvmem_sysfs_setup_compat()
443 nvmem->flags |= FLAG_COMPAT; in nvmem_sysfs_setup_compat()
448 static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem, in nvmem_sysfs_remove_compat() argument
452 device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); in nvmem_sysfs_remove_compat()
455 static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) in nvmem_populate_sysfs_cells() argument
468 if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated) in nvmem_populate_sysfs_cells()
472 ncells = list_count_nodes(&nvmem->cells); in nvmem_populate_sysfs_cells()
473 pattrs = devm_kcalloc(&nvmem->dev, ncells + 1, in nvmem_populate_sysfs_cells()
480 attrs = devm_kcalloc(&nvmem->dev, ncells, sizeof(struct bin_attribute), GFP_KERNEL); in nvmem_populate_sysfs_cells()
487 list_for_each_entry(entry, &nvmem->cells, node) { in nvmem_populate_sysfs_cells()
489 attrs[i].attr.name = devm_kasprintf(&nvmem->dev, GFP_KERNEL, in nvmem_populate_sysfs_cells()
493 attrs[i].attr.mode = 0444 & nvmem_bin_attr_get_umode(nvmem); in nvmem_populate_sysfs_cells()
508 ret = device_add_group(&nvmem->dev, &group); in nvmem_populate_sysfs_cells()
512 nvmem->sysfs_cells_populated = true; in nvmem_populate_sysfs_cells()
522 static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem, in nvmem_sysfs_setup_compat() argument
527 static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem, in nvmem_sysfs_remove_compat() argument
536 struct nvmem_device *nvmem = to_nvmem_device(dev); in nvmem_release() local
538 ida_free(&nvmem_ida, nvmem->id); in nvmem_release()
539 gpiod_put(nvmem->wp_gpio); in nvmem_release()
540 kfree(nvmem); in nvmem_release()
548 .name = "nvmem",
562 static void nvmem_device_remove_all_cells(const struct nvmem_device *nvmem) in nvmem_device_remove_all_cells() argument
566 list_for_each_entry_safe(cell, p, &nvmem->cells, node) in nvmem_device_remove_all_cells()
573 list_add_tail(&cell->node, &cell->nvmem->cells); in nvmem_cell_entry_add()
578 static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, in nvmem_cell_info_to_nvmem_cell_entry_nodup() argument
582 cell->nvmem = nvmem; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
597 cell->raw_len = ALIGN(cell->bytes, nvmem->word_size); in nvmem_cell_info_to_nvmem_cell_entry_nodup()
600 if (!IS_ALIGNED(cell->offset, nvmem->stride)) { in nvmem_cell_info_to_nvmem_cell_entry_nodup()
601 dev_err(&nvmem->dev, in nvmem_cell_info_to_nvmem_cell_entry_nodup()
602 "cell %s unaligned to nvmem stride %d\n", in nvmem_cell_info_to_nvmem_cell_entry_nodup()
603 cell->name ?: "<unknown>", nvmem->stride); in nvmem_cell_info_to_nvmem_cell_entry_nodup()
607 if (!IS_ALIGNED(cell->raw_len, nvmem->word_size)) { in nvmem_cell_info_to_nvmem_cell_entry_nodup()
608 dev_err(&nvmem->dev, in nvmem_cell_info_to_nvmem_cell_entry_nodup()
609 "cell %s raw len %zd unaligned to nvmem word size %d\n", in nvmem_cell_info_to_nvmem_cell_entry_nodup()
611 nvmem->word_size); in nvmem_cell_info_to_nvmem_cell_entry_nodup()
616 cell->raw_len = ALIGN(cell->raw_len, nvmem->word_size); in nvmem_cell_info_to_nvmem_cell_entry_nodup()
622 static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem, in nvmem_cell_info_to_nvmem_cell_entry() argument
628 err = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, cell); in nvmem_cell_info_to_nvmem_cell_entry()
640 * nvmem_add_one_cell() - Add one cell information to an nvmem device
642 * @nvmem: nvmem device to add cells to.
643 * @info: nvmem cell info to add to the device
647 int nvmem_add_one_cell(struct nvmem_device *nvmem, in nvmem_add_one_cell() argument
657 rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell); in nvmem_add_one_cell()
670 * nvmem_add_cells() - Add cell information to an nvmem device
672 * @nvmem: nvmem device to add cells to.
673 * @info: nvmem cell info to add to the device
678 static int nvmem_add_cells(struct nvmem_device *nvmem, in nvmem_add_cells() argument
685 rval = nvmem_add_one_cell(nvmem, &info[i]); in nvmem_add_cells()
694 * nvmem_register_notifier() - Register a notifier block for nvmem events.
696 * @nb: notifier block to be called on nvmem events.
707 * nvmem_unregister_notifier() - Unregister a notifier block for nvmem events.
720 nvmem_find_cell_entry_by_name(struct nvmem_device *nvmem, const char *cell_id) in nvmem_find_cell_entry_by_name() argument
725 list_for_each_entry(iter, &nvmem->cells, node) { in nvmem_find_cell_entry_by_name()
736 static int nvmem_validate_keepouts(struct nvmem_device *nvmem) in nvmem_validate_keepouts() argument
739 const struct nvmem_keepout *keepout = nvmem->keepout; in nvmem_validate_keepouts()
740 const struct nvmem_keepout *keepoutend = keepout + nvmem->nkeepout; in nvmem_validate_keepouts()
745 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
752 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
762 if ((keepout->end - keepout->start < nvmem->word_size) || in nvmem_validate_keepouts()
764 (keepout->start - cur < nvmem->word_size))) { in nvmem_validate_keepouts()
766 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
773 if (!IS_ALIGNED(keepout->start, nvmem->stride) || in nvmem_validate_keepouts()
774 !IS_ALIGNED(keepout->end, nvmem->stride)) { in nvmem_validate_keepouts()
776 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
789 static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np) in nvmem_add_cells_from_dt() argument
791 struct device *dev = &nvmem->dev; in nvmem_add_cells_from_dt()
803 dev_err(dev, "nvmem: invalid reg on %pOF\n", child); in nvmem_add_cells_from_dt()
819 dev_err(dev, "nvmem: invalid bits on %pOF\n", child); in nvmem_add_cells_from_dt()
827 if (nvmem->fixup_dt_cell_info) in nvmem_add_cells_from_dt()
828 nvmem->fixup_dt_cell_info(nvmem, &info); in nvmem_add_cells_from_dt()
830 ret = nvmem_add_one_cell(nvmem, &info); in nvmem_add_cells_from_dt()
841 static int nvmem_add_cells_from_legacy_of(struct nvmem_device *nvmem) in nvmem_add_cells_from_legacy_of() argument
843 return nvmem_add_cells_from_dt(nvmem, nvmem->dev.of_node); in nvmem_add_cells_from_legacy_of()
846 static int nvmem_add_cells_from_fixed_layout(struct nvmem_device *nvmem) in nvmem_add_cells_from_fixed_layout() argument
851 layout_np = of_nvmem_layout_get_container(nvmem); in nvmem_add_cells_from_fixed_layout()
856 err = nvmem_add_cells_from_dt(nvmem, layout_np); in nvmem_add_cells_from_fixed_layout()
876 ret = nvmem_populate_sysfs_cells(layout->nvmem); in nvmem_layout_register()
878 nvmem_device_remove_all_cells(layout->nvmem); in nvmem_layout_register()
894 * nvmem_register() - Register a nvmem device for given nvmem_config.
895 * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
897 * @config: nvmem device configuration with which nvmem device is created.
905 struct nvmem_device *nvmem; in nvmem_register() local
914 nvmem = kzalloc(sizeof(*nvmem), GFP_KERNEL); in nvmem_register()
915 if (!nvmem) in nvmem_register()
920 kfree(nvmem); in nvmem_register()
924 nvmem->id = rval; in nvmem_register()
926 nvmem->dev.type = &nvmem_provider_type; in nvmem_register()
927 nvmem->dev.bus = &nvmem_bus_type; in nvmem_register()
928 nvmem->dev.parent = config->dev; in nvmem_register()
930 device_initialize(&nvmem->dev); in nvmem_register()
933 nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", in nvmem_register()
935 if (IS_ERR(nvmem->wp_gpio)) { in nvmem_register()
936 rval = PTR_ERR(nvmem->wp_gpio); in nvmem_register()
937 nvmem->wp_gpio = NULL; in nvmem_register()
941 kref_init(&nvmem->refcnt); in nvmem_register()
942 INIT_LIST_HEAD(&nvmem->cells); in nvmem_register()
943 nvmem->fixup_dt_cell_info = config->fixup_dt_cell_info; in nvmem_register()
945 nvmem->owner = config->owner; in nvmem_register()
946 if (!nvmem->owner && config->dev->driver) in nvmem_register()
947 nvmem->owner = config->dev->driver->owner; in nvmem_register()
948 nvmem->stride = config->stride ?: 1; in nvmem_register()
949 nvmem->word_size = config->word_size ?: 1; in nvmem_register()
950 nvmem->size = config->size; in nvmem_register()
951 nvmem->root_only = config->root_only; in nvmem_register()
952 nvmem->priv = config->priv; in nvmem_register()
953 nvmem->type = config->type; in nvmem_register()
954 nvmem->reg_read = config->reg_read; in nvmem_register()
955 nvmem->reg_write = config->reg_write; in nvmem_register()
956 nvmem->keepout = config->keepout; in nvmem_register()
957 nvmem->nkeepout = config->nkeepout; in nvmem_register()
959 nvmem->dev.of_node = config->of_node; in nvmem_register()
961 nvmem->dev.of_node = config->dev->of_node; in nvmem_register()
965 rval = dev_set_name(&nvmem->dev, "%s", config->name); in nvmem_register()
968 rval = dev_set_name(&nvmem->dev, "%s%d", config->name, nvmem->id); in nvmem_register()
971 rval = dev_set_name(&nvmem->dev, "%s%d", in nvmem_register()
972 config->name ? : "nvmem", in nvmem_register()
973 config->name ? config->id : nvmem->id); in nvmem_register()
980 nvmem->read_only = device_property_present(config->dev, "read-only") || in nvmem_register()
981 config->read_only || !nvmem->reg_write; in nvmem_register()
984 nvmem->dev.groups = nvmem_dev_groups; in nvmem_register()
987 if (nvmem->nkeepout) { in nvmem_register()
988 rval = nvmem_validate_keepouts(nvmem); in nvmem_register()
994 rval = nvmem_sysfs_setup_compat(nvmem, config); in nvmem_register()
1000 rval = nvmem_add_cells(nvmem, config->cells, config->ncells); in nvmem_register()
1006 rval = nvmem_add_cells_from_legacy_of(nvmem); in nvmem_register()
1011 rval = nvmem_add_cells_from_fixed_layout(nvmem); in nvmem_register()
1015 dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); in nvmem_register()
1017 rval = device_add(&nvmem->dev); in nvmem_register()
1021 rval = nvmem_populate_layout(nvmem); in nvmem_register()
1026 rval = nvmem_populate_sysfs_cells(nvmem); in nvmem_register()
1031 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); in nvmem_register()
1033 return nvmem; in nvmem_register()
1037 nvmem_destroy_layout(nvmem); in nvmem_register()
1040 device_del(&nvmem->dev); in nvmem_register()
1042 nvmem_device_remove_all_cells(nvmem); in nvmem_register()
1044 nvmem_sysfs_remove_compat(nvmem, config); in nvmem_register()
1046 put_device(&nvmem->dev); in nvmem_register()
1054 struct nvmem_device *nvmem; in nvmem_device_release() local
1056 nvmem = container_of(kref, struct nvmem_device, refcnt); in nvmem_device_release()
1058 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_REMOVE, nvmem); in nvmem_device_release()
1060 if (nvmem->flags & FLAG_COMPAT) in nvmem_device_release()
1061 device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); in nvmem_device_release()
1063 nvmem_device_remove_all_cells(nvmem); in nvmem_device_release()
1064 nvmem_destroy_layout(nvmem); in nvmem_device_release()
1065 device_unregister(&nvmem->dev); in nvmem_device_release()
1069 * nvmem_unregister() - Unregister previously registered nvmem device
1071 * @nvmem: Pointer to previously registered nvmem device.
1073 void nvmem_unregister(struct nvmem_device *nvmem) in nvmem_unregister() argument
1075 if (nvmem) in nvmem_unregister()
1076 kref_put(&nvmem->refcnt, nvmem_device_release); in nvmem_unregister()
1080 static void devm_nvmem_unregister(void *nvmem) in devm_nvmem_unregister() argument
1082 nvmem_unregister(nvmem); in devm_nvmem_unregister()
1086 * devm_nvmem_register() - Register a managed nvmem device for given
1088 * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
1090 * @dev: Device that uses the nvmem device.
1091 * @config: nvmem device configuration with which nvmem device is created.
1099 struct nvmem_device *nvmem; in devm_nvmem_register() local
1102 nvmem = nvmem_register(config); in devm_nvmem_register()
1103 if (IS_ERR(nvmem)) in devm_nvmem_register()
1104 return nvmem; in devm_nvmem_register()
1106 ret = devm_add_action_or_reset(dev, devm_nvmem_unregister, nvmem); in devm_nvmem_register()
1110 return nvmem; in devm_nvmem_register()
1117 struct nvmem_device *nvmem = NULL; in __nvmem_device_get() local
1123 nvmem = to_nvmem_device(dev); in __nvmem_device_get()
1125 if (!nvmem) in __nvmem_device_get()
1128 if (!try_module_get(nvmem->owner)) { in __nvmem_device_get()
1129 dev_err(&nvmem->dev, in __nvmem_device_get()
1131 nvmem_dev_name(nvmem)); in __nvmem_device_get()
1133 put_device(&nvmem->dev); in __nvmem_device_get()
1137 kref_get(&nvmem->refcnt); in __nvmem_device_get()
1139 return nvmem; in __nvmem_device_get()
1142 static void __nvmem_device_put(struct nvmem_device *nvmem) in __nvmem_device_put() argument
1144 put_device(&nvmem->dev); in __nvmem_device_put()
1145 module_put(nvmem->owner); in __nvmem_device_put()
1146 kref_put(&nvmem->refcnt, nvmem_device_release); in __nvmem_device_put()
1151 * of_nvmem_device_get() - Get nvmem device from a given id
1153 * @np: Device tree node that uses the nvmem device.
1154 * @id: nvmem name from nvmem-names property.
1163 struct nvmem_device *nvmem; in of_nvmem_device_get() local
1167 index = of_property_match_string(np, "nvmem-names", id); in of_nvmem_device_get()
1169 nvmem_np = of_parse_phandle(np, "nvmem", index); in of_nvmem_device_get()
1173 nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); in of_nvmem_device_get()
1175 return nvmem; in of_nvmem_device_get()
1181 * nvmem_device_get() - Get nvmem device from a given id
1183 * @dev: Device that uses the nvmem device.
1184 * @dev_name: name of the requested nvmem device.
1192 struct nvmem_device *nvmem; in nvmem_device_get() local
1194 nvmem = of_nvmem_device_get(dev->of_node, dev_name); in nvmem_device_get()
1196 if (!IS_ERR(nvmem) || PTR_ERR(nvmem) == -EPROBE_DEFER) in nvmem_device_get()
1197 return nvmem; in nvmem_device_get()
1206 * nvmem_device_find() - Find nvmem device with matching function
1223 struct nvmem_device **nvmem = res; in devm_nvmem_device_match() local
1225 if (WARN_ON(!nvmem || !*nvmem)) in devm_nvmem_device_match()
1228 return *nvmem == data; in devm_nvmem_device_match()
1237 * devm_nvmem_device_put() - put already got nvmem device
1239 * @dev: Device that uses the nvmem device.
1240 * @nvmem: pointer to nvmem device allocated by devm_nvmem_cell_get(),
1243 void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem) in devm_nvmem_device_put() argument
1248 devm_nvmem_device_match, nvmem); in devm_nvmem_device_put()
1255 * nvmem_device_put() - put already got nvmem device
1257 * @nvmem: pointer to nvmem device that needs to be released.
1259 void nvmem_device_put(struct nvmem_device *nvmem) in nvmem_device_put() argument
1261 __nvmem_device_put(nvmem); in nvmem_device_put()
1266 * devm_nvmem_device_get() - Get nvmem device of device form a given id
1268 * @dev: Device that requests the nvmem device.
1269 * @id: name id for the requested nvmem device.
1277 struct nvmem_device **ptr, *nvmem; in devm_nvmem_device_get() local
1283 nvmem = nvmem_device_get(dev, id); in devm_nvmem_device_get()
1284 if (!IS_ERR(nvmem)) { in devm_nvmem_device_get()
1285 *ptr = nvmem; in devm_nvmem_device_get()
1291 return nvmem; in devm_nvmem_device_get()
1326 struct nvmem_device *nvmem; in nvmem_cell_get_from_lookup() local
1340 nvmem = __nvmem_device_get((void *)lookup->nvmem_name, in nvmem_cell_get_from_lookup()
1342 if (IS_ERR(nvmem)) { in nvmem_cell_get_from_lookup()
1344 cell = ERR_CAST(nvmem); in nvmem_cell_get_from_lookup()
1348 cell_entry = nvmem_find_cell_entry_by_name(nvmem, in nvmem_cell_get_from_lookup()
1351 __nvmem_device_put(nvmem); in nvmem_cell_get_from_lookup()
1356 __nvmem_device_put(nvmem); in nvmem_cell_get_from_lookup()
1366 static void nvmem_layout_module_put(struct nvmem_device *nvmem) in nvmem_layout_module_put() argument
1368 if (nvmem->layout && nvmem->layout->dev.driver) in nvmem_layout_module_put()
1369 module_put(nvmem->layout->dev.driver->owner); in nvmem_layout_module_put()
1374 nvmem_find_cell_entry_by_node(struct nvmem_device *nvmem, struct device_node *np) in nvmem_find_cell_entry_by_node() argument
1379 list_for_each_entry(iter, &nvmem->cells, node) { in nvmem_find_cell_entry_by_node()
1390 static int nvmem_layout_module_get_optional(struct nvmem_device *nvmem) in nvmem_layout_module_get_optional() argument
1392 if (!nvmem->layout) in nvmem_layout_module_get_optional()
1395 if (!nvmem->layout->dev.driver || in nvmem_layout_module_get_optional()
1396 !try_module_get(nvmem->layout->dev.driver->owner)) in nvmem_layout_module_get_optional()
1403 * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id
1405 * @np: Device tree node that uses the nvmem cell.
1406 * @id: nvmem cell name from nvmem-cell-names property, or NULL
1408 * nvmem-cell-names property).
1417 struct nvmem_device *nvmem; in of_nvmem_cell_get() local
1427 index = of_property_match_string(np, "nvmem-cell-names", id); in of_nvmem_cell_get()
1429 ret = of_parse_phandle_with_optional_args(np, "nvmem-cells", in of_nvmem_cell_get()
1430 "#nvmem-cell-cells", in of_nvmem_cell_get()
1448 /* nvmem layouts produce cells within the nvmem-layout container */ in of_nvmem_cell_get()
1449 if (of_node_name_eq(nvmem_np, "nvmem-layout")) { in of_nvmem_cell_get()
1457 nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); in of_nvmem_cell_get()
1459 if (IS_ERR(nvmem)) { in of_nvmem_cell_get()
1461 return ERR_CAST(nvmem); in of_nvmem_cell_get()
1464 ret = nvmem_layout_module_get_optional(nvmem); in of_nvmem_cell_get()
1467 __nvmem_device_put(nvmem); in of_nvmem_cell_get()
1471 cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np); in of_nvmem_cell_get()
1474 __nvmem_device_put(nvmem); in of_nvmem_cell_get()
1475 nvmem_layout_module_put(nvmem); in of_nvmem_cell_get()
1476 if (nvmem->layout) in of_nvmem_cell_get()
1484 __nvmem_device_put(nvmem); in of_nvmem_cell_get()
1485 nvmem_layout_module_put(nvmem); in of_nvmem_cell_get()
1494 * nvmem_cell_get() - Get nvmem cell of device form a given cell name
1496 * @dev: Device that requests the nvmem cell.
1497 * @id: nvmem cell name to get (this corresponds with the name from the
1498 * nvmem-cell-names property for DT systems and with the con_id from
1529 * devm_nvmem_cell_get() - Get nvmem cell of device form a given id
1531 * @dev: Device that requests the nvmem cell.
1532 * @id: nvmem cell name id to get.
1569 * devm_nvmem_cell_put() - Release previously allocated nvmem cell
1572 * @dev: Device that requests the nvmem cell.
1573 * @cell: Previously allocated nvmem cell by devm_nvmem_cell_get().
1587 * nvmem_cell_put() - Release previously allocated nvmem cell.
1589 * @cell: Previously allocated nvmem cell by nvmem_cell_get().
1593 struct nvmem_device *nvmem = cell->entry->nvmem; in nvmem_cell_put() local
1599 __nvmem_device_put(nvmem); in nvmem_cell_put()
1600 nvmem_layout_module_put(nvmem); in nvmem_cell_put()
1645 static int __nvmem_cell_read(struct nvmem_device *nvmem, in __nvmem_cell_read() argument
1651 rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->raw_len); in __nvmem_cell_read()
1674 * nvmem_cell_read() - Read a given nvmem cell
1676 * @cell: nvmem cell to be read.
1686 struct nvmem_device *nvmem = entry->nvmem; in nvmem_cell_read() local
1690 if (!nvmem) in nvmem_cell_read()
1697 rc = __nvmem_cell_read(nvmem, cell->entry, buf, len, cell->id, cell->index); in nvmem_cell_read()
1710 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_prepare_write_buffer() local
1726 /* setup the first byte with lsb bits from nvmem */ in nvmem_cell_prepare_write_buffer()
1727 rc = nvmem_reg_read(nvmem, cell->offset, &v, 1); in nvmem_cell_prepare_write_buffer()
1745 /* setup the last byte with msb bits from nvmem */ in nvmem_cell_prepare_write_buffer()
1746 rc = nvmem_reg_read(nvmem, in nvmem_cell_prepare_write_buffer()
1762 struct nvmem_device *nvmem = cell->nvmem; in __nvmem_cell_entry_write() local
1765 if (!nvmem || nvmem->read_only || in __nvmem_cell_entry_write()
1785 rc = nvmem_reg_write(nvmem, cell->offset, buf, cell->bytes); in __nvmem_cell_entry_write()
1798 * nvmem_cell_write() - Write to a given nvmem cell
1800 * @cell: nvmem cell to be written.
1802 * @len: length of buffer to be written to nvmem cell.
1844 * @dev: Device that requests the nvmem cell.
1845 * @cell_id: Name of nvmem cell to read.
1859 * @dev: Device that requests the nvmem cell.
1860 * @cell_id: Name of nvmem cell to read.
1874 * @dev: Device that requests the nvmem cell.
1875 * @cell_id: Name of nvmem cell to read.
1889 * @dev: Device that requests the nvmem cell.
1890 * @cell_id: Name of nvmem cell to read.
1937 * @dev: Device that requests the nvmem cell.
1938 * @cell_id: Name of nvmem cell to read.
1968 * @dev: Device that requests the nvmem cell.
1969 * @cell_id: Name of nvmem cell to read.
1997 * nvmem_device_cell_read() - Read a given nvmem device and cell
1999 * @nvmem: nvmem device to read from.
2000 * @info: nvmem cell info to be read.
2006 ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, in nvmem_device_cell_read() argument
2013 if (!nvmem) in nvmem_device_cell_read()
2016 rc = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, &cell); in nvmem_device_cell_read()
2020 rc = __nvmem_cell_read(nvmem, &cell, buf, &len, NULL, 0); in nvmem_device_cell_read()
2029 * nvmem_device_cell_write() - Write cell to a given nvmem device
2031 * @nvmem: nvmem device to be written to.
2032 * @info: nvmem cell info to be written.
2037 int nvmem_device_cell_write(struct nvmem_device *nvmem, in nvmem_device_cell_write() argument
2043 if (!nvmem) in nvmem_device_cell_write()
2046 rc = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, &cell); in nvmem_device_cell_write()
2055 * nvmem_device_read() - Read from a given nvmem device
2057 * @nvmem: nvmem device to read from.
2058 * @offset: offset in nvmem device.
2065 int nvmem_device_read(struct nvmem_device *nvmem, in nvmem_device_read() argument
2071 if (!nvmem) in nvmem_device_read()
2074 rc = nvmem_reg_read(nvmem, offset, buf, bytes); in nvmem_device_read()
2084 * nvmem_device_write() - Write cell to a given nvmem device
2086 * @nvmem: nvmem device to be written to.
2087 * @offset: offset in nvmem device.
2093 int nvmem_device_write(struct nvmem_device *nvmem, in nvmem_device_write() argument
2099 if (!nvmem) in nvmem_device_write()
2102 rc = nvmem_reg_write(nvmem, offset, buf, bytes); in nvmem_device_write()
2148 * nvmem_dev_name() - Get the name of a given nvmem device.
2150 * @nvmem: nvmem device.
2152 * Return: name of the nvmem device.
2154 const char *nvmem_dev_name(struct nvmem_device *nvmem) in nvmem_dev_name() argument
2156 return dev_name(&nvmem->dev); in nvmem_dev_name()
2161 * nvmem_dev_size() - Get the size of a given nvmem device.
2163 * @nvmem: nvmem device.
2165 * Return: size of the nvmem device.
2167 size_t nvmem_dev_size(struct nvmem_device *nvmem) in nvmem_dev_size() argument
2169 return nvmem->size; in nvmem_dev_size()
2199 MODULE_DESCRIPTION("nvmem Driver Core");