Lines Matching +full:spi +full:- +full:device
1 // SPDX-License-Identifier: GPL-2.0+
11 #include <linux/spi/spi.h>
12 #include <linux/spi/spi-mem.h>
20 * spi_controller_dma_map_mem_op_data() - DMA-map the buffer attached to a
22 * @ctlr: the SPI controller requesting this dma_map()
24 * @sgt: a pointer to a non-initialized sg_table that will be filled by this
28 * This helper prepares everything for you and provides a ready-to-use
29 * sg_table. This function is not intended to be called from spi drivers.
30 * Only SPI controller drivers should use it.
32 * op->data.buf.{in,out} is DMA-able before calling this function.
40 struct device *dmadev; in spi_controller_dma_map_mem_op_data()
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
64 * @ctlr: the SPI controller requesting this dma_unmap()
71 * op->data.buf.{in,out} buffer again.
73 * This function is not intended to be called from SPI drivers. Only SPI
86 struct device *dmadev; in spi_controller_dma_unmap_mem_op_data()
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()
106 u32 mode = mem->spi->mode; in spi_check_buswidth_req()
139 return -ENOTSUPP; in spi_check_buswidth_req()
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()
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()
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()
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()
252 * spi_mem_supports_op() - Check if a memory device and the controller it is
254 * @mem: the SPI memory
258 * support specific opcodes, or it can even be that the controller and device
277 struct spi_controller *ctlr = mem->spi->controller; in spi_mem_access_start()
280 * Flush the message queue before executing our SPI memory in spi_mem_access_start()
281 * operation to prevent preemption of regular SPI transfers. 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()
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
371 struct spi_controller *ctlr = mem->spi->controller; in spi_mem_exec_op()
380 …dev_vdbg(&mem->spi->dev, "[cmd: 0x%02x][%dB addr: %#8llx][%2dB dummy][%4dB data %s] %d%c-%d%c-%d%c… in spi_mem_exec_op()
381 op->cmd.opcode, in spi_mem_exec_op()
382 op->addr.nbytes, (op->addr.nbytes ? op->addr.val : 0), in spi_mem_exec_op()
383 op->dummy.nbytes, in spi_mem_exec_op()
384 …op->data.nbytes, (op->data.nbytes ? (op->data.dir == SPI_MEM_DATA_IN ? " read" : "write") : " … in spi_mem_exec_op()
385 op->cmd.buswidth, op->cmd.dtr ? 'D' : 'S', in spi_mem_exec_op()
386 op->addr.buswidth, op->addr.dtr ? 'D' : 'S', in spi_mem_exec_op()
387 op->dummy.buswidth, op->dummy.dtr ? 'D' : 'S', in spi_mem_exec_op()
388 op->data.buswidth, op->data.dtr ? 'D' : 'S', in spi_mem_exec_op()
389 op->max_freq ? op->max_freq : mem->spi->max_speed_hz); in spi_mem_exec_op()
396 return -EOPNOTSUPP; in spi_mem_exec_op()
398 if (ctlr->mem_ops && ctlr->mem_ops->exec_op && !spi_get_csgpiod(mem->spi, 0)) { in spi_mem_exec_op()
403 ret = ctlr->mem_ops->exec_op(mem, op); in spi_mem_exec_op()
409 * read path) and expect the core to use the regular SPI in spi_mem_exec_op()
412 if (!ret || (ret != -ENOTSUPP && ret != -EOPNOTSUPP)) { in spi_mem_exec_op()
413 spi_mem_add_op_stats(ctlr->pcpu_statistics, op, ret); in spi_mem_exec_op()
414 spi_mem_add_op_stats(mem->spi->pcpu_statistics, op, ret); in spi_mem_exec_op()
420 tmpbufsize = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes; in spi_mem_exec_op()
424 * we're guaranteed that this buffer is DMA-able, as required by the in spi_mem_exec_op()
425 * SPI layer. in spi_mem_exec_op()
429 return -ENOMEM; in spi_mem_exec_op()
433 tmpbuf[0] = op->cmd.opcode; in spi_mem_exec_op()
435 xfers[xferpos].len = op->cmd.nbytes; in spi_mem_exec_op()
436 xfers[xferpos].tx_nbits = op->cmd.buswidth; in spi_mem_exec_op()
437 xfers[xferpos].speed_hz = op->max_freq; in spi_mem_exec_op()
442 if (op->addr.nbytes) { in spi_mem_exec_op()
445 for (i = 0; i < op->addr.nbytes; i++) in spi_mem_exec_op()
446 tmpbuf[i + 1] = op->addr.val >> in spi_mem_exec_op()
447 (8 * (op->addr.nbytes - i - 1)); in spi_mem_exec_op()
450 xfers[xferpos].len = op->addr.nbytes; in spi_mem_exec_op()
451 xfers[xferpos].tx_nbits = op->addr.buswidth; in spi_mem_exec_op()
452 xfers[xferpos].speed_hz = op->max_freq; in spi_mem_exec_op()
455 totalxferlen += op->addr.nbytes; in spi_mem_exec_op()
458 if (op->dummy.nbytes) { in spi_mem_exec_op()
459 memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes); in spi_mem_exec_op()
460 xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1; in spi_mem_exec_op()
461 xfers[xferpos].len = op->dummy.nbytes; in spi_mem_exec_op()
462 xfers[xferpos].tx_nbits = op->dummy.buswidth; in spi_mem_exec_op()
464 xfers[xferpos].speed_hz = op->max_freq; in spi_mem_exec_op()
467 totalxferlen += op->dummy.nbytes; in spi_mem_exec_op()
470 if (op->data.nbytes) { in spi_mem_exec_op()
471 if (op->data.dir == SPI_MEM_DATA_IN) { in spi_mem_exec_op()
472 xfers[xferpos].rx_buf = op->data.buf.in; in spi_mem_exec_op()
473 xfers[xferpos].rx_nbits = op->data.buswidth; in spi_mem_exec_op()
475 xfers[xferpos].tx_buf = op->data.buf.out; in spi_mem_exec_op()
476 xfers[xferpos].tx_nbits = op->data.buswidth; in spi_mem_exec_op()
479 xfers[xferpos].len = op->data.nbytes; in spi_mem_exec_op()
480 xfers[xferpos].speed_hz = op->max_freq; in spi_mem_exec_op()
483 totalxferlen += op->data.nbytes; in spi_mem_exec_op()
486 ret = spi_sync(mem->spi, &msg); in spi_mem_exec_op()
494 return -EIO; in spi_mem_exec_op()
501 * spi_mem_get_name() - Return the SPI mem device name to be used by the
503 * @mem: the SPI memory
505 * This function allows SPI mem users to retrieve the SPI mem device name.
509 * Return: a string containing the name of the memory device to be used
510 * by the SPI mem user
514 return mem->name; in spi_mem_get_name()
519 * spi_mem_adjust_op_size() - Adjust the data size of a SPI mem operation to
521 * @mem: the SPI memory
526 * optimized accesses. This function allows SPI mem drivers to split a single
527 * operation into multiple sub-operations when required.
530 * 0 otherwise. Note that @op->data.nbytes will be updated if @op
535 struct spi_controller *ctlr = mem->spi->controller; in spi_mem_adjust_op_size()
538 if (ctlr->mem_ops && ctlr->mem_ops->adjust_op_size) in spi_mem_adjust_op_size()
539 return ctlr->mem_ops->adjust_op_size(mem, op); in spi_mem_adjust_op_size()
541 if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op) { in spi_mem_adjust_op_size()
542 len = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes; in spi_mem_adjust_op_size()
544 if (len > spi_max_transfer_size(mem->spi)) in spi_mem_adjust_op_size()
545 return -EINVAL; in spi_mem_adjust_op_size()
547 op->data.nbytes = min3((size_t)op->data.nbytes, in spi_mem_adjust_op_size()
548 spi_max_transfer_size(mem->spi), in spi_mem_adjust_op_size()
549 spi_max_message_size(mem->spi) - in spi_mem_adjust_op_size()
551 if (!op->data.nbytes) in spi_mem_adjust_op_size()
552 return -EINVAL; in spi_mem_adjust_op_size()
560 * spi_mem_adjust_op_freq() - Adjust the frequency of a SPI mem operation to
562 * @mem: the SPI memory
565 * Some chips have per-op frequency limitations and must adapt the maximum
566 * speed. This function allows SPI mem drivers to set @op->max_freq to the
571 if (!op->max_freq || op->max_freq > mem->spi->max_speed_hz) in spi_mem_adjust_op_freq()
572 op->max_freq = mem->spi->max_speed_hz; in spi_mem_adjust_op_freq()
577 * spi_mem_calc_op_duration() - Derives the theoretical length (in ns) of an
582 * Some chips have per-op frequency limitations, PCBs usually have their own
596 ns_per_cycles = 1000000000 / op->max_freq; in spi_mem_calc_op_duration()
597 ncycles += ((op->cmd.nbytes * 8) / op->cmd.buswidth) / (op->cmd.dtr ? 2 : 1); in spi_mem_calc_op_duration()
598 ncycles += ((op->addr.nbytes * 8) / op->addr.buswidth) / (op->addr.dtr ? 2 : 1); in spi_mem_calc_op_duration()
600 /* Dummy bytes are optional for some SPI flash memory operations */ in spi_mem_calc_op_duration()
601 if (op->dummy.nbytes) in spi_mem_calc_op_duration()
602 ncycles += ((op->dummy.nbytes * 8) / op->dummy.buswidth) / (op->dummy.dtr ? 2 : 1); in spi_mem_calc_op_duration()
604 ncycles += ((op->data.nbytes * 8) / op->data.buswidth) / (op->data.dtr ? 2 : 1); in spi_mem_calc_op_duration()
613 struct spi_mem_op op = desc->info.op_tmpl; in spi_mem_no_dirmap_read()
616 op.addr.val = desc->info.offset + offs; in spi_mem_no_dirmap_read()
619 ret = spi_mem_adjust_op_size(desc->mem, &op); in spi_mem_no_dirmap_read()
623 ret = spi_mem_exec_op(desc->mem, &op); in spi_mem_no_dirmap_read()
633 struct spi_mem_op op = desc->info.op_tmpl; in spi_mem_no_dirmap_write()
636 op.addr.val = desc->info.offset + offs; in spi_mem_no_dirmap_write()
639 ret = spi_mem_adjust_op_size(desc->mem, &op); in spi_mem_no_dirmap_write()
643 ret = spi_mem_exec_op(desc->mem, &op); in spi_mem_no_dirmap_write()
651 * spi_mem_dirmap_create() - Create a direct mapping descriptor
652 * @mem: SPI mem device this direct mapping should be created for
657 * If the SPI controller driver does not support direct mapping, this function
667 struct spi_controller *ctlr = mem->spi->controller; in spi_mem_dirmap_create()
669 int ret = -ENOTSUPP; in spi_mem_dirmap_create()
672 if (!info->op_tmpl.addr.nbytes || info->op_tmpl.addr.nbytes > 8) in spi_mem_dirmap_create()
673 return ERR_PTR(-EINVAL); in spi_mem_dirmap_create()
676 if (info->op_tmpl.data.dir == SPI_MEM_NO_DATA) in spi_mem_dirmap_create()
677 return ERR_PTR(-EINVAL); in spi_mem_dirmap_create()
681 return ERR_PTR(-ENOMEM); in spi_mem_dirmap_create()
683 desc->mem = mem; in spi_mem_dirmap_create()
684 desc->info = *info; in spi_mem_dirmap_create()
685 if (ctlr->mem_ops && ctlr->mem_ops->dirmap_create) in spi_mem_dirmap_create()
686 ret = ctlr->mem_ops->dirmap_create(desc); in spi_mem_dirmap_create()
689 desc->nodirmap = true; in spi_mem_dirmap_create()
690 if (!spi_mem_supports_op(desc->mem, &desc->info.op_tmpl)) in spi_mem_dirmap_create()
691 ret = -EOPNOTSUPP; in spi_mem_dirmap_create()
706 * spi_mem_dirmap_destroy() - Destroy a direct mapping descriptor
714 struct spi_controller *ctlr = desc->mem->spi->controller; in spi_mem_dirmap_destroy()
716 if (!desc->nodirmap && ctlr->mem_ops && ctlr->mem_ops->dirmap_destroy) in spi_mem_dirmap_destroy()
717 ctlr->mem_ops->dirmap_destroy(desc); in spi_mem_dirmap_destroy()
723 static void devm_spi_mem_dirmap_release(struct device *dev, void *res) in devm_spi_mem_dirmap_release()
731 * devm_spi_mem_dirmap_create() - Create a direct mapping descriptor and attach
732 * it to a device
733 * @dev: device the dirmap desc will be attached to
734 * @mem: SPI mem device this direct mapping should be created for
743 devm_spi_mem_dirmap_create(struct device *dev, struct spi_mem *mem, in devm_spi_mem_dirmap_create()
751 return ERR_PTR(-ENOMEM); in devm_spi_mem_dirmap_create()
765 static int devm_spi_mem_dirmap_match(struct device *dev, void *res, void *data) in devm_spi_mem_dirmap_match()
776 * devm_spi_mem_dirmap_destroy() - Destroy a direct mapping descriptor attached
777 * to a device
778 * @dev: device the dirmap desc is attached to
784 void devm_spi_mem_dirmap_destroy(struct device *dev, in devm_spi_mem_dirmap_destroy()
793 * spi_mem_dirmap_read() - Read data through a direct mapping
799 * @buf: destination buffer. This buffer must be DMA-able
801 * This function reads data from a memory device using a direct mapping
804 * Return: the amount of data read from the memory device or a negative error
811 struct spi_controller *ctlr = desc->mem->spi->controller; in spi_mem_dirmap_read()
814 if (desc->info.op_tmpl.data.dir != SPI_MEM_DATA_IN) in spi_mem_dirmap_read()
815 return -EINVAL; in spi_mem_dirmap_read()
820 if (desc->nodirmap) { in spi_mem_dirmap_read()
822 } else if (ctlr->mem_ops && ctlr->mem_ops->dirmap_read) { in spi_mem_dirmap_read()
823 ret = spi_mem_access_start(desc->mem); in spi_mem_dirmap_read()
827 ret = ctlr->mem_ops->dirmap_read(desc, offs, len, buf); in spi_mem_dirmap_read()
829 spi_mem_access_end(desc->mem); in spi_mem_dirmap_read()
831 ret = -ENOTSUPP; in spi_mem_dirmap_read()
839 * spi_mem_dirmap_write() - Write data through a direct mapping
845 * @buf: source buffer. This buffer must be DMA-able
847 * This function writes data to a memory device using a direct mapping
850 * Return: the amount of data written to the memory device or a negative error
857 struct spi_controller *ctlr = desc->mem->spi->controller; in spi_mem_dirmap_write()
860 if (desc->info.op_tmpl.data.dir != SPI_MEM_DATA_OUT) in spi_mem_dirmap_write()
861 return -EINVAL; in spi_mem_dirmap_write()
866 if (desc->nodirmap) { in spi_mem_dirmap_write()
868 } else if (ctlr->mem_ops && ctlr->mem_ops->dirmap_write) { in spi_mem_dirmap_write()
869 ret = spi_mem_access_start(desc->mem); in spi_mem_dirmap_write()
873 ret = ctlr->mem_ops->dirmap_write(desc, offs, len, buf); in spi_mem_dirmap_write()
875 spi_mem_access_end(desc->mem); in spi_mem_dirmap_write()
877 ret = -ENOTSUPP; in spi_mem_dirmap_write()
893 const u8 *bytes = (u8 *)op->data.buf.in; in spi_mem_read_status()
900 if (op->data.nbytes > 1) in spi_mem_read_status()
909 * spi_mem_poll_status() - Poll memory device status
910 * @mem: SPI memory device
921 * Return: 0 in case of success, -ETIMEDOUT in case of error,
922 * -EOPNOTSUPP if not supported.
931 struct spi_controller *ctlr = mem->spi->controller; in spi_mem_poll_status()
932 int ret = -EOPNOTSUPP; in spi_mem_poll_status()
936 if (op->data.nbytes < 1 || op->data.nbytes > 2 || in spi_mem_poll_status()
937 op->data.dir != SPI_MEM_DATA_IN) in spi_mem_poll_status()
938 return -EINVAL; in spi_mem_poll_status()
940 if (ctlr->mem_ops && ctlr->mem_ops->poll_status && !spi_get_csgpiod(mem->spi, 0)) { in spi_mem_poll_status()
945 ret = ctlr->mem_ops->poll_status(mem, op, mask, match, in spi_mem_poll_status()
952 if (ret == -EOPNOTSUPP) { in spi_mem_poll_status()
974 static int spi_mem_probe(struct spi_device *spi) in spi_mem_probe() argument
976 struct spi_mem_driver *memdrv = to_spi_mem_drv(spi->dev.driver); in spi_mem_probe()
977 struct spi_controller *ctlr = spi->controller; in spi_mem_probe()
980 mem = devm_kzalloc(&spi->dev, sizeof(*mem), GFP_KERNEL); in spi_mem_probe()
982 return -ENOMEM; in spi_mem_probe()
984 mem->spi = spi; in spi_mem_probe()
986 if (ctlr->mem_ops && ctlr->mem_ops->get_name) in spi_mem_probe()
987 mem->name = ctlr->mem_ops->get_name(mem); in spi_mem_probe()
989 mem->name = dev_name(&spi->dev); in spi_mem_probe()
991 if (IS_ERR_OR_NULL(mem->name)) in spi_mem_probe()
992 return PTR_ERR_OR_ZERO(mem->name); in spi_mem_probe()
994 spi_set_drvdata(spi, mem); in spi_mem_probe()
996 return memdrv->probe(mem); in spi_mem_probe()
999 static void spi_mem_remove(struct spi_device *spi) in spi_mem_remove() argument
1001 struct spi_mem_driver *memdrv = to_spi_mem_drv(spi->dev.driver); in spi_mem_remove()
1002 struct spi_mem *mem = spi_get_drvdata(spi); in spi_mem_remove()
1004 if (memdrv->remove) in spi_mem_remove()
1005 memdrv->remove(mem); in spi_mem_remove()
1008 static void spi_mem_shutdown(struct spi_device *spi) in spi_mem_shutdown() argument
1010 struct spi_mem_driver *memdrv = to_spi_mem_drv(spi->dev.driver); in spi_mem_shutdown()
1011 struct spi_mem *mem = spi_get_drvdata(spi); in spi_mem_shutdown()
1013 if (memdrv->shutdown) in spi_mem_shutdown()
1014 memdrv->shutdown(mem); in spi_mem_shutdown()
1018 * spi_mem_driver_register_with_owner() - Register a SPI memory driver
1019 * @memdrv: the SPI memory driver to register
1022 * Registers a SPI memory driver.
1030 memdrv->spidrv.probe = spi_mem_probe; in spi_mem_driver_register_with_owner()
1031 memdrv->spidrv.remove = spi_mem_remove; in spi_mem_driver_register_with_owner()
1032 memdrv->spidrv.shutdown = spi_mem_shutdown; in spi_mem_driver_register_with_owner()
1034 return __spi_register_driver(owner, &memdrv->spidrv); in spi_mem_driver_register_with_owner()
1039 * spi_mem_driver_unregister() - Unregister a SPI memory driver
1040 * @memdrv: the SPI memory driver to unregister
1042 * Unregisters a SPI memory driver.
1046 spi_unregister_driver(&memdrv->spidrv); in spi_mem_driver_unregister()