Lines Matching full:cell
425 static void nvmem_cell_drop(struct nvmem_cell *cell) in nvmem_cell_drop() argument
427 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_REMOVE, cell); in nvmem_cell_drop()
429 list_del(&cell->node); in nvmem_cell_drop()
431 of_node_put(cell->np); in nvmem_cell_drop()
432 kfree_const(cell->name); in nvmem_cell_drop()
433 kfree(cell); in nvmem_cell_drop()
438 struct nvmem_cell *cell, *p; in nvmem_device_remove_all_cells() local
440 list_for_each_entry_safe(cell, p, &nvmem->cells, node) in nvmem_device_remove_all_cells()
441 nvmem_cell_drop(cell); in nvmem_device_remove_all_cells()
444 static void nvmem_cell_add(struct nvmem_cell *cell) in nvmem_cell_add() argument
447 list_add_tail(&cell->node, &cell->nvmem->cells); in nvmem_cell_add()
449 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_ADD, cell); in nvmem_cell_add()
454 struct nvmem_cell *cell) in nvmem_cell_info_to_nvmem_cell_nodup() argument
456 cell->nvmem = nvmem; in nvmem_cell_info_to_nvmem_cell_nodup()
457 cell->offset = info->offset; in nvmem_cell_info_to_nvmem_cell_nodup()
458 cell->bytes = info->bytes; in nvmem_cell_info_to_nvmem_cell_nodup()
459 cell->name = info->name; in nvmem_cell_info_to_nvmem_cell_nodup()
461 cell->bit_offset = info->bit_offset; in nvmem_cell_info_to_nvmem_cell_nodup()
462 cell->nbits = info->nbits; in nvmem_cell_info_to_nvmem_cell_nodup()
464 if (cell->nbits) in nvmem_cell_info_to_nvmem_cell_nodup()
465 cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset, in nvmem_cell_info_to_nvmem_cell_nodup()
468 if (!IS_ALIGNED(cell->offset, nvmem->stride)) { in nvmem_cell_info_to_nvmem_cell_nodup()
470 "cell %s unaligned to nvmem stride %d\n", in nvmem_cell_info_to_nvmem_cell_nodup()
471 cell->name ?: "<unknown>", nvmem->stride); in nvmem_cell_info_to_nvmem_cell_nodup()
480 struct nvmem_cell *cell) in nvmem_cell_info_to_nvmem_cell() argument
484 err = nvmem_cell_info_to_nvmem_cell_nodup(nvmem, info, cell); in nvmem_cell_info_to_nvmem_cell()
488 cell->name = kstrdup_const(info->name, GFP_KERNEL); in nvmem_cell_info_to_nvmem_cell()
489 if (!cell->name) in nvmem_cell_info_to_nvmem_cell()
496 * nvmem_add_cells() - Add cell information to an nvmem device
499 * @info: nvmem cell info to add to the device
574 struct nvmem_cell *cell; in nvmem_add_cells_from_table() local
583 cell = kzalloc(sizeof(*cell), GFP_KERNEL); in nvmem_add_cells_from_table()
584 if (!cell) { in nvmem_add_cells_from_table()
591 cell); in nvmem_add_cells_from_table()
593 kfree(cell); in nvmem_add_cells_from_table()
597 nvmem_cell_add(cell); in nvmem_add_cells_from_table()
610 struct nvmem_cell *iter, *cell = NULL; in nvmem_find_cell_by_name() local
615 cell = iter; in nvmem_find_cell_by_name()
621 return cell; in nvmem_find_cell_by_name()
681 struct nvmem_cell *cell; in nvmem_add_cells_from_of() local
697 cell = kzalloc(sizeof(*cell), GFP_KERNEL); in nvmem_add_cells_from_of()
698 if (!cell) { in nvmem_add_cells_from_of()
703 cell->nvmem = nvmem; in nvmem_add_cells_from_of()
704 cell->offset = be32_to_cpup(addr++); in nvmem_add_cells_from_of()
705 cell->bytes = be32_to_cpup(addr); in nvmem_add_cells_from_of()
706 cell->name = kasprintf(GFP_KERNEL, "%pOFn", child); in nvmem_add_cells_from_of()
710 cell->bit_offset = be32_to_cpup(addr++); in nvmem_add_cells_from_of()
711 cell->nbits = be32_to_cpup(addr); in nvmem_add_cells_from_of()
714 if (cell->nbits) in nvmem_add_cells_from_of()
715 cell->bytes = DIV_ROUND_UP( in nvmem_add_cells_from_of()
716 cell->nbits + cell->bit_offset, in nvmem_add_cells_from_of()
719 if (!IS_ALIGNED(cell->offset, nvmem->stride)) { in nvmem_add_cells_from_of()
720 dev_err(dev, "cell %s unaligned to nvmem stride %d\n", in nvmem_add_cells_from_of()
721 cell->name, nvmem->stride); in nvmem_add_cells_from_of()
723 kfree_const(cell->name); in nvmem_add_cells_from_of()
724 kfree(cell); in nvmem_add_cells_from_of()
729 cell->np = of_node_get(child); in nvmem_add_cells_from_of()
730 nvmem_cell_add(cell); in nvmem_add_cells_from_of()
980 "could not increase module refcount for cell %s\n", in __nvmem_device_get()
1116 * devm_nvmem_device_get() - Get nvmem cell of device form a given id
1148 struct nvmem_cell *cell = ERR_PTR(-ENOENT); in nvmem_cell_get_from_lookup() local
1168 cell = ERR_CAST(nvmem); in nvmem_cell_get_from_lookup()
1172 cell = nvmem_find_cell_by_name(nvmem, in nvmem_cell_get_from_lookup()
1174 if (!cell) { in nvmem_cell_get_from_lookup()
1176 cell = ERR_PTR(-ENOENT); in nvmem_cell_get_from_lookup()
1183 return cell; in nvmem_cell_get_from_lookup()
1190 struct nvmem_cell *iter, *cell = NULL; in nvmem_find_cell_by_node() local
1195 cell = iter; in nvmem_find_cell_by_node()
1201 return cell; in nvmem_find_cell_by_node()
1205 * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id
1207 * @np: Device tree node that uses the nvmem cell.
1208 * @id: nvmem cell name from nvmem-cell-names property, or NULL
1209 * for the cell at index 0 (the lone cell with no accompanying
1210 * nvmem-cell-names property).
1220 struct nvmem_cell *cell; in of_nvmem_cell_get() local
1223 /* if cell name exists, find index to the name */ in of_nvmem_cell_get()
1225 index = of_property_match_string(np, "nvmem-cell-names", id); in of_nvmem_cell_get()
1240 cell = nvmem_find_cell_by_node(nvmem, cell_np); in of_nvmem_cell_get()
1241 if (!cell) { in of_nvmem_cell_get()
1246 return cell; in of_nvmem_cell_get()
1252 * nvmem_cell_get() - Get nvmem cell of device form a given cell name
1254 * @dev: Device that requests the nvmem cell.
1255 * @id: nvmem cell name to get (this corresponds with the name from the
1256 * nvmem-cell-names property for DT systems and with the con_id from
1265 struct nvmem_cell *cell; in nvmem_cell_get() local
1268 cell = of_nvmem_cell_get(dev->of_node, id); in nvmem_cell_get()
1269 if (!IS_ERR(cell) || PTR_ERR(cell) == -EPROBE_DEFER) in nvmem_cell_get()
1270 return cell; in nvmem_cell_get()
1273 /* NULL cell id only allowed for device tree; invalid otherwise */ in nvmem_cell_get()
1287 * devm_nvmem_cell_get() - Get nvmem cell of device form a given id
1289 * @dev: Device that requests the nvmem cell.
1290 * @id: nvmem cell name id to get.
1298 struct nvmem_cell **ptr, *cell; in devm_nvmem_cell_get() local
1304 cell = nvmem_cell_get(dev, id); in devm_nvmem_cell_get()
1305 if (!IS_ERR(cell)) { in devm_nvmem_cell_get()
1306 *ptr = cell; in devm_nvmem_cell_get()
1312 return cell; in devm_nvmem_cell_get()
1327 * devm_nvmem_cell_put() - Release previously allocated nvmem cell
1330 * @dev: Device that requests the nvmem cell.
1331 * @cell: Previously allocated nvmem cell by devm_nvmem_cell_get().
1333 void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell) in devm_nvmem_cell_put() argument
1338 devm_nvmem_cell_match, cell); in devm_nvmem_cell_put()
1345 * nvmem_cell_put() - Release previously allocated nvmem cell.
1347 * @cell: Previously allocated nvmem cell by nvmem_cell_get().
1349 void nvmem_cell_put(struct nvmem_cell *cell) in nvmem_cell_put() argument
1351 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_put()
1357 static void nvmem_shift_read_buffer_in_place(struct nvmem_cell *cell, void *buf) in nvmem_shift_read_buffer_in_place() argument
1360 int i, extra, bit_offset = cell->bit_offset; in nvmem_shift_read_buffer_in_place()
1368 for (i = 1; i < cell->bytes; i++) { in nvmem_shift_read_buffer_in_place()
1377 p += cell->bytes - 1; in nvmem_shift_read_buffer_in_place()
1381 extra = cell->bytes - DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE); in nvmem_shift_read_buffer_in_place()
1386 if (cell->nbits % BITS_PER_BYTE) in nvmem_shift_read_buffer_in_place()
1387 *p &= GENMASK((cell->nbits % BITS_PER_BYTE) - 1, 0); in nvmem_shift_read_buffer_in_place()
1391 struct nvmem_cell *cell, in __nvmem_cell_read() argument
1396 rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->bytes); in __nvmem_cell_read()
1402 if (cell->bit_offset || cell->nbits) in __nvmem_cell_read()
1403 nvmem_shift_read_buffer_in_place(cell, buf); in __nvmem_cell_read()
1406 *len = cell->bytes; in __nvmem_cell_read()
1412 * nvmem_cell_read() - Read a given nvmem cell
1414 * @cell: nvmem cell to be read.
1415 * @len: pointer to length of cell which will be populated on successful read;
1421 void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) in nvmem_cell_read() argument
1423 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_read()
1430 buf = kzalloc(cell->bytes, GFP_KERNEL); in nvmem_cell_read()
1434 rc = __nvmem_cell_read(nvmem, cell, buf, len); in nvmem_cell_read()
1444 static void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell, in nvmem_cell_prepare_write_buffer() argument
1447 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_prepare_write_buffer()
1448 int i, rc, nbits, bit_offset = cell->bit_offset; in nvmem_cell_prepare_write_buffer()
1451 nbits = cell->nbits; in nvmem_cell_prepare_write_buffer()
1452 buf = kzalloc(cell->bytes, GFP_KERNEL); in nvmem_cell_prepare_write_buffer()
1464 rc = nvmem_reg_read(nvmem, cell->offset, &v, 1); in nvmem_cell_prepare_write_buffer()
1470 for (i = 1; i < cell->bytes; i++) { in nvmem_cell_prepare_write_buffer()
1484 cell->offset + cell->bytes - 1, &v, 1); in nvmem_cell_prepare_write_buffer()
1498 * nvmem_cell_write() - Write to a given nvmem cell
1500 * @cell: nvmem cell to be written.
1502 * @len: length of buffer to be written to nvmem cell.
1506 int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len) in nvmem_cell_write() argument
1508 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_write()
1512 (cell->bit_offset == 0 && len != cell->bytes)) in nvmem_cell_write()
1515 if (cell->bit_offset || cell->nbits) { in nvmem_cell_write()
1516 buf = nvmem_cell_prepare_write_buffer(cell, buf, len); in nvmem_cell_write()
1521 rc = nvmem_reg_write(nvmem, cell->offset, buf, cell->bytes); in nvmem_cell_write()
1524 if (cell->bit_offset || cell->nbits) in nvmem_cell_write()
1537 struct nvmem_cell *cell; in nvmem_cell_read_common() local
1541 cell = nvmem_cell_get(dev, cell_id); in nvmem_cell_read_common()
1542 if (IS_ERR(cell)) in nvmem_cell_read_common()
1543 return PTR_ERR(cell); in nvmem_cell_read_common()
1545 buf = nvmem_cell_read(cell, &len); in nvmem_cell_read_common()
1547 nvmem_cell_put(cell); in nvmem_cell_read_common()
1552 nvmem_cell_put(cell); in nvmem_cell_read_common()
1557 nvmem_cell_put(cell); in nvmem_cell_read_common()
1563 * nvmem_cell_read_u8() - Read a cell value as a u8
1565 * @dev: Device that requests the nvmem cell.
1566 * @cell_id: Name of nvmem cell to read.
1578 * nvmem_cell_read_u16() - Read a cell value as a u16
1580 * @dev: Device that requests the nvmem cell.
1581 * @cell_id: Name of nvmem cell to read.
1593 * nvmem_cell_read_u32() - Read a cell value as a u32
1595 * @dev: Device that requests the nvmem cell.
1596 * @cell_id: Name of nvmem cell to read.
1608 * nvmem_cell_read_u64() - Read a cell value as a u64
1610 * @dev: Device that requests the nvmem cell.
1611 * @cell_id: Name of nvmem cell to read.
1626 struct nvmem_cell *cell; in nvmem_cell_read_variable_common() local
1630 cell = nvmem_cell_get(dev, cell_id); in nvmem_cell_read_variable_common()
1631 if (IS_ERR(cell)) in nvmem_cell_read_variable_common()
1632 return cell; in nvmem_cell_read_variable_common()
1634 nbits = cell->nbits; in nvmem_cell_read_variable_common()
1635 buf = nvmem_cell_read(cell, len); in nvmem_cell_read_variable_common()
1636 nvmem_cell_put(cell); in nvmem_cell_read_variable_common()
1658 * @dev: Device that requests the nvmem cell.
1659 * @cell_id: Name of nvmem cell to read.
1689 * @dev: Device that requests the nvmem cell.
1690 * @cell_id: Name of nvmem cell to read.
1718 * nvmem_device_cell_read() - Read a given nvmem device and cell
1721 * @info: nvmem cell info to be read.
1730 struct nvmem_cell cell; in nvmem_device_cell_read() local
1737 rc = nvmem_cell_info_to_nvmem_cell_nodup(nvmem, info, &cell); in nvmem_device_cell_read()
1741 rc = __nvmem_cell_read(nvmem, &cell, buf, &len); in nvmem_device_cell_read()
1750 * nvmem_device_cell_write() - Write cell to a given nvmem device
1753 * @info: nvmem cell info to be written.
1754 * @buf: buffer to be written to cell.
1761 struct nvmem_cell cell; in nvmem_device_cell_write() local
1767 rc = nvmem_cell_info_to_nvmem_cell_nodup(nvmem, info, &cell); in nvmem_device_cell_write()
1771 return nvmem_cell_write(&cell, buf, cell.bytes); in nvmem_device_cell_write()
1805 * nvmem_device_write() - Write cell to a given nvmem device
1834 * nvmem_add_cell_table() - register a table of cell info entries
1836 * @table: table of cell info entries
1847 * nvmem_del_cell_table() - remove a previously registered cell info table
1849 * @table: table of cell info entries
1860 * nvmem_add_cell_lookups() - register a list of cell lookup entries
1862 * @entries: array of cell lookup entries
1863 * @nentries: number of cell lookup entries in the array
1877 * nvmem_del_cell_lookups() - remove a list of previously added cell lookup
1880 * @entries: array of cell lookup entries
1881 * @nentries: number of cell lookup entries in the array