blob: 16a7d2b605edfe6764f8071faf8898943b9f24b3 [file] [log] [blame]
Linus Walleij8d318a52010-03-30 15:33:42 +02001/*
2 * driver/dma/ste_dma40.c
3 *
4 * Copyright (C) ST-Ericsson 2007-2010
5 * License terms: GNU General Public License (GPL) version 2
6 * Author: Per Friden <per.friden@stericsson.com>
7 * Author: Jonas Aaberg <jonas.aberg@stericsson.com>
8 *
9 */
10
11#include <linux/kernel.h>
12#include <linux/slab.h>
13#include <linux/dmaengine.h>
14#include <linux/platform_device.h>
15#include <linux/clk.h>
16#include <linux/delay.h>
17
18#include <plat/ste_dma40.h>
19
20#include "ste_dma40_ll.h"
21
22#define D40_NAME "dma40"
23
24#define D40_PHY_CHAN -1
25
26/* For masking out/in 2 bit channel positions */
27#define D40_CHAN_POS(chan) (2 * (chan / 2))
28#define D40_CHAN_POS_MASK(chan) (0x3 << D40_CHAN_POS(chan))
29
30/* Maximum iterations taken before giving up suspending a channel */
31#define D40_SUSPEND_MAX_IT 500
32
33#define D40_ALLOC_FREE (1 << 31)
34#define D40_ALLOC_PHY (1 << 30)
35#define D40_ALLOC_LOG_FREE 0
36
37/* The number of free d40_desc to keep in memory before starting
38 * to kfree() them */
39#define D40_DESC_CACHE_SIZE 50
40
41/* Hardware designer of the block */
42#define D40_PERIPHID2_DESIGNER 0x8
43
44/**
45 * enum 40_command - The different commands and/or statuses.
46 *
47 * @D40_DMA_STOP: DMA channel command STOP or status STOPPED,
48 * @D40_DMA_RUN: The DMA channel is RUNNING of the command RUN.
49 * @D40_DMA_SUSPEND_REQ: Request the DMA to SUSPEND as soon as possible.
50 * @D40_DMA_SUSPENDED: The DMA channel is SUSPENDED.
51 */
52enum d40_command {
53 D40_DMA_STOP = 0,
54 D40_DMA_RUN = 1,
55 D40_DMA_SUSPEND_REQ = 2,
56 D40_DMA_SUSPENDED = 3
57};
58
59/**
60 * struct d40_lli_pool - Structure for keeping LLIs in memory
61 *
62 * @base: Pointer to memory area when the pre_alloc_lli's are not large
63 * enough, IE bigger than the most common case, 1 dst and 1 src. NULL if
64 * pre_alloc_lli is used.
65 * @size: The size in bytes of the memory at base or the size of pre_alloc_lli.
66 * @pre_alloc_lli: Pre allocated area for the most common case of transfers,
67 * one buffer to one buffer.
68 */
69struct d40_lli_pool {
70 void *base;
71 int size;
72 /* Space for dst and src, plus an extra for padding */
73 u8 pre_alloc_lli[3 * sizeof(struct d40_phy_lli)];
74};
75
76/**
77 * struct d40_desc - A descriptor is one DMA job.
78 *
79 * @lli_phy: LLI settings for physical channel. Both src and dst=
80 * points into the lli_pool, to base if lli_len > 1 or to pre_alloc_lli if
81 * lli_len equals one.
82 * @lli_log: Same as above but for logical channels.
83 * @lli_pool: The pool with two entries pre-allocated.
84 * @lli_len: Number of LLI's in lli_pool
85 * @lli_tcount: Number of LLIs processed in the transfer. When equals lli_len
86 * then this transfer job is done.
87 * @txd: DMA engine struct. Used for among other things for communication
88 * during a transfer.
89 * @node: List entry.
90 * @dir: The transfer direction of this job.
91 * @is_in_client_list: true if the client owns this descriptor.
92 *
93 * This descriptor is used for both logical and physical transfers.
94 */
95
96struct d40_desc {
97 /* LLI physical */
98 struct d40_phy_lli_bidir lli_phy;
99 /* LLI logical */
100 struct d40_log_lli_bidir lli_log;
101
102 struct d40_lli_pool lli_pool;
103 u32 lli_len;
104 u32 lli_tcount;
105
106 struct dma_async_tx_descriptor txd;
107 struct list_head node;
108
109 enum dma_data_direction dir;
110 bool is_in_client_list;
111};
112
113/**
114 * struct d40_lcla_pool - LCLA pool settings and data.
115 *
116 * @base: The virtual address of LCLA.
117 * @phy: Physical base address of LCLA.
118 * @base_size: size of lcla.
119 * @lock: Lock to protect the content in this struct.
120 * @alloc_map: Mapping between physical channel and LCLA entries.
121 * @num_blocks: The number of entries of alloc_map. Equals to the
122 * number of physical channels.
123 */
124struct d40_lcla_pool {
125 void *base;
126 dma_addr_t phy;
127 resource_size_t base_size;
128 spinlock_t lock;
129 u32 *alloc_map;
130 int num_blocks;
131};
132
133/**
134 * struct d40_phy_res - struct for handling eventlines mapped to physical
135 * channels.
136 *
137 * @lock: A lock protection this entity.
138 * @num: The physical channel number of this entity.
139 * @allocated_src: Bit mapped to show which src event line's are mapped to
140 * this physical channel. Can also be free or physically allocated.
141 * @allocated_dst: Same as for src but is dst.
142 * allocated_dst and allocated_src uses the D40_ALLOC* defines as well as
143 * event line number. Both allocated_src and allocated_dst can not be
144 * allocated to a physical channel, since the interrupt handler has then
145 * no way of figure out which one the interrupt belongs to.
146 */
147struct d40_phy_res {
148 spinlock_t lock;
149 int num;
150 u32 allocated_src;
151 u32 allocated_dst;
152};
153
154struct d40_base;
155
156/**
157 * struct d40_chan - Struct that describes a channel.
158 *
159 * @lock: A spinlock to protect this struct.
160 * @log_num: The logical number, if any of this channel.
161 * @completed: Starts with 1, after first interrupt it is set to dma engine's
162 * current cookie.
163 * @pending_tx: The number of pending transfers. Used between interrupt handler
164 * and tasklet.
165 * @busy: Set to true when transfer is ongoing on this channel.
166 * @phy_chan: Pointer to physical channel which this instance runs on.
167 * @chan: DMA engine handle.
168 * @tasklet: Tasklet that gets scheduled from interrupt context to complete a
169 * transfer and call client callback.
170 * @client: Cliented owned descriptor list.
171 * @active: Active descriptor.
172 * @queue: Queued jobs.
173 * @free: List of free descripts, ready to be reused.
174 * @free_len: Number of descriptors in the free list.
175 * @dma_cfg: The client configuration of this dma channel.
176 * @base: Pointer to the device instance struct.
177 * @src_def_cfg: Default cfg register setting for src.
178 * @dst_def_cfg: Default cfg register setting for dst.
179 * @log_def: Default logical channel settings.
180 * @lcla: Space for one dst src pair for logical channel transfers.
181 * @lcpa: Pointer to dst and src lcpa settings.
182 *
183 * This struct can either "be" a logical or a physical channel.
184 */
185struct d40_chan {
186 spinlock_t lock;
187 int log_num;
188 /* ID of the most recent completed transfer */
189 int completed;
190 int pending_tx;
191 bool busy;
192 struct d40_phy_res *phy_chan;
193 struct dma_chan chan;
194 struct tasklet_struct tasklet;
195 struct list_head client;
196 struct list_head active;
197 struct list_head queue;
198 struct list_head free;
199 int free_len;
200 struct stedma40_chan_cfg dma_cfg;
201 struct d40_base *base;
202 /* Default register configurations */
203 u32 src_def_cfg;
204 u32 dst_def_cfg;
205 struct d40_def_lcsp log_def;
206 struct d40_lcla_elem lcla;
207 struct d40_log_lli_full *lcpa;
208};
209
210/**
211 * struct d40_base - The big global struct, one for each probe'd instance.
212 *
213 * @interrupt_lock: Lock used to make sure one interrupt is handle a time.
214 * @execmd_lock: Lock for execute command usage since several channels share
215 * the same physical register.
216 * @dev: The device structure.
217 * @virtbase: The virtual base address of the DMA's register.
218 * @clk: Pointer to the DMA clock structure.
219 * @phy_start: Physical memory start of the DMA registers.
220 * @phy_size: Size of the DMA register map.
221 * @irq: The IRQ number.
222 * @num_phy_chans: The number of physical channels. Read from HW. This
223 * is the number of available channels for this driver, not counting "Secure
224 * mode" allocated physical channels.
225 * @num_log_chans: The number of logical channels. Calculated from
226 * num_phy_chans.
227 * @dma_both: dma_device channels that can do both memcpy and slave transfers.
228 * @dma_slave: dma_device channels that can do only do slave transfers.
229 * @dma_memcpy: dma_device channels that can do only do memcpy transfers.
230 * @phy_chans: Room for all possible physical channels in system.
231 * @log_chans: Room for all possible logical channels in system.
232 * @lookup_log_chans: Used to map interrupt number to logical channel. Points
233 * to log_chans entries.
234 * @lookup_phy_chans: Used to map interrupt number to physical channel. Points
235 * to phy_chans entries.
236 * @plat_data: Pointer to provided platform_data which is the driver
237 * configuration.
238 * @phy_res: Vector containing all physical channels.
239 * @lcla_pool: lcla pool settings and data.
240 * @lcpa_base: The virtual mapped address of LCPA.
241 * @phy_lcpa: The physical address of the LCPA.
242 * @lcpa_size: The size of the LCPA area.
243 */
244struct d40_base {
245 spinlock_t interrupt_lock;
246 spinlock_t execmd_lock;
247 struct device *dev;
248 void __iomem *virtbase;
249 struct clk *clk;
250 phys_addr_t phy_start;
251 resource_size_t phy_size;
252 int irq;
253 int num_phy_chans;
254 int num_log_chans;
255 struct dma_device dma_both;
256 struct dma_device dma_slave;
257 struct dma_device dma_memcpy;
258 struct d40_chan *phy_chans;
259 struct d40_chan *log_chans;
260 struct d40_chan **lookup_log_chans;
261 struct d40_chan **lookup_phy_chans;
262 struct stedma40_platform_data *plat_data;
263 /* Physical half channels */
264 struct d40_phy_res *phy_res;
265 struct d40_lcla_pool lcla_pool;
266 void *lcpa_base;
267 dma_addr_t phy_lcpa;
268 resource_size_t lcpa_size;
269};
270
271/**
272 * struct d40_interrupt_lookup - lookup table for interrupt handler
273 *
274 * @src: Interrupt mask register.
275 * @clr: Interrupt clear register.
276 * @is_error: true if this is an error interrupt.
277 * @offset: start delta in the lookup_log_chans in d40_base. If equals to
278 * D40_PHY_CHAN, the lookup_phy_chans shall be used instead.
279 */
280struct d40_interrupt_lookup {
281 u32 src;
282 u32 clr;
283 bool is_error;
284 int offset;
285};
286
287/**
288 * struct d40_reg_val - simple lookup struct
289 *
290 * @reg: The register.
291 * @val: The value that belongs to the register in reg.
292 */
293struct d40_reg_val {
294 unsigned int reg;
295 unsigned int val;
296};
297
298static int d40_pool_lli_alloc(struct d40_desc *d40d,
299 int lli_len, bool is_log)
300{
301 u32 align;
302 void *base;
303
304 if (is_log)
305 align = sizeof(struct d40_log_lli);
306 else
307 align = sizeof(struct d40_phy_lli);
308
309 if (lli_len == 1) {
310 base = d40d->lli_pool.pre_alloc_lli;
311 d40d->lli_pool.size = sizeof(d40d->lli_pool.pre_alloc_lli);
312 d40d->lli_pool.base = NULL;
313 } else {
314 d40d->lli_pool.size = ALIGN(lli_len * 2 * align, align);
315
316 base = kmalloc(d40d->lli_pool.size + align, GFP_NOWAIT);
317 d40d->lli_pool.base = base;
318
319 if (d40d->lli_pool.base == NULL)
320 return -ENOMEM;
321 }
322
323 if (is_log) {
324 d40d->lli_log.src = PTR_ALIGN((struct d40_log_lli *) base,
325 align);
326 d40d->lli_log.dst = PTR_ALIGN(d40d->lli_log.src + lli_len,
327 align);
328 } else {
329 d40d->lli_phy.src = PTR_ALIGN((struct d40_phy_lli *)base,
330 align);
331 d40d->lli_phy.dst = PTR_ALIGN(d40d->lli_phy.src + lli_len,
332 align);
333
334 d40d->lli_phy.src_addr = virt_to_phys(d40d->lli_phy.src);
335 d40d->lli_phy.dst_addr = virt_to_phys(d40d->lli_phy.dst);
336 }
337
338 return 0;
339}
340
341static void d40_pool_lli_free(struct d40_desc *d40d)
342{
343 kfree(d40d->lli_pool.base);
344 d40d->lli_pool.base = NULL;
345 d40d->lli_pool.size = 0;
346 d40d->lli_log.src = NULL;
347 d40d->lli_log.dst = NULL;
348 d40d->lli_phy.src = NULL;
349 d40d->lli_phy.dst = NULL;
350 d40d->lli_phy.src_addr = 0;
351 d40d->lli_phy.dst_addr = 0;
352}
353
354static dma_cookie_t d40_assign_cookie(struct d40_chan *d40c,
355 struct d40_desc *desc)
356{
357 dma_cookie_t cookie = d40c->chan.cookie;
358
359 if (++cookie < 0)
360 cookie = 1;
361
362 d40c->chan.cookie = cookie;
363 desc->txd.cookie = cookie;
364
365 return cookie;
366}
367
368static void d40_desc_reset(struct d40_desc *d40d)
369{
370 d40d->lli_tcount = 0;
371}
372
373static void d40_desc_remove(struct d40_desc *d40d)
374{
375 list_del(&d40d->node);
376}
377
378static struct d40_desc *d40_desc_get(struct d40_chan *d40c)
379{
380 struct d40_desc *desc;
381 struct d40_desc *d;
382 struct d40_desc *_d;
383
384 if (!list_empty(&d40c->client)) {
385 list_for_each_entry_safe(d, _d, &d40c->client, node)
386 if (async_tx_test_ack(&d->txd)) {
387 d40_pool_lli_free(d);
388 d40_desc_remove(d);
389 desc = d;
390 goto out;
391 }
392 }
393
394 if (list_empty(&d40c->free)) {
395 /* Alloc new desc because we're out of used ones */
396 desc = kzalloc(sizeof(struct d40_desc), GFP_NOWAIT);
397 if (desc == NULL)
398 goto out;
399 INIT_LIST_HEAD(&desc->node);
400 } else {
401 /* Reuse an old desc. */
402 desc = list_first_entry(&d40c->free,
403 struct d40_desc,
404 node);
405 list_del(&desc->node);
406 d40c->free_len--;
407 }
408out:
409 return desc;
410}
411
412static void d40_desc_free(struct d40_chan *d40c, struct d40_desc *d40d)
413{
414 if (d40c->free_len < D40_DESC_CACHE_SIZE) {
415 list_add_tail(&d40d->node, &d40c->free);
416 d40c->free_len++;
417 } else
418 kfree(d40d);
419}
420
421static void d40_desc_submit(struct d40_chan *d40c, struct d40_desc *desc)
422{
423 list_add_tail(&desc->node, &d40c->active);
424}
425
426static struct d40_desc *d40_first_active_get(struct d40_chan *d40c)
427{
428 struct d40_desc *d;
429
430 if (list_empty(&d40c->active))
431 return NULL;
432
433 d = list_first_entry(&d40c->active,
434 struct d40_desc,
435 node);
436 return d;
437}
438
439static void d40_desc_queue(struct d40_chan *d40c, struct d40_desc *desc)
440{
441 list_add_tail(&desc->node, &d40c->queue);
442}
443
444static struct d40_desc *d40_first_queued(struct d40_chan *d40c)
445{
446 struct d40_desc *d;
447
448 if (list_empty(&d40c->queue))
449 return NULL;
450
451 d = list_first_entry(&d40c->queue,
452 struct d40_desc,
453 node);
454 return d;
455}
456
457/* Support functions for logical channels */
458
459static int d40_lcla_id_get(struct d40_chan *d40c,
460 struct d40_lcla_pool *pool)
461{
462 int src_id = 0;
463 int dst_id = 0;
464 struct d40_log_lli *lcla_lidx_base =
465 pool->base + d40c->phy_chan->num * 1024;
466 int i;
467 int lli_per_log = d40c->base->plat_data->llis_per_log;
468
469 if (d40c->lcla.src_id >= 0 && d40c->lcla.dst_id >= 0)
470 return 0;
471
472 if (pool->num_blocks > 32)
473 return -EINVAL;
474
475 spin_lock(&pool->lock);
476
477 for (i = 0; i < pool->num_blocks; i++) {
478 if (!(pool->alloc_map[d40c->phy_chan->num] & (0x1 << i))) {
479 pool->alloc_map[d40c->phy_chan->num] |= (0x1 << i);
480 break;
481 }
482 }
483 src_id = i;
484 if (src_id >= pool->num_blocks)
485 goto err;
486
487 for (; i < pool->num_blocks; i++) {
488 if (!(pool->alloc_map[d40c->phy_chan->num] & (0x1 << i))) {
489 pool->alloc_map[d40c->phy_chan->num] |= (0x1 << i);
490 break;
491 }
492 }
493
494 dst_id = i;
495 if (dst_id == src_id)
496 goto err;
497
498 d40c->lcla.src_id = src_id;
499 d40c->lcla.dst_id = dst_id;
500 d40c->lcla.dst = lcla_lidx_base + dst_id * lli_per_log + 1;
501 d40c->lcla.src = lcla_lidx_base + src_id * lli_per_log + 1;
502
503
504 spin_unlock(&pool->lock);
505 return 0;
506err:
507 spin_unlock(&pool->lock);
508 return -EINVAL;
509}
510
511static void d40_lcla_id_put(struct d40_chan *d40c,
512 struct d40_lcla_pool *pool,
513 int id)
514{
515 if (id < 0)
516 return;
517
518 d40c->lcla.src_id = -1;
519 d40c->lcla.dst_id = -1;
520
521 spin_lock(&pool->lock);
522 pool->alloc_map[d40c->phy_chan->num] &= (~(0x1 << id));
523 spin_unlock(&pool->lock);
524}
525
526static int d40_channel_execute_command(struct d40_chan *d40c,
527 enum d40_command command)
528{
529 int status, i;
530 void __iomem *active_reg;
531 int ret = 0;
532 unsigned long flags;
533
534 spin_lock_irqsave(&d40c->base->execmd_lock, flags);
535
536 if (d40c->phy_chan->num % 2 == 0)
537 active_reg = d40c->base->virtbase + D40_DREG_ACTIVE;
538 else
539 active_reg = d40c->base->virtbase + D40_DREG_ACTIVO;
540
541 if (command == D40_DMA_SUSPEND_REQ) {
542 status = (readl(active_reg) &
543 D40_CHAN_POS_MASK(d40c->phy_chan->num)) >>
544 D40_CHAN_POS(d40c->phy_chan->num);
545
546 if (status == D40_DMA_SUSPENDED || status == D40_DMA_STOP)
547 goto done;
548 }
549
550 writel(command << D40_CHAN_POS(d40c->phy_chan->num), active_reg);
551
552 if (command == D40_DMA_SUSPEND_REQ) {
553
554 for (i = 0 ; i < D40_SUSPEND_MAX_IT; i++) {
555 status = (readl(active_reg) &
556 D40_CHAN_POS_MASK(d40c->phy_chan->num)) >>
557 D40_CHAN_POS(d40c->phy_chan->num);
558
559 cpu_relax();
560 /*
561 * Reduce the number of bus accesses while
562 * waiting for the DMA to suspend.
563 */
564 udelay(3);
565
566 if (status == D40_DMA_STOP ||
567 status == D40_DMA_SUSPENDED)
568 break;
569 }
570
571 if (i == D40_SUSPEND_MAX_IT) {
572 dev_err(&d40c->chan.dev->device,
573 "[%s]: unable to suspend the chl %d (log: %d) status %x\n",
574 __func__, d40c->phy_chan->num, d40c->log_num,
575 status);
576 dump_stack();
577 ret = -EBUSY;
578 }
579
580 }
581done:
582 spin_unlock_irqrestore(&d40c->base->execmd_lock, flags);
583 return ret;
584}
585
586static void d40_term_all(struct d40_chan *d40c)
587{
588 struct d40_desc *d40d;
589 struct d40_desc *d;
590 struct d40_desc *_d;
591
592 /* Release active descriptors */
593 while ((d40d = d40_first_active_get(d40c))) {
594 d40_desc_remove(d40d);
595
596 /* Return desc to free-list */
597 d40_desc_free(d40c, d40d);
598 }
599
600 /* Release queued descriptors waiting for transfer */
601 while ((d40d = d40_first_queued(d40c))) {
602 d40_desc_remove(d40d);
603
604 /* Return desc to free-list */
605 d40_desc_free(d40c, d40d);
606 }
607
608 /* Release client owned descriptors */
609 if (!list_empty(&d40c->client))
610 list_for_each_entry_safe(d, _d, &d40c->client, node) {
611 d40_pool_lli_free(d);
612 d40_desc_remove(d);
613 /* Return desc to free-list */
614 d40_desc_free(d40c, d40d);
615 }
616
617 d40_lcla_id_put(d40c, &d40c->base->lcla_pool,
618 d40c->lcla.src_id);
619 d40_lcla_id_put(d40c, &d40c->base->lcla_pool,
620 d40c->lcla.dst_id);
621
622 d40c->pending_tx = 0;
623 d40c->busy = false;
624}
625
626static void d40_config_set_event(struct d40_chan *d40c, bool do_enable)
627{
628 u32 val;
629 unsigned long flags;
630
631 if (do_enable)
632 val = D40_ACTIVATE_EVENTLINE;
633 else
634 val = D40_DEACTIVATE_EVENTLINE;
635
636 spin_lock_irqsave(&d40c->phy_chan->lock, flags);
637
638 /* Enable event line connected to device (or memcpy) */
639 if ((d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) ||
640 (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_PERIPH)) {
641 u32 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.src_dev_type);
642
643 writel((val << D40_EVENTLINE_POS(event)) |
644 ~D40_EVENTLINE_MASK(event),
645 d40c->base->virtbase + D40_DREG_PCBASE +
646 d40c->phy_chan->num * D40_DREG_PCDELTA +
647 D40_CHAN_REG_SSLNK);
648 }
649 if (d40c->dma_cfg.dir != STEDMA40_PERIPH_TO_MEM) {
650 u32 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dst_dev_type);
651
652 writel((val << D40_EVENTLINE_POS(event)) |
653 ~D40_EVENTLINE_MASK(event),
654 d40c->base->virtbase + D40_DREG_PCBASE +
655 d40c->phy_chan->num * D40_DREG_PCDELTA +
656 D40_CHAN_REG_SDLNK);
657 }
658
659 spin_unlock_irqrestore(&d40c->phy_chan->lock, flags);
660}
661
Jonas Aaberga5ebca42010-05-18 00:41:09 +0200662static u32 d40_chan_has_events(struct d40_chan *d40c)
Linus Walleij8d318a52010-03-30 15:33:42 +0200663{
664 u32 val = 0;
665
666 /* If SSLNK or SDLNK is zero all events are disabled */
667 if ((d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) ||
668 (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_PERIPH))
669 val = readl(d40c->base->virtbase + D40_DREG_PCBASE +
670 d40c->phy_chan->num * D40_DREG_PCDELTA +
671 D40_CHAN_REG_SSLNK);
672
673 if (d40c->dma_cfg.dir != STEDMA40_PERIPH_TO_MEM)
674 val = readl(d40c->base->virtbase + D40_DREG_PCBASE +
675 d40c->phy_chan->num * D40_DREG_PCDELTA +
676 D40_CHAN_REG_SDLNK);
Jonas Aaberga5ebca42010-05-18 00:41:09 +0200677 return val;
Linus Walleij8d318a52010-03-30 15:33:42 +0200678}
679
680static void d40_config_enable_lidx(struct d40_chan *d40c)
681{
682 /* Set LIDX for lcla */
683 writel((d40c->phy_chan->num << D40_SREG_ELEM_LOG_LIDX_POS) &
684 D40_SREG_ELEM_LOG_LIDX_MASK,
685 d40c->base->virtbase + D40_DREG_PCBASE +
686 d40c->phy_chan->num * D40_DREG_PCDELTA + D40_CHAN_REG_SDELT);
687
688 writel((d40c->phy_chan->num << D40_SREG_ELEM_LOG_LIDX_POS) &
689 D40_SREG_ELEM_LOG_LIDX_MASK,
690 d40c->base->virtbase + D40_DREG_PCBASE +
691 d40c->phy_chan->num * D40_DREG_PCDELTA + D40_CHAN_REG_SSELT);
692}
693
694static int d40_config_write(struct d40_chan *d40c)
695{
696 u32 addr_base;
697 u32 var;
698 int res;
699
700 res = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ);
701 if (res)
702 return res;
703
704 /* Odd addresses are even addresses + 4 */
705 addr_base = (d40c->phy_chan->num % 2) * 4;
706 /* Setup channel mode to logical or physical */
707 var = ((u32)(d40c->log_num != D40_PHY_CHAN) + 1) <<
708 D40_CHAN_POS(d40c->phy_chan->num);
709 writel(var, d40c->base->virtbase + D40_DREG_PRMSE + addr_base);
710
711 /* Setup operational mode option register */
712 var = ((d40c->dma_cfg.channel_type >> STEDMA40_INFO_CH_MODE_OPT_POS) &
713 0x3) << D40_CHAN_POS(d40c->phy_chan->num);
714
715 writel(var, d40c->base->virtbase + D40_DREG_PRMOE + addr_base);
716
717 if (d40c->log_num != D40_PHY_CHAN) {
718 /* Set default config for CFG reg */
719 writel(d40c->src_def_cfg,
720 d40c->base->virtbase + D40_DREG_PCBASE +
721 d40c->phy_chan->num * D40_DREG_PCDELTA +
722 D40_CHAN_REG_SSCFG);
723 writel(d40c->dst_def_cfg,
724 d40c->base->virtbase + D40_DREG_PCBASE +
725 d40c->phy_chan->num * D40_DREG_PCDELTA +
726 D40_CHAN_REG_SDCFG);
727
728 d40_config_enable_lidx(d40c);
729 }
730 return res;
731}
732
733static void d40_desc_load(struct d40_chan *d40c, struct d40_desc *d40d)
734{
735
736 if (d40d->lli_phy.dst && d40d->lli_phy.src) {
737 d40_phy_lli_write(d40c->base->virtbase,
738 d40c->phy_chan->num,
739 d40d->lli_phy.dst,
740 d40d->lli_phy.src);
741 d40d->lli_tcount = d40d->lli_len;
742 } else if (d40d->lli_log.dst && d40d->lli_log.src) {
743 u32 lli_len;
744 struct d40_log_lli *src = d40d->lli_log.src;
745 struct d40_log_lli *dst = d40d->lli_log.dst;
746
747 src += d40d->lli_tcount;
748 dst += d40d->lli_tcount;
749
750 if (d40d->lli_len <= d40c->base->plat_data->llis_per_log)
751 lli_len = d40d->lli_len;
752 else
753 lli_len = d40c->base->plat_data->llis_per_log;
754 d40d->lli_tcount += lli_len;
755 d40_log_lli_write(d40c->lcpa, d40c->lcla.src,
756 d40c->lcla.dst,
757 dst, src,
758 d40c->base->plat_data->llis_per_log);
759 }
760}
761
762static dma_cookie_t d40_tx_submit(struct dma_async_tx_descriptor *tx)
763{
764 struct d40_chan *d40c = container_of(tx->chan,
765 struct d40_chan,
766 chan);
767 struct d40_desc *d40d = container_of(tx, struct d40_desc, txd);
768 unsigned long flags;
769
770 spin_lock_irqsave(&d40c->lock, flags);
771
772 tx->cookie = d40_assign_cookie(d40c, d40d);
773
774 d40_desc_queue(d40c, d40d);
775
776 spin_unlock_irqrestore(&d40c->lock, flags);
777
778 return tx->cookie;
779}
780
781static int d40_start(struct d40_chan *d40c)
782{
783 int err;
784
785 if (d40c->log_num != D40_PHY_CHAN) {
786 err = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ);
787 if (err)
788 return err;
789 d40_config_set_event(d40c, true);
790 }
791
792 err = d40_channel_execute_command(d40c, D40_DMA_RUN);
793
794 return err;
795}
796
797static struct d40_desc *d40_queue_start(struct d40_chan *d40c)
798{
799 struct d40_desc *d40d;
800 int err;
801
802 /* Start queued jobs, if any */
803 d40d = d40_first_queued(d40c);
804
805 if (d40d != NULL) {
806 d40c->busy = true;
807
808 /* Remove from queue */
809 d40_desc_remove(d40d);
810
811 /* Add to active queue */
812 d40_desc_submit(d40c, d40d);
813
814 /* Initiate DMA job */
815 d40_desc_load(d40c, d40d);
816
817 /* Start dma job */
818 err = d40_start(d40c);
819
820 if (err)
821 return NULL;
822 }
823
824 return d40d;
825}
826
827/* called from interrupt context */
828static void dma_tc_handle(struct d40_chan *d40c)
829{
830 struct d40_desc *d40d;
831
832 if (!d40c->phy_chan)
833 return;
834
835 /* Get first active entry from list */
836 d40d = d40_first_active_get(d40c);
837
838 if (d40d == NULL)
839 return;
840
841 if (d40d->lli_tcount < d40d->lli_len) {
842
843 d40_desc_load(d40c, d40d);
844 /* Start dma job */
845 (void) d40_start(d40c);
846 return;
847 }
848
849 if (d40_queue_start(d40c) == NULL)
850 d40c->busy = false;
851
852 d40c->pending_tx++;
853 tasklet_schedule(&d40c->tasklet);
854
855}
856
857static void dma_tasklet(unsigned long data)
858{
859 struct d40_chan *d40c = (struct d40_chan *) data;
860 struct d40_desc *d40d_fin;
861 unsigned long flags;
862 dma_async_tx_callback callback;
863 void *callback_param;
864
865 spin_lock_irqsave(&d40c->lock, flags);
866
867 /* Get first active entry from list */
868 d40d_fin = d40_first_active_get(d40c);
869
870 if (d40d_fin == NULL)
871 goto err;
872
873 d40c->completed = d40d_fin->txd.cookie;
874
875 /*
876 * If terminating a channel pending_tx is set to zero.
877 * This prevents any finished active jobs to return to the client.
878 */
879 if (d40c->pending_tx == 0) {
880 spin_unlock_irqrestore(&d40c->lock, flags);
881 return;
882 }
883
884 /* Callback to client */
885 callback = d40d_fin->txd.callback;
886 callback_param = d40d_fin->txd.callback_param;
887
888 if (async_tx_test_ack(&d40d_fin->txd)) {
889 d40_pool_lli_free(d40d_fin);
890 d40_desc_remove(d40d_fin);
891 /* Return desc to free-list */
892 d40_desc_free(d40c, d40d_fin);
893 } else {
894 d40_desc_reset(d40d_fin);
895 if (!d40d_fin->is_in_client_list) {
896 d40_desc_remove(d40d_fin);
897 list_add_tail(&d40d_fin->node, &d40c->client);
898 d40d_fin->is_in_client_list = true;
899 }
900 }
901
902 d40c->pending_tx--;
903
904 if (d40c->pending_tx)
905 tasklet_schedule(&d40c->tasklet);
906
907 spin_unlock_irqrestore(&d40c->lock, flags);
908
909 if (callback)
910 callback(callback_param);
911
912 return;
913
914 err:
915 /* Rescue manouver if receiving double interrupts */
916 if (d40c->pending_tx > 0)
917 d40c->pending_tx--;
918 spin_unlock_irqrestore(&d40c->lock, flags);
919}
920
921static irqreturn_t d40_handle_interrupt(int irq, void *data)
922{
923 static const struct d40_interrupt_lookup il[] = {
924 {D40_DREG_LCTIS0, D40_DREG_LCICR0, false, 0},
925 {D40_DREG_LCTIS1, D40_DREG_LCICR1, false, 32},
926 {D40_DREG_LCTIS2, D40_DREG_LCICR2, false, 64},
927 {D40_DREG_LCTIS3, D40_DREG_LCICR3, false, 96},
928 {D40_DREG_LCEIS0, D40_DREG_LCICR0, true, 0},
929 {D40_DREG_LCEIS1, D40_DREG_LCICR1, true, 32},
930 {D40_DREG_LCEIS2, D40_DREG_LCICR2, true, 64},
931 {D40_DREG_LCEIS3, D40_DREG_LCICR3, true, 96},
932 {D40_DREG_PCTIS, D40_DREG_PCICR, false, D40_PHY_CHAN},
933 {D40_DREG_PCEIS, D40_DREG_PCICR, true, D40_PHY_CHAN},
934 };
935
936 int i;
937 u32 regs[ARRAY_SIZE(il)];
938 u32 tmp;
939 u32 idx;
940 u32 row;
941 long chan = -1;
942 struct d40_chan *d40c;
943 unsigned long flags;
944 struct d40_base *base = data;
945
946 spin_lock_irqsave(&base->interrupt_lock, flags);
947
948 /* Read interrupt status of both logical and physical channels */
949 for (i = 0; i < ARRAY_SIZE(il); i++)
950 regs[i] = readl(base->virtbase + il[i].src);
951
952 for (;;) {
953
954 chan = find_next_bit((unsigned long *)regs,
955 BITS_PER_LONG * ARRAY_SIZE(il), chan + 1);
956
957 /* No more set bits found? */
958 if (chan == BITS_PER_LONG * ARRAY_SIZE(il))
959 break;
960
961 row = chan / BITS_PER_LONG;
962 idx = chan & (BITS_PER_LONG - 1);
963
964 /* ACK interrupt */
965 tmp = readl(base->virtbase + il[row].clr);
966 tmp |= 1 << idx;
967 writel(tmp, base->virtbase + il[row].clr);
968
969 if (il[row].offset == D40_PHY_CHAN)
970 d40c = base->lookup_phy_chans[idx];
971 else
972 d40c = base->lookup_log_chans[il[row].offset + idx];
973 spin_lock(&d40c->lock);
974
975 if (!il[row].is_error)
976 dma_tc_handle(d40c);
977 else
978 dev_err(base->dev, "[%s] IRQ chan: %ld offset %d idx %d\n",
979 __func__, chan, il[row].offset, idx);
980
981 spin_unlock(&d40c->lock);
982 }
983
984 spin_unlock_irqrestore(&base->interrupt_lock, flags);
985
986 return IRQ_HANDLED;
987}
988
989
990static int d40_validate_conf(struct d40_chan *d40c,
991 struct stedma40_chan_cfg *conf)
992{
993 int res = 0;
994 u32 dst_event_group = D40_TYPE_TO_GROUP(conf->dst_dev_type);
995 u32 src_event_group = D40_TYPE_TO_GROUP(conf->src_dev_type);
996 bool is_log = (conf->channel_type & STEDMA40_CHANNEL_IN_OPER_MODE)
997 == STEDMA40_CHANNEL_IN_LOG_MODE;
998
999 if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_PERIPH &&
1000 dst_event_group == STEDMA40_DEV_DST_MEMORY) {
1001 dev_err(&d40c->chan.dev->device, "[%s] Invalid dst\n",
1002 __func__);
1003 res = -EINVAL;
1004 }
1005
1006 if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM &&
1007 src_event_group == STEDMA40_DEV_SRC_MEMORY) {
1008 dev_err(&d40c->chan.dev->device, "[%s] Invalid src\n",
1009 __func__);
1010 res = -EINVAL;
1011 }
1012
1013 if (src_event_group == STEDMA40_DEV_SRC_MEMORY &&
1014 dst_event_group == STEDMA40_DEV_DST_MEMORY && is_log) {
1015 dev_err(&d40c->chan.dev->device,
1016 "[%s] No event line\n", __func__);
1017 res = -EINVAL;
1018 }
1019
1020 if (conf->dir == STEDMA40_PERIPH_TO_PERIPH &&
1021 (src_event_group != dst_event_group)) {
1022 dev_err(&d40c->chan.dev->device,
1023 "[%s] Invalid event group\n", __func__);
1024 res = -EINVAL;
1025 }
1026
1027 if (conf->dir == STEDMA40_PERIPH_TO_PERIPH) {
1028 /*
1029 * DMAC HW supports it. Will be added to this driver,
1030 * in case any dma client requires it.
1031 */
1032 dev_err(&d40c->chan.dev->device,
1033 "[%s] periph to periph not supported\n",
1034 __func__);
1035 res = -EINVAL;
1036 }
1037
1038 return res;
1039}
1040
1041static bool d40_alloc_mask_set(struct d40_phy_res *phy, bool is_src,
1042 int log_event_line)
1043{
1044 unsigned long flags;
1045 spin_lock_irqsave(&phy->lock, flags);
1046 if (!log_event_line) {
1047 /* Physical interrupts are masked per physical full channel */
1048 if (phy->allocated_src == D40_ALLOC_FREE &&
1049 phy->allocated_dst == D40_ALLOC_FREE) {
1050 phy->allocated_dst = D40_ALLOC_PHY;
1051 phy->allocated_src = D40_ALLOC_PHY;
1052 goto found;
1053 } else
1054 goto not_found;
1055 }
1056
1057 /* Logical channel */
1058 if (is_src) {
1059 if (phy->allocated_src == D40_ALLOC_PHY)
1060 goto not_found;
1061
1062 if (phy->allocated_src == D40_ALLOC_FREE)
1063 phy->allocated_src = D40_ALLOC_LOG_FREE;
1064
1065 if (!(phy->allocated_src & (1 << log_event_line))) {
1066 phy->allocated_src |= 1 << log_event_line;
1067 goto found;
1068 } else
1069 goto not_found;
1070 } else {
1071 if (phy->allocated_dst == D40_ALLOC_PHY)
1072 goto not_found;
1073
1074 if (phy->allocated_dst == D40_ALLOC_FREE)
1075 phy->allocated_dst = D40_ALLOC_LOG_FREE;
1076
1077 if (!(phy->allocated_dst & (1 << log_event_line))) {
1078 phy->allocated_dst |= 1 << log_event_line;
1079 goto found;
1080 } else
1081 goto not_found;
1082 }
1083
1084not_found:
1085 spin_unlock_irqrestore(&phy->lock, flags);
1086 return false;
1087found:
1088 spin_unlock_irqrestore(&phy->lock, flags);
1089 return true;
1090}
1091
1092static bool d40_alloc_mask_free(struct d40_phy_res *phy, bool is_src,
1093 int log_event_line)
1094{
1095 unsigned long flags;
1096 bool is_free = false;
1097
1098 spin_lock_irqsave(&phy->lock, flags);
1099 if (!log_event_line) {
1100 /* Physical interrupts are masked per physical full channel */
1101 phy->allocated_dst = D40_ALLOC_FREE;
1102 phy->allocated_src = D40_ALLOC_FREE;
1103 is_free = true;
1104 goto out;
1105 }
1106
1107 /* Logical channel */
1108 if (is_src) {
1109 phy->allocated_src &= ~(1 << log_event_line);
1110 if (phy->allocated_src == D40_ALLOC_LOG_FREE)
1111 phy->allocated_src = D40_ALLOC_FREE;
1112 } else {
1113 phy->allocated_dst &= ~(1 << log_event_line);
1114 if (phy->allocated_dst == D40_ALLOC_LOG_FREE)
1115 phy->allocated_dst = D40_ALLOC_FREE;
1116 }
1117
1118 is_free = ((phy->allocated_src | phy->allocated_dst) ==
1119 D40_ALLOC_FREE);
1120
1121out:
1122 spin_unlock_irqrestore(&phy->lock, flags);
1123
1124 return is_free;
1125}
1126
1127static int d40_allocate_channel(struct d40_chan *d40c)
1128{
1129 int dev_type;
1130 int event_group;
1131 int event_line;
1132 struct d40_phy_res *phys;
1133 int i;
1134 int j;
1135 int log_num;
1136 bool is_src;
1137 bool is_log = (d40c->dma_cfg.channel_type & STEDMA40_CHANNEL_IN_OPER_MODE)
1138 == STEDMA40_CHANNEL_IN_LOG_MODE;
1139
1140
1141 phys = d40c->base->phy_res;
1142
1143 if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) {
1144 dev_type = d40c->dma_cfg.src_dev_type;
1145 log_num = 2 * dev_type;
1146 is_src = true;
1147 } else if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_PERIPH ||
1148 d40c->dma_cfg.dir == STEDMA40_MEM_TO_MEM) {
1149 /* dst event lines are used for logical memcpy */
1150 dev_type = d40c->dma_cfg.dst_dev_type;
1151 log_num = 2 * dev_type + 1;
1152 is_src = false;
1153 } else
1154 return -EINVAL;
1155
1156 event_group = D40_TYPE_TO_GROUP(dev_type);
1157 event_line = D40_TYPE_TO_EVENT(dev_type);
1158
1159 if (!is_log) {
1160 if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_MEM) {
1161 /* Find physical half channel */
1162 for (i = 0; i < d40c->base->num_phy_chans; i++) {
1163
1164 if (d40_alloc_mask_set(&phys[i], is_src, 0))
1165 goto found_phy;
1166 }
1167 } else
1168 for (j = 0; j < d40c->base->num_phy_chans; j += 8) {
1169 int phy_num = j + event_group * 2;
1170 for (i = phy_num; i < phy_num + 2; i++) {
1171 if (d40_alloc_mask_set(&phys[i],
1172 is_src, 0))
1173 goto found_phy;
1174 }
1175 }
1176 return -EINVAL;
1177found_phy:
1178 d40c->phy_chan = &phys[i];
1179 d40c->log_num = D40_PHY_CHAN;
1180 goto out;
1181 }
1182 if (dev_type == -1)
1183 return -EINVAL;
1184
1185 /* Find logical channel */
1186 for (j = 0; j < d40c->base->num_phy_chans; j += 8) {
1187 int phy_num = j + event_group * 2;
1188 /*
1189 * Spread logical channels across all available physical rather
1190 * than pack every logical channel at the first available phy
1191 * channels.
1192 */
1193 if (is_src) {
1194 for (i = phy_num; i < phy_num + 2; i++) {
1195 if (d40_alloc_mask_set(&phys[i], is_src,
1196 event_line))
1197 goto found_log;
1198 }
1199 } else {
1200 for (i = phy_num + 1; i >= phy_num; i--) {
1201 if (d40_alloc_mask_set(&phys[i], is_src,
1202 event_line))
1203 goto found_log;
1204 }
1205 }
1206 }
1207 return -EINVAL;
1208
1209found_log:
1210 d40c->phy_chan = &phys[i];
1211 d40c->log_num = log_num;
1212out:
1213
1214 if (is_log)
1215 d40c->base->lookup_log_chans[d40c->log_num] = d40c;
1216 else
1217 d40c->base->lookup_phy_chans[d40c->phy_chan->num] = d40c;
1218
1219 return 0;
1220
1221}
1222
1223static int d40_config_chan(struct d40_chan *d40c,
1224 struct stedma40_chan_cfg *info)
1225{
1226
1227 /* Fill in basic CFG register values */
1228 d40_phy_cfg(&d40c->dma_cfg, &d40c->src_def_cfg,
1229 &d40c->dst_def_cfg, d40c->log_num != D40_PHY_CHAN);
1230
1231 if (d40c->log_num != D40_PHY_CHAN) {
1232 d40_log_cfg(&d40c->dma_cfg,
1233 &d40c->log_def.lcsp1, &d40c->log_def.lcsp3);
1234
1235 if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM)
1236 d40c->lcpa = d40c->base->lcpa_base +
1237 d40c->dma_cfg.src_dev_type * 32;
1238 else
1239 d40c->lcpa = d40c->base->lcpa_base +
1240 d40c->dma_cfg.dst_dev_type * 32 + 16;
1241 }
1242
1243 /* Write channel configuration to the DMA */
1244 return d40_config_write(d40c);
1245}
1246
1247static int d40_config_memcpy(struct d40_chan *d40c)
1248{
1249 dma_cap_mask_t cap = d40c->chan.device->cap_mask;
1250
1251 if (dma_has_cap(DMA_MEMCPY, cap) && !dma_has_cap(DMA_SLAVE, cap)) {
1252 d40c->dma_cfg = *d40c->base->plat_data->memcpy_conf_log;
1253 d40c->dma_cfg.src_dev_type = STEDMA40_DEV_SRC_MEMORY;
1254 d40c->dma_cfg.dst_dev_type = d40c->base->plat_data->
1255 memcpy[d40c->chan.chan_id];
1256
1257 } else if (dma_has_cap(DMA_MEMCPY, cap) &&
1258 dma_has_cap(DMA_SLAVE, cap)) {
1259 d40c->dma_cfg = *d40c->base->plat_data->memcpy_conf_phy;
1260 } else {
1261 dev_err(&d40c->chan.dev->device, "[%s] No memcpy\n",
1262 __func__);
1263 return -EINVAL;
1264 }
1265
1266 return 0;
1267}
1268
1269
1270static int d40_free_dma(struct d40_chan *d40c)
1271{
1272
1273 int res = 0;
1274 u32 event, dir;
1275 struct d40_phy_res *phy = d40c->phy_chan;
1276 bool is_src;
1277
1278 /* Terminate all queued and active transfers */
1279 d40_term_all(d40c);
1280
1281 if (phy == NULL) {
1282 dev_err(&d40c->chan.dev->device, "[%s] phy == null\n",
1283 __func__);
1284 return -EINVAL;
1285 }
1286
1287 if (phy->allocated_src == D40_ALLOC_FREE &&
1288 phy->allocated_dst == D40_ALLOC_FREE) {
1289 dev_err(&d40c->chan.dev->device, "[%s] channel already free\n",
1290 __func__);
1291 return -EINVAL;
1292 }
1293
1294
1295 res = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ);
1296 if (res) {
1297 dev_err(&d40c->chan.dev->device, "[%s] suspend\n",
1298 __func__);
1299 return res;
1300 }
1301
1302 if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_PERIPH ||
1303 d40c->dma_cfg.dir == STEDMA40_MEM_TO_MEM) {
1304 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dst_dev_type);
1305 dir = D40_CHAN_REG_SDLNK;
1306 is_src = false;
1307 } else if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) {
1308 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.src_dev_type);
1309 dir = D40_CHAN_REG_SSLNK;
1310 is_src = true;
1311 } else {
1312 dev_err(&d40c->chan.dev->device,
1313 "[%s] Unknown direction\n", __func__);
1314 return -EINVAL;
1315 }
1316
1317 if (d40c->log_num != D40_PHY_CHAN) {
1318 /*
1319 * Release logical channel, deactivate the event line during
1320 * the time physical res is suspended.
1321 */
1322 writel((D40_DEACTIVATE_EVENTLINE << D40_EVENTLINE_POS(event)) &
1323 D40_EVENTLINE_MASK(event),
1324 d40c->base->virtbase + D40_DREG_PCBASE +
1325 phy->num * D40_DREG_PCDELTA + dir);
1326
1327 d40c->base->lookup_log_chans[d40c->log_num] = NULL;
1328
1329 /*
1330 * Check if there are more logical allocation
1331 * on this phy channel.
1332 */
1333 if (!d40_alloc_mask_free(phy, is_src, event)) {
1334 /* Resume the other logical channels if any */
1335 if (d40_chan_has_events(d40c)) {
1336 res = d40_channel_execute_command(d40c,
1337 D40_DMA_RUN);
1338 if (res) {
1339 dev_err(&d40c->chan.dev->device,
1340 "[%s] Executing RUN command\n",
1341 __func__);
1342 return res;
1343 }
1344 }
1345 return 0;
1346 }
1347 } else
1348 d40_alloc_mask_free(phy, is_src, 0);
1349
1350 /* Release physical channel */
1351 res = d40_channel_execute_command(d40c, D40_DMA_STOP);
1352 if (res) {
1353 dev_err(&d40c->chan.dev->device,
1354 "[%s] Failed to stop channel\n", __func__);
1355 return res;
1356 }
1357 d40c->phy_chan = NULL;
1358 /* Invalidate channel type */
1359 d40c->dma_cfg.channel_type = 0;
1360 d40c->base->lookup_phy_chans[phy->num] = NULL;
1361
1362 return 0;
1363
1364
1365}
1366
1367static int d40_pause(struct dma_chan *chan)
1368{
1369 struct d40_chan *d40c =
1370 container_of(chan, struct d40_chan, chan);
1371 int res;
1372
1373 unsigned long flags;
1374
1375 spin_lock_irqsave(&d40c->lock, flags);
1376
1377 res = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ);
1378 if (res == 0) {
1379 if (d40c->log_num != D40_PHY_CHAN) {
1380 d40_config_set_event(d40c, false);
1381 /* Resume the other logical channels if any */
1382 if (d40_chan_has_events(d40c))
1383 res = d40_channel_execute_command(d40c,
1384 D40_DMA_RUN);
1385 }
1386 }
1387
1388 spin_unlock_irqrestore(&d40c->lock, flags);
1389 return res;
1390}
1391
Jonas Aaberga5ebca42010-05-18 00:41:09 +02001392static bool d40_is_paused(struct d40_chan *d40c)
1393{
1394 bool is_paused = false;
1395 unsigned long flags;
1396 void __iomem *active_reg;
1397 u32 status;
1398 u32 event;
1399 int res;
1400
1401 spin_lock_irqsave(&d40c->lock, flags);
1402
1403 if (d40c->log_num == D40_PHY_CHAN) {
1404 if (d40c->phy_chan->num % 2 == 0)
1405 active_reg = d40c->base->virtbase + D40_DREG_ACTIVE;
1406 else
1407 active_reg = d40c->base->virtbase + D40_DREG_ACTIVO;
1408
1409 status = (readl(active_reg) &
1410 D40_CHAN_POS_MASK(d40c->phy_chan->num)) >>
1411 D40_CHAN_POS(d40c->phy_chan->num);
1412 if (status == D40_DMA_SUSPENDED || status == D40_DMA_STOP)
1413 is_paused = true;
1414
1415 goto _exit;
1416 }
1417
1418 res = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ);
1419 if (res != 0)
1420 goto _exit;
1421
1422 if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_PERIPH ||
1423 d40c->dma_cfg.dir == STEDMA40_MEM_TO_MEM)
1424 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dst_dev_type);
1425 else if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM)
1426 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.src_dev_type);
1427 else {
1428 dev_err(&d40c->chan.dev->device,
1429 "[%s] Unknown direction\n", __func__);
1430 goto _exit;
1431 }
1432 status = d40_chan_has_events(d40c);
1433 status = (status & D40_EVENTLINE_MASK(event)) >>
1434 D40_EVENTLINE_POS(event);
1435
1436 if (status != D40_DMA_RUN)
1437 is_paused = true;
1438
1439 /* Resume the other logical channels if any */
1440 if (d40_chan_has_events(d40c))
1441 res = d40_channel_execute_command(d40c,
1442 D40_DMA_RUN);
1443
1444_exit:
1445 spin_unlock_irqrestore(&d40c->lock, flags);
1446 return is_paused;
1447
1448}
1449
1450
Linus Walleij8d318a52010-03-30 15:33:42 +02001451static bool d40_tx_is_linked(struct d40_chan *d40c)
1452{
1453 bool is_link;
1454
1455 if (d40c->log_num != D40_PHY_CHAN)
1456 is_link = readl(&d40c->lcpa->lcsp3) & D40_MEM_LCSP3_DLOS_MASK;
1457 else
1458 is_link = readl(d40c->base->virtbase + D40_DREG_PCBASE +
1459 d40c->phy_chan->num * D40_DREG_PCDELTA +
1460 D40_CHAN_REG_SDLNK) &
1461 D40_SREG_LNK_PHYS_LNK_MASK;
1462 return is_link;
1463}
1464
1465static u32 d40_residue(struct d40_chan *d40c)
1466{
1467 u32 num_elt;
1468
1469 if (d40c->log_num != D40_PHY_CHAN)
1470 num_elt = (readl(&d40c->lcpa->lcsp2) & D40_MEM_LCSP2_ECNT_MASK)
1471 >> D40_MEM_LCSP2_ECNT_POS;
1472 else
1473 num_elt = (readl(d40c->base->virtbase + D40_DREG_PCBASE +
1474 d40c->phy_chan->num * D40_DREG_PCDELTA +
1475 D40_CHAN_REG_SDELT) &
1476 D40_SREG_ELEM_PHY_ECNT_MASK) >> D40_SREG_ELEM_PHY_ECNT_POS;
1477 return num_elt * (1 << d40c->dma_cfg.dst_info.data_width);
1478}
1479
1480static int d40_resume(struct dma_chan *chan)
1481{
1482 struct d40_chan *d40c =
1483 container_of(chan, struct d40_chan, chan);
1484 int res = 0;
1485 unsigned long flags;
1486
1487 spin_lock_irqsave(&d40c->lock, flags);
1488
1489 if (d40c->log_num != D40_PHY_CHAN) {
1490 res = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ);
1491 if (res)
1492 goto out;
1493
1494 /* If bytes left to transfer or linked tx resume job */
1495 if (d40_residue(d40c) || d40_tx_is_linked(d40c)) {
1496 d40_config_set_event(d40c, true);
1497 res = d40_channel_execute_command(d40c, D40_DMA_RUN);
1498 }
1499 } else if (d40_residue(d40c) || d40_tx_is_linked(d40c))
1500 res = d40_channel_execute_command(d40c, D40_DMA_RUN);
1501
1502out:
1503 spin_unlock_irqrestore(&d40c->lock, flags);
1504 return res;
1505}
1506
1507static u32 stedma40_residue(struct dma_chan *chan)
1508{
1509 struct d40_chan *d40c =
1510 container_of(chan, struct d40_chan, chan);
1511 u32 bytes_left;
1512 unsigned long flags;
1513
1514 spin_lock_irqsave(&d40c->lock, flags);
1515 bytes_left = d40_residue(d40c);
1516 spin_unlock_irqrestore(&d40c->lock, flags);
1517
1518 return bytes_left;
1519}
1520
1521/* Public DMA functions in addition to the DMA engine framework */
1522
1523int stedma40_set_psize(struct dma_chan *chan,
1524 int src_psize,
1525 int dst_psize)
1526{
1527 struct d40_chan *d40c =
1528 container_of(chan, struct d40_chan, chan);
1529 unsigned long flags;
1530
1531 spin_lock_irqsave(&d40c->lock, flags);
1532
1533 if (d40c->log_num != D40_PHY_CHAN) {
1534 d40c->log_def.lcsp1 &= ~D40_MEM_LCSP1_SCFG_PSIZE_MASK;
1535 d40c->log_def.lcsp3 &= ~D40_MEM_LCSP1_SCFG_PSIZE_MASK;
1536 d40c->log_def.lcsp1 |= src_psize << D40_MEM_LCSP1_SCFG_PSIZE_POS;
1537 d40c->log_def.lcsp3 |= dst_psize << D40_MEM_LCSP1_SCFG_PSIZE_POS;
1538 goto out;
1539 }
1540
1541 if (src_psize == STEDMA40_PSIZE_PHY_1)
1542 d40c->src_def_cfg &= ~(1 << D40_SREG_CFG_PHY_PEN_POS);
1543 else {
1544 d40c->src_def_cfg |= 1 << D40_SREG_CFG_PHY_PEN_POS;
1545 d40c->src_def_cfg &= ~(STEDMA40_PSIZE_PHY_16 <<
1546 D40_SREG_CFG_PSIZE_POS);
1547 d40c->src_def_cfg |= src_psize << D40_SREG_CFG_PSIZE_POS;
1548 }
1549
1550 if (dst_psize == STEDMA40_PSIZE_PHY_1)
1551 d40c->dst_def_cfg &= ~(1 << D40_SREG_CFG_PHY_PEN_POS);
1552 else {
1553 d40c->dst_def_cfg |= 1 << D40_SREG_CFG_PHY_PEN_POS;
1554 d40c->dst_def_cfg &= ~(STEDMA40_PSIZE_PHY_16 <<
1555 D40_SREG_CFG_PSIZE_POS);
1556 d40c->dst_def_cfg |= dst_psize << D40_SREG_CFG_PSIZE_POS;
1557 }
1558out:
1559 spin_unlock_irqrestore(&d40c->lock, flags);
1560 return 0;
1561}
1562EXPORT_SYMBOL(stedma40_set_psize);
1563
1564struct dma_async_tx_descriptor *stedma40_memcpy_sg(struct dma_chan *chan,
1565 struct scatterlist *sgl_dst,
1566 struct scatterlist *sgl_src,
1567 unsigned int sgl_len,
1568 unsigned long flags)
1569{
1570 int res;
1571 struct d40_desc *d40d;
1572 struct d40_chan *d40c = container_of(chan, struct d40_chan,
1573 chan);
1574 unsigned long flg;
1575 int lli_max = d40c->base->plat_data->llis_per_log;
1576
1577
1578 spin_lock_irqsave(&d40c->lock, flg);
1579 d40d = d40_desc_get(d40c);
1580
1581 if (d40d == NULL)
1582 goto err;
1583
1584 memset(d40d, 0, sizeof(struct d40_desc));
1585 d40d->lli_len = sgl_len;
1586
1587 d40d->txd.flags = flags;
1588
1589 if (d40c->log_num != D40_PHY_CHAN) {
1590 if (sgl_len > 1)
1591 /*
1592 * Check if there is space available in lcla. If not,
1593 * split list into 1-length and run only in lcpa
1594 * space.
1595 */
1596 if (d40_lcla_id_get(d40c,
1597 &d40c->base->lcla_pool) != 0)
1598 lli_max = 1;
1599
1600 if (d40_pool_lli_alloc(d40d, sgl_len, true) < 0) {
1601 dev_err(&d40c->chan.dev->device,
1602 "[%s] Out of memory\n", __func__);
1603 goto err;
1604 }
1605
1606 (void) d40_log_sg_to_lli(d40c->lcla.src_id,
1607 sgl_src,
1608 sgl_len,
1609 d40d->lli_log.src,
1610 d40c->log_def.lcsp1,
1611 d40c->dma_cfg.src_info.data_width,
1612 flags & DMA_PREP_INTERRUPT, lli_max,
1613 d40c->base->plat_data->llis_per_log);
1614
1615 (void) d40_log_sg_to_lli(d40c->lcla.dst_id,
1616 sgl_dst,
1617 sgl_len,
1618 d40d->lli_log.dst,
1619 d40c->log_def.lcsp3,
1620 d40c->dma_cfg.dst_info.data_width,
1621 flags & DMA_PREP_INTERRUPT, lli_max,
1622 d40c->base->plat_data->llis_per_log);
1623
1624
1625 } else {
1626 if (d40_pool_lli_alloc(d40d, sgl_len, false) < 0) {
1627 dev_err(&d40c->chan.dev->device,
1628 "[%s] Out of memory\n", __func__);
1629 goto err;
1630 }
1631
1632 res = d40_phy_sg_to_lli(sgl_src,
1633 sgl_len,
1634 0,
1635 d40d->lli_phy.src,
1636 d40d->lli_phy.src_addr,
1637 d40c->src_def_cfg,
1638 d40c->dma_cfg.src_info.data_width,
1639 d40c->dma_cfg.src_info.psize,
1640 true);
1641
1642 if (res < 0)
1643 goto err;
1644
1645 res = d40_phy_sg_to_lli(sgl_dst,
1646 sgl_len,
1647 0,
1648 d40d->lli_phy.dst,
1649 d40d->lli_phy.dst_addr,
1650 d40c->dst_def_cfg,
1651 d40c->dma_cfg.dst_info.data_width,
1652 d40c->dma_cfg.dst_info.psize,
1653 true);
1654
1655 if (res < 0)
1656 goto err;
1657
1658 (void) dma_map_single(d40c->base->dev, d40d->lli_phy.src,
1659 d40d->lli_pool.size, DMA_TO_DEVICE);
1660 }
1661
1662 dma_async_tx_descriptor_init(&d40d->txd, chan);
1663
1664 d40d->txd.tx_submit = d40_tx_submit;
1665
1666 spin_unlock_irqrestore(&d40c->lock, flg);
1667
1668 return &d40d->txd;
1669err:
1670 spin_unlock_irqrestore(&d40c->lock, flg);
1671 return NULL;
1672}
1673EXPORT_SYMBOL(stedma40_memcpy_sg);
1674
1675bool stedma40_filter(struct dma_chan *chan, void *data)
1676{
1677 struct stedma40_chan_cfg *info = data;
1678 struct d40_chan *d40c =
1679 container_of(chan, struct d40_chan, chan);
1680 int err;
1681
1682 if (data) {
1683 err = d40_validate_conf(d40c, info);
1684 if (!err)
1685 d40c->dma_cfg = *info;
1686 } else
1687 err = d40_config_memcpy(d40c);
1688
1689 return err == 0;
1690}
1691EXPORT_SYMBOL(stedma40_filter);
1692
1693/* DMA ENGINE functions */
1694static int d40_alloc_chan_resources(struct dma_chan *chan)
1695{
1696 int err;
1697 unsigned long flags;
1698 struct d40_chan *d40c =
1699 container_of(chan, struct d40_chan, chan);
1700
1701 spin_lock_irqsave(&d40c->lock, flags);
1702
1703 d40c->completed = chan->cookie = 1;
1704
1705 /*
1706 * If no dma configuration is set (channel_type == 0)
1707 * use default configuration
1708 */
1709 if (d40c->dma_cfg.channel_type == 0) {
1710 err = d40_config_memcpy(d40c);
1711 if (err)
1712 goto err_alloc;
1713 }
1714
1715 err = d40_allocate_channel(d40c);
1716 if (err) {
1717 dev_err(&d40c->chan.dev->device,
1718 "[%s] Failed to allocate channel\n", __func__);
1719 goto err_alloc;
1720 }
1721
1722 err = d40_config_chan(d40c, &d40c->dma_cfg);
1723 if (err) {
1724 dev_err(&d40c->chan.dev->device,
1725 "[%s] Failed to configure channel\n",
1726 __func__);
1727 goto err_config;
1728 }
1729
1730 spin_unlock_irqrestore(&d40c->lock, flags);
1731 return 0;
1732
1733 err_config:
1734 (void) d40_free_dma(d40c);
1735 err_alloc:
1736 spin_unlock_irqrestore(&d40c->lock, flags);
1737 dev_err(&d40c->chan.dev->device,
1738 "[%s] Channel allocation failed\n", __func__);
1739 return -EINVAL;
1740}
1741
1742static void d40_free_chan_resources(struct dma_chan *chan)
1743{
1744 struct d40_chan *d40c =
1745 container_of(chan, struct d40_chan, chan);
1746 int err;
1747 unsigned long flags;
1748
1749 spin_lock_irqsave(&d40c->lock, flags);
1750
1751 err = d40_free_dma(d40c);
1752
1753 if (err)
1754 dev_err(&d40c->chan.dev->device,
1755 "[%s] Failed to free channel\n", __func__);
1756 spin_unlock_irqrestore(&d40c->lock, flags);
1757}
1758
1759static struct dma_async_tx_descriptor *d40_prep_memcpy(struct dma_chan *chan,
1760 dma_addr_t dst,
1761 dma_addr_t src,
1762 size_t size,
1763 unsigned long flags)
1764{
1765 struct d40_desc *d40d;
1766 struct d40_chan *d40c = container_of(chan, struct d40_chan,
1767 chan);
1768 unsigned long flg;
1769 int err = 0;
1770
1771 spin_lock_irqsave(&d40c->lock, flg);
1772 d40d = d40_desc_get(d40c);
1773
1774 if (d40d == NULL) {
1775 dev_err(&d40c->chan.dev->device,
1776 "[%s] Descriptor is NULL\n", __func__);
1777 goto err;
1778 }
1779
1780 memset(d40d, 0, sizeof(struct d40_desc));
1781
1782 d40d->txd.flags = flags;
1783
1784 dma_async_tx_descriptor_init(&d40d->txd, chan);
1785
1786 d40d->txd.tx_submit = d40_tx_submit;
1787
1788 if (d40c->log_num != D40_PHY_CHAN) {
1789
1790 if (d40_pool_lli_alloc(d40d, 1, true) < 0) {
1791 dev_err(&d40c->chan.dev->device,
1792 "[%s] Out of memory\n", __func__);
1793 goto err;
1794 }
1795 d40d->lli_len = 1;
1796
1797 d40_log_fill_lli(d40d->lli_log.src,
1798 src,
1799 size,
1800 0,
1801 d40c->log_def.lcsp1,
1802 d40c->dma_cfg.src_info.data_width,
1803 true, true);
1804
1805 d40_log_fill_lli(d40d->lli_log.dst,
1806 dst,
1807 size,
1808 0,
1809 d40c->log_def.lcsp3,
1810 d40c->dma_cfg.dst_info.data_width,
1811 true, true);
1812
1813 } else {
1814
1815 if (d40_pool_lli_alloc(d40d, 1, false) < 0) {
1816 dev_err(&d40c->chan.dev->device,
1817 "[%s] Out of memory\n", __func__);
1818 goto err;
1819 }
1820
1821 err = d40_phy_fill_lli(d40d->lli_phy.src,
1822 src,
1823 size,
1824 d40c->dma_cfg.src_info.psize,
1825 0,
1826 d40c->src_def_cfg,
1827 true,
1828 d40c->dma_cfg.src_info.data_width,
1829 false);
1830 if (err)
1831 goto err_fill_lli;
1832
1833 err = d40_phy_fill_lli(d40d->lli_phy.dst,
1834 dst,
1835 size,
1836 d40c->dma_cfg.dst_info.psize,
1837 0,
1838 d40c->dst_def_cfg,
1839 true,
1840 d40c->dma_cfg.dst_info.data_width,
1841 false);
1842
1843 if (err)
1844 goto err_fill_lli;
1845
1846 (void) dma_map_single(d40c->base->dev, d40d->lli_phy.src,
1847 d40d->lli_pool.size, DMA_TO_DEVICE);
1848 }
1849
1850 spin_unlock_irqrestore(&d40c->lock, flg);
1851 return &d40d->txd;
1852
1853err_fill_lli:
1854 dev_err(&d40c->chan.dev->device,
1855 "[%s] Failed filling in PHY LLI\n", __func__);
1856 d40_pool_lli_free(d40d);
1857err:
1858 spin_unlock_irqrestore(&d40c->lock, flg);
1859 return NULL;
1860}
1861
1862static int d40_prep_slave_sg_log(struct d40_desc *d40d,
1863 struct d40_chan *d40c,
1864 struct scatterlist *sgl,
1865 unsigned int sg_len,
1866 enum dma_data_direction direction,
1867 unsigned long flags)
1868{
1869 dma_addr_t dev_addr = 0;
1870 int total_size;
1871 int lli_max = d40c->base->plat_data->llis_per_log;
1872
1873 if (d40_pool_lli_alloc(d40d, sg_len, true) < 0) {
1874 dev_err(&d40c->chan.dev->device,
1875 "[%s] Out of memory\n", __func__);
1876 return -ENOMEM;
1877 }
1878
1879 d40d->lli_len = sg_len;
1880 d40d->lli_tcount = 0;
1881
1882 if (sg_len > 1)
1883 /*
1884 * Check if there is space available in lcla.
1885 * If not, split list into 1-length and run only
1886 * in lcpa space.
1887 */
1888 if (d40_lcla_id_get(d40c, &d40c->base->lcla_pool) != 0)
1889 lli_max = 1;
1890
1891 if (direction == DMA_FROM_DEVICE) {
1892 dev_addr = d40c->base->plat_data->dev_rx[d40c->dma_cfg.src_dev_type];
1893 total_size = d40_log_sg_to_dev(&d40c->lcla,
1894 sgl, sg_len,
1895 &d40d->lli_log,
1896 &d40c->log_def,
1897 d40c->dma_cfg.src_info.data_width,
1898 d40c->dma_cfg.dst_info.data_width,
1899 direction,
1900 flags & DMA_PREP_INTERRUPT,
1901 dev_addr, lli_max,
1902 d40c->base->plat_data->llis_per_log);
1903 } else if (direction == DMA_TO_DEVICE) {
1904 dev_addr = d40c->base->plat_data->dev_tx[d40c->dma_cfg.dst_dev_type];
1905 total_size = d40_log_sg_to_dev(&d40c->lcla,
1906 sgl, sg_len,
1907 &d40d->lli_log,
1908 &d40c->log_def,
1909 d40c->dma_cfg.src_info.data_width,
1910 d40c->dma_cfg.dst_info.data_width,
1911 direction,
1912 flags & DMA_PREP_INTERRUPT,
1913 dev_addr, lli_max,
1914 d40c->base->plat_data->llis_per_log);
1915 } else
1916 return -EINVAL;
1917 if (total_size < 0)
1918 return -EINVAL;
1919
1920 return 0;
1921}
1922
1923static int d40_prep_slave_sg_phy(struct d40_desc *d40d,
1924 struct d40_chan *d40c,
1925 struct scatterlist *sgl,
1926 unsigned int sgl_len,
1927 enum dma_data_direction direction,
1928 unsigned long flags)
1929{
1930 dma_addr_t src_dev_addr;
1931 dma_addr_t dst_dev_addr;
1932 int res;
1933
1934 if (d40_pool_lli_alloc(d40d, sgl_len, false) < 0) {
1935 dev_err(&d40c->chan.dev->device,
1936 "[%s] Out of memory\n", __func__);
1937 return -ENOMEM;
1938 }
1939
1940 d40d->lli_len = sgl_len;
1941 d40d->lli_tcount = 0;
1942
1943 if (direction == DMA_FROM_DEVICE) {
1944 dst_dev_addr = 0;
1945 src_dev_addr = d40c->base->plat_data->dev_rx[d40c->dma_cfg.src_dev_type];
1946 } else if (direction == DMA_TO_DEVICE) {
1947 dst_dev_addr = d40c->base->plat_data->dev_tx[d40c->dma_cfg.dst_dev_type];
1948 src_dev_addr = 0;
1949 } else
1950 return -EINVAL;
1951
1952 res = d40_phy_sg_to_lli(sgl,
1953 sgl_len,
1954 src_dev_addr,
1955 d40d->lli_phy.src,
1956 d40d->lli_phy.src_addr,
1957 d40c->src_def_cfg,
1958 d40c->dma_cfg.src_info.data_width,
1959 d40c->dma_cfg.src_info.psize,
1960 true);
1961 if (res < 0)
1962 return res;
1963
1964 res = d40_phy_sg_to_lli(sgl,
1965 sgl_len,
1966 dst_dev_addr,
1967 d40d->lli_phy.dst,
1968 d40d->lli_phy.dst_addr,
1969 d40c->dst_def_cfg,
1970 d40c->dma_cfg.dst_info.data_width,
1971 d40c->dma_cfg.dst_info.psize,
1972 true);
1973 if (res < 0)
1974 return res;
1975
1976 (void) dma_map_single(d40c->base->dev, d40d->lli_phy.src,
1977 d40d->lli_pool.size, DMA_TO_DEVICE);
1978 return 0;
1979}
1980
1981static struct dma_async_tx_descriptor *d40_prep_slave_sg(struct dma_chan *chan,
1982 struct scatterlist *sgl,
1983 unsigned int sg_len,
1984 enum dma_data_direction direction,
1985 unsigned long flags)
1986{
1987 struct d40_desc *d40d;
1988 struct d40_chan *d40c = container_of(chan, struct d40_chan,
1989 chan);
1990 unsigned long flg;
1991 int err;
1992
1993 if (d40c->dma_cfg.pre_transfer)
1994 d40c->dma_cfg.pre_transfer(chan,
1995 d40c->dma_cfg.pre_transfer_data,
1996 sg_dma_len(sgl));
1997
1998 spin_lock_irqsave(&d40c->lock, flg);
1999 d40d = d40_desc_get(d40c);
2000 spin_unlock_irqrestore(&d40c->lock, flg);
2001
2002 if (d40d == NULL)
2003 return NULL;
2004
2005 memset(d40d, 0, sizeof(struct d40_desc));
2006
2007 if (d40c->log_num != D40_PHY_CHAN)
2008 err = d40_prep_slave_sg_log(d40d, d40c, sgl, sg_len,
2009 direction, flags);
2010 else
2011 err = d40_prep_slave_sg_phy(d40d, d40c, sgl, sg_len,
2012 direction, flags);
2013 if (err) {
2014 dev_err(&d40c->chan.dev->device,
2015 "[%s] Failed to prepare %s slave sg job: %d\n",
2016 __func__,
2017 d40c->log_num != D40_PHY_CHAN ? "log" : "phy", err);
2018 return NULL;
2019 }
2020
2021 d40d->txd.flags = flags;
2022
2023 dma_async_tx_descriptor_init(&d40d->txd, chan);
2024
2025 d40d->txd.tx_submit = d40_tx_submit;
2026
2027 return &d40d->txd;
2028}
2029
2030static enum dma_status d40_tx_status(struct dma_chan *chan,
2031 dma_cookie_t cookie,
2032 struct dma_tx_state *txstate)
2033{
2034 struct d40_chan *d40c = container_of(chan, struct d40_chan, chan);
2035 dma_cookie_t last_used;
2036 dma_cookie_t last_complete;
2037 int ret;
2038
2039 last_complete = d40c->completed;
2040 last_used = chan->cookie;
2041
Jonas Aaberga5ebca42010-05-18 00:41:09 +02002042 if (d40_is_paused(d40c))
2043 ret = DMA_PAUSED;
2044 else
2045 ret = dma_async_is_complete(cookie, last_complete, last_used);
Linus Walleij8d318a52010-03-30 15:33:42 +02002046
Jonas Aaberga5ebca42010-05-18 00:41:09 +02002047 dma_set_tx_state(txstate, last_complete, last_used,
2048 stedma40_residue(chan));
Linus Walleij8d318a52010-03-30 15:33:42 +02002049
2050 return ret;
2051}
2052
2053static void d40_issue_pending(struct dma_chan *chan)
2054{
2055 struct d40_chan *d40c = container_of(chan, struct d40_chan, chan);
2056 unsigned long flags;
2057
2058 spin_lock_irqsave(&d40c->lock, flags);
2059
2060 /* Busy means that pending jobs are already being processed */
2061 if (!d40c->busy)
2062 (void) d40_queue_start(d40c);
2063
2064 spin_unlock_irqrestore(&d40c->lock, flags);
2065}
2066
2067static int d40_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd)
2068{
2069 unsigned long flags;
2070 struct d40_chan *d40c = container_of(chan, struct d40_chan, chan);
2071
2072 switch (cmd) {
2073 case DMA_TERMINATE_ALL:
2074 spin_lock_irqsave(&d40c->lock, flags);
2075 d40_term_all(d40c);
2076 spin_unlock_irqrestore(&d40c->lock, flags);
2077 return 0;
2078 case DMA_PAUSE:
2079 return d40_pause(chan);
2080 case DMA_RESUME:
2081 return d40_resume(chan);
2082 }
2083
2084 /* Other commands are unimplemented */
2085 return -ENXIO;
2086}
2087
2088/* Initialization functions */
2089
2090static void __init d40_chan_init(struct d40_base *base, struct dma_device *dma,
2091 struct d40_chan *chans, int offset,
2092 int num_chans)
2093{
2094 int i = 0;
2095 struct d40_chan *d40c;
2096
2097 INIT_LIST_HEAD(&dma->channels);
2098
2099 for (i = offset; i < offset + num_chans; i++) {
2100 d40c = &chans[i];
2101 d40c->base = base;
2102 d40c->chan.device = dma;
2103
2104 /* Invalidate lcla element */
2105 d40c->lcla.src_id = -1;
2106 d40c->lcla.dst_id = -1;
2107
2108 spin_lock_init(&d40c->lock);
2109
2110 d40c->log_num = D40_PHY_CHAN;
2111
2112 INIT_LIST_HEAD(&d40c->free);
2113 INIT_LIST_HEAD(&d40c->active);
2114 INIT_LIST_HEAD(&d40c->queue);
2115 INIT_LIST_HEAD(&d40c->client);
2116
2117 d40c->free_len = 0;
2118
2119 tasklet_init(&d40c->tasklet, dma_tasklet,
2120 (unsigned long) d40c);
2121
2122 list_add_tail(&d40c->chan.device_node,
2123 &dma->channels);
2124 }
2125}
2126
2127static int __init d40_dmaengine_init(struct d40_base *base,
2128 int num_reserved_chans)
2129{
2130 int err ;
2131
2132 d40_chan_init(base, &base->dma_slave, base->log_chans,
2133 0, base->num_log_chans);
2134
2135 dma_cap_zero(base->dma_slave.cap_mask);
2136 dma_cap_set(DMA_SLAVE, base->dma_slave.cap_mask);
2137
2138 base->dma_slave.device_alloc_chan_resources = d40_alloc_chan_resources;
2139 base->dma_slave.device_free_chan_resources = d40_free_chan_resources;
2140 base->dma_slave.device_prep_dma_memcpy = d40_prep_memcpy;
2141 base->dma_slave.device_prep_slave_sg = d40_prep_slave_sg;
2142 base->dma_slave.device_tx_status = d40_tx_status;
2143 base->dma_slave.device_issue_pending = d40_issue_pending;
2144 base->dma_slave.device_control = d40_control;
2145 base->dma_slave.dev = base->dev;
2146
2147 err = dma_async_device_register(&base->dma_slave);
2148
2149 if (err) {
2150 dev_err(base->dev,
2151 "[%s] Failed to register slave channels\n",
2152 __func__);
2153 goto failure1;
2154 }
2155
2156 d40_chan_init(base, &base->dma_memcpy, base->log_chans,
2157 base->num_log_chans, base->plat_data->memcpy_len);
2158
2159 dma_cap_zero(base->dma_memcpy.cap_mask);
2160 dma_cap_set(DMA_MEMCPY, base->dma_memcpy.cap_mask);
2161
2162 base->dma_memcpy.device_alloc_chan_resources = d40_alloc_chan_resources;
2163 base->dma_memcpy.device_free_chan_resources = d40_free_chan_resources;
2164 base->dma_memcpy.device_prep_dma_memcpy = d40_prep_memcpy;
2165 base->dma_memcpy.device_prep_slave_sg = d40_prep_slave_sg;
2166 base->dma_memcpy.device_tx_status = d40_tx_status;
2167 base->dma_memcpy.device_issue_pending = d40_issue_pending;
2168 base->dma_memcpy.device_control = d40_control;
2169 base->dma_memcpy.dev = base->dev;
2170 /*
2171 * This controller can only access address at even
2172 * 32bit boundaries, i.e. 2^2
2173 */
2174 base->dma_memcpy.copy_align = 2;
2175
2176 err = dma_async_device_register(&base->dma_memcpy);
2177
2178 if (err) {
2179 dev_err(base->dev,
2180 "[%s] Failed to regsiter memcpy only channels\n",
2181 __func__);
2182 goto failure2;
2183 }
2184
2185 d40_chan_init(base, &base->dma_both, base->phy_chans,
2186 0, num_reserved_chans);
2187
2188 dma_cap_zero(base->dma_both.cap_mask);
2189 dma_cap_set(DMA_SLAVE, base->dma_both.cap_mask);
2190 dma_cap_set(DMA_MEMCPY, base->dma_both.cap_mask);
2191
2192 base->dma_both.device_alloc_chan_resources = d40_alloc_chan_resources;
2193 base->dma_both.device_free_chan_resources = d40_free_chan_resources;
2194 base->dma_both.device_prep_dma_memcpy = d40_prep_memcpy;
2195 base->dma_both.device_prep_slave_sg = d40_prep_slave_sg;
2196 base->dma_both.device_tx_status = d40_tx_status;
2197 base->dma_both.device_issue_pending = d40_issue_pending;
2198 base->dma_both.device_control = d40_control;
2199 base->dma_both.dev = base->dev;
2200 base->dma_both.copy_align = 2;
2201 err = dma_async_device_register(&base->dma_both);
2202
2203 if (err) {
2204 dev_err(base->dev,
2205 "[%s] Failed to register logical and physical capable channels\n",
2206 __func__);
2207 goto failure3;
2208 }
2209 return 0;
2210failure3:
2211 dma_async_device_unregister(&base->dma_memcpy);
2212failure2:
2213 dma_async_device_unregister(&base->dma_slave);
2214failure1:
2215 return err;
2216}
2217
2218/* Initialization functions. */
2219
2220static int __init d40_phy_res_init(struct d40_base *base)
2221{
2222 int i;
2223 int num_phy_chans_avail = 0;
2224 u32 val[2];
2225 int odd_even_bit = -2;
2226
2227 val[0] = readl(base->virtbase + D40_DREG_PRSME);
2228 val[1] = readl(base->virtbase + D40_DREG_PRSMO);
2229
2230 for (i = 0; i < base->num_phy_chans; i++) {
2231 base->phy_res[i].num = i;
2232 odd_even_bit += 2 * ((i % 2) == 0);
2233 if (((val[i % 2] >> odd_even_bit) & 3) == 1) {
2234 /* Mark security only channels as occupied */
2235 base->phy_res[i].allocated_src = D40_ALLOC_PHY;
2236 base->phy_res[i].allocated_dst = D40_ALLOC_PHY;
2237 } else {
2238 base->phy_res[i].allocated_src = D40_ALLOC_FREE;
2239 base->phy_res[i].allocated_dst = D40_ALLOC_FREE;
2240 num_phy_chans_avail++;
2241 }
2242 spin_lock_init(&base->phy_res[i].lock);
2243 }
2244 dev_info(base->dev, "%d of %d physical DMA channels available\n",
2245 num_phy_chans_avail, base->num_phy_chans);
2246
2247 /* Verify settings extended vs standard */
2248 val[0] = readl(base->virtbase + D40_DREG_PRTYP);
2249
2250 for (i = 0; i < base->num_phy_chans; i++) {
2251
2252 if (base->phy_res[i].allocated_src == D40_ALLOC_FREE &&
2253 (val[0] & 0x3) != 1)
2254 dev_info(base->dev,
2255 "[%s] INFO: channel %d is misconfigured (%d)\n",
2256 __func__, i, val[0] & 0x3);
2257
2258 val[0] = val[0] >> 2;
2259 }
2260
2261 return num_phy_chans_avail;
2262}
2263
2264static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
2265{
2266 static const struct d40_reg_val dma_id_regs[] = {
2267 /* Peripheral Id */
2268 { .reg = D40_DREG_PERIPHID0, .val = 0x0040},
2269 { .reg = D40_DREG_PERIPHID1, .val = 0x0000},
2270 /*
2271 * D40_DREG_PERIPHID2 Depends on HW revision:
2272 * MOP500/HREF ED has 0x0008,
2273 * ? has 0x0018,
2274 * HREF V1 has 0x0028
2275 */
2276 { .reg = D40_DREG_PERIPHID3, .val = 0x0000},
2277
2278 /* PCell Id */
2279 { .reg = D40_DREG_CELLID0, .val = 0x000d},
2280 { .reg = D40_DREG_CELLID1, .val = 0x00f0},
2281 { .reg = D40_DREG_CELLID2, .val = 0x0005},
2282 { .reg = D40_DREG_CELLID3, .val = 0x00b1}
2283 };
2284 struct stedma40_platform_data *plat_data;
2285 struct clk *clk = NULL;
2286 void __iomem *virtbase = NULL;
2287 struct resource *res = NULL;
2288 struct d40_base *base = NULL;
2289 int num_log_chans = 0;
2290 int num_phy_chans;
2291 int i;
2292
2293 clk = clk_get(&pdev->dev, NULL);
2294
2295 if (IS_ERR(clk)) {
2296 dev_err(&pdev->dev, "[%s] No matching clock found\n",
2297 __func__);
2298 goto failure;
2299 }
2300
2301 clk_enable(clk);
2302
2303 /* Get IO for DMAC base address */
2304 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "base");
2305 if (!res)
2306 goto failure;
2307
2308 if (request_mem_region(res->start, resource_size(res),
2309 D40_NAME " I/O base") == NULL)
2310 goto failure;
2311
2312 virtbase = ioremap(res->start, resource_size(res));
2313 if (!virtbase)
2314 goto failure;
2315
2316 /* HW version check */
2317 for (i = 0; i < ARRAY_SIZE(dma_id_regs); i++) {
2318 if (dma_id_regs[i].val !=
2319 readl(virtbase + dma_id_regs[i].reg)) {
2320 dev_err(&pdev->dev,
2321 "[%s] Unknown hardware! Expected 0x%x at 0x%x but got 0x%x\n",
2322 __func__,
2323 dma_id_regs[i].val,
2324 dma_id_regs[i].reg,
2325 readl(virtbase + dma_id_regs[i].reg));
2326 goto failure;
2327 }
2328 }
2329
2330 i = readl(virtbase + D40_DREG_PERIPHID2);
2331
2332 if ((i & 0xf) != D40_PERIPHID2_DESIGNER) {
2333 dev_err(&pdev->dev,
2334 "[%s] Unknown designer! Got %x wanted %x\n",
2335 __func__, i & 0xf, D40_PERIPHID2_DESIGNER);
2336 goto failure;
2337 }
2338
2339 /* The number of physical channels on this HW */
2340 num_phy_chans = 4 * (readl(virtbase + D40_DREG_ICFG) & 0x7) + 4;
2341
2342 dev_info(&pdev->dev, "hardware revision: %d @ 0x%x\n",
2343 (i >> 4) & 0xf, res->start);
2344
2345 plat_data = pdev->dev.platform_data;
2346
2347 /* Count the number of logical channels in use */
2348 for (i = 0; i < plat_data->dev_len; i++)
2349 if (plat_data->dev_rx[i] != 0)
2350 num_log_chans++;
2351
2352 for (i = 0; i < plat_data->dev_len; i++)
2353 if (plat_data->dev_tx[i] != 0)
2354 num_log_chans++;
2355
2356 base = kzalloc(ALIGN(sizeof(struct d40_base), 4) +
2357 (num_phy_chans + num_log_chans + plat_data->memcpy_len) *
2358 sizeof(struct d40_chan), GFP_KERNEL);
2359
2360 if (base == NULL) {
2361 dev_err(&pdev->dev, "[%s] Out of memory\n", __func__);
2362 goto failure;
2363 }
2364
2365 base->clk = clk;
2366 base->num_phy_chans = num_phy_chans;
2367 base->num_log_chans = num_log_chans;
2368 base->phy_start = res->start;
2369 base->phy_size = resource_size(res);
2370 base->virtbase = virtbase;
2371 base->plat_data = plat_data;
2372 base->dev = &pdev->dev;
2373 base->phy_chans = ((void *)base) + ALIGN(sizeof(struct d40_base), 4);
2374 base->log_chans = &base->phy_chans[num_phy_chans];
2375
2376 base->phy_res = kzalloc(num_phy_chans * sizeof(struct d40_phy_res),
2377 GFP_KERNEL);
2378 if (!base->phy_res)
2379 goto failure;
2380
2381 base->lookup_phy_chans = kzalloc(num_phy_chans *
2382 sizeof(struct d40_chan *),
2383 GFP_KERNEL);
2384 if (!base->lookup_phy_chans)
2385 goto failure;
2386
2387 if (num_log_chans + plat_data->memcpy_len) {
2388 /*
2389 * The max number of logical channels are event lines for all
2390 * src devices and dst devices
2391 */
2392 base->lookup_log_chans = kzalloc(plat_data->dev_len * 2 *
2393 sizeof(struct d40_chan *),
2394 GFP_KERNEL);
2395 if (!base->lookup_log_chans)
2396 goto failure;
2397 }
2398 base->lcla_pool.alloc_map = kzalloc(num_phy_chans * sizeof(u32),
2399 GFP_KERNEL);
2400 if (!base->lcla_pool.alloc_map)
2401 goto failure;
2402
2403 return base;
2404
2405failure:
2406 if (clk) {
2407 clk_disable(clk);
2408 clk_put(clk);
2409 }
2410 if (virtbase)
2411 iounmap(virtbase);
2412 if (res)
2413 release_mem_region(res->start,
2414 resource_size(res));
2415 if (virtbase)
2416 iounmap(virtbase);
2417
2418 if (base) {
2419 kfree(base->lcla_pool.alloc_map);
2420 kfree(base->lookup_log_chans);
2421 kfree(base->lookup_phy_chans);
2422 kfree(base->phy_res);
2423 kfree(base);
2424 }
2425
2426 return NULL;
2427}
2428
2429static void __init d40_hw_init(struct d40_base *base)
2430{
2431
2432 static const struct d40_reg_val dma_init_reg[] = {
2433 /* Clock every part of the DMA block from start */
2434 { .reg = D40_DREG_GCC, .val = 0x0000ff01},
2435
2436 /* Interrupts on all logical channels */
2437 { .reg = D40_DREG_LCMIS0, .val = 0xFFFFFFFF},
2438 { .reg = D40_DREG_LCMIS1, .val = 0xFFFFFFFF},
2439 { .reg = D40_DREG_LCMIS2, .val = 0xFFFFFFFF},
2440 { .reg = D40_DREG_LCMIS3, .val = 0xFFFFFFFF},
2441 { .reg = D40_DREG_LCICR0, .val = 0xFFFFFFFF},
2442 { .reg = D40_DREG_LCICR1, .val = 0xFFFFFFFF},
2443 { .reg = D40_DREG_LCICR2, .val = 0xFFFFFFFF},
2444 { .reg = D40_DREG_LCICR3, .val = 0xFFFFFFFF},
2445 { .reg = D40_DREG_LCTIS0, .val = 0xFFFFFFFF},
2446 { .reg = D40_DREG_LCTIS1, .val = 0xFFFFFFFF},
2447 { .reg = D40_DREG_LCTIS2, .val = 0xFFFFFFFF},
2448 { .reg = D40_DREG_LCTIS3, .val = 0xFFFFFFFF}
2449 };
2450 int i;
2451 u32 prmseo[2] = {0, 0};
2452 u32 activeo[2] = {0xFFFFFFFF, 0xFFFFFFFF};
2453 u32 pcmis = 0;
2454 u32 pcicr = 0;
2455
2456 for (i = 0; i < ARRAY_SIZE(dma_init_reg); i++)
2457 writel(dma_init_reg[i].val,
2458 base->virtbase + dma_init_reg[i].reg);
2459
2460 /* Configure all our dma channels to default settings */
2461 for (i = 0; i < base->num_phy_chans; i++) {
2462
2463 activeo[i % 2] = activeo[i % 2] << 2;
2464
2465 if (base->phy_res[base->num_phy_chans - i - 1].allocated_src
2466 == D40_ALLOC_PHY) {
2467 activeo[i % 2] |= 3;
2468 continue;
2469 }
2470
2471 /* Enable interrupt # */
2472 pcmis = (pcmis << 1) | 1;
2473
2474 /* Clear interrupt # */
2475 pcicr = (pcicr << 1) | 1;
2476
2477 /* Set channel to physical mode */
2478 prmseo[i % 2] = prmseo[i % 2] << 2;
2479 prmseo[i % 2] |= 1;
2480
2481 }
2482
2483 writel(prmseo[1], base->virtbase + D40_DREG_PRMSE);
2484 writel(prmseo[0], base->virtbase + D40_DREG_PRMSO);
2485 writel(activeo[1], base->virtbase + D40_DREG_ACTIVE);
2486 writel(activeo[0], base->virtbase + D40_DREG_ACTIVO);
2487
2488 /* Write which interrupt to enable */
2489 writel(pcmis, base->virtbase + D40_DREG_PCMIS);
2490
2491 /* Write which interrupt to clear */
2492 writel(pcicr, base->virtbase + D40_DREG_PCICR);
2493
2494}
2495
2496static int __init d40_probe(struct platform_device *pdev)
2497{
2498 int err;
2499 int ret = -ENOENT;
2500 struct d40_base *base;
2501 struct resource *res = NULL;
2502 int num_reserved_chans;
2503 u32 val;
2504
2505 base = d40_hw_detect_init(pdev);
2506
2507 if (!base)
2508 goto failure;
2509
2510 num_reserved_chans = d40_phy_res_init(base);
2511
2512 platform_set_drvdata(pdev, base);
2513
2514 spin_lock_init(&base->interrupt_lock);
2515 spin_lock_init(&base->execmd_lock);
2516
2517 /* Get IO for logical channel parameter address */
2518 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcpa");
2519 if (!res) {
2520 ret = -ENOENT;
2521 dev_err(&pdev->dev,
2522 "[%s] No \"lcpa\" memory resource\n",
2523 __func__);
2524 goto failure;
2525 }
2526 base->lcpa_size = resource_size(res);
2527 base->phy_lcpa = res->start;
2528
2529 if (request_mem_region(res->start, resource_size(res),
2530 D40_NAME " I/O lcpa") == NULL) {
2531 ret = -EBUSY;
2532 dev_err(&pdev->dev,
2533 "[%s] Failed to request LCPA region 0x%x-0x%x\n",
2534 __func__, res->start, res->end);
2535 goto failure;
2536 }
2537
2538 /* We make use of ESRAM memory for this. */
2539 val = readl(base->virtbase + D40_DREG_LCPA);
2540 if (res->start != val && val != 0) {
2541 dev_warn(&pdev->dev,
2542 "[%s] Mismatch LCPA dma 0x%x, def 0x%x\n",
2543 __func__, val, res->start);
2544 } else
2545 writel(res->start, base->virtbase + D40_DREG_LCPA);
2546
2547 base->lcpa_base = ioremap(res->start, resource_size(res));
2548 if (!base->lcpa_base) {
2549 ret = -ENOMEM;
2550 dev_err(&pdev->dev,
2551 "[%s] Failed to ioremap LCPA region\n",
2552 __func__);
2553 goto failure;
2554 }
2555 /* Get IO for logical channel link address */
2556 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcla");
2557 if (!res) {
2558 ret = -ENOENT;
2559 dev_err(&pdev->dev,
2560 "[%s] No \"lcla\" resource defined\n",
2561 __func__);
2562 goto failure;
2563 }
2564
2565 base->lcla_pool.base_size = resource_size(res);
2566 base->lcla_pool.phy = res->start;
2567
2568 if (request_mem_region(res->start, resource_size(res),
2569 D40_NAME " I/O lcla") == NULL) {
2570 ret = -EBUSY;
2571 dev_err(&pdev->dev,
2572 "[%s] Failed to request LCLA region 0x%x-0x%x\n",
2573 __func__, res->start, res->end);
2574 goto failure;
2575 }
2576 val = readl(base->virtbase + D40_DREG_LCLA);
2577 if (res->start != val && val != 0) {
2578 dev_warn(&pdev->dev,
2579 "[%s] Mismatch LCLA dma 0x%x, def 0x%x\n",
2580 __func__, val, res->start);
2581 } else
2582 writel(res->start, base->virtbase + D40_DREG_LCLA);
2583
2584 base->lcla_pool.base = ioremap(res->start, resource_size(res));
2585 if (!base->lcla_pool.base) {
2586 ret = -ENOMEM;
2587 dev_err(&pdev->dev,
2588 "[%s] Failed to ioremap LCLA 0x%x-0x%x\n",
2589 __func__, res->start, res->end);
2590 goto failure;
2591 }
2592
2593 spin_lock_init(&base->lcla_pool.lock);
2594
2595 base->lcla_pool.num_blocks = base->num_phy_chans;
2596
2597 base->irq = platform_get_irq(pdev, 0);
2598
2599 ret = request_irq(base->irq, d40_handle_interrupt, 0, D40_NAME, base);
2600
2601 if (ret) {
2602 dev_err(&pdev->dev, "[%s] No IRQ defined\n", __func__);
2603 goto failure;
2604 }
2605
2606 err = d40_dmaengine_init(base, num_reserved_chans);
2607 if (err)
2608 goto failure;
2609
2610 d40_hw_init(base);
2611
2612 dev_info(base->dev, "initialized\n");
2613 return 0;
2614
2615failure:
2616 if (base) {
2617 if (base->virtbase)
2618 iounmap(base->virtbase);
2619 if (base->lcla_pool.phy)
2620 release_mem_region(base->lcla_pool.phy,
2621 base->lcla_pool.base_size);
2622 if (base->phy_lcpa)
2623 release_mem_region(base->phy_lcpa,
2624 base->lcpa_size);
2625 if (base->phy_start)
2626 release_mem_region(base->phy_start,
2627 base->phy_size);
2628 if (base->clk) {
2629 clk_disable(base->clk);
2630 clk_put(base->clk);
2631 }
2632
2633 kfree(base->lcla_pool.alloc_map);
2634 kfree(base->lookup_log_chans);
2635 kfree(base->lookup_phy_chans);
2636 kfree(base->phy_res);
2637 kfree(base);
2638 }
2639
2640 dev_err(&pdev->dev, "[%s] probe failed\n", __func__);
2641 return ret;
2642}
2643
2644static struct platform_driver d40_driver = {
2645 .driver = {
2646 .owner = THIS_MODULE,
2647 .name = D40_NAME,
2648 },
2649};
2650
2651int __init stedma40_init(void)
2652{
2653 return platform_driver_probe(&d40_driver, d40_probe);
2654}
2655arch_initcall(stedma40_init);