Lines Matching refs:nvmem

49 	struct nvmem_device	*nvmem;  member
66 struct nvmem_device *nvmem = to_nvmem_device(dev); in bin_attr_nvmem_read() local
70 if (pos >= nvmem->size) in bin_attr_nvmem_read()
73 if (pos + count > nvmem->size) in bin_attr_nvmem_read()
74 count = nvmem->size - pos; in bin_attr_nvmem_read()
76 count = round_down(count, nvmem->word_size); in bin_attr_nvmem_read()
78 rc = regmap_raw_read(nvmem->regmap, pos, buf, count); in bin_attr_nvmem_read()
91 struct nvmem_device *nvmem = to_nvmem_device(dev); in bin_attr_nvmem_write() local
95 if (pos >= nvmem->size) in bin_attr_nvmem_write()
98 if (pos + count > nvmem->size) in bin_attr_nvmem_write()
99 count = nvmem->size - pos; in bin_attr_nvmem_write()
101 count = round_down(count, nvmem->word_size); in bin_attr_nvmem_write()
103 rc = regmap_raw_write(nvmem->regmap, pos, buf, count); in bin_attr_nvmem_write()
160 struct nvmem_device *nvmem = to_nvmem_device(dev); in nvmem_release() local
162 ida_simple_remove(&nvmem_ida, nvmem->id); in nvmem_release()
163 kfree(nvmem); in nvmem_release()
213 static void nvmem_device_remove_all_cells(const struct nvmem_device *nvmem) in nvmem_device_remove_all_cells() argument
220 if (cell->nvmem == nvmem) in nvmem_device_remove_all_cells()
232 static int nvmem_cell_info_to_nvmem_cell(struct nvmem_device *nvmem, in nvmem_cell_info_to_nvmem_cell() argument
236 cell->nvmem = nvmem; in nvmem_cell_info_to_nvmem_cell()
248 if (!IS_ALIGNED(cell->offset, nvmem->stride)) { in nvmem_cell_info_to_nvmem_cell()
249 dev_err(&nvmem->dev, in nvmem_cell_info_to_nvmem_cell()
251 cell->name, nvmem->stride); in nvmem_cell_info_to_nvmem_cell()
258 static int nvmem_add_cells(struct nvmem_device *nvmem, in nvmem_add_cells() argument
276 rval = nvmem_cell_info_to_nvmem_cell(nvmem, &info[i], cells[i]); in nvmem_add_cells()
285 nvmem->ncells = cfg->ncells; in nvmem_add_cells()
309 struct nvmem_device *nvmem; in nvmem_register() local
323 nvmem = kzalloc(sizeof(*nvmem), GFP_KERNEL); in nvmem_register()
324 if (!nvmem) in nvmem_register()
329 kfree(nvmem); in nvmem_register()
333 nvmem->id = rval; in nvmem_register()
334 nvmem->regmap = rm; in nvmem_register()
335 nvmem->owner = config->owner; in nvmem_register()
336 nvmem->stride = regmap_get_reg_stride(rm); in nvmem_register()
337 nvmem->word_size = regmap_get_val_bytes(rm); in nvmem_register()
338 nvmem->size = regmap_get_max_register(rm) + nvmem->stride; in nvmem_register()
339 nvmem->dev.type = &nvmem_provider_type; in nvmem_register()
340 nvmem->dev.bus = &nvmem_bus_type; in nvmem_register()
341 nvmem->dev.parent = config->dev; in nvmem_register()
343 nvmem->dev.of_node = np; in nvmem_register()
344 dev_set_name(&nvmem->dev, "%s%d", in nvmem_register()
347 nvmem->read_only = of_property_read_bool(np, "read-only") | in nvmem_register()
350 nvmem->dev.groups = nvmem->read_only ? nvmem_ro_dev_groups : in nvmem_register()
353 device_initialize(&nvmem->dev); in nvmem_register()
355 dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); in nvmem_register()
357 rval = device_add(&nvmem->dev); in nvmem_register()
359 ida_simple_remove(&nvmem_ida, nvmem->id); in nvmem_register()
360 kfree(nvmem); in nvmem_register()
365 nvmem_add_cells(nvmem, config); in nvmem_register()
367 return nvmem; in nvmem_register()
378 int nvmem_unregister(struct nvmem_device *nvmem) in nvmem_unregister() argument
381 if (nvmem->users) { in nvmem_unregister()
387 nvmem_device_remove_all_cells(nvmem); in nvmem_unregister()
388 device_del(&nvmem->dev); in nvmem_unregister()
398 struct nvmem_device *nvmem = NULL; in __nvmem_device_get() local
403 nvmem = of_nvmem_find(np); in __nvmem_device_get()
404 if (!nvmem) { in __nvmem_device_get()
412 nvmem = cell->nvmem; in __nvmem_device_get()
416 if (!nvmem) { in __nvmem_device_get()
422 nvmem->users++; in __nvmem_device_get()
425 if (!try_module_get(nvmem->owner)) { in __nvmem_device_get()
426 dev_err(&nvmem->dev, in __nvmem_device_get()
428 nvmem->name); in __nvmem_device_get()
431 nvmem->users--; in __nvmem_device_get()
437 return nvmem; in __nvmem_device_get()
440 static void __nvmem_device_put(struct nvmem_device *nvmem) in __nvmem_device_put() argument
442 module_put(nvmem->owner); in __nvmem_device_put()
444 nvmem->users--; in __nvmem_device_put()
504 struct nvmem_device *nvmem; in nvmem_device_get() local
506 nvmem = of_nvmem_device_get(dev->of_node, dev_name); in nvmem_device_get()
508 if (!IS_ERR(nvmem) || PTR_ERR(nvmem) == -EPROBE_DEFER) in nvmem_device_get()
509 return nvmem; in nvmem_device_get()
519 struct nvmem_device **nvmem = res; in devm_nvmem_device_match() local
521 if (WARN_ON(!nvmem || !*nvmem)) in devm_nvmem_device_match()
524 return *nvmem == data; in devm_nvmem_device_match()
538 void devm_nvmem_device_put(struct device *dev, struct nvmem_device *nvmem) in devm_nvmem_device_put() argument
543 devm_nvmem_device_match, nvmem); in devm_nvmem_device_put()
554 void nvmem_device_put(struct nvmem_device *nvmem) in nvmem_device_put() argument
556 __nvmem_device_put(nvmem); in nvmem_device_put()
572 struct nvmem_device **ptr, *nvmem; in devm_nvmem_device_get() local
578 nvmem = nvmem_device_get(dev, id); in devm_nvmem_device_get()
579 if (!IS_ERR(nvmem)) { in devm_nvmem_device_get()
580 *ptr = nvmem; in devm_nvmem_device_get()
586 return nvmem; in devm_nvmem_device_get()
593 struct nvmem_device *nvmem; in nvmem_cell_get_from_list() local
595 nvmem = __nvmem_device_get(NULL, &cell, cell_id); in nvmem_cell_get_from_list()
596 if (IS_ERR(nvmem)) in nvmem_cell_get_from_list()
597 return ERR_CAST(nvmem); in nvmem_cell_get_from_list()
618 struct nvmem_device *nvmem; in of_nvmem_cell_get() local
632 nvmem = __nvmem_device_get(nvmem_np, NULL, NULL); in of_nvmem_cell_get()
633 if (IS_ERR(nvmem)) in of_nvmem_cell_get()
634 return ERR_CAST(nvmem); in of_nvmem_cell_get()
638 dev_err(&nvmem->dev, "nvmem: invalid reg on %s\n", in of_nvmem_cell_get()
650 cell->nvmem = nvmem; in of_nvmem_cell_get()
665 if (!IS_ALIGNED(cell->offset, nvmem->stride)) { in of_nvmem_cell_get()
666 dev_err(&nvmem->dev, in of_nvmem_cell_get()
668 cell->name, nvmem->stride); in of_nvmem_cell_get()
681 __nvmem_device_put(nvmem); in of_nvmem_cell_get()
781 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_put() local
783 __nvmem_device_put(nvmem); in nvmem_cell_put()
816 static int __nvmem_cell_read(struct nvmem_device *nvmem, in __nvmem_cell_read() argument
822 rc = regmap_raw_read(nvmem->regmap, cell->offset, buf, cell->bytes); in __nvmem_cell_read()
847 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_read() local
851 if (!nvmem || !nvmem->regmap) in nvmem_cell_read()
858 rc = __nvmem_cell_read(nvmem, cell, buf, len); in nvmem_cell_read()
871 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_prepare_write_buffer() local
888 rc = regmap_raw_read(nvmem->regmap, cell->offset, &v, 1); in nvmem_cell_prepare_write_buffer()
905 rc = regmap_raw_read(nvmem->regmap, in nvmem_cell_prepare_write_buffer()
925 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_write() local
928 if (!nvmem || !nvmem->regmap || nvmem->read_only || in nvmem_cell_write()
938 rc = regmap_raw_write(nvmem->regmap, cell->offset, buf, cell->bytes); in nvmem_cell_write()
961 ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, in nvmem_device_cell_read() argument
968 if (!nvmem || !nvmem->regmap) in nvmem_device_cell_read()
971 rc = nvmem_cell_info_to_nvmem_cell(nvmem, info, &cell); in nvmem_device_cell_read()
975 rc = __nvmem_cell_read(nvmem, &cell, buf, &len); in nvmem_device_cell_read()
992 int nvmem_device_cell_write(struct nvmem_device *nvmem, in nvmem_device_cell_write() argument
998 if (!nvmem || !nvmem->regmap) in nvmem_device_cell_write()
1001 rc = nvmem_cell_info_to_nvmem_cell(nvmem, info, &cell); in nvmem_device_cell_write()
1020 int nvmem_device_read(struct nvmem_device *nvmem, in nvmem_device_read() argument
1026 if (!nvmem || !nvmem->regmap) in nvmem_device_read()
1029 rc = regmap_raw_read(nvmem->regmap, offset, buf, bytes); in nvmem_device_read()
1048 int nvmem_device_write(struct nvmem_device *nvmem, in nvmem_device_write() argument
1054 if (!nvmem || !nvmem->regmap) in nvmem_device_write()
1057 rc = regmap_raw_write(nvmem->regmap, offset, buf, bytes); in nvmem_device_write()