• Home
  • Raw
  • Download

Lines Matching refs:ctlr

119 	struct spi_controller *ctlr = container_of(dev,			\
121 return spi_statistics_##field##_show(&ctlr->statistics, buf); \
290 struct spi_controller *ctlr) in spi_statistics_add_transfer_stats() argument
305 (xfer->tx_buf != ctlr->dummy_tx)) in spi_statistics_add_transfer_stats()
308 (xfer->rx_buf != ctlr->dummy_rx)) in spi_statistics_add_transfer_stats()
498 struct spi_device *spi_alloc_device(struct spi_controller *ctlr) in spi_alloc_device() argument
502 if (!spi_controller_get(ctlr)) in spi_alloc_device()
507 spi_controller_put(ctlr); in spi_alloc_device()
511 spi->master = spi->controller = ctlr; in spi_alloc_device()
512 spi->dev.parent = &ctlr->dev; in spi_alloc_device()
516 spi->mode = ctlr->buswidth_override_bits; in spi_alloc_device()
566 struct spi_controller *ctlr = spi->controller; in spi_add_device() local
567 struct device *dev = ctlr->dev.parent; in spi_add_device()
571 if (spi->chip_select >= ctlr->num_chipselect) { in spi_add_device()
573 ctlr->num_chipselect); in spi_add_device()
595 !device_is_registered(&ctlr->dev)) { in spi_add_device()
601 if (ctlr->cs_gpiods) in spi_add_device()
602 spi->cs_gpiod = ctlr->cs_gpiods[spi->chip_select]; in spi_add_device()
603 else if (ctlr->cs_gpios) in spi_add_device()
604 spi->cs_gpio = ctlr->cs_gpios[spi->chip_select]; in spi_add_device()
647 struct spi_device *spi_new_device(struct spi_controller *ctlr, in spi_new_device() argument
660 proxy = spi_alloc_device(ctlr); in spi_new_device()
678 dev_err(&ctlr->dev, in spi_new_device()
724 static void spi_match_controller_to_boardinfo(struct spi_controller *ctlr, in spi_match_controller_to_boardinfo() argument
729 if (ctlr->bus_num != bi->bus_num) in spi_match_controller_to_boardinfo()
732 dev = spi_new_device(ctlr, bi); in spi_match_controller_to_boardinfo()
734 dev_err(ctlr->dev.parent, "can't create new device for %s\n", in spi_match_controller_to_boardinfo()
773 struct spi_controller *ctlr; in spi_register_board_info() local
785 list_for_each_entry(ctlr, &spi_controller_list, list) in spi_register_board_info()
786 spi_match_controller_to_boardinfo(ctlr, in spi_register_board_info()
862 int spi_map_buf(struct spi_controller *ctlr, struct device *dev, in spi_map_buf() argument
887 desc_len = min_t(size_t, max_seg_size, ctlr->max_dma_len); in spi_map_buf()
943 void spi_unmap_buf(struct spi_controller *ctlr, struct device *dev, in spi_unmap_buf() argument
954 static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg) in __spi_map_msg() argument
960 if (!ctlr->can_dma) in __spi_map_msg()
963 if (ctlr->dma_tx) in __spi_map_msg()
964 tx_dev = ctlr->dma_tx->device->dev; in __spi_map_msg()
966 tx_dev = ctlr->dev.parent; in __spi_map_msg()
968 if (ctlr->dma_rx) in __spi_map_msg()
969 rx_dev = ctlr->dma_rx->device->dev; in __spi_map_msg()
971 rx_dev = ctlr->dev.parent; in __spi_map_msg()
974 if (!ctlr->can_dma(ctlr, msg->spi, xfer)) in __spi_map_msg()
978 ret = spi_map_buf(ctlr, tx_dev, &xfer->tx_sg, in __spi_map_msg()
986 ret = spi_map_buf(ctlr, rx_dev, &xfer->rx_sg, in __spi_map_msg()
990 spi_unmap_buf(ctlr, tx_dev, &xfer->tx_sg, in __spi_map_msg()
997 ctlr->cur_msg_mapped = true; in __spi_map_msg()
1002 static int __spi_unmap_msg(struct spi_controller *ctlr, struct spi_message *msg) in __spi_unmap_msg() argument
1007 if (!ctlr->cur_msg_mapped || !ctlr->can_dma) in __spi_unmap_msg()
1010 if (ctlr->dma_tx) in __spi_unmap_msg()
1011 tx_dev = ctlr->dma_tx->device->dev; in __spi_unmap_msg()
1013 tx_dev = ctlr->dev.parent; in __spi_unmap_msg()
1015 if (ctlr->dma_rx) in __spi_unmap_msg()
1016 rx_dev = ctlr->dma_rx->device->dev; in __spi_unmap_msg()
1018 rx_dev = ctlr->dev.parent; in __spi_unmap_msg()
1021 if (!ctlr->can_dma(ctlr, msg->spi, xfer)) in __spi_unmap_msg()
1024 spi_unmap_buf(ctlr, rx_dev, &xfer->rx_sg, DMA_FROM_DEVICE); in __spi_unmap_msg()
1025 spi_unmap_buf(ctlr, tx_dev, &xfer->tx_sg, DMA_TO_DEVICE); in __spi_unmap_msg()
1028 ctlr->cur_msg_mapped = false; in __spi_unmap_msg()
1033 static inline int __spi_map_msg(struct spi_controller *ctlr, in __spi_map_msg() argument
1039 static inline int __spi_unmap_msg(struct spi_controller *ctlr, in __spi_unmap_msg() argument
1046 static inline int spi_unmap_msg(struct spi_controller *ctlr, in spi_unmap_msg() argument
1056 if (xfer->tx_buf == ctlr->dummy_tx) in spi_unmap_msg()
1058 if (xfer->rx_buf == ctlr->dummy_rx) in spi_unmap_msg()
1062 return __spi_unmap_msg(ctlr, msg); in spi_unmap_msg()
1065 static int spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg) in spi_map_msg() argument
1071 if ((ctlr->flags & (SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX)) in spi_map_msg()
1077 if ((ctlr->flags & SPI_CONTROLLER_MUST_TX) && in spi_map_msg()
1080 if ((ctlr->flags & SPI_CONTROLLER_MUST_RX) && in spi_map_msg()
1086 tmp = krealloc(ctlr->dummy_tx, max_tx, in spi_map_msg()
1090 ctlr->dummy_tx = tmp; in spi_map_msg()
1095 tmp = krealloc(ctlr->dummy_rx, max_rx, in spi_map_msg()
1099 ctlr->dummy_rx = tmp; in spi_map_msg()
1108 xfer->tx_buf = ctlr->dummy_tx; in spi_map_msg()
1110 xfer->rx_buf = ctlr->dummy_rx; in spi_map_msg()
1115 return __spi_map_msg(ctlr, msg); in spi_map_msg()
1118 static int spi_transfer_wait(struct spi_controller *ctlr, in spi_transfer_wait() argument
1122 struct spi_statistics *statm = &ctlr->statistics; in spi_transfer_wait()
1127 if (spi_controller_is_slave(ctlr)) { in spi_transfer_wait()
1128 if (wait_for_completion_interruptible(&ctlr->xfer_completion)) { in spi_transfer_wait()
1143 ms = wait_for_completion_timeout(&ctlr->xfer_completion, in spi_transfer_wait()
1258 static int spi_transfer_one_message(struct spi_controller *ctlr, in spi_transfer_one_message() argument
1264 struct spi_statistics *statm = &ctlr->statistics; in spi_transfer_one_message()
1275 spi_statistics_add_transfer_stats(statm, xfer, ctlr); in spi_transfer_one_message()
1276 spi_statistics_add_transfer_stats(stats, xfer, ctlr); in spi_transfer_one_message()
1278 if (!ctlr->ptp_sts_supported) { in spi_transfer_one_message()
1284 reinit_completion(&ctlr->xfer_completion); in spi_transfer_one_message()
1287 ret = ctlr->transfer_one(ctlr, msg->spi, xfer); in spi_transfer_one_message()
1289 if (ctlr->cur_msg_mapped && in spi_transfer_one_message()
1291 __spi_unmap_msg(ctlr, msg); in spi_transfer_one_message()
1292 ctlr->fallback = true; in spi_transfer_one_message()
1307 ret = spi_transfer_wait(ctlr, msg, xfer); in spi_transfer_one_message()
1318 if (!ctlr->ptp_sts_supported) { in spi_transfer_one_message()
1351 if (msg->status && ctlr->handle_err) in spi_transfer_one_message()
1352 ctlr->handle_err(ctlr, msg); in spi_transfer_one_message()
1354 spi_finalize_current_message(ctlr); in spi_transfer_one_message()
1367 void spi_finalize_current_transfer(struct spi_controller *ctlr) in spi_finalize_current_transfer() argument
1369 complete(&ctlr->xfer_completion); in spi_finalize_current_transfer()
1373 static void spi_idle_runtime_pm(struct spi_controller *ctlr) in spi_idle_runtime_pm() argument
1375 if (ctlr->auto_runtime_pm) { in spi_idle_runtime_pm()
1376 pm_runtime_mark_last_busy(ctlr->dev.parent); in spi_idle_runtime_pm()
1377 pm_runtime_put_autosuspend(ctlr->dev.parent); in spi_idle_runtime_pm()
1394 static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread) in __spi_pump_messages() argument
1403 spin_lock_irqsave(&ctlr->queue_lock, flags); in __spi_pump_messages()
1406 if (ctlr->cur_msg) { in __spi_pump_messages()
1407 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in __spi_pump_messages()
1412 if (ctlr->idling) { in __spi_pump_messages()
1413 kthread_queue_work(ctlr->kworker, &ctlr->pump_messages); in __spi_pump_messages()
1414 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in __spi_pump_messages()
1419 if (list_empty(&ctlr->queue) || !ctlr->running) { in __spi_pump_messages()
1420 if (!ctlr->busy) { in __spi_pump_messages()
1421 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in __spi_pump_messages()
1427 if (!ctlr->dummy_rx && !ctlr->dummy_tx && in __spi_pump_messages()
1428 !ctlr->unprepare_transfer_hardware) { in __spi_pump_messages()
1429 spi_idle_runtime_pm(ctlr); in __spi_pump_messages()
1430 ctlr->busy = false; in __spi_pump_messages()
1431 trace_spi_controller_idle(ctlr); in __spi_pump_messages()
1433 kthread_queue_work(ctlr->kworker, in __spi_pump_messages()
1434 &ctlr->pump_messages); in __spi_pump_messages()
1436 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in __spi_pump_messages()
1440 ctlr->busy = false; in __spi_pump_messages()
1441 ctlr->idling = true; in __spi_pump_messages()
1442 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in __spi_pump_messages()
1444 kfree(ctlr->dummy_rx); in __spi_pump_messages()
1445 ctlr->dummy_rx = NULL; in __spi_pump_messages()
1446 kfree(ctlr->dummy_tx); in __spi_pump_messages()
1447 ctlr->dummy_tx = NULL; in __spi_pump_messages()
1448 if (ctlr->unprepare_transfer_hardware && in __spi_pump_messages()
1449 ctlr->unprepare_transfer_hardware(ctlr)) in __spi_pump_messages()
1450 dev_err(&ctlr->dev, in __spi_pump_messages()
1452 spi_idle_runtime_pm(ctlr); in __spi_pump_messages()
1453 trace_spi_controller_idle(ctlr); in __spi_pump_messages()
1455 spin_lock_irqsave(&ctlr->queue_lock, flags); in __spi_pump_messages()
1456 ctlr->idling = false; in __spi_pump_messages()
1457 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in __spi_pump_messages()
1462 msg = list_first_entry(&ctlr->queue, struct spi_message, queue); in __spi_pump_messages()
1463 ctlr->cur_msg = msg; in __spi_pump_messages()
1466 if (ctlr->busy) in __spi_pump_messages()
1469 ctlr->busy = true; in __spi_pump_messages()
1470 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in __spi_pump_messages()
1472 mutex_lock(&ctlr->io_mutex); in __spi_pump_messages()
1474 if (!was_busy && ctlr->auto_runtime_pm) { in __spi_pump_messages()
1475 ret = pm_runtime_get_sync(ctlr->dev.parent); in __spi_pump_messages()
1477 pm_runtime_put_noidle(ctlr->dev.parent); in __spi_pump_messages()
1478 dev_err(&ctlr->dev, "Failed to power device: %d\n", in __spi_pump_messages()
1480 mutex_unlock(&ctlr->io_mutex); in __spi_pump_messages()
1486 trace_spi_controller_busy(ctlr); in __spi_pump_messages()
1488 if (!was_busy && ctlr->prepare_transfer_hardware) { in __spi_pump_messages()
1489 ret = ctlr->prepare_transfer_hardware(ctlr); in __spi_pump_messages()
1491 dev_err(&ctlr->dev, in __spi_pump_messages()
1495 if (ctlr->auto_runtime_pm) in __spi_pump_messages()
1496 pm_runtime_put(ctlr->dev.parent); in __spi_pump_messages()
1499 spi_finalize_current_message(ctlr); in __spi_pump_messages()
1501 mutex_unlock(&ctlr->io_mutex); in __spi_pump_messages()
1508 if (ctlr->prepare_message) { in __spi_pump_messages()
1509 ret = ctlr->prepare_message(ctlr, msg); in __spi_pump_messages()
1511 dev_err(&ctlr->dev, "failed to prepare message: %d\n", in __spi_pump_messages()
1514 spi_finalize_current_message(ctlr); in __spi_pump_messages()
1517 ctlr->cur_msg_prepared = true; in __spi_pump_messages()
1520 ret = spi_map_msg(ctlr, msg); in __spi_pump_messages()
1523 spi_finalize_current_message(ctlr); in __spi_pump_messages()
1527 if (!ctlr->ptp_sts_supported && !ctlr->transfer_one) { in __spi_pump_messages()
1534 ret = ctlr->transfer_one_message(ctlr, msg); in __spi_pump_messages()
1536 dev_err(&ctlr->dev, in __spi_pump_messages()
1542 mutex_unlock(&ctlr->io_mutex); in __spi_pump_messages()
1555 struct spi_controller *ctlr = in spi_pump_messages() local
1558 __spi_pump_messages(ctlr, true); in spi_pump_messages()
1582 void spi_take_timestamp_pre(struct spi_controller *ctlr, in spi_take_timestamp_pre() argument
1599 local_irq_save(ctlr->irq_flags); in spi_take_timestamp_pre()
1619 void spi_take_timestamp_post(struct spi_controller *ctlr, in spi_take_timestamp_post() argument
1635 local_irq_restore(ctlr->irq_flags); in spi_take_timestamp_post()
1661 static void spi_set_thread_rt(struct spi_controller *ctlr) in spi_set_thread_rt() argument
1663 dev_info(&ctlr->dev, in spi_set_thread_rt()
1665 sched_set_fifo(ctlr->kworker->task); in spi_set_thread_rt()
1668 static int spi_init_queue(struct spi_controller *ctlr) in spi_init_queue() argument
1670 ctlr->running = false; in spi_init_queue()
1671 ctlr->busy = false; in spi_init_queue()
1673 ctlr->kworker = kthread_create_worker(0, dev_name(&ctlr->dev)); in spi_init_queue()
1674 if (IS_ERR(ctlr->kworker)) { in spi_init_queue()
1675 dev_err(&ctlr->dev, "failed to create message pump kworker\n"); in spi_init_queue()
1676 return PTR_ERR(ctlr->kworker); in spi_init_queue()
1679 kthread_init_work(&ctlr->pump_messages, spi_pump_messages); in spi_init_queue()
1688 if (ctlr->rt) in spi_init_queue()
1689 spi_set_thread_rt(ctlr); in spi_init_queue()
1704 struct spi_message *spi_get_next_queued_message(struct spi_controller *ctlr) in spi_get_next_queued_message() argument
1710 spin_lock_irqsave(&ctlr->queue_lock, flags); in spi_get_next_queued_message()
1711 next = list_first_entry_or_null(&ctlr->queue, struct spi_message, in spi_get_next_queued_message()
1713 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in spi_get_next_queued_message()
1726 void spi_finalize_current_message(struct spi_controller *ctlr) in spi_finalize_current_message() argument
1733 spin_lock_irqsave(&ctlr->queue_lock, flags); in spi_finalize_current_message()
1734 mesg = ctlr->cur_msg; in spi_finalize_current_message()
1735 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in spi_finalize_current_message()
1737 if (!ctlr->ptp_sts_supported && !ctlr->transfer_one) { in spi_finalize_current_message()
1744 if (unlikely(ctlr->ptp_sts_supported)) in spi_finalize_current_message()
1748 spi_unmap_msg(ctlr, mesg); in spi_finalize_current_message()
1755 spi_res_release(ctlr, mesg); in spi_finalize_current_message()
1757 if (ctlr->cur_msg_prepared && ctlr->unprepare_message) { in spi_finalize_current_message()
1758 ret = ctlr->unprepare_message(ctlr, mesg); in spi_finalize_current_message()
1760 dev_err(&ctlr->dev, "failed to unprepare message: %d\n", in spi_finalize_current_message()
1765 spin_lock_irqsave(&ctlr->queue_lock, flags); in spi_finalize_current_message()
1766 ctlr->cur_msg = NULL; in spi_finalize_current_message()
1767 ctlr->cur_msg_prepared = false; in spi_finalize_current_message()
1768 ctlr->fallback = false; in spi_finalize_current_message()
1769 kthread_queue_work(ctlr->kworker, &ctlr->pump_messages); in spi_finalize_current_message()
1770 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in spi_finalize_current_message()
1780 static int spi_start_queue(struct spi_controller *ctlr) in spi_start_queue() argument
1784 spin_lock_irqsave(&ctlr->queue_lock, flags); in spi_start_queue()
1786 if (ctlr->running || ctlr->busy) { in spi_start_queue()
1787 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in spi_start_queue()
1791 ctlr->running = true; in spi_start_queue()
1792 ctlr->cur_msg = NULL; in spi_start_queue()
1793 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in spi_start_queue()
1795 kthread_queue_work(ctlr->kworker, &ctlr->pump_messages); in spi_start_queue()
1800 static int spi_stop_queue(struct spi_controller *ctlr) in spi_stop_queue() argument
1806 spin_lock_irqsave(&ctlr->queue_lock, flags); in spi_stop_queue()
1814 while ((!list_empty(&ctlr->queue) || ctlr->busy) && limit--) { in spi_stop_queue()
1815 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in spi_stop_queue()
1817 spin_lock_irqsave(&ctlr->queue_lock, flags); in spi_stop_queue()
1820 if (!list_empty(&ctlr->queue) || ctlr->busy) in spi_stop_queue()
1823 ctlr->running = false; in spi_stop_queue()
1825 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in spi_stop_queue()
1828 dev_warn(&ctlr->dev, "could not stop message queue\n"); in spi_stop_queue()
1834 static int spi_destroy_queue(struct spi_controller *ctlr) in spi_destroy_queue() argument
1838 ret = spi_stop_queue(ctlr); in spi_destroy_queue()
1847 dev_err(&ctlr->dev, "problem destroying queue\n"); in spi_destroy_queue()
1851 kthread_destroy_worker(ctlr->kworker); in spi_destroy_queue()
1860 struct spi_controller *ctlr = spi->controller; in __spi_queued_transfer() local
1863 spin_lock_irqsave(&ctlr->queue_lock, flags); in __spi_queued_transfer()
1865 if (!ctlr->running) { in __spi_queued_transfer()
1866 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in __spi_queued_transfer()
1872 list_add_tail(&msg->queue, &ctlr->queue); in __spi_queued_transfer()
1873 if (!ctlr->busy && need_pump) in __spi_queued_transfer()
1874 kthread_queue_work(ctlr->kworker, &ctlr->pump_messages); in __spi_queued_transfer()
1876 spin_unlock_irqrestore(&ctlr->queue_lock, flags); in __spi_queued_transfer()
1892 static int spi_controller_initialize_queue(struct spi_controller *ctlr) in spi_controller_initialize_queue() argument
1896 ctlr->transfer = spi_queued_transfer; in spi_controller_initialize_queue()
1897 if (!ctlr->transfer_one_message) in spi_controller_initialize_queue()
1898 ctlr->transfer_one_message = spi_transfer_one_message; in spi_controller_initialize_queue()
1901 ret = spi_init_queue(ctlr); in spi_controller_initialize_queue()
1903 dev_err(&ctlr->dev, "problem initializing queue\n"); in spi_controller_initialize_queue()
1906 ctlr->queued = true; in spi_controller_initialize_queue()
1907 ret = spi_start_queue(ctlr); in spi_controller_initialize_queue()
1909 dev_err(&ctlr->dev, "problem starting queue\n"); in spi_controller_initialize_queue()
1916 spi_destroy_queue(ctlr); in spi_controller_initialize_queue()
1931 void spi_flush_queue(struct spi_controller *ctlr) in spi_flush_queue() argument
1933 if (ctlr->transfer == spi_queued_transfer) in spi_flush_queue()
1934 __spi_pump_messages(ctlr, false); in spi_flush_queue()
1940 static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, in of_spi_parse_dt() argument
1973 dev_warn(&ctlr->dev, in of_spi_parse_dt()
1994 dev_warn(&ctlr->dev, in of_spi_parse_dt()
2001 if (spi_controller_is_slave(ctlr)) { in of_spi_parse_dt()
2003 dev_err(&ctlr->dev, "%pOF is not called 'slave'\n", in of_spi_parse_dt()
2013 dev_err(&ctlr->dev, "%pOF has no valid 'reg' property (%d)\n", in of_spi_parse_dt()
2027 of_register_spi_device(struct spi_controller *ctlr, struct device_node *nc) in of_register_spi_device() argument
2033 spi = spi_alloc_device(ctlr); in of_register_spi_device()
2035 dev_err(&ctlr->dev, "spi_device alloc error for %pOF\n", nc); in of_register_spi_device()
2044 dev_err(&ctlr->dev, "cannot find modalias for %pOF\n", nc); in of_register_spi_device()
2048 rc = of_spi_parse_dt(ctlr, spi, nc); in of_register_spi_device()
2060 dev_err(&ctlr->dev, "spi_device register error %pOF\n", nc); in of_register_spi_device()
2080 static void of_register_spi_devices(struct spi_controller *ctlr) in of_register_spi_devices() argument
2085 if (!ctlr->dev.of_node) in of_register_spi_devices()
2088 for_each_available_child_of_node(ctlr->dev.of_node, nc) { in of_register_spi_devices()
2091 spi = of_register_spi_device(ctlr, nc); in of_register_spi_devices()
2093 dev_warn(&ctlr->dev, in of_register_spi_devices()
2100 static void of_register_spi_devices(struct spi_controller *ctlr) { } in of_register_spi_devices() argument
2105 struct spi_controller *ctlr; member
2145 struct spi_controller *ctlr = lookup->ctlr; in acpi_spi_add_resource() local
2160 ACPI_HANDLE(ctlr->dev.parent) != parent_handle) in acpi_spi_add_resource()
2170 if (ctlr->fw_translate_cs) { in acpi_spi_add_resource()
2171 int cs = ctlr->fw_translate_cs(ctlr, in acpi_spi_add_resource()
2201 static acpi_status acpi_register_spi_device(struct spi_controller *ctlr, in acpi_register_spi_device() argument
2214 lookup.ctlr = ctlr; in acpi_register_spi_device()
2228 ACPI_HANDLE(ctlr->dev.parent) == parent_handle) { in acpi_register_spi_device()
2236 spi = spi_alloc_device(ctlr); in acpi_register_spi_device()
2238 dev_err(&ctlr->dev, "failed to allocate SPI device for %s\n", in acpi_register_spi_device()
2262 dev_err(&ctlr->dev, "failed to add SPI device %s from ACPI\n", in acpi_register_spi_device()
2273 struct spi_controller *ctlr = data; in acpi_spi_add_device() local
2279 return acpi_register_spi_device(ctlr, adev); in acpi_spi_add_device()
2284 static void acpi_register_spi_devices(struct spi_controller *ctlr) in acpi_register_spi_devices() argument
2289 handle = ACPI_HANDLE(ctlr->dev.parent); in acpi_register_spi_devices()
2295 acpi_spi_add_device, NULL, ctlr, NULL); in acpi_register_spi_devices()
2297 dev_warn(&ctlr->dev, "failed to enumerate SPI slaves\n"); in acpi_register_spi_devices()
2300 static inline void acpi_register_spi_devices(struct spi_controller *ctlr) {} in acpi_register_spi_devices() argument
2305 struct spi_controller *ctlr; in spi_controller_release() local
2307 ctlr = container_of(dev, struct spi_controller, dev); in spi_controller_release()
2308 kfree(ctlr); in spi_controller_release()
2326 struct spi_controller *ctlr = spi->controller; in spi_slave_abort() local
2328 if (spi_controller_is_slave(ctlr) && ctlr->slave_abort) in spi_slave_abort()
2329 return ctlr->slave_abort(ctlr); in spi_slave_abort()
2343 struct spi_controller *ctlr = container_of(dev, struct spi_controller, in slave_show() local
2347 child = device_find_child(&ctlr->dev, NULL, match_true); in slave_show()
2355 struct spi_controller *ctlr = container_of(dev, struct spi_controller, in slave_store() local
2366 child = device_find_child(&ctlr->dev, NULL, match_true); in slave_store()
2375 spi = spi_alloc_device(ctlr); in slave_store()
2446 struct spi_controller *ctlr; in __spi_alloc_controller() local
2447 size_t ctlr_size = ALIGN(sizeof(*ctlr), dma_get_cache_alignment()); in __spi_alloc_controller()
2452 ctlr = kzalloc(size + ctlr_size, GFP_KERNEL); in __spi_alloc_controller()
2453 if (!ctlr) in __spi_alloc_controller()
2456 device_initialize(&ctlr->dev); in __spi_alloc_controller()
2457 ctlr->bus_num = -1; in __spi_alloc_controller()
2458 ctlr->num_chipselect = 1; in __spi_alloc_controller()
2459 ctlr->slave = slave; in __spi_alloc_controller()
2461 ctlr->dev.class = &spi_slave_class; in __spi_alloc_controller()
2463 ctlr->dev.class = &spi_master_class; in __spi_alloc_controller()
2464 ctlr->dev.parent = dev; in __spi_alloc_controller()
2465 pm_suspend_ignore_children(&ctlr->dev, true); in __spi_alloc_controller()
2466 spi_controller_set_devdata(ctlr, (void *)ctlr + ctlr_size); in __spi_alloc_controller()
2468 return ctlr; in __spi_alloc_controller()
2472 static void devm_spi_release_controller(struct device *dev, void *ctlr) in devm_spi_release_controller() argument
2474 spi_controller_put(*(struct spi_controller **)ctlr); in devm_spi_release_controller()
2496 struct spi_controller **ptr, *ctlr; in __devm_spi_alloc_controller() local
2503 ctlr = __spi_alloc_controller(dev, size, slave); in __devm_spi_alloc_controller()
2504 if (ctlr) { in __devm_spi_alloc_controller()
2505 ctlr->devm_allocated = true; in __devm_spi_alloc_controller()
2506 *ptr = ctlr; in __devm_spi_alloc_controller()
2512 return ctlr; in __devm_spi_alloc_controller()
2517 static int of_spi_get_gpio_numbers(struct spi_controller *ctlr) in of_spi_get_gpio_numbers() argument
2520 struct device_node *np = ctlr->dev.of_node; in of_spi_get_gpio_numbers()
2526 ctlr->num_chipselect = max_t(int, nb, ctlr->num_chipselect); in of_spi_get_gpio_numbers()
2534 cs = devm_kcalloc(&ctlr->dev, ctlr->num_chipselect, sizeof(int), in of_spi_get_gpio_numbers()
2536 ctlr->cs_gpios = cs; in of_spi_get_gpio_numbers()
2538 if (!ctlr->cs_gpios) in of_spi_get_gpio_numbers()
2541 for (i = 0; i < ctlr->num_chipselect; i++) in of_spi_get_gpio_numbers()
2550 static int of_spi_get_gpio_numbers(struct spi_controller *ctlr) in of_spi_get_gpio_numbers() argument
2560 static int spi_get_gpio_descs(struct spi_controller *ctlr) in spi_get_gpio_descs() argument
2564 struct device *dev = &ctlr->dev; in spi_get_gpio_descs()
2569 ctlr->num_chipselect = max_t(int, nb, ctlr->num_chipselect); in spi_get_gpio_descs()
2577 cs = devm_kcalloc(dev, ctlr->num_chipselect, sizeof(*cs), in spi_get_gpio_descs()
2581 ctlr->cs_gpiods = cs; in spi_get_gpio_descs()
2612 if (ctlr->max_native_cs && i >= ctlr->max_native_cs) { in spi_get_gpio_descs()
2619 ctlr->unused_native_cs = ffs(~native_cs_mask) - 1; in spi_get_gpio_descs()
2621 if ((ctlr->flags & SPI_MASTER_GPIO_SS) && num_cs_gpios && in spi_get_gpio_descs()
2622 ctlr->max_native_cs && ctlr->unused_native_cs >= ctlr->max_native_cs) { in spi_get_gpio_descs()
2630 static int spi_controller_check_ops(struct spi_controller *ctlr) in spi_controller_check_ops() argument
2639 if (ctlr->mem_ops) { in spi_controller_check_ops()
2640 if (!ctlr->mem_ops->exec_op) in spi_controller_check_ops()
2642 } else if (!ctlr->transfer && !ctlr->transfer_one && in spi_controller_check_ops()
2643 !ctlr->transfer_one_message) { in spi_controller_check_ops()
2673 int spi_register_controller(struct spi_controller *ctlr) in spi_register_controller() argument
2675 struct device *dev = ctlr->dev.parent; in spi_register_controller()
2687 status = spi_controller_check_ops(ctlr); in spi_register_controller()
2691 if (ctlr->bus_num >= 0) { in spi_register_controller()
2694 id = idr_alloc(&spi_master_idr, ctlr, ctlr->bus_num, in spi_register_controller()
2695 ctlr->bus_num + 1, GFP_KERNEL); in spi_register_controller()
2699 ctlr->bus_num = id; in spi_register_controller()
2700 } else if (ctlr->dev.of_node) { in spi_register_controller()
2702 id = of_alias_get_id(ctlr->dev.of_node, "spi"); in spi_register_controller()
2704 ctlr->bus_num = id; in spi_register_controller()
2706 id = idr_alloc(&spi_master_idr, ctlr, ctlr->bus_num, in spi_register_controller()
2707 ctlr->bus_num + 1, GFP_KERNEL); in spi_register_controller()
2713 if (ctlr->bus_num < 0) { in spi_register_controller()
2721 id = idr_alloc(&spi_master_idr, ctlr, first_dynamic, in spi_register_controller()
2726 ctlr->bus_num = id; in spi_register_controller()
2728 INIT_LIST_HEAD(&ctlr->queue); in spi_register_controller()
2729 spin_lock_init(&ctlr->queue_lock); in spi_register_controller()
2730 spin_lock_init(&ctlr->bus_lock_spinlock); in spi_register_controller()
2731 mutex_init(&ctlr->bus_lock_mutex); in spi_register_controller()
2732 mutex_init(&ctlr->io_mutex); in spi_register_controller()
2733 ctlr->bus_lock_flag = 0; in spi_register_controller()
2734 init_completion(&ctlr->xfer_completion); in spi_register_controller()
2735 if (!ctlr->max_dma_len) in spi_register_controller()
2736 ctlr->max_dma_len = INT_MAX; in spi_register_controller()
2741 dev_set_name(&ctlr->dev, "spi%u", ctlr->bus_num); in spi_register_controller()
2743 if (!spi_controller_is_slave(ctlr)) { in spi_register_controller()
2744 if (ctlr->use_gpio_descriptors) { in spi_register_controller()
2745 status = spi_get_gpio_descs(ctlr); in spi_register_controller()
2752 ctlr->mode_bits |= SPI_CS_HIGH; in spi_register_controller()
2755 status = of_spi_get_gpio_numbers(ctlr); in spi_register_controller()
2765 if (!ctlr->num_chipselect) { in spi_register_controller()
2770 status = device_add(&ctlr->dev); in spi_register_controller()
2774 spi_controller_is_slave(ctlr) ? "slave" : "master", in spi_register_controller()
2775 dev_name(&ctlr->dev)); in spi_register_controller()
2782 if (ctlr->transfer) { in spi_register_controller()
2784 } else if (ctlr->transfer_one || ctlr->transfer_one_message) { in spi_register_controller()
2785 status = spi_controller_initialize_queue(ctlr); in spi_register_controller()
2787 device_del(&ctlr->dev); in spi_register_controller()
2792 spin_lock_init(&ctlr->statistics.lock); in spi_register_controller()
2795 list_add_tail(&ctlr->list, &spi_controller_list); in spi_register_controller()
2797 spi_match_controller_to_boardinfo(ctlr, &bi->board_info); in spi_register_controller()
2801 of_register_spi_devices(ctlr); in spi_register_controller()
2802 acpi_register_spi_devices(ctlr); in spi_register_controller()
2807 idr_remove(&spi_master_idr, ctlr->bus_num); in spi_register_controller()
2832 struct spi_controller *ctlr) in devm_spi_register_controller() argument
2841 ret = spi_register_controller(ctlr); in devm_spi_register_controller()
2843 *ptr = ctlr; in devm_spi_register_controller()
2871 void spi_unregister_controller(struct spi_controller *ctlr) in spi_unregister_controller() argument
2874 int id = ctlr->bus_num; in spi_unregister_controller()
2880 device_for_each_child(&ctlr->dev, NULL, __unregister); in spi_unregister_controller()
2886 if (ctlr->queued) { in spi_unregister_controller()
2887 if (spi_destroy_queue(ctlr)) in spi_unregister_controller()
2888 dev_err(&ctlr->dev, "queue remove failed\n"); in spi_unregister_controller()
2891 list_del(&ctlr->list); in spi_unregister_controller()
2894 device_del(&ctlr->dev); in spi_unregister_controller()
2899 if (!ctlr->devm_allocated) in spi_unregister_controller()
2900 put_device(&ctlr->dev); in spi_unregister_controller()
2904 if (found == ctlr) in spi_unregister_controller()
2913 int spi_controller_suspend(struct spi_controller *ctlr) in spi_controller_suspend() argument
2918 if (!ctlr->queued) in spi_controller_suspend()
2921 ret = spi_stop_queue(ctlr); in spi_controller_suspend()
2923 dev_err(&ctlr->dev, "queue stop failed\n"); in spi_controller_suspend()
2929 int spi_controller_resume(struct spi_controller *ctlr) in spi_controller_resume() argument
2933 if (!ctlr->queued) in spi_controller_resume()
2936 ret = spi_start_queue(ctlr); in spi_controller_resume()
2938 dev_err(&ctlr->dev, "queue restart failed\n"); in spi_controller_resume()
2946 struct spi_controller *ctlr; in __spi_controller_match() local
2949 ctlr = container_of(dev, struct spi_controller, dev); in __spi_controller_match()
2950 return ctlr->bus_num == *bus_num; in __spi_controller_match()
2968 struct spi_controller *ctlr = NULL; in spi_busnum_to_master() local
2973 ctlr = container_of(dev, struct spi_controller, dev); in spi_busnum_to_master()
2975 return ctlr; in spi_busnum_to_master()
3050 void spi_res_release(struct spi_controller *ctlr, struct spi_message *message) in spi_res_release() argument
3056 res->release(ctlr, message, res->data); in spi_res_release()
3069 static void __spi_replace_transfers_release(struct spi_controller *ctlr, in __spi_replace_transfers_release() argument
3078 rxfer->release(ctlr, msg, res); in __spi_replace_transfers_release()
3198 static int __spi_split_transfer_maxsize(struct spi_controller *ctlr, in __spi_split_transfer_maxsize() argument
3255 SPI_STATISTICS_INCREMENT_FIELD(&ctlr->statistics, in __spi_split_transfer_maxsize()
3274 int spi_split_transfers_maxsize(struct spi_controller *ctlr, in spi_split_transfers_maxsize() argument
3290 ret = __spi_split_transfer_maxsize(ctlr, msg, &xfer, in spi_split_transfers_maxsize()
3307 static int __spi_validate_bits_per_word(struct spi_controller *ctlr, in __spi_validate_bits_per_word() argument
3310 if (ctlr->bits_per_word_mask) { in __spi_validate_bits_per_word()
3314 if (!(ctlr->bits_per_word_mask & SPI_BPW_MASK(bits_per_word))) in __spi_validate_bits_per_word()
3518 struct spi_controller *ctlr = spi->controller; in __spi_validate() local
3531 if ((spi->mode & SPI_CS_WORD) && (!(ctlr->mode_bits & SPI_CS_WORD) || in __spi_validate()
3542 ret = spi_split_transfers_maxsize(ctlr, message, maxsize, in __spi_validate()
3560 if ((ctlr->flags & SPI_CONTROLLER_HALF_DUPLEX) || in __spi_validate()
3562 unsigned flags = ctlr->flags; in __spi_validate()
3592 if (ctlr->max_speed_hz && xfer->speed_hz > ctlr->max_speed_hz) in __spi_validate()
3593 xfer->speed_hz = ctlr->max_speed_hz; in __spi_validate()
3595 if (__spi_validate_bits_per_word(ctlr, xfer->bits_per_word)) in __spi_validate()
3613 if (xfer->speed_hz && ctlr->min_speed_hz && in __spi_validate()
3614 xfer->speed_hz < ctlr->min_speed_hz) in __spi_validate()
3662 struct spi_controller *ctlr = spi->controller; in __spi_async() local
3669 if (!ctlr->transfer) in __spi_async()
3674 SPI_STATISTICS_INCREMENT_FIELD(&ctlr->statistics, spi_async); in __spi_async()
3679 if (!ctlr->ptp_sts_supported) { in __spi_async()
3686 return ctlr->transfer(spi, message); in __spi_async()
3722 struct spi_controller *ctlr = spi->controller; in spi_async() local
3730 spin_lock_irqsave(&ctlr->bus_lock_spinlock, flags); in spi_async()
3732 if (ctlr->bus_lock_flag) in spi_async()
3737 spin_unlock_irqrestore(&ctlr->bus_lock_spinlock, flags); in spi_async()
3776 struct spi_controller *ctlr = spi->controller; in spi_async_locked() local
3784 spin_lock_irqsave(&ctlr->bus_lock_spinlock, flags); in spi_async_locked()
3788 spin_unlock_irqrestore(&ctlr->bus_lock_spinlock, flags); in spi_async_locked()
3811 struct spi_controller *ctlr = spi->controller; in __spi_sync() local
3822 SPI_STATISTICS_INCREMENT_FIELD(&ctlr->statistics, spi_sync); in __spi_sync()
3830 if (ctlr->transfer == spi_queued_transfer) { in __spi_sync()
3831 spin_lock_irqsave(&ctlr->bus_lock_spinlock, flags); in __spi_sync()
3837 spin_unlock_irqrestore(&ctlr->bus_lock_spinlock, flags); in __spi_sync()
3846 if (ctlr->transfer == spi_queued_transfer) { in __spi_sync()
3847 SPI_STATISTICS_INCREMENT_FIELD(&ctlr->statistics, in __spi_sync()
3851 __spi_pump_messages(ctlr, false); in __spi_sync()
3931 int spi_bus_lock(struct spi_controller *ctlr) in spi_bus_lock() argument
3935 mutex_lock(&ctlr->bus_lock_mutex); in spi_bus_lock()
3937 spin_lock_irqsave(&ctlr->bus_lock_spinlock, flags); in spi_bus_lock()
3938 ctlr->bus_lock_flag = 1; in spi_bus_lock()
3939 spin_unlock_irqrestore(&ctlr->bus_lock_spinlock, flags); in spi_bus_lock()
3960 int spi_bus_unlock(struct spi_controller *ctlr) in spi_bus_unlock() argument
3962 ctlr->bus_lock_flag = 0; in spi_bus_unlock()
3964 mutex_unlock(&ctlr->bus_lock_mutex); in spi_bus_unlock()
4082 struct spi_controller *ctlr; in of_spi_notify() local
4087 ctlr = of_find_spi_controller_by_node(rd->dn->parent); in of_spi_notify()
4088 if (ctlr == NULL) in of_spi_notify()
4092 put_device(&ctlr->dev); in of_spi_notify()
4096 spi = of_register_spi_device(ctlr, rd->dn); in of_spi_notify()
4097 put_device(&ctlr->dev); in of_spi_notify()
4168 struct spi_controller *ctlr; in acpi_spi_notify() local
4173 ctlr = acpi_spi_find_controller_by_adev(adev->parent); in acpi_spi_notify()
4174 if (!ctlr) in acpi_spi_notify()
4177 acpi_register_spi_device(ctlr, adev); in acpi_spi_notify()
4178 put_device(&ctlr->dev); in acpi_spi_notify()