blob: a377bc72774084b567642c7dab0e4e89922e4cf6 [file] [log] [blame]
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -04001/*
2 * Texas Instruments CPDMA Driver
3 *
4 * Copyright (C) 2010 Texas Instruments
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation version 2.
9 *
10 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11 * kind, whether express or implied; without even the implied warranty
12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15#include <linux/kernel.h>
16#include <linux/spinlock.h>
17#include <linux/device.h>
Daniel Mack76fbc242012-06-28 06:12:32 +000018#include <linux/module.h>
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -040019#include <linux/slab.h>
20#include <linux/err.h>
21#include <linux/dma-mapping.h>
22#include <linux/io.h>
Sebastian Siewior817f6d12013-04-23 07:31:35 +000023#include <linux/delay.h>
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -040024
25#include "davinci_cpdma.h"
26
27/* DMA Registers */
28#define CPDMA_TXIDVER 0x00
29#define CPDMA_TXCONTROL 0x04
30#define CPDMA_TXTEARDOWN 0x08
31#define CPDMA_RXIDVER 0x10
32#define CPDMA_RXCONTROL 0x14
33#define CPDMA_SOFTRESET 0x1c
34#define CPDMA_RXTEARDOWN 0x18
35#define CPDMA_TXINTSTATRAW 0x80
36#define CPDMA_TXINTSTATMASKED 0x84
37#define CPDMA_TXINTMASKSET 0x88
38#define CPDMA_TXINTMASKCLEAR 0x8c
39#define CPDMA_MACINVECTOR 0x90
40#define CPDMA_MACEOIVECTOR 0x94
41#define CPDMA_RXINTSTATRAW 0xa0
42#define CPDMA_RXINTSTATMASKED 0xa4
43#define CPDMA_RXINTMASKSET 0xa8
44#define CPDMA_RXINTMASKCLEAR 0xac
45#define CPDMA_DMAINTSTATRAW 0xb0
46#define CPDMA_DMAINTSTATMASKED 0xb4
47#define CPDMA_DMAINTMASKSET 0xb8
48#define CPDMA_DMAINTMASKCLEAR 0xbc
49#define CPDMA_DMAINT_HOSTERR BIT(1)
50
51/* the following exist only if has_ext_regs is set */
52#define CPDMA_DMACONTROL 0x20
53#define CPDMA_DMASTATUS 0x24
54#define CPDMA_RXBUFFOFS 0x28
55#define CPDMA_EM_CONTROL 0x2c
56
57/* Descriptor mode bits */
58#define CPDMA_DESC_SOP BIT(31)
59#define CPDMA_DESC_EOP BIT(30)
60#define CPDMA_DESC_OWNER BIT(29)
61#define CPDMA_DESC_EOQ BIT(28)
62#define CPDMA_DESC_TD_COMPLETE BIT(27)
63#define CPDMA_DESC_PASS_CRC BIT(26)
Mugunthan V Nf6e135c2013-02-11 09:52:18 +000064#define CPDMA_DESC_TO_PORT_EN BIT(20)
65#define CPDMA_TO_PORT_SHIFT 16
66#define CPDMA_DESC_PORT_MASK (BIT(18) | BIT(17) | BIT(16))
Mugunthan V N28a19fe2013-05-29 20:22:01 +000067#define CPDMA_DESC_CRC_LEN 4
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -040068
69#define CPDMA_TEARDOWN_VALUE 0xfffffffc
70
71struct cpdma_desc {
72 /* hardware fields */
73 u32 hw_next;
74 u32 hw_buffer;
75 u32 hw_len;
76 u32 hw_mode;
77 /* software fields */
78 void *sw_token;
79 u32 sw_buffer;
80 u32 sw_len;
81};
82
83struct cpdma_desc_pool {
84 u32 phys;
Sriram6a1fef62011-03-22 02:31:03 +000085 u32 hw_addr;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -040086 void __iomem *iomap; /* ioremap map */
87 void *cpumap; /* dma_alloc map */
88 int desc_size, mem_size;
89 int num_desc, used_desc;
90 unsigned long *bitmap;
91 struct device *dev;
92 spinlock_t lock;
93};
94
95enum cpdma_state {
96 CPDMA_STATE_IDLE,
97 CPDMA_STATE_ACTIVE,
98 CPDMA_STATE_TEARDOWN,
99};
100
Arnd Bergmann32a6d902012-04-20 10:56:09 +0000101static const char *cpdma_state_str[] = { "idle", "active", "teardown" };
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400102
103struct cpdma_ctlr {
104 enum cpdma_state state;
105 struct cpdma_params params;
106 struct device *dev;
107 struct cpdma_desc_pool *pool;
108 spinlock_t lock;
109 struct cpdma_chan *channels[2 * CPDMA_MAX_CHANNELS];
110};
111
112struct cpdma_chan {
Mugunthan V Nfae50822013-01-17 06:31:34 +0000113 struct cpdma_desc __iomem *head, *tail;
114 void __iomem *hdp, *cp, *rxfree;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400115 enum cpdma_state state;
116 struct cpdma_ctlr *ctlr;
117 int chan_num;
118 spinlock_t lock;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400119 int count;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400120 u32 mask;
121 cpdma_handler_fn handler;
122 enum dma_data_direction dir;
123 struct cpdma_chan_stats stats;
124 /* offsets into dmaregs */
125 int int_set, int_clear, td;
126};
127
128/* The following make access to common cpdma_ctlr params more readable */
129#define dmaregs params.dmaregs
130#define num_chan params.num_chan
131
132/* various accessors */
133#define dma_reg_read(ctlr, ofs) __raw_readl((ctlr)->dmaregs + (ofs))
134#define chan_read(chan, fld) __raw_readl((chan)->fld)
135#define desc_read(desc, fld) __raw_readl(&(desc)->fld)
136#define dma_reg_write(ctlr, ofs, v) __raw_writel(v, (ctlr)->dmaregs + (ofs))
137#define chan_write(chan, fld, v) __raw_writel(v, (chan)->fld)
138#define desc_write(desc, fld, v) __raw_writel((u32)(v), &(desc)->fld)
139
Mugunthan V Nf6e135c2013-02-11 09:52:18 +0000140#define cpdma_desc_to_port(chan, mode, directed) \
141 do { \
142 if (!is_rx_chan(chan) && ((directed == 1) || \
143 (directed == 2))) \
144 mode |= (CPDMA_DESC_TO_PORT_EN | \
145 (directed << CPDMA_TO_PORT_SHIFT)); \
146 } while (0)
147
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400148/*
149 * Utility constructs for a cpdma descriptor pool. Some devices (e.g. davinci
150 * emac) have dedicated on-chip memory for these descriptors. Some other
151 * devices (e.g. cpsw switches) use plain old memory. Descriptor pools
152 * abstract out these details
153 */
154static struct cpdma_desc_pool *
Sriram6a1fef62011-03-22 02:31:03 +0000155cpdma_desc_pool_create(struct device *dev, u32 phys, u32 hw_addr,
156 int size, int align)
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400157{
158 int bitmap_size;
159 struct cpdma_desc_pool *pool;
160
161 pool = kzalloc(sizeof(*pool), GFP_KERNEL);
162 if (!pool)
163 return NULL;
164
165 spin_lock_init(&pool->lock);
166
167 pool->dev = dev;
168 pool->mem_size = size;
169 pool->desc_size = ALIGN(sizeof(struct cpdma_desc), align);
170 pool->num_desc = size / pool->desc_size;
171
172 bitmap_size = (pool->num_desc / BITS_PER_LONG) * sizeof(long);
173 pool->bitmap = kzalloc(bitmap_size, GFP_KERNEL);
174 if (!pool->bitmap)
175 goto fail;
176
177 if (phys) {
178 pool->phys = phys;
179 pool->iomap = ioremap(phys, size);
Sriram6a1fef62011-03-22 02:31:03 +0000180 pool->hw_addr = hw_addr;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400181 } else {
182 pool->cpumap = dma_alloc_coherent(dev, size, &pool->phys,
183 GFP_KERNEL);
Joe Perches43d620c2011-06-16 19:08:06 +0000184 pool->iomap = pool->cpumap;
Sriram6a1fef62011-03-22 02:31:03 +0000185 pool->hw_addr = pool->phys;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400186 }
187
188 if (pool->iomap)
189 return pool;
190
191fail:
192 kfree(pool->bitmap);
193 kfree(pool);
194 return NULL;
195}
196
197static void cpdma_desc_pool_destroy(struct cpdma_desc_pool *pool)
198{
199 unsigned long flags;
200
201 if (!pool)
202 return;
203
204 spin_lock_irqsave(&pool->lock, flags);
205 WARN_ON(pool->used_desc);
206 kfree(pool->bitmap);
207 if (pool->cpumap) {
208 dma_free_coherent(pool->dev, pool->mem_size, pool->cpumap,
209 pool->phys);
210 } else {
211 iounmap(pool->iomap);
212 }
213 spin_unlock_irqrestore(&pool->lock, flags);
214 kfree(pool);
215}
216
217static inline dma_addr_t desc_phys(struct cpdma_desc_pool *pool,
218 struct cpdma_desc __iomem *desc)
219{
220 if (!desc)
221 return 0;
Sriram6a1fef62011-03-22 02:31:03 +0000222 return pool->hw_addr + (__force dma_addr_t)desc -
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400223 (__force dma_addr_t)pool->iomap;
224}
225
226static inline struct cpdma_desc __iomem *
227desc_from_phys(struct cpdma_desc_pool *pool, dma_addr_t dma)
228{
Sriram6a1fef62011-03-22 02:31:03 +0000229 return dma ? pool->iomap + dma - pool->hw_addr : NULL;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400230}
231
232static struct cpdma_desc __iomem *
Mugunthan V Nfae50822013-01-17 06:31:34 +0000233cpdma_desc_alloc(struct cpdma_desc_pool *pool, int num_desc, bool is_rx)
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400234{
235 unsigned long flags;
236 int index;
Mugunthan V Nfae50822013-01-17 06:31:34 +0000237 int desc_start;
238 int desc_end;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400239 struct cpdma_desc __iomem *desc = NULL;
240
241 spin_lock_irqsave(&pool->lock, flags);
242
Mugunthan V Nfae50822013-01-17 06:31:34 +0000243 if (is_rx) {
244 desc_start = 0;
245 desc_end = pool->num_desc/2;
246 } else {
247 desc_start = pool->num_desc/2;
248 desc_end = pool->num_desc;
249 }
250
251 index = bitmap_find_next_zero_area(pool->bitmap,
252 desc_end, desc_start, num_desc, 0);
253 if (index < desc_end) {
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400254 bitmap_set(pool->bitmap, index, num_desc);
255 desc = pool->iomap + pool->desc_size * index;
256 pool->used_desc++;
257 }
258
259 spin_unlock_irqrestore(&pool->lock, flags);
260 return desc;
261}
262
263static void cpdma_desc_free(struct cpdma_desc_pool *pool,
264 struct cpdma_desc __iomem *desc, int num_desc)
265{
266 unsigned long flags, index;
267
268 index = ((unsigned long)desc - (unsigned long)pool->iomap) /
269 pool->desc_size;
270 spin_lock_irqsave(&pool->lock, flags);
271 bitmap_clear(pool->bitmap, index, num_desc);
272 pool->used_desc--;
273 spin_unlock_irqrestore(&pool->lock, flags);
274}
275
276struct cpdma_ctlr *cpdma_ctlr_create(struct cpdma_params *params)
277{
278 struct cpdma_ctlr *ctlr;
279
280 ctlr = kzalloc(sizeof(*ctlr), GFP_KERNEL);
281 if (!ctlr)
282 return NULL;
283
284 ctlr->state = CPDMA_STATE_IDLE;
285 ctlr->params = *params;
286 ctlr->dev = params->dev;
287 spin_lock_init(&ctlr->lock);
288
289 ctlr->pool = cpdma_desc_pool_create(ctlr->dev,
290 ctlr->params.desc_mem_phys,
Sriram6a1fef62011-03-22 02:31:03 +0000291 ctlr->params.desc_hw_addr,
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400292 ctlr->params.desc_mem_size,
293 ctlr->params.desc_align);
294 if (!ctlr->pool) {
295 kfree(ctlr);
296 return NULL;
297 }
298
299 if (WARN_ON(ctlr->num_chan > CPDMA_MAX_CHANNELS))
300 ctlr->num_chan = CPDMA_MAX_CHANNELS;
301 return ctlr;
302}
Arnd Bergmann32a6d902012-04-20 10:56:09 +0000303EXPORT_SYMBOL_GPL(cpdma_ctlr_create);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400304
305int cpdma_ctlr_start(struct cpdma_ctlr *ctlr)
306{
307 unsigned long flags;
308 int i;
309
310 spin_lock_irqsave(&ctlr->lock, flags);
311 if (ctlr->state != CPDMA_STATE_IDLE) {
312 spin_unlock_irqrestore(&ctlr->lock, flags);
313 return -EBUSY;
314 }
315
316 if (ctlr->params.has_soft_reset) {
Sebastian Siewior817f6d12013-04-23 07:31:35 +0000317 unsigned timeout = 10 * 100;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400318
319 dma_reg_write(ctlr, CPDMA_SOFTRESET, 1);
Sebastian Siewior817f6d12013-04-23 07:31:35 +0000320 while (timeout) {
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400321 if (dma_reg_read(ctlr, CPDMA_SOFTRESET) == 0)
322 break;
Sebastian Siewior817f6d12013-04-23 07:31:35 +0000323 udelay(10);
324 timeout--;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400325 }
Sebastian Siewior817f6d12013-04-23 07:31:35 +0000326 WARN_ON(!timeout);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400327 }
328
329 for (i = 0; i < ctlr->num_chan; i++) {
330 __raw_writel(0, ctlr->params.txhdp + 4 * i);
331 __raw_writel(0, ctlr->params.rxhdp + 4 * i);
332 __raw_writel(0, ctlr->params.txcp + 4 * i);
333 __raw_writel(0, ctlr->params.rxcp + 4 * i);
334 }
335
336 dma_reg_write(ctlr, CPDMA_RXINTMASKCLEAR, 0xffffffff);
337 dma_reg_write(ctlr, CPDMA_TXINTMASKCLEAR, 0xffffffff);
338
339 dma_reg_write(ctlr, CPDMA_TXCONTROL, 1);
340 dma_reg_write(ctlr, CPDMA_RXCONTROL, 1);
341
342 ctlr->state = CPDMA_STATE_ACTIVE;
343
344 for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++) {
345 if (ctlr->channels[i])
346 cpdma_chan_start(ctlr->channels[i]);
347 }
348 spin_unlock_irqrestore(&ctlr->lock, flags);
349 return 0;
350}
Arnd Bergmann32a6d902012-04-20 10:56:09 +0000351EXPORT_SYMBOL_GPL(cpdma_ctlr_start);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400352
353int cpdma_ctlr_stop(struct cpdma_ctlr *ctlr)
354{
355 unsigned long flags;
356 int i;
357
358 spin_lock_irqsave(&ctlr->lock, flags);
359 if (ctlr->state != CPDMA_STATE_ACTIVE) {
360 spin_unlock_irqrestore(&ctlr->lock, flags);
361 return -EINVAL;
362 }
363
364 ctlr->state = CPDMA_STATE_TEARDOWN;
365
366 for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++) {
367 if (ctlr->channels[i])
368 cpdma_chan_stop(ctlr->channels[i]);
369 }
370
371 dma_reg_write(ctlr, CPDMA_RXINTMASKCLEAR, 0xffffffff);
372 dma_reg_write(ctlr, CPDMA_TXINTMASKCLEAR, 0xffffffff);
373
374 dma_reg_write(ctlr, CPDMA_TXCONTROL, 0);
375 dma_reg_write(ctlr, CPDMA_RXCONTROL, 0);
376
377 ctlr->state = CPDMA_STATE_IDLE;
378
379 spin_unlock_irqrestore(&ctlr->lock, flags);
380 return 0;
381}
Arnd Bergmann32a6d902012-04-20 10:56:09 +0000382EXPORT_SYMBOL_GPL(cpdma_ctlr_stop);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400383
384int cpdma_ctlr_dump(struct cpdma_ctlr *ctlr)
385{
386 struct device *dev = ctlr->dev;
387 unsigned long flags;
388 int i;
389
390 spin_lock_irqsave(&ctlr->lock, flags);
391
392 dev_info(dev, "CPDMA: state: %s", cpdma_state_str[ctlr->state]);
393
394 dev_info(dev, "CPDMA: txidver: %x",
395 dma_reg_read(ctlr, CPDMA_TXIDVER));
396 dev_info(dev, "CPDMA: txcontrol: %x",
397 dma_reg_read(ctlr, CPDMA_TXCONTROL));
398 dev_info(dev, "CPDMA: txteardown: %x",
399 dma_reg_read(ctlr, CPDMA_TXTEARDOWN));
400 dev_info(dev, "CPDMA: rxidver: %x",
401 dma_reg_read(ctlr, CPDMA_RXIDVER));
402 dev_info(dev, "CPDMA: rxcontrol: %x",
403 dma_reg_read(ctlr, CPDMA_RXCONTROL));
404 dev_info(dev, "CPDMA: softreset: %x",
405 dma_reg_read(ctlr, CPDMA_SOFTRESET));
406 dev_info(dev, "CPDMA: rxteardown: %x",
407 dma_reg_read(ctlr, CPDMA_RXTEARDOWN));
408 dev_info(dev, "CPDMA: txintstatraw: %x",
409 dma_reg_read(ctlr, CPDMA_TXINTSTATRAW));
410 dev_info(dev, "CPDMA: txintstatmasked: %x",
411 dma_reg_read(ctlr, CPDMA_TXINTSTATMASKED));
412 dev_info(dev, "CPDMA: txintmaskset: %x",
413 dma_reg_read(ctlr, CPDMA_TXINTMASKSET));
414 dev_info(dev, "CPDMA: txintmaskclear: %x",
415 dma_reg_read(ctlr, CPDMA_TXINTMASKCLEAR));
416 dev_info(dev, "CPDMA: macinvector: %x",
417 dma_reg_read(ctlr, CPDMA_MACINVECTOR));
418 dev_info(dev, "CPDMA: maceoivector: %x",
419 dma_reg_read(ctlr, CPDMA_MACEOIVECTOR));
420 dev_info(dev, "CPDMA: rxintstatraw: %x",
421 dma_reg_read(ctlr, CPDMA_RXINTSTATRAW));
422 dev_info(dev, "CPDMA: rxintstatmasked: %x",
423 dma_reg_read(ctlr, CPDMA_RXINTSTATMASKED));
424 dev_info(dev, "CPDMA: rxintmaskset: %x",
425 dma_reg_read(ctlr, CPDMA_RXINTMASKSET));
426 dev_info(dev, "CPDMA: rxintmaskclear: %x",
427 dma_reg_read(ctlr, CPDMA_RXINTMASKCLEAR));
428 dev_info(dev, "CPDMA: dmaintstatraw: %x",
429 dma_reg_read(ctlr, CPDMA_DMAINTSTATRAW));
430 dev_info(dev, "CPDMA: dmaintstatmasked: %x",
431 dma_reg_read(ctlr, CPDMA_DMAINTSTATMASKED));
432 dev_info(dev, "CPDMA: dmaintmaskset: %x",
433 dma_reg_read(ctlr, CPDMA_DMAINTMASKSET));
434 dev_info(dev, "CPDMA: dmaintmaskclear: %x",
435 dma_reg_read(ctlr, CPDMA_DMAINTMASKCLEAR));
436
437 if (!ctlr->params.has_ext_regs) {
438 dev_info(dev, "CPDMA: dmacontrol: %x",
439 dma_reg_read(ctlr, CPDMA_DMACONTROL));
440 dev_info(dev, "CPDMA: dmastatus: %x",
441 dma_reg_read(ctlr, CPDMA_DMASTATUS));
442 dev_info(dev, "CPDMA: rxbuffofs: %x",
443 dma_reg_read(ctlr, CPDMA_RXBUFFOFS));
444 }
445
446 for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++)
447 if (ctlr->channels[i])
448 cpdma_chan_dump(ctlr->channels[i]);
449
450 spin_unlock_irqrestore(&ctlr->lock, flags);
451 return 0;
452}
Arnd Bergmann32a6d902012-04-20 10:56:09 +0000453EXPORT_SYMBOL_GPL(cpdma_ctlr_dump);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400454
455int cpdma_ctlr_destroy(struct cpdma_ctlr *ctlr)
456{
457 unsigned long flags;
458 int ret = 0, i;
459
460 if (!ctlr)
461 return -EINVAL;
462
463 spin_lock_irqsave(&ctlr->lock, flags);
464 if (ctlr->state != CPDMA_STATE_IDLE)
465 cpdma_ctlr_stop(ctlr);
466
Cyril Roelandt79876e02013-02-12 12:52:30 +0000467 for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++)
468 cpdma_chan_destroy(ctlr->channels[i]);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400469
470 cpdma_desc_pool_destroy(ctlr->pool);
471 spin_unlock_irqrestore(&ctlr->lock, flags);
472 kfree(ctlr);
473 return ret;
474}
Arnd Bergmann32a6d902012-04-20 10:56:09 +0000475EXPORT_SYMBOL_GPL(cpdma_ctlr_destroy);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400476
477int cpdma_ctlr_int_ctrl(struct cpdma_ctlr *ctlr, bool enable)
478{
479 unsigned long flags;
480 int i, reg;
481
482 spin_lock_irqsave(&ctlr->lock, flags);
483 if (ctlr->state != CPDMA_STATE_ACTIVE) {
484 spin_unlock_irqrestore(&ctlr->lock, flags);
485 return -EINVAL;
486 }
487
488 reg = enable ? CPDMA_DMAINTMASKSET : CPDMA_DMAINTMASKCLEAR;
489 dma_reg_write(ctlr, reg, CPDMA_DMAINT_HOSTERR);
490
491 for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++) {
492 if (ctlr->channels[i])
493 cpdma_chan_int_ctrl(ctlr->channels[i], enable);
494 }
495
496 spin_unlock_irqrestore(&ctlr->lock, flags);
497 return 0;
498}
Arnd Bergmann6929e242013-02-14 17:53:01 +0100499EXPORT_SYMBOL_GPL(cpdma_ctlr_int_ctrl);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400500
Mugunthan V N510a1e722013-02-17 22:19:20 +0000501void cpdma_ctlr_eoi(struct cpdma_ctlr *ctlr, u32 value)
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400502{
Mugunthan V N510a1e722013-02-17 22:19:20 +0000503 dma_reg_write(ctlr, CPDMA_MACEOIVECTOR, value);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400504}
Arnd Bergmann6929e242013-02-14 17:53:01 +0100505EXPORT_SYMBOL_GPL(cpdma_ctlr_eoi);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400506
507struct cpdma_chan *cpdma_chan_create(struct cpdma_ctlr *ctlr, int chan_num,
508 cpdma_handler_fn handler)
509{
510 struct cpdma_chan *chan;
511 int ret, offset = (chan_num % CPDMA_MAX_CHANNELS) * 4;
512 unsigned long flags;
513
514 if (__chan_linear(chan_num) >= ctlr->num_chan)
515 return NULL;
516
517 ret = -ENOMEM;
518 chan = kzalloc(sizeof(*chan), GFP_KERNEL);
519 if (!chan)
520 goto err_chan_alloc;
521
522 spin_lock_irqsave(&ctlr->lock, flags);
523 ret = -EBUSY;
524 if (ctlr->channels[chan_num])
525 goto err_chan_busy;
526
527 chan->ctlr = ctlr;
528 chan->state = CPDMA_STATE_IDLE;
529 chan->chan_num = chan_num;
530 chan->handler = handler;
531
532 if (is_rx_chan(chan)) {
533 chan->hdp = ctlr->params.rxhdp + offset;
534 chan->cp = ctlr->params.rxcp + offset;
535 chan->rxfree = ctlr->params.rxfree + offset;
536 chan->int_set = CPDMA_RXINTMASKSET;
537 chan->int_clear = CPDMA_RXINTMASKCLEAR;
538 chan->td = CPDMA_RXTEARDOWN;
539 chan->dir = DMA_FROM_DEVICE;
540 } else {
541 chan->hdp = ctlr->params.txhdp + offset;
542 chan->cp = ctlr->params.txcp + offset;
543 chan->int_set = CPDMA_TXINTMASKSET;
544 chan->int_clear = CPDMA_TXINTMASKCLEAR;
545 chan->td = CPDMA_TXTEARDOWN;
546 chan->dir = DMA_TO_DEVICE;
547 }
548 chan->mask = BIT(chan_linear(chan));
549
550 spin_lock_init(&chan->lock);
551
552 ctlr->channels[chan_num] = chan;
553 spin_unlock_irqrestore(&ctlr->lock, flags);
554 return chan;
555
556err_chan_busy:
557 spin_unlock_irqrestore(&ctlr->lock, flags);
558 kfree(chan);
559err_chan_alloc:
560 return ERR_PTR(ret);
561}
Arnd Bergmann32a6d902012-04-20 10:56:09 +0000562EXPORT_SYMBOL_GPL(cpdma_chan_create);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400563
564int cpdma_chan_destroy(struct cpdma_chan *chan)
565{
Julia Lawallf37c54b2012-08-14 05:49:47 +0000566 struct cpdma_ctlr *ctlr;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400567 unsigned long flags;
568
569 if (!chan)
570 return -EINVAL;
Julia Lawallf37c54b2012-08-14 05:49:47 +0000571 ctlr = chan->ctlr;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400572
573 spin_lock_irqsave(&ctlr->lock, flags);
574 if (chan->state != CPDMA_STATE_IDLE)
575 cpdma_chan_stop(chan);
576 ctlr->channels[chan->chan_num] = NULL;
577 spin_unlock_irqrestore(&ctlr->lock, flags);
578 kfree(chan);
579 return 0;
580}
Arnd Bergmann32a6d902012-04-20 10:56:09 +0000581EXPORT_SYMBOL_GPL(cpdma_chan_destroy);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400582
583int cpdma_chan_get_stats(struct cpdma_chan *chan,
584 struct cpdma_chan_stats *stats)
585{
586 unsigned long flags;
587 if (!chan)
588 return -EINVAL;
589 spin_lock_irqsave(&chan->lock, flags);
590 memcpy(stats, &chan->stats, sizeof(*stats));
591 spin_unlock_irqrestore(&chan->lock, flags);
592 return 0;
593}
594
595int cpdma_chan_dump(struct cpdma_chan *chan)
596{
597 unsigned long flags;
598 struct device *dev = chan->ctlr->dev;
599
600 spin_lock_irqsave(&chan->lock, flags);
601
602 dev_info(dev, "channel %d (%s %d) state %s",
603 chan->chan_num, is_rx_chan(chan) ? "rx" : "tx",
604 chan_linear(chan), cpdma_state_str[chan->state]);
605 dev_info(dev, "\thdp: %x\n", chan_read(chan, hdp));
606 dev_info(dev, "\tcp: %x\n", chan_read(chan, cp));
607 if (chan->rxfree) {
608 dev_info(dev, "\trxfree: %x\n",
609 chan_read(chan, rxfree));
610 }
611
612 dev_info(dev, "\tstats head_enqueue: %d\n",
613 chan->stats.head_enqueue);
614 dev_info(dev, "\tstats tail_enqueue: %d\n",
615 chan->stats.tail_enqueue);
616 dev_info(dev, "\tstats pad_enqueue: %d\n",
617 chan->stats.pad_enqueue);
618 dev_info(dev, "\tstats misqueued: %d\n",
619 chan->stats.misqueued);
620 dev_info(dev, "\tstats desc_alloc_fail: %d\n",
621 chan->stats.desc_alloc_fail);
622 dev_info(dev, "\tstats pad_alloc_fail: %d\n",
623 chan->stats.pad_alloc_fail);
624 dev_info(dev, "\tstats runt_receive_buff: %d\n",
625 chan->stats.runt_receive_buff);
626 dev_info(dev, "\tstats runt_transmit_buff: %d\n",
627 chan->stats.runt_transmit_buff);
628 dev_info(dev, "\tstats empty_dequeue: %d\n",
629 chan->stats.empty_dequeue);
630 dev_info(dev, "\tstats busy_dequeue: %d\n",
631 chan->stats.busy_dequeue);
632 dev_info(dev, "\tstats good_dequeue: %d\n",
633 chan->stats.good_dequeue);
634 dev_info(dev, "\tstats requeue: %d\n",
635 chan->stats.requeue);
636 dev_info(dev, "\tstats teardown_dequeue: %d\n",
637 chan->stats.teardown_dequeue);
638
639 spin_unlock_irqrestore(&chan->lock, flags);
640 return 0;
641}
642
643static void __cpdma_chan_submit(struct cpdma_chan *chan,
644 struct cpdma_desc __iomem *desc)
645{
646 struct cpdma_ctlr *ctlr = chan->ctlr;
647 struct cpdma_desc __iomem *prev = chan->tail;
648 struct cpdma_desc_pool *pool = ctlr->pool;
649 dma_addr_t desc_dma;
650 u32 mode;
651
652 desc_dma = desc_phys(pool, desc);
653
654 /* simple case - idle channel */
655 if (!chan->head) {
656 chan->stats.head_enqueue++;
657 chan->head = desc;
658 chan->tail = desc;
659 if (chan->state == CPDMA_STATE_ACTIVE)
660 chan_write(chan, hdp, desc_dma);
661 return;
662 }
663
664 /* first chain the descriptor at the tail of the list */
665 desc_write(prev, hw_next, desc_dma);
666 chan->tail = desc;
667 chan->stats.tail_enqueue++;
668
669 /* next check if EOQ has been triggered already */
670 mode = desc_read(prev, hw_mode);
671 if (((mode & (CPDMA_DESC_EOQ | CPDMA_DESC_OWNER)) == CPDMA_DESC_EOQ) &&
672 (chan->state == CPDMA_STATE_ACTIVE)) {
673 desc_write(prev, hw_mode, mode & ~CPDMA_DESC_EOQ);
674 chan_write(chan, hdp, desc_dma);
675 chan->stats.misqueued++;
676 }
677}
678
679int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data,
Sebastian Siewioraef614e2013-04-23 07:31:38 +0000680 int len, int directed)
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400681{
682 struct cpdma_ctlr *ctlr = chan->ctlr;
683 struct cpdma_desc __iomem *desc;
684 dma_addr_t buffer;
685 unsigned long flags;
686 u32 mode;
687 int ret = 0;
688
689 spin_lock_irqsave(&chan->lock, flags);
690
691 if (chan->state == CPDMA_STATE_TEARDOWN) {
692 ret = -EINVAL;
693 goto unlock_ret;
694 }
695
Mugunthan V Nfae50822013-01-17 06:31:34 +0000696 desc = cpdma_desc_alloc(ctlr->pool, 1, is_rx_chan(chan));
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400697 if (!desc) {
698 chan->stats.desc_alloc_fail++;
699 ret = -ENOMEM;
700 goto unlock_ret;
701 }
702
703 if (len < ctlr->params.min_packet_size) {
704 len = ctlr->params.min_packet_size;
705 chan->stats.runt_transmit_buff++;
706 }
707
708 buffer = dma_map_single(ctlr->dev, data, len, chan->dir);
709 mode = CPDMA_DESC_OWNER | CPDMA_DESC_SOP | CPDMA_DESC_EOP;
Mugunthan V Nf6e135c2013-02-11 09:52:18 +0000710 cpdma_desc_to_port(chan, mode, directed);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400711
712 desc_write(desc, hw_next, 0);
713 desc_write(desc, hw_buffer, buffer);
714 desc_write(desc, hw_len, len);
715 desc_write(desc, hw_mode, mode | len);
716 desc_write(desc, sw_token, token);
717 desc_write(desc, sw_buffer, buffer);
718 desc_write(desc, sw_len, len);
719
720 __cpdma_chan_submit(chan, desc);
721
722 if (chan->state == CPDMA_STATE_ACTIVE && chan->rxfree)
723 chan_write(chan, rxfree, 1);
724
725 chan->count++;
726
727unlock_ret:
728 spin_unlock_irqrestore(&chan->lock, flags);
729 return ret;
730}
Arnd Bergmann32a6d902012-04-20 10:56:09 +0000731EXPORT_SYMBOL_GPL(cpdma_chan_submit);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400732
Mugunthan V Nfae50822013-01-17 06:31:34 +0000733bool cpdma_check_free_tx_desc(struct cpdma_chan *chan)
734{
735 unsigned long flags;
736 int index;
737 bool ret;
738 struct cpdma_ctlr *ctlr = chan->ctlr;
739 struct cpdma_desc_pool *pool = ctlr->pool;
740
741 spin_lock_irqsave(&pool->lock, flags);
742
743 index = bitmap_find_next_zero_area(pool->bitmap,
744 pool->num_desc, pool->num_desc/2, 1, 0);
745
746 if (index < pool->num_desc)
747 ret = true;
748 else
749 ret = false;
750
751 spin_unlock_irqrestore(&pool->lock, flags);
752 return ret;
753}
754EXPORT_SYMBOL_GPL(cpdma_check_free_tx_desc);
755
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400756static void __cpdma_chan_free(struct cpdma_chan *chan,
757 struct cpdma_desc __iomem *desc,
758 int outlen, int status)
759{
760 struct cpdma_ctlr *ctlr = chan->ctlr;
761 struct cpdma_desc_pool *pool = ctlr->pool;
762 dma_addr_t buff_dma;
763 int origlen;
764 void *token;
765
766 token = (void *)desc_read(desc, sw_token);
767 buff_dma = desc_read(desc, sw_buffer);
768 origlen = desc_read(desc, sw_len);
769
770 dma_unmap_single(ctlr->dev, buff_dma, origlen, chan->dir);
771 cpdma_desc_free(pool, desc, 1);
772 (*chan->handler)(token, outlen, status);
773}
774
775static int __cpdma_chan_process(struct cpdma_chan *chan)
776{
777 struct cpdma_ctlr *ctlr = chan->ctlr;
778 struct cpdma_desc __iomem *desc;
779 int status, outlen;
Sebastian Siewiorb4727e62013-04-23 07:31:39 +0000780 int cb_status = 0;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400781 struct cpdma_desc_pool *pool = ctlr->pool;
782 dma_addr_t desc_dma;
783 unsigned long flags;
784
785 spin_lock_irqsave(&chan->lock, flags);
786
787 desc = chan->head;
788 if (!desc) {
789 chan->stats.empty_dequeue++;
790 status = -ENOENT;
791 goto unlock_ret;
792 }
793 desc_dma = desc_phys(pool, desc);
794
795 status = __raw_readl(&desc->hw_mode);
796 outlen = status & 0x7ff;
797 if (status & CPDMA_DESC_OWNER) {
798 chan->stats.busy_dequeue++;
799 status = -EBUSY;
800 goto unlock_ret;
801 }
Mugunthan V N28a19fe2013-05-29 20:22:01 +0000802
803 if (status & CPDMA_DESC_PASS_CRC)
804 outlen -= CPDMA_DESC_CRC_LEN;
805
Mugunthan V Nf6e135c2013-02-11 09:52:18 +0000806 status = status & (CPDMA_DESC_EOQ | CPDMA_DESC_TD_COMPLETE |
807 CPDMA_DESC_PORT_MASK);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400808
809 chan->head = desc_from_phys(pool, desc_read(desc, hw_next));
810 chan_write(chan, cp, desc_dma);
811 chan->count--;
812 chan->stats.good_dequeue++;
813
814 if (status & CPDMA_DESC_EOQ) {
815 chan->stats.requeue++;
816 chan_write(chan, hdp, desc_phys(pool, chan->head));
817 }
818
819 spin_unlock_irqrestore(&chan->lock, flags);
Sebastian Siewiorb4727e62013-04-23 07:31:39 +0000820 if (unlikely(status & CPDMA_DESC_TD_COMPLETE))
821 cb_status = -ENOSYS;
822 else
823 cb_status = status;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400824
Sebastian Siewiorb4727e62013-04-23 07:31:39 +0000825 __cpdma_chan_free(chan, desc, outlen, cb_status);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400826 return status;
827
828unlock_ret:
829 spin_unlock_irqrestore(&chan->lock, flags);
830 return status;
831}
832
833int cpdma_chan_process(struct cpdma_chan *chan, int quota)
834{
835 int used = 0, ret = 0;
836
837 if (chan->state != CPDMA_STATE_ACTIVE)
838 return -EINVAL;
839
840 while (used < quota) {
841 ret = __cpdma_chan_process(chan);
842 if (ret < 0)
843 break;
844 used++;
845 }
846 return used;
847}
Arnd Bergmann32a6d902012-04-20 10:56:09 +0000848EXPORT_SYMBOL_GPL(cpdma_chan_process);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400849
850int cpdma_chan_start(struct cpdma_chan *chan)
851{
852 struct cpdma_ctlr *ctlr = chan->ctlr;
853 struct cpdma_desc_pool *pool = ctlr->pool;
854 unsigned long flags;
855
856 spin_lock_irqsave(&chan->lock, flags);
857 if (chan->state != CPDMA_STATE_IDLE) {
858 spin_unlock_irqrestore(&chan->lock, flags);
859 return -EBUSY;
860 }
861 if (ctlr->state != CPDMA_STATE_ACTIVE) {
862 spin_unlock_irqrestore(&chan->lock, flags);
863 return -EINVAL;
864 }
865 dma_reg_write(ctlr, chan->int_set, chan->mask);
866 chan->state = CPDMA_STATE_ACTIVE;
867 if (chan->head) {
868 chan_write(chan, hdp, desc_phys(pool, chan->head));
869 if (chan->rxfree)
870 chan_write(chan, rxfree, chan->count);
871 }
872
873 spin_unlock_irqrestore(&chan->lock, flags);
874 return 0;
875}
Arnd Bergmann32a6d902012-04-20 10:56:09 +0000876EXPORT_SYMBOL_GPL(cpdma_chan_start);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400877
878int cpdma_chan_stop(struct cpdma_chan *chan)
879{
880 struct cpdma_ctlr *ctlr = chan->ctlr;
881 struct cpdma_desc_pool *pool = ctlr->pool;
882 unsigned long flags;
883 int ret;
Sebastian Siewior817f6d12013-04-23 07:31:35 +0000884 unsigned timeout;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400885
886 spin_lock_irqsave(&chan->lock, flags);
887 if (chan->state != CPDMA_STATE_ACTIVE) {
888 spin_unlock_irqrestore(&chan->lock, flags);
889 return -EINVAL;
890 }
891
892 chan->state = CPDMA_STATE_TEARDOWN;
893 dma_reg_write(ctlr, chan->int_clear, chan->mask);
894
895 /* trigger teardown */
Christian Rieschb4ad0422012-02-22 21:58:00 +0000896 dma_reg_write(ctlr, chan->td, chan_linear(chan));
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400897
898 /* wait for teardown complete */
Sebastian Siewior817f6d12013-04-23 07:31:35 +0000899 timeout = 100 * 100; /* 100 ms */
900 while (timeout) {
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400901 u32 cp = chan_read(chan, cp);
902 if ((cp & CPDMA_TEARDOWN_VALUE) == CPDMA_TEARDOWN_VALUE)
903 break;
Sebastian Siewior817f6d12013-04-23 07:31:35 +0000904 udelay(10);
905 timeout--;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400906 }
Sebastian Siewior817f6d12013-04-23 07:31:35 +0000907 WARN_ON(!timeout);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400908 chan_write(chan, cp, CPDMA_TEARDOWN_VALUE);
909
910 /* handle completed packets */
Ilya Yanok7746ab02011-12-18 10:02:04 +0000911 spin_unlock_irqrestore(&chan->lock, flags);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400912 do {
913 ret = __cpdma_chan_process(chan);
914 if (ret < 0)
915 break;
916 } while ((ret & CPDMA_DESC_TD_COMPLETE) == 0);
Ilya Yanok7746ab02011-12-18 10:02:04 +0000917 spin_lock_irqsave(&chan->lock, flags);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400918
919 /* remaining packets haven't been tx/rx'ed, clean them up */
920 while (chan->head) {
921 struct cpdma_desc __iomem *desc = chan->head;
922 dma_addr_t next_dma;
923
924 next_dma = desc_read(desc, hw_next);
925 chan->head = desc_from_phys(pool, next_dma);
htbeginffb5ba92012-10-01 16:42:43 +0000926 chan->count--;
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400927 chan->stats.teardown_dequeue++;
928
929 /* issue callback without locks held */
930 spin_unlock_irqrestore(&chan->lock, flags);
931 __cpdma_chan_free(chan, desc, 0, -ENOSYS);
932 spin_lock_irqsave(&chan->lock, flags);
933 }
934
935 chan->state = CPDMA_STATE_IDLE;
936 spin_unlock_irqrestore(&chan->lock, flags);
937 return 0;
938}
Arnd Bergmann32a6d902012-04-20 10:56:09 +0000939EXPORT_SYMBOL_GPL(cpdma_chan_stop);
Cyril Chemparathyef8c2da2010-09-15 10:11:28 -0400940
941int cpdma_chan_int_ctrl(struct cpdma_chan *chan, bool enable)
942{
943 unsigned long flags;
944
945 spin_lock_irqsave(&chan->lock, flags);
946 if (chan->state != CPDMA_STATE_ACTIVE) {
947 spin_unlock_irqrestore(&chan->lock, flags);
948 return -EINVAL;
949 }
950
951 dma_reg_write(chan->ctlr, enable ? chan->int_set : chan->int_clear,
952 chan->mask);
953 spin_unlock_irqrestore(&chan->lock, flags);
954
955 return 0;
956}
957
958struct cpdma_control_info {
959 u32 reg;
960 u32 shift, mask;
961 int access;
962#define ACCESS_RO BIT(0)
963#define ACCESS_WO BIT(1)
964#define ACCESS_RW (ACCESS_RO | ACCESS_WO)
965};
966
967struct cpdma_control_info controls[] = {
968 [CPDMA_CMD_IDLE] = {CPDMA_DMACONTROL, 3, 1, ACCESS_WO},
969 [CPDMA_COPY_ERROR_FRAMES] = {CPDMA_DMACONTROL, 4, 1, ACCESS_RW},
970 [CPDMA_RX_OFF_LEN_UPDATE] = {CPDMA_DMACONTROL, 2, 1, ACCESS_RW},
971 [CPDMA_RX_OWNERSHIP_FLIP] = {CPDMA_DMACONTROL, 1, 1, ACCESS_RW},
972 [CPDMA_TX_PRIO_FIXED] = {CPDMA_DMACONTROL, 0, 1, ACCESS_RW},
973 [CPDMA_STAT_IDLE] = {CPDMA_DMASTATUS, 31, 1, ACCESS_RO},
974 [CPDMA_STAT_TX_ERR_CODE] = {CPDMA_DMASTATUS, 20, 0xf, ACCESS_RW},
975 [CPDMA_STAT_TX_ERR_CHAN] = {CPDMA_DMASTATUS, 16, 0x7, ACCESS_RW},
976 [CPDMA_STAT_RX_ERR_CODE] = {CPDMA_DMASTATUS, 12, 0xf, ACCESS_RW},
977 [CPDMA_STAT_RX_ERR_CHAN] = {CPDMA_DMASTATUS, 8, 0x7, ACCESS_RW},
978 [CPDMA_RX_BUFFER_OFFSET] = {CPDMA_RXBUFFOFS, 0, 0xffff, ACCESS_RW},
979};
980
981int cpdma_control_get(struct cpdma_ctlr *ctlr, int control)
982{
983 unsigned long flags;
984 struct cpdma_control_info *info = &controls[control];
985 int ret;
986
987 spin_lock_irqsave(&ctlr->lock, flags);
988
989 ret = -ENOTSUPP;
990 if (!ctlr->params.has_ext_regs)
991 goto unlock_ret;
992
993 ret = -EINVAL;
994 if (ctlr->state != CPDMA_STATE_ACTIVE)
995 goto unlock_ret;
996
997 ret = -ENOENT;
998 if (control < 0 || control >= ARRAY_SIZE(controls))
999 goto unlock_ret;
1000
1001 ret = -EPERM;
1002 if ((info->access & ACCESS_RO) != ACCESS_RO)
1003 goto unlock_ret;
1004
1005 ret = (dma_reg_read(ctlr, info->reg) >> info->shift) & info->mask;
1006
1007unlock_ret:
1008 spin_unlock_irqrestore(&ctlr->lock, flags);
1009 return ret;
1010}
1011
1012int cpdma_control_set(struct cpdma_ctlr *ctlr, int control, int value)
1013{
1014 unsigned long flags;
1015 struct cpdma_control_info *info = &controls[control];
1016 int ret;
1017 u32 val;
1018
1019 spin_lock_irqsave(&ctlr->lock, flags);
1020
1021 ret = -ENOTSUPP;
1022 if (!ctlr->params.has_ext_regs)
1023 goto unlock_ret;
1024
1025 ret = -EINVAL;
1026 if (ctlr->state != CPDMA_STATE_ACTIVE)
1027 goto unlock_ret;
1028
1029 ret = -ENOENT;
1030 if (control < 0 || control >= ARRAY_SIZE(controls))
1031 goto unlock_ret;
1032
1033 ret = -EPERM;
1034 if ((info->access & ACCESS_WO) != ACCESS_WO)
1035 goto unlock_ret;
1036
1037 val = dma_reg_read(ctlr, info->reg);
1038 val &= ~(info->mask << info->shift);
1039 val |= (value & info->mask) << info->shift;
1040 dma_reg_write(ctlr, info->reg, val);
1041 ret = 0;
1042
1043unlock_ret:
1044 spin_unlock_irqrestore(&ctlr->lock, flags);
1045 return ret;
1046}
Arnd Bergmann6929e242013-02-14 17:53:01 +01001047EXPORT_SYMBOL_GPL(cpdma_control_set);
Sebastian Siewior4bc21d42013-04-24 08:48:22 +00001048
1049MODULE_LICENSE("GPL");