Lines Matching +full:dma +full:- +full:mem

1 // SPDX-License-Identifier: GPL-2.0+
12 #include <linux/spi/spi-mem.h>
20 * spi_controller_dma_map_mem_op_data() - DMA-map the buffer attached to a
24 * @sgt: a pointer to a non-initialized sg_table that will be filled by this
27 * Some controllers might want to do DMA on the data buffer embedded in @op.
28 * This helper prepares everything for you and provides a ready-to-use
32 * op->data.buf.{in,out} is DMA-able before calling this function.
42 if (!op->data.nbytes) in spi_controller_dma_map_mem_op_data()
43 return -EINVAL; in spi_controller_dma_map_mem_op_data()
45 if (op->data.dir == SPI_MEM_DATA_OUT && ctlr->dma_tx) in spi_controller_dma_map_mem_op_data()
46 dmadev = ctlr->dma_tx->device->dev; in spi_controller_dma_map_mem_op_data()
47 else if (op->data.dir == SPI_MEM_DATA_IN && ctlr->dma_rx) in spi_controller_dma_map_mem_op_data()
48 dmadev = ctlr->dma_rx->device->dev; in spi_controller_dma_map_mem_op_data()
50 dmadev = ctlr->dev.parent; in spi_controller_dma_map_mem_op_data()
53 return -EINVAL; in spi_controller_dma_map_mem_op_data()
55 return spi_map_buf(ctlr, dmadev, sgt, op->data.buf.in, op->data.nbytes, in spi_controller_dma_map_mem_op_data()
56 op->data.dir == SPI_MEM_DATA_IN ? in spi_controller_dma_map_mem_op_data()
62 * spi_controller_dma_unmap_mem_op_data() - DMA-unmap the buffer attached to a
69 * Some controllers might want to do DMA on the data buffer embedded in @op.
71 * op->data.buf.{in,out} buffer again.
76 * This function should be called after the DMA operation has finished and is
88 if (!op->data.nbytes) in spi_controller_dma_unmap_mem_op_data()
91 if (op->data.dir == SPI_MEM_DATA_OUT && ctlr->dma_tx) in spi_controller_dma_unmap_mem_op_data()
92 dmadev = ctlr->dma_tx->device->dev; in spi_controller_dma_unmap_mem_op_data()
93 else if (op->data.dir == SPI_MEM_DATA_IN && ctlr->dma_rx) in spi_controller_dma_unmap_mem_op_data()
94 dmadev = ctlr->dma_rx->device->dev; in spi_controller_dma_unmap_mem_op_data()
96 dmadev = ctlr->dev.parent; in spi_controller_dma_unmap_mem_op_data()
99 op->data.dir == SPI_MEM_DATA_IN ? in spi_controller_dma_unmap_mem_op_data()
104 static int spi_check_buswidth_req(struct spi_mem *mem, u8 buswidth, bool tx) in spi_check_buswidth_req() argument
106 u32 mode = mem->spi->mode; in spi_check_buswidth_req()
139 return -ENOTSUPP; in spi_check_buswidth_req()
142 static bool spi_mem_check_buswidth(struct spi_mem *mem, in spi_mem_check_buswidth() argument
145 if (spi_check_buswidth_req(mem, op->cmd.buswidth, true)) in spi_mem_check_buswidth()
148 if (op->addr.nbytes && in spi_mem_check_buswidth()
149 spi_check_buswidth_req(mem, op->addr.buswidth, true)) in spi_mem_check_buswidth()
152 if (op->dummy.nbytes && in spi_mem_check_buswidth()
153 spi_check_buswidth_req(mem, op->dummy.buswidth, true)) in spi_mem_check_buswidth()
156 if (op->data.dir != SPI_MEM_NO_DATA && in spi_mem_check_buswidth()
157 spi_check_buswidth_req(mem, op->data.buswidth, in spi_mem_check_buswidth()
158 op->data.dir == SPI_MEM_DATA_OUT)) in spi_mem_check_buswidth()
164 bool spi_mem_default_supports_op(struct spi_mem *mem, in spi_mem_default_supports_op() argument
167 struct spi_controller *ctlr = mem->spi->controller; in spi_mem_default_supports_op()
169 op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr; in spi_mem_default_supports_op()
175 if (op->data.swap16 && !spi_mem_controller_is_capable(ctlr, swap16)) in spi_mem_default_supports_op()
178 if (op->cmd.nbytes != 2) in spi_mem_default_supports_op()
181 if (op->cmd.nbytes != 1) in spi_mem_default_supports_op()
185 if (op->data.ecc) { in spi_mem_default_supports_op()
190 if (op->max_freq && mem->spi->controller->min_speed_hz && in spi_mem_default_supports_op()
191 op->max_freq < mem->spi->controller->min_speed_hz) in spi_mem_default_supports_op()
194 if (op->max_freq && in spi_mem_default_supports_op()
195 op->max_freq < mem->spi->max_speed_hz) { in spi_mem_default_supports_op()
200 return spi_mem_check_buswidth(mem, op); in spi_mem_default_supports_op()
214 if (!op->cmd.buswidth || !op->cmd.nbytes) in spi_mem_check_op()
215 return -EINVAL; in spi_mem_check_op()
217 if ((op->addr.nbytes && !op->addr.buswidth) || in spi_mem_check_op()
218 (op->dummy.nbytes && !op->dummy.buswidth) || in spi_mem_check_op()
219 (op->data.nbytes && !op->data.buswidth)) in spi_mem_check_op()
220 return -EINVAL; in spi_mem_check_op()
222 if (!spi_mem_buswidth_is_valid(op->cmd.buswidth) || in spi_mem_check_op()
223 !spi_mem_buswidth_is_valid(op->addr.buswidth) || in spi_mem_check_op()
224 !spi_mem_buswidth_is_valid(op->dummy.buswidth) || in spi_mem_check_op()
225 !spi_mem_buswidth_is_valid(op->data.buswidth)) in spi_mem_check_op()
226 return -EINVAL; in spi_mem_check_op()
228 /* Buffers must be DMA-able. */ in spi_mem_check_op()
229 if (WARN_ON_ONCE(op->data.dir == SPI_MEM_DATA_IN && in spi_mem_check_op()
230 object_is_on_stack(op->data.buf.in))) in spi_mem_check_op()
231 return -EINVAL; in spi_mem_check_op()
233 if (WARN_ON_ONCE(op->data.dir == SPI_MEM_DATA_OUT && in spi_mem_check_op()
234 object_is_on_stack(op->data.buf.out))) in spi_mem_check_op()
235 return -EINVAL; in spi_mem_check_op()
240 static bool spi_mem_internal_supports_op(struct spi_mem *mem, in spi_mem_internal_supports_op() argument
243 struct spi_controller *ctlr = mem->spi->controller; in spi_mem_internal_supports_op()
245 if (ctlr->mem_ops && ctlr->mem_ops->supports_op) in spi_mem_internal_supports_op()
246 return ctlr->mem_ops->supports_op(mem, op); in spi_mem_internal_supports_op()
248 return spi_mem_default_supports_op(mem, op); in spi_mem_internal_supports_op()
252 * spi_mem_supports_op() - Check if a memory device and the controller it is
254 * @mem: the SPI memory
266 bool spi_mem_supports_op(struct spi_mem *mem, const struct spi_mem_op *op) in spi_mem_supports_op() argument
271 return spi_mem_internal_supports_op(mem, op); in spi_mem_supports_op()
275 static int spi_mem_access_start(struct spi_mem *mem) in spi_mem_access_start() argument
277 struct spi_controller *ctlr = mem->spi->controller; in spi_mem_access_start()
285 if (ctlr->auto_runtime_pm) { in spi_mem_access_start()
288 ret = pm_runtime_resume_and_get(ctlr->dev.parent); in spi_mem_access_start()
290 dev_err(&ctlr->dev, "Failed to power device: %d\n", in spi_mem_access_start()
296 mutex_lock(&ctlr->bus_lock_mutex); in spi_mem_access_start()
297 mutex_lock(&ctlr->io_mutex); in spi_mem_access_start()
302 static void spi_mem_access_end(struct spi_mem *mem) in spi_mem_access_end() argument
304 struct spi_controller *ctlr = mem->spi->controller; in spi_mem_access_end()
306 mutex_unlock(&ctlr->io_mutex); in spi_mem_access_end()
307 mutex_unlock(&ctlr->bus_lock_mutex); in spi_mem_access_end()
309 if (ctlr->auto_runtime_pm) in spi_mem_access_end()
310 pm_runtime_put(ctlr->dev.parent); in spi_mem_access_end()
321 u64_stats_update_begin(&stats->syncp); in spi_mem_add_op_stats()
327 u64_stats_inc(&stats->messages); in spi_mem_add_op_stats()
328 u64_stats_inc(&stats->transfers); in spi_mem_add_op_stats()
331 len = op->cmd.nbytes + op->addr.nbytes; in spi_mem_add_op_stats()
332 len += op->dummy.nbytes + op->data.nbytes; in spi_mem_add_op_stats()
333 u64_stats_add(&stats->bytes, len); in spi_mem_add_op_stats()
334 l2len = min(fls(len), SPI_STATISTICS_HISTO_SIZE) - 1; in spi_mem_add_op_stats()
335 u64_stats_inc(&stats->transfer_bytes_histo[l2len]); in spi_mem_add_op_stats()
338 if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_OUT) in spi_mem_add_op_stats()
339 u64_stats_add(&stats->bytes_tx, op->data.nbytes); in spi_mem_add_op_stats()
340 if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_IN) in spi_mem_add_op_stats()
341 u64_stats_add(&stats->bytes_rx, op->data.nbytes); in spi_mem_add_op_stats()
347 if (exec_op_ret == -ETIMEDOUT) in spi_mem_add_op_stats()
348 u64_stats_inc(&stats->timedout); in spi_mem_add_op_stats()
350 u64_stats_inc(&stats->errors); in spi_mem_add_op_stats()
352 u64_stats_update_end(&stats->syncp); in spi_mem_add_op_stats()
357 * spi_mem_exec_op() - Execute a memory operation
358 * @mem: the SPI memory
368 int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) in spi_mem_exec_op() argument
371 struct spi_controller *ctlr = mem->spi->controller; in spi_mem_exec_op()
378 spi_mem_adjust_op_freq(mem, (struct spi_mem_op *)op); in spi_mem_exec_op()
384 if (!spi_mem_internal_supports_op(mem, op)) in spi_mem_exec_op()
385 return -EOPNOTSUPP; in spi_mem_exec_op()
387 if (ctlr->mem_ops && ctlr->mem_ops->exec_op && !spi_get_csgpiod(mem->spi, 0)) { in spi_mem_exec_op()
388 ret = spi_mem_access_start(mem); in spi_mem_exec_op()
392 ret = ctlr->mem_ops->exec_op(mem, op); in spi_mem_exec_op()
394 spi_mem_access_end(mem); in spi_mem_exec_op()
401 if (!ret || (ret != -ENOTSUPP && ret != -EOPNOTSUPP)) { in spi_mem_exec_op()
402 spi_mem_add_op_stats(ctlr->pcpu_statistics, op, ret); in spi_mem_exec_op()
403 spi_mem_add_op_stats(mem->spi->pcpu_statistics, op, ret); in spi_mem_exec_op()
409 tmpbufsize = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes; in spi_mem_exec_op()
413 * we're guaranteed that this buffer is DMA-able, as required by the in spi_mem_exec_op()
418 return -ENOMEM; in spi_mem_exec_op()
422 tmpbuf[0] = op->cmd.opcode; in spi_mem_exec_op()
424 xfers[xferpos].len = op->cmd.nbytes; in spi_mem_exec_op()
425 xfers[xferpos].tx_nbits = op->cmd.buswidth; in spi_mem_exec_op()
426 xfers[xferpos].speed_hz = op->max_freq; in spi_mem_exec_op()
431 if (op->addr.nbytes) { in spi_mem_exec_op()
434 for (i = 0; i < op->addr.nbytes; i++) in spi_mem_exec_op()
435 tmpbuf[i + 1] = op->addr.val >> in spi_mem_exec_op()
436 (8 * (op->addr.nbytes - i - 1)); in spi_mem_exec_op()
439 xfers[xferpos].len = op->addr.nbytes; in spi_mem_exec_op()
440 xfers[xferpos].tx_nbits = op->addr.buswidth; in spi_mem_exec_op()
441 xfers[xferpos].speed_hz = op->max_freq; in spi_mem_exec_op()
444 totalxferlen += op->addr.nbytes; in spi_mem_exec_op()
447 if (op->dummy.nbytes) { in spi_mem_exec_op()
448 memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes); in spi_mem_exec_op()
449 xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1; in spi_mem_exec_op()
450 xfers[xferpos].len = op->dummy.nbytes; in spi_mem_exec_op()
451 xfers[xferpos].tx_nbits = op->dummy.buswidth; in spi_mem_exec_op()
453 xfers[xferpos].speed_hz = op->max_freq; in spi_mem_exec_op()
456 totalxferlen += op->dummy.nbytes; in spi_mem_exec_op()
459 if (op->data.nbytes) { in spi_mem_exec_op()
460 if (op->data.dir == SPI_MEM_DATA_IN) { in spi_mem_exec_op()
461 xfers[xferpos].rx_buf = op->data.buf.in; in spi_mem_exec_op()
462 xfers[xferpos].rx_nbits = op->data.buswidth; in spi_mem_exec_op()
464 xfers[xferpos].tx_buf = op->data.buf.out; in spi_mem_exec_op()
465 xfers[xferpos].tx_nbits = op->data.buswidth; in spi_mem_exec_op()
468 xfers[xferpos].len = op->data.nbytes; in spi_mem_exec_op()
469 xfers[xferpos].speed_hz = op->max_freq; in spi_mem_exec_op()
472 totalxferlen += op->data.nbytes; in spi_mem_exec_op()
475 ret = spi_sync(mem->spi, &msg); in spi_mem_exec_op()
483 return -EIO; in spi_mem_exec_op()
490 * spi_mem_get_name() - Return the SPI mem device name to be used by the
492 * @mem: the SPI memory
494 * This function allows SPI mem users to retrieve the SPI mem device name.
499 * by the SPI mem user
501 const char *spi_mem_get_name(struct spi_mem *mem) in spi_mem_get_name() argument
503 return mem->name; in spi_mem_get_name()
508 * spi_mem_adjust_op_size() - Adjust the data size of a SPI mem operation to
510 * @mem: the SPI memory
515 * optimized accesses. This function allows SPI mem drivers to split a single
516 * operation into multiple sub-operations when required.
519 * 0 otherwise. Note that @op->data.nbytes will be updated if @op
522 int spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op) in spi_mem_adjust_op_size() argument
524 struct spi_controller *ctlr = mem->spi->controller; in spi_mem_adjust_op_size()
527 if (ctlr->mem_ops && ctlr->mem_ops->adjust_op_size) in spi_mem_adjust_op_size()
528 return ctlr->mem_ops->adjust_op_size(mem, op); in spi_mem_adjust_op_size()
530 if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op) { in spi_mem_adjust_op_size()
531 len = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes; in spi_mem_adjust_op_size()
533 if (len > spi_max_transfer_size(mem->spi)) in spi_mem_adjust_op_size()
534 return -EINVAL; in spi_mem_adjust_op_size()
536 op->data.nbytes = min3((size_t)op->data.nbytes, in spi_mem_adjust_op_size()
537 spi_max_transfer_size(mem->spi), in spi_mem_adjust_op_size()
538 spi_max_message_size(mem->spi) - in spi_mem_adjust_op_size()
540 if (!op->data.nbytes) in spi_mem_adjust_op_size()
541 return -EINVAL; in spi_mem_adjust_op_size()
549 * spi_mem_adjust_op_freq() - Adjust the frequency of a SPI mem operation to
551 * @mem: the SPI memory
554 * Some chips have per-op frequency limitations and must adapt the maximum
555 * speed. This function allows SPI mem drivers to set @op->max_freq to the
558 void spi_mem_adjust_op_freq(struct spi_mem *mem, struct spi_mem_op *op) in spi_mem_adjust_op_freq() argument
560 if (!op->max_freq || op->max_freq > mem->spi->max_speed_hz) in spi_mem_adjust_op_freq()
561 op->max_freq = mem->spi->max_speed_hz; in spi_mem_adjust_op_freq()
566 * spi_mem_calc_op_duration() - Derives the theoretical length (in ns) of an
571 * Some chips have per-op frequency limitations, PCBs usually have their own
585 ns_per_cycles = 1000000000 / op->max_freq; in spi_mem_calc_op_duration()
586 ncycles += ((op->cmd.nbytes * 8) / op->cmd.buswidth) / (op->cmd.dtr ? 2 : 1); in spi_mem_calc_op_duration()
587 ncycles += ((op->addr.nbytes * 8) / op->addr.buswidth) / (op->addr.dtr ? 2 : 1); in spi_mem_calc_op_duration()
588 ncycles += ((op->dummy.nbytes * 8) / op->dummy.buswidth) / (op->dummy.dtr ? 2 : 1); in spi_mem_calc_op_duration()
589 ncycles += ((op->data.nbytes * 8) / op->data.buswidth) / (op->data.dtr ? 2 : 1); in spi_mem_calc_op_duration()
598 struct spi_mem_op op = desc->info.op_tmpl; in spi_mem_no_dirmap_read()
601 op.addr.val = desc->info.offset + offs; in spi_mem_no_dirmap_read()
604 ret = spi_mem_adjust_op_size(desc->mem, &op); in spi_mem_no_dirmap_read()
608 ret = spi_mem_exec_op(desc->mem, &op); in spi_mem_no_dirmap_read()
618 struct spi_mem_op op = desc->info.op_tmpl; in spi_mem_no_dirmap_write()
621 op.addr.val = desc->info.offset + offs; in spi_mem_no_dirmap_write()
624 ret = spi_mem_adjust_op_size(desc->mem, &op); in spi_mem_no_dirmap_write()
628 ret = spi_mem_exec_op(desc->mem, &op); in spi_mem_no_dirmap_write()
636 * spi_mem_dirmap_create() - Create a direct mapping descriptor
637 * @mem: SPI mem device this direct mapping should be created for
649 spi_mem_dirmap_create(struct spi_mem *mem, in spi_mem_dirmap_create() argument
652 struct spi_controller *ctlr = mem->spi->controller; in spi_mem_dirmap_create()
654 int ret = -ENOTSUPP; in spi_mem_dirmap_create()
657 if (!info->op_tmpl.addr.nbytes || info->op_tmpl.addr.nbytes > 8) in spi_mem_dirmap_create()
658 return ERR_PTR(-EINVAL); in spi_mem_dirmap_create()
661 if (info->op_tmpl.data.dir == SPI_MEM_NO_DATA) in spi_mem_dirmap_create()
662 return ERR_PTR(-EINVAL); in spi_mem_dirmap_create()
666 return ERR_PTR(-ENOMEM); in spi_mem_dirmap_create()
668 desc->mem = mem; in spi_mem_dirmap_create()
669 desc->info = *info; in spi_mem_dirmap_create()
670 if (ctlr->mem_ops && ctlr->mem_ops->dirmap_create) in spi_mem_dirmap_create()
671 ret = ctlr->mem_ops->dirmap_create(desc); in spi_mem_dirmap_create()
674 desc->nodirmap = true; in spi_mem_dirmap_create()
675 if (!spi_mem_supports_op(desc->mem, &desc->info.op_tmpl)) in spi_mem_dirmap_create()
676 ret = -EOPNOTSUPP; in spi_mem_dirmap_create()
691 * spi_mem_dirmap_destroy() - Destroy a direct mapping descriptor
699 struct spi_controller *ctlr = desc->mem->spi->controller; in spi_mem_dirmap_destroy()
701 if (!desc->nodirmap && ctlr->mem_ops && ctlr->mem_ops->dirmap_destroy) in spi_mem_dirmap_destroy()
702 ctlr->mem_ops->dirmap_destroy(desc); in spi_mem_dirmap_destroy()
716 * devm_spi_mem_dirmap_create() - Create a direct mapping descriptor and attach
719 * @mem: SPI mem device this direct mapping should be created for
728 devm_spi_mem_dirmap_create(struct device *dev, struct spi_mem *mem, in devm_spi_mem_dirmap_create() argument
736 return ERR_PTR(-ENOMEM); in devm_spi_mem_dirmap_create()
738 desc = spi_mem_dirmap_create(mem, info); in devm_spi_mem_dirmap_create()
761 * devm_spi_mem_dirmap_destroy() - Destroy a direct mapping descriptor attached
778 * spi_mem_dirmap_read() - Read data through a direct mapping
784 * @buf: destination buffer. This buffer must be DMA-able
796 struct spi_controller *ctlr = desc->mem->spi->controller; in spi_mem_dirmap_read()
799 if (desc->info.op_tmpl.data.dir != SPI_MEM_DATA_IN) in spi_mem_dirmap_read()
800 return -EINVAL; in spi_mem_dirmap_read()
805 if (desc->nodirmap) { in spi_mem_dirmap_read()
807 } else if (ctlr->mem_ops && ctlr->mem_ops->dirmap_read) { in spi_mem_dirmap_read()
808 ret = spi_mem_access_start(desc->mem); in spi_mem_dirmap_read()
812 ret = ctlr->mem_ops->dirmap_read(desc, offs, len, buf); in spi_mem_dirmap_read()
814 spi_mem_access_end(desc->mem); in spi_mem_dirmap_read()
816 ret = -ENOTSUPP; in spi_mem_dirmap_read()
824 * spi_mem_dirmap_write() - Write data through a direct mapping
830 * @buf: source buffer. This buffer must be DMA-able
842 struct spi_controller *ctlr = desc->mem->spi->controller; in spi_mem_dirmap_write()
845 if (desc->info.op_tmpl.data.dir != SPI_MEM_DATA_OUT) in spi_mem_dirmap_write()
846 return -EINVAL; in spi_mem_dirmap_write()
851 if (desc->nodirmap) { in spi_mem_dirmap_write()
853 } else if (ctlr->mem_ops && ctlr->mem_ops->dirmap_write) { in spi_mem_dirmap_write()
854 ret = spi_mem_access_start(desc->mem); in spi_mem_dirmap_write()
858 ret = ctlr->mem_ops->dirmap_write(desc, offs, len, buf); in spi_mem_dirmap_write()
860 spi_mem_access_end(desc->mem); in spi_mem_dirmap_write()
862 ret = -ENOTSUPP; in spi_mem_dirmap_write()
874 static int spi_mem_read_status(struct spi_mem *mem, in spi_mem_read_status() argument
878 const u8 *bytes = (u8 *)op->data.buf.in; in spi_mem_read_status()
881 ret = spi_mem_exec_op(mem, op); in spi_mem_read_status()
885 if (op->data.nbytes > 1) in spi_mem_read_status()
894 * spi_mem_poll_status() - Poll memory device status
895 * @mem: SPI memory device
906 * Return: 0 in case of success, -ETIMEDOUT in case of error,
907 * -EOPNOTSUPP if not supported.
909 int spi_mem_poll_status(struct spi_mem *mem, in spi_mem_poll_status() argument
916 struct spi_controller *ctlr = mem->spi->controller; in spi_mem_poll_status()
917 int ret = -EOPNOTSUPP; in spi_mem_poll_status()
921 if (op->data.nbytes < 1 || op->data.nbytes > 2 || in spi_mem_poll_status()
922 op->data.dir != SPI_MEM_DATA_IN) in spi_mem_poll_status()
923 return -EINVAL; in spi_mem_poll_status()
925 if (ctlr->mem_ops && ctlr->mem_ops->poll_status && !spi_get_csgpiod(mem->spi, 0)) { in spi_mem_poll_status()
926 ret = spi_mem_access_start(mem); in spi_mem_poll_status()
930 ret = ctlr->mem_ops->poll_status(mem, op, mask, match, in spi_mem_poll_status()
934 spi_mem_access_end(mem); in spi_mem_poll_status()
937 if (ret == -EOPNOTSUPP) { in spi_mem_poll_status()
938 if (!spi_mem_supports_op(mem, op)) in spi_mem_poll_status()
949 polling_delay_us, timeout_ms * 1000, false, mem, in spi_mem_poll_status()
961 struct spi_mem_driver *memdrv = to_spi_mem_drv(spi->dev.driver); in spi_mem_probe()
962 struct spi_controller *ctlr = spi->controller; in spi_mem_probe()
963 struct spi_mem *mem; in spi_mem_probe() local
965 mem = devm_kzalloc(&spi->dev, sizeof(*mem), GFP_KERNEL); in spi_mem_probe()
966 if (!mem) in spi_mem_probe()
967 return -ENOMEM; in spi_mem_probe()
969 mem->spi = spi; in spi_mem_probe()
971 if (ctlr->mem_ops && ctlr->mem_ops->get_name) in spi_mem_probe()
972 mem->name = ctlr->mem_ops->get_name(mem); in spi_mem_probe()
974 mem->name = dev_name(&spi->dev); in spi_mem_probe()
976 if (IS_ERR_OR_NULL(mem->name)) in spi_mem_probe()
977 return PTR_ERR_OR_ZERO(mem->name); in spi_mem_probe()
979 spi_set_drvdata(spi, mem); in spi_mem_probe()
981 return memdrv->probe(mem); in spi_mem_probe()
986 struct spi_mem_driver *memdrv = to_spi_mem_drv(spi->dev.driver); in spi_mem_remove()
987 struct spi_mem *mem = spi_get_drvdata(spi); in spi_mem_remove() local
989 if (memdrv->remove) in spi_mem_remove()
990 memdrv->remove(mem); in spi_mem_remove()
995 struct spi_mem_driver *memdrv = to_spi_mem_drv(spi->dev.driver); in spi_mem_shutdown()
996 struct spi_mem *mem = spi_get_drvdata(spi); in spi_mem_shutdown() local
998 if (memdrv->shutdown) in spi_mem_shutdown()
999 memdrv->shutdown(mem); in spi_mem_shutdown()
1003 * spi_mem_driver_register_with_owner() - Register a SPI memory driver
1015 memdrv->spidrv.probe = spi_mem_probe; in spi_mem_driver_register_with_owner()
1016 memdrv->spidrv.remove = spi_mem_remove; in spi_mem_driver_register_with_owner()
1017 memdrv->spidrv.shutdown = spi_mem_shutdown; in spi_mem_driver_register_with_owner()
1019 return __spi_register_driver(owner, &memdrv->spidrv); in spi_mem_driver_register_with_owner()
1024 * spi_mem_driver_unregister() - Unregister a SPI memory driver
1031 spi_unregister_driver(&memdrv->spidrv); in spi_mem_driver_unregister()