Lines Matching +full:nvmem +full:- +full:cell +full:- +full:names
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
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()
67 return -EINVAL; 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()
82 return -EINVAL; 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()
100 while ((keepout < keepoutend) && (keepout->end <= offset)) in nvmem_access_with_keepouts()
105 if (offset < keepout->start) { in nvmem_access_with_keepouts()
106 kend = min(end, keepout->start); in nvmem_access_with_keepouts()
107 ksize = kend - offset; 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()
124 kend = min(end, keepout->end); in nvmem_access_with_keepouts()
125 ksize = kend - offset; in nvmem_access_with_keepouts()
127 memset(val, keepout->value, ksize); in nvmem_access_with_keepouts()
139 ksize = end - offset; 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
203 if (attr->private) in bin_attr_nvmem_read()
204 dev = attr->private; in bin_attr_nvmem_read()
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()
214 return -EINVAL; in bin_attr_nvmem_read()
216 if (count < nvmem->word_size) in bin_attr_nvmem_read()
217 return -EINVAL; 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()
225 return -EPERM; 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
243 if (attr->private) in bin_attr_nvmem_write()
244 dev = attr->private; in bin_attr_nvmem_write()
247 nvmem = to_nvmem_device(dev); in bin_attr_nvmem_write()
250 if (pos >= nvmem->size) in bin_attr_nvmem_write()
251 return -EFBIG; in bin_attr_nvmem_write()
253 if (!IS_ALIGNED(pos, nvmem->stride)) in bin_attr_nvmem_write()
254 return -EINVAL; in bin_attr_nvmem_write()
256 if (count < nvmem->word_size) in bin_attr_nvmem_write()
257 return -EINVAL; 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()
265 return -EPERM; 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",
340 * nvmem_setup_compat() - Create an additional binary entry in
344 static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem, in nvmem_sysfs_setup_compat() argument
349 if (!config->compat) in nvmem_sysfs_setup_compat()
352 if (!config->base_dev) in nvmem_sysfs_setup_compat()
353 return -EINVAL; in nvmem_sysfs_setup_compat()
355 nvmem->eeprom = bin_attr_nvmem_eeprom_compat; in nvmem_sysfs_setup_compat()
356 if (config->type == NVMEM_TYPE_FRAM) 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
381 if (config->compat) in nvmem_sysfs_remove_compat()
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
390 return -ENOSYS; in nvmem_sysfs_setup_compat()
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",
416 static void nvmem_cell_entry_drop(struct nvmem_cell_entry *cell) in nvmem_cell_entry_drop() argument
418 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_REMOVE, cell); in nvmem_cell_entry_drop()
420 list_del(&cell->node); in nvmem_cell_entry_drop()
422 of_node_put(cell->np); in nvmem_cell_entry_drop()
423 kfree_const(cell->name); in nvmem_cell_entry_drop()
424 kfree(cell); in nvmem_cell_entry_drop()
427 static void nvmem_device_remove_all_cells(const struct nvmem_device *nvmem) in nvmem_device_remove_all_cells() argument
429 struct nvmem_cell_entry *cell, *p; in nvmem_device_remove_all_cells() local
431 list_for_each_entry_safe(cell, p, &nvmem->cells, node) in nvmem_device_remove_all_cells()
432 nvmem_cell_entry_drop(cell); in nvmem_device_remove_all_cells()
435 static void nvmem_cell_entry_add(struct nvmem_cell_entry *cell) in nvmem_cell_entry_add() argument
438 list_add_tail(&cell->node, &cell->nvmem->cells); in nvmem_cell_entry_add()
440 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_ADD, cell); 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
445 struct nvmem_cell_entry *cell) in nvmem_cell_info_to_nvmem_cell_entry_nodup() argument
447 cell->nvmem = nvmem; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
448 cell->offset = info->offset; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
449 cell->raw_len = info->raw_len ?: info->bytes; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
450 cell->bytes = info->bytes; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
451 cell->name = info->name; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
452 cell->read_post_process = info->read_post_process; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
453 cell->priv = info->priv; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
455 cell->bit_offset = info->bit_offset; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
456 cell->nbits = info->nbits; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
457 cell->np = info->np; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
459 if (cell->nbits) { in nvmem_cell_info_to_nvmem_cell_entry_nodup()
460 cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset, in nvmem_cell_info_to_nvmem_cell_entry_nodup()
462 cell->raw_len = ALIGN(cell->bytes, nvmem->word_size); in nvmem_cell_info_to_nvmem_cell_entry_nodup()
465 if (!IS_ALIGNED(cell->offset, nvmem->stride)) { in nvmem_cell_info_to_nvmem_cell_entry_nodup()
466 dev_err(&nvmem->dev, in nvmem_cell_info_to_nvmem_cell_entry_nodup()
467 "cell %s unaligned to nvmem stride %d\n", in nvmem_cell_info_to_nvmem_cell_entry_nodup()
468 cell->name ?: "<unknown>", nvmem->stride); in nvmem_cell_info_to_nvmem_cell_entry_nodup()
469 return -EINVAL; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
472 if (!IS_ALIGNED(cell->raw_len, nvmem->word_size)) { in nvmem_cell_info_to_nvmem_cell_entry_nodup()
473 dev_err(&nvmem->dev, in nvmem_cell_info_to_nvmem_cell_entry_nodup()
474 "cell %s raw len %zd unaligned to nvmem word size %d\n", in nvmem_cell_info_to_nvmem_cell_entry_nodup()
475 cell->name ?: "<unknown>", cell->raw_len, in nvmem_cell_info_to_nvmem_cell_entry_nodup()
476 nvmem->word_size); in nvmem_cell_info_to_nvmem_cell_entry_nodup()
478 if (info->raw_len) in nvmem_cell_info_to_nvmem_cell_entry_nodup()
479 return -EINVAL; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
481 cell->raw_len = ALIGN(cell->raw_len, nvmem->word_size); in nvmem_cell_info_to_nvmem_cell_entry_nodup()
487 static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem, in nvmem_cell_info_to_nvmem_cell_entry() argument
489 struct nvmem_cell_entry *cell) in nvmem_cell_info_to_nvmem_cell_entry() argument
493 err = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, cell); in nvmem_cell_info_to_nvmem_cell_entry()
497 cell->name = kstrdup_const(info->name, GFP_KERNEL); in nvmem_cell_info_to_nvmem_cell_entry()
498 if (!cell->name) in nvmem_cell_info_to_nvmem_cell_entry()
499 return -ENOMEM; in nvmem_cell_info_to_nvmem_cell_entry()
505 * nvmem_add_one_cell() - Add one cell information to an nvmem device
507 * @nvmem: nvmem device to add cells to.
508 * @info: nvmem cell info to add to the device
512 int nvmem_add_one_cell(struct nvmem_device *nvmem, in nvmem_add_one_cell() argument
515 struct nvmem_cell_entry *cell; in nvmem_add_one_cell() local
518 cell = kzalloc(sizeof(*cell), GFP_KERNEL); in nvmem_add_one_cell()
519 if (!cell) in nvmem_add_one_cell()
520 return -ENOMEM; in nvmem_add_one_cell()
522 rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell); in nvmem_add_one_cell()
524 kfree(cell); in nvmem_add_one_cell()
528 nvmem_cell_entry_add(cell); in nvmem_add_one_cell()
535 * nvmem_add_cells() - Add cell information to an nvmem device
537 * @nvmem: nvmem device to add cells to.
538 * @info: nvmem cell info to add to the device
543 static int nvmem_add_cells(struct nvmem_device *nvmem, in nvmem_add_cells() argument
550 rval = nvmem_add_one_cell(nvmem, &info[i]); in nvmem_add_cells()
559 * nvmem_register_notifier() - Register a notifier block for nvmem events.
561 * @nb: notifier block to be called on nvmem events.
572 * nvmem_unregister_notifier() - Unregister a notifier block for nvmem events.
584 static int nvmem_add_cells_from_table(struct nvmem_device *nvmem) in nvmem_add_cells_from_table() argument
588 struct nvmem_cell_entry *cell; in nvmem_add_cells_from_table() local
593 if (strcmp(nvmem_dev_name(nvmem), table->nvmem_name) == 0) { in nvmem_add_cells_from_table()
594 for (i = 0; i < table->ncells; i++) { in nvmem_add_cells_from_table()
595 info = &table->cells[i]; in nvmem_add_cells_from_table()
597 cell = kzalloc(sizeof(*cell), GFP_KERNEL); in nvmem_add_cells_from_table()
598 if (!cell) { in nvmem_add_cells_from_table()
599 rval = -ENOMEM; in nvmem_add_cells_from_table()
603 rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell); in nvmem_add_cells_from_table()
605 kfree(cell); in nvmem_add_cells_from_table()
609 nvmem_cell_entry_add(cell); in nvmem_add_cells_from_table()
620 nvmem_find_cell_entry_by_name(struct nvmem_device *nvmem, const char *cell_id) in nvmem_find_cell_entry_by_name() argument
622 struct nvmem_cell_entry *iter, *cell = NULL; in nvmem_find_cell_entry_by_name() local
625 list_for_each_entry(iter, &nvmem->cells, node) { in nvmem_find_cell_entry_by_name()
626 if (strcmp(cell_id, iter->name) == 0) { in nvmem_find_cell_entry_by_name()
627 cell = iter; in nvmem_find_cell_entry_by_name()
633 return cell; in nvmem_find_cell_entry_by_name()
636 static int nvmem_validate_keepouts(struct nvmem_device *nvmem) in nvmem_validate_keepouts() argument
639 const struct nvmem_keepout *keepout = nvmem->keepout; in nvmem_validate_keepouts()
640 const struct nvmem_keepout *keepoutend = keepout + nvmem->nkeepout; in nvmem_validate_keepouts()
644 if (keepout->start < cur) { in nvmem_validate_keepouts()
645 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
648 return -ERANGE; in nvmem_validate_keepouts()
651 if (keepout->end < keepout->start) { in nvmem_validate_keepouts()
652 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
655 return -EINVAL; in nvmem_validate_keepouts()
662 if ((keepout->end - keepout->start < nvmem->word_size) || in nvmem_validate_keepouts()
663 ((keepout->start != cur) && in nvmem_validate_keepouts()
664 (keepout->start - cur < nvmem->word_size))) { in nvmem_validate_keepouts()
666 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
669 return -ERANGE; in nvmem_validate_keepouts()
673 if (!IS_ALIGNED(keepout->start, nvmem->stride) || in nvmem_validate_keepouts()
674 !IS_ALIGNED(keepout->end, nvmem->stride)) { in nvmem_validate_keepouts()
676 dev_err(&nvmem->dev, in nvmem_validate_keepouts()
679 return -EINVAL; in nvmem_validate_keepouts()
682 cur = keepout->end; in nvmem_validate_keepouts()
689 static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np) in nvmem_add_cells_from_dt() argument
691 struct device *dev = &nvmem->dev; in nvmem_add_cells_from_dt()
703 dev_err(dev, "nvmem: invalid reg on %pOF\n", child); in nvmem_add_cells_from_dt()
705 return -EINVAL; in nvmem_add_cells_from_dt()
720 if (nvmem->fixup_dt_cell_info) in nvmem_add_cells_from_dt()
721 nvmem->fixup_dt_cell_info(nvmem, &info); in nvmem_add_cells_from_dt()
723 ret = nvmem_add_one_cell(nvmem, &info); in nvmem_add_cells_from_dt()
734 static int nvmem_add_cells_from_legacy_of(struct nvmem_device *nvmem) in nvmem_add_cells_from_legacy_of() argument
736 return nvmem_add_cells_from_dt(nvmem, nvmem->dev.of_node); in nvmem_add_cells_from_legacy_of()
739 static int nvmem_add_cells_from_fixed_layout(struct nvmem_device *nvmem) in nvmem_add_cells_from_fixed_layout() argument
744 layout_np = of_nvmem_layout_get_container(nvmem); in nvmem_add_cells_from_fixed_layout()
748 if (of_device_is_compatible(layout_np, "fixed-layout")) in nvmem_add_cells_from_fixed_layout()
749 err = nvmem_add_cells_from_dt(nvmem, layout_np); in nvmem_add_cells_from_fixed_layout()
758 layout->owner = owner; in __nvmem_layout_register()
761 list_add(&layout->node, &nvmem_layouts); in __nvmem_layout_register()
775 list_del(&layout->node); in nvmem_layout_unregister()
780 static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) in nvmem_layout_get() argument
783 struct nvmem_layout *l, *layout = ERR_PTR(-EPROBE_DEFER); in nvmem_layout_get()
785 layout_np = of_nvmem_layout_get_container(nvmem); in nvmem_layout_get()
790 if (of_device_is_compatible(layout_np, "fixed-layout")) { in nvmem_layout_get()
796 * In case the nvmem device was built-in while the layout was built as a in nvmem_layout_get()
805 if (of_match_node(l->of_match_table, layout_np)) { in nvmem_layout_get()
806 if (try_module_get(l->owner)) in nvmem_layout_get()
822 module_put(layout->owner); in nvmem_layout_put()
825 static int nvmem_add_cells_from_layout(struct nvmem_device *nvmem) in nvmem_add_cells_from_layout() argument
827 struct nvmem_layout *layout = nvmem->layout; in nvmem_add_cells_from_layout()
830 if (layout && layout->add_cells) { in nvmem_add_cells_from_layout()
831 ret = layout->add_cells(&nvmem->dev, nvmem); in nvmem_add_cells_from_layout()
841 * of_nvmem_layout_get_container() - Get OF node to layout container.
843 * @nvmem: nvmem device.
848 struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem) in of_nvmem_layout_get_container() argument
850 return of_get_child_by_name(nvmem->dev.of_node, "nvmem-layout"); in of_nvmem_layout_get_container()
855 const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, in nvmem_layout_get_match_data() argument
861 layout_np = of_nvmem_layout_get_container(nvmem); in nvmem_layout_get_match_data()
862 match = of_match_node(layout->of_match_table, layout_np); in nvmem_layout_get_match_data()
864 return match ? match->data : NULL; in nvmem_layout_get_match_data()
869 * nvmem_register() - Register a nvmem device for given nvmem_config.
870 * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
872 * @config: nvmem device configuration with which nvmem device is created.
880 struct nvmem_device *nvmem; in nvmem_register() local
883 if (!config->dev) in nvmem_register()
884 return ERR_PTR(-EINVAL); in nvmem_register()
886 if (!config->reg_read && !config->reg_write) in nvmem_register()
887 return ERR_PTR(-EINVAL); in nvmem_register()
889 nvmem = kzalloc(sizeof(*nvmem), GFP_KERNEL); in nvmem_register()
890 if (!nvmem) in nvmem_register()
891 return ERR_PTR(-ENOMEM); in nvmem_register()
895 kfree(nvmem); in nvmem_register()
899 nvmem->id = rval; in nvmem_register()
901 nvmem->dev.type = &nvmem_provider_type; in nvmem_register()
902 nvmem->dev.bus = &nvmem_bus_type; in nvmem_register()
903 nvmem->dev.parent = config->dev; in nvmem_register()
905 device_initialize(&nvmem->dev); in nvmem_register()
907 if (!config->ignore_wp) in nvmem_register()
908 nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", in nvmem_register()
910 if (IS_ERR(nvmem->wp_gpio)) { in nvmem_register()
911 rval = PTR_ERR(nvmem->wp_gpio); in nvmem_register()
912 nvmem->wp_gpio = NULL; in nvmem_register()
916 kref_init(&nvmem->refcnt); in nvmem_register()
917 INIT_LIST_HEAD(&nvmem->cells); in nvmem_register()
918 nvmem->fixup_dt_cell_info = config->fixup_dt_cell_info; in nvmem_register()
920 nvmem->owner = config->owner; in nvmem_register()
921 if (!nvmem->owner && config->dev->driver) in nvmem_register()
922 nvmem->owner = config->dev->driver->owner; in nvmem_register()
923 nvmem->stride = config->stride ?: 1; in nvmem_register()
924 nvmem->word_size = config->word_size ?: 1; in nvmem_register()
925 nvmem->size = config->size; in nvmem_register()
926 nvmem->root_only = config->root_only; in nvmem_register()
927 nvmem->priv = config->priv; in nvmem_register()
928 nvmem->type = config->type; in nvmem_register()
929 nvmem->reg_read = config->reg_read; in nvmem_register()
930 nvmem->reg_write = config->reg_write; in nvmem_register()
931 nvmem->keepout = config->keepout; in nvmem_register()
932 nvmem->nkeepout = config->nkeepout; in nvmem_register()
933 if (config->of_node) in nvmem_register()
934 nvmem->dev.of_node = config->of_node; in nvmem_register()
935 else if (!config->no_of_node) in nvmem_register()
936 nvmem->dev.of_node = config->dev->of_node; in nvmem_register()
938 switch (config->id) { in nvmem_register()
940 rval = dev_set_name(&nvmem->dev, "%s", config->name); in nvmem_register()
943 rval = dev_set_name(&nvmem->dev, "%s%d", config->name, nvmem->id); in nvmem_register()
946 rval = dev_set_name(&nvmem->dev, "%s%d", in nvmem_register()
947 config->name ? : "nvmem", in nvmem_register()
948 config->name ? config->id : nvmem->id); in nvmem_register()
955 nvmem->read_only = device_property_present(config->dev, "read-only") || in nvmem_register()
956 config->read_only || !nvmem->reg_write; in nvmem_register()
959 nvmem->dev.groups = nvmem_dev_groups; in nvmem_register()
962 if (nvmem->nkeepout) { in nvmem_register()
963 rval = nvmem_validate_keepouts(nvmem); in nvmem_register()
968 if (config->compat) { in nvmem_register()
969 rval = nvmem_sysfs_setup_compat(nvmem, config); in nvmem_register()
975 * If the driver supplied a layout by config->layout, the module in nvmem_register()
978 nvmem->layout = config->layout ?: nvmem_layout_get(nvmem); in nvmem_register()
979 if (IS_ERR(nvmem->layout)) { in nvmem_register()
980 rval = PTR_ERR(nvmem->layout); in nvmem_register()
981 nvmem->layout = NULL; in nvmem_register()
983 if (rval == -EPROBE_DEFER) in nvmem_register()
987 if (config->cells) { in nvmem_register()
988 rval = nvmem_add_cells(nvmem, config->cells, config->ncells); in nvmem_register()
993 rval = nvmem_add_cells_from_table(nvmem); in nvmem_register()
997 if (config->add_legacy_fixed_of_cells) { in nvmem_register()
998 rval = nvmem_add_cells_from_legacy_of(nvmem); in nvmem_register()
1003 rval = nvmem_add_cells_from_fixed_layout(nvmem); in nvmem_register()
1007 rval = nvmem_add_cells_from_layout(nvmem); in nvmem_register()
1011 dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); in nvmem_register()
1013 rval = device_add(&nvmem->dev); in nvmem_register()
1017 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); in nvmem_register()
1019 return nvmem; in nvmem_register()
1022 nvmem_device_remove_all_cells(nvmem); in nvmem_register()
1023 nvmem_layout_put(nvmem->layout); in nvmem_register()
1025 if (config->compat) in nvmem_register()
1026 nvmem_sysfs_remove_compat(nvmem, config); in nvmem_register()
1028 put_device(&nvmem->dev); in nvmem_register()
1036 struct nvmem_device *nvmem; in nvmem_device_release() local
1038 nvmem = container_of(kref, struct nvmem_device, refcnt); in nvmem_device_release()
1040 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_REMOVE, nvmem); in nvmem_device_release()
1042 if (nvmem->flags & FLAG_COMPAT) in nvmem_device_release()
1043 device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); in nvmem_device_release()
1045 nvmem_device_remove_all_cells(nvmem); in nvmem_device_release()
1046 nvmem_layout_put(nvmem->layout); in nvmem_device_release()
1047 device_unregister(&nvmem->dev); in nvmem_device_release()
1051 * nvmem_unregister() - Unregister previously registered nvmem device
1053 * @nvmem: Pointer to previously registered nvmem device.
1055 void nvmem_unregister(struct nvmem_device *nvmem) in nvmem_unregister() argument
1057 if (nvmem) in nvmem_unregister()
1058 kref_put(&nvmem->refcnt, nvmem_device_release); in nvmem_unregister()
1062 static void devm_nvmem_unregister(void *nvmem) in devm_nvmem_unregister() argument
1064 nvmem_unregister(nvmem); in devm_nvmem_unregister()
1068 * devm_nvmem_register() - Register a managed nvmem device for given
1070 * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
1072 * @dev: Device that uses the nvmem device.
1073 * @config: nvmem device configuration with which nvmem device is created.
1081 struct nvmem_device *nvmem; in devm_nvmem_register() local
1084 nvmem = nvmem_register(config); in devm_nvmem_register()
1085 if (IS_ERR(nvmem)) in devm_nvmem_register()
1086 return nvmem; in devm_nvmem_register()
1088 ret = devm_add_action_or_reset(dev, devm_nvmem_unregister, nvmem); in devm_nvmem_register()
1092 return nvmem; in devm_nvmem_register()
1099 struct nvmem_device *nvmem = NULL; in __nvmem_device_get() local
1105 nvmem = to_nvmem_device(dev); in __nvmem_device_get()
1107 if (!nvmem) in __nvmem_device_get()
1108 return ERR_PTR(-EPROBE_DEFER); in __nvmem_device_get()
1110 if (!try_module_get(nvmem->owner)) { in __nvmem_device_get()
1111 dev_err(&nvmem->dev, in __nvmem_device_get()
1112 "could not increase module refcount for cell %s\n", in __nvmem_device_get()
1113 nvmem_dev_name(nvmem)); in __nvmem_device_get()
1115 put_device(&nvmem->dev); in __nvmem_device_get()
1116 return ERR_PTR(-EINVAL); in __nvmem_device_get()
1119 kref_get(&nvmem->refcnt); in __nvmem_device_get()
1121 return nvmem; in __nvmem_device_get()
1124 static void __nvmem_device_put(struct nvmem_device *nvmem) in __nvmem_device_put() argument
1126 put_device(&nvmem->dev); in __nvmem_device_put()
1127 module_put(nvmem->owner); in __nvmem_device_put()
1128 kref_put(&nvmem->refcnt, nvmem_device_release); in __nvmem_device_put()
1133 * of_nvmem_device_get() - Get nvmem device from a given id
1135 * @np: Device tree node that uses the nvmem device.
1136 * @id: nvmem name from nvmem-names property.
1145 struct nvmem_device *nvmem; in of_nvmem_device_get() local
1149 index = of_property_match_string(np, "nvmem-names", id); in of_nvmem_device_get()
1151 nvmem_np = of_parse_phandle(np, "nvmem", index); in of_nvmem_device_get()
1153 return ERR_PTR(-ENOENT); in of_nvmem_device_get()
1155 nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); in of_nvmem_device_get()
1157 return nvmem; in of_nvmem_device_get()
1163 * nvmem_device_get() - Get nvmem device from a given id
1165 * @dev: Device that uses the nvmem device.
1166 * @dev_name: name of the requested nvmem device.
1173 if (dev->of_node) { /* try dt first */ in nvmem_device_get()
1174 struct nvmem_device *nvmem; in nvmem_device_get() local
1176 nvmem = of_nvmem_device_get(dev->of_node, dev_name); in nvmem_device_get()
1178 if (!IS_ERR(nvmem) || PTR_ERR(nvmem) == -EPROBE_DEFER) in nvmem_device_get()
1179 return nvmem; in nvmem_device_get()
1188 * nvmem_device_find() - Find nvmem device with matching function
1205 struct nvmem_device **nvmem = res; in devm_nvmem_device_match() local
1207 if (WARN_ON(!nvmem || !*nvmem)) in devm_nvmem_device_match()
1210 return *nvmem == data; in devm_nvmem_device_match()
1219 * devm_nvmem_device_put() - put alredy got nvmem device
1221 * @dev: Device that uses the nvmem device.
1222 * @nvmem: pointer to nvmem device allocated by devm_nvmem_cell_get(),
1225 void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem) in devm_nvmem_device_put() argument
1230 devm_nvmem_device_match, nvmem); in devm_nvmem_device_put()
1237 * nvmem_device_put() - put alredy got nvmem device
1239 * @nvmem: pointer to nvmem device that needs to be released.
1241 void nvmem_device_put(struct nvmem_device *nvmem) in nvmem_device_put() argument
1243 __nvmem_device_put(nvmem); in nvmem_device_put()
1248 * devm_nvmem_device_get() - Get nvmem device of device form a given id
1250 * @dev: Device that requests the nvmem device.
1251 * @id: name id for the requested nvmem device.
1259 struct nvmem_device **ptr, *nvmem; in devm_nvmem_device_get() local
1263 return ERR_PTR(-ENOMEM); in devm_nvmem_device_get()
1265 nvmem = nvmem_device_get(dev, id); in devm_nvmem_device_get()
1266 if (!IS_ERR(nvmem)) { in devm_nvmem_device_get()
1267 *ptr = nvmem; in devm_nvmem_device_get()
1273 return nvmem; in devm_nvmem_device_get()
1280 struct nvmem_cell *cell; in nvmem_create_cell() local
1283 cell = kzalloc(sizeof(*cell), GFP_KERNEL); in nvmem_create_cell()
1284 if (!cell) in nvmem_create_cell()
1285 return ERR_PTR(-ENOMEM); in nvmem_create_cell()
1290 kfree(cell); in nvmem_create_cell()
1291 return ERR_PTR(-ENOMEM); in nvmem_create_cell()
1295 cell->id = name; in nvmem_create_cell()
1296 cell->entry = entry; in nvmem_create_cell()
1297 cell->index = index; in nvmem_create_cell()
1299 return cell; in nvmem_create_cell()
1306 struct nvmem_cell *cell = ERR_PTR(-ENOENT); in nvmem_cell_get_from_lookup() local
1308 struct nvmem_device *nvmem; in nvmem_cell_get_from_lookup() local
1312 return ERR_PTR(-EINVAL); in nvmem_cell_get_from_lookup()
1319 if ((strcmp(lookup->dev_id, dev_id) == 0) && in nvmem_cell_get_from_lookup()
1320 (strcmp(lookup->con_id, con_id) == 0)) { in nvmem_cell_get_from_lookup()
1322 nvmem = __nvmem_device_get((void *)lookup->nvmem_name, in nvmem_cell_get_from_lookup()
1324 if (IS_ERR(nvmem)) { in nvmem_cell_get_from_lookup()
1326 cell = ERR_CAST(nvmem); in nvmem_cell_get_from_lookup()
1330 cell_entry = nvmem_find_cell_entry_by_name(nvmem, in nvmem_cell_get_from_lookup()
1331 lookup->cell_name); in nvmem_cell_get_from_lookup()
1333 __nvmem_device_put(nvmem); in nvmem_cell_get_from_lookup()
1334 cell = ERR_PTR(-ENOENT); in nvmem_cell_get_from_lookup()
1336 cell = nvmem_create_cell(cell_entry, con_id, 0); in nvmem_cell_get_from_lookup()
1337 if (IS_ERR(cell)) in nvmem_cell_get_from_lookup()
1338 __nvmem_device_put(nvmem); in nvmem_cell_get_from_lookup()
1345 return cell; in nvmem_cell_get_from_lookup()
1350 nvmem_find_cell_entry_by_node(struct nvmem_device *nvmem, struct device_node *np) in nvmem_find_cell_entry_by_node() argument
1352 struct nvmem_cell_entry *iter, *cell = NULL; in nvmem_find_cell_entry_by_node() local
1355 list_for_each_entry(iter, &nvmem->cells, node) { in nvmem_find_cell_entry_by_node()
1356 if (np == iter->np) { in nvmem_find_cell_entry_by_node()
1357 cell = iter; in nvmem_find_cell_entry_by_node()
1363 return cell; in nvmem_find_cell_entry_by_node()
1367 * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id
1369 * @np: Device tree node that uses the nvmem cell.
1370 * @id: nvmem cell name from nvmem-cell-names property, or NULL
1371 * for the cell at index 0 (the lone cell with no accompanying
1372 * nvmem-cell-names property).
1381 struct nvmem_device *nvmem; in of_nvmem_cell_get() local
1383 struct nvmem_cell *cell; in of_nvmem_cell_get() local
1389 /* if cell name exists, find index to the name */ in of_nvmem_cell_get()
1391 index = of_property_match_string(np, "nvmem-cell-names", id); in of_nvmem_cell_get()
1393 ret = of_parse_phandle_with_optional_args(np, "nvmem-cells", in of_nvmem_cell_get()
1394 "#nvmem-cell-cells", in of_nvmem_cell_get()
1397 return ERR_PTR(-ENOENT); in of_nvmem_cell_get()
1400 return ERR_PTR(-EINVAL); in of_nvmem_cell_get()
1409 return ERR_PTR(-EINVAL); in of_nvmem_cell_get()
1412 /* nvmem layouts produce cells within the nvmem-layout container */ in of_nvmem_cell_get()
1413 if (of_node_name_eq(nvmem_np, "nvmem-layout")) { in of_nvmem_cell_get()
1417 return ERR_PTR(-EINVAL); in of_nvmem_cell_get()
1421 nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); in of_nvmem_cell_get()
1423 if (IS_ERR(nvmem)) { in of_nvmem_cell_get()
1425 return ERR_CAST(nvmem); in of_nvmem_cell_get()
1428 cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np); in of_nvmem_cell_get()
1431 __nvmem_device_put(nvmem); in of_nvmem_cell_get()
1432 return ERR_PTR(-ENOENT); in of_nvmem_cell_get()
1435 cell = nvmem_create_cell(cell_entry, id, cell_index); in of_nvmem_cell_get()
1436 if (IS_ERR(cell)) in of_nvmem_cell_get()
1437 __nvmem_device_put(nvmem); in of_nvmem_cell_get()
1439 return cell; in of_nvmem_cell_get()
1445 * nvmem_cell_get() - Get nvmem cell of device form a given cell name
1447 * @dev: Device that requests the nvmem cell.
1448 * @id: nvmem cell name to get (this corresponds with the name from the
1449 * nvmem-cell-names property for DT systems and with the con_id from
1450 * the lookup entry for non-DT systems).
1458 struct nvmem_cell *cell; in nvmem_cell_get() local
1460 if (dev->of_node) { /* try dt first */ in nvmem_cell_get()
1461 cell = of_nvmem_cell_get(dev->of_node, id); in nvmem_cell_get()
1462 if (!IS_ERR(cell) || PTR_ERR(cell) == -EPROBE_DEFER) in nvmem_cell_get()
1463 return cell; in nvmem_cell_get()
1466 /* NULL cell id only allowed for device tree; invalid otherwise */ in nvmem_cell_get()
1468 return ERR_PTR(-EINVAL); in nvmem_cell_get()
1480 * devm_nvmem_cell_get() - Get nvmem cell of device form a given id
1482 * @dev: Device that requests the nvmem cell.
1483 * @id: nvmem cell name id to get.
1491 struct nvmem_cell **ptr, *cell; in devm_nvmem_cell_get() local
1495 return ERR_PTR(-ENOMEM); in devm_nvmem_cell_get()
1497 cell = nvmem_cell_get(dev, id); in devm_nvmem_cell_get()
1498 if (!IS_ERR(cell)) { in devm_nvmem_cell_get()
1499 *ptr = cell; in devm_nvmem_cell_get()
1505 return cell; in devm_nvmem_cell_get()
1520 * devm_nvmem_cell_put() - Release previously allocated nvmem cell
1523 * @dev: Device that requests the nvmem cell.
1524 * @cell: Previously allocated nvmem cell by devm_nvmem_cell_get().
1526 void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell) in devm_nvmem_cell_put() argument
1531 devm_nvmem_cell_match, cell); in devm_nvmem_cell_put()
1538 * nvmem_cell_put() - Release previously allocated nvmem cell.
1540 * @cell: Previously allocated nvmem cell by nvmem_cell_get().
1542 void nvmem_cell_put(struct nvmem_cell *cell) in nvmem_cell_put() argument
1544 struct nvmem_device *nvmem = cell->entry->nvmem; in nvmem_cell_put() local
1546 if (cell->id) in nvmem_cell_put()
1547 kfree_const(cell->id); in nvmem_cell_put()
1549 kfree(cell); in nvmem_cell_put()
1550 __nvmem_device_put(nvmem); in nvmem_cell_put()
1554 static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void *buf) in nvmem_shift_read_buffer_in_place() argument
1557 int i, extra, bit_offset = cell->bit_offset; in nvmem_shift_read_buffer_in_place()
1565 for (i = 1; i < cell->bytes; i++) { in nvmem_shift_read_buffer_in_place()
1567 *p |= *b << (BITS_PER_BYTE - bit_offset); in nvmem_shift_read_buffer_in_place()
1574 p += cell->bytes - 1; in nvmem_shift_read_buffer_in_place()
1578 extra = cell->bytes - DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE); in nvmem_shift_read_buffer_in_place()
1579 while (--extra >= 0) in nvmem_shift_read_buffer_in_place()
1580 *p-- = 0; in nvmem_shift_read_buffer_in_place()
1583 if (cell->nbits % BITS_PER_BYTE) in nvmem_shift_read_buffer_in_place()
1584 *p &= GENMASK((cell->nbits % BITS_PER_BYTE) - 1, 0); in nvmem_shift_read_buffer_in_place()
1587 static int __nvmem_cell_read(struct nvmem_device *nvmem, in __nvmem_cell_read() argument
1588 struct nvmem_cell_entry *cell, in __nvmem_cell_read() argument
1593 rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->raw_len); in __nvmem_cell_read()
1598 /* shift bits in-place */ in __nvmem_cell_read()
1599 if (cell->bit_offset || cell->nbits) in __nvmem_cell_read()
1600 nvmem_shift_read_buffer_in_place(cell, buf); in __nvmem_cell_read()
1602 if (cell->read_post_process) { in __nvmem_cell_read()
1603 rc = cell->read_post_process(cell->priv, id, index, in __nvmem_cell_read()
1604 cell->offset, buf, cell->raw_len); in __nvmem_cell_read()
1610 *len = cell->bytes; in __nvmem_cell_read()
1616 * nvmem_cell_read() - Read a given nvmem cell
1618 * @cell: nvmem cell to be read.
1619 * @len: pointer to length of cell which will be populated on successful read;
1625 void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) in nvmem_cell_read() argument
1627 struct nvmem_cell_entry *entry = cell->entry; in nvmem_cell_read()
1628 struct nvmem_device *nvmem = entry->nvmem; in nvmem_cell_read() local
1632 if (!nvmem) in nvmem_cell_read()
1633 return ERR_PTR(-EINVAL); in nvmem_cell_read()
1635 buf = kzalloc(max_t(size_t, entry->raw_len, entry->bytes), GFP_KERNEL); in nvmem_cell_read()
1637 return ERR_PTR(-ENOMEM); in nvmem_cell_read()
1639 rc = __nvmem_cell_read(nvmem, cell->entry, buf, len, cell->id, cell->index); in nvmem_cell_read()
1649 static void *nvmem_cell_prepare_write_buffer(struct nvmem_cell_entry *cell, in nvmem_cell_prepare_write_buffer() argument
1652 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_prepare_write_buffer() local
1653 int i, rc, nbits, bit_offset = cell->bit_offset; in nvmem_cell_prepare_write_buffer()
1656 nbits = cell->nbits; in nvmem_cell_prepare_write_buffer()
1657 buf = kzalloc(cell->bytes, GFP_KERNEL); in nvmem_cell_prepare_write_buffer()
1659 return ERR_PTR(-ENOMEM); in nvmem_cell_prepare_write_buffer()
1668 /* setup the first byte with lsb bits from nvmem */ in nvmem_cell_prepare_write_buffer()
1669 rc = nvmem_reg_read(nvmem, cell->offset, &v, 1); in nvmem_cell_prepare_write_buffer()
1672 *b++ |= GENMASK(bit_offset - 1, 0) & v; in nvmem_cell_prepare_write_buffer()
1675 for (i = 1; i < cell->bytes; i++) { in nvmem_cell_prepare_write_buffer()
1677 pbits = pbyte >> (BITS_PER_BYTE - 1 - bit_offset); in nvmem_cell_prepare_write_buffer()
1687 /* setup the last byte with msb bits from nvmem */ in nvmem_cell_prepare_write_buffer()
1688 rc = nvmem_reg_read(nvmem, in nvmem_cell_prepare_write_buffer()
1689 cell->offset + cell->bytes - 1, &v, 1); in nvmem_cell_prepare_write_buffer()
1702 static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, size_t len) in __nvmem_cell_entry_write() argument
1704 struct nvmem_device *nvmem = cell->nvmem; in __nvmem_cell_entry_write() local
1707 if (!nvmem || nvmem->read_only || in __nvmem_cell_entry_write()
1708 (cell->bit_offset == 0 && len != cell->bytes)) in __nvmem_cell_entry_write()
1709 return -EINVAL; in __nvmem_cell_entry_write()
1712 * Any cells which have a read_post_process hook are read-only because in __nvmem_cell_entry_write()
1716 if (cell->read_post_process) in __nvmem_cell_entry_write()
1717 return -EINVAL; in __nvmem_cell_entry_write()
1719 if (cell->bit_offset || cell->nbits) { in __nvmem_cell_entry_write()
1720 if (len != BITS_TO_BYTES(cell->nbits) && len != cell->bytes) in __nvmem_cell_entry_write()
1721 return -EINVAL; in __nvmem_cell_entry_write()
1722 buf = nvmem_cell_prepare_write_buffer(cell, buf, len); in __nvmem_cell_entry_write()
1727 rc = nvmem_reg_write(nvmem, cell->offset, buf, cell->bytes); in __nvmem_cell_entry_write()
1730 if (cell->bit_offset || cell->nbits) in __nvmem_cell_entry_write()
1740 * nvmem_cell_write() - Write to a given nvmem cell
1742 * @cell: nvmem cell to be written.
1744 * @len: length of buffer to be written to nvmem cell.
1748 int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len) in nvmem_cell_write() argument
1750 return __nvmem_cell_entry_write(cell->entry, buf, len); in nvmem_cell_write()
1758 struct nvmem_cell *cell; in nvmem_cell_read_common() local
1762 cell = nvmem_cell_get(dev, cell_id); in nvmem_cell_read_common()
1763 if (IS_ERR(cell)) in nvmem_cell_read_common()
1764 return PTR_ERR(cell); in nvmem_cell_read_common()
1766 buf = nvmem_cell_read(cell, &len); in nvmem_cell_read_common()
1768 nvmem_cell_put(cell); in nvmem_cell_read_common()
1773 nvmem_cell_put(cell); in nvmem_cell_read_common()
1774 return -EINVAL; in nvmem_cell_read_common()
1778 nvmem_cell_put(cell); in nvmem_cell_read_common()
1784 * nvmem_cell_read_u8() - Read a cell value as a u8
1786 * @dev: Device that requests the nvmem cell.
1787 * @cell_id: Name of nvmem cell to read.
1799 * nvmem_cell_read_u16() - Read a cell value as a u16
1801 * @dev: Device that requests the nvmem cell.
1802 * @cell_id: Name of nvmem cell to read.
1814 * nvmem_cell_read_u32() - Read a cell value as a u32
1816 * @dev: Device that requests the nvmem cell.
1817 * @cell_id: Name of nvmem cell to read.
1829 * nvmem_cell_read_u64() - Read a cell value as a u64
1831 * @dev: Device that requests the nvmem cell.
1832 * @cell_id: Name of nvmem cell to read.
1847 struct nvmem_cell *cell; in nvmem_cell_read_variable_common() local
1851 cell = nvmem_cell_get(dev, cell_id); in nvmem_cell_read_variable_common()
1852 if (IS_ERR(cell)) in nvmem_cell_read_variable_common()
1853 return cell; in nvmem_cell_read_variable_common()
1855 nbits = cell->entry->nbits; in nvmem_cell_read_variable_common()
1856 buf = nvmem_cell_read(cell, len); in nvmem_cell_read_variable_common()
1857 nvmem_cell_put(cell); in nvmem_cell_read_variable_common()
1870 return ERR_PTR(-ERANGE); in nvmem_cell_read_variable_common()
1877 * nvmem_cell_read_variable_le_u32() - Read up to 32-bits of data as a little endian number.
1879 * @dev: Device that requests the nvmem cell.
1880 * @cell_id: Name of nvmem cell to read.
1908 * nvmem_cell_read_variable_le_u64() - Read up to 64-bits of data as a little endian number.
1910 * @dev: Device that requests the nvmem cell.
1911 * @cell_id: Name of nvmem cell to read.
1939 * nvmem_device_cell_read() - Read a given nvmem device and cell
1941 * @nvmem: nvmem device to read from.
1942 * @info: nvmem cell info to be read.
1948 ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, in nvmem_device_cell_read() argument
1951 struct nvmem_cell_entry cell; in nvmem_device_cell_read() local
1955 if (!nvmem) in nvmem_device_cell_read()
1956 return -EINVAL; in nvmem_device_cell_read()
1958 rc = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, &cell); in nvmem_device_cell_read()
1962 rc = __nvmem_cell_read(nvmem, &cell, buf, &len, NULL, 0); in nvmem_device_cell_read()
1971 * nvmem_device_cell_write() - Write cell to a given nvmem device
1973 * @nvmem: nvmem device to be written to.
1974 * @info: nvmem cell info to be written.
1975 * @buf: buffer to be written to cell.
1979 int nvmem_device_cell_write(struct nvmem_device *nvmem, in nvmem_device_cell_write() argument
1982 struct nvmem_cell_entry cell; in nvmem_device_cell_write() local
1985 if (!nvmem) in nvmem_device_cell_write()
1986 return -EINVAL; in nvmem_device_cell_write()
1988 rc = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, &cell); in nvmem_device_cell_write()
1992 return __nvmem_cell_entry_write(&cell, buf, cell.bytes); in nvmem_device_cell_write()
1997 * nvmem_device_read() - Read from a given nvmem device
1999 * @nvmem: nvmem device to read from.
2000 * @offset: offset in nvmem device.
2007 int nvmem_device_read(struct nvmem_device *nvmem, in nvmem_device_read() argument
2013 if (!nvmem) in nvmem_device_read()
2014 return -EINVAL; in nvmem_device_read()
2016 rc = nvmem_reg_read(nvmem, offset, buf, bytes); in nvmem_device_read()
2026 * nvmem_device_write() - Write cell to a given nvmem device
2028 * @nvmem: nvmem device to be written to.
2029 * @offset: offset in nvmem device.
2035 int nvmem_device_write(struct nvmem_device *nvmem, in nvmem_device_write() argument
2041 if (!nvmem) in nvmem_device_write()
2042 return -EINVAL; in nvmem_device_write()
2044 rc = nvmem_reg_write(nvmem, offset, buf, bytes); in nvmem_device_write()
2055 * nvmem_add_cell_table() - register a table of cell info entries
2057 * @table: table of cell info entries
2062 list_add_tail(&table->node, &nvmem_cell_tables); in nvmem_add_cell_table()
2068 * nvmem_del_cell_table() - remove a previously registered cell info table
2070 * @table: table of cell info entries
2075 list_del(&table->node); in nvmem_del_cell_table()
2081 * nvmem_add_cell_lookups() - register a list of cell lookup entries
2083 * @entries: array of cell lookup entries
2084 * @nentries: number of cell lookup entries in the array
2098 * nvmem_del_cell_lookups() - remove a list of previously added cell lookup
2101 * @entries: array of cell lookup entries
2102 * @nentries: number of cell lookup entries in the array
2116 * nvmem_dev_name() - Get the name of a given nvmem device.
2118 * @nvmem: nvmem device.
2120 * Return: name of the nvmem device.
2122 const char *nvmem_dev_name(struct nvmem_device *nvmem) in nvmem_dev_name() argument
2124 return dev_name(&nvmem->dev); in nvmem_dev_name()
2129 * nvmem_dev_size() - Get the size of a given nvmem device.
2131 * @nvmem: nvmem device.
2133 * Return: size of the nvmem device.
2135 size_t nvmem_dev_size(struct nvmem_device *nvmem) in nvmem_dev_size() argument
2137 return nvmem->size; in nvmem_dev_size()
2155 MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com");
2156 MODULE_DESCRIPTION("nvmem Driver Core");