Lines Matching refs:nvmem

29 	struct nvmem_device	*nvmem;  member
45 static int nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, in nvmem_reg_read() argument
48 if (nvmem->reg_read) in nvmem_reg_read()
49 return nvmem->reg_read(nvmem->priv, offset, val, bytes); in nvmem_reg_read()
54 static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset, in nvmem_reg_write() argument
57 if (nvmem->reg_write) in nvmem_reg_write()
58 return nvmem->reg_write(nvmem->priv, offset, val, bytes); in nvmem_reg_write()
65 struct nvmem_device *nvmem = to_nvmem_device(dev); in nvmem_release() local
67 ida_simple_remove(&nvmem_ida, nvmem->id); in nvmem_release()
68 kfree(nvmem); in nvmem_release()
117 static void nvmem_device_remove_all_cells(const struct nvmem_device *nvmem) in nvmem_device_remove_all_cells() argument
121 list_for_each_entry_safe(cell, p, &nvmem->cells, node) in nvmem_device_remove_all_cells()
128 list_add_tail(&cell->node, &cell->nvmem->cells); in nvmem_cell_add()
133 static int nvmem_cell_info_to_nvmem_cell(struct nvmem_device *nvmem, in nvmem_cell_info_to_nvmem_cell() argument
137 cell->nvmem = nvmem; in nvmem_cell_info_to_nvmem_cell()
149 if (!IS_ALIGNED(cell->offset, nvmem->stride)) { in nvmem_cell_info_to_nvmem_cell()
150 dev_err(&nvmem->dev, in nvmem_cell_info_to_nvmem_cell()
152 cell->name, nvmem->stride); in nvmem_cell_info_to_nvmem_cell()
168 static int nvmem_add_cells(struct nvmem_device *nvmem, in nvmem_add_cells() argument
186 rval = nvmem_cell_info_to_nvmem_cell(nvmem, &info[i], cells[i]); in nvmem_add_cells()
234 static int nvmem_add_cells_from_table(struct nvmem_device *nvmem) in nvmem_add_cells_from_table() argument
243 if (strcmp(nvmem_dev_name(nvmem), table->nvmem_name) == 0) { in nvmem_add_cells_from_table()
253 rval = nvmem_cell_info_to_nvmem_cell(nvmem, in nvmem_add_cells_from_table()
272 nvmem_find_cell_by_name(struct nvmem_device *nvmem, const char *cell_id) in nvmem_find_cell_by_name() argument
277 list_for_each_entry(iter, &nvmem->cells, node) { in nvmem_find_cell_by_name()
288 static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) in nvmem_add_cells_from_of() argument
291 struct device *dev = &nvmem->dev; in nvmem_add_cells_from_of()
309 cell->nvmem = nvmem; in nvmem_add_cells_from_of()
326 if (!IS_ALIGNED(cell->offset, nvmem->stride)) { in nvmem_add_cells_from_of()
328 cell->name, nvmem->stride); in nvmem_add_cells_from_of()
353 struct nvmem_device *nvmem; in nvmem_register() local
359 nvmem = kzalloc(sizeof(*nvmem), GFP_KERNEL); in nvmem_register()
360 if (!nvmem) in nvmem_register()
365 kfree(nvmem); in nvmem_register()
369 kref_init(&nvmem->refcnt); in nvmem_register()
370 INIT_LIST_HEAD(&nvmem->cells); in nvmem_register()
372 nvmem->id = rval; in nvmem_register()
373 nvmem->owner = config->owner; in nvmem_register()
374 if (!nvmem->owner && config->dev->driver) in nvmem_register()
375 nvmem->owner = config->dev->driver->owner; in nvmem_register()
376 nvmem->stride = config->stride ?: 1; in nvmem_register()
377 nvmem->word_size = config->word_size ?: 1; in nvmem_register()
378 nvmem->size = config->size; in nvmem_register()
379 nvmem->dev.type = &nvmem_provider_type; in nvmem_register()
380 nvmem->dev.bus = &nvmem_bus_type; in nvmem_register()
381 nvmem->dev.parent = config->dev; in nvmem_register()
382 nvmem->priv = config->priv; in nvmem_register()
383 nvmem->type = config->type; in nvmem_register()
384 nvmem->reg_read = config->reg_read; in nvmem_register()
385 nvmem->reg_write = config->reg_write; in nvmem_register()
387 nvmem->dev.of_node = config->dev->of_node; in nvmem_register()
390 dev_set_name(&nvmem->dev, "%s", config->name); in nvmem_register()
392 dev_set_name(&nvmem->dev, "%s%d", in nvmem_register()
394 config->name ? config->id : nvmem->id); in nvmem_register()
397 nvmem->read_only = device_property_present(config->dev, "read-only") || in nvmem_register()
398 config->read_only || !nvmem->reg_write; in nvmem_register()
400 nvmem->dev.groups = nvmem_sysfs_get_groups(nvmem, config); in nvmem_register()
402 device_initialize(&nvmem->dev); in nvmem_register()
404 dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); in nvmem_register()
406 rval = device_add(&nvmem->dev); in nvmem_register()
411 rval = nvmem_sysfs_setup_compat(nvmem, config); in nvmem_register()
417 rval = nvmem_add_cells(nvmem, config->cells, config->ncells); in nvmem_register()
422 rval = nvmem_add_cells_from_table(nvmem); in nvmem_register()
426 rval = nvmem_add_cells_from_of(nvmem); in nvmem_register()
430 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); in nvmem_register()
432 return nvmem; in nvmem_register()
435 nvmem_device_remove_all_cells(nvmem); in nvmem_register()
438 nvmem_sysfs_remove_compat(nvmem, config); in nvmem_register()
440 device_del(&nvmem->dev); in nvmem_register()
442 put_device(&nvmem->dev); in nvmem_register()
450 struct nvmem_device *nvmem; in nvmem_device_release() local
452 nvmem = container_of(kref, struct nvmem_device, refcnt); in nvmem_device_release()
454 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_REMOVE, nvmem); in nvmem_device_release()
456 if (nvmem->flags & FLAG_COMPAT) in nvmem_device_release()
457 device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); in nvmem_device_release()
459 nvmem_device_remove_all_cells(nvmem); in nvmem_device_release()
460 device_del(&nvmem->dev); in nvmem_device_release()
461 put_device(&nvmem->dev); in nvmem_device_release()
469 void nvmem_unregister(struct nvmem_device *nvmem) in nvmem_unregister() argument
471 kref_put(&nvmem->refcnt, nvmem_device_release); in nvmem_unregister()
494 struct nvmem_device **ptr, *nvmem; in devm_nvmem_register() local
500 nvmem = nvmem_register(config); in devm_nvmem_register()
502 if (!IS_ERR(nvmem)) { in devm_nvmem_register()
503 *ptr = nvmem; in devm_nvmem_register()
509 return nvmem; in devm_nvmem_register()
529 int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem) in devm_nvmem_unregister() argument
531 return devres_release(dev, devm_nvmem_release, devm_nvmem_match, nvmem); in devm_nvmem_unregister()
538 struct nvmem_device *nvmem = NULL; in __nvmem_device_get() local
541 nvmem = np ? of_nvmem_find(np) : nvmem_find(nvmem_name); in __nvmem_device_get()
543 if (!nvmem) in __nvmem_device_get()
546 if (!try_module_get(nvmem->owner)) { in __nvmem_device_get()
547 dev_err(&nvmem->dev, in __nvmem_device_get()
549 nvmem_dev_name(nvmem)); in __nvmem_device_get()
551 put_device(&nvmem->dev); in __nvmem_device_get()
555 kref_get(&nvmem->refcnt); in __nvmem_device_get()
557 return nvmem; in __nvmem_device_get()
560 static void __nvmem_device_put(struct nvmem_device *nvmem) in __nvmem_device_put() argument
562 put_device(&nvmem->dev); in __nvmem_device_put()
563 module_put(nvmem->owner); in __nvmem_device_put()
564 kref_put(&nvmem->refcnt, nvmem_device_release); in __nvmem_device_put()
607 struct nvmem_device *nvmem; in nvmem_device_get() local
609 nvmem = of_nvmem_device_get(dev->of_node, dev_name); in nvmem_device_get()
611 if (!IS_ERR(nvmem) || PTR_ERR(nvmem) == -EPROBE_DEFER) in nvmem_device_get()
612 return nvmem; in nvmem_device_get()
622 struct nvmem_device **nvmem = res; in devm_nvmem_device_match() local
624 if (WARN_ON(!nvmem || !*nvmem)) in devm_nvmem_device_match()
627 return *nvmem == data; in devm_nvmem_device_match()
642 void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem) in devm_nvmem_device_put() argument
647 devm_nvmem_device_match, nvmem); in devm_nvmem_device_put()
658 void nvmem_device_put(struct nvmem_device *nvmem) in nvmem_device_put() argument
660 __nvmem_device_put(nvmem); in nvmem_device_put()
676 struct nvmem_device **ptr, *nvmem; in devm_nvmem_device_get() local
682 nvmem = nvmem_device_get(dev, id); in devm_nvmem_device_get()
683 if (!IS_ERR(nvmem)) { in devm_nvmem_device_get()
684 *ptr = nvmem; in devm_nvmem_device_get()
690 return nvmem; in devm_nvmem_device_get()
699 struct nvmem_device *nvmem; in nvmem_cell_get_from_lookup() local
713 nvmem = __nvmem_device_get(NULL, lookup->nvmem_name); in nvmem_cell_get_from_lookup()
714 if (IS_ERR(nvmem)) { in nvmem_cell_get_from_lookup()
716 cell = ERR_CAST(nvmem); in nvmem_cell_get_from_lookup()
720 cell = nvmem_find_cell_by_name(nvmem, in nvmem_cell_get_from_lookup()
723 __nvmem_device_put(nvmem); in nvmem_cell_get_from_lookup()
736 nvmem_find_cell_by_node(struct nvmem_device *nvmem, struct device_node *np) in nvmem_find_cell_by_node() argument
741 list_for_each_entry(iter, &nvmem->cells, node) { in nvmem_find_cell_by_node()
767 struct nvmem_device *nvmem; in of_nvmem_cell_get() local
783 nvmem = __nvmem_device_get(nvmem_np, NULL); in of_nvmem_cell_get()
785 if (IS_ERR(nvmem)) in of_nvmem_cell_get()
786 return ERR_CAST(nvmem); in of_nvmem_cell_get()
788 cell = nvmem_find_cell_by_node(nvmem, cell_np); in of_nvmem_cell_get()
790 __nvmem_device_put(nvmem); in of_nvmem_cell_get()
899 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_put() local
901 __nvmem_device_put(nvmem); in nvmem_cell_put()
937 static int __nvmem_cell_read(struct nvmem_device *nvmem, in __nvmem_cell_read() argument
943 rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->bytes); in __nvmem_cell_read()
970 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_read() local
974 if (!nvmem) in nvmem_cell_read()
981 rc = __nvmem_cell_read(nvmem, cell, buf, len); in nvmem_cell_read()
994 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_prepare_write_buffer() local
1011 rc = nvmem_reg_read(nvmem, cell->offset, &v, 1); in nvmem_cell_prepare_write_buffer()
1030 rc = nvmem_reg_read(nvmem, in nvmem_cell_prepare_write_buffer()
1055 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_write() local
1058 if (!nvmem || nvmem->read_only || in nvmem_cell_write()
1068 rc = nvmem_reg_write(nvmem, cell->offset, buf, cell->bytes); in nvmem_cell_write()
1165 ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, in nvmem_device_cell_read() argument
1172 if (!nvmem) in nvmem_device_cell_read()
1175 rc = nvmem_cell_info_to_nvmem_cell(nvmem, info, &cell); in nvmem_device_cell_read()
1179 rc = __nvmem_cell_read(nvmem, &cell, buf, &len); in nvmem_device_cell_read()
1196 int nvmem_device_cell_write(struct nvmem_device *nvmem, in nvmem_device_cell_write() argument
1202 if (!nvmem) in nvmem_device_cell_write()
1205 rc = nvmem_cell_info_to_nvmem_cell(nvmem, info, &cell); in nvmem_device_cell_write()
1224 int nvmem_device_read(struct nvmem_device *nvmem, in nvmem_device_read() argument
1230 if (!nvmem) in nvmem_device_read()
1233 rc = nvmem_reg_read(nvmem, offset, buf, bytes); in nvmem_device_read()
1252 int nvmem_device_write(struct nvmem_device *nvmem, in nvmem_device_write() argument
1258 if (!nvmem) in nvmem_device_write()
1261 rc = nvmem_reg_write(nvmem, offset, buf, bytes); in nvmem_device_write()
1339 const char *nvmem_dev_name(struct nvmem_device *nvmem) in nvmem_dev_name() argument
1341 return dev_name(&nvmem->dev); in nvmem_dev_name()