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
61 static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, in __nvmem_reg_read() argument
64 if (nvmem->reg_read) in __nvmem_reg_read()
65 return nvmem->reg_read(nvmem->priv, offset, val, bytes); in __nvmem_reg_read()
70 static int __nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset, in __nvmem_reg_write() argument
75 if (nvmem->reg_write) { in __nvmem_reg_write()
76 gpiod_set_value_cansleep(nvmem->wp_gpio, 0); in __nvmem_reg_write()
77 ret = nvmem->reg_write(nvmem->priv, offset, val, bytes); in __nvmem_reg_write()
78 gpiod_set_value_cansleep(nvmem->wp_gpio, 1); in __nvmem_reg_write()
85 static int nvmem_access_with_keepouts(struct nvmem_device *nvmem, in nvmem_access_with_keepouts() argument
92 const struct nvmem_keepout *keepout = nvmem->keepout; in nvmem_access_with_keepouts()
93 const struct nvmem_keepout *keepoutend = keepout + nvmem->nkeepout; in nvmem_access_with_keepouts()
109 rc = __nvmem_reg_write(nvmem, offset, val, ksize); in nvmem_access_with_keepouts()
111 rc = __nvmem_reg_read(nvmem, offset, val, ksize); in nvmem_access_with_keepouts()
141 return __nvmem_reg_write(nvmem, offset, val, ksize); in nvmem_access_with_keepouts()
143 return __nvmem_reg_read(nvmem, offset, val, ksize); in nvmem_access_with_keepouts()
149 static int nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, in nvmem_reg_read() argument
152 if (!nvmem->nkeepout) in nvmem_reg_read()
153 return __nvmem_reg_read(nvmem, offset, val, bytes); in nvmem_reg_read()
155 return nvmem_access_with_keepouts(nvmem, offset, val, bytes, false); in nvmem_reg_read()
158 static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset, in nvmem_reg_write() argument
161 if (!nvmem->nkeepout) in nvmem_reg_write()
162 return __nvmem_reg_write(nvmem, offset, val, bytes); in nvmem_reg_write()
164 return nvmem_access_with_keepouts(nvmem, offset, val, bytes, true); in nvmem_reg_write()
183 struct nvmem_device *nvmem = to_nvmem_device(dev); in type_show() local
185 return sprintf(buf, "%s\n", nvmem_type_str[nvmem->type]); in type_show()
200 struct nvmem_device *nvmem; in bin_attr_nvmem_read() local
207 nvmem = to_nvmem_device(dev); in bin_attr_nvmem_read()
210 if (pos >= nvmem->size) in bin_attr_nvmem_read()
213 if (!IS_ALIGNED(pos, nvmem->stride)) in bin_attr_nvmem_read()
216 if (count < nvmem->word_size) in bin_attr_nvmem_read()
219 if (pos + count > nvmem->size) in bin_attr_nvmem_read()
220 count = nvmem->size - pos; in bin_attr_nvmem_read()
222 count = round_down(count, nvmem->word_size); in bin_attr_nvmem_read()
224 if (!nvmem->reg_read) in bin_attr_nvmem_read()
227 rc = nvmem_reg_read(nvmem, pos, buf, count); in bin_attr_nvmem_read()
240 struct nvmem_device *nvmem; in bin_attr_nvmem_write() local
247 nvmem = to_nvmem_device(dev); in bin_attr_nvmem_write()
250 if (pos >= nvmem->size) in bin_attr_nvmem_write()
253 if (!IS_ALIGNED(pos, nvmem->stride)) in bin_attr_nvmem_write()
256 if (count < nvmem->word_size) in bin_attr_nvmem_write()
259 if (pos + count > nvmem->size) in bin_attr_nvmem_write()
260 count = nvmem->size - pos; in bin_attr_nvmem_write()
262 count = round_down(count, nvmem->word_size); in bin_attr_nvmem_write()
264 if (!nvmem->reg_write) in bin_attr_nvmem_write()
267 rc = nvmem_reg_write(nvmem, pos, buf, count); in bin_attr_nvmem_write()
275 static umode_t nvmem_bin_attr_get_umode(struct nvmem_device *nvmem) in nvmem_bin_attr_get_umode() argument
279 if (!nvmem->root_only) in nvmem_bin_attr_get_umode()
282 if (!nvmem->read_only) in nvmem_bin_attr_get_umode()
285 if (!nvmem->reg_write) in nvmem_bin_attr_get_umode()
288 if (!nvmem->reg_read) in nvmem_bin_attr_get_umode()
298 struct nvmem_device *nvmem = to_nvmem_device(dev); in nvmem_bin_attr_is_visible() local
300 attr->size = nvmem->size; in nvmem_bin_attr_is_visible()
302 return nvmem_bin_attr_get_umode(nvmem); in nvmem_bin_attr_is_visible()
308 .name = "nvmem",
344 static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem, in nvmem_sysfs_setup_compat() argument
355 nvmem->eeprom = bin_attr_nvmem_eeprom_compat; in nvmem_sysfs_setup_compat()
357 nvmem->eeprom.attr.name = "fram"; in nvmem_sysfs_setup_compat()
358 nvmem->eeprom.attr.mode = nvmem_bin_attr_get_umode(nvmem); in nvmem_sysfs_setup_compat()
359 nvmem->eeprom.size = nvmem->size; in nvmem_sysfs_setup_compat()
361 nvmem->eeprom.attr.key = &eeprom_lock_key; in nvmem_sysfs_setup_compat()
363 nvmem->eeprom.private = &nvmem->dev; in nvmem_sysfs_setup_compat()
364 nvmem->base_dev = config->base_dev; in nvmem_sysfs_setup_compat()
366 rval = device_create_bin_file(nvmem->base_dev, &nvmem->eeprom); in nvmem_sysfs_setup_compat()
368 dev_err(&nvmem->dev, in nvmem_sysfs_setup_compat()
373 nvmem->flags |= FLAG_COMPAT; in nvmem_sysfs_setup_compat()
378 static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem, in nvmem_sysfs_remove_compat() argument
382 device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); in nvmem_sysfs_remove_compat()
387 static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem, in nvmem_sysfs_setup_compat() argument
392 static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem, in nvmem_sysfs_remove_compat() argument
401 struct nvmem_device *nvmem = to_nvmem_device(dev); in nvmem_release() local
403 ida_free(&nvmem_ida, nvmem->id); in nvmem_release()
404 gpiod_put(nvmem->wp_gpio); in nvmem_release()
405 kfree(nvmem); in nvmem_release()
413 .name = "nvmem",
427 static void nvmem_device_remove_all_cells(const struct nvmem_device *nvmem) in nvmem_device_remove_all_cells() argument
431 list_for_each_entry_safe(cell, p, &nvmem->cells, node) in nvmem_device_remove_all_cells()
438 list_add_tail(&cell->node, &cell->nvmem->cells); in nvmem_cell_entry_add()
443 static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, in nvmem_cell_info_to_nvmem_cell_entry_nodup() argument
447 cell->nvmem = nvmem; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
463 if (!IS_ALIGNED(cell->offset, nvmem->stride)) { in nvmem_cell_info_to_nvmem_cell_entry_nodup()
464 dev_err(&nvmem->dev, in nvmem_cell_info_to_nvmem_cell_entry_nodup()
465 "cell %s unaligned to nvmem stride %d\n", in nvmem_cell_info_to_nvmem_cell_entry_nodup()
466 cell->name ?: "<unknown>", nvmem->stride); in nvmem_cell_info_to_nvmem_cell_entry_nodup()
473 static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem, in nvmem_cell_info_to_nvmem_cell_entry() argument
479 err = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, cell); in nvmem_cell_info_to_nvmem_cell_entry()
491 * nvmem_add_one_cell() - Add one cell information to an nvmem device
493 * @nvmem: nvmem device to add cells to.
494 * @info: nvmem cell info to add to the device
498 int nvmem_add_one_cell(struct nvmem_device *nvmem, in nvmem_add_one_cell() argument
508 rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell); in nvmem_add_one_cell()
521 * nvmem_add_cells() - Add cell information to an nvmem device
523 * @nvmem: nvmem device to add cells to.
524 * @info: nvmem cell info to add to the device
529 static int nvmem_add_cells(struct nvmem_device *nvmem, in nvmem_add_cells() argument
536 rval = nvmem_add_one_cell(nvmem, &info[i]); in nvmem_add_cells()
545 * nvmem_register_notifier() - Register a notifier block for nvmem events.
547 * @nb: notifier block to be called on nvmem events.
558 * nvmem_unregister_notifier() - Unregister a notifier block for nvmem events.
570 static int nvmem_add_cells_from_table(struct nvmem_device *nvmem) in nvmem_add_cells_from_table() argument
579 if (strcmp(nvmem_dev_name(nvmem), table->nvmem_name) == 0) { in nvmem_add_cells_from_table()
589 rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell); in nvmem_add_cells_from_table()
606 nvmem_find_cell_entry_by_name(struct nvmem_device *nvmem, const char *cell_id) in nvmem_find_cell_entry_by_name() argument
611 list_for_each_entry(iter, &nvmem->cells, node) { in nvmem_find_cell_entry_by_name()
622 static int nvmem_validate_keepouts(struct nvmem_device *nvmem) in nvmem_validate_keepouts() argument
625 const struct nvmem_keepout *keepout = nvmem->keepout; in nvmem_validate_keepouts()
626 const struct nvmem_keepout *keepoutend = keepout + nvmem->nkeepout; in nvmem_validate_keepouts()
631 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
638 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
648 if ((keepout->end - keepout->start < nvmem->word_size) || in nvmem_validate_keepouts()
650 (keepout->start - cur < nvmem->word_size))) { in nvmem_validate_keepouts()
652 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
659 if (!IS_ALIGNED(keepout->start, nvmem->stride) || in nvmem_validate_keepouts()
660 !IS_ALIGNED(keepout->end, nvmem->stride)) { in nvmem_validate_keepouts()
662 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
675 static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np) in nvmem_add_cells_from_dt() argument
677 struct device *dev = &nvmem->dev; in nvmem_add_cells_from_dt()
689 dev_err(dev, "nvmem: invalid reg on %pOF\n", child); in nvmem_add_cells_from_dt()
706 if (nvmem->fixup_dt_cell_info) in nvmem_add_cells_from_dt()
707 nvmem->fixup_dt_cell_info(nvmem, &info); in nvmem_add_cells_from_dt()
709 ret = nvmem_add_one_cell(nvmem, &info); in nvmem_add_cells_from_dt()
720 static int nvmem_add_cells_from_legacy_of(struct nvmem_device *nvmem) in nvmem_add_cells_from_legacy_of() argument
722 return nvmem_add_cells_from_dt(nvmem, nvmem->dev.of_node); in nvmem_add_cells_from_legacy_of()
725 static int nvmem_add_cells_from_fixed_layout(struct nvmem_device *nvmem) in nvmem_add_cells_from_fixed_layout() argument
730 layout_np = of_nvmem_layout_get_container(nvmem); in nvmem_add_cells_from_fixed_layout()
735 err = nvmem_add_cells_from_dt(nvmem, layout_np); in nvmem_add_cells_from_fixed_layout()
766 static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) in nvmem_layout_get() argument
771 layout_np = of_nvmem_layout_get_container(nvmem); in nvmem_layout_get()
782 * In case the nvmem device was built-in while the layout was built as a in nvmem_layout_get()
811 static int nvmem_add_cells_from_layout(struct nvmem_device *nvmem) in nvmem_add_cells_from_layout() argument
813 struct nvmem_layout *layout = nvmem->layout; in nvmem_add_cells_from_layout()
817 ret = layout->add_cells(&nvmem->dev, nvmem); in nvmem_add_cells_from_layout()
829 * @nvmem: nvmem device.
834 struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem) in of_nvmem_layout_get_container() argument
836 return of_get_child_by_name(nvmem->dev.of_node, "nvmem-layout"); in of_nvmem_layout_get_container()
841 const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, in nvmem_layout_get_match_data() argument
847 layout_np = of_nvmem_layout_get_container(nvmem); in nvmem_layout_get_match_data()
855 * nvmem_register() - Register a nvmem device for given nvmem_config.
856 * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
858 * @config: nvmem device configuration with which nvmem device is created.
866 struct nvmem_device *nvmem; in nvmem_register() local
875 nvmem = kzalloc(sizeof(*nvmem), GFP_KERNEL); in nvmem_register()
876 if (!nvmem) in nvmem_register()
881 kfree(nvmem); in nvmem_register()
885 nvmem->id = rval; in nvmem_register()
887 nvmem->dev.type = &nvmem_provider_type; in nvmem_register()
888 nvmem->dev.bus = &nvmem_bus_type; in nvmem_register()
889 nvmem->dev.parent = config->dev; in nvmem_register()
891 device_initialize(&nvmem->dev); in nvmem_register()
894 nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", in nvmem_register()
896 if (IS_ERR(nvmem->wp_gpio)) { in nvmem_register()
897 rval = PTR_ERR(nvmem->wp_gpio); in nvmem_register()
898 nvmem->wp_gpio = NULL; in nvmem_register()
902 kref_init(&nvmem->refcnt); in nvmem_register()
903 INIT_LIST_HEAD(&nvmem->cells); in nvmem_register()
904 nvmem->fixup_dt_cell_info = config->fixup_dt_cell_info; in nvmem_register()
906 nvmem->owner = config->owner; in nvmem_register()
907 if (!nvmem->owner && config->dev->driver) in nvmem_register()
908 nvmem->owner = config->dev->driver->owner; in nvmem_register()
909 nvmem->stride = config->stride ?: 1; in nvmem_register()
910 nvmem->word_size = config->word_size ?: 1; in nvmem_register()
911 nvmem->size = config->size; in nvmem_register()
912 nvmem->root_only = config->root_only; in nvmem_register()
913 nvmem->priv = config->priv; in nvmem_register()
914 nvmem->type = config->type; in nvmem_register()
915 nvmem->reg_read = config->reg_read; in nvmem_register()
916 nvmem->reg_write = config->reg_write; in nvmem_register()
917 nvmem->keepout = config->keepout; in nvmem_register()
918 nvmem->nkeepout = config->nkeepout; in nvmem_register()
920 nvmem->dev.of_node = config->of_node; in nvmem_register()
922 nvmem->dev.of_node = config->dev->of_node; in nvmem_register()
926 rval = dev_set_name(&nvmem->dev, "%s", config->name); in nvmem_register()
929 rval = dev_set_name(&nvmem->dev, "%s%d", config->name, nvmem->id); in nvmem_register()
932 rval = dev_set_name(&nvmem->dev, "%s%d", in nvmem_register()
933 config->name ? : "nvmem", in nvmem_register()
934 config->name ? config->id : nvmem->id); in nvmem_register()
941 nvmem->read_only = device_property_present(config->dev, "read-only") || in nvmem_register()
942 config->read_only || !nvmem->reg_write; in nvmem_register()
945 nvmem->dev.groups = nvmem_dev_groups; in nvmem_register()
948 if (nvmem->nkeepout) { in nvmem_register()
949 rval = nvmem_validate_keepouts(nvmem); in nvmem_register()
955 rval = nvmem_sysfs_setup_compat(nvmem, config); in nvmem_register()
964 nvmem->layout = config->layout ?: nvmem_layout_get(nvmem); in nvmem_register()
965 if (IS_ERR(nvmem->layout)) { in nvmem_register()
966 rval = PTR_ERR(nvmem->layout); in nvmem_register()
967 nvmem->layout = NULL; in nvmem_register()
974 rval = nvmem_add_cells(nvmem, config->cells, config->ncells); in nvmem_register()
979 rval = nvmem_add_cells_from_table(nvmem); in nvmem_register()
984 rval = nvmem_add_cells_from_legacy_of(nvmem); in nvmem_register()
989 rval = nvmem_add_cells_from_fixed_layout(nvmem); in nvmem_register()
993 rval = nvmem_add_cells_from_layout(nvmem); in nvmem_register()
997 dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); in nvmem_register()
999 rval = device_add(&nvmem->dev); in nvmem_register()
1003 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); in nvmem_register()
1005 return nvmem; in nvmem_register()
1008 nvmem_device_remove_all_cells(nvmem); in nvmem_register()
1009 nvmem_layout_put(nvmem->layout); in nvmem_register()
1012 nvmem_sysfs_remove_compat(nvmem, config); in nvmem_register()
1014 put_device(&nvmem->dev); in nvmem_register()
1022 struct nvmem_device *nvmem; in nvmem_device_release() local
1024 nvmem = container_of(kref, struct nvmem_device, refcnt); in nvmem_device_release()
1026 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_REMOVE, nvmem); in nvmem_device_release()
1028 if (nvmem->flags & FLAG_COMPAT) in nvmem_device_release()
1029 device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); in nvmem_device_release()
1031 nvmem_device_remove_all_cells(nvmem); in nvmem_device_release()
1032 nvmem_layout_put(nvmem->layout); in nvmem_device_release()
1033 device_unregister(&nvmem->dev); in nvmem_device_release()
1037 * nvmem_unregister() - Unregister previously registered nvmem device
1039 * @nvmem: Pointer to previously registered nvmem device.
1041 void nvmem_unregister(struct nvmem_device *nvmem) in nvmem_unregister() argument
1043 if (nvmem) in nvmem_unregister()
1044 kref_put(&nvmem->refcnt, nvmem_device_release); in nvmem_unregister()
1048 static void devm_nvmem_unregister(void *nvmem) in devm_nvmem_unregister() argument
1050 nvmem_unregister(nvmem); in devm_nvmem_unregister()
1054 * devm_nvmem_register() - Register a managed nvmem device for given
1056 * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
1058 * @dev: Device that uses the nvmem device.
1059 * @config: nvmem device configuration with which nvmem device is created.
1067 struct nvmem_device *nvmem; in devm_nvmem_register() local
1070 nvmem = nvmem_register(config); in devm_nvmem_register()
1071 if (IS_ERR(nvmem)) in devm_nvmem_register()
1072 return nvmem; in devm_nvmem_register()
1074 ret = devm_add_action_or_reset(dev, devm_nvmem_unregister, nvmem); in devm_nvmem_register()
1078 return nvmem; in devm_nvmem_register()
1085 struct nvmem_device *nvmem = NULL; in __nvmem_device_get() local
1091 nvmem = to_nvmem_device(dev); in __nvmem_device_get()
1093 if (!nvmem) in __nvmem_device_get()
1096 if (!try_module_get(nvmem->owner)) { in __nvmem_device_get()
1097 dev_err(&nvmem->dev, in __nvmem_device_get()
1099 nvmem_dev_name(nvmem)); in __nvmem_device_get()
1101 put_device(&nvmem->dev); in __nvmem_device_get()
1105 kref_get(&nvmem->refcnt); in __nvmem_device_get()
1107 return nvmem; in __nvmem_device_get()
1110 static void __nvmem_device_put(struct nvmem_device *nvmem) in __nvmem_device_put() argument
1112 put_device(&nvmem->dev); in __nvmem_device_put()
1113 module_put(nvmem->owner); in __nvmem_device_put()
1114 kref_put(&nvmem->refcnt, nvmem_device_release); in __nvmem_device_put()
1119 * of_nvmem_device_get() - Get nvmem device from a given id
1121 * @np: Device tree node that uses the nvmem device.
1122 * @id: nvmem name from nvmem-names property.
1131 struct nvmem_device *nvmem; in of_nvmem_device_get() local
1135 index = of_property_match_string(np, "nvmem-names", id); in of_nvmem_device_get()
1137 nvmem_np = of_parse_phandle(np, "nvmem", index); in of_nvmem_device_get()
1141 nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); in of_nvmem_device_get()
1143 return nvmem; in of_nvmem_device_get()
1149 * nvmem_device_get() - Get nvmem device from a given id
1151 * @dev: Device that uses the nvmem device.
1152 * @dev_name: name of the requested nvmem device.
1160 struct nvmem_device *nvmem; in nvmem_device_get() local
1162 nvmem = of_nvmem_device_get(dev->of_node, dev_name); in nvmem_device_get()
1164 if (!IS_ERR(nvmem) || PTR_ERR(nvmem) == -EPROBE_DEFER) in nvmem_device_get()
1165 return nvmem; in nvmem_device_get()
1174 * nvmem_device_find() - Find nvmem device with matching function
1191 struct nvmem_device **nvmem = res; in devm_nvmem_device_match() local
1193 if (WARN_ON(!nvmem || !*nvmem)) in devm_nvmem_device_match()
1196 return *nvmem == data; in devm_nvmem_device_match()
1205 * devm_nvmem_device_put() - put alredy got nvmem device
1207 * @dev: Device that uses the nvmem device.
1208 * @nvmem: pointer to nvmem device allocated by devm_nvmem_cell_get(),
1211 void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem) in devm_nvmem_device_put() argument
1216 devm_nvmem_device_match, nvmem); in devm_nvmem_device_put()
1223 * nvmem_device_put() - put alredy got nvmem device
1225 * @nvmem: pointer to nvmem device that needs to be released.
1227 void nvmem_device_put(struct nvmem_device *nvmem) in nvmem_device_put() argument
1229 __nvmem_device_put(nvmem); in nvmem_device_put()
1234 * devm_nvmem_device_get() - Get nvmem device of device form a given id
1236 * @dev: Device that requests the nvmem device.
1237 * @id: name id for the requested nvmem device.
1245 struct nvmem_device **ptr, *nvmem; in devm_nvmem_device_get() local
1251 nvmem = nvmem_device_get(dev, id); in devm_nvmem_device_get()
1252 if (!IS_ERR(nvmem)) { in devm_nvmem_device_get()
1253 *ptr = nvmem; in devm_nvmem_device_get()
1259 return nvmem; in devm_nvmem_device_get()
1294 struct nvmem_device *nvmem; in nvmem_cell_get_from_lookup() local
1308 nvmem = __nvmem_device_get((void *)lookup->nvmem_name, in nvmem_cell_get_from_lookup()
1310 if (IS_ERR(nvmem)) { in nvmem_cell_get_from_lookup()
1312 cell = ERR_CAST(nvmem); in nvmem_cell_get_from_lookup()
1316 cell_entry = nvmem_find_cell_entry_by_name(nvmem, in nvmem_cell_get_from_lookup()
1319 __nvmem_device_put(nvmem); in nvmem_cell_get_from_lookup()
1324 __nvmem_device_put(nvmem); in nvmem_cell_get_from_lookup()
1336 nvmem_find_cell_entry_by_node(struct nvmem_device *nvmem, struct device_node *np) in nvmem_find_cell_entry_by_node() argument
1341 list_for_each_entry(iter, &nvmem->cells, node) { in nvmem_find_cell_entry_by_node()
1353 * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id
1355 * @np: Device tree node that uses the nvmem cell.
1356 * @id: nvmem cell name from nvmem-cell-names property, or NULL
1358 * nvmem-cell-names property).
1367 struct nvmem_device *nvmem; in of_nvmem_cell_get() local
1377 index = of_property_match_string(np, "nvmem-cell-names", id); in of_nvmem_cell_get()
1379 ret = of_parse_phandle_with_optional_args(np, "nvmem-cells", in of_nvmem_cell_get()
1380 "#nvmem-cell-cells", in of_nvmem_cell_get()
1398 /* nvmem layouts produce cells within the nvmem-layout container */ in of_nvmem_cell_get()
1399 if (of_node_name_eq(nvmem_np, "nvmem-layout")) { in of_nvmem_cell_get()
1407 nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); in of_nvmem_cell_get()
1409 if (IS_ERR(nvmem)) { in of_nvmem_cell_get()
1411 return ERR_CAST(nvmem); in of_nvmem_cell_get()
1414 cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np); in of_nvmem_cell_get()
1417 __nvmem_device_put(nvmem); in of_nvmem_cell_get()
1423 __nvmem_device_put(nvmem); in of_nvmem_cell_get()
1431 * nvmem_cell_get() - Get nvmem cell of device form a given cell name
1433 * @dev: Device that requests the nvmem cell.
1434 * @id: nvmem cell name to get (this corresponds with the name from the
1435 * nvmem-cell-names property for DT systems and with the con_id from
1466 * devm_nvmem_cell_get() - Get nvmem cell of device form a given id
1468 * @dev: Device that requests the nvmem cell.
1469 * @id: nvmem cell name id to get.
1506 * devm_nvmem_cell_put() - Release previously allocated nvmem cell
1509 * @dev: Device that requests the nvmem cell.
1510 * @cell: Previously allocated nvmem cell by devm_nvmem_cell_get().
1524 * nvmem_cell_put() - Release previously allocated nvmem cell.
1526 * @cell: Previously allocated nvmem cell by nvmem_cell_get().
1530 struct nvmem_device *nvmem = cell->entry->nvmem; in nvmem_cell_put() local
1536 __nvmem_device_put(nvmem); in nvmem_cell_put()
1573 static int __nvmem_cell_read(struct nvmem_device *nvmem, in __nvmem_cell_read() argument
1579 rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->raw_len); in __nvmem_cell_read()
1602 * nvmem_cell_read() - Read a given nvmem cell
1604 * @cell: nvmem cell to be read.
1614 struct nvmem_device *nvmem = entry->nvmem; in nvmem_cell_read() local
1618 if (!nvmem) in nvmem_cell_read()
1625 rc = __nvmem_cell_read(nvmem, cell->entry, buf, len, cell->id, cell->index); in nvmem_cell_read()
1638 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_prepare_write_buffer() local
1654 /* setup the first byte with lsb bits from nvmem */ in nvmem_cell_prepare_write_buffer()
1655 rc = nvmem_reg_read(nvmem, cell->offset, &v, 1); in nvmem_cell_prepare_write_buffer()
1673 /* setup the last byte with msb bits from nvmem */ in nvmem_cell_prepare_write_buffer()
1674 rc = nvmem_reg_read(nvmem, in nvmem_cell_prepare_write_buffer()
1690 struct nvmem_device *nvmem = cell->nvmem; in __nvmem_cell_entry_write() local
1693 if (!nvmem || nvmem->read_only || in __nvmem_cell_entry_write()
1713 rc = nvmem_reg_write(nvmem, cell->offset, buf, cell->bytes); in __nvmem_cell_entry_write()
1726 * nvmem_cell_write() - Write to a given nvmem cell
1728 * @cell: nvmem cell to be written.
1730 * @len: length of buffer to be written to nvmem cell.
1772 * @dev: Device that requests the nvmem cell.
1773 * @cell_id: Name of nvmem cell to read.
1787 * @dev: Device that requests the nvmem cell.
1788 * @cell_id: Name of nvmem cell to read.
1802 * @dev: Device that requests the nvmem cell.
1803 * @cell_id: Name of nvmem cell to read.
1817 * @dev: Device that requests the nvmem cell.
1818 * @cell_id: Name of nvmem cell to read.
1865 * @dev: Device that requests the nvmem cell.
1866 * @cell_id: Name of nvmem cell to read.
1896 * @dev: Device that requests the nvmem cell.
1897 * @cell_id: Name of nvmem cell to read.
1925 * nvmem_device_cell_read() - Read a given nvmem device and cell
1927 * @nvmem: nvmem device to read from.
1928 * @info: nvmem cell info to be read.
1934 ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, in nvmem_device_cell_read() argument
1941 if (!nvmem) in nvmem_device_cell_read()
1944 rc = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, &cell); in nvmem_device_cell_read()
1948 rc = __nvmem_cell_read(nvmem, &cell, buf, &len, NULL, 0); in nvmem_device_cell_read()
1957 * nvmem_device_cell_write() - Write cell to a given nvmem device
1959 * @nvmem: nvmem device to be written to.
1960 * @info: nvmem cell info to be written.
1965 int nvmem_device_cell_write(struct nvmem_device *nvmem, in nvmem_device_cell_write() argument
1971 if (!nvmem) in nvmem_device_cell_write()
1974 rc = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, &cell); in nvmem_device_cell_write()
1983 * nvmem_device_read() - Read from a given nvmem device
1985 * @nvmem: nvmem device to read from.
1986 * @offset: offset in nvmem device.
1993 int nvmem_device_read(struct nvmem_device *nvmem, in nvmem_device_read() argument
1999 if (!nvmem) in nvmem_device_read()
2002 rc = nvmem_reg_read(nvmem, offset, buf, bytes); in nvmem_device_read()
2012 * nvmem_device_write() - Write cell to a given nvmem device
2014 * @nvmem: nvmem device to be written to.
2015 * @offset: offset in nvmem device.
2021 int nvmem_device_write(struct nvmem_device *nvmem, in nvmem_device_write() argument
2027 if (!nvmem) in nvmem_device_write()
2030 rc = nvmem_reg_write(nvmem, offset, buf, bytes); in nvmem_device_write()
2102 * nvmem_dev_name() - Get the name of a given nvmem device.
2104 * @nvmem: nvmem device.
2106 * Return: name of the nvmem device.
2108 const char *nvmem_dev_name(struct nvmem_device *nvmem) in nvmem_dev_name() argument
2110 return dev_name(&nvmem->dev); in nvmem_dev_name()
2115 * nvmem_dev_size() - Get the size of a given nvmem device.
2117 * @nvmem: nvmem device.
2119 * Return: size of the nvmem device.
2121 size_t nvmem_dev_size(struct nvmem_device *nvmem) in nvmem_dev_size() argument
2123 return nvmem->size; in nvmem_dev_size()
2142 MODULE_DESCRIPTION("nvmem Driver Core");