Lines Matching refs:cell
106 static void nvmem_cell_drop(struct nvmem_cell *cell) in nvmem_cell_drop() argument
108 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_REMOVE, cell); in nvmem_cell_drop()
110 list_del(&cell->node); in nvmem_cell_drop()
112 of_node_put(cell->np); in nvmem_cell_drop()
113 kfree(cell->name); in nvmem_cell_drop()
114 kfree(cell); in nvmem_cell_drop()
119 struct nvmem_cell *cell, *p; in nvmem_device_remove_all_cells() local
121 list_for_each_entry_safe(cell, p, &nvmem->cells, node) in nvmem_device_remove_all_cells()
122 nvmem_cell_drop(cell); in nvmem_device_remove_all_cells()
125 static void nvmem_cell_add(struct nvmem_cell *cell) in nvmem_cell_add() argument
128 list_add_tail(&cell->node, &cell->nvmem->cells); in nvmem_cell_add()
130 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_ADD, cell); in nvmem_cell_add()
135 struct nvmem_cell *cell) in nvmem_cell_info_to_nvmem_cell() argument
137 cell->nvmem = nvmem; in nvmem_cell_info_to_nvmem_cell()
138 cell->offset = info->offset; in nvmem_cell_info_to_nvmem_cell()
139 cell->bytes = info->bytes; in nvmem_cell_info_to_nvmem_cell()
140 cell->name = info->name; in nvmem_cell_info_to_nvmem_cell()
142 cell->bit_offset = info->bit_offset; in nvmem_cell_info_to_nvmem_cell()
143 cell->nbits = info->nbits; in nvmem_cell_info_to_nvmem_cell()
145 if (cell->nbits) in nvmem_cell_info_to_nvmem_cell()
146 cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset, in nvmem_cell_info_to_nvmem_cell()
149 if (!IS_ALIGNED(cell->offset, nvmem->stride)) { in nvmem_cell_info_to_nvmem_cell()
152 cell->name, nvmem->stride); in nvmem_cell_info_to_nvmem_cell()
238 struct nvmem_cell *cell; in nvmem_add_cells_from_table() local
247 cell = kzalloc(sizeof(*cell), GFP_KERNEL); in nvmem_add_cells_from_table()
248 if (!cell) { in nvmem_add_cells_from_table()
255 cell); in nvmem_add_cells_from_table()
257 kfree(cell); in nvmem_add_cells_from_table()
261 nvmem_cell_add(cell); in nvmem_add_cells_from_table()
274 struct nvmem_cell *iter, *cell = NULL; in nvmem_find_cell_by_name() local
279 cell = iter; in nvmem_find_cell_by_name()
285 return cell; in nvmem_find_cell_by_name()
292 struct nvmem_cell *cell; in nvmem_add_cells_from_of() local
305 cell = kzalloc(sizeof(*cell), GFP_KERNEL); in nvmem_add_cells_from_of()
306 if (!cell) in nvmem_add_cells_from_of()
309 cell->nvmem = nvmem; in nvmem_add_cells_from_of()
310 cell->np = of_node_get(child); in nvmem_add_cells_from_of()
311 cell->offset = be32_to_cpup(addr++); in nvmem_add_cells_from_of()
312 cell->bytes = be32_to_cpup(addr); in nvmem_add_cells_from_of()
313 cell->name = kasprintf(GFP_KERNEL, "%pOFn", child); in nvmem_add_cells_from_of()
317 cell->bit_offset = be32_to_cpup(addr++); in nvmem_add_cells_from_of()
318 cell->nbits = be32_to_cpup(addr); in nvmem_add_cells_from_of()
321 if (cell->nbits) in nvmem_add_cells_from_of()
322 cell->bytes = DIV_ROUND_UP( in nvmem_add_cells_from_of()
323 cell->nbits + cell->bit_offset, 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()
330 kfree(cell->name); in nvmem_add_cells_from_of()
331 kfree(cell); in nvmem_add_cells_from_of()
335 nvmem_cell_add(cell); in nvmem_add_cells_from_of()
697 struct nvmem_cell *cell = ERR_PTR(-ENOENT); in nvmem_cell_get_from_lookup() local
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()
722 if (!cell) { in nvmem_cell_get_from_lookup()
724 cell = ERR_PTR(-ENOENT); in nvmem_cell_get_from_lookup()
731 return cell; in nvmem_cell_get_from_lookup()
738 struct nvmem_cell *iter, *cell = NULL; in nvmem_find_cell_by_node() local
743 cell = iter; in nvmem_find_cell_by_node()
749 return cell; in nvmem_find_cell_by_node()
768 struct nvmem_cell *cell; in of_nvmem_cell_get() local
788 cell = nvmem_find_cell_by_node(nvmem, cell_np); in of_nvmem_cell_get()
789 if (!cell) { in of_nvmem_cell_get()
794 return cell; in of_nvmem_cell_get()
813 struct nvmem_cell *cell; in nvmem_cell_get() local
816 cell = of_nvmem_cell_get(dev->of_node, id); in nvmem_cell_get()
817 if (!IS_ERR(cell) || PTR_ERR(cell) == -EPROBE_DEFER) in nvmem_cell_get()
818 return cell; in nvmem_cell_get()
846 struct nvmem_cell **ptr, *cell; in devm_nvmem_cell_get() local
852 cell = nvmem_cell_get(dev, id); in devm_nvmem_cell_get()
853 if (!IS_ERR(cell)) { in devm_nvmem_cell_get()
854 *ptr = cell; in devm_nvmem_cell_get()
860 return cell; in devm_nvmem_cell_get()
881 void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell) in devm_nvmem_cell_put() argument
886 devm_nvmem_cell_match, cell); in devm_nvmem_cell_put()
897 void nvmem_cell_put(struct nvmem_cell *cell) in nvmem_cell_put() argument
899 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_put()
905 static void nvmem_shift_read_buffer_in_place(struct nvmem_cell *cell, void *buf) in nvmem_shift_read_buffer_in_place() argument
908 int i, extra, bit_offset = cell->bit_offset; in nvmem_shift_read_buffer_in_place()
916 for (i = 1; i < cell->bytes; i++) { in nvmem_shift_read_buffer_in_place()
925 p += cell->bytes - 1; in nvmem_shift_read_buffer_in_place()
929 extra = cell->bytes - DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE); in nvmem_shift_read_buffer_in_place()
934 *p &= GENMASK((cell->nbits%BITS_PER_BYTE) - 1, 0); in nvmem_shift_read_buffer_in_place()
938 struct nvmem_cell *cell, in __nvmem_cell_read() argument
943 rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->bytes); in __nvmem_cell_read()
949 if (cell->bit_offset || cell->nbits) in __nvmem_cell_read()
950 nvmem_shift_read_buffer_in_place(cell, buf); in __nvmem_cell_read()
953 *len = cell->bytes; in __nvmem_cell_read()
968 void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) in nvmem_cell_read() argument
970 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_read()
977 buf = kzalloc(cell->bytes, GFP_KERNEL); in nvmem_cell_read()
981 rc = __nvmem_cell_read(nvmem, cell, buf, len); in nvmem_cell_read()
991 static void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell, in nvmem_cell_prepare_write_buffer() argument
994 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_prepare_write_buffer()
995 int i, rc, nbits, bit_offset = cell->bit_offset; in nvmem_cell_prepare_write_buffer()
998 nbits = cell->nbits; in nvmem_cell_prepare_write_buffer()
999 buf = kzalloc(cell->bytes, GFP_KERNEL); in nvmem_cell_prepare_write_buffer()
1011 rc = nvmem_reg_read(nvmem, cell->offset, &v, 1); in nvmem_cell_prepare_write_buffer()
1017 for (i = 1; i < cell->bytes; i++) { in nvmem_cell_prepare_write_buffer()
1031 cell->offset + cell->bytes - 1, &v, 1); in nvmem_cell_prepare_write_buffer()
1053 int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len) in nvmem_cell_write() argument
1055 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_write()
1059 (cell->bit_offset == 0 && len != cell->bytes)) in nvmem_cell_write()
1062 if (cell->bit_offset || cell->nbits) { in nvmem_cell_write()
1063 buf = nvmem_cell_prepare_write_buffer(cell, buf, len); in nvmem_cell_write()
1068 rc = nvmem_reg_write(nvmem, cell->offset, buf, cell->bytes); in nvmem_cell_write()
1071 if (cell->bit_offset || cell->nbits) in nvmem_cell_write()
1092 struct nvmem_cell *cell; in nvmem_cell_read_u16() local
1096 cell = nvmem_cell_get(dev, cell_id); in nvmem_cell_read_u16()
1097 if (IS_ERR(cell)) in nvmem_cell_read_u16()
1098 return PTR_ERR(cell); in nvmem_cell_read_u16()
1100 buf = nvmem_cell_read(cell, &len); in nvmem_cell_read_u16()
1102 nvmem_cell_put(cell); in nvmem_cell_read_u16()
1107 nvmem_cell_put(cell); in nvmem_cell_read_u16()
1112 nvmem_cell_put(cell); in nvmem_cell_read_u16()
1129 struct nvmem_cell *cell; in nvmem_cell_read_u32() local
1133 cell = nvmem_cell_get(dev, cell_id); in nvmem_cell_read_u32()
1134 if (IS_ERR(cell)) in nvmem_cell_read_u32()
1135 return PTR_ERR(cell); in nvmem_cell_read_u32()
1137 buf = nvmem_cell_read(cell, &len); in nvmem_cell_read_u32()
1139 nvmem_cell_put(cell); in nvmem_cell_read_u32()
1144 nvmem_cell_put(cell); in nvmem_cell_read_u32()
1150 nvmem_cell_put(cell); in nvmem_cell_read_u32()
1168 struct nvmem_cell cell; in nvmem_device_cell_read() local
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()
1199 struct nvmem_cell cell; in nvmem_device_cell_write() local
1205 rc = nvmem_cell_info_to_nvmem_cell(nvmem, info, &cell); in nvmem_device_cell_write()
1209 return nvmem_cell_write(&cell, buf, cell.bytes); in nvmem_device_cell_write()