2019-05-28 20:10:04 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-06-06 09:25:27 +04:00
|
|
|
/*
|
|
|
|
* DMA driver for Nvidia's Tegra20 APB DMA controller.
|
|
|
|
*
|
2013-11-12 00:09:35 +04:00
|
|
|
* Copyright (c) 2012-2013, NVIDIA CORPORATION. All rights reserved.
|
2012-06-06 09:25:27 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/dmaengine.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
2013-01-21 14:09:00 +04:00
|
|
|
#include <linux/err.h>
|
2012-06-06 09:25:27 +04:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2013-11-12 00:09:35 +04:00
|
|
|
#include <linux/of_dma.h>
|
2012-06-06 09:25:27 +04:00
|
|
|
#include <linux/platform_device.h>
|
2013-04-24 13:54:27 +04:00
|
|
|
#include <linux/pm.h>
|
2012-06-06 09:25:27 +04:00
|
|
|
#include <linux/pm_runtime.h>
|
2013-11-07 03:35:34 +04:00
|
|
|
#include <linux/reset.h>
|
2012-06-06 09:25:27 +04:00
|
|
|
#include <linux/slab.h>
|
2020-03-20 00:23:21 +03:00
|
|
|
#include <linux/wait.h>
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
#include "dmaengine.h"
|
|
|
|
|
2018-11-21 19:13:23 +03:00
|
|
|
#define CREATE_TRACE_POINTS
|
|
|
|
#include <trace/events/tegra_apb_dma.h>
|
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
#define TEGRA_APBDMA_GENERAL 0x0
|
|
|
|
#define TEGRA_APBDMA_GENERAL_ENABLE BIT(31)
|
|
|
|
|
|
|
|
#define TEGRA_APBDMA_CONTROL 0x010
|
|
|
|
#define TEGRA_APBDMA_IRQ_MASK 0x01c
|
|
|
|
#define TEGRA_APBDMA_IRQ_MASK_SET 0x020
|
|
|
|
|
|
|
|
/* CSR register */
|
|
|
|
#define TEGRA_APBDMA_CHAN_CSR 0x00
|
|
|
|
#define TEGRA_APBDMA_CSR_ENB BIT(31)
|
|
|
|
#define TEGRA_APBDMA_CSR_IE_EOC BIT(30)
|
|
|
|
#define TEGRA_APBDMA_CSR_HOLD BIT(29)
|
|
|
|
#define TEGRA_APBDMA_CSR_DIR BIT(28)
|
|
|
|
#define TEGRA_APBDMA_CSR_ONCE BIT(27)
|
|
|
|
#define TEGRA_APBDMA_CSR_FLOW BIT(21)
|
|
|
|
#define TEGRA_APBDMA_CSR_REQ_SEL_SHIFT 16
|
2016-04-23 12:36:00 +03:00
|
|
|
#define TEGRA_APBDMA_CSR_REQ_SEL_MASK 0x1F
|
2012-06-06 09:25:27 +04:00
|
|
|
#define TEGRA_APBDMA_CSR_WCOUNT_MASK 0xFFFC
|
|
|
|
|
|
|
|
/* STATUS register */
|
|
|
|
#define TEGRA_APBDMA_CHAN_STATUS 0x004
|
|
|
|
#define TEGRA_APBDMA_STATUS_BUSY BIT(31)
|
|
|
|
#define TEGRA_APBDMA_STATUS_ISE_EOC BIT(30)
|
|
|
|
#define TEGRA_APBDMA_STATUS_HALT BIT(29)
|
|
|
|
#define TEGRA_APBDMA_STATUS_PING_PONG BIT(28)
|
|
|
|
#define TEGRA_APBDMA_STATUS_COUNT_SHIFT 2
|
|
|
|
#define TEGRA_APBDMA_STATUS_COUNT_MASK 0xFFFC
|
|
|
|
|
2013-01-06 20:22:02 +04:00
|
|
|
#define TEGRA_APBDMA_CHAN_CSRE 0x00C
|
2020-02-09 19:33:45 +03:00
|
|
|
#define TEGRA_APBDMA_CHAN_CSRE_PAUSE BIT(31)
|
2013-01-06 20:22:02 +04:00
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
/* AHB memory address */
|
|
|
|
#define TEGRA_APBDMA_CHAN_AHBPTR 0x010
|
|
|
|
|
|
|
|
/* AHB sequence register */
|
|
|
|
#define TEGRA_APBDMA_CHAN_AHBSEQ 0x14
|
|
|
|
#define TEGRA_APBDMA_AHBSEQ_INTR_ENB BIT(31)
|
|
|
|
#define TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_8 (0 << 28)
|
|
|
|
#define TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_16 (1 << 28)
|
|
|
|
#define TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_32 (2 << 28)
|
|
|
|
#define TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_64 (3 << 28)
|
|
|
|
#define TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_128 (4 << 28)
|
|
|
|
#define TEGRA_APBDMA_AHBSEQ_DATA_SWAP BIT(27)
|
|
|
|
#define TEGRA_APBDMA_AHBSEQ_BURST_1 (4 << 24)
|
|
|
|
#define TEGRA_APBDMA_AHBSEQ_BURST_4 (5 << 24)
|
|
|
|
#define TEGRA_APBDMA_AHBSEQ_BURST_8 (6 << 24)
|
|
|
|
#define TEGRA_APBDMA_AHBSEQ_DBL_BUF BIT(19)
|
|
|
|
#define TEGRA_APBDMA_AHBSEQ_WRAP_SHIFT 16
|
|
|
|
#define TEGRA_APBDMA_AHBSEQ_WRAP_NONE 0
|
|
|
|
|
|
|
|
/* APB address */
|
|
|
|
#define TEGRA_APBDMA_CHAN_APBPTR 0x018
|
|
|
|
|
|
|
|
/* APB sequence register */
|
|
|
|
#define TEGRA_APBDMA_CHAN_APBSEQ 0x01c
|
|
|
|
#define TEGRA_APBDMA_APBSEQ_BUS_WIDTH_8 (0 << 28)
|
|
|
|
#define TEGRA_APBDMA_APBSEQ_BUS_WIDTH_16 (1 << 28)
|
|
|
|
#define TEGRA_APBDMA_APBSEQ_BUS_WIDTH_32 (2 << 28)
|
|
|
|
#define TEGRA_APBDMA_APBSEQ_BUS_WIDTH_64 (3 << 28)
|
|
|
|
#define TEGRA_APBDMA_APBSEQ_BUS_WIDTH_128 (4 << 28)
|
|
|
|
#define TEGRA_APBDMA_APBSEQ_DATA_SWAP BIT(27)
|
|
|
|
#define TEGRA_APBDMA_APBSEQ_WRAP_WORD_1 (1 << 16)
|
|
|
|
|
2014-01-06 22:16:45 +04:00
|
|
|
/* Tegra148 specific registers */
|
|
|
|
#define TEGRA_APBDMA_CHAN_WCOUNT 0x20
|
|
|
|
|
|
|
|
#define TEGRA_APBDMA_CHAN_WORD_TRANSFER 0x24
|
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
/*
|
|
|
|
* If any burst is in flight and DMA paused then this is the time to complete
|
|
|
|
* on-flight burst and update DMA status register.
|
|
|
|
*/
|
|
|
|
#define TEGRA_APBDMA_BURST_COMPLETE_TIME 20
|
|
|
|
|
|
|
|
/* Channel base address offset from APBDMA base address */
|
|
|
|
#define TEGRA_APBDMA_CHANNEL_BASE_ADD_OFFSET 0x1000
|
|
|
|
|
2016-04-23 12:36:00 +03:00
|
|
|
#define TEGRA_APBDMA_SLAVE_ID_INVALID (TEGRA_APBDMA_CSR_REQ_SEL_MASK + 1)
|
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
struct tegra_dma;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tegra_dma_chip_data Tegra chip specific DMA data
|
|
|
|
* @nr_channels: Number of channels available in the controller.
|
2014-01-06 22:16:45 +04:00
|
|
|
* @channel_reg_size: Channel register size/stride.
|
2012-06-06 09:25:27 +04:00
|
|
|
* @max_dma_count: Maximum DMA transfer count supported by DMA controller.
|
2013-01-06 20:22:02 +04:00
|
|
|
* @support_channel_pause: Support channel wise pause of dma.
|
2014-01-06 22:16:45 +04:00
|
|
|
* @support_separate_wcount_reg: Support separate word count register.
|
2012-06-06 09:25:27 +04:00
|
|
|
*/
|
|
|
|
struct tegra_dma_chip_data {
|
2020-02-09 19:33:45 +03:00
|
|
|
unsigned int nr_channels;
|
|
|
|
unsigned int channel_reg_size;
|
|
|
|
unsigned int max_dma_count;
|
2013-01-06 20:22:02 +04:00
|
|
|
bool support_channel_pause;
|
2014-01-06 22:16:45 +04:00
|
|
|
bool support_separate_wcount_reg;
|
2012-06-06 09:25:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* DMA channel registers */
|
|
|
|
struct tegra_dma_channel_regs {
|
2020-02-09 19:33:45 +03:00
|
|
|
u32 csr;
|
|
|
|
u32 ahb_ptr;
|
|
|
|
u32 apb_ptr;
|
|
|
|
u32 ahb_seq;
|
|
|
|
u32 apb_seq;
|
|
|
|
u32 wcount;
|
2012-06-06 09:25:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2018-11-21 19:13:21 +03:00
|
|
|
* tegra_dma_sg_req: DMA request details to configure hardware. This
|
2012-06-06 09:25:27 +04:00
|
|
|
* contains the details for one transfer to configure DMA hw.
|
|
|
|
* The client's request for data transfer can be broken into multiple
|
|
|
|
* sub-transfer as per requester details and hw support.
|
|
|
|
* This sub transfer get added in the list of transfer and point to Tegra
|
|
|
|
* DMA descriptor which manages the transfer details.
|
|
|
|
*/
|
|
|
|
struct tegra_dma_sg_req {
|
|
|
|
struct tegra_dma_channel_regs ch_regs;
|
2018-11-21 19:13:20 +03:00
|
|
|
unsigned int req_len;
|
2012-06-06 09:25:27 +04:00
|
|
|
bool configured;
|
|
|
|
bool last_sg;
|
|
|
|
struct list_head node;
|
|
|
|
struct tegra_dma_desc *dma_desc;
|
2019-07-05 18:05:19 +03:00
|
|
|
unsigned int words_xferred;
|
2012-06-06 09:25:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tegra_dma_desc: Tegra DMA descriptors which manages the client requests.
|
|
|
|
* This descriptor keep track of transfer status, callbacks and request
|
|
|
|
* counts etc.
|
|
|
|
*/
|
|
|
|
struct tegra_dma_desc {
|
|
|
|
struct dma_async_tx_descriptor txd;
|
2018-11-21 19:13:20 +03:00
|
|
|
unsigned int bytes_requested;
|
|
|
|
unsigned int bytes_transferred;
|
2012-06-06 09:25:27 +04:00
|
|
|
enum dma_status dma_status;
|
|
|
|
struct list_head node;
|
|
|
|
struct list_head tx_list;
|
|
|
|
struct list_head cb_node;
|
2020-02-09 19:33:45 +03:00
|
|
|
unsigned int cb_count;
|
2012-06-06 09:25:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct tegra_dma_channel;
|
|
|
|
|
|
|
|
typedef void (*dma_isr_handler)(struct tegra_dma_channel *tdc,
|
|
|
|
bool to_terminate);
|
|
|
|
|
|
|
|
/* tegra_dma_channel: Channel specific information */
|
|
|
|
struct tegra_dma_channel {
|
|
|
|
struct dma_chan dma_chan;
|
2018-11-21 19:13:22 +03:00
|
|
|
char name[12];
|
2012-06-06 09:25:27 +04:00
|
|
|
bool config_init;
|
2020-02-09 19:33:45 +03:00
|
|
|
unsigned int id;
|
2015-08-06 16:32:31 +03:00
|
|
|
void __iomem *chan_addr;
|
2012-06-06 09:25:27 +04:00
|
|
|
spinlock_t lock;
|
|
|
|
bool busy;
|
|
|
|
struct tegra_dma *tdma;
|
|
|
|
bool cyclic;
|
|
|
|
|
|
|
|
/* Different lists for managing the requests */
|
|
|
|
struct list_head free_sg_req;
|
|
|
|
struct list_head pending_sg_req;
|
|
|
|
struct list_head free_dma_desc;
|
|
|
|
struct list_head cb_desc;
|
|
|
|
|
|
|
|
/* ISR handler and tasklet for bottom half of isr handling */
|
|
|
|
dma_isr_handler isr_handler;
|
|
|
|
struct tasklet_struct tasklet;
|
|
|
|
|
|
|
|
/* Channel-slave specific configuration */
|
2013-11-12 00:09:35 +04:00
|
|
|
unsigned int slave_id;
|
2012-06-06 09:25:27 +04:00
|
|
|
struct dma_slave_config dma_sconfig;
|
2020-02-09 19:33:45 +03:00
|
|
|
struct tegra_dma_channel_regs channel_reg;
|
2020-03-20 00:23:21 +03:00
|
|
|
|
|
|
|
struct wait_queue_head wq;
|
2012-06-06 09:25:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* tegra_dma: Tegra DMA specific information */
|
|
|
|
struct tegra_dma {
|
|
|
|
struct dma_device dma_dev;
|
|
|
|
struct device *dev;
|
|
|
|
struct clk *dma_clk;
|
2013-11-07 03:35:34 +04:00
|
|
|
struct reset_control *rst;
|
2012-06-06 09:25:27 +04:00
|
|
|
spinlock_t global_lock;
|
|
|
|
void __iomem *base_addr;
|
2012-08-29 12:23:07 +04:00
|
|
|
const struct tegra_dma_chip_data *chip_data;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
2015-08-06 16:32:33 +03:00
|
|
|
/*
|
|
|
|
* Counter for managing global pausing of the DMA controller.
|
|
|
|
* Only applicable for devices that don't support individual
|
|
|
|
* channel pausing.
|
|
|
|
*/
|
|
|
|
u32 global_pause_count;
|
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
/* Last member of the structure */
|
2020-05-28 17:35:11 +03:00
|
|
|
struct tegra_dma_channel channels[];
|
2012-06-06 09:25:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline void tdma_write(struct tegra_dma *tdma, u32 reg, u32 val)
|
|
|
|
{
|
|
|
|
writel(val, tdma->base_addr + reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 tdma_read(struct tegra_dma *tdma, u32 reg)
|
|
|
|
{
|
|
|
|
return readl(tdma->base_addr + reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tdc_write(struct tegra_dma_channel *tdc,
|
2020-02-09 19:33:45 +03:00
|
|
|
u32 reg, u32 val)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
2015-08-06 16:32:31 +03:00
|
|
|
writel(val, tdc->chan_addr + reg);
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 tdc_read(struct tegra_dma_channel *tdc, u32 reg)
|
|
|
|
{
|
2015-08-06 16:32:31 +03:00
|
|
|
return readl(tdc->chan_addr + reg);
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct tegra_dma_channel *to_tegra_dma_chan(struct dma_chan *dc)
|
|
|
|
{
|
|
|
|
return container_of(dc, struct tegra_dma_channel, dma_chan);
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:33:45 +03:00
|
|
|
static inline struct tegra_dma_desc *
|
|
|
|
txd_to_tegra_dma_desc(struct dma_async_tx_descriptor *td)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
return container_of(td, struct tegra_dma_desc, txd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct device *tdc2dev(struct tegra_dma_channel *tdc)
|
|
|
|
{
|
|
|
|
return &tdc->dma_chan.dev->device;
|
|
|
|
}
|
|
|
|
|
|
|
|
static dma_cookie_t tegra_dma_tx_submit(struct dma_async_tx_descriptor *tx);
|
|
|
|
|
|
|
|
/* Get DMA desc from free list, if not there then allocate it. */
|
2020-02-09 19:33:45 +03:00
|
|
|
static struct tegra_dma_desc *tegra_dma_desc_get(struct tegra_dma_channel *tdc)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
struct tegra_dma_desc *dma_desc;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&tdc->lock, flags);
|
|
|
|
|
|
|
|
/* Do not allocate if desc are waiting for ack */
|
|
|
|
list_for_each_entry(dma_desc, &tdc->free_dma_desc, node) {
|
2020-02-09 19:33:39 +03:00
|
|
|
if (async_tx_test_ack(&dma_desc->txd) && !dma_desc->cb_count) {
|
2012-06-06 09:25:27 +04:00
|
|
|
list_del(&dma_desc->node);
|
|
|
|
spin_unlock_irqrestore(&tdc->lock, flags);
|
2013-01-09 13:56:22 +04:00
|
|
|
dma_desc->txd.flags = 0;
|
2012-06-06 09:25:27 +04:00
|
|
|
return dma_desc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&tdc->lock, flags);
|
|
|
|
|
|
|
|
/* Allocate DMA desc */
|
2015-11-13 19:39:42 +03:00
|
|
|
dma_desc = kzalloc(sizeof(*dma_desc), GFP_NOWAIT);
|
2016-06-07 20:38:41 +03:00
|
|
|
if (!dma_desc)
|
2012-06-06 09:25:27 +04:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dma_async_tx_descriptor_init(&dma_desc->txd, &tdc->dma_chan);
|
|
|
|
dma_desc->txd.tx_submit = tegra_dma_tx_submit;
|
|
|
|
dma_desc->txd.flags = 0;
|
2020-02-09 19:33:45 +03:00
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
return dma_desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tegra_dma_desc_put(struct tegra_dma_channel *tdc,
|
2020-02-09 19:33:45 +03:00
|
|
|
struct tegra_dma_desc *dma_desc)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&tdc->lock, flags);
|
|
|
|
if (!list_empty(&dma_desc->tx_list))
|
|
|
|
list_splice_init(&dma_desc->tx_list, &tdc->free_sg_req);
|
|
|
|
list_add_tail(&dma_desc->node, &tdc->free_dma_desc);
|
|
|
|
spin_unlock_irqrestore(&tdc->lock, flags);
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:33:45 +03:00
|
|
|
static struct tegra_dma_sg_req *
|
|
|
|
tegra_dma_sg_req_get(struct tegra_dma_channel *tdc)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
2020-02-09 19:33:45 +03:00
|
|
|
struct tegra_dma_sg_req *sg_req;
|
2012-06-06 09:25:27 +04:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&tdc->lock, flags);
|
|
|
|
if (!list_empty(&tdc->free_sg_req)) {
|
2020-02-09 19:33:45 +03:00
|
|
|
sg_req = list_first_entry(&tdc->free_sg_req, typeof(*sg_req),
|
|
|
|
node);
|
2012-06-06 09:25:27 +04:00
|
|
|
list_del(&sg_req->node);
|
|
|
|
spin_unlock_irqrestore(&tdc->lock, flags);
|
|
|
|
return sg_req;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&tdc->lock, flags);
|
|
|
|
|
2020-02-09 19:33:45 +03:00
|
|
|
sg_req = kzalloc(sizeof(*sg_req), GFP_NOWAIT);
|
2016-06-07 20:38:41 +03:00
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
return sg_req;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tegra_dma_slave_config(struct dma_chan *dc,
|
2020-02-09 19:33:45 +03:00
|
|
|
struct dma_slave_config *sconfig)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
|
|
|
|
|
|
|
|
if (!list_empty(&tdc->pending_sg_req)) {
|
|
|
|
dev_err(tdc2dev(tdc), "Configuration not allowed\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&tdc->dma_sconfig, sconfig, sizeof(*sconfig));
|
2017-11-16 20:11:06 +03:00
|
|
|
if (tdc->slave_id == TEGRA_APBDMA_SLAVE_ID_INVALID &&
|
|
|
|
sconfig->device_fc) {
|
2016-04-23 12:36:00 +03:00
|
|
|
if (sconfig->slave_id > TEGRA_APBDMA_CSR_REQ_SEL_MASK)
|
|
|
|
return -EINVAL;
|
2013-11-12 00:09:35 +04:00
|
|
|
tdc->slave_id = sconfig->slave_id;
|
2016-04-23 12:36:00 +03:00
|
|
|
}
|
2012-06-06 09:25:27 +04:00
|
|
|
tdc->config_init = true;
|
2020-02-09 19:33:45 +03:00
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tegra_dma_global_pause(struct tegra_dma_channel *tdc,
|
2020-02-09 19:33:45 +03:00
|
|
|
bool wait_for_burst_complete)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
struct tegra_dma *tdma = tdc->tdma;
|
|
|
|
|
|
|
|
spin_lock(&tdma->global_lock);
|
2015-08-06 16:32:33 +03:00
|
|
|
|
|
|
|
if (tdc->tdma->global_pause_count == 0) {
|
|
|
|
tdma_write(tdma, TEGRA_APBDMA_GENERAL, 0);
|
|
|
|
if (wait_for_burst_complete)
|
|
|
|
udelay(TEGRA_APBDMA_BURST_COMPLETE_TIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
tdc->tdma->global_pause_count++;
|
|
|
|
|
|
|
|
spin_unlock(&tdma->global_lock);
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tegra_dma_global_resume(struct tegra_dma_channel *tdc)
|
|
|
|
{
|
|
|
|
struct tegra_dma *tdma = tdc->tdma;
|
|
|
|
|
2015-08-06 16:32:33 +03:00
|
|
|
spin_lock(&tdma->global_lock);
|
|
|
|
|
|
|
|
if (WARN_ON(tdc->tdma->global_pause_count == 0))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (--tdc->tdma->global_pause_count == 0)
|
|
|
|
tdma_write(tdma, TEGRA_APBDMA_GENERAL,
|
|
|
|
TEGRA_APBDMA_GENERAL_ENABLE);
|
|
|
|
|
|
|
|
out:
|
2012-06-06 09:25:27 +04:00
|
|
|
spin_unlock(&tdma->global_lock);
|
|
|
|
}
|
|
|
|
|
2013-01-06 20:22:02 +04:00
|
|
|
static void tegra_dma_pause(struct tegra_dma_channel *tdc,
|
2020-02-09 19:33:45 +03:00
|
|
|
bool wait_for_burst_complete)
|
2013-01-06 20:22:02 +04:00
|
|
|
{
|
|
|
|
struct tegra_dma *tdma = tdc->tdma;
|
|
|
|
|
|
|
|
if (tdma->chip_data->support_channel_pause) {
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_CSRE,
|
2020-02-09 19:33:45 +03:00
|
|
|
TEGRA_APBDMA_CHAN_CSRE_PAUSE);
|
2013-01-06 20:22:02 +04:00
|
|
|
if (wait_for_burst_complete)
|
|
|
|
udelay(TEGRA_APBDMA_BURST_COMPLETE_TIME);
|
|
|
|
} else {
|
|
|
|
tegra_dma_global_pause(tdc, wait_for_burst_complete);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tegra_dma_resume(struct tegra_dma_channel *tdc)
|
|
|
|
{
|
|
|
|
struct tegra_dma *tdma = tdc->tdma;
|
|
|
|
|
2020-02-09 19:33:45 +03:00
|
|
|
if (tdma->chip_data->support_channel_pause)
|
2013-01-06 20:22:02 +04:00
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_CSRE, 0);
|
2020-02-09 19:33:45 +03:00
|
|
|
else
|
2013-01-06 20:22:02 +04:00
|
|
|
tegra_dma_global_resume(tdc);
|
|
|
|
}
|
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
static void tegra_dma_stop(struct tegra_dma_channel *tdc)
|
|
|
|
{
|
2020-02-09 19:33:45 +03:00
|
|
|
u32 csr, status;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
/* Disable interrupts */
|
|
|
|
csr = tdc_read(tdc, TEGRA_APBDMA_CHAN_CSR);
|
|
|
|
csr &= ~TEGRA_APBDMA_CSR_IE_EOC;
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR, csr);
|
|
|
|
|
|
|
|
/* Disable DMA */
|
|
|
|
csr &= ~TEGRA_APBDMA_CSR_ENB;
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR, csr);
|
|
|
|
|
|
|
|
/* Clear interrupt status if it is there */
|
|
|
|
status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
|
|
|
|
if (status & TEGRA_APBDMA_STATUS_ISE_EOC) {
|
|
|
|
dev_dbg(tdc2dev(tdc), "%s():clearing interrupt\n", __func__);
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_STATUS, status);
|
|
|
|
}
|
|
|
|
tdc->busy = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tegra_dma_start(struct tegra_dma_channel *tdc,
|
2020-02-09 19:33:45 +03:00
|
|
|
struct tegra_dma_sg_req *sg_req)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
struct tegra_dma_channel_regs *ch_regs = &sg_req->ch_regs;
|
|
|
|
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR, ch_regs->csr);
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_APBSEQ, ch_regs->apb_seq);
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_APBPTR, ch_regs->apb_ptr);
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_AHBSEQ, ch_regs->ahb_seq);
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_AHBPTR, ch_regs->ahb_ptr);
|
2014-01-06 22:16:45 +04:00
|
|
|
if (tdc->tdma->chip_data->support_separate_wcount_reg)
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_WCOUNT, ch_regs->wcount);
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
/* Start DMA */
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR,
|
2020-02-09 19:33:45 +03:00
|
|
|
ch_regs->csr | TEGRA_APBDMA_CSR_ENB);
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tegra_dma_configure_for_next(struct tegra_dma_channel *tdc,
|
2020-02-09 19:33:45 +03:00
|
|
|
struct tegra_dma_sg_req *nsg_req)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
unsigned long status;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The DMA controller reloads the new configuration for next transfer
|
|
|
|
* after last burst of current transfer completes.
|
|
|
|
* If there is no IEC status then this makes sure that last burst
|
|
|
|
* has not be completed. There may be case that last burst is on
|
|
|
|
* flight and so it can complete but because DMA is paused, it
|
|
|
|
* will not generates interrupt as well as not reload the new
|
|
|
|
* configuration.
|
|
|
|
* If there is already IEC status then interrupt handler need to
|
|
|
|
* load new configuration.
|
|
|
|
*/
|
2013-01-06 20:22:02 +04:00
|
|
|
tegra_dma_pause(tdc, false);
|
2016-06-14 17:18:46 +03:00
|
|
|
status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If interrupt is pending then do nothing as the ISR will handle
|
|
|
|
* the programing for new request.
|
|
|
|
*/
|
|
|
|
if (status & TEGRA_APBDMA_STATUS_ISE_EOC) {
|
|
|
|
dev_err(tdc2dev(tdc),
|
|
|
|
"Skipping new configuration as interrupt is pending\n");
|
2013-01-06 20:22:02 +04:00
|
|
|
tegra_dma_resume(tdc);
|
2012-06-06 09:25:27 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Safe to program new configuration */
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_APBPTR, nsg_req->ch_regs.apb_ptr);
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_AHBPTR, nsg_req->ch_regs.ahb_ptr);
|
2014-01-06 22:16:45 +04:00
|
|
|
if (tdc->tdma->chip_data->support_separate_wcount_reg)
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_WCOUNT,
|
2020-02-09 19:33:45 +03:00
|
|
|
nsg_req->ch_regs.wcount);
|
2012-06-06 09:25:27 +04:00
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR,
|
2020-02-09 19:33:45 +03:00
|
|
|
nsg_req->ch_regs.csr | TEGRA_APBDMA_CSR_ENB);
|
2012-06-06 09:25:27 +04:00
|
|
|
nsg_req->configured = true;
|
2019-07-05 18:05:19 +03:00
|
|
|
nsg_req->words_xferred = 0;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
2013-01-06 20:22:02 +04:00
|
|
|
tegra_dma_resume(tdc);
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tdc_start_head_req(struct tegra_dma_channel *tdc)
|
|
|
|
{
|
|
|
|
struct tegra_dma_sg_req *sg_req;
|
|
|
|
|
2020-02-09 19:33:45 +03:00
|
|
|
sg_req = list_first_entry(&tdc->pending_sg_req, typeof(*sg_req), node);
|
2012-06-06 09:25:27 +04:00
|
|
|
tegra_dma_start(tdc, sg_req);
|
|
|
|
sg_req->configured = true;
|
2019-07-05 18:05:19 +03:00
|
|
|
sg_req->words_xferred = 0;
|
2012-06-06 09:25:27 +04:00
|
|
|
tdc->busy = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tdc_configure_next_head_desc(struct tegra_dma_channel *tdc)
|
|
|
|
{
|
2020-02-09 19:33:45 +03:00
|
|
|
struct tegra_dma_sg_req *hsgreq, *hnsgreq;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
hsgreq = list_first_entry(&tdc->pending_sg_req, typeof(*hsgreq), node);
|
|
|
|
if (!list_is_last(&hsgreq->node, &tdc->pending_sg_req)) {
|
2020-02-09 19:33:45 +03:00
|
|
|
hnsgreq = list_first_entry(&hsgreq->node, typeof(*hnsgreq),
|
|
|
|
node);
|
2012-06-06 09:25:27 +04:00
|
|
|
tegra_dma_configure_for_next(tdc, hnsgreq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:33:45 +03:00
|
|
|
static inline unsigned int
|
|
|
|
get_current_xferred_count(struct tegra_dma_channel *tdc,
|
|
|
|
struct tegra_dma_sg_req *sg_req,
|
|
|
|
unsigned long status)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
return sg_req->req_len - (status & TEGRA_APBDMA_STATUS_COUNT_MASK) - 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tegra_dma_abort_all(struct tegra_dma_channel *tdc)
|
|
|
|
{
|
|
|
|
struct tegra_dma_desc *dma_desc;
|
2020-02-09 19:33:45 +03:00
|
|
|
struct tegra_dma_sg_req *sgreq;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
while (!list_empty(&tdc->pending_sg_req)) {
|
2020-02-09 19:33:45 +03:00
|
|
|
sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq),
|
|
|
|
node);
|
2012-09-05 11:08:56 +04:00
|
|
|
list_move_tail(&sgreq->node, &tdc->free_sg_req);
|
2012-06-06 09:25:27 +04:00
|
|
|
if (sgreq->last_sg) {
|
|
|
|
dma_desc = sgreq->dma_desc;
|
|
|
|
dma_desc->dma_status = DMA_ERROR;
|
|
|
|
list_add_tail(&dma_desc->node, &tdc->free_dma_desc);
|
|
|
|
|
|
|
|
/* Add in cb list if it is not there. */
|
|
|
|
if (!dma_desc->cb_count)
|
|
|
|
list_add_tail(&dma_desc->cb_node,
|
2020-02-09 19:33:45 +03:00
|
|
|
&tdc->cb_desc);
|
2012-06-06 09:25:27 +04:00
|
|
|
dma_desc->cb_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tdc->isr_handler = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool handle_continuous_head_request(struct tegra_dma_channel *tdc,
|
2020-02-09 19:33:45 +03:00
|
|
|
bool to_terminate)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
2020-02-09 19:33:45 +03:00
|
|
|
struct tegra_dma_sg_req *hsgreq;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that head req on list should be in flight.
|
|
|
|
* If it is not in flight then abort transfer as
|
|
|
|
* looping of transfer can not continue.
|
|
|
|
*/
|
|
|
|
hsgreq = list_first_entry(&tdc->pending_sg_req, typeof(*hsgreq), node);
|
|
|
|
if (!hsgreq->configured) {
|
|
|
|
tegra_dma_stop(tdc);
|
2020-02-09 19:33:49 +03:00
|
|
|
pm_runtime_put(tdc->tdma->dev);
|
2020-02-09 19:33:56 +03:00
|
|
|
dev_err(tdc2dev(tdc), "DMA transfer underflow, aborting DMA\n");
|
2012-06-06 09:25:27 +04:00
|
|
|
tegra_dma_abort_all(tdc);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure next request */
|
|
|
|
if (!to_terminate)
|
|
|
|
tdc_configure_next_head_desc(tdc);
|
2020-02-09 19:33:45 +03:00
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_once_dma_done(struct tegra_dma_channel *tdc,
|
2020-02-09 19:33:45 +03:00
|
|
|
bool to_terminate)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
struct tegra_dma_desc *dma_desc;
|
2020-02-09 19:33:45 +03:00
|
|
|
struct tegra_dma_sg_req *sgreq;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
tdc->busy = false;
|
|
|
|
sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq), node);
|
|
|
|
dma_desc = sgreq->dma_desc;
|
|
|
|
dma_desc->bytes_transferred += sgreq->req_len;
|
|
|
|
|
|
|
|
list_del(&sgreq->node);
|
|
|
|
if (sgreq->last_sg) {
|
2013-10-16 19:34:50 +04:00
|
|
|
dma_desc->dma_status = DMA_COMPLETE;
|
2012-06-06 09:25:27 +04:00
|
|
|
dma_cookie_complete(&dma_desc->txd);
|
|
|
|
if (!dma_desc->cb_count)
|
|
|
|
list_add_tail(&dma_desc->cb_node, &tdc->cb_desc);
|
|
|
|
dma_desc->cb_count++;
|
|
|
|
list_add_tail(&dma_desc->node, &tdc->free_dma_desc);
|
|
|
|
}
|
|
|
|
list_add_tail(&sgreq->node, &tdc->free_sg_req);
|
|
|
|
|
|
|
|
/* Do not start DMA if it is going to be terminate */
|
2020-02-09 19:33:49 +03:00
|
|
|
if (to_terminate)
|
2012-06-06 09:25:27 +04:00
|
|
|
return;
|
|
|
|
|
2020-02-09 19:33:49 +03:00
|
|
|
if (list_empty(&tdc->pending_sg_req)) {
|
|
|
|
pm_runtime_put(tdc->tdma->dev);
|
2012-06-06 09:25:27 +04:00
|
|
|
return;
|
2020-02-09 19:33:49 +03:00
|
|
|
}
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
tdc_start_head_req(tdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_cont_sngl_cycle_dma_done(struct tegra_dma_channel *tdc,
|
2020-02-09 19:33:45 +03:00
|
|
|
bool to_terminate)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
struct tegra_dma_desc *dma_desc;
|
2020-02-09 19:33:45 +03:00
|
|
|
struct tegra_dma_sg_req *sgreq;
|
2012-06-06 09:25:27 +04:00
|
|
|
bool st;
|
|
|
|
|
|
|
|
sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq), node);
|
|
|
|
dma_desc = sgreq->dma_desc;
|
2018-11-21 19:13:19 +03:00
|
|
|
/* if we dma for long enough the transfer count will wrap */
|
|
|
|
dma_desc->bytes_transferred =
|
|
|
|
(dma_desc->bytes_transferred + sgreq->req_len) %
|
|
|
|
dma_desc->bytes_requested;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
/* Callback need to be call */
|
|
|
|
if (!dma_desc->cb_count)
|
|
|
|
list_add_tail(&dma_desc->cb_node, &tdc->cb_desc);
|
|
|
|
dma_desc->cb_count++;
|
|
|
|
|
2019-07-05 18:05:19 +03:00
|
|
|
sgreq->words_xferred = 0;
|
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
/* If not last req then put at end of pending list */
|
|
|
|
if (!list_is_last(&sgreq->node, &tdc->pending_sg_req)) {
|
2012-09-05 11:08:56 +04:00
|
|
|
list_move_tail(&sgreq->node, &tdc->pending_sg_req);
|
2012-06-06 09:25:27 +04:00
|
|
|
sgreq->configured = false;
|
2020-02-09 19:33:55 +03:00
|
|
|
st = handle_continuous_head_request(tdc, to_terminate);
|
2012-06-06 09:25:27 +04:00
|
|
|
if (!st)
|
|
|
|
dma_desc->dma_status = DMA_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-31 13:35:34 +03:00
|
|
|
static void tegra_dma_tasklet(struct tasklet_struct *t)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
2020-08-31 13:35:34 +03:00
|
|
|
struct tegra_dma_channel *tdc = from_tasklet(tdc, t, tasklet);
|
2016-07-20 23:13:16 +03:00
|
|
|
struct dmaengine_desc_callback cb;
|
2012-06-06 09:25:27 +04:00
|
|
|
struct tegra_dma_desc *dma_desc;
|
2020-02-09 19:33:45 +03:00
|
|
|
unsigned int cb_count;
|
2012-06-06 09:25:27 +04:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&tdc->lock, flags);
|
|
|
|
while (!list_empty(&tdc->cb_desc)) {
|
2020-02-09 19:33:45 +03:00
|
|
|
dma_desc = list_first_entry(&tdc->cb_desc, typeof(*dma_desc),
|
|
|
|
cb_node);
|
2012-06-06 09:25:27 +04:00
|
|
|
list_del(&dma_desc->cb_node);
|
2016-07-20 23:13:16 +03:00
|
|
|
dmaengine_desc_get_callback(&dma_desc->txd, &cb);
|
2012-06-06 09:25:27 +04:00
|
|
|
cb_count = dma_desc->cb_count;
|
|
|
|
dma_desc->cb_count = 0;
|
2018-11-21 19:13:23 +03:00
|
|
|
trace_tegra_dma_complete_cb(&tdc->dma_chan, cb_count,
|
|
|
|
cb.callback);
|
2012-06-06 09:25:27 +04:00
|
|
|
spin_unlock_irqrestore(&tdc->lock, flags);
|
2016-07-20 23:13:16 +03:00
|
|
|
while (cb_count--)
|
|
|
|
dmaengine_desc_callback_invoke(&cb, NULL);
|
2012-06-06 09:25:27 +04:00
|
|
|
spin_lock_irqsave(&tdc->lock, flags);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&tdc->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t tegra_dma_isr(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct tegra_dma_channel *tdc = dev_id;
|
2020-02-09 19:33:45 +03:00
|
|
|
u32 status;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
2020-03-20 00:23:20 +03:00
|
|
|
spin_lock(&tdc->lock);
|
2012-06-06 09:25:27 +04:00
|
|
|
|
2018-11-21 19:13:23 +03:00
|
|
|
trace_tegra_dma_isr(&tdc->dma_chan, irq);
|
2012-06-06 09:25:27 +04:00
|
|
|
status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
|
|
|
|
if (status & TEGRA_APBDMA_STATUS_ISE_EOC) {
|
|
|
|
tdc_write(tdc, TEGRA_APBDMA_CHAN_STATUS, status);
|
|
|
|
tdc->isr_handler(tdc, false);
|
|
|
|
tasklet_schedule(&tdc->tasklet);
|
2020-03-20 00:23:21 +03:00
|
|
|
wake_up_all(&tdc->wq);
|
2020-03-20 00:23:20 +03:00
|
|
|
spin_unlock(&tdc->lock);
|
2012-06-06 09:25:27 +04:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2020-03-20 00:23:20 +03:00
|
|
|
spin_unlock(&tdc->lock);
|
2020-02-09 19:33:45 +03:00
|
|
|
dev_info(tdc2dev(tdc), "Interrupt already served status 0x%08x\n",
|
|
|
|
status);
|
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static dma_cookie_t tegra_dma_tx_submit(struct dma_async_tx_descriptor *txd)
|
|
|
|
{
|
|
|
|
struct tegra_dma_desc *dma_desc = txd_to_tegra_dma_desc(txd);
|
|
|
|
struct tegra_dma_channel *tdc = to_tegra_dma_chan(txd->chan);
|
|
|
|
unsigned long flags;
|
|
|
|
dma_cookie_t cookie;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&tdc->lock, flags);
|
|
|
|
dma_desc->dma_status = DMA_IN_PROGRESS;
|
|
|
|
cookie = dma_cookie_assign(&dma_desc->txd);
|
|
|
|
list_splice_tail_init(&dma_desc->tx_list, &tdc->pending_sg_req);
|
|
|
|
spin_unlock_irqrestore(&tdc->lock, flags);
|
2020-02-09 19:33:45 +03:00
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
return cookie;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tegra_dma_issue_pending(struct dma_chan *dc)
|
|
|
|
{
|
|
|
|
struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
|
|
|
|
unsigned long flags;
|
2020-02-09 19:33:49 +03:00
|
|
|
int err;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
spin_lock_irqsave(&tdc->lock, flags);
|
|
|
|
if (list_empty(&tdc->pending_sg_req)) {
|
|
|
|
dev_err(tdc2dev(tdc), "No DMA request\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (!tdc->busy) {
|
2020-02-09 19:33:49 +03:00
|
|
|
err = pm_runtime_get_sync(tdc->tdma->dev);
|
|
|
|
if (err < 0) {
|
|
|
|
dev_err(tdc2dev(tdc), "Failed to enable DMA\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
tdc_start_head_req(tdc);
|
|
|
|
|
|
|
|
/* Continuous single mode: Configure next req */
|
|
|
|
if (tdc->cyclic) {
|
|
|
|
/*
|
|
|
|
* Wait for 1 burst time for configure DMA for
|
|
|
|
* next transfer.
|
|
|
|
*/
|
|
|
|
udelay(TEGRA_APBDMA_BURST_COMPLETE_TIME);
|
|
|
|
tdc_configure_next_head_desc(tdc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
spin_unlock_irqrestore(&tdc->lock, flags);
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:00:17 +03:00
|
|
|
static int tegra_dma_terminate_all(struct dma_chan *dc)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
|
|
|
|
struct tegra_dma_desc *dma_desc;
|
2020-02-09 19:33:45 +03:00
|
|
|
struct tegra_dma_sg_req *sgreq;
|
2012-06-06 09:25:27 +04:00
|
|
|
unsigned long flags;
|
2020-02-09 19:33:45 +03:00
|
|
|
u32 status, wcount;
|
2012-06-06 09:25:27 +04:00
|
|
|
bool was_busy;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&tdc->lock, flags);
|
|
|
|
|
|
|
|
if (!tdc->busy)
|
|
|
|
goto skip_dma_stop;
|
|
|
|
|
|
|
|
/* Pause DMA before checking the queue status */
|
2013-01-06 20:22:02 +04:00
|
|
|
tegra_dma_pause(tdc, true);
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
|
|
|
|
if (status & TEGRA_APBDMA_STATUS_ISE_EOC) {
|
|
|
|
dev_dbg(tdc2dev(tdc), "%s():handling isr\n", __func__);
|
|
|
|
tdc->isr_handler(tdc, true);
|
|
|
|
status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
|
|
|
|
}
|
2014-01-06 22:16:45 +04:00
|
|
|
if (tdc->tdma->chip_data->support_separate_wcount_reg)
|
|
|
|
wcount = tdc_read(tdc, TEGRA_APBDMA_CHAN_WORD_TRANSFER);
|
|
|
|
else
|
|
|
|
wcount = status;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
was_busy = tdc->busy;
|
|
|
|
tegra_dma_stop(tdc);
|
|
|
|
|
|
|
|
if (!list_empty(&tdc->pending_sg_req) && was_busy) {
|
2020-02-09 19:33:45 +03:00
|
|
|
sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq),
|
|
|
|
node);
|
2012-06-06 09:25:27 +04:00
|
|
|
sgreq->dma_desc->bytes_transferred +=
|
2014-01-06 22:16:45 +04:00
|
|
|
get_current_xferred_count(tdc, sgreq, wcount);
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
2013-01-06 20:22:02 +04:00
|
|
|
tegra_dma_resume(tdc);
|
2012-06-06 09:25:27 +04:00
|
|
|
|
2020-02-09 19:33:49 +03:00
|
|
|
pm_runtime_put(tdc->tdma->dev);
|
2020-03-20 00:23:21 +03:00
|
|
|
wake_up_all(&tdc->wq);
|
2020-02-09 19:33:49 +03:00
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
skip_dma_stop:
|
|
|
|
tegra_dma_abort_all(tdc);
|
|
|
|
|
|
|
|
while (!list_empty(&tdc->cb_desc)) {
|
2020-02-09 19:33:45 +03:00
|
|
|
dma_desc = list_first_entry(&tdc->cb_desc, typeof(*dma_desc),
|
|
|
|
cb_node);
|
2012-06-06 09:25:27 +04:00
|
|
|
list_del(&dma_desc->cb_node);
|
|
|
|
dma_desc->cb_count = 0;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&tdc->lock, flags);
|
2020-02-09 19:33:45 +03:00
|
|
|
|
2014-12-08 09:00:17 +03:00
|
|
|
return 0;
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
|
|
|
|
2020-03-20 00:23:21 +03:00
|
|
|
static bool tegra_dma_eoc_interrupt_deasserted(struct tegra_dma_channel *tdc)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
u32 status;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&tdc->lock, flags);
|
|
|
|
status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
|
|
|
|
spin_unlock_irqrestore(&tdc->lock, flags);
|
|
|
|
|
|
|
|
return !(status & TEGRA_APBDMA_STATUS_ISE_EOC);
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:33:40 +03:00
|
|
|
static void tegra_dma_synchronize(struct dma_chan *dc)
|
|
|
|
{
|
|
|
|
struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
|
2020-04-26 22:08:35 +03:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = pm_runtime_get_sync(tdc->tdma->dev);
|
|
|
|
if (err < 0) {
|
|
|
|
dev_err(tdc2dev(tdc), "Failed to synchronize DMA: %d\n", err);
|
|
|
|
return;
|
|
|
|
}
|
2020-02-09 19:33:40 +03:00
|
|
|
|
2020-03-20 00:23:21 +03:00
|
|
|
/*
|
|
|
|
* CPU, which handles interrupt, could be busy in
|
|
|
|
* uninterruptible state, in this case sibling CPU
|
|
|
|
* should wait until interrupt is handled.
|
|
|
|
*/
|
|
|
|
wait_event(tdc->wq, tegra_dma_eoc_interrupt_deasserted(tdc));
|
|
|
|
|
2020-02-09 19:33:40 +03:00
|
|
|
tasklet_kill(&tdc->tasklet);
|
2020-04-26 22:08:35 +03:00
|
|
|
|
|
|
|
pm_runtime_put(tdc->tdma->dev);
|
2020-02-09 19:33:40 +03:00
|
|
|
}
|
|
|
|
|
2019-07-05 18:05:19 +03:00
|
|
|
static unsigned int tegra_dma_sg_bytes_xferred(struct tegra_dma_channel *tdc,
|
|
|
|
struct tegra_dma_sg_req *sg_req)
|
|
|
|
{
|
2020-02-09 19:33:45 +03:00
|
|
|
u32 status, wcount = 0;
|
2019-07-05 18:05:19 +03:00
|
|
|
|
|
|
|
if (!list_is_first(&sg_req->node, &tdc->pending_sg_req))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (tdc->tdma->chip_data->support_separate_wcount_reg)
|
|
|
|
wcount = tdc_read(tdc, TEGRA_APBDMA_CHAN_WORD_TRANSFER);
|
|
|
|
|
|
|
|
status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
|
|
|
|
|
|
|
|
if (!tdc->tdma->chip_data->support_separate_wcount_reg)
|
|
|
|
wcount = status;
|
|
|
|
|
|
|
|
if (status & TEGRA_APBDMA_STATUS_ISE_EOC)
|
|
|
|
return sg_req->req_len;
|
|
|
|
|
|
|
|
wcount = get_current_xferred_count(tdc, sg_req, wcount);
|
|
|
|
|
|
|
|
if (!wcount) {
|
|
|
|
/*
|
|
|
|
* If wcount wasn't ever polled for this SG before, then
|
|
|
|
* simply assume that transfer hasn't started yet.
|
|
|
|
*
|
|
|
|
* Otherwise it's the end of the transfer.
|
|
|
|
*
|
|
|
|
* The alternative would be to poll the status register
|
|
|
|
* until EOC bit is set or wcount goes UP. That's so
|
|
|
|
* because EOC bit is getting set only after the last
|
|
|
|
* burst's completion and counter is less than the actual
|
|
|
|
* transfer size by 4 bytes. The counter value wraps around
|
|
|
|
* in a cyclic mode before EOC is set(!), so we can't easily
|
|
|
|
* distinguish start of transfer from its end.
|
|
|
|
*/
|
|
|
|
if (sg_req->words_xferred)
|
|
|
|
wcount = sg_req->req_len - 4;
|
|
|
|
|
|
|
|
} else if (wcount < sg_req->words_xferred) {
|
|
|
|
/*
|
|
|
|
* This case will never happen for a non-cyclic transfer.
|
|
|
|
*
|
|
|
|
* For a cyclic transfer, although it is possible for the
|
|
|
|
* next transfer to have already started (resetting the word
|
|
|
|
* count), this case should still not happen because we should
|
|
|
|
* have detected that the EOC bit is set and hence the transfer
|
|
|
|
* was completed.
|
|
|
|
*/
|
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
|
|
|
|
wcount = sg_req->req_len - 4;
|
|
|
|
} else {
|
|
|
|
sg_req->words_xferred = wcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wcount;
|
|
|
|
}
|
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
static enum dma_status tegra_dma_tx_status(struct dma_chan *dc,
|
2020-02-09 19:33:45 +03:00
|
|
|
dma_cookie_t cookie,
|
|
|
|
struct dma_tx_state *txstate)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
|
|
|
|
struct tegra_dma_desc *dma_desc;
|
|
|
|
struct tegra_dma_sg_req *sg_req;
|
|
|
|
enum dma_status ret;
|
|
|
|
unsigned long flags;
|
2012-07-02 12:22:07 +04:00
|
|
|
unsigned int residual;
|
2019-07-05 18:05:19 +03:00
|
|
|
unsigned int bytes = 0;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
ret = dma_cookie_status(dc, cookie, txstate);
|
2016-06-29 19:08:39 +03:00
|
|
|
if (ret == DMA_COMPLETE)
|
2012-06-06 09:25:27 +04:00
|
|
|
return ret;
|
2013-05-27 16:14:39 +04:00
|
|
|
|
|
|
|
spin_lock_irqsave(&tdc->lock, flags);
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
/* Check on wait_ack desc status */
|
|
|
|
list_for_each_entry(dma_desc, &tdc->free_dma_desc, node) {
|
|
|
|
if (dma_desc->txd.cookie == cookie) {
|
|
|
|
ret = dma_desc->dma_status;
|
2016-06-29 19:08:38 +03:00
|
|
|
goto found;
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check in pending list */
|
|
|
|
list_for_each_entry(sg_req, &tdc->pending_sg_req, node) {
|
|
|
|
dma_desc = sg_req->dma_desc;
|
|
|
|
if (dma_desc->txd.cookie == cookie) {
|
2019-07-05 18:05:19 +03:00
|
|
|
bytes = tegra_dma_sg_bytes_xferred(tdc, sg_req);
|
2012-06-06 09:25:27 +04:00
|
|
|
ret = dma_desc->dma_status;
|
2016-06-29 19:08:38 +03:00
|
|
|
goto found;
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-29 19:08:37 +03:00
|
|
|
dev_dbg(tdc2dev(tdc), "cookie %d not found\n", cookie);
|
2016-06-29 19:08:38 +03:00
|
|
|
dma_desc = NULL;
|
|
|
|
|
|
|
|
found:
|
2016-06-29 19:08:39 +03:00
|
|
|
if (dma_desc && txstate) {
|
2016-06-29 19:08:38 +03:00
|
|
|
residual = dma_desc->bytes_requested -
|
2019-07-05 18:05:19 +03:00
|
|
|
((dma_desc->bytes_transferred + bytes) %
|
2016-06-29 19:08:38 +03:00
|
|
|
dma_desc->bytes_requested);
|
|
|
|
dma_set_residue(txstate, residual);
|
|
|
|
}
|
|
|
|
|
2018-11-21 19:13:23 +03:00
|
|
|
trace_tegra_dma_tx_status(&tdc->dma_chan, cookie, txstate);
|
2012-06-06 09:25:27 +04:00
|
|
|
spin_unlock_irqrestore(&tdc->lock, flags);
|
2020-02-09 19:33:45 +03:00
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:33:45 +03:00
|
|
|
static inline unsigned int get_bus_width(struct tegra_dma_channel *tdc,
|
|
|
|
enum dma_slave_buswidth slave_bw)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
switch (slave_bw) {
|
|
|
|
case DMA_SLAVE_BUSWIDTH_1_BYTE:
|
|
|
|
return TEGRA_APBDMA_APBSEQ_BUS_WIDTH_8;
|
|
|
|
case DMA_SLAVE_BUSWIDTH_2_BYTES:
|
|
|
|
return TEGRA_APBDMA_APBSEQ_BUS_WIDTH_16;
|
|
|
|
case DMA_SLAVE_BUSWIDTH_4_BYTES:
|
|
|
|
return TEGRA_APBDMA_APBSEQ_BUS_WIDTH_32;
|
|
|
|
case DMA_SLAVE_BUSWIDTH_8_BYTES:
|
|
|
|
return TEGRA_APBDMA_APBSEQ_BUS_WIDTH_64;
|
|
|
|
default:
|
|
|
|
dev_warn(tdc2dev(tdc),
|
2020-02-09 19:33:45 +03:00
|
|
|
"slave bw is not supported, using 32bits\n");
|
2012-06-06 09:25:27 +04:00
|
|
|
return TEGRA_APBDMA_APBSEQ_BUS_WIDTH_32;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:33:45 +03:00
|
|
|
static inline unsigned int get_burst_size(struct tegra_dma_channel *tdc,
|
|
|
|
u32 burst_size,
|
|
|
|
enum dma_slave_buswidth slave_bw,
|
|
|
|
u32 len)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
2020-02-09 19:33:45 +03:00
|
|
|
unsigned int burst_byte, burst_ahb_width;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* burst_size from client is in terms of the bus_width.
|
|
|
|
* convert them into AHB memory width which is 4 byte.
|
|
|
|
*/
|
|
|
|
burst_byte = burst_size * slave_bw;
|
|
|
|
burst_ahb_width = burst_byte / 4;
|
|
|
|
|
|
|
|
/* If burst size is 0 then calculate the burst size based on length */
|
|
|
|
if (!burst_ahb_width) {
|
|
|
|
if (len & 0xF)
|
|
|
|
return TEGRA_APBDMA_AHBSEQ_BURST_1;
|
|
|
|
else if ((len >> 4) & 0x1)
|
|
|
|
return TEGRA_APBDMA_AHBSEQ_BURST_4;
|
|
|
|
else
|
|
|
|
return TEGRA_APBDMA_AHBSEQ_BURST_8;
|
|
|
|
}
|
|
|
|
if (burst_ahb_width < 4)
|
|
|
|
return TEGRA_APBDMA_AHBSEQ_BURST_1;
|
|
|
|
else if (burst_ahb_width < 8)
|
|
|
|
return TEGRA_APBDMA_AHBSEQ_BURST_4;
|
|
|
|
else
|
|
|
|
return TEGRA_APBDMA_AHBSEQ_BURST_8;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_transfer_param(struct tegra_dma_channel *tdc,
|
2020-02-09 19:33:45 +03:00
|
|
|
enum dma_transfer_direction direction,
|
|
|
|
u32 *apb_addr,
|
|
|
|
u32 *apb_seq,
|
|
|
|
u32 *csr,
|
|
|
|
unsigned int *burst_size,
|
|
|
|
enum dma_slave_buswidth *slave_bw)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
switch (direction) {
|
|
|
|
case DMA_MEM_TO_DEV:
|
|
|
|
*apb_addr = tdc->dma_sconfig.dst_addr;
|
|
|
|
*apb_seq = get_bus_width(tdc, tdc->dma_sconfig.dst_addr_width);
|
|
|
|
*burst_size = tdc->dma_sconfig.dst_maxburst;
|
|
|
|
*slave_bw = tdc->dma_sconfig.dst_addr_width;
|
|
|
|
*csr = TEGRA_APBDMA_CSR_DIR;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case DMA_DEV_TO_MEM:
|
|
|
|
*apb_addr = tdc->dma_sconfig.src_addr;
|
|
|
|
*apb_seq = get_bus_width(tdc, tdc->dma_sconfig.src_addr_width);
|
|
|
|
*burst_size = tdc->dma_sconfig.src_maxburst;
|
|
|
|
*slave_bw = tdc->dma_sconfig.src_addr_width;
|
|
|
|
*csr = 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
2018-11-21 19:13:21 +03:00
|
|
|
dev_err(tdc2dev(tdc), "DMA direction is not supported\n");
|
2020-02-09 19:33:45 +03:00
|
|
|
break;
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
2020-02-09 19:33:45 +03:00
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-01-06 22:16:45 +04:00
|
|
|
static void tegra_dma_prep_wcount(struct tegra_dma_channel *tdc,
|
2020-02-09 19:33:45 +03:00
|
|
|
struct tegra_dma_channel_regs *ch_regs,
|
|
|
|
u32 len)
|
2014-01-06 22:16:45 +04:00
|
|
|
{
|
|
|
|
u32 len_field = (len - 4) & 0xFFFC;
|
|
|
|
|
|
|
|
if (tdc->tdma->chip_data->support_separate_wcount_reg)
|
|
|
|
ch_regs->wcount = len_field;
|
|
|
|
else
|
|
|
|
ch_regs->csr |= len_field;
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:33:45 +03:00
|
|
|
static struct dma_async_tx_descriptor *
|
|
|
|
tegra_dma_prep_slave_sg(struct dma_chan *dc,
|
|
|
|
struct scatterlist *sgl,
|
|
|
|
unsigned int sg_len,
|
|
|
|
enum dma_transfer_direction direction,
|
|
|
|
unsigned long flags,
|
|
|
|
void *context)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
|
2020-02-09 19:33:45 +03:00
|
|
|
struct tegra_dma_sg_req *sg_req = NULL;
|
|
|
|
u32 csr, ahb_seq, apb_ptr, apb_seq;
|
|
|
|
enum dma_slave_buswidth slave_bw;
|
2012-06-06 09:25:27 +04:00
|
|
|
struct tegra_dma_desc *dma_desc;
|
|
|
|
struct list_head req_list;
|
2020-02-09 19:33:45 +03:00
|
|
|
struct scatterlist *sg;
|
|
|
|
unsigned int burst_size;
|
|
|
|
unsigned int i;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
if (!tdc->config_init) {
|
2018-11-21 19:13:21 +03:00
|
|
|
dev_err(tdc2dev(tdc), "DMA channel is not configured\n");
|
2012-06-06 09:25:27 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (sg_len < 1) {
|
|
|
|
dev_err(tdc2dev(tdc), "Invalid segment length %d\n", sg_len);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-06 16:32:32 +03:00
|
|
|
if (get_transfer_param(tdc, direction, &apb_ptr, &apb_seq, &csr,
|
2020-02-09 19:33:45 +03:00
|
|
|
&burst_size, &slave_bw) < 0)
|
2012-06-06 09:25:27 +04:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&req_list);
|
|
|
|
|
|
|
|
ahb_seq = TEGRA_APBDMA_AHBSEQ_INTR_ENB;
|
|
|
|
ahb_seq |= TEGRA_APBDMA_AHBSEQ_WRAP_NONE <<
|
|
|
|
TEGRA_APBDMA_AHBSEQ_WRAP_SHIFT;
|
|
|
|
ahb_seq |= TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_32;
|
|
|
|
|
2017-11-16 20:11:06 +03:00
|
|
|
csr |= TEGRA_APBDMA_CSR_ONCE;
|
|
|
|
|
|
|
|
if (tdc->slave_id != TEGRA_APBDMA_SLAVE_ID_INVALID) {
|
|
|
|
csr |= TEGRA_APBDMA_CSR_FLOW;
|
|
|
|
csr |= tdc->slave_id << TEGRA_APBDMA_CSR_REQ_SEL_SHIFT;
|
|
|
|
}
|
|
|
|
|
2019-05-30 00:43:55 +03:00
|
|
|
if (flags & DMA_PREP_INTERRUPT) {
|
2012-06-06 09:25:27 +04:00
|
|
|
csr |= TEGRA_APBDMA_CSR_IE_EOC;
|
2019-05-30 00:43:55 +03:00
|
|
|
} else {
|
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
apb_seq |= TEGRA_APBDMA_APBSEQ_WRAP_WORD_1;
|
|
|
|
|
|
|
|
dma_desc = tegra_dma_desc_get(tdc);
|
|
|
|
if (!dma_desc) {
|
2018-11-21 19:13:21 +03:00
|
|
|
dev_err(tdc2dev(tdc), "DMA descriptors not available\n");
|
2012-06-06 09:25:27 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
INIT_LIST_HEAD(&dma_desc->tx_list);
|
|
|
|
INIT_LIST_HEAD(&dma_desc->cb_node);
|
|
|
|
dma_desc->cb_count = 0;
|
|
|
|
dma_desc->bytes_requested = 0;
|
|
|
|
dma_desc->bytes_transferred = 0;
|
|
|
|
dma_desc->dma_status = DMA_IN_PROGRESS;
|
|
|
|
|
|
|
|
/* Make transfer requests */
|
|
|
|
for_each_sg(sgl, sg, sg_len, i) {
|
|
|
|
u32 len, mem;
|
|
|
|
|
2012-06-22 19:11:10 +04:00
|
|
|
mem = sg_dma_address(sg);
|
2012-06-06 09:25:27 +04:00
|
|
|
len = sg_dma_len(sg);
|
|
|
|
|
|
|
|
if ((len & 3) || (mem & 3) ||
|
2020-02-09 19:33:45 +03:00
|
|
|
len > tdc->tdma->chip_data->max_dma_count) {
|
2012-06-06 09:25:27 +04:00
|
|
|
dev_err(tdc2dev(tdc),
|
2018-11-21 19:13:21 +03:00
|
|
|
"DMA length/memory address is not supported\n");
|
2012-06-06 09:25:27 +04:00
|
|
|
tegra_dma_desc_put(tdc, dma_desc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sg_req = tegra_dma_sg_req_get(tdc);
|
|
|
|
if (!sg_req) {
|
2018-11-21 19:13:21 +03:00
|
|
|
dev_err(tdc2dev(tdc), "DMA sg-req not available\n");
|
2012-06-06 09:25:27 +04:00
|
|
|
tegra_dma_desc_put(tdc, dma_desc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ahb_seq |= get_burst_size(tdc, burst_size, slave_bw, len);
|
|
|
|
dma_desc->bytes_requested += len;
|
|
|
|
|
|
|
|
sg_req->ch_regs.apb_ptr = apb_ptr;
|
|
|
|
sg_req->ch_regs.ahb_ptr = mem;
|
2014-01-06 22:16:45 +04:00
|
|
|
sg_req->ch_regs.csr = csr;
|
|
|
|
tegra_dma_prep_wcount(tdc, &sg_req->ch_regs, len);
|
2012-06-06 09:25:27 +04:00
|
|
|
sg_req->ch_regs.apb_seq = apb_seq;
|
|
|
|
sg_req->ch_regs.ahb_seq = ahb_seq;
|
|
|
|
sg_req->configured = false;
|
|
|
|
sg_req->last_sg = false;
|
|
|
|
sg_req->dma_desc = dma_desc;
|
|
|
|
sg_req->req_len = len;
|
|
|
|
|
|
|
|
list_add_tail(&sg_req->node, &dma_desc->tx_list);
|
|
|
|
}
|
|
|
|
sg_req->last_sg = true;
|
|
|
|
if (flags & DMA_CTRL_ACK)
|
|
|
|
dma_desc->txd.flags = DMA_CTRL_ACK;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that mode should not be conflicting with currently
|
|
|
|
* configured mode.
|
|
|
|
*/
|
|
|
|
if (!tdc->isr_handler) {
|
|
|
|
tdc->isr_handler = handle_once_dma_done;
|
|
|
|
tdc->cyclic = false;
|
|
|
|
} else {
|
|
|
|
if (tdc->cyclic) {
|
|
|
|
dev_err(tdc2dev(tdc), "DMA configured in cyclic mode\n");
|
|
|
|
tegra_dma_desc_put(tdc, dma_desc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &dma_desc->txd;
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:33:45 +03:00
|
|
|
static struct dma_async_tx_descriptor *
|
|
|
|
tegra_dma_prep_dma_cyclic(struct dma_chan *dc, dma_addr_t buf_addr,
|
|
|
|
size_t buf_len,
|
|
|
|
size_t period_len,
|
|
|
|
enum dma_transfer_direction direction,
|
|
|
|
unsigned long flags)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
|
2016-06-14 17:18:46 +03:00
|
|
|
struct tegra_dma_sg_req *sg_req = NULL;
|
2020-02-09 19:33:45 +03:00
|
|
|
u32 csr, ahb_seq, apb_ptr, apb_seq;
|
2012-06-06 09:25:27 +04:00
|
|
|
enum dma_slave_buswidth slave_bw;
|
2020-02-09 19:33:45 +03:00
|
|
|
struct tegra_dma_desc *dma_desc;
|
|
|
|
dma_addr_t mem = buf_addr;
|
|
|
|
unsigned int burst_size;
|
|
|
|
size_t len, remain_len;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
if (!buf_len || !period_len) {
|
|
|
|
dev_err(tdc2dev(tdc), "Invalid buffer/period len\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tdc->config_init) {
|
|
|
|
dev_err(tdc2dev(tdc), "DMA slave is not configured\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We allow to take more number of requests till DMA is
|
|
|
|
* not started. The driver will loop over all requests.
|
|
|
|
* Once DMA is started then new requests can be queued only after
|
|
|
|
* terminating the DMA.
|
|
|
|
*/
|
|
|
|
if (tdc->busy) {
|
2018-11-21 19:13:21 +03:00
|
|
|
dev_err(tdc2dev(tdc), "Request not allowed when DMA running\n");
|
2012-06-06 09:25:27 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We only support cycle transfer when buf_len is multiple of
|
|
|
|
* period_len.
|
|
|
|
*/
|
|
|
|
if (buf_len % period_len) {
|
|
|
|
dev_err(tdc2dev(tdc), "buf_len is not multiple of period_len\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = period_len;
|
|
|
|
if ((len & 3) || (buf_addr & 3) ||
|
2020-02-09 19:33:45 +03:00
|
|
|
len > tdc->tdma->chip_data->max_dma_count) {
|
2012-06-06 09:25:27 +04:00
|
|
|
dev_err(tdc2dev(tdc), "Req len/mem address is not correct\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-06 16:32:32 +03:00
|
|
|
if (get_transfer_param(tdc, direction, &apb_ptr, &apb_seq, &csr,
|
2020-02-09 19:33:45 +03:00
|
|
|
&burst_size, &slave_bw) < 0)
|
2012-06-06 09:25:27 +04:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ahb_seq = TEGRA_APBDMA_AHBSEQ_INTR_ENB;
|
|
|
|
ahb_seq |= TEGRA_APBDMA_AHBSEQ_WRAP_NONE <<
|
|
|
|
TEGRA_APBDMA_AHBSEQ_WRAP_SHIFT;
|
|
|
|
ahb_seq |= TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_32;
|
|
|
|
|
2017-11-16 20:11:06 +03:00
|
|
|
if (tdc->slave_id != TEGRA_APBDMA_SLAVE_ID_INVALID) {
|
|
|
|
csr |= TEGRA_APBDMA_CSR_FLOW;
|
|
|
|
csr |= tdc->slave_id << TEGRA_APBDMA_CSR_REQ_SEL_SHIFT;
|
|
|
|
}
|
|
|
|
|
2019-05-30 00:43:55 +03:00
|
|
|
if (flags & DMA_PREP_INTERRUPT) {
|
2013-01-09 13:56:22 +04:00
|
|
|
csr |= TEGRA_APBDMA_CSR_IE_EOC;
|
2019-05-30 00:43:55 +03:00
|
|
|
} else {
|
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
apb_seq |= TEGRA_APBDMA_APBSEQ_WRAP_WORD_1;
|
|
|
|
|
|
|
|
dma_desc = tegra_dma_desc_get(tdc);
|
|
|
|
if (!dma_desc) {
|
|
|
|
dev_err(tdc2dev(tdc), "not enough descriptors available\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&dma_desc->tx_list);
|
|
|
|
INIT_LIST_HEAD(&dma_desc->cb_node);
|
|
|
|
dma_desc->cb_count = 0;
|
|
|
|
|
|
|
|
dma_desc->bytes_transferred = 0;
|
|
|
|
dma_desc->bytes_requested = buf_len;
|
|
|
|
remain_len = buf_len;
|
|
|
|
|
|
|
|
/* Split transfer equal to period size */
|
|
|
|
while (remain_len) {
|
|
|
|
sg_req = tegra_dma_sg_req_get(tdc);
|
|
|
|
if (!sg_req) {
|
2018-11-21 19:13:21 +03:00
|
|
|
dev_err(tdc2dev(tdc), "DMA sg-req not available\n");
|
2012-06-06 09:25:27 +04:00
|
|
|
tegra_dma_desc_put(tdc, dma_desc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ahb_seq |= get_burst_size(tdc, burst_size, slave_bw, len);
|
|
|
|
sg_req->ch_regs.apb_ptr = apb_ptr;
|
|
|
|
sg_req->ch_regs.ahb_ptr = mem;
|
2014-01-06 22:16:45 +04:00
|
|
|
sg_req->ch_regs.csr = csr;
|
|
|
|
tegra_dma_prep_wcount(tdc, &sg_req->ch_regs, len);
|
2012-06-06 09:25:27 +04:00
|
|
|
sg_req->ch_regs.apb_seq = apb_seq;
|
|
|
|
sg_req->ch_regs.ahb_seq = ahb_seq;
|
|
|
|
sg_req->configured = false;
|
|
|
|
sg_req->last_sg = false;
|
|
|
|
sg_req->dma_desc = dma_desc;
|
|
|
|
sg_req->req_len = len;
|
|
|
|
|
|
|
|
list_add_tail(&sg_req->node, &dma_desc->tx_list);
|
|
|
|
remain_len -= len;
|
|
|
|
mem += len;
|
|
|
|
}
|
|
|
|
sg_req->last_sg = true;
|
2013-01-09 13:56:22 +04:00
|
|
|
if (flags & DMA_CTRL_ACK)
|
|
|
|
dma_desc->txd.flags = DMA_CTRL_ACK;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that mode should not be conflicting with currently
|
|
|
|
* configured mode.
|
|
|
|
*/
|
|
|
|
if (!tdc->isr_handler) {
|
|
|
|
tdc->isr_handler = handle_cont_sngl_cycle_dma_done;
|
|
|
|
tdc->cyclic = true;
|
|
|
|
} else {
|
|
|
|
if (!tdc->cyclic) {
|
|
|
|
dev_err(tdc2dev(tdc), "DMA configuration conflict\n");
|
|
|
|
tegra_dma_desc_put(tdc, dma_desc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &dma_desc->txd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tegra_dma_alloc_chan_resources(struct dma_chan *dc)
|
|
|
|
{
|
|
|
|
struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
|
|
|
|
|
|
|
|
dma_cookie_init(&tdc->dma_chan);
|
2015-11-13 19:39:38 +03:00
|
|
|
|
|
|
|
return 0;
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tegra_dma_free_chan_resources(struct dma_chan *dc)
|
|
|
|
{
|
|
|
|
struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
|
|
|
|
struct tegra_dma_desc *dma_desc;
|
|
|
|
struct tegra_dma_sg_req *sg_req;
|
|
|
|
struct list_head dma_desc_list;
|
|
|
|
struct list_head sg_req_list;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&dma_desc_list);
|
|
|
|
INIT_LIST_HEAD(&sg_req_list);
|
|
|
|
|
|
|
|
dev_dbg(tdc2dev(tdc), "Freeing channel %d\n", tdc->id);
|
|
|
|
|
2020-02-09 19:33:41 +03:00
|
|
|
tegra_dma_terminate_all(dc);
|
2020-02-09 19:33:42 +03:00
|
|
|
tasklet_kill(&tdc->tasklet);
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
list_splice_init(&tdc->pending_sg_req, &sg_req_list);
|
|
|
|
list_splice_init(&tdc->free_sg_req, &sg_req_list);
|
|
|
|
list_splice_init(&tdc->free_dma_desc, &dma_desc_list);
|
|
|
|
INIT_LIST_HEAD(&tdc->cb_desc);
|
|
|
|
tdc->config_init = false;
|
2013-05-11 20:30:53 +04:00
|
|
|
tdc->isr_handler = NULL;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
while (!list_empty(&dma_desc_list)) {
|
2020-02-09 19:33:45 +03:00
|
|
|
dma_desc = list_first_entry(&dma_desc_list, typeof(*dma_desc),
|
|
|
|
node);
|
2012-06-06 09:25:27 +04:00
|
|
|
list_del(&dma_desc->node);
|
|
|
|
kfree(dma_desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!list_empty(&sg_req_list)) {
|
|
|
|
sg_req = list_first_entry(&sg_req_list, typeof(*sg_req), node);
|
|
|
|
list_del(&sg_req->node);
|
|
|
|
kfree(sg_req);
|
|
|
|
}
|
2013-11-12 00:09:35 +04:00
|
|
|
|
2016-04-23 12:36:00 +03:00
|
|
|
tdc->slave_id = TEGRA_APBDMA_SLAVE_ID_INVALID;
|
2013-11-12 00:09:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct dma_chan *tegra_dma_of_xlate(struct of_phandle_args *dma_spec,
|
|
|
|
struct of_dma *ofdma)
|
|
|
|
{
|
|
|
|
struct tegra_dma *tdma = ofdma->of_dma_data;
|
|
|
|
struct tegra_dma_channel *tdc;
|
2020-02-09 19:33:45 +03:00
|
|
|
struct dma_chan *chan;
|
2013-11-12 00:09:35 +04:00
|
|
|
|
2016-04-23 12:36:00 +03:00
|
|
|
if (dma_spec->args[0] > TEGRA_APBDMA_CSR_REQ_SEL_MASK) {
|
|
|
|
dev_err(tdma->dev, "Invalid slave id: %d\n", dma_spec->args[0]);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-11-12 00:09:35 +04:00
|
|
|
chan = dma_get_any_slave_channel(&tdma->dma_dev);
|
|
|
|
if (!chan)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tdc = to_tegra_dma_chan(chan);
|
|
|
|
tdc->slave_id = dma_spec->args[0];
|
|
|
|
|
|
|
|
return chan;
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Tegra20 specific DMA controller information */
|
2012-08-29 12:31:18 +04:00
|
|
|
static const struct tegra_dma_chip_data tegra20_dma_chip_data = {
|
2012-06-06 09:25:27 +04:00
|
|
|
.nr_channels = 16,
|
2014-01-06 22:16:45 +04:00
|
|
|
.channel_reg_size = 0x20,
|
2012-06-06 09:25:27 +04:00
|
|
|
.max_dma_count = 1024UL * 64,
|
2013-01-06 20:22:02 +04:00
|
|
|
.support_channel_pause = false,
|
2014-01-06 22:16:45 +04:00
|
|
|
.support_separate_wcount_reg = false,
|
2012-06-06 09:25:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Tegra30 specific DMA controller information */
|
2012-08-29 12:31:18 +04:00
|
|
|
static const struct tegra_dma_chip_data tegra30_dma_chip_data = {
|
2012-06-06 09:25:27 +04:00
|
|
|
.nr_channels = 32,
|
2014-01-06 22:16:45 +04:00
|
|
|
.channel_reg_size = 0x20,
|
2012-06-06 09:25:27 +04:00
|
|
|
.max_dma_count = 1024UL * 64,
|
2013-01-06 20:22:02 +04:00
|
|
|
.support_channel_pause = false,
|
2014-01-06 22:16:45 +04:00
|
|
|
.support_separate_wcount_reg = false,
|
2012-06-06 09:25:27 +04:00
|
|
|
};
|
|
|
|
|
2013-01-06 20:22:03 +04:00
|
|
|
/* Tegra114 specific DMA controller information */
|
|
|
|
static const struct tegra_dma_chip_data tegra114_dma_chip_data = {
|
|
|
|
.nr_channels = 32,
|
2014-01-06 22:16:45 +04:00
|
|
|
.channel_reg_size = 0x20,
|
2013-01-06 20:22:03 +04:00
|
|
|
.max_dma_count = 1024UL * 64,
|
|
|
|
.support_channel_pause = true,
|
2014-01-06 22:16:45 +04:00
|
|
|
.support_separate_wcount_reg = false,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Tegra148 specific DMA controller information */
|
|
|
|
static const struct tegra_dma_chip_data tegra148_dma_chip_data = {
|
|
|
|
.nr_channels = 32,
|
|
|
|
.channel_reg_size = 0x40,
|
|
|
|
.max_dma_count = 1024UL * 64,
|
|
|
|
.support_channel_pause = true,
|
|
|
|
.support_separate_wcount_reg = true,
|
2013-01-06 20:22:03 +04:00
|
|
|
};
|
|
|
|
|
2020-02-09 19:33:50 +03:00
|
|
|
static int tegra_dma_init_hw(struct tegra_dma *tdma)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = reset_control_assert(tdma->rst);
|
|
|
|
if (err) {
|
|
|
|
dev_err(tdma->dev, "failed to assert reset: %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = clk_enable(tdma->dma_clk);
|
|
|
|
if (err) {
|
|
|
|
dev_err(tdma->dev, "failed to enable clk: %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset DMA controller */
|
|
|
|
udelay(2);
|
|
|
|
reset_control_deassert(tdma->rst);
|
|
|
|
|
|
|
|
/* enable global DMA registers */
|
|
|
|
tdma_write(tdma, TEGRA_APBDMA_GENERAL, TEGRA_APBDMA_GENERAL_ENABLE);
|
|
|
|
tdma_write(tdma, TEGRA_APBDMA_CONTROL, 0);
|
|
|
|
tdma_write(tdma, TEGRA_APBDMA_IRQ_MASK_SET, 0xFFFFFFFF);
|
|
|
|
|
|
|
|
clk_disable(tdma->dma_clk);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-19 22:22:55 +04:00
|
|
|
static int tegra_dma_probe(struct platform_device *pdev)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
2020-02-09 19:33:45 +03:00
|
|
|
const struct tegra_dma_chip_data *cdata;
|
2012-06-06 09:25:27 +04:00
|
|
|
struct tegra_dma *tdma;
|
2020-02-09 19:33:45 +03:00
|
|
|
unsigned int i;
|
|
|
|
size_t size;
|
2012-06-06 09:25:27 +04:00
|
|
|
int ret;
|
|
|
|
|
2016-03-01 16:24:40 +03:00
|
|
|
cdata = of_device_get_match_data(&pdev->dev);
|
2020-02-09 19:33:45 +03:00
|
|
|
size = struct_size(tdma, channels, cdata->nr_channels);
|
2012-06-06 09:25:27 +04:00
|
|
|
|
2020-02-09 19:33:45 +03:00
|
|
|
tdma = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
|
2016-06-07 20:38:41 +03:00
|
|
|
if (!tdma)
|
2012-06-06 09:25:27 +04:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
tdma->dev = &pdev->dev;
|
|
|
|
tdma->chip_data = cdata;
|
|
|
|
platform_set_drvdata(pdev, tdma);
|
|
|
|
|
2020-02-09 19:33:43 +03:00
|
|
|
tdma->base_addr = devm_platform_ioremap_resource(pdev, 0);
|
2013-01-21 14:09:00 +04:00
|
|
|
if (IS_ERR(tdma->base_addr))
|
|
|
|
return PTR_ERR(tdma->base_addr);
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
tdma->dma_clk = devm_clk_get(&pdev->dev, NULL);
|
|
|
|
if (IS_ERR(tdma->dma_clk)) {
|
|
|
|
dev_err(&pdev->dev, "Error: Missing controller clock\n");
|
|
|
|
return PTR_ERR(tdma->dma_clk);
|
|
|
|
}
|
|
|
|
|
2013-11-07 03:35:34 +04:00
|
|
|
tdma->rst = devm_reset_control_get(&pdev->dev, "dma");
|
|
|
|
if (IS_ERR(tdma->rst)) {
|
|
|
|
dev_err(&pdev->dev, "Error: Missing reset\n");
|
|
|
|
return PTR_ERR(tdma->rst);
|
|
|
|
}
|
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
spin_lock_init(&tdma->global_lock);
|
|
|
|
|
2020-02-09 19:33:49 +03:00
|
|
|
ret = clk_prepare(tdma->dma_clk);
|
|
|
|
if (ret)
|
2015-11-13 19:39:38 +03:00
|
|
|
return ret;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
2020-02-09 19:33:50 +03:00
|
|
|
ret = tegra_dma_init_hw(tdma);
|
|
|
|
if (ret)
|
|
|
|
goto err_clk_unprepare;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
2020-02-09 19:33:49 +03:00
|
|
|
pm_runtime_irq_safe(&pdev->dev);
|
2012-06-06 09:25:27 +04:00
|
|
|
pm_runtime_enable(&pdev->dev);
|
2012-07-20 12:01:08 +04:00
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
INIT_LIST_HEAD(&tdma->dma_dev.channels);
|
|
|
|
for (i = 0; i < cdata->nr_channels; i++) {
|
|
|
|
struct tegra_dma_channel *tdc = &tdma->channels[i];
|
2020-02-09 19:33:44 +03:00
|
|
|
int irq;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
2015-08-06 16:32:31 +03:00
|
|
|
tdc->chan_addr = tdma->base_addr +
|
|
|
|
TEGRA_APBDMA_CHANNEL_BASE_ADD_OFFSET +
|
|
|
|
(i * cdata->channel_reg_size);
|
2012-06-06 09:25:27 +04:00
|
|
|
|
2020-02-09 19:33:44 +03:00
|
|
|
irq = platform_get_irq(pdev, i);
|
|
|
|
if (irq < 0) {
|
|
|
|
ret = irq;
|
|
|
|
goto err_pm_disable;
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
2020-02-09 19:33:44 +03:00
|
|
|
|
2012-10-03 21:18:07 +04:00
|
|
|
snprintf(tdc->name, sizeof(tdc->name), "apbdma.%d", i);
|
2020-02-09 19:33:44 +03:00
|
|
|
ret = devm_request_irq(&pdev->dev, irq, tegra_dma_isr, 0,
|
|
|
|
tdc->name, tdc);
|
2012-06-06 09:25:27 +04:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"request_irq failed with err %d channel %d\n",
|
2013-05-11 20:30:52 +04:00
|
|
|
ret, i);
|
2020-02-09 19:33:44 +03:00
|
|
|
goto err_pm_disable;
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
tdc->dma_chan.device = &tdma->dma_dev;
|
|
|
|
dma_cookie_init(&tdc->dma_chan);
|
|
|
|
list_add_tail(&tdc->dma_chan.device_node,
|
2020-02-09 19:33:45 +03:00
|
|
|
&tdma->dma_dev.channels);
|
2012-06-06 09:25:27 +04:00
|
|
|
tdc->tdma = tdma;
|
|
|
|
tdc->id = i;
|
2016-04-23 12:36:00 +03:00
|
|
|
tdc->slave_id = TEGRA_APBDMA_SLAVE_ID_INVALID;
|
2012-06-06 09:25:27 +04:00
|
|
|
|
2020-08-31 13:35:34 +03:00
|
|
|
tasklet_setup(&tdc->tasklet, tegra_dma_tasklet);
|
2012-06-06 09:25:27 +04:00
|
|
|
spin_lock_init(&tdc->lock);
|
2020-03-20 00:23:21 +03:00
|
|
|
init_waitqueue_head(&tdc->wq);
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&tdc->pending_sg_req);
|
|
|
|
INIT_LIST_HEAD(&tdc->free_sg_req);
|
|
|
|
INIT_LIST_HEAD(&tdc->free_dma_desc);
|
|
|
|
INIT_LIST_HEAD(&tdc->cb_desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
dma_cap_set(DMA_SLAVE, tdma->dma_dev.cap_mask);
|
|
|
|
dma_cap_set(DMA_PRIVATE, tdma->dma_dev.cap_mask);
|
2012-06-22 15:42:43 +04:00
|
|
|
dma_cap_set(DMA_CYCLIC, tdma->dma_dev.cap_mask);
|
|
|
|
|
2015-08-06 16:32:33 +03:00
|
|
|
tdma->global_pause_count = 0;
|
2012-06-06 09:25:27 +04:00
|
|
|
tdma->dma_dev.dev = &pdev->dev;
|
|
|
|
tdma->dma_dev.device_alloc_chan_resources =
|
|
|
|
tegra_dma_alloc_chan_resources;
|
|
|
|
tdma->dma_dev.device_free_chan_resources =
|
|
|
|
tegra_dma_free_chan_resources;
|
|
|
|
tdma->dma_dev.device_prep_slave_sg = tegra_dma_prep_slave_sg;
|
|
|
|
tdma->dma_dev.device_prep_dma_cyclic = tegra_dma_prep_dma_cyclic;
|
2015-01-06 09:44:56 +03:00
|
|
|
tdma->dma_dev.src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) |
|
|
|
|
BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) |
|
|
|
|
BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) |
|
|
|
|
BIT(DMA_SLAVE_BUSWIDTH_8_BYTES);
|
|
|
|
tdma->dma_dev.dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) |
|
|
|
|
BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) |
|
|
|
|
BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) |
|
|
|
|
BIT(DMA_SLAVE_BUSWIDTH_8_BYTES);
|
|
|
|
tdma->dma_dev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
|
2019-07-05 18:05:19 +03:00
|
|
|
tdma->dma_dev.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
|
2014-11-17 16:42:37 +03:00
|
|
|
tdma->dma_dev.device_config = tegra_dma_slave_config;
|
|
|
|
tdma->dma_dev.device_terminate_all = tegra_dma_terminate_all;
|
2020-02-09 19:33:40 +03:00
|
|
|
tdma->dma_dev.device_synchronize = tegra_dma_synchronize;
|
2012-06-06 09:25:27 +04:00
|
|
|
tdma->dma_dev.device_tx_status = tegra_dma_tx_status;
|
|
|
|
tdma->dma_dev.device_issue_pending = tegra_dma_issue_pending;
|
|
|
|
|
|
|
|
ret = dma_async_device_register(&tdma->dma_dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"Tegra20 APB DMA driver registration failed %d\n", ret);
|
2020-02-09 19:33:44 +03:00
|
|
|
goto err_pm_disable;
|
2012-06-06 09:25:27 +04:00
|
|
|
}
|
|
|
|
|
2013-11-12 00:09:35 +04:00
|
|
|
ret = of_dma_controller_register(pdev->dev.of_node,
|
|
|
|
tegra_dma_of_xlate, tdma);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"Tegra20 APB DMA OF registration failed %d\n", ret);
|
|
|
|
goto err_unregister_dma_dev;
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:33:45 +03:00
|
|
|
dev_info(&pdev->dev, "Tegra20 APB DMA driver registered %u channels\n",
|
|
|
|
cdata->nr_channels);
|
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
return 0;
|
|
|
|
|
2013-11-12 00:09:35 +04:00
|
|
|
err_unregister_dma_dev:
|
|
|
|
dma_async_device_unregister(&tdma->dma_dev);
|
2012-06-06 09:25:27 +04:00
|
|
|
|
2020-02-09 19:33:44 +03:00
|
|
|
err_pm_disable:
|
2012-06-06 09:25:27 +04:00
|
|
|
pm_runtime_disable(&pdev->dev);
|
2020-02-09 19:33:50 +03:00
|
|
|
|
|
|
|
err_clk_unprepare:
|
2020-02-09 19:33:49 +03:00
|
|
|
clk_unprepare(tdma->dma_clk);
|
2020-02-09 19:33:45 +03:00
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-22 03:09:59 +04:00
|
|
|
static int tegra_dma_remove(struct platform_device *pdev)
|
2012-06-06 09:25:27 +04:00
|
|
|
{
|
|
|
|
struct tegra_dma *tdma = platform_get_drvdata(pdev);
|
|
|
|
|
2020-02-09 19:33:51 +03:00
|
|
|
of_dma_controller_free(pdev->dev.of_node);
|
2012-06-06 09:25:27 +04:00
|
|
|
dma_async_device_unregister(&tdma->dma_dev);
|
|
|
|
pm_runtime_disable(&pdev->dev);
|
2020-02-09 19:33:49 +03:00
|
|
|
clk_unprepare(tdma->dma_clk);
|
2012-06-06 09:25:27 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-20 10:13:37 +03:00
|
|
|
static int __maybe_unused tegra_dma_runtime_suspend(struct device *dev)
|
2013-04-24 13:54:27 +04:00
|
|
|
{
|
|
|
|
struct tegra_dma *tdma = dev_get_drvdata(dev);
|
|
|
|
|
2020-02-09 19:33:49 +03:00
|
|
|
clk_disable(tdma->dma_clk);
|
2017-06-06 15:49:29 +03:00
|
|
|
|
2013-04-24 13:54:27 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-20 10:13:37 +03:00
|
|
|
static int __maybe_unused tegra_dma_runtime_resume(struct device *dev)
|
2013-04-24 13:54:27 +04:00
|
|
|
{
|
|
|
|
struct tegra_dma *tdma = dev_get_drvdata(dev);
|
|
|
|
|
2020-02-09 19:33:50 +03:00
|
|
|
return clk_enable(tdma->dma_clk);
|
|
|
|
}
|
2013-04-24 13:54:27 +04:00
|
|
|
|
2020-02-09 19:33:50 +03:00
|
|
|
static int __maybe_unused tegra_dma_dev_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct tegra_dma *tdma = dev_get_drvdata(dev);
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int i;
|
|
|
|
bool busy;
|
2013-04-24 13:54:27 +04:00
|
|
|
|
|
|
|
for (i = 0; i < tdma->chip_data->nr_channels; i++) {
|
|
|
|
struct tegra_dma_channel *tdc = &tdma->channels[i];
|
2020-02-09 19:33:50 +03:00
|
|
|
|
|
|
|
tasklet_kill(&tdc->tasklet);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&tdc->lock, flags);
|
|
|
|
busy = tdc->busy;
|
|
|
|
spin_unlock_irqrestore(&tdc->lock, flags);
|
|
|
|
|
|
|
|
if (busy) {
|
|
|
|
dev_err(tdma->dev, "channel %u busy\n", i);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
2013-04-24 13:54:27 +04:00
|
|
|
}
|
|
|
|
|
2020-02-09 19:33:50 +03:00
|
|
|
return pm_runtime_force_suspend(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __maybe_unused tegra_dma_dev_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct tegra_dma *tdma = dev_get_drvdata(dev);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = tegra_dma_init_hw(tdma);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return pm_runtime_force_resume(dev);
|
2013-04-24 13:54:27 +04:00
|
|
|
}
|
|
|
|
|
2012-12-22 03:09:59 +04:00
|
|
|
static const struct dev_pm_ops tegra_dma_dev_pm_ops = {
|
2015-11-13 19:39:38 +03:00
|
|
|
SET_RUNTIME_PM_OPS(tegra_dma_runtime_suspend, tegra_dma_runtime_resume,
|
|
|
|
NULL)
|
2020-02-09 19:33:50 +03:00
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(tegra_dma_dev_suspend, tegra_dma_dev_resume)
|
2012-06-06 09:25:27 +04:00
|
|
|
};
|
|
|
|
|
2016-03-04 13:25:11 +03:00
|
|
|
static const struct of_device_id tegra_dma_of_match[] = {
|
|
|
|
{
|
|
|
|
.compatible = "nvidia,tegra148-apbdma",
|
|
|
|
.data = &tegra148_dma_chip_data,
|
|
|
|
}, {
|
|
|
|
.compatible = "nvidia,tegra114-apbdma",
|
|
|
|
.data = &tegra114_dma_chip_data,
|
|
|
|
}, {
|
|
|
|
.compatible = "nvidia,tegra30-apbdma",
|
|
|
|
.data = &tegra30_dma_chip_data,
|
|
|
|
}, {
|
|
|
|
.compatible = "nvidia,tegra20-apbdma",
|
|
|
|
.data = &tegra20_dma_chip_data,
|
|
|
|
}, {
|
|
|
|
},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, tegra_dma_of_match);
|
|
|
|
|
2012-06-06 09:25:27 +04:00
|
|
|
static struct platform_driver tegra_dmac_driver = {
|
|
|
|
.driver = {
|
2012-07-02 12:22:08 +04:00
|
|
|
.name = "tegra-apbdma",
|
2012-06-06 09:25:27 +04:00
|
|
|
.pm = &tegra_dma_dev_pm_ops,
|
2013-03-12 02:30:26 +04:00
|
|
|
.of_match_table = tegra_dma_of_match,
|
2012-06-06 09:25:27 +04:00
|
|
|
},
|
|
|
|
.probe = tegra_dma_probe,
|
2012-11-19 22:20:04 +04:00
|
|
|
.remove = tegra_dma_remove,
|
2012-06-06 09:25:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(tegra_dmac_driver);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("NVIDIA Tegra APB DMA Controller driver");
|
|
|
|
MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
|
|
|
|
MODULE_LICENSE("GPL v2");
|