blob: 5183a310657cbc4455cf4a31b14d9ad720e87189 [file] [log] [blame]
Kevin Hilmana4768d22009-04-14 07:18:14 -05001/*
2 * EDMA3 support for DaVinci
3 *
4 * Copyright (C) 2006-2009 Texas Instruments.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
Lad, Prabhakare7eff702013-06-17 20:27:58 +053020#include <linux/err.h>
Kevin Hilmana4768d22009-04-14 07:18:14 -050021#include <linux/kernel.h>
Kevin Hilmana4768d22009-04-14 07:18:14 -050022#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/interrupt.h>
25#include <linux/platform_device.h>
Kevin Hilmana4768d22009-04-14 07:18:14 -050026#include <linux/io.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/slab.h>
Matt Porter6cba4352013-06-20 16:06:38 -050028#include <linux/edma.h>
29#include <linux/err.h>
30#include <linux/of_address.h>
31#include <linux/of_device.h>
32#include <linux/of_dma.h>
33#include <linux/of_irq.h>
34#include <linux/pm_runtime.h>
Kevin Hilmana4768d22009-04-14 07:18:14 -050035
Matt Porter3ad7a422013-03-06 11:15:31 -050036#include <linux/platform_data/edma.h>
Kevin Hilmana4768d22009-04-14 07:18:14 -050037
38/* Offsets matching "struct edmacc_param" */
39#define PARM_OPT 0x00
40#define PARM_SRC 0x04
41#define PARM_A_B_CNT 0x08
42#define PARM_DST 0x0c
43#define PARM_SRC_DST_BIDX 0x10
44#define PARM_LINK_BCNTRLD 0x14
45#define PARM_SRC_DST_CIDX 0x18
46#define PARM_CCNT 0x1c
47
48#define PARM_SIZE 0x20
49
50/* Offsets for EDMA CC global channel registers and their shadows */
51#define SH_ER 0x00 /* 64 bits */
52#define SH_ECR 0x08 /* 64 bits */
53#define SH_ESR 0x10 /* 64 bits */
54#define SH_CER 0x18 /* 64 bits */
55#define SH_EER 0x20 /* 64 bits */
56#define SH_EECR 0x28 /* 64 bits */
57#define SH_EESR 0x30 /* 64 bits */
58#define SH_SER 0x38 /* 64 bits */
59#define SH_SECR 0x40 /* 64 bits */
60#define SH_IER 0x50 /* 64 bits */
61#define SH_IECR 0x58 /* 64 bits */
62#define SH_IESR 0x60 /* 64 bits */
63#define SH_IPR 0x68 /* 64 bits */
64#define SH_ICR 0x70 /* 64 bits */
65#define SH_IEVAL 0x78
66#define SH_QER 0x80
67#define SH_QEER 0x84
68#define SH_QEECR 0x88
69#define SH_QEESR 0x8c
70#define SH_QSER 0x90
71#define SH_QSECR 0x94
72#define SH_SIZE 0x200
73
74/* Offsets for EDMA CC global registers */
75#define EDMA_REV 0x0000
76#define EDMA_CCCFG 0x0004
77#define EDMA_QCHMAP 0x0200 /* 8 registers */
78#define EDMA_DMAQNUM 0x0240 /* 8 registers (4 on OMAP-L1xx) */
79#define EDMA_QDMAQNUM 0x0260
80#define EDMA_QUETCMAP 0x0280
81#define EDMA_QUEPRI 0x0284
82#define EDMA_EMR 0x0300 /* 64 bits */
83#define EDMA_EMCR 0x0308 /* 64 bits */
84#define EDMA_QEMR 0x0310
85#define EDMA_QEMCR 0x0314
86#define EDMA_CCERR 0x0318
87#define EDMA_CCERRCLR 0x031c
88#define EDMA_EEVAL 0x0320
89#define EDMA_DRAE 0x0340 /* 4 x 64 bits*/
90#define EDMA_QRAE 0x0380 /* 4 registers */
91#define EDMA_QUEEVTENTRY 0x0400 /* 2 x 16 registers */
92#define EDMA_QSTAT 0x0600 /* 2 registers */
93#define EDMA_QWMTHRA 0x0620
94#define EDMA_QWMTHRB 0x0624
95#define EDMA_CCSTAT 0x0640
96
97#define EDMA_M 0x1000 /* global channel registers */
98#define EDMA_ECR 0x1008
99#define EDMA_ECRH 0x100C
100#define EDMA_SHADOW0 0x2000 /* 4 regions shadowing global channels */
101#define EDMA_PARM 0x4000 /* 128 param entries */
102
Kevin Hilmana4768d22009-04-14 07:18:14 -0500103#define PARM_OFFSET(param_no) (EDMA_PARM + ((param_no) << 5))
104
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400105#define EDMA_DCHMAP 0x0100 /* 64 registers */
106#define CHMAP_EXIST BIT(24)
107
Kevin Hilmana4768d22009-04-14 07:18:14 -0500108#define EDMA_MAX_DMACH 64
109#define EDMA_MAX_PARAMENTRY 512
Kevin Hilmana4768d22009-04-14 07:18:14 -0500110
111/*****************************************************************************/
112
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400113static void __iomem *edmacc_regs_base[EDMA_MAX_CC];
Kevin Hilmana4768d22009-04-14 07:18:14 -0500114
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400115static inline unsigned int edma_read(unsigned ctlr, int offset)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500116{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400117 return (unsigned int)__raw_readl(edmacc_regs_base[ctlr] + offset);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500118}
119
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400120static inline void edma_write(unsigned ctlr, int offset, int val)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500121{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400122 __raw_writel(val, edmacc_regs_base[ctlr] + offset);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500123}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400124static inline void edma_modify(unsigned ctlr, int offset, unsigned and,
125 unsigned or)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500126{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400127 unsigned val = edma_read(ctlr, offset);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500128 val &= and;
129 val |= or;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400130 edma_write(ctlr, offset, val);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500131}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400132static inline void edma_and(unsigned ctlr, int offset, unsigned and)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500133{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400134 unsigned val = edma_read(ctlr, offset);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500135 val &= and;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400136 edma_write(ctlr, offset, val);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500137}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400138static inline void edma_or(unsigned ctlr, int offset, unsigned or)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500139{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400140 unsigned val = edma_read(ctlr, offset);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500141 val |= or;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400142 edma_write(ctlr, offset, val);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500143}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400144static inline unsigned int edma_read_array(unsigned ctlr, int offset, int i)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500145{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400146 return edma_read(ctlr, offset + (i << 2));
Kevin Hilmana4768d22009-04-14 07:18:14 -0500147}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400148static inline void edma_write_array(unsigned ctlr, int offset, int i,
149 unsigned val)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500150{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400151 edma_write(ctlr, offset + (i << 2), val);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500152}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400153static inline void edma_modify_array(unsigned ctlr, int offset, int i,
Kevin Hilmana4768d22009-04-14 07:18:14 -0500154 unsigned and, unsigned or)
155{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400156 edma_modify(ctlr, offset + (i << 2), and, or);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500157}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400158static inline void edma_or_array(unsigned ctlr, int offset, int i, unsigned or)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500159{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400160 edma_or(ctlr, offset + (i << 2), or);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500161}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400162static inline void edma_or_array2(unsigned ctlr, int offset, int i, int j,
163 unsigned or)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500164{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400165 edma_or(ctlr, offset + ((i*2 + j) << 2), or);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500166}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400167static inline void edma_write_array2(unsigned ctlr, int offset, int i, int j,
168 unsigned val)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500169{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400170 edma_write(ctlr, offset + ((i*2 + j) << 2), val);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500171}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400172static inline unsigned int edma_shadow0_read(unsigned ctlr, int offset)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500173{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400174 return edma_read(ctlr, EDMA_SHADOW0 + offset);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500175}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400176static inline unsigned int edma_shadow0_read_array(unsigned ctlr, int offset,
177 int i)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500178{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400179 return edma_read(ctlr, EDMA_SHADOW0 + offset + (i << 2));
Kevin Hilmana4768d22009-04-14 07:18:14 -0500180}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400181static inline void edma_shadow0_write(unsigned ctlr, int offset, unsigned val)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500182{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400183 edma_write(ctlr, EDMA_SHADOW0 + offset, val);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500184}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400185static inline void edma_shadow0_write_array(unsigned ctlr, int offset, int i,
186 unsigned val)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500187{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400188 edma_write(ctlr, EDMA_SHADOW0 + offset + (i << 2), val);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500189}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400190static inline unsigned int edma_parm_read(unsigned ctlr, int offset,
191 int param_no)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500192{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400193 return edma_read(ctlr, EDMA_PARM + offset + (param_no << 5));
Kevin Hilmana4768d22009-04-14 07:18:14 -0500194}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400195static inline void edma_parm_write(unsigned ctlr, int offset, int param_no,
196 unsigned val)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500197{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400198 edma_write(ctlr, EDMA_PARM + offset + (param_no << 5), val);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500199}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400200static inline void edma_parm_modify(unsigned ctlr, int offset, int param_no,
Kevin Hilmana4768d22009-04-14 07:18:14 -0500201 unsigned and, unsigned or)
202{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400203 edma_modify(ctlr, EDMA_PARM + offset + (param_no << 5), and, or);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500204}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400205static inline void edma_parm_and(unsigned ctlr, int offset, int param_no,
206 unsigned and)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500207{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400208 edma_and(ctlr, EDMA_PARM + offset + (param_no << 5), and);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500209}
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400210static inline void edma_parm_or(unsigned ctlr, int offset, int param_no,
211 unsigned or)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500212{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400213 edma_or(ctlr, EDMA_PARM + offset + (param_no << 5), or);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500214}
215
Rajashekhara, Sudhakar90bd4e62010-06-29 11:35:13 +0530216static inline void set_bits(int offset, int len, unsigned long *p)
217{
218 for (; len > 0; len--)
219 set_bit(offset + (len - 1), p);
220}
221
222static inline void clear_bits(int offset, int len, unsigned long *p)
223{
224 for (; len > 0; len--)
225 clear_bit(offset + (len - 1), p);
226}
227
Kevin Hilmana4768d22009-04-14 07:18:14 -0500228/*****************************************************************************/
229
230/* actual number of DMA channels and slots on this silicon */
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400231struct edma {
232 /* how many dma resources of each type */
233 unsigned num_channels;
234 unsigned num_region;
235 unsigned num_slots;
236 unsigned num_tc;
237 unsigned num_cc;
Sandeep Paulraja0f02022009-07-27 09:57:07 -0400238 enum dma_event_q default_queue;
Kevin Hilmana4768d22009-04-14 07:18:14 -0500239
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400240 /* list of channels with no even trigger; terminated by "-1" */
241 const s8 *noevent;
Kevin Hilmana4768d22009-04-14 07:18:14 -0500242
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400243 /* The edma_inuse bit for each PaRAM slot is clear unless the
244 * channel is in use ... by ARM or DSP, for QDMA, or whatever.
245 */
246 DECLARE_BITMAP(edma_inuse, EDMA_MAX_PARAMENTRY);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500247
Sudhakar Rajashekharaf900d552010-01-06 17:29:49 +0530248 /* The edma_unused bit for each channel is clear unless
249 * it is not being used on this platform. It uses a bit
250 * of SOC-specific initialization code.
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400251 */
Sudhakar Rajashekharaf900d552010-01-06 17:29:49 +0530252 DECLARE_BITMAP(edma_unused, EDMA_MAX_DMACH);
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400253
254 unsigned irq_res_start;
255 unsigned irq_res_end;
256
257 struct dma_interrupt_data {
258 void (*callback)(unsigned channel, unsigned short ch_status,
259 void *data);
260 void *data;
261 } intr_data[EDMA_MAX_DMACH];
262};
263
Sekhar Nori3f68b982010-05-04 14:11:35 +0530264static struct edma *edma_cc[EDMA_MAX_CC];
Sudhakar Rajashekhara2d517502010-01-06 17:28:44 +0530265static int arch_num_cc;
Kevin Hilmana4768d22009-04-14 07:18:14 -0500266
267/* dummy param set used to (re)initialize parameter RAM slots */
268static const struct edmacc_param dummy_paramset = {
269 .link_bcntrld = 0xffff,
270 .ccnt = 1,
271};
272
Kevin Hilmana4768d22009-04-14 07:18:14 -0500273/*****************************************************************************/
274
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400275static void map_dmach_queue(unsigned ctlr, unsigned ch_no,
276 enum dma_event_q queue_no)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500277{
278 int bit = (ch_no & 0x7) * 4;
279
280 /* default to low priority queue */
281 if (queue_no == EVENTQ_DEFAULT)
Sekhar Nori3f68b982010-05-04 14:11:35 +0530282 queue_no = edma_cc[ctlr]->default_queue;
Kevin Hilmana4768d22009-04-14 07:18:14 -0500283
284 queue_no &= 7;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400285 edma_modify_array(ctlr, EDMA_DMAQNUM, (ch_no >> 3),
Kevin Hilmana4768d22009-04-14 07:18:14 -0500286 ~(0x7 << bit), queue_no << bit);
287}
288
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400289static void __init map_queue_tc(unsigned ctlr, int queue_no, int tc_no)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500290{
291 int bit = queue_no * 4;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400292 edma_modify(ctlr, EDMA_QUETCMAP, ~(0x7 << bit), ((tc_no & 0x7) << bit));
Kevin Hilmana4768d22009-04-14 07:18:14 -0500293}
294
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400295static void __init assign_priority_to_queue(unsigned ctlr, int queue_no,
296 int priority)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500297{
298 int bit = queue_no * 4;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400299 edma_modify(ctlr, EDMA_QUEPRI, ~(0x7 << bit),
300 ((priority & 0x7) << bit));
301}
302
303/**
304 * map_dmach_param - Maps channel number to param entry number
305 *
306 * This maps the dma channel number to param entry numberter. In
307 * other words using the DMA channel mapping registers a param entry
308 * can be mapped to any channel
309 *
310 * Callers are responsible for ensuring the channel mapping logic is
311 * included in that particular EDMA variant (Eg : dm646x)
312 *
313 */
314static void __init map_dmach_param(unsigned ctlr)
315{
316 int i;
317 for (i = 0; i < EDMA_MAX_DMACH; i++)
318 edma_write_array(ctlr, EDMA_DCHMAP , i , (i << 5));
Kevin Hilmana4768d22009-04-14 07:18:14 -0500319}
320
321static inline void
322setup_dma_interrupt(unsigned lch,
323 void (*callback)(unsigned channel, u16 ch_status, void *data),
324 void *data)
325{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400326 unsigned ctlr;
327
328 ctlr = EDMA_CTLR(lch);
329 lch = EDMA_CHAN_SLOT(lch);
330
Sekhar Nori243bc652010-05-04 14:11:36 +0530331 if (!callback)
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400332 edma_shadow0_write_array(ctlr, SH_IECR, lch >> 5,
Sekhar Norid78a9492010-05-10 12:41:18 +0530333 BIT(lch & 0x1f));
Kevin Hilmana4768d22009-04-14 07:18:14 -0500334
Sekhar Nori3f68b982010-05-04 14:11:35 +0530335 edma_cc[ctlr]->intr_data[lch].callback = callback;
336 edma_cc[ctlr]->intr_data[lch].data = data;
Kevin Hilmana4768d22009-04-14 07:18:14 -0500337
338 if (callback) {
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400339 edma_shadow0_write_array(ctlr, SH_ICR, lch >> 5,
Sekhar Norid78a9492010-05-10 12:41:18 +0530340 BIT(lch & 0x1f));
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400341 edma_shadow0_write_array(ctlr, SH_IESR, lch >> 5,
Sekhar Norid78a9492010-05-10 12:41:18 +0530342 BIT(lch & 0x1f));
Kevin Hilmana4768d22009-04-14 07:18:14 -0500343 }
344}
345
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400346static int irq2ctlr(int irq)
347{
Sekhar Nori3f68b982010-05-04 14:11:35 +0530348 if (irq >= edma_cc[0]->irq_res_start && irq <= edma_cc[0]->irq_res_end)
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400349 return 0;
Sekhar Nori3f68b982010-05-04 14:11:35 +0530350 else if (irq >= edma_cc[1]->irq_res_start &&
351 irq <= edma_cc[1]->irq_res_end)
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400352 return 1;
353
354 return -1;
355}
356
Kevin Hilmana4768d22009-04-14 07:18:14 -0500357/******************************************************************************
358 *
359 * DMA interrupt handler
360 *
361 *****************************************************************************/
362static irqreturn_t dma_irq_handler(int irq, void *data)
363{
Kulikov Vasiliy93fe23d2010-07-17 19:19:07 +0400364 int ctlr;
Sebastian Andrzej Siewiorbcd59b02012-02-09 13:28:26 +0100365 u32 sh_ier;
366 u32 sh_ipr;
367 u32 bank;
Kevin Hilmana4768d22009-04-14 07:18:14 -0500368
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400369 ctlr = irq2ctlr(irq);
Kulikov Vasiliy93fe23d2010-07-17 19:19:07 +0400370 if (ctlr < 0)
371 return IRQ_NONE;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400372
Kevin Hilmana4768d22009-04-14 07:18:14 -0500373 dev_dbg(data, "dma_irq_handler\n");
374
Sebastian Andrzej Siewiorbcd59b02012-02-09 13:28:26 +0100375 sh_ipr = edma_shadow0_read_array(ctlr, SH_IPR, 0);
376 if (!sh_ipr) {
377 sh_ipr = edma_shadow0_read_array(ctlr, SH_IPR, 1);
378 if (!sh_ipr)
379 return IRQ_NONE;
380 sh_ier = edma_shadow0_read_array(ctlr, SH_IER, 1);
381 bank = 1;
382 } else {
383 sh_ier = edma_shadow0_read_array(ctlr, SH_IER, 0);
384 bank = 0;
Kevin Hilmana4768d22009-04-14 07:18:14 -0500385 }
Sebastian Andrzej Siewiorbcd59b02012-02-09 13:28:26 +0100386
387 do {
388 u32 slot;
389 u32 channel;
390
391 dev_dbg(data, "IPR%d %08x\n", bank, sh_ipr);
392
393 slot = __ffs(sh_ipr);
394 sh_ipr &= ~(BIT(slot));
395
396 if (sh_ier & BIT(slot)) {
397 channel = (bank << 5) | slot;
398 /* Clear the corresponding IPR bits */
399 edma_shadow0_write_array(ctlr, SH_ICR, bank,
400 BIT(slot));
401 if (edma_cc[ctlr]->intr_data[channel].callback)
402 edma_cc[ctlr]->intr_data[channel].callback(
403 channel, DMA_COMPLETE,
404 edma_cc[ctlr]->intr_data[channel].data);
405 }
406 } while (sh_ipr);
407
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400408 edma_shadow0_write(ctlr, SH_IEVAL, 1);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500409 return IRQ_HANDLED;
410}
411
412/******************************************************************************
413 *
414 * DMA error interrupt handler
415 *
416 *****************************************************************************/
417static irqreturn_t dma_ccerr_handler(int irq, void *data)
418{
419 int i;
Kulikov Vasiliy93fe23d2010-07-17 19:19:07 +0400420 int ctlr;
Kevin Hilmana4768d22009-04-14 07:18:14 -0500421 unsigned int cnt = 0;
422
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400423 ctlr = irq2ctlr(irq);
Kulikov Vasiliy93fe23d2010-07-17 19:19:07 +0400424 if (ctlr < 0)
425 return IRQ_NONE;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400426
Kevin Hilmana4768d22009-04-14 07:18:14 -0500427 dev_dbg(data, "dma_ccerr_handler\n");
428
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400429 if ((edma_read_array(ctlr, EDMA_EMR, 0) == 0) &&
430 (edma_read_array(ctlr, EDMA_EMR, 1) == 0) &&
431 (edma_read(ctlr, EDMA_QEMR) == 0) &&
432 (edma_read(ctlr, EDMA_CCERR) == 0))
Kevin Hilmana4768d22009-04-14 07:18:14 -0500433 return IRQ_NONE;
434
435 while (1) {
436 int j = -1;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400437 if (edma_read_array(ctlr, EDMA_EMR, 0))
Kevin Hilmana4768d22009-04-14 07:18:14 -0500438 j = 0;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400439 else if (edma_read_array(ctlr, EDMA_EMR, 1))
Kevin Hilmana4768d22009-04-14 07:18:14 -0500440 j = 1;
441 if (j >= 0) {
442 dev_dbg(data, "EMR%d %08x\n", j,
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400443 edma_read_array(ctlr, EDMA_EMR, j));
Kevin Hilmana4768d22009-04-14 07:18:14 -0500444 for (i = 0; i < 32; i++) {
445 int k = (j << 5) + i;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400446 if (edma_read_array(ctlr, EDMA_EMR, j) &
Sekhar Norid78a9492010-05-10 12:41:18 +0530447 BIT(i)) {
Kevin Hilmana4768d22009-04-14 07:18:14 -0500448 /* Clear the corresponding EMR bits */
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400449 edma_write_array(ctlr, EDMA_EMCR, j,
Sekhar Norid78a9492010-05-10 12:41:18 +0530450 BIT(i));
Kevin Hilmana4768d22009-04-14 07:18:14 -0500451 /* Clear any SER */
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400452 edma_shadow0_write_array(ctlr, SH_SECR,
Sekhar Norid78a9492010-05-10 12:41:18 +0530453 j, BIT(i));
Sekhar Nori3f68b982010-05-04 14:11:35 +0530454 if (edma_cc[ctlr]->intr_data[k].
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400455 callback) {
Sekhar Nori3f68b982010-05-04 14:11:35 +0530456 edma_cc[ctlr]->intr_data[k].
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400457 callback(k,
458 DMA_CC_ERROR,
Sekhar Nori3f68b982010-05-04 14:11:35 +0530459 edma_cc[ctlr]->intr_data
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400460 [k].data);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500461 }
462 }
463 }
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400464 } else if (edma_read(ctlr, EDMA_QEMR)) {
Kevin Hilmana4768d22009-04-14 07:18:14 -0500465 dev_dbg(data, "QEMR %02x\n",
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400466 edma_read(ctlr, EDMA_QEMR));
Kevin Hilmana4768d22009-04-14 07:18:14 -0500467 for (i = 0; i < 8; i++) {
Sekhar Norid78a9492010-05-10 12:41:18 +0530468 if (edma_read(ctlr, EDMA_QEMR) & BIT(i)) {
Kevin Hilmana4768d22009-04-14 07:18:14 -0500469 /* Clear the corresponding IPR bits */
Sekhar Norid78a9492010-05-10 12:41:18 +0530470 edma_write(ctlr, EDMA_QEMCR, BIT(i));
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400471 edma_shadow0_write(ctlr, SH_QSECR,
Sekhar Norid78a9492010-05-10 12:41:18 +0530472 BIT(i));
Kevin Hilmana4768d22009-04-14 07:18:14 -0500473
474 /* NOTE: not reported!! */
475 }
476 }
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400477 } else if (edma_read(ctlr, EDMA_CCERR)) {
Kevin Hilmana4768d22009-04-14 07:18:14 -0500478 dev_dbg(data, "CCERR %08x\n",
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400479 edma_read(ctlr, EDMA_CCERR));
Kevin Hilmana4768d22009-04-14 07:18:14 -0500480 /* FIXME: CCERR.BIT(16) ignored! much better
481 * to just write CCERRCLR with CCERR value...
482 */
483 for (i = 0; i < 8; i++) {
Sekhar Norid78a9492010-05-10 12:41:18 +0530484 if (edma_read(ctlr, EDMA_CCERR) & BIT(i)) {
Kevin Hilmana4768d22009-04-14 07:18:14 -0500485 /* Clear the corresponding IPR bits */
Sekhar Norid78a9492010-05-10 12:41:18 +0530486 edma_write(ctlr, EDMA_CCERRCLR, BIT(i));
Kevin Hilmana4768d22009-04-14 07:18:14 -0500487
488 /* NOTE: not reported!! */
489 }
490 }
491 }
Sekhar Noria6374f52010-05-10 12:41:19 +0530492 if ((edma_read_array(ctlr, EDMA_EMR, 0) == 0) &&
493 (edma_read_array(ctlr, EDMA_EMR, 1) == 0) &&
494 (edma_read(ctlr, EDMA_QEMR) == 0) &&
495 (edma_read(ctlr, EDMA_CCERR) == 0))
Kevin Hilmana4768d22009-04-14 07:18:14 -0500496 break;
Kevin Hilmana4768d22009-04-14 07:18:14 -0500497 cnt++;
498 if (cnt > 10)
499 break;
500 }
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400501 edma_write(ctlr, EDMA_EEVAL, 1);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500502 return IRQ_HANDLED;
503}
504
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400505static int reserve_contiguous_slots(int ctlr, unsigned int id,
506 unsigned int num_slots,
507 unsigned int start_slot)
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400508{
509 int i, j;
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400510 unsigned int count = num_slots;
511 int stop_slot = start_slot;
Sandeep Paulrajcc93fc32009-09-20 13:47:03 -0400512 DECLARE_BITMAP(tmp_inuse, EDMA_MAX_PARAMENTRY);
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400513
Sekhar Nori3f68b982010-05-04 14:11:35 +0530514 for (i = start_slot; i < edma_cc[ctlr]->num_slots; ++i) {
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400515 j = EDMA_CHAN_SLOT(i);
Sekhar Nori3f68b982010-05-04 14:11:35 +0530516 if (!test_and_set_bit(j, edma_cc[ctlr]->edma_inuse)) {
Sandeep Paulrajcc93fc32009-09-20 13:47:03 -0400517 /* Record our current beginning slot */
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400518 if (count == num_slots)
519 stop_slot = i;
Sandeep Paulrajcc93fc32009-09-20 13:47:03 -0400520
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400521 count--;
Sandeep Paulrajcc93fc32009-09-20 13:47:03 -0400522 set_bit(j, tmp_inuse);
523
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400524 if (count == 0)
525 break;
Sandeep Paulrajcc93fc32009-09-20 13:47:03 -0400526 } else {
527 clear_bit(j, tmp_inuse);
528
529 if (id == EDMA_CONT_PARAMS_FIXED_EXACT) {
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400530 stop_slot = i;
Sandeep Paulrajcc93fc32009-09-20 13:47:03 -0400531 break;
Sekhar Nori243bc652010-05-04 14:11:36 +0530532 } else {
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400533 count = num_slots;
Sekhar Nori243bc652010-05-04 14:11:36 +0530534 }
Sandeep Paulrajcc93fc32009-09-20 13:47:03 -0400535 }
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400536 }
537
538 /*
539 * We have to clear any bits that we set
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400540 * if we run out parameter RAM slots, i.e we do find a set
541 * of contiguous parameter RAM slots but do not find the exact number
542 * requested as we may reach the total number of parameter RAM slots
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400543 */
Sekhar Nori3f68b982010-05-04 14:11:35 +0530544 if (i == edma_cc[ctlr]->num_slots)
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400545 stop_slot = i;
Sandeep Paulrajcc93fc32009-09-20 13:47:03 -0400546
Akinobu Mita98e3b332012-04-11 20:36:53 +0900547 j = start_slot;
548 for_each_set_bit_from(j, tmp_inuse, stop_slot)
549 clear_bit(j, edma_cc[ctlr]->edma_inuse);
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400550
Sandeep Paulrajcc93fc32009-09-20 13:47:03 -0400551 if (count)
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400552 return -EBUSY;
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400553
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400554 for (j = i - num_slots + 1; j <= i; ++j)
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400555 memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(j),
556 &dummy_paramset, PARM_SIZE);
557
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400558 return EDMA_CTLR_CHAN(ctlr, i - num_slots + 1);
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400559}
560
Sudhakar Rajashekharaf900d552010-01-06 17:29:49 +0530561static int prepare_unused_channel_list(struct device *dev, void *data)
562{
563 struct platform_device *pdev = to_platform_device(dev);
564 int i, ctlr;
565
566 for (i = 0; i < pdev->num_resources; i++) {
567 if ((pdev->resource[i].flags & IORESOURCE_DMA) &&
568 (int)pdev->resource[i].start >= 0) {
569 ctlr = EDMA_CTLR(pdev->resource[i].start);
570 clear_bit(EDMA_CHAN_SLOT(pdev->resource[i].start),
Sekhar Nori3f68b982010-05-04 14:11:35 +0530571 edma_cc[ctlr]->edma_unused);
Sudhakar Rajashekharaf900d552010-01-06 17:29:49 +0530572 }
573 }
574
575 return 0;
576}
577
Kevin Hilmana4768d22009-04-14 07:18:14 -0500578/*-----------------------------------------------------------------------*/
579
Sudhakar Rajashekharaf900d552010-01-06 17:29:49 +0530580static bool unused_chan_list_done;
581
Kevin Hilmana4768d22009-04-14 07:18:14 -0500582/* Resource alloc/free: dma channels, parameter RAM slots */
583
584/**
585 * edma_alloc_channel - allocate DMA channel and paired parameter RAM
586 * @channel: specific channel to allocate; negative for "any unmapped channel"
587 * @callback: optional; to be issued on DMA completion or errors
588 * @data: passed to callback
589 * @eventq_no: an EVENTQ_* constant, used to choose which Transfer
590 * Controller (TC) executes requests using this channel. Use
591 * EVENTQ_DEFAULT unless you really need a high priority queue.
592 *
593 * This allocates a DMA channel and its associated parameter RAM slot.
594 * The parameter RAM is initialized to hold a dummy transfer.
595 *
596 * Normal use is to pass a specific channel number as @channel, to make
597 * use of hardware events mapped to that channel. When the channel will
598 * be used only for software triggering or event chaining, channels not
599 * mapped to hardware events (or mapped to unused events) are preferable.
600 *
601 * DMA transfers start from a channel using edma_start(), or by
602 * chaining. When the transfer described in that channel's parameter RAM
603 * slot completes, that slot's data may be reloaded through a link.
604 *
605 * DMA errors are only reported to the @callback associated with the
606 * channel driving that transfer, but transfer completion callbacks can
607 * be sent to another channel under control of the TCC field in
608 * the option word of the transfer's parameter RAM set. Drivers must not
609 * use DMA transfer completion callbacks for channels they did not allocate.
610 * (The same applies to TCC codes used in transfer chaining.)
611 *
612 * Returns the number of the channel, else negative errno.
613 */
614int edma_alloc_channel(int channel,
615 void (*callback)(unsigned channel, u16 ch_status, void *data),
616 void *data,
617 enum dma_event_q eventq_no)
618{
Sudhakar Rajashekhara447f18f2010-01-06 17:29:11 +0530619 unsigned i, done = 0, ctlr = 0;
Sudhakar Rajashekharaf900d552010-01-06 17:29:49 +0530620 int ret = 0;
621
622 if (!unused_chan_list_done) {
623 /*
624 * Scan all the platform devices to find out the EDMA channels
625 * used and clear them in the unused list, making the rest
626 * available for ARM usage.
627 */
628 ret = bus_for_each_dev(&platform_bus_type, NULL, NULL,
629 prepare_unused_channel_list);
630 if (ret < 0)
631 return ret;
632
633 unused_chan_list_done = true;
634 }
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400635
636 if (channel >= 0) {
637 ctlr = EDMA_CTLR(channel);
638 channel = EDMA_CHAN_SLOT(channel);
639 }
640
Kevin Hilmana4768d22009-04-14 07:18:14 -0500641 if (channel < 0) {
Sudhakar Rajashekhara2d517502010-01-06 17:28:44 +0530642 for (i = 0; i < arch_num_cc; i++) {
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400643 channel = 0;
644 for (;;) {
Sekhar Nori3f68b982010-05-04 14:11:35 +0530645 channel = find_next_bit(edma_cc[i]->edma_unused,
646 edma_cc[i]->num_channels,
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400647 channel);
Sekhar Nori3f68b982010-05-04 14:11:35 +0530648 if (channel == edma_cc[i]->num_channels)
Sudhakar Rajashekhara447f18f2010-01-06 17:29:11 +0530649 break;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400650 if (!test_and_set_bit(channel,
Sekhar Nori3f68b982010-05-04 14:11:35 +0530651 edma_cc[i]->edma_inuse)) {
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400652 done = 1;
653 ctlr = i;
654 break;
655 }
656 channel++;
657 }
658 if (done)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500659 break;
Kevin Hilmana4768d22009-04-14 07:18:14 -0500660 }
Sudhakar Rajashekhara447f18f2010-01-06 17:29:11 +0530661 if (!done)
662 return -ENOMEM;
Sekhar Nori3f68b982010-05-04 14:11:35 +0530663 } else if (channel >= edma_cc[ctlr]->num_channels) {
Kevin Hilmana4768d22009-04-14 07:18:14 -0500664 return -EINVAL;
Sekhar Nori3f68b982010-05-04 14:11:35 +0530665 } else if (test_and_set_bit(channel, edma_cc[ctlr]->edma_inuse)) {
Kevin Hilmana4768d22009-04-14 07:18:14 -0500666 return -EBUSY;
667 }
668
669 /* ensure access through shadow region 0 */
Sekhar Norid78a9492010-05-10 12:41:18 +0530670 edma_or_array2(ctlr, EDMA_DRAE, 0, channel >> 5, BIT(channel & 0x1f));
Kevin Hilmana4768d22009-04-14 07:18:14 -0500671
672 /* ensure no events are pending */
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400673 edma_stop(EDMA_CTLR_CHAN(ctlr, channel));
674 memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(channel),
Kevin Hilmana4768d22009-04-14 07:18:14 -0500675 &dummy_paramset, PARM_SIZE);
676
677 if (callback)
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400678 setup_dma_interrupt(EDMA_CTLR_CHAN(ctlr, channel),
679 callback, data);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500680
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400681 map_dmach_queue(ctlr, channel, eventq_no);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500682
Sudhakar Rajashekhara0e6cb8d2010-01-06 17:28:36 +0530683 return EDMA_CTLR_CHAN(ctlr, channel);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500684}
685EXPORT_SYMBOL(edma_alloc_channel);
686
687
688/**
689 * edma_free_channel - deallocate DMA channel
690 * @channel: dma channel returned from edma_alloc_channel()
691 *
692 * This deallocates the DMA channel and associated parameter RAM slot
693 * allocated by edma_alloc_channel().
694 *
695 * Callers are responsible for ensuring the channel is inactive, and
696 * will not be reactivated by linking, chaining, or software calls to
697 * edma_start().
698 */
699void edma_free_channel(unsigned channel)
700{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400701 unsigned ctlr;
702
703 ctlr = EDMA_CTLR(channel);
704 channel = EDMA_CHAN_SLOT(channel);
705
Sekhar Nori3f68b982010-05-04 14:11:35 +0530706 if (channel >= edma_cc[ctlr]->num_channels)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500707 return;
708
709 setup_dma_interrupt(channel, NULL, NULL);
710 /* REVISIT should probably take out of shadow region 0 */
711
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400712 memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(channel),
Kevin Hilmana4768d22009-04-14 07:18:14 -0500713 &dummy_paramset, PARM_SIZE);
Sekhar Nori3f68b982010-05-04 14:11:35 +0530714 clear_bit(channel, edma_cc[ctlr]->edma_inuse);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500715}
716EXPORT_SYMBOL(edma_free_channel);
717
718/**
719 * edma_alloc_slot - allocate DMA parameter RAM
720 * @slot: specific slot to allocate; negative for "any unused slot"
721 *
722 * This allocates a parameter RAM slot, initializing it to hold a
723 * dummy transfer. Slots allocated using this routine have not been
724 * mapped to a hardware DMA channel, and will normally be used by
725 * linking to them from a slot associated with a DMA channel.
726 *
727 * Normal use is to pass EDMA_SLOT_ANY as the @slot, but specific
728 * slots may be allocated on behalf of DSP firmware.
729 *
730 * Returns the number of the slot, else negative errno.
731 */
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400732int edma_alloc_slot(unsigned ctlr, int slot)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500733{
Matt Porter06955272013-03-05 10:58:22 -0500734 if (!edma_cc[ctlr])
735 return -EINVAL;
736
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400737 if (slot >= 0)
738 slot = EDMA_CHAN_SLOT(slot);
739
Kevin Hilmana4768d22009-04-14 07:18:14 -0500740 if (slot < 0) {
Sekhar Nori3f68b982010-05-04 14:11:35 +0530741 slot = edma_cc[ctlr]->num_channels;
Kevin Hilmana4768d22009-04-14 07:18:14 -0500742 for (;;) {
Sekhar Nori3f68b982010-05-04 14:11:35 +0530743 slot = find_next_zero_bit(edma_cc[ctlr]->edma_inuse,
744 edma_cc[ctlr]->num_slots, slot);
745 if (slot == edma_cc[ctlr]->num_slots)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500746 return -ENOMEM;
Sekhar Nori3f68b982010-05-04 14:11:35 +0530747 if (!test_and_set_bit(slot, edma_cc[ctlr]->edma_inuse))
Kevin Hilmana4768d22009-04-14 07:18:14 -0500748 break;
749 }
Sekhar Nori3f68b982010-05-04 14:11:35 +0530750 } else if (slot < edma_cc[ctlr]->num_channels ||
751 slot >= edma_cc[ctlr]->num_slots) {
Kevin Hilmana4768d22009-04-14 07:18:14 -0500752 return -EINVAL;
Sekhar Nori3f68b982010-05-04 14:11:35 +0530753 } else if (test_and_set_bit(slot, edma_cc[ctlr]->edma_inuse)) {
Kevin Hilmana4768d22009-04-14 07:18:14 -0500754 return -EBUSY;
755 }
756
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400757 memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(slot),
Kevin Hilmana4768d22009-04-14 07:18:14 -0500758 &dummy_paramset, PARM_SIZE);
759
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400760 return EDMA_CTLR_CHAN(ctlr, slot);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500761}
762EXPORT_SYMBOL(edma_alloc_slot);
763
764/**
765 * edma_free_slot - deallocate DMA parameter RAM
766 * @slot: parameter RAM slot returned from edma_alloc_slot()
767 *
768 * This deallocates the parameter RAM slot allocated by edma_alloc_slot().
769 * Callers are responsible for ensuring the slot is inactive, and will
770 * not be activated.
771 */
772void edma_free_slot(unsigned slot)
773{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400774 unsigned ctlr;
775
776 ctlr = EDMA_CTLR(slot);
777 slot = EDMA_CHAN_SLOT(slot);
778
Sekhar Nori3f68b982010-05-04 14:11:35 +0530779 if (slot < edma_cc[ctlr]->num_channels ||
780 slot >= edma_cc[ctlr]->num_slots)
Kevin Hilmana4768d22009-04-14 07:18:14 -0500781 return;
782
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400783 memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(slot),
Kevin Hilmana4768d22009-04-14 07:18:14 -0500784 &dummy_paramset, PARM_SIZE);
Sekhar Nori3f68b982010-05-04 14:11:35 +0530785 clear_bit(slot, edma_cc[ctlr]->edma_inuse);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500786}
787EXPORT_SYMBOL(edma_free_slot);
788
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400789
790/**
791 * edma_alloc_cont_slots- alloc contiguous parameter RAM slots
792 * The API will return the starting point of a set of
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400793 * contiguous parameter RAM slots that have been requested
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400794 *
795 * @id: can only be EDMA_CONT_PARAMS_ANY or EDMA_CONT_PARAMS_FIXED_EXACT
796 * or EDMA_CONT_PARAMS_FIXED_NOT_EXACT
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400797 * @count: number of contiguous Paramter RAM slots
798 * @slot - the start value of Parameter RAM slot that should be passed if id
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400799 * is EDMA_CONT_PARAMS_FIXED_EXACT or EDMA_CONT_PARAMS_FIXED_NOT_EXACT
800 *
801 * If id is EDMA_CONT_PARAMS_ANY then the API starts looking for a set of
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400802 * contiguous Parameter RAM slots from parameter RAM 64 in the case of
803 * DaVinci SOCs and 32 in the case of DA8xx SOCs.
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400804 *
805 * If id is EDMA_CONT_PARAMS_FIXED_EXACT then the API starts looking for a
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400806 * set of contiguous parameter RAM slots from the "slot" that is passed as an
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400807 * argument to the API.
808 *
809 * If id is EDMA_CONT_PARAMS_FIXED_NOT_EXACT then the API initially tries
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400810 * starts looking for a set of contiguous parameter RAMs from the "slot"
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400811 * that is passed as an argument to the API. On failure the API will try to
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400812 * find a set of contiguous Parameter RAM slots from the remaining Parameter
813 * RAM slots
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400814 */
815int edma_alloc_cont_slots(unsigned ctlr, unsigned int id, int slot, int count)
816{
817 /*
818 * The start slot requested should be greater than
819 * the number of channels and lesser than the total number
820 * of slots
821 */
Sandeep Paulraj6b0cf4e2009-09-16 18:17:43 -0400822 if ((id != EDMA_CONT_PARAMS_ANY) &&
Sekhar Nori3f68b982010-05-04 14:11:35 +0530823 (slot < edma_cc[ctlr]->num_channels ||
824 slot >= edma_cc[ctlr]->num_slots))
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400825 return -EINVAL;
826
827 /*
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400828 * The number of parameter RAM slots requested cannot be less than 1
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400829 * and cannot be more than the number of slots minus the number of
830 * channels
831 */
832 if (count < 1 || count >
Sekhar Nori3f68b982010-05-04 14:11:35 +0530833 (edma_cc[ctlr]->num_slots - edma_cc[ctlr]->num_channels))
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400834 return -EINVAL;
835
836 switch (id) {
837 case EDMA_CONT_PARAMS_ANY:
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400838 return reserve_contiguous_slots(ctlr, id, count,
Sekhar Nori3f68b982010-05-04 14:11:35 +0530839 edma_cc[ctlr]->num_channels);
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400840 case EDMA_CONT_PARAMS_FIXED_EXACT:
841 case EDMA_CONT_PARAMS_FIXED_NOT_EXACT:
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400842 return reserve_contiguous_slots(ctlr, id, count, slot);
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400843 default:
844 return -EINVAL;
845 }
846
847}
848EXPORT_SYMBOL(edma_alloc_cont_slots);
849
850/**
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400851 * edma_free_cont_slots - deallocate DMA parameter RAM slots
852 * @slot: first parameter RAM of a set of parameter RAM slots to be freed
853 * @count: the number of contiguous parameter RAM slots to be freed
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400854 *
855 * This deallocates the parameter RAM slots allocated by
856 * edma_alloc_cont_slots.
857 * Callers/applications need to keep track of sets of contiguous
Sandeep Paulraj134ce222009-09-20 14:06:33 -0400858 * parameter RAM slots that have been allocated using the edma_alloc_cont_slots
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400859 * API.
860 * Callers are responsible for ensuring the slots are inactive, and will
861 * not be activated.
862 */
863int edma_free_cont_slots(unsigned slot, int count)
864{
Sandeep Paulraj51c99e02009-09-16 18:09:59 -0400865 unsigned ctlr, slot_to_free;
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400866 int i;
867
868 ctlr = EDMA_CTLR(slot);
869 slot = EDMA_CHAN_SLOT(slot);
870
Sekhar Nori3f68b982010-05-04 14:11:35 +0530871 if (slot < edma_cc[ctlr]->num_channels ||
872 slot >= edma_cc[ctlr]->num_slots ||
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400873 count < 1)
874 return -EINVAL;
875
876 for (i = slot; i < slot + count; ++i) {
877 ctlr = EDMA_CTLR(i);
Sandeep Paulraj51c99e02009-09-16 18:09:59 -0400878 slot_to_free = EDMA_CHAN_SLOT(i);
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400879
Sandeep Paulraj51c99e02009-09-16 18:09:59 -0400880 memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(slot_to_free),
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400881 &dummy_paramset, PARM_SIZE);
Sekhar Nori3f68b982010-05-04 14:11:35 +0530882 clear_bit(slot_to_free, edma_cc[ctlr]->edma_inuse);
Sandeep Paulraj213765d2009-07-27 15:10:36 -0400883 }
884
885 return 0;
886}
887EXPORT_SYMBOL(edma_free_cont_slots);
888
Kevin Hilmana4768d22009-04-14 07:18:14 -0500889/*-----------------------------------------------------------------------*/
890
891/* Parameter RAM operations (i) -- read/write partial slots */
892
893/**
894 * edma_set_src - set initial DMA source address in parameter RAM slot
895 * @slot: parameter RAM slot being configured
896 * @src_port: physical address of source (memory, controller FIFO, etc)
897 * @addressMode: INCR, except in very rare cases
898 * @fifoWidth: ignored unless @addressMode is FIFO, else specifies the
899 * width to use when addressing the fifo (e.g. W8BIT, W32BIT)
900 *
901 * Note that the source address is modified during the DMA transfer
902 * according to edma_set_src_index().
903 */
904void edma_set_src(unsigned slot, dma_addr_t src_port,
905 enum address_mode mode, enum fifo_width width)
906{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400907 unsigned ctlr;
908
909 ctlr = EDMA_CTLR(slot);
910 slot = EDMA_CHAN_SLOT(slot);
911
Sekhar Nori3f68b982010-05-04 14:11:35 +0530912 if (slot < edma_cc[ctlr]->num_slots) {
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400913 unsigned int i = edma_parm_read(ctlr, PARM_OPT, slot);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500914
915 if (mode) {
916 /* set SAM and program FWID */
917 i = (i & ~(EDMA_FWID)) | (SAM | ((width & 0x7) << 8));
918 } else {
919 /* clear SAM */
920 i &= ~SAM;
921 }
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400922 edma_parm_write(ctlr, PARM_OPT, slot, i);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500923
924 /* set the source port address
925 in source register of param structure */
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400926 edma_parm_write(ctlr, PARM_SRC, slot, src_port);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500927 }
928}
929EXPORT_SYMBOL(edma_set_src);
930
931/**
932 * edma_set_dest - set initial DMA destination address in parameter RAM slot
933 * @slot: parameter RAM slot being configured
934 * @dest_port: physical address of destination (memory, controller FIFO, etc)
935 * @addressMode: INCR, except in very rare cases
936 * @fifoWidth: ignored unless @addressMode is FIFO, else specifies the
937 * width to use when addressing the fifo (e.g. W8BIT, W32BIT)
938 *
939 * Note that the destination address is modified during the DMA transfer
940 * according to edma_set_dest_index().
941 */
942void edma_set_dest(unsigned slot, dma_addr_t dest_port,
943 enum address_mode mode, enum fifo_width width)
944{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400945 unsigned ctlr;
946
947 ctlr = EDMA_CTLR(slot);
948 slot = EDMA_CHAN_SLOT(slot);
949
Sekhar Nori3f68b982010-05-04 14:11:35 +0530950 if (slot < edma_cc[ctlr]->num_slots) {
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400951 unsigned int i = edma_parm_read(ctlr, PARM_OPT, slot);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500952
953 if (mode) {
954 /* set DAM and program FWID */
955 i = (i & ~(EDMA_FWID)) | (DAM | ((width & 0x7) << 8));
956 } else {
957 /* clear DAM */
958 i &= ~DAM;
959 }
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400960 edma_parm_write(ctlr, PARM_OPT, slot, i);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500961 /* set the destination port address
962 in dest register of param structure */
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400963 edma_parm_write(ctlr, PARM_DST, slot, dest_port);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500964 }
965}
966EXPORT_SYMBOL(edma_set_dest);
967
968/**
969 * edma_get_position - returns the current transfer points
970 * @slot: parameter RAM slot being examined
971 * @src: pointer to source port position
972 * @dst: pointer to destination port position
973 *
974 * Returns current source and destination addresses for a particular
975 * parameter RAM slot. Its channel should not be active when this is called.
976 */
977void edma_get_position(unsigned slot, dma_addr_t *src, dma_addr_t *dst)
978{
979 struct edmacc_param temp;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400980 unsigned ctlr;
Kevin Hilmana4768d22009-04-14 07:18:14 -0500981
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -0400982 ctlr = EDMA_CTLR(slot);
983 slot = EDMA_CHAN_SLOT(slot);
984
985 edma_read_slot(EDMA_CTLR_CHAN(ctlr, slot), &temp);
Kevin Hilmana4768d22009-04-14 07:18:14 -0500986 if (src != NULL)
987 *src = temp.src;
988 if (dst != NULL)
989 *dst = temp.dst;
990}
991EXPORT_SYMBOL(edma_get_position);
992
993/**
994 * edma_set_src_index - configure DMA source address indexing
995 * @slot: parameter RAM slot being configured
996 * @src_bidx: byte offset between source arrays in a frame
997 * @src_cidx: byte offset between source frames in a block
998 *
999 * Offsets are specified to support either contiguous or discontiguous
1000 * memory transfers, or repeated access to a hardware register, as needed.
1001 * When accessing hardware registers, both offsets are normally zero.
1002 */
1003void edma_set_src_index(unsigned slot, s16 src_bidx, s16 src_cidx)
1004{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001005 unsigned ctlr;
1006
1007 ctlr = EDMA_CTLR(slot);
1008 slot = EDMA_CHAN_SLOT(slot);
1009
Sekhar Nori3f68b982010-05-04 14:11:35 +05301010 if (slot < edma_cc[ctlr]->num_slots) {
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001011 edma_parm_modify(ctlr, PARM_SRC_DST_BIDX, slot,
Kevin Hilmana4768d22009-04-14 07:18:14 -05001012 0xffff0000, src_bidx);
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001013 edma_parm_modify(ctlr, PARM_SRC_DST_CIDX, slot,
Kevin Hilmana4768d22009-04-14 07:18:14 -05001014 0xffff0000, src_cidx);
1015 }
1016}
1017EXPORT_SYMBOL(edma_set_src_index);
1018
1019/**
1020 * edma_set_dest_index - configure DMA destination address indexing
1021 * @slot: parameter RAM slot being configured
1022 * @dest_bidx: byte offset between destination arrays in a frame
1023 * @dest_cidx: byte offset between destination frames in a block
1024 *
1025 * Offsets are specified to support either contiguous or discontiguous
1026 * memory transfers, or repeated access to a hardware register, as needed.
1027 * When accessing hardware registers, both offsets are normally zero.
1028 */
1029void edma_set_dest_index(unsigned slot, s16 dest_bidx, s16 dest_cidx)
1030{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001031 unsigned ctlr;
1032
1033 ctlr = EDMA_CTLR(slot);
1034 slot = EDMA_CHAN_SLOT(slot);
1035
Sekhar Nori3f68b982010-05-04 14:11:35 +05301036 if (slot < edma_cc[ctlr]->num_slots) {
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001037 edma_parm_modify(ctlr, PARM_SRC_DST_BIDX, slot,
Kevin Hilmana4768d22009-04-14 07:18:14 -05001038 0x0000ffff, dest_bidx << 16);
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001039 edma_parm_modify(ctlr, PARM_SRC_DST_CIDX, slot,
Kevin Hilmana4768d22009-04-14 07:18:14 -05001040 0x0000ffff, dest_cidx << 16);
1041 }
1042}
1043EXPORT_SYMBOL(edma_set_dest_index);
1044
1045/**
1046 * edma_set_transfer_params - configure DMA transfer parameters
1047 * @slot: parameter RAM slot being configured
1048 * @acnt: how many bytes per array (at least one)
1049 * @bcnt: how many arrays per frame (at least one)
1050 * @ccnt: how many frames per block (at least one)
1051 * @bcnt_rld: used only for A-Synchronized transfers; this specifies
1052 * the value to reload into bcnt when it decrements to zero
1053 * @sync_mode: ASYNC or ABSYNC
1054 *
1055 * See the EDMA3 documentation to understand how to configure and link
1056 * transfers using the fields in PaRAM slots. If you are not doing it
1057 * all at once with edma_write_slot(), you will use this routine
1058 * plus two calls each for source and destination, setting the initial
1059 * address and saying how to index that address.
1060 *
1061 * An example of an A-Synchronized transfer is a serial link using a
1062 * single word shift register. In that case, @acnt would be equal to
1063 * that word size; the serial controller issues a DMA synchronization
1064 * event to transfer each word, and memory access by the DMA transfer
1065 * controller will be word-at-a-time.
1066 *
1067 * An example of an AB-Synchronized transfer is a device using a FIFO.
1068 * In that case, @acnt equals the FIFO width and @bcnt equals its depth.
1069 * The controller with the FIFO issues DMA synchronization events when
1070 * the FIFO threshold is reached, and the DMA transfer controller will
1071 * transfer one frame to (or from) the FIFO. It will probably use
1072 * efficient burst modes to access memory.
1073 */
1074void edma_set_transfer_params(unsigned slot,
1075 u16 acnt, u16 bcnt, u16 ccnt,
1076 u16 bcnt_rld, enum sync_dimension sync_mode)
1077{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001078 unsigned ctlr;
1079
1080 ctlr = EDMA_CTLR(slot);
1081 slot = EDMA_CHAN_SLOT(slot);
1082
Sekhar Nori3f68b982010-05-04 14:11:35 +05301083 if (slot < edma_cc[ctlr]->num_slots) {
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001084 edma_parm_modify(ctlr, PARM_LINK_BCNTRLD, slot,
Kevin Hilmana4768d22009-04-14 07:18:14 -05001085 0x0000ffff, bcnt_rld << 16);
1086 if (sync_mode == ASYNC)
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001087 edma_parm_and(ctlr, PARM_OPT, slot, ~SYNCDIM);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001088 else
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001089 edma_parm_or(ctlr, PARM_OPT, slot, SYNCDIM);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001090 /* Set the acount, bcount, ccount registers */
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001091 edma_parm_write(ctlr, PARM_A_B_CNT, slot, (bcnt << 16) | acnt);
1092 edma_parm_write(ctlr, PARM_CCNT, slot, ccnt);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001093 }
1094}
1095EXPORT_SYMBOL(edma_set_transfer_params);
1096
1097/**
1098 * edma_link - link one parameter RAM slot to another
1099 * @from: parameter RAM slot originating the link
1100 * @to: parameter RAM slot which is the link target
1101 *
1102 * The originating slot should not be part of any active DMA transfer.
1103 */
1104void edma_link(unsigned from, unsigned to)
1105{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001106 unsigned ctlr_from, ctlr_to;
1107
1108 ctlr_from = EDMA_CTLR(from);
1109 from = EDMA_CHAN_SLOT(from);
1110 ctlr_to = EDMA_CTLR(to);
1111 to = EDMA_CHAN_SLOT(to);
1112
Sekhar Nori3f68b982010-05-04 14:11:35 +05301113 if (from >= edma_cc[ctlr_from]->num_slots)
Kevin Hilmana4768d22009-04-14 07:18:14 -05001114 return;
Sekhar Nori3f68b982010-05-04 14:11:35 +05301115 if (to >= edma_cc[ctlr_to]->num_slots)
Kevin Hilmana4768d22009-04-14 07:18:14 -05001116 return;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001117 edma_parm_modify(ctlr_from, PARM_LINK_BCNTRLD, from, 0xffff0000,
1118 PARM_OFFSET(to));
Kevin Hilmana4768d22009-04-14 07:18:14 -05001119}
1120EXPORT_SYMBOL(edma_link);
1121
1122/**
1123 * edma_unlink - cut link from one parameter RAM slot
1124 * @from: parameter RAM slot originating the link
1125 *
1126 * The originating slot should not be part of any active DMA transfer.
1127 * Its link is set to 0xffff.
1128 */
1129void edma_unlink(unsigned from)
1130{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001131 unsigned ctlr;
1132
1133 ctlr = EDMA_CTLR(from);
1134 from = EDMA_CHAN_SLOT(from);
1135
Sekhar Nori3f68b982010-05-04 14:11:35 +05301136 if (from >= edma_cc[ctlr]->num_slots)
Kevin Hilmana4768d22009-04-14 07:18:14 -05001137 return;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001138 edma_parm_or(ctlr, PARM_LINK_BCNTRLD, from, 0xffff);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001139}
1140EXPORT_SYMBOL(edma_unlink);
1141
1142/*-----------------------------------------------------------------------*/
1143
1144/* Parameter RAM operations (ii) -- read/write whole parameter sets */
1145
1146/**
1147 * edma_write_slot - write parameter RAM data for slot
1148 * @slot: number of parameter RAM slot being modified
1149 * @param: data to be written into parameter RAM slot
1150 *
1151 * Use this to assign all parameters of a transfer at once. This
1152 * allows more efficient setup of transfers than issuing multiple
1153 * calls to set up those parameters in small pieces, and provides
1154 * complete control over all transfer options.
1155 */
1156void edma_write_slot(unsigned slot, const struct edmacc_param *param)
1157{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001158 unsigned ctlr;
1159
1160 ctlr = EDMA_CTLR(slot);
1161 slot = EDMA_CHAN_SLOT(slot);
1162
Sekhar Nori3f68b982010-05-04 14:11:35 +05301163 if (slot >= edma_cc[ctlr]->num_slots)
Kevin Hilmana4768d22009-04-14 07:18:14 -05001164 return;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001165 memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(slot), param,
1166 PARM_SIZE);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001167}
1168EXPORT_SYMBOL(edma_write_slot);
1169
1170/**
1171 * edma_read_slot - read parameter RAM data from slot
1172 * @slot: number of parameter RAM slot being copied
1173 * @param: where to store copy of parameter RAM data
1174 *
1175 * Use this to read data from a parameter RAM slot, perhaps to
1176 * save them as a template for later reuse.
1177 */
1178void edma_read_slot(unsigned slot, struct edmacc_param *param)
1179{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001180 unsigned ctlr;
1181
1182 ctlr = EDMA_CTLR(slot);
1183 slot = EDMA_CHAN_SLOT(slot);
1184
Sekhar Nori3f68b982010-05-04 14:11:35 +05301185 if (slot >= edma_cc[ctlr]->num_slots)
Kevin Hilmana4768d22009-04-14 07:18:14 -05001186 return;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001187 memcpy_fromio(param, edmacc_regs_base[ctlr] + PARM_OFFSET(slot),
1188 PARM_SIZE);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001189}
1190EXPORT_SYMBOL(edma_read_slot);
1191
1192/*-----------------------------------------------------------------------*/
1193
1194/* Various EDMA channel control operations */
1195
1196/**
1197 * edma_pause - pause dma on a channel
1198 * @channel: on which edma_start() has been called
1199 *
1200 * This temporarily disables EDMA hardware events on the specified channel,
1201 * preventing them from triggering new transfers on its behalf
1202 */
1203void edma_pause(unsigned channel)
1204{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001205 unsigned ctlr;
1206
1207 ctlr = EDMA_CTLR(channel);
1208 channel = EDMA_CHAN_SLOT(channel);
1209
Sekhar Nori3f68b982010-05-04 14:11:35 +05301210 if (channel < edma_cc[ctlr]->num_channels) {
Sekhar Norid78a9492010-05-10 12:41:18 +05301211 unsigned int mask = BIT(channel & 0x1f);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001212
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001213 edma_shadow0_write_array(ctlr, SH_EECR, channel >> 5, mask);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001214 }
1215}
1216EXPORT_SYMBOL(edma_pause);
1217
1218/**
1219 * edma_resume - resumes dma on a paused channel
1220 * @channel: on which edma_pause() has been called
1221 *
1222 * This re-enables EDMA hardware events on the specified channel.
1223 */
1224void edma_resume(unsigned channel)
1225{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001226 unsigned ctlr;
1227
1228 ctlr = EDMA_CTLR(channel);
1229 channel = EDMA_CHAN_SLOT(channel);
1230
Sekhar Nori3f68b982010-05-04 14:11:35 +05301231 if (channel < edma_cc[ctlr]->num_channels) {
Sekhar Norid78a9492010-05-10 12:41:18 +05301232 unsigned int mask = BIT(channel & 0x1f);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001233
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001234 edma_shadow0_write_array(ctlr, SH_EESR, channel >> 5, mask);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001235 }
1236}
1237EXPORT_SYMBOL(edma_resume);
1238
1239/**
1240 * edma_start - start dma on a channel
1241 * @channel: channel being activated
1242 *
1243 * Channels with event associations will be triggered by their hardware
1244 * events, and channels without such associations will be triggered by
1245 * software. (At this writing there is no interface for using software
1246 * triggers except with channels that don't support hardware triggers.)
1247 *
1248 * Returns zero on success, else negative errno.
1249 */
1250int edma_start(unsigned channel)
1251{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001252 unsigned ctlr;
1253
1254 ctlr = EDMA_CTLR(channel);
1255 channel = EDMA_CHAN_SLOT(channel);
1256
Sekhar Nori3f68b982010-05-04 14:11:35 +05301257 if (channel < edma_cc[ctlr]->num_channels) {
Kevin Hilmana4768d22009-04-14 07:18:14 -05001258 int j = channel >> 5;
Sekhar Norid78a9492010-05-10 12:41:18 +05301259 unsigned int mask = BIT(channel & 0x1f);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001260
1261 /* EDMA channels without event association */
Sekhar Nori3f68b982010-05-04 14:11:35 +05301262 if (test_bit(channel, edma_cc[ctlr]->edma_unused)) {
Kevin Hilmana4768d22009-04-14 07:18:14 -05001263 pr_debug("EDMA: ESR%d %08x\n", j,
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001264 edma_shadow0_read_array(ctlr, SH_ESR, j));
1265 edma_shadow0_write_array(ctlr, SH_ESR, j, mask);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001266 return 0;
1267 }
1268
1269 /* EDMA channel with event association */
1270 pr_debug("EDMA: ER%d %08x\n", j,
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001271 edma_shadow0_read_array(ctlr, SH_ER, j));
Brian Niebuhrbb17ef12010-03-09 16:48:03 -06001272 /* Clear any pending event or error */
1273 edma_write_array(ctlr, EDMA_ECR, j, mask);
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001274 edma_write_array(ctlr, EDMA_EMCR, j, mask);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001275 /* Clear any SER */
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001276 edma_shadow0_write_array(ctlr, SH_SECR, j, mask);
1277 edma_shadow0_write_array(ctlr, SH_EESR, j, mask);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001278 pr_debug("EDMA: EER%d %08x\n", j,
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001279 edma_shadow0_read_array(ctlr, SH_EER, j));
Kevin Hilmana4768d22009-04-14 07:18:14 -05001280 return 0;
1281 }
1282
1283 return -EINVAL;
1284}
1285EXPORT_SYMBOL(edma_start);
1286
1287/**
1288 * edma_stop - stops dma on the channel passed
1289 * @channel: channel being deactivated
1290 *
1291 * When @lch is a channel, any active transfer is paused and
1292 * all pending hardware events are cleared. The current transfer
1293 * may not be resumed, and the channel's Parameter RAM should be
1294 * reinitialized before being reused.
1295 */
1296void edma_stop(unsigned channel)
1297{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001298 unsigned ctlr;
1299
1300 ctlr = EDMA_CTLR(channel);
1301 channel = EDMA_CHAN_SLOT(channel);
1302
Sekhar Nori3f68b982010-05-04 14:11:35 +05301303 if (channel < edma_cc[ctlr]->num_channels) {
Kevin Hilmana4768d22009-04-14 07:18:14 -05001304 int j = channel >> 5;
Sekhar Norid78a9492010-05-10 12:41:18 +05301305 unsigned int mask = BIT(channel & 0x1f);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001306
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001307 edma_shadow0_write_array(ctlr, SH_EECR, j, mask);
1308 edma_shadow0_write_array(ctlr, SH_ECR, j, mask);
1309 edma_shadow0_write_array(ctlr, SH_SECR, j, mask);
1310 edma_write_array(ctlr, EDMA_EMCR, j, mask);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001311
1312 pr_debug("EDMA: EER%d %08x\n", j,
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001313 edma_shadow0_read_array(ctlr, SH_EER, j));
Kevin Hilmana4768d22009-04-14 07:18:14 -05001314
1315 /* REVISIT: consider guarding against inappropriate event
1316 * chaining by overwriting with dummy_paramset.
1317 */
1318 }
1319}
1320EXPORT_SYMBOL(edma_stop);
1321
1322/******************************************************************************
1323 *
1324 * It cleans ParamEntry qand bring back EDMA to initial state if media has
1325 * been removed before EDMA has finished.It is usedful for removable media.
1326 * Arguments:
1327 * ch_no - channel no
1328 *
1329 * Return: zero on success, or corresponding error no on failure
1330 *
1331 * FIXME this should not be needed ... edma_stop() should suffice.
1332 *
1333 *****************************************************************************/
1334
1335void edma_clean_channel(unsigned channel)
1336{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001337 unsigned ctlr;
1338
1339 ctlr = EDMA_CTLR(channel);
1340 channel = EDMA_CHAN_SLOT(channel);
1341
Sekhar Nori3f68b982010-05-04 14:11:35 +05301342 if (channel < edma_cc[ctlr]->num_channels) {
Kevin Hilmana4768d22009-04-14 07:18:14 -05001343 int j = (channel >> 5);
Sekhar Norid78a9492010-05-10 12:41:18 +05301344 unsigned int mask = BIT(channel & 0x1f);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001345
1346 pr_debug("EDMA: EMR%d %08x\n", j,
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001347 edma_read_array(ctlr, EDMA_EMR, j));
1348 edma_shadow0_write_array(ctlr, SH_ECR, j, mask);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001349 /* Clear the corresponding EMR bits */
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001350 edma_write_array(ctlr, EDMA_EMCR, j, mask);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001351 /* Clear any SER */
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001352 edma_shadow0_write_array(ctlr, SH_SECR, j, mask);
Sekhar Norid78a9492010-05-10 12:41:18 +05301353 edma_write(ctlr, EDMA_CCERRCLR, BIT(16) | BIT(1) | BIT(0));
Kevin Hilmana4768d22009-04-14 07:18:14 -05001354 }
1355}
1356EXPORT_SYMBOL(edma_clean_channel);
1357
1358/*
1359 * edma_clear_event - clear an outstanding event on the DMA channel
1360 * Arguments:
1361 * channel - channel number
1362 */
1363void edma_clear_event(unsigned channel)
1364{
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001365 unsigned ctlr;
1366
1367 ctlr = EDMA_CTLR(channel);
1368 channel = EDMA_CHAN_SLOT(channel);
1369
Sekhar Nori3f68b982010-05-04 14:11:35 +05301370 if (channel >= edma_cc[ctlr]->num_channels)
Kevin Hilmana4768d22009-04-14 07:18:14 -05001371 return;
1372 if (channel < 32)
Sekhar Norid78a9492010-05-10 12:41:18 +05301373 edma_write(ctlr, EDMA_ECR, BIT(channel));
Kevin Hilmana4768d22009-04-14 07:18:14 -05001374 else
Sekhar Norid78a9492010-05-10 12:41:18 +05301375 edma_write(ctlr, EDMA_ECRH, BIT(channel - 32));
Kevin Hilmana4768d22009-04-14 07:18:14 -05001376}
1377EXPORT_SYMBOL(edma_clear_event);
1378
Matt Porter6cba4352013-06-20 16:06:38 -05001379#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DMADEVICES)
Kevin Hilmana4768d22009-04-14 07:18:14 -05001380
Matt Porter6cba4352013-06-20 16:06:38 -05001381static int edma_of_parse_dt(struct device *dev,
1382 struct device_node *node,
1383 struct edma_soc_info *pdata)
1384{
1385 int ret = 0, i;
1386 u32 value;
1387 struct edma_rsv_info *rsv_info;
1388 s8 (*queue_tc_map)[2], (*queue_priority_map)[2];
1389
1390 memset(pdata, 0, sizeof(struct edma_soc_info));
1391
1392 ret = of_property_read_u32(node, "dma-channels", &value);
1393 if (ret < 0)
1394 return ret;
1395 pdata->n_channel = value;
1396
1397 ret = of_property_read_u32(node, "ti,edma-regions", &value);
1398 if (ret < 0)
1399 return ret;
1400 pdata->n_region = value;
1401
1402 ret = of_property_read_u32(node, "ti,edma-slots", &value);
1403 if (ret < 0)
1404 return ret;
1405 pdata->n_slot = value;
1406
1407 pdata->n_cc = 1;
1408
1409 rsv_info = devm_kzalloc(dev, sizeof(struct edma_rsv_info), GFP_KERNEL);
1410 if (!rsv_info)
1411 return -ENOMEM;
1412 pdata->rsv = rsv_info;
1413
1414 queue_tc_map = devm_kzalloc(dev, 8*sizeof(s8), GFP_KERNEL);
1415 if (!queue_tc_map)
1416 return -ENOMEM;
1417
1418 for (i = 0; i < 3; i++) {
1419 queue_tc_map[i][0] = i;
1420 queue_tc_map[i][1] = i;
1421 }
1422 queue_tc_map[i][0] = -1;
1423 queue_tc_map[i][1] = -1;
1424
1425 pdata->queue_tc_mapping = queue_tc_map;
1426
1427 queue_priority_map = devm_kzalloc(dev, 8*sizeof(s8), GFP_KERNEL);
1428 if (!queue_priority_map)
1429 return -ENOMEM;
1430
1431 for (i = 0; i < 3; i++) {
1432 queue_priority_map[i][0] = i;
1433 queue_priority_map[i][1] = i;
1434 }
1435 queue_priority_map[i][0] = -1;
1436 queue_priority_map[i][1] = -1;
1437
1438 pdata->queue_priority_mapping = queue_priority_map;
1439
1440 pdata->default_queue = 0;
1441
1442 return ret;
1443}
1444
1445static struct of_dma_filter_info edma_filter_info = {
1446 .filter_fn = edma_filter_fn,
1447};
1448
1449static struct edma_soc_info *edma_setup_info_from_dt(struct device *dev,
1450 struct device_node *node)
1451{
1452 struct edma_soc_info *info;
1453 int ret;
1454
1455 info = devm_kzalloc(dev, sizeof(struct edma_soc_info), GFP_KERNEL);
1456 if (!info)
1457 return ERR_PTR(-ENOMEM);
1458
1459 ret = edma_of_parse_dt(dev, node, info);
1460 if (ret)
1461 return ERR_PTR(ret);
1462
1463 dma_cap_set(DMA_SLAVE, edma_filter_info.dma_cap);
1464 of_dma_controller_register(dev->of_node, of_dma_simple_xlate,
1465 &edma_filter_info);
1466
1467 return info;
1468}
1469#else
1470static struct edma_soc_info *edma_setup_info_from_dt(struct device *dev,
1471 struct device_node *node)
1472{
1473 return ERR_PTR(-ENOSYS);
1474}
1475#endif
1476
1477static int edma_probe(struct platform_device *pdev)
Kevin Hilmana4768d22009-04-14 07:18:14 -05001478{
Sekhar Noribc3ac9f2010-06-29 11:35:12 +05301479 struct edma_soc_info **info = pdev->dev.platform_data;
Matt Porter6cba4352013-06-20 16:06:38 -05001480 struct edma_soc_info *ninfo[EDMA_MAX_CC] = {NULL};
1481 s8 (*queue_priority_mapping)[2];
1482 s8 (*queue_tc_mapping)[2];
Rajashekhara, Sudhakar90bd4e62010-06-29 11:35:13 +05301483 int i, j, off, ln, found = 0;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001484 int status = -1;
Rajashekhara, Sudhakar90bd4e62010-06-29 11:35:13 +05301485 const s16 (*rsv_chans)[2];
1486 const s16 (*rsv_slots)[2];
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001487 int irq[EDMA_MAX_CC] = {0, 0};
1488 int err_irq[EDMA_MAX_CC] = {0, 0};
1489 struct resource *r[EDMA_MAX_CC] = {NULL};
Matt Porter6cba4352013-06-20 16:06:38 -05001490 struct resource res[EDMA_MAX_CC];
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001491 char res_name[10];
1492 char irq_name[10];
Matt Porter6cba4352013-06-20 16:06:38 -05001493 struct device_node *node = pdev->dev.of_node;
1494 struct device *dev = &pdev->dev;
1495 int ret;
1496
1497 if (node) {
1498 /* Check if this is a second instance registered */
1499 if (arch_num_cc) {
1500 dev_err(dev, "only one EDMA instance is supported via DT\n");
1501 return -ENODEV;
1502 }
1503
1504 ninfo[0] = edma_setup_info_from_dt(dev, node);
1505 if (IS_ERR(ninfo[0])) {
1506 dev_err(dev, "failed to get DT data\n");
1507 return PTR_ERR(ninfo[0]);
1508 }
1509
1510 info = ninfo;
1511 }
Kevin Hilmana4768d22009-04-14 07:18:14 -05001512
1513 if (!info)
1514 return -ENODEV;
1515
Matt Porter6cba4352013-06-20 16:06:38 -05001516 pm_runtime_enable(dev);
1517 ret = pm_runtime_get_sync(dev);
1518 if (ret < 0) {
1519 dev_err(dev, "pm_runtime_get_sync() failed\n");
1520 return ret;
1521 }
1522
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001523 for (j = 0; j < EDMA_MAX_CC; j++) {
Matt Porter6cba4352013-06-20 16:06:38 -05001524 if (!info[j]) {
1525 if (!found)
1526 return -ENODEV;
1527 break;
1528 }
1529 if (node) {
1530 ret = of_address_to_resource(node, j, &res[j]);
1531 if (!ret)
1532 r[j] = &res[j];
1533 } else {
1534 sprintf(res_name, "edma_cc%d", j);
1535 r[j] = platform_get_resource_byname(pdev,
1536 IORESOURCE_MEM,
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001537 res_name);
Matt Porter6cba4352013-06-20 16:06:38 -05001538 }
1539 if (!r[j]) {
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001540 if (found)
1541 break;
1542 else
1543 return -ENODEV;
Sekhar Nori243bc652010-05-04 14:11:36 +05301544 } else {
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001545 found = 1;
Sekhar Nori243bc652010-05-04 14:11:36 +05301546 }
Kevin Hilmana4768d22009-04-14 07:18:14 -05001547
Lad, Prabhakare7eff702013-06-17 20:27:58 +05301548 edmacc_regs_base[j] = devm_ioremap_resource(&pdev->dev, r[j]);
1549 if (IS_ERR(edmacc_regs_base[j]))
1550 return PTR_ERR(edmacc_regs_base[j]);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001551
Lad, Prabhakare7eff702013-06-17 20:27:58 +05301552 edma_cc[j] = devm_kzalloc(&pdev->dev, sizeof(struct edma),
1553 GFP_KERNEL);
1554 if (!edma_cc[j])
1555 return -ENOMEM;
Kevin Hilmana4768d22009-04-14 07:18:14 -05001556
Sekhar Noribc3ac9f2010-06-29 11:35:12 +05301557 edma_cc[j]->num_channels = min_t(unsigned, info[j]->n_channel,
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001558 EDMA_MAX_DMACH);
Sekhar Noribc3ac9f2010-06-29 11:35:12 +05301559 edma_cc[j]->num_slots = min_t(unsigned, info[j]->n_slot,
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001560 EDMA_MAX_PARAMENTRY);
Sekhar Noribc3ac9f2010-06-29 11:35:12 +05301561 edma_cc[j]->num_cc = min_t(unsigned, info[j]->n_cc,
1562 EDMA_MAX_CC);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001563
Sekhar Noribc3ac9f2010-06-29 11:35:12 +05301564 edma_cc[j]->default_queue = info[j]->default_queue;
Sandeep Paulraja0f02022009-07-27 09:57:07 -04001565
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001566 dev_dbg(&pdev->dev, "DMA REG BASE ADDR=%p\n",
1567 edmacc_regs_base[j]);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001568
Sekhar Nori3f68b982010-05-04 14:11:35 +05301569 for (i = 0; i < edma_cc[j]->num_slots; i++)
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001570 memcpy_toio(edmacc_regs_base[j] + PARM_OFFSET(i),
1571 &dummy_paramset, PARM_SIZE);
Kevin Hilmana4768d22009-04-14 07:18:14 -05001572
Sudhakar Rajashekharaf900d552010-01-06 17:29:49 +05301573 /* Mark all channels as unused */
Sekhar Nori3f68b982010-05-04 14:11:35 +05301574 memset(edma_cc[j]->edma_unused, 0xff,
1575 sizeof(edma_cc[j]->edma_unused));
Kevin Hilmana4768d22009-04-14 07:18:14 -05001576
Rajashekhara, Sudhakar90bd4e62010-06-29 11:35:13 +05301577 if (info[j]->rsv) {
1578
1579 /* Clear the reserved channels in unused list */
1580 rsv_chans = info[j]->rsv->rsv_chans;
1581 if (rsv_chans) {
1582 for (i = 0; rsv_chans[i][0] != -1; i++) {
1583 off = rsv_chans[i][0];
1584 ln = rsv_chans[i][1];
1585 clear_bits(off, ln,
Matt Porter6cba4352013-06-20 16:06:38 -05001586 edma_cc[j]->edma_unused);
Rajashekhara, Sudhakar90bd4e62010-06-29 11:35:13 +05301587 }
1588 }
1589
1590 /* Set the reserved slots in inuse list */
1591 rsv_slots = info[j]->rsv->rsv_slots;
1592 if (rsv_slots) {
1593 for (i = 0; rsv_slots[i][0] != -1; i++) {
1594 off = rsv_slots[i][0];
1595 ln = rsv_slots[i][1];
1596 set_bits(off, ln,
1597 edma_cc[j]->edma_inuse);
1598 }
1599 }
1600 }
1601
Matt Porter6cba4352013-06-20 16:06:38 -05001602
1603 if (node) {
1604 irq[j] = irq_of_parse_and_map(node, 0);
1605 } else {
1606 sprintf(irq_name, "edma%d", j);
1607 irq[j] = platform_get_irq_byname(pdev, irq_name);
1608 }
Sekhar Nori3f68b982010-05-04 14:11:35 +05301609 edma_cc[j]->irq_res_start = irq[j];
Lad, Prabhakare7eff702013-06-17 20:27:58 +05301610 status = devm_request_irq(&pdev->dev, irq[j],
1611 dma_irq_handler, 0, "edma",
1612 &pdev->dev);
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001613 if (status < 0) {
Lad, Prabhakare7eff702013-06-17 20:27:58 +05301614 dev_dbg(&pdev->dev,
1615 "devm_request_irq %d failed --> %d\n",
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001616 irq[j], status);
Lad, Prabhakare7eff702013-06-17 20:27:58 +05301617 return status;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001618 }
1619
Matt Porter6cba4352013-06-20 16:06:38 -05001620 if (node) {
1621 err_irq[j] = irq_of_parse_and_map(node, 2);
1622 } else {
1623 sprintf(irq_name, "edma%d_err", j);
1624 err_irq[j] = platform_get_irq_byname(pdev, irq_name);
1625 }
Sekhar Nori3f68b982010-05-04 14:11:35 +05301626 edma_cc[j]->irq_res_end = err_irq[j];
Lad, Prabhakare7eff702013-06-17 20:27:58 +05301627 status = devm_request_irq(&pdev->dev, err_irq[j],
1628 dma_ccerr_handler, 0,
1629 "edma_error", &pdev->dev);
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001630 if (status < 0) {
Lad, Prabhakare7eff702013-06-17 20:27:58 +05301631 dev_dbg(&pdev->dev,
1632 "devm_request_irq %d failed --> %d\n",
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001633 err_irq[j], status);
Lad, Prabhakare7eff702013-06-17 20:27:58 +05301634 return status;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001635 }
1636
Sekhar Nori3f68b982010-05-04 14:11:35 +05301637 for (i = 0; i < edma_cc[j]->num_channels; i++)
Heiko Schocher0b7580b2012-01-19 08:05:21 +01001638 map_dmach_queue(j, i, info[j]->default_queue);
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001639
Sekhar Noribc3ac9f2010-06-29 11:35:12 +05301640 queue_tc_mapping = info[j]->queue_tc_mapping;
1641 queue_priority_mapping = info[j]->queue_priority_mapping;
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001642
1643 /* Event queue to TC mapping */
1644 for (i = 0; queue_tc_mapping[i][0] != -1; i++)
1645 map_queue_tc(j, queue_tc_mapping[i][0],
1646 queue_tc_mapping[i][1]);
1647
1648 /* Event queue priority mapping */
1649 for (i = 0; queue_priority_mapping[i][0] != -1; i++)
1650 assign_priority_to_queue(j,
1651 queue_priority_mapping[i][0],
1652 queue_priority_mapping[i][1]);
1653
1654 /* Map the channel to param entry if channel mapping logic
1655 * exist
1656 */
1657 if (edma_read(j, EDMA_CCCFG) & CHMAP_EXIST)
1658 map_dmach_param(j);
1659
Sekhar Noribc3ac9f2010-06-29 11:35:12 +05301660 for (i = 0; i < info[j]->n_region; i++) {
Sudhakar Rajashekhara60902a22009-05-21 07:41:35 -04001661 edma_write_array2(j, EDMA_DRAE, i, 0, 0x0);
1662 edma_write_array2(j, EDMA_DRAE, i, 1, 0x0);
1663 edma_write_array(j, EDMA_QRAE, i, 0x0);
1664 }
Sudhakar Rajashekhara2d517502010-01-06 17:28:44 +05301665 arch_num_cc++;
Kevin Hilmana4768d22009-04-14 07:18:14 -05001666 }
1667
Kevin Hilmana4768d22009-04-14 07:18:14 -05001668 return 0;
Kevin Hilmana4768d22009-04-14 07:18:14 -05001669}
1670
Matt Porter6cba4352013-06-20 16:06:38 -05001671static const struct of_device_id edma_of_ids[] = {
1672 { .compatible = "ti,edma3", },
1673 {}
1674};
Kevin Hilmana4768d22009-04-14 07:18:14 -05001675
1676static struct platform_driver edma_driver = {
Matt Porter6cba4352013-06-20 16:06:38 -05001677 .driver = {
1678 .name = "edma",
1679 .of_match_table = edma_of_ids,
1680 },
1681 .probe = edma_probe,
Kevin Hilmana4768d22009-04-14 07:18:14 -05001682};
1683
1684static int __init edma_init(void)
1685{
1686 return platform_driver_probe(&edma_driver, edma_probe);
1687}
1688arch_initcall(edma_init);
1689