Lines Matching refs:cell

339 static void nvmem_cell_drop(struct nvmem_cell *cell)
341 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_REMOVE, cell);
343 list_del(&cell->node);
345 of_node_put(cell->np);
346 kfree_const(cell->name);
347 kfree(cell);
352 struct nvmem_cell *cell, *p;
354 list_for_each_entry_safe(cell, p, &nvmem->cells, node)
355 nvmem_cell_drop(cell);
358 static void nvmem_cell_add(struct nvmem_cell *cell)
361 list_add_tail(&cell->node, &cell->nvmem->cells);
363 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_ADD, cell);
368 struct nvmem_cell *cell)
370 cell->nvmem = nvmem;
371 cell->offset = info->offset;
372 cell->bytes = info->bytes;
373 cell->name = info->name;
375 cell->bit_offset = info->bit_offset;
376 cell->nbits = info->nbits;
378 if (cell->nbits)
379 cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset,
382 if (!IS_ALIGNED(cell->offset, nvmem->stride)) {
384 "cell %s unaligned to nvmem stride %d\n",
385 cell->name ?: "<unknown>", nvmem->stride);
394 struct nvmem_cell *cell)
398 err = nvmem_cell_info_to_nvmem_cell_nodup(nvmem, info, cell);
402 cell->name = kstrdup_const(info->name, GFP_KERNEL);
403 if (!cell->name)
410 * nvmem_add_cells() - Add cell information to an nvmem device
413 * @info: nvmem cell info to add to the device
488 struct nvmem_cell *cell;
497 cell = kzalloc(sizeof(*cell), GFP_KERNEL);
498 if (!cell) {
505 cell);
507 kfree(cell);
511 nvmem_cell_add(cell);
524 struct nvmem_cell *iter, *cell = NULL;
529 cell = iter;
535 return cell;
542 struct nvmem_cell *cell;
558 cell = kzalloc(sizeof(*cell), GFP_KERNEL);
559 if (!cell) {
564 cell->nvmem = nvmem;
565 cell->offset = be32_to_cpup(addr++);
566 cell->bytes = be32_to_cpup(addr);
567 cell->name = kasprintf(GFP_KERNEL, "%pOFn", child);
571 cell->bit_offset = be32_to_cpup(addr++);
572 cell->nbits = be32_to_cpup(addr);
575 if (cell->nbits)
576 cell->bytes = DIV_ROUND_UP(
577 cell->nbits + cell->bit_offset,
580 if (!IS_ALIGNED(cell->offset, nvmem->stride)) {
581 dev_err(dev, "cell %s unaligned to nvmem stride %d\n",
582 cell->name, nvmem->stride);
584 kfree_const(cell->name);
585 kfree(cell);
590 cell->np = of_node_get(child);
591 nvmem_cell_add(cell);
829 "could not increase module refcount for cell %s\n",
965 * devm_nvmem_device_get() - Get nvmem cell of device form a given id
997 struct nvmem_cell *cell = ERR_PTR(-ENOENT);
1017 cell = ERR_CAST(nvmem);
1021 cell = nvmem_find_cell_by_name(nvmem,
1023 if (!cell) {
1025 cell = ERR_PTR(-ENOENT);
1032 return cell;
1039 struct nvmem_cell *iter, *cell = NULL;
1044 cell = iter;
1050 return cell;
1054 * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id
1056 * @np: Device tree node that uses the nvmem cell.
1057 * @id: nvmem cell name from nvmem-cell-names property, or NULL
1058 * for the cell at index 0 (the lone cell with no accompanying
1059 * nvmem-cell-names property).
1069 struct nvmem_cell *cell;
1072 /* if cell name exists, find index to the name */
1074 index = of_property_match_string(np, "nvmem-cell-names", id);
1089 cell = nvmem_find_cell_by_node(nvmem, cell_np);
1090 if (!cell) {
1095 return cell;
1101 * nvmem_cell_get() - Get nvmem cell of device form a given cell name
1103 * @dev: Device that requests the nvmem cell.
1104 * @id: nvmem cell name to get (this corresponds with the name from the
1105 * nvmem-cell-names property for DT systems and with the con_id from
1114 struct nvmem_cell *cell;
1117 cell = of_nvmem_cell_get(dev->of_node, id);
1118 if (!IS_ERR(cell) || PTR_ERR(cell) == -EPROBE_DEFER)
1119 return cell;
1122 /* NULL cell id only allowed for device tree; invalid otherwise */
1136 * devm_nvmem_cell_get() - Get nvmem cell of device form a given id
1138 * @dev: Device that requests the nvmem cell.
1139 * @id: nvmem cell name id to get.
1147 struct nvmem_cell **ptr, *cell;
1153 cell = nvmem_cell_get(dev, id);
1154 if (!IS_ERR(cell)) {
1155 *ptr = cell;
1161 return cell;
1176 * devm_nvmem_cell_put() - Release previously allocated nvmem cell
1179 * @dev: Device that requests the nvmem cell.
1180 * @cell: Previously allocated nvmem cell by devm_nvmem_cell_get().
1182 void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell)
1187 devm_nvmem_cell_match, cell);
1194 * nvmem_cell_put() - Release previously allocated nvmem cell.
1196 * @cell: Previously allocated nvmem cell by nvmem_cell_get().
1198 void nvmem_cell_put(struct nvmem_cell *cell)
1200 struct nvmem_device *nvmem = cell->nvmem;
1206 static void nvmem_shift_read_buffer_in_place(struct nvmem_cell *cell, void *buf)
1209 int i, extra, bit_offset = cell->bit_offset;
1217 for (i = 1; i < cell->bytes; i++) {
1226 p += cell->bytes - 1;
1230 extra = cell->bytes - DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE);
1235 if (cell->nbits % BITS_PER_BYTE)
1236 *p &= GENMASK((cell->nbits % BITS_PER_BYTE) - 1, 0);
1240 struct nvmem_cell *cell,
1245 rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->bytes);
1251 if (cell->bit_offset || cell->nbits)
1252 nvmem_shift_read_buffer_in_place(cell, buf);
1255 *len = cell->bytes;
1261 * nvmem_cell_read() - Read a given nvmem cell
1263 * @cell: nvmem cell to be read.
1264 * @len: pointer to length of cell which will be populated on successful read;
1270 void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
1272 struct nvmem_device *nvmem = cell->nvmem;
1279 buf = kzalloc(cell->bytes, GFP_KERNEL);
1283 rc = __nvmem_cell_read(nvmem, cell, buf, len);
1293 static void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell,
1296 struct nvmem_device *nvmem = cell->nvmem;
1297 int i, rc, nbits, bit_offset = cell->bit_offset;
1300 nbits = cell->nbits;
1301 buf = kzalloc(cell->bytes, GFP_KERNEL);
1313 rc = nvmem_reg_read(nvmem, cell->offset, &v, 1);
1319 for (i = 1; i < cell->bytes; i++) {
1333 cell->offset + cell->bytes - 1, &v, 1);
1347 * nvmem_cell_write() - Write to a given nvmem cell
1349 * @cell: nvmem cell to be written.
1351 * @len: length of buffer to be written to nvmem cell.
1355 int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len)
1357 struct nvmem_device *nvmem = cell->nvmem;
1361 (cell->bit_offset == 0 && len != cell->bytes))
1364 if (cell->bit_offset || cell->nbits) {
1365 buf = nvmem_cell_prepare_write_buffer(cell, buf, len);
1370 rc = nvmem_reg_write(nvmem, cell->offset, buf, cell->bytes);
1373 if (cell->bit_offset || cell->nbits)
1386 struct nvmem_cell *cell;
1390 cell = nvmem_cell_get(dev, cell_id);
1391 if (IS_ERR(cell))
1392 return PTR_ERR(cell);
1394 buf = nvmem_cell_read(cell, &len);
1396 nvmem_cell_put(cell);
1401 nvmem_cell_put(cell);
1406 nvmem_cell_put(cell);
1412 * nvmem_cell_read_u8() - Read a cell value as a u8
1414 * @dev: Device that requests the nvmem cell.
1415 * @cell_id: Name of nvmem cell to read.
1427 * nvmem_cell_read_u16() - Read a cell value as a u16
1429 * @dev: Device that requests the nvmem cell.
1430 * @cell_id: Name of nvmem cell to read.
1442 * nvmem_cell_read_u32() - Read a cell value as a u32
1444 * @dev: Device that requests the nvmem cell.
1445 * @cell_id: Name of nvmem cell to read.
1457 * nvmem_cell_read_u64() - Read a cell value as a u64
1459 * @dev: Device that requests the nvmem cell.
1460 * @cell_id: Name of nvmem cell to read.
1472 * nvmem_device_cell_read() - Read a given nvmem device and cell
1475 * @info: nvmem cell info to be read.
1484 struct nvmem_cell cell;
1491 rc = nvmem_cell_info_to_nvmem_cell_nodup(nvmem, info, &cell);
1495 rc = __nvmem_cell_read(nvmem, &cell, buf, &len);
1504 * nvmem_device_cell_write() - Write cell to a given nvmem device
1507 * @info: nvmem cell info to be written.
1508 * @buf: buffer to be written to cell.
1515 struct nvmem_cell cell;
1521 rc = nvmem_cell_info_to_nvmem_cell_nodup(nvmem, info, &cell);
1525 return nvmem_cell_write(&cell, buf, cell.bytes);
1559 * nvmem_device_write() - Write cell to a given nvmem device
1588 * nvmem_add_cell_table() - register a table of cell info entries
1590 * @table: table of cell info entries
1601 * nvmem_del_cell_table() - remove a previously registered cell info table
1603 * @table: table of cell info entries
1614 * nvmem_add_cell_lookups() - register a list of cell lookup entries
1616 * @entries: array of cell lookup entries
1617 * @nentries: number of cell lookup entries in the array
1631 * nvmem_del_cell_lookups() - remove a list of previously added cell lookup
1634 * @entries: array of cell lookup entries
1635 * @nentries: number of cell lookup entries in the array