16 #include <linux/kernel.h>
24 #include <linux/sched.h>
31 #if defined(CONFIG_TEGRA20_APB_DMA)
33 static u32 *tegra_apb_bb;
37 static u32 tegra_apb_readl_direct(
unsigned long offset);
38 static void tegra_apb_writel_direct(
u32 value,
unsigned long offset);
40 static struct dma_chan *tegra_apb_dma_chan;
43 bool tegra_apb_dma_init(
void)
50 if (tegra_apb_dma_chan)
56 if (!tegra_apb_dma_chan) {
61 pr_debug(
"%s: can not allocate dma channel\n", __func__);
68 pr_err(
"%s: can not allocate bounce buffer\n", __func__);
75 dma_sconfig.src_maxburst = 1;
76 dma_sconfig.dst_maxburst = 1;
84 tegra_apb_dma_chan =
NULL;
91 static void apb_dma_complete(
void *args)
96 static int do_dma_transfer(
unsigned long apb_add,
103 dma_sconfig.src_addr = apb_add;
105 dma_sconfig.dst_addr = apb_add;
107 ret = dmaengine_slave_config(tegra_apb_dma_chan, &dma_sconfig);
111 dma_desc = dmaengine_prep_slave_single(tegra_apb_dma_chan,
112 tegra_apb_bb_phys,
sizeof(
u32), dir,
117 dma_desc->
callback = apb_dma_complete;
122 dmaengine_submit(dma_desc);
123 dma_async_issue_pending(tegra_apb_dma_chan);
127 if (
WARN(ret == 0,
"apb read dma timed out")) {
128 dmaengine_terminate_all(tegra_apb_dma_chan);
138 if (!tegra_apb_dma_chan && !tegra_apb_dma_init())
139 return tegra_apb_readl_direct(offset);
144 pr_err(
"error in reading offset 0x%08lx using dma\n", offset);
145 *(
u32 *)tegra_apb_bb = 0;
148 return *((
u32 *)tegra_apb_bb);
155 if (!tegra_apb_dma_chan && !tegra_apb_dma_init()) {
156 tegra_apb_writel_direct(value, offset);
164 pr_err(
"error in writing offset 0x%08lx using dma\n", offset);
168 #define tegra_apb_readl_using_dma tegra_apb_readl_direct
169 #define tegra_apb_writel_using_dma tegra_apb_writel_direct
178 static u32 tegra_apb_readl_direct(
unsigned long offset)
183 static void tegra_apb_writel_direct(
u32 value,
unsigned long offset)
192 !of_have_populated_dt()) {
196 apbio_read = tegra_apb_readl_direct;
197 apbio_write = tegra_apb_writel_direct;
203 return apbio_read(offset);
208 apbio_write(value, offset);