|
18 | 18 |
|
19 | 19 | #include <linux/cleanup.h> |
20 | 20 | #include <linux/device.h> |
| 21 | +#include <linux/dmaengine.h> |
21 | 22 | #include <linux/export.h> |
22 | 23 | #include <linux/kref.h> |
23 | 24 | #include <linux/list.h> |
@@ -332,6 +333,75 @@ void spi_offload_trigger_disable(struct spi_offload *offload, |
332 | 333 | } |
333 | 334 | EXPORT_SYMBOL_GPL(spi_offload_trigger_disable); |
334 | 335 |
|
| 336 | +static void spi_offload_release_dma_chan(void *chan) |
| 337 | +{ |
| 338 | + dma_release_channel(chan); |
| 339 | +} |
| 340 | + |
| 341 | +/** |
| 342 | + * devm_spi_offload_tx_stream_request_dma_chan - Get the DMA channel info for the TX stream |
| 343 | + * @dev: Device for devm purposes. |
| 344 | + * @offload: Offload instance |
| 345 | + * |
| 346 | + * This is the DMA channel that will provide data to transfers that use the |
| 347 | + * %SPI_OFFLOAD_XFER_TX_STREAM offload flag. |
| 348 | + * |
| 349 | + * Return: Pointer to DMA channel info, or negative error code |
| 350 | + */ |
| 351 | +struct dma_chan |
| 352 | +*devm_spi_offload_tx_stream_request_dma_chan(struct device *dev, |
| 353 | + struct spi_offload *offload) |
| 354 | +{ |
| 355 | + struct dma_chan *chan; |
| 356 | + int ret; |
| 357 | + |
| 358 | + if (!offload->ops || !offload->ops->tx_stream_request_dma_chan) |
| 359 | + return ERR_PTR(-EOPNOTSUPP); |
| 360 | + |
| 361 | + chan = offload->ops->tx_stream_request_dma_chan(offload); |
| 362 | + if (IS_ERR(chan)) |
| 363 | + return chan; |
| 364 | + |
| 365 | + ret = devm_add_action_or_reset(dev, spi_offload_release_dma_chan, chan); |
| 366 | + if (ret) |
| 367 | + return ERR_PTR(ret); |
| 368 | + |
| 369 | + return chan; |
| 370 | +} |
| 371 | +EXPORT_SYMBOL_GPL(devm_spi_offload_tx_stream_request_dma_chan); |
| 372 | + |
| 373 | +/** |
| 374 | + * devm_spi_offload_rx_stream_request_dma_chan - Get the DMA channel info for the RX stream |
| 375 | + * @dev: Device for devm purposes. |
| 376 | + * @offload: Offload instance |
| 377 | + * |
| 378 | + * This is the DMA channel that will receive data from transfers that use the |
| 379 | + * %SPI_OFFLOAD_XFER_RX_STREAM offload flag. |
| 380 | + * |
| 381 | + * Return: Pointer to DMA channel info, or negative error code |
| 382 | + */ |
| 383 | +struct dma_chan |
| 384 | +*devm_spi_offload_rx_stream_request_dma_chan(struct device *dev, |
| 385 | + struct spi_offload *offload) |
| 386 | +{ |
| 387 | + struct dma_chan *chan; |
| 388 | + int ret; |
| 389 | + |
| 390 | + if (!offload->ops || !offload->ops->rx_stream_request_dma_chan) |
| 391 | + return ERR_PTR(-EOPNOTSUPP); |
| 392 | + |
| 393 | + chan = offload->ops->rx_stream_request_dma_chan(offload); |
| 394 | + if (IS_ERR(chan)) |
| 395 | + return chan; |
| 396 | + |
| 397 | + ret = devm_add_action_or_reset(dev, spi_offload_release_dma_chan, chan); |
| 398 | + if (ret) |
| 399 | + return ERR_PTR(ret); |
| 400 | + |
| 401 | + return chan; |
| 402 | +} |
| 403 | +EXPORT_SYMBOL_GPL(devm_spi_offload_rx_stream_request_dma_chan); |
| 404 | + |
335 | 405 | /* Triggers providers */ |
336 | 406 |
|
337 | 407 | static void spi_offload_trigger_unregister(void *data) |
|
0 commit comments