Lines Matching refs:cell
439 static void nvmem_cell_entry_drop(struct nvmem_cell_entry *cell)
441 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_REMOVE, cell);
443 list_del(&cell->node);
445 of_node_put(cell->np);
446 kfree_const(cell->name);
447 kfree(cell);
452 struct nvmem_cell_entry *cell, *p;
454 list_for_each_entry_safe(cell, p, &nvmem->cells, node)
455 nvmem_cell_entry_drop(cell);
458 static void nvmem_cell_entry_add(struct nvmem_cell_entry *cell)
461 list_add_tail(&cell->node, &cell->nvmem->cells);
463 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_ADD, cell);
468 struct nvmem_cell_entry *cell)
470 cell->nvmem = nvmem;
471 cell->offset = info->offset;
472 cell->raw_len = info->raw_len ?: info->bytes;
473 cell->bytes = info->bytes;
474 cell->name = info->name;
475 cell->read_post_process = info->read_post_process;
476 cell->priv = info->priv;
478 cell->bit_offset = info->bit_offset;
479 cell->nbits = info->nbits;
480 cell->np = info->np;
482 if (cell->nbits)
483 cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset,
486 if (!IS_ALIGNED(cell->offset, nvmem->stride)) {
488 "cell %s unaligned to nvmem stride %d\n",
489 cell->name ?: "<unknown>", nvmem->stride);
498 struct nvmem_cell_entry *cell)
502 err = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, cell);
506 cell->name = kstrdup_const(info->name, GFP_KERNEL);
507 if (!cell->name)
514 * nvmem_add_one_cell() - Add one cell information to an nvmem device
517 * @info: nvmem cell info to add to the device
524 struct nvmem_cell_entry *cell;
527 cell = kzalloc(sizeof(*cell), GFP_KERNEL);
528 if (!cell)
531 rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell);
533 kfree(cell);
537 nvmem_cell_entry_add(cell);
544 * nvmem_add_cells() - Add cell information to an nvmem device
547 * @info: nvmem cell info to add to the device
597 struct nvmem_cell_entry *cell;
606 cell = kzalloc(sizeof(*cell), GFP_KERNEL);
607 if (!cell) {
612 rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell);
614 kfree(cell);
618 nvmem_cell_entry_add(cell);
631 struct nvmem_cell_entry *iter, *cell = NULL;
636 cell = iter;
642 return cell;
1119 "could not increase module refcount for cell %s\n",
1255 * devm_nvmem_device_get() - Get nvmem cell of device form a given id
1287 struct nvmem_cell *cell;
1290 cell = kzalloc(sizeof(*cell), GFP_KERNEL);
1291 if (!cell)
1297 kfree(cell);
1302 cell->id = name;
1303 cell->entry = entry;
1304 cell->index = index;
1306 return cell;
1313 struct nvmem_cell *cell = ERR_PTR(-ENOENT);
1333 cell = ERR_CAST(nvmem);
1341 cell = ERR_PTR(-ENOENT);
1343 cell = nvmem_create_cell(cell_entry, con_id, 0);
1344 if (IS_ERR(cell))
1352 return cell;
1359 struct nvmem_cell_entry *iter, *cell = NULL;
1364 cell = iter;
1370 return cell;
1374 * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id
1376 * @np: Device tree node that uses the nvmem cell.
1377 * @id: nvmem cell name from nvmem-cell-names property, or NULL
1378 * for the cell at index 0 (the lone cell with no accompanying
1379 * nvmem-cell-names property).
1390 struct nvmem_cell *cell;
1396 /* if cell name exists, find index to the name */
1398 index = of_property_match_string(np, "nvmem-cell-names", id);
1401 "#nvmem-cell-cells",
1442 cell = nvmem_create_cell(cell_entry, id, cell_index);
1443 if (IS_ERR(cell))
1446 return cell;
1452 * nvmem_cell_get() - Get nvmem cell of device form a given cell name
1454 * @dev: Device that requests the nvmem cell.
1455 * @id: nvmem cell name to get (this corresponds with the name from the
1456 * nvmem-cell-names property for DT systems and with the con_id from
1465 struct nvmem_cell *cell;
1468 cell = of_nvmem_cell_get(dev->of_node, id);
1469 if (!IS_ERR(cell) || PTR_ERR(cell) == -EPROBE_DEFER)
1470 return cell;
1473 /* NULL cell id only allowed for device tree; invalid otherwise */
1487 * devm_nvmem_cell_get() - Get nvmem cell of device form a given id
1489 * @dev: Device that requests the nvmem cell.
1490 * @id: nvmem cell name id to get.
1498 struct nvmem_cell **ptr, *cell;
1504 cell = nvmem_cell_get(dev, id);
1505 if (!IS_ERR(cell)) {
1506 *ptr = cell;
1512 return cell;
1527 * devm_nvmem_cell_put() - Release previously allocated nvmem cell
1530 * @dev: Device that requests the nvmem cell.
1531 * @cell: Previously allocated nvmem cell by devm_nvmem_cell_get().
1533 void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell)
1538 devm_nvmem_cell_match, cell);
1545 * nvmem_cell_put() - Release previously allocated nvmem cell.
1547 * @cell: Previously allocated nvmem cell by nvmem_cell_get().
1549 void nvmem_cell_put(struct nvmem_cell *cell)
1551 struct nvmem_device *nvmem = cell->entry->nvmem;
1553 if (cell->id)
1554 kfree_const(cell->id);
1556 kfree(cell);
1561 static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void *buf)
1564 int i, extra, bit_offset = cell->bit_offset;
1572 for (i = 1; i < cell->bytes; i++) {
1581 p += cell->bytes - 1;
1585 extra = cell->bytes - DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE);
1590 if (cell->nbits % BITS_PER_BYTE)
1591 *p &= GENMASK((cell->nbits % BITS_PER_BYTE) - 1, 0);
1595 struct nvmem_cell_entry *cell,
1600 rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->raw_len);
1606 if (cell->bit_offset || cell->nbits)
1607 nvmem_shift_read_buffer_in_place(cell, buf);
1609 if (cell->read_post_process) {
1610 rc = cell->read_post_process(cell->priv, id, index,
1611 cell->offset, buf, cell->raw_len);
1617 *len = cell->bytes;
1623 * nvmem_cell_read() - Read a given nvmem cell
1625 * @cell: nvmem cell to be read.
1626 * @len: pointer to length of cell which will be populated on successful read;
1632 void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
1634 struct nvmem_cell_entry *entry = cell->entry;
1646 rc = __nvmem_cell_read(nvmem, cell->entry, buf, len, cell->id, cell->index);
1656 static void *nvmem_cell_prepare_write_buffer(struct nvmem_cell_entry *cell,
1659 struct nvmem_device *nvmem = cell->nvmem;
1660 int i, rc, nbits, bit_offset = cell->bit_offset;
1663 nbits = cell->nbits;
1664 buf = kzalloc(cell->bytes, GFP_KERNEL);
1676 rc = nvmem_reg_read(nvmem, cell->offset, &v, 1);
1682 for (i = 1; i < cell->bytes; i++) {
1696 cell->offset + cell->bytes - 1, &v, 1);
1709 static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, size_t len)
1711 struct nvmem_device *nvmem = cell->nvmem;
1715 (cell->bit_offset == 0 && len != cell->bytes))
1723 if (cell->read_post_process)
1726 if (cell->bit_offset || cell->nbits) {
1727 buf = nvmem_cell_prepare_write_buffer(cell, buf, len);
1732 rc = nvmem_reg_write(nvmem, cell->offset, buf, cell->bytes);
1735 if (cell->bit_offset || cell->nbits)
1745 * nvmem_cell_write() - Write to a given nvmem cell
1747 * @cell: nvmem cell to be written.
1749 * @len: length of buffer to be written to nvmem cell.
1753 int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len)
1755 return __nvmem_cell_entry_write(cell->entry, buf, len);
1763 struct nvmem_cell *cell;
1767 cell = nvmem_cell_get(dev, cell_id);
1768 if (IS_ERR(cell))
1769 return PTR_ERR(cell);
1771 buf = nvmem_cell_read(cell, &len);
1773 nvmem_cell_put(cell);
1778 nvmem_cell_put(cell);
1783 nvmem_cell_put(cell);
1789 * nvmem_cell_read_u8() - Read a cell value as a u8
1791 * @dev: Device that requests the nvmem cell.
1792 * @cell_id: Name of nvmem cell to read.
1804 * nvmem_cell_read_u16() - Read a cell value as a u16
1806 * @dev: Device that requests the nvmem cell.
1807 * @cell_id: Name of nvmem cell to read.
1819 * nvmem_cell_read_u32() - Read a cell value as a u32
1821 * @dev: Device that requests the nvmem cell.
1822 * @cell_id: Name of nvmem cell to read.
1834 * nvmem_cell_read_u64() - Read a cell value as a u64
1836 * @dev: Device that requests the nvmem cell.
1837 * @cell_id: Name of nvmem cell to read.
1852 struct nvmem_cell *cell;
1856 cell = nvmem_cell_get(dev, cell_id);
1857 if (IS_ERR(cell))
1858 return cell;
1860 nbits = cell->entry->nbits;
1861 buf = nvmem_cell_read(cell, len);
1862 nvmem_cell_put(cell);
1884 * @dev: Device that requests the nvmem cell.
1885 * @cell_id: Name of nvmem cell to read.
1915 * @dev: Device that requests the nvmem cell.
1916 * @cell_id: Name of nvmem cell to read.
1944 * nvmem_device_cell_read() - Read a given nvmem device and cell
1947 * @info: nvmem cell info to be read.
1956 struct nvmem_cell_entry cell;
1963 rc = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, &cell);
1967 rc = __nvmem_cell_read(nvmem, &cell, buf, &len, NULL, 0);
1976 * nvmem_device_cell_write() - Write cell to a given nvmem device
1979 * @info: nvmem cell info to be written.
1980 * @buf: buffer to be written to cell.
1987 struct nvmem_cell_entry cell;
1993 rc = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, &cell);
1997 return __nvmem_cell_entry_write(&cell, buf, cell.bytes);
2031 * nvmem_device_write() - Write cell to a given nvmem device
2060 * nvmem_add_cell_table() - register a table of cell info entries
2062 * @table: table of cell info entries
2073 * nvmem_del_cell_table() - remove a previously registered cell info table
2075 * @table: table of cell info entries
2086 * nvmem_add_cell_lookups() - register a list of cell lookup entries
2088 * @entries: array of cell lookup entries
2089 * @nentries: number of cell lookup entries in the array
2103 * nvmem_del_cell_lookups() - remove a list of previously added cell lookup
2106 * @entries: array of cell lookup entries
2107 * @nentries: number of cell lookup entries in the array