Lines Matching full:cell

432 static void nvmem_cell_entry_drop(struct nvmem_cell_entry *cell)  in nvmem_cell_entry_drop()  argument
434 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_REMOVE, cell); in nvmem_cell_entry_drop()
436 list_del(&cell->node); in nvmem_cell_entry_drop()
438 of_node_put(cell->np); in nvmem_cell_entry_drop()
439 kfree_const(cell->name); in nvmem_cell_entry_drop()
440 kfree(cell); in nvmem_cell_entry_drop()
445 struct nvmem_cell_entry *cell, *p; in nvmem_device_remove_all_cells() local
447 list_for_each_entry_safe(cell, p, &nvmem->cells, node) in nvmem_device_remove_all_cells()
448 nvmem_cell_entry_drop(cell); in nvmem_device_remove_all_cells()
451 static void nvmem_cell_entry_add(struct nvmem_cell_entry *cell) in nvmem_cell_entry_add() argument
454 list_add_tail(&cell->node, &cell->nvmem->cells); in nvmem_cell_entry_add()
456 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_ADD, cell); in nvmem_cell_entry_add()
461 struct nvmem_cell_entry *cell) in nvmem_cell_info_to_nvmem_cell_entry_nodup() argument
463 cell->nvmem = nvmem; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
464 cell->offset = info->offset; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
465 cell->bytes = info->bytes; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
466 cell->name = info->name; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
468 cell->bit_offset = info->bit_offset; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
469 cell->nbits = info->nbits; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
470 cell->np = info->np; in nvmem_cell_info_to_nvmem_cell_entry_nodup()
472 if (cell->nbits) in nvmem_cell_info_to_nvmem_cell_entry_nodup()
473 cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset, in nvmem_cell_info_to_nvmem_cell_entry_nodup()
476 if (!IS_ALIGNED(cell->offset, nvmem->stride)) { in nvmem_cell_info_to_nvmem_cell_entry_nodup()
478 "cell %s unaligned to nvmem stride %d\n", in nvmem_cell_info_to_nvmem_cell_entry_nodup()
479 cell->name ?: "<unknown>", nvmem->stride); in nvmem_cell_info_to_nvmem_cell_entry_nodup()
488 struct nvmem_cell_entry *cell) in nvmem_cell_info_to_nvmem_cell_entry() argument
492 err = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, cell); in nvmem_cell_info_to_nvmem_cell_entry()
496 cell->name = kstrdup_const(info->name, GFP_KERNEL); in nvmem_cell_info_to_nvmem_cell_entry()
497 if (!cell->name) in nvmem_cell_info_to_nvmem_cell_entry()
504 * nvmem_add_cells() - Add cell information to an nvmem device
507 * @info: nvmem cell info to add to the device
582 struct nvmem_cell_entry *cell; in nvmem_add_cells_from_table() local
591 cell = kzalloc(sizeof(*cell), GFP_KERNEL); in nvmem_add_cells_from_table()
592 if (!cell) { in nvmem_add_cells_from_table()
597 rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell); in nvmem_add_cells_from_table()
599 kfree(cell); in nvmem_add_cells_from_table()
603 nvmem_cell_entry_add(cell); in nvmem_add_cells_from_table()
616 struct nvmem_cell_entry *iter, *cell = NULL; in nvmem_find_cell_entry_by_name() local
621 cell = iter; in nvmem_find_cell_entry_by_name()
627 return cell; in nvmem_find_cell_entry_by_name()
687 struct nvmem_cell_entry *cell; in nvmem_add_cells_from_of() local
703 cell = kzalloc(sizeof(*cell), GFP_KERNEL); in nvmem_add_cells_from_of()
704 if (!cell) { in nvmem_add_cells_from_of()
709 cell->nvmem = nvmem; in nvmem_add_cells_from_of()
710 cell->offset = be32_to_cpup(addr++); in nvmem_add_cells_from_of()
711 cell->bytes = be32_to_cpup(addr); in nvmem_add_cells_from_of()
712 cell->name = kasprintf(GFP_KERNEL, "%pOFn", child); in nvmem_add_cells_from_of()
716 cell->bit_offset = be32_to_cpup(addr++); in nvmem_add_cells_from_of()
717 cell->nbits = be32_to_cpup(addr); in nvmem_add_cells_from_of()
720 if (cell->nbits) in nvmem_add_cells_from_of()
721 cell->bytes = DIV_ROUND_UP( in nvmem_add_cells_from_of()
722 cell->nbits + cell->bit_offset, in nvmem_add_cells_from_of()
725 if (!IS_ALIGNED(cell->offset, nvmem->stride)) { in nvmem_add_cells_from_of()
726 dev_err(dev, "cell %s unaligned to nvmem stride %d\n", in nvmem_add_cells_from_of()
727 cell->name, nvmem->stride); in nvmem_add_cells_from_of()
729 kfree_const(cell->name); in nvmem_add_cells_from_of()
730 kfree(cell); in nvmem_add_cells_from_of()
735 cell->np = of_node_get(child); in nvmem_add_cells_from_of()
736 nvmem_cell_entry_add(cell); in nvmem_add_cells_from_of()
965 "could not increase module refcount for cell %s\n", in __nvmem_device_get()
1101 * devm_nvmem_device_get() - Get nvmem cell of device form a given id
1132 struct nvmem_cell *cell; in nvmem_create_cell() local
1135 cell = kzalloc(sizeof(*cell), GFP_KERNEL); in nvmem_create_cell()
1136 if (!cell) in nvmem_create_cell()
1142 kfree(cell); in nvmem_create_cell()
1147 cell->id = name; in nvmem_create_cell()
1148 cell->entry = entry; in nvmem_create_cell()
1150 return cell; in nvmem_create_cell()
1157 struct nvmem_cell *cell = ERR_PTR(-ENOENT); in nvmem_cell_get_from_lookup() local
1177 cell = ERR_CAST(nvmem); in nvmem_cell_get_from_lookup()
1185 cell = ERR_PTR(-ENOENT); in nvmem_cell_get_from_lookup()
1187 cell = nvmem_create_cell(cell_entry, con_id); in nvmem_cell_get_from_lookup()
1188 if (IS_ERR(cell)) in nvmem_cell_get_from_lookup()
1196 return cell; in nvmem_cell_get_from_lookup()
1203 struct nvmem_cell_entry *iter, *cell = NULL; in nvmem_find_cell_entry_by_node() local
1208 cell = iter; in nvmem_find_cell_entry_by_node()
1214 return cell; in nvmem_find_cell_entry_by_node()
1218 * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id
1220 * @np: Device tree node that uses the nvmem cell.
1221 * @id: nvmem cell name from nvmem-cell-names property, or NULL
1222 * for the cell at index 0 (the lone cell with no accompanying
1223 * nvmem-cell-names property).
1234 struct nvmem_cell *cell; in of_nvmem_cell_get() local
1237 /* if cell name exists, find index to the name */ in of_nvmem_cell_get()
1239 index = of_property_match_string(np, "nvmem-cell-names", id); in of_nvmem_cell_get()
1260 cell = nvmem_create_cell(cell_entry, id); in of_nvmem_cell_get()
1261 if (IS_ERR(cell)) in of_nvmem_cell_get()
1264 return cell; in of_nvmem_cell_get()
1270 * nvmem_cell_get() - Get nvmem cell of device form a given cell name
1272 * @dev: Device that requests the nvmem cell.
1273 * @id: nvmem cell name to get (this corresponds with the name from the
1274 * nvmem-cell-names property for DT systems and with the con_id from
1283 struct nvmem_cell *cell; in nvmem_cell_get() local
1286 cell = of_nvmem_cell_get(dev->of_node, id); in nvmem_cell_get()
1287 if (!IS_ERR(cell) || PTR_ERR(cell) == -EPROBE_DEFER) in nvmem_cell_get()
1288 return cell; in nvmem_cell_get()
1291 /* NULL cell id only allowed for device tree; invalid otherwise */ in nvmem_cell_get()
1305 * devm_nvmem_cell_get() - Get nvmem cell of device form a given id
1307 * @dev: Device that requests the nvmem cell.
1308 * @id: nvmem cell name id to get.
1316 struct nvmem_cell **ptr, *cell; in devm_nvmem_cell_get() local
1322 cell = nvmem_cell_get(dev, id); in devm_nvmem_cell_get()
1323 if (!IS_ERR(cell)) { in devm_nvmem_cell_get()
1324 *ptr = cell; in devm_nvmem_cell_get()
1330 return cell; in devm_nvmem_cell_get()
1345 * devm_nvmem_cell_put() - Release previously allocated nvmem cell
1348 * @dev: Device that requests the nvmem cell.
1349 * @cell: Previously allocated nvmem cell by devm_nvmem_cell_get().
1351 void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell) in devm_nvmem_cell_put() argument
1356 devm_nvmem_cell_match, cell); in devm_nvmem_cell_put()
1363 * nvmem_cell_put() - Release previously allocated nvmem cell.
1365 * @cell: Previously allocated nvmem cell by nvmem_cell_get().
1367 void nvmem_cell_put(struct nvmem_cell *cell) in nvmem_cell_put() argument
1369 struct nvmem_device *nvmem = cell->entry->nvmem; in nvmem_cell_put()
1371 if (cell->id) in nvmem_cell_put()
1372 kfree_const(cell->id); in nvmem_cell_put()
1374 kfree(cell); in nvmem_cell_put()
1379 static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void *buf) in nvmem_shift_read_buffer_in_place() argument
1382 int i, extra, bit_offset = cell->bit_offset; in nvmem_shift_read_buffer_in_place()
1390 for (i = 1; i < cell->bytes; i++) { in nvmem_shift_read_buffer_in_place()
1399 p += cell->bytes - 1; in nvmem_shift_read_buffer_in_place()
1403 extra = cell->bytes - DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE); in nvmem_shift_read_buffer_in_place()
1408 if (cell->nbits % BITS_PER_BYTE) in nvmem_shift_read_buffer_in_place()
1409 *p &= GENMASK((cell->nbits % BITS_PER_BYTE) - 1, 0); in nvmem_shift_read_buffer_in_place()
1413 struct nvmem_cell_entry *cell, in __nvmem_cell_read() argument
1418 rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->bytes); in __nvmem_cell_read()
1424 if (cell->bit_offset || cell->nbits) in __nvmem_cell_read()
1425 nvmem_shift_read_buffer_in_place(cell, buf); in __nvmem_cell_read()
1429 cell->offset, buf, cell->bytes); in __nvmem_cell_read()
1435 *len = cell->bytes; in __nvmem_cell_read()
1441 * nvmem_cell_read() - Read a given nvmem cell
1443 * @cell: nvmem cell to be read.
1444 * @len: pointer to length of cell which will be populated on successful read;
1450 void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) in nvmem_cell_read() argument
1452 struct nvmem_device *nvmem = cell->entry->nvmem; in nvmem_cell_read()
1459 buf = kzalloc(cell->entry->bytes, GFP_KERNEL); in nvmem_cell_read()
1463 rc = __nvmem_cell_read(nvmem, cell->entry, buf, len, cell->id); in nvmem_cell_read()
1473 static void *nvmem_cell_prepare_write_buffer(struct nvmem_cell_entry *cell, in nvmem_cell_prepare_write_buffer() argument
1476 struct nvmem_device *nvmem = cell->nvmem; in nvmem_cell_prepare_write_buffer()
1477 int i, rc, nbits, bit_offset = cell->bit_offset; in nvmem_cell_prepare_write_buffer()
1480 nbits = cell->nbits; in nvmem_cell_prepare_write_buffer()
1481 buf = kzalloc(cell->bytes, GFP_KERNEL); in nvmem_cell_prepare_write_buffer()
1493 rc = nvmem_reg_read(nvmem, cell->offset, &v, 1); in nvmem_cell_prepare_write_buffer()
1499 for (i = 1; i < cell->bytes; i++) { in nvmem_cell_prepare_write_buffer()
1513 cell->offset + cell->bytes - 1, &v, 1); in nvmem_cell_prepare_write_buffer()
1526 static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, size_t len) in __nvmem_cell_entry_write() argument
1528 struct nvmem_device *nvmem = cell->nvmem; in __nvmem_cell_entry_write()
1532 (cell->bit_offset == 0 && len != cell->bytes)) in __nvmem_cell_entry_write()
1535 if (cell->bit_offset || cell->nbits) { in __nvmem_cell_entry_write()
1536 buf = nvmem_cell_prepare_write_buffer(cell, buf, len); in __nvmem_cell_entry_write()
1541 rc = nvmem_reg_write(nvmem, cell->offset, buf, cell->bytes); in __nvmem_cell_entry_write()
1544 if (cell->bit_offset || cell->nbits) in __nvmem_cell_entry_write()
1554 * nvmem_cell_write() - Write to a given nvmem cell
1556 * @cell: nvmem cell to be written.
1558 * @len: length of buffer to be written to nvmem cell.
1562 int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len) in nvmem_cell_write() argument
1564 return __nvmem_cell_entry_write(cell->entry, buf, len); in nvmem_cell_write()
1572 struct nvmem_cell *cell; in nvmem_cell_read_common() local
1576 cell = nvmem_cell_get(dev, cell_id); in nvmem_cell_read_common()
1577 if (IS_ERR(cell)) in nvmem_cell_read_common()
1578 return PTR_ERR(cell); in nvmem_cell_read_common()
1580 buf = nvmem_cell_read(cell, &len); in nvmem_cell_read_common()
1582 nvmem_cell_put(cell); in nvmem_cell_read_common()
1587 nvmem_cell_put(cell); in nvmem_cell_read_common()
1592 nvmem_cell_put(cell); in nvmem_cell_read_common()
1598 * nvmem_cell_read_u8() - Read a cell value as a u8
1600 * @dev: Device that requests the nvmem cell.
1601 * @cell_id: Name of nvmem cell to read.
1613 * nvmem_cell_read_u16() - Read a cell value as a u16
1615 * @dev: Device that requests the nvmem cell.
1616 * @cell_id: Name of nvmem cell to read.
1628 * nvmem_cell_read_u32() - Read a cell value as a u32
1630 * @dev: Device that requests the nvmem cell.
1631 * @cell_id: Name of nvmem cell to read.
1643 * nvmem_cell_read_u64() - Read a cell value as a u64
1645 * @dev: Device that requests the nvmem cell.
1646 * @cell_id: Name of nvmem cell to read.
1661 struct nvmem_cell *cell; in nvmem_cell_read_variable_common() local
1665 cell = nvmem_cell_get(dev, cell_id); in nvmem_cell_read_variable_common()
1666 if (IS_ERR(cell)) in nvmem_cell_read_variable_common()
1667 return cell; in nvmem_cell_read_variable_common()
1669 nbits = cell->entry->nbits; in nvmem_cell_read_variable_common()
1670 buf = nvmem_cell_read(cell, len); in nvmem_cell_read_variable_common()
1671 nvmem_cell_put(cell); in nvmem_cell_read_variable_common()
1693 * @dev: Device that requests the nvmem cell.
1694 * @cell_id: Name of nvmem cell to read.
1724 * @dev: Device that requests the nvmem cell.
1725 * @cell_id: Name of nvmem cell to read.
1753 * nvmem_device_cell_read() - Read a given nvmem device and cell
1756 * @info: nvmem cell info to be read.
1765 struct nvmem_cell_entry cell; in nvmem_device_cell_read() local
1772 rc = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, &cell); in nvmem_device_cell_read()
1776 rc = __nvmem_cell_read(nvmem, &cell, buf, &len, NULL); in nvmem_device_cell_read()
1785 * nvmem_device_cell_write() - Write cell to a given nvmem device
1788 * @info: nvmem cell info to be written.
1789 * @buf: buffer to be written to cell.
1796 struct nvmem_cell_entry cell; in nvmem_device_cell_write() local
1802 rc = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, &cell); in nvmem_device_cell_write()
1806 return __nvmem_cell_entry_write(&cell, buf, cell.bytes); in nvmem_device_cell_write()
1840 * nvmem_device_write() - Write cell to a given nvmem device
1869 * nvmem_add_cell_table() - register a table of cell info entries
1871 * @table: table of cell info entries
1882 * nvmem_del_cell_table() - remove a previously registered cell info table
1884 * @table: table of cell info entries
1895 * nvmem_add_cell_lookups() - register a list of cell lookup entries
1897 * @entries: array of cell lookup entries
1898 * @nentries: number of cell lookup entries in the array
1912 * nvmem_del_cell_lookups() - remove a list of previously added cell lookup
1915 * @entries: array of cell lookup entries
1916 * @nentries: number of cell lookup entries in the array