2 * intel_mid_dma.c - Intel Langwell DMA Drivers
4 * Copyright (C) 2008-10 Intel Corp
5 * Author: Vinod Koul <vinod.koul@intel.com>
6 * The driver design is based on dw_dmac driver
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28 #include <linux/pm_runtime.h>
29 #include <linux/intel_mid_dma.h>
31 #define MAX_CHAN 4 /*max ch across controllers*/
32 #include "intel_mid_dma_regs.h"
34 #define INTEL_MID_DMAC1_ID 0x0814
35 #define INTEL_MID_DMAC2_ID 0x0813
36 #define INTEL_MID_GP_DMAC2_ID 0x0827
37 #define INTEL_MFLD_DMAC1_ID 0x0830
38 #define LNW_PERIPHRAL_MASK_BASE 0xFFAE8008
39 #define LNW_PERIPHRAL_MASK_SIZE 0x10
40 #define LNW_PERIPHRAL_STATUS 0x0
41 #define LNW_PERIPHRAL_MASK 0x8
43 struct intel_mid_dma_probe_info
{
50 #define INFO(_max_chan, _ch_base, _block_size, _pimr_mask) \
51 ((kernel_ulong_t)&(struct intel_mid_dma_probe_info) { \
52 .max_chan = (_max_chan), \
53 .ch_base = (_ch_base), \
54 .block_size = (_block_size), \
55 .pimr_mask = (_pimr_mask), \
58 /*****************************************************************************
61 * get_ch_index - convert status to channel
62 * @status: status mask
63 * @base: dma ch base value
65 * Modify the status mask and return the channel index needing
66 * attention (or -1 if neither)
68 static int get_ch_index(int *status
, unsigned int base
)
71 for (i
= 0; i
< MAX_CHAN
; i
++) {
72 if (*status
& (1 << (i
+ base
))) {
73 *status
= *status
& ~(1 << (i
+ base
));
74 pr_debug("MDMA: index %d New status %x\n", i
, *status
);
82 * get_block_ts - calculates dma transaction length
83 * @len: dma transfer length
84 * @tx_width: dma transfer src width
85 * @block_size: dma controller max block size
87 * Based on src width calculate the DMA trsaction length in data items
88 * return data items or FFFF if exceeds max length for block
90 static int get_block_ts(int len
, int tx_width
, int block_size
)
92 int byte_width
= 0, block_ts
= 0;
95 case DMA_SLAVE_BUSWIDTH_1_BYTE
:
98 case DMA_SLAVE_BUSWIDTH_2_BYTES
:
101 case DMA_SLAVE_BUSWIDTH_4_BYTES
:
107 block_ts
= len
/byte_width
;
108 if (block_ts
> block_size
)
113 /*****************************************************************************
114 DMAC1 interrupt Functions*/
117 * dmac1_mask_periphral_intr - mask the periphral interrupt
118 * @midc: dma channel for which masking is required
120 * Masks the DMA periphral interrupt
121 * this is valid for DMAC1 family controllers only
122 * This controller should have periphral mask registers already mapped
124 static void dmac1_mask_periphral_intr(struct intel_mid_dma_chan
*midc
)
127 struct middma_device
*mid
= to_middma_device(midc
->chan
.device
);
129 if (mid
->pimr_mask
) {
130 pimr
= readl(mid
->mask_reg
+ LNW_PERIPHRAL_MASK
);
131 pimr
|= mid
->pimr_mask
;
132 writel(pimr
, mid
->mask_reg
+ LNW_PERIPHRAL_MASK
);
138 * dmac1_unmask_periphral_intr - unmask the periphral interrupt
139 * @midc: dma channel for which masking is required
141 * UnMasks the DMA periphral interrupt,
142 * this is valid for DMAC1 family controllers only
143 * This controller should have periphral mask registers already mapped
145 static void dmac1_unmask_periphral_intr(struct intel_mid_dma_chan
*midc
)
148 struct middma_device
*mid
= to_middma_device(midc
->chan
.device
);
150 if (mid
->pimr_mask
) {
151 pimr
= readl(mid
->mask_reg
+ LNW_PERIPHRAL_MASK
);
152 pimr
&= ~mid
->pimr_mask
;
153 writel(pimr
, mid
->mask_reg
+ LNW_PERIPHRAL_MASK
);
159 * enable_dma_interrupt - enable the periphral interrupt
160 * @midc: dma channel for which enable interrupt is required
162 * Enable the DMA periphral interrupt,
163 * this is valid for DMAC1 family controllers only
164 * This controller should have periphral mask registers already mapped
166 static void enable_dma_interrupt(struct intel_mid_dma_chan
*midc
)
168 dmac1_unmask_periphral_intr(midc
);
171 iowrite32(UNMASK_INTR_REG(midc
->ch_id
), midc
->dma_base
+ MASK_TFR
);
172 iowrite32(UNMASK_INTR_REG(midc
->ch_id
), midc
->dma_base
+ MASK_ERR
);
177 * disable_dma_interrupt - disable the periphral interrupt
178 * @midc: dma channel for which disable interrupt is required
180 * Disable the DMA periphral interrupt,
181 * this is valid for DMAC1 family controllers only
182 * This controller should have periphral mask registers already mapped
184 static void disable_dma_interrupt(struct intel_mid_dma_chan
*midc
)
186 /*Check LPE PISR, make sure fwd is disabled*/
187 dmac1_mask_periphral_intr(midc
);
188 iowrite32(MASK_INTR_REG(midc
->ch_id
), midc
->dma_base
+ MASK_BLOCK
);
189 iowrite32(MASK_INTR_REG(midc
->ch_id
), midc
->dma_base
+ MASK_TFR
);
190 iowrite32(MASK_INTR_REG(midc
->ch_id
), midc
->dma_base
+ MASK_ERR
);
194 /*****************************************************************************
195 DMA channel helper Functions*/
197 * mid_desc_get - get a descriptor
198 * @midc: dma channel for which descriptor is required
200 * Obtain a descriptor for the channel. Returns NULL if none are free.
201 * Once the descriptor is returned it is private until put on another
204 static struct intel_mid_dma_desc
*midc_desc_get(struct intel_mid_dma_chan
*midc
)
206 struct intel_mid_dma_desc
*desc
, *_desc
;
207 struct intel_mid_dma_desc
*ret
= NULL
;
209 spin_lock_bh(&midc
->lock
);
210 list_for_each_entry_safe(desc
, _desc
, &midc
->free_list
, desc_node
) {
211 if (async_tx_test_ack(&desc
->txd
)) {
212 list_del(&desc
->desc_node
);
217 spin_unlock_bh(&midc
->lock
);
222 * mid_desc_put - put a descriptor
223 * @midc: dma channel for which descriptor is required
224 * @desc: descriptor to put
226 * Return a descriptor from lwn_desc_get back to the free pool
228 static void midc_desc_put(struct intel_mid_dma_chan
*midc
,
229 struct intel_mid_dma_desc
*desc
)
232 spin_lock_bh(&midc
->lock
);
233 list_add_tail(&desc
->desc_node
, &midc
->free_list
);
234 spin_unlock_bh(&midc
->lock
);
238 * midc_dostart - begin a DMA transaction
239 * @midc: channel for which txn is to be started
240 * @first: first descriptor of series
242 * Load a transaction into the engine. This must be called with midc->lock
243 * held and bh disabled.
245 static void midc_dostart(struct intel_mid_dma_chan
*midc
,
246 struct intel_mid_dma_desc
*first
)
248 struct middma_device
*mid
= to_middma_device(midc
->chan
.device
);
250 /* channel is idle */
251 if (midc
->busy
&& test_ch_en(midc
->dma_base
, midc
->ch_id
)) {
253 pr_err("ERR_MDMA: channel is busy in start\n");
254 /* The tasklet will hopefully advance the queue... */
258 /*write registers and en*/
259 iowrite32(first
->sar
, midc
->ch_regs
+ SAR
);
260 iowrite32(first
->dar
, midc
->ch_regs
+ DAR
);
261 iowrite32(first
->lli_phys
, midc
->ch_regs
+ LLP
);
262 iowrite32(first
->cfg_hi
, midc
->ch_regs
+ CFG_HIGH
);
263 iowrite32(first
->cfg_lo
, midc
->ch_regs
+ CFG_LOW
);
264 iowrite32(first
->ctl_lo
, midc
->ch_regs
+ CTL_LOW
);
265 iowrite32(first
->ctl_hi
, midc
->ch_regs
+ CTL_HIGH
);
266 pr_debug("MDMA:TX SAR %x,DAR %x,CFGL %x,CFGH %x,CTLH %x, CTLL %x\n",
267 (int)first
->sar
, (int)first
->dar
, first
->cfg_hi
,
268 first
->cfg_lo
, first
->ctl_hi
, first
->ctl_lo
);
269 first
->status
= DMA_IN_PROGRESS
;
271 iowrite32(ENABLE_CHANNEL(midc
->ch_id
), mid
->dma_base
+ DMA_CHAN_EN
);
275 * midc_descriptor_complete - process completed descriptor
276 * @midc: channel owning the descriptor
277 * @desc: the descriptor itself
279 * Process a completed descriptor and perform any callbacks upon
280 * the completion. The completion handling drops the lock during the
281 * callbacks but must be called with the lock held.
283 static void midc_descriptor_complete(struct intel_mid_dma_chan
*midc
,
284 struct intel_mid_dma_desc
*desc
)
286 struct dma_async_tx_descriptor
*txd
= &desc
->txd
;
287 dma_async_tx_callback callback_txd
= NULL
;
288 struct intel_mid_dma_lli
*llitem
;
289 void *param_txd
= NULL
;
291 midc
->completed
= txd
->cookie
;
292 callback_txd
= txd
->callback
;
293 param_txd
= txd
->callback_param
;
295 if (desc
->lli
!= NULL
) {
296 /*clear the DONE bit of completed LLI in memory*/
297 llitem
= desc
->lli
+ desc
->current_lli
;
298 llitem
->ctl_hi
&= CLEAR_DONE
;
299 if (desc
->current_lli
< desc
->lli_length
-1)
300 (desc
->current_lli
)++;
302 desc
->current_lli
= 0;
304 spin_unlock_bh(&midc
->lock
);
306 pr_debug("MDMA: TXD callback set ... calling\n");
307 callback_txd(param_txd
);
310 desc
->status
= DMA_SUCCESS
;
311 if (desc
->lli
!= NULL
) {
312 pci_pool_free(desc
->lli_pool
, desc
->lli
,
314 pci_pool_destroy(desc
->lli_pool
);
316 list_move(&desc
->desc_node
, &midc
->free_list
);
319 spin_lock_bh(&midc
->lock
);
323 * midc_scan_descriptors - check the descriptors in channel
324 * mark completed when tx is completete
326 * @midc: channel to scan
328 * Walk the descriptor chain for the device and process any entries
331 static void midc_scan_descriptors(struct middma_device
*mid
,
332 struct intel_mid_dma_chan
*midc
)
334 struct intel_mid_dma_desc
*desc
= NULL
, *_desc
= NULL
;
337 list_for_each_entry_safe(desc
, _desc
, &midc
->active_list
, desc_node
) {
338 if (desc
->status
== DMA_IN_PROGRESS
)
339 midc_descriptor_complete(midc
, desc
);
344 * midc_lli_fill_sg - Helper function to convert
345 * SG list to Linked List Items.
347 *@desc: DMA descriptor
348 *@sglist: Pointer to SG list
349 *@sglen: SG list length
350 *@flags: DMA transaction flags
352 * Walk through the SG list and convert the SG list into Linked
355 static int midc_lli_fill_sg(struct intel_mid_dma_chan
*midc
,
356 struct intel_mid_dma_desc
*desc
,
357 struct scatterlist
*sglist
,
361 struct intel_mid_dma_slave
*mids
;
362 struct scatterlist
*sg
;
363 dma_addr_t lli_next
, sg_phy_addr
;
364 struct intel_mid_dma_lli
*lli_bloc_desc
;
365 union intel_mid_dma_ctl_lo ctl_lo
;
366 union intel_mid_dma_ctl_hi ctl_hi
;
369 pr_debug("MDMA: Entered midc_lli_fill_sg\n");
370 mids
= midc
->mid_slave
;
372 lli_bloc_desc
= desc
->lli
;
373 lli_next
= desc
->lli_phys
;
375 ctl_lo
.ctl_lo
= desc
->ctl_lo
;
376 ctl_hi
.ctl_hi
= desc
->ctl_hi
;
377 for_each_sg(sglist
, sg
, sglen
, i
) {
378 /*Populate CTL_LOW and LLI values*/
379 if (i
!= sglen
- 1) {
380 lli_next
= lli_next
+
381 sizeof(struct intel_mid_dma_lli
);
383 /*Check for circular list, otherwise terminate LLI to ZERO*/
384 if (flags
& DMA_PREP_CIRCULAR_LIST
) {
385 pr_debug("MDMA: LLI is configured in circular mode\n");
386 lli_next
= desc
->lli_phys
;
389 ctl_lo
.ctlx
.llp_dst_en
= 0;
390 ctl_lo
.ctlx
.llp_src_en
= 0;
393 /*Populate CTL_HI values*/
394 ctl_hi
.ctlx
.block_ts
= get_block_ts(sg
->length
,
396 midc
->dma
->block_size
);
397 /*Populate SAR and DAR values*/
398 sg_phy_addr
= sg_phys(sg
);
399 if (desc
->dirn
== DMA_TO_DEVICE
) {
400 lli_bloc_desc
->sar
= sg_phy_addr
;
401 lli_bloc_desc
->dar
= mids
->dma_slave
.dst_addr
;
402 } else if (desc
->dirn
== DMA_FROM_DEVICE
) {
403 lli_bloc_desc
->sar
= mids
->dma_slave
.src_addr
;
404 lli_bloc_desc
->dar
= sg_phy_addr
;
406 /*Copy values into block descriptor in system memroy*/
407 lli_bloc_desc
->llp
= lli_next
;
408 lli_bloc_desc
->ctl_lo
= ctl_lo
.ctl_lo
;
409 lli_bloc_desc
->ctl_hi
= ctl_hi
.ctl_hi
;
413 /*Copy very first LLI values to descriptor*/
414 desc
->ctl_lo
= desc
->lli
->ctl_lo
;
415 desc
->ctl_hi
= desc
->lli
->ctl_hi
;
416 desc
->sar
= desc
->lli
->sar
;
417 desc
->dar
= desc
->lli
->dar
;
421 /*****************************************************************************
422 DMA engine callback Functions*/
424 * intel_mid_dma_tx_submit - callback to submit DMA transaction
425 * @tx: dma engine descriptor
427 * Submit the DMA trasaction for this descriptor, start if ch idle
429 static dma_cookie_t
intel_mid_dma_tx_submit(struct dma_async_tx_descriptor
*tx
)
431 struct intel_mid_dma_desc
*desc
= to_intel_mid_dma_desc(tx
);
432 struct intel_mid_dma_chan
*midc
= to_intel_mid_dma_chan(tx
->chan
);
435 spin_lock_bh(&midc
->lock
);
436 cookie
= midc
->chan
.cookie
;
441 midc
->chan
.cookie
= cookie
;
442 desc
->txd
.cookie
= cookie
;
445 if (list_empty(&midc
->active_list
))
446 list_add_tail(&desc
->desc_node
, &midc
->active_list
);
448 list_add_tail(&desc
->desc_node
, &midc
->queue
);
450 midc_dostart(midc
, desc
);
451 spin_unlock_bh(&midc
->lock
);
457 * intel_mid_dma_issue_pending - callback to issue pending txn
458 * @chan: chan where pending trascation needs to be checked and submitted
460 * Call for scan to issue pending descriptors
462 static void intel_mid_dma_issue_pending(struct dma_chan
*chan
)
464 struct intel_mid_dma_chan
*midc
= to_intel_mid_dma_chan(chan
);
466 spin_lock_bh(&midc
->lock
);
467 if (!list_empty(&midc
->queue
))
468 midc_scan_descriptors(to_middma_device(chan
->device
), midc
);
469 spin_unlock_bh(&midc
->lock
);
473 * intel_mid_dma_tx_status - Return status of txn
474 * @chan: chan for where status needs to be checked
475 * @cookie: cookie for txn
476 * @txstate: DMA txn state
478 * Return status of DMA txn
480 static enum dma_status
intel_mid_dma_tx_status(struct dma_chan
*chan
,
482 struct dma_tx_state
*txstate
)
484 struct intel_mid_dma_chan
*midc
= to_intel_mid_dma_chan(chan
);
485 dma_cookie_t last_used
;
486 dma_cookie_t last_complete
;
489 last_complete
= midc
->completed
;
490 last_used
= chan
->cookie
;
492 ret
= dma_async_is_complete(cookie
, last_complete
, last_used
);
493 if (ret
!= DMA_SUCCESS
) {
494 midc_scan_descriptors(to_middma_device(chan
->device
), midc
);
496 last_complete
= midc
->completed
;
497 last_used
= chan
->cookie
;
499 ret
= dma_async_is_complete(cookie
, last_complete
, last_used
);
503 txstate
->last
= last_complete
;
504 txstate
->used
= last_used
;
505 txstate
->residue
= 0;
510 static int dma_slave_control(struct dma_chan
*chan
, unsigned long arg
)
512 struct intel_mid_dma_chan
*midc
= to_intel_mid_dma_chan(chan
);
513 struct dma_slave_config
*slave
= (struct dma_slave_config
*)arg
;
514 struct intel_mid_dma_slave
*mid_slave
;
518 pr_debug("MDMA: slave control called\n");
520 mid_slave
= to_intel_mid_dma_slave(slave
);
524 midc
->mid_slave
= mid_slave
;
528 * intel_mid_dma_device_control - DMA device control
529 * @chan: chan for DMA control
531 * @arg: cmd arg value
533 * Perform DMA control command
535 static int intel_mid_dma_device_control(struct dma_chan
*chan
,
536 enum dma_ctrl_cmd cmd
, unsigned long arg
)
538 struct intel_mid_dma_chan
*midc
= to_intel_mid_dma_chan(chan
);
539 struct middma_device
*mid
= to_middma_device(chan
->device
);
540 struct intel_mid_dma_desc
*desc
, *_desc
;
541 union intel_mid_dma_cfg_lo cfg_lo
;
543 if (cmd
== DMA_SLAVE_CONFIG
)
544 return dma_slave_control(chan
, arg
);
546 if (cmd
!= DMA_TERMINATE_ALL
)
549 spin_lock_bh(&midc
->lock
);
550 if (midc
->busy
== false) {
551 spin_unlock_bh(&midc
->lock
);
554 /*Suspend and disable the channel*/
555 cfg_lo
.cfg_lo
= ioread32(midc
->ch_regs
+ CFG_LOW
);
556 cfg_lo
.cfgx
.ch_susp
= 1;
557 iowrite32(cfg_lo
.cfg_lo
, midc
->ch_regs
+ CFG_LOW
);
558 iowrite32(DISABLE_CHANNEL(midc
->ch_id
), mid
->dma_base
+ DMA_CHAN_EN
);
560 /* Disable interrupts */
561 disable_dma_interrupt(midc
);
562 midc
->descs_allocated
= 0;
564 spin_unlock_bh(&midc
->lock
);
565 list_for_each_entry_safe(desc
, _desc
, &midc
->active_list
, desc_node
) {
566 if (desc
->lli
!= NULL
) {
567 pci_pool_free(desc
->lli_pool
, desc
->lli
,
569 pci_pool_destroy(desc
->lli_pool
);
571 list_move(&desc
->desc_node
, &midc
->free_list
);
578 * intel_mid_dma_prep_memcpy - Prep memcpy txn
579 * @chan: chan for DMA transfer
580 * @dest: destn address
582 * @len: DMA transfer len
585 * Perform a DMA memcpy. Note we support slave periphral DMA transfers only
586 * The periphral txn details should be filled in slave structure properly
587 * Returns the descriptor for this txn
589 static struct dma_async_tx_descriptor
*intel_mid_dma_prep_memcpy(
590 struct dma_chan
*chan
, dma_addr_t dest
,
591 dma_addr_t src
, size_t len
, unsigned long flags
)
593 struct intel_mid_dma_chan
*midc
;
594 struct intel_mid_dma_desc
*desc
= NULL
;
595 struct intel_mid_dma_slave
*mids
;
596 union intel_mid_dma_ctl_lo ctl_lo
;
597 union intel_mid_dma_ctl_hi ctl_hi
;
598 union intel_mid_dma_cfg_lo cfg_lo
;
599 union intel_mid_dma_cfg_hi cfg_hi
;
600 enum dma_slave_buswidth width
;
602 pr_debug("MDMA: Prep for memcpy\n");
607 midc
= to_intel_mid_dma_chan(chan
);
610 mids
= midc
->mid_slave
;
613 pr_debug("MDMA:called for DMA %x CH %d Length %zu\n",
614 midc
->dma
->pci_id
, midc
->ch_id
, len
);
615 pr_debug("MDMA:Cfg passed Mode %x, Dirn %x, HS %x, Width %x\n",
616 mids
->cfg_mode
, mids
->dma_slave
.direction
,
617 mids
->hs_mode
, mids
->dma_slave
.src_addr_width
);
620 if (mids
->hs_mode
== LNW_DMA_SW_HS
) {
622 cfg_lo
.cfgx
.hs_sel_dst
= 1;
623 cfg_lo
.cfgx
.hs_sel_src
= 1;
624 } else if (mids
->hs_mode
== LNW_DMA_HW_HS
)
625 cfg_lo
.cfg_lo
= 0x00000;
628 if (mids
->cfg_mode
== LNW_DMA_MEM_TO_MEM
) {
633 if (midc
->dma
->pimr_mask
) {
634 cfg_hi
.cfgx
.protctl
= 0x0; /*default value*/
635 cfg_hi
.cfgx
.fifo_mode
= 1;
636 if (mids
->dma_slave
.direction
== DMA_TO_DEVICE
) {
637 cfg_hi
.cfgx
.src_per
= 0;
638 if (mids
->device_instance
== 0)
639 cfg_hi
.cfgx
.dst_per
= 3;
640 if (mids
->device_instance
== 1)
641 cfg_hi
.cfgx
.dst_per
= 1;
642 } else if (mids
->dma_slave
.direction
== DMA_FROM_DEVICE
) {
643 if (mids
->device_instance
== 0)
644 cfg_hi
.cfgx
.src_per
= 2;
645 if (mids
->device_instance
== 1)
646 cfg_hi
.cfgx
.src_per
= 0;
647 cfg_hi
.cfgx
.dst_per
= 0;
650 cfg_hi
.cfgx
.protctl
= 0x1; /*default value*/
651 cfg_hi
.cfgx
.src_per
= cfg_hi
.cfgx
.dst_per
=
652 midc
->ch_id
- midc
->dma
->chan_base
;
657 ctl_hi
.ctlx
.reser
= 0;
658 ctl_hi
.ctlx
.done
= 0;
659 width
= mids
->dma_slave
.src_addr_width
;
661 ctl_hi
.ctlx
.block_ts
= get_block_ts(len
, width
, midc
->dma
->block_size
);
662 pr_debug("MDMA:calc len %d for block size %d\n",
663 ctl_hi
.ctlx
.block_ts
, midc
->dma
->block_size
);
666 ctl_lo
.ctlx
.int_en
= 1;
667 ctl_lo
.ctlx
.dst_tr_width
= mids
->dma_slave
.dst_addr_width
;
668 ctl_lo
.ctlx
.src_tr_width
= mids
->dma_slave
.src_addr_width
;
669 ctl_lo
.ctlx
.dst_msize
= mids
->dma_slave
.src_maxburst
;
670 ctl_lo
.ctlx
.src_msize
= mids
->dma_slave
.dst_maxburst
;
672 if (mids
->cfg_mode
== LNW_DMA_MEM_TO_MEM
) {
673 ctl_lo
.ctlx
.tt_fc
= 0;
674 ctl_lo
.ctlx
.sinc
= 0;
675 ctl_lo
.ctlx
.dinc
= 0;
677 if (mids
->dma_slave
.direction
== DMA_TO_DEVICE
) {
678 ctl_lo
.ctlx
.sinc
= 0;
679 ctl_lo
.ctlx
.dinc
= 2;
680 ctl_lo
.ctlx
.tt_fc
= 1;
681 } else if (mids
->dma_slave
.direction
== DMA_FROM_DEVICE
) {
682 ctl_lo
.ctlx
.sinc
= 2;
683 ctl_lo
.ctlx
.dinc
= 0;
684 ctl_lo
.ctlx
.tt_fc
= 2;
688 pr_debug("MDMA:Calc CTL LO %x, CTL HI %x, CFG LO %x, CFG HI %x\n",
689 ctl_lo
.ctl_lo
, ctl_hi
.ctl_hi
, cfg_lo
.cfg_lo
, cfg_hi
.cfg_hi
);
691 enable_dma_interrupt(midc
);
693 desc
= midc_desc_get(midc
);
699 desc
->cfg_hi
= cfg_hi
.cfg_hi
;
700 desc
->cfg_lo
= cfg_lo
.cfg_lo
;
701 desc
->ctl_lo
= ctl_lo
.ctl_lo
;
702 desc
->ctl_hi
= ctl_hi
.ctl_hi
;
704 desc
->dirn
= mids
->dma_slave
.direction
;
707 desc
->lli_pool
= NULL
;
711 pr_err("ERR_MDMA: Failed to get desc\n");
712 midc_desc_put(midc
, desc
);
716 * intel_mid_dma_prep_slave_sg - Prep slave sg txn
717 * @chan: chan for DMA transfer
718 * @sgl: scatter gather list
719 * @sg_len: length of sg txn
720 * @direction: DMA transfer dirtn
723 * Prepares LLI based periphral transfer
725 static struct dma_async_tx_descriptor
*intel_mid_dma_prep_slave_sg(
726 struct dma_chan
*chan
, struct scatterlist
*sgl
,
727 unsigned int sg_len
, enum dma_data_direction direction
,
730 struct intel_mid_dma_chan
*midc
= NULL
;
731 struct intel_mid_dma_slave
*mids
= NULL
;
732 struct intel_mid_dma_desc
*desc
= NULL
;
733 struct dma_async_tx_descriptor
*txd
= NULL
;
734 union intel_mid_dma_ctl_lo ctl_lo
;
736 pr_debug("MDMA: Prep for slave SG\n");
739 pr_err("MDMA: Invalid SG length\n");
742 midc
= to_intel_mid_dma_chan(chan
);
745 mids
= midc
->mid_slave
;
748 if (!midc
->dma
->pimr_mask
) {
749 pr_debug("MDMA: SG list is not supported by this controller\n");
753 pr_debug("MDMA: SG Length = %d, direction = %d, Flags = %#lx\n",
754 sg_len
, direction
, flags
);
756 txd
= intel_mid_dma_prep_memcpy(chan
, 0, 0, sgl
->length
, flags
);
758 pr_err("MDMA: Prep memcpy failed\n");
761 desc
= to_intel_mid_dma_desc(txd
);
762 desc
->dirn
= direction
;
763 ctl_lo
.ctl_lo
= desc
->ctl_lo
;
764 ctl_lo
.ctlx
.llp_dst_en
= 1;
765 ctl_lo
.ctlx
.llp_src_en
= 1;
766 desc
->ctl_lo
= ctl_lo
.ctl_lo
;
767 desc
->lli_length
= sg_len
;
768 desc
->current_lli
= 0;
769 /* DMA coherent memory pool for LLI descriptors*/
770 desc
->lli_pool
= pci_pool_create("intel_mid_dma_lli_pool",
772 (sizeof(struct intel_mid_dma_lli
)*sg_len
),
774 if (NULL
== desc
->lli_pool
) {
775 pr_err("MID_DMA:LLI pool create failed\n");
779 desc
->lli
= pci_pool_alloc(desc
->lli_pool
, GFP_KERNEL
, &desc
->lli_phys
);
781 pr_err("MID_DMA: LLI alloc failed\n");
782 pci_pool_destroy(desc
->lli_pool
);
786 midc_lli_fill_sg(midc
, desc
, sgl
, sg_len
, flags
);
787 if (flags
& DMA_PREP_INTERRUPT
) {
788 iowrite32(UNMASK_INTR_REG(midc
->ch_id
),
789 midc
->dma_base
+ MASK_BLOCK
);
790 pr_debug("MDMA:Enabled Block interrupt\n");
796 * intel_mid_dma_free_chan_resources - Frees dma resources
797 * @chan: chan requiring attention
799 * Frees the allocated resources on this DMA chan
801 static void intel_mid_dma_free_chan_resources(struct dma_chan
*chan
)
803 struct intel_mid_dma_chan
*midc
= to_intel_mid_dma_chan(chan
);
804 struct middma_device
*mid
= to_middma_device(chan
->device
);
805 struct intel_mid_dma_desc
*desc
, *_desc
;
807 if (true == midc
->busy
) {
808 /*trying to free ch in use!!!!!*/
809 pr_err("ERR_MDMA: trying to free ch in use\n");
811 pm_runtime_put(&mid
->pdev
->dev
);
812 spin_lock_bh(&midc
->lock
);
813 midc
->descs_allocated
= 0;
814 list_for_each_entry_safe(desc
, _desc
, &midc
->active_list
, desc_node
) {
815 list_del(&desc
->desc_node
);
816 pci_pool_free(mid
->dma_pool
, desc
, desc
->txd
.phys
);
818 list_for_each_entry_safe(desc
, _desc
, &midc
->free_list
, desc_node
) {
819 list_del(&desc
->desc_node
);
820 pci_pool_free(mid
->dma_pool
, desc
, desc
->txd
.phys
);
822 list_for_each_entry_safe(desc
, _desc
, &midc
->queue
, desc_node
) {
823 list_del(&desc
->desc_node
);
824 pci_pool_free(mid
->dma_pool
, desc
, desc
->txd
.phys
);
826 spin_unlock_bh(&midc
->lock
);
827 midc
->in_use
= false;
829 /* Disable CH interrupts */
830 iowrite32(MASK_INTR_REG(midc
->ch_id
), mid
->dma_base
+ MASK_BLOCK
);
831 iowrite32(MASK_INTR_REG(midc
->ch_id
), mid
->dma_base
+ MASK_ERR
);
835 * intel_mid_dma_alloc_chan_resources - Allocate dma resources
836 * @chan: chan requiring attention
838 * Allocates DMA resources on this chan
839 * Return the descriptors allocated
841 static int intel_mid_dma_alloc_chan_resources(struct dma_chan
*chan
)
843 struct intel_mid_dma_chan
*midc
= to_intel_mid_dma_chan(chan
);
844 struct middma_device
*mid
= to_middma_device(chan
->device
);
845 struct intel_mid_dma_desc
*desc
;
849 pm_runtime_get_sync(&mid
->pdev
->dev
);
851 if (mid
->state
== SUSPENDED
) {
852 if (dma_resume(mid
->pdev
)) {
853 pr_err("ERR_MDMA: resume failed");
858 /* ASSERT: channel is idle */
859 if (test_ch_en(mid
->dma_base
, midc
->ch_id
)) {
861 pr_err("ERR_MDMA: ch not idle\n");
862 pm_runtime_put(&mid
->pdev
->dev
);
865 midc
->completed
= chan
->cookie
= 1;
867 spin_lock_bh(&midc
->lock
);
868 while (midc
->descs_allocated
< DESCS_PER_CHANNEL
) {
869 spin_unlock_bh(&midc
->lock
);
870 desc
= pci_pool_alloc(mid
->dma_pool
, GFP_KERNEL
, &phys
);
872 pr_err("ERR_MDMA: desc failed\n");
873 pm_runtime_put(&mid
->pdev
->dev
);
877 dma_async_tx_descriptor_init(&desc
->txd
, chan
);
878 desc
->txd
.tx_submit
= intel_mid_dma_tx_submit
;
879 desc
->txd
.flags
= DMA_CTRL_ACK
;
880 desc
->txd
.phys
= phys
;
881 spin_lock_bh(&midc
->lock
);
882 i
= ++midc
->descs_allocated
;
883 list_add_tail(&desc
->desc_node
, &midc
->free_list
);
885 spin_unlock_bh(&midc
->lock
);
888 pr_debug("MID_DMA: Desc alloc done ret: %d desc\n", i
);
893 * midc_handle_error - Handle DMA txn error
894 * @mid: controller where error occured
895 * @midc: chan where error occured
897 * Scan the descriptor for error
899 static void midc_handle_error(struct middma_device
*mid
,
900 struct intel_mid_dma_chan
*midc
)
902 midc_scan_descriptors(mid
, midc
);
906 * dma_tasklet - DMA interrupt tasklet
907 * @data: tasklet arg (the controller structure)
909 * Scan the controller for interrupts for completion/error
910 * Clear the interrupt and call for handling completion/error
912 static void dma_tasklet(unsigned long data
)
914 struct middma_device
*mid
= NULL
;
915 struct intel_mid_dma_chan
*midc
= NULL
;
916 u32 status
, raw_tfr
, raw_block
;
919 mid
= (struct middma_device
*)data
;
921 pr_err("ERR_MDMA: tasklet Null param\n");
924 pr_debug("MDMA: in tasklet for device %x\n", mid
->pci_id
);
925 raw_tfr
= ioread32(mid
->dma_base
+ RAW_TFR
);
926 raw_block
= ioread32(mid
->dma_base
+ RAW_BLOCK
);
927 status
= raw_tfr
| raw_block
;
928 status
&= mid
->intr_mask
;
931 i
= get_ch_index(&status
, mid
->chan_base
);
933 pr_err("ERR_MDMA:Invalid ch index %x\n", i
);
938 pr_err("ERR_MDMA:Null param midc\n");
941 pr_debug("MDMA:Tx complete interrupt %x, Ch No %d Index %d\n",
942 status
, midc
->ch_id
, i
);
943 midc
->raw_tfr
= raw_tfr
;
944 midc
->raw_block
= raw_block
;
945 spin_lock_bh(&midc
->lock
);
946 /*clearing this interrupts first*/
947 iowrite32((1 << midc
->ch_id
), mid
->dma_base
+ CLEAR_TFR
);
949 iowrite32((1 << midc
->ch_id
),
950 mid
->dma_base
+ CLEAR_BLOCK
);
952 midc_scan_descriptors(mid
, midc
);
953 pr_debug("MDMA:Scan of desc... complete, unmasking\n");
954 iowrite32(UNMASK_INTR_REG(midc
->ch_id
),
955 mid
->dma_base
+ MASK_TFR
);
957 iowrite32(UNMASK_INTR_REG(midc
->ch_id
),
958 mid
->dma_base
+ MASK_BLOCK
);
960 spin_unlock_bh(&midc
->lock
);
963 status
= ioread32(mid
->dma_base
+ RAW_ERR
);
964 status
&= mid
->intr_mask
;
967 i
= get_ch_index(&status
, mid
->chan_base
);
969 pr_err("ERR_MDMA:Invalid ch index %x\n", i
);
974 pr_err("ERR_MDMA:Null param midc\n");
977 pr_debug("MDMA:Tx complete interrupt %x, Ch No %d Index %d\n",
978 status
, midc
->ch_id
, i
);
980 iowrite32((1 << midc
->ch_id
), mid
->dma_base
+ CLEAR_ERR
);
981 spin_lock_bh(&midc
->lock
);
982 midc_handle_error(mid
, midc
);
983 iowrite32(UNMASK_INTR_REG(midc
->ch_id
),
984 mid
->dma_base
+ MASK_ERR
);
985 spin_unlock_bh(&midc
->lock
);
987 pr_debug("MDMA:Exiting takslet...\n");
991 static void dma_tasklet1(unsigned long data
)
993 pr_debug("MDMA:in takslet1...\n");
994 return dma_tasklet(data
);
997 static void dma_tasklet2(unsigned long data
)
999 pr_debug("MDMA:in takslet2...\n");
1000 return dma_tasklet(data
);
1004 * intel_mid_dma_interrupt - DMA ISR
1005 * @irq: IRQ where interrupt occurred
1006 * @data: ISR cllback data (the controller structure)
1008 * See if this is our interrupt if so then schedule the tasklet
1011 static irqreturn_t
intel_mid_dma_interrupt(int irq
, void *data
)
1013 struct middma_device
*mid
= data
;
1014 u32 tfr_status
, err_status
;
1015 int call_tasklet
= 0;
1017 tfr_status
= ioread32(mid
->dma_base
+ RAW_TFR
);
1018 err_status
= ioread32(mid
->dma_base
+ RAW_ERR
);
1019 if (!tfr_status
&& !err_status
)
1023 pr_debug("MDMA:Got an interrupt on irq %d\n", irq
);
1025 pr_err("ERR_MDMA:null pointer mid\n");
1029 pr_debug("MDMA: Status %x, Mask %x\n", tfr_status
, mid
->intr_mask
);
1030 tfr_status
&= mid
->intr_mask
;
1032 /*need to disable intr*/
1033 iowrite32((tfr_status
<< INT_MASK_WE
), mid
->dma_base
+ MASK_TFR
);
1034 iowrite32((tfr_status
<< INT_MASK_WE
), mid
->dma_base
+ MASK_BLOCK
);
1035 pr_debug("MDMA: Calling tasklet %x\n", tfr_status
);
1038 err_status
&= mid
->intr_mask
;
1040 iowrite32(MASK_INTR_REG(err_status
), mid
->dma_base
+ MASK_ERR
);
1044 tasklet_schedule(&mid
->tasklet
);
1049 static irqreturn_t
intel_mid_dma_interrupt1(int irq
, void *data
)
1051 return intel_mid_dma_interrupt(irq
, data
);
1054 static irqreturn_t
intel_mid_dma_interrupt2(int irq
, void *data
)
1056 return intel_mid_dma_interrupt(irq
, data
);
1060 * mid_setup_dma - Setup the DMA controller
1061 * @pdev: Controller PCI device structure
1063 * Initilize the DMA controller, channels, registers with DMA engine,
1064 * ISR. Initilize DMA controller channels.
1066 static int mid_setup_dma(struct pci_dev
*pdev
)
1068 struct middma_device
*dma
= pci_get_drvdata(pdev
);
1071 /* DMA coherent memory pool for DMA descriptor allocations */
1072 dma
->dma_pool
= pci_pool_create("intel_mid_dma_desc_pool", pdev
,
1073 sizeof(struct intel_mid_dma_desc
),
1075 if (NULL
== dma
->dma_pool
) {
1076 pr_err("ERR_MDMA:pci_pool_create failed\n");
1082 INIT_LIST_HEAD(&dma
->common
.channels
);
1083 dma
->pci_id
= pdev
->device
;
1084 if (dma
->pimr_mask
) {
1085 dma
->mask_reg
= ioremap(LNW_PERIPHRAL_MASK_BASE
,
1086 LNW_PERIPHRAL_MASK_SIZE
);
1087 if (dma
->mask_reg
== NULL
) {
1088 pr_err("ERR_MDMA:Cant map periphral intr space !!\n");
1092 dma
->mask_reg
= NULL
;
1094 pr_debug("MDMA:Adding %d channel for this controller\n", dma
->max_chan
);
1095 /*init CH structures*/
1097 dma
->state
= RUNNING
;
1098 for (i
= 0; i
< dma
->max_chan
; i
++) {
1099 struct intel_mid_dma_chan
*midch
= &dma
->ch
[i
];
1101 midch
->chan
.device
= &dma
->common
;
1102 midch
->chan
.cookie
= 1;
1103 midch
->chan
.chan_id
= i
;
1104 midch
->ch_id
= dma
->chan_base
+ i
;
1105 pr_debug("MDMA:Init CH %d, ID %d\n", i
, midch
->ch_id
);
1107 midch
->dma_base
= dma
->dma_base
;
1108 midch
->ch_regs
= dma
->dma_base
+ DMA_CH_SIZE
* midch
->ch_id
;
1110 dma
->intr_mask
|= 1 << (dma
->chan_base
+ i
);
1111 spin_lock_init(&midch
->lock
);
1113 INIT_LIST_HEAD(&midch
->active_list
);
1114 INIT_LIST_HEAD(&midch
->queue
);
1115 INIT_LIST_HEAD(&midch
->free_list
);
1117 iowrite32(MASK_INTR_REG(midch
->ch_id
),
1118 dma
->dma_base
+ MASK_BLOCK
);
1119 iowrite32(MASK_INTR_REG(midch
->ch_id
),
1120 dma
->dma_base
+ MASK_SRC_TRAN
);
1121 iowrite32(MASK_INTR_REG(midch
->ch_id
),
1122 dma
->dma_base
+ MASK_DST_TRAN
);
1123 iowrite32(MASK_INTR_REG(midch
->ch_id
),
1124 dma
->dma_base
+ MASK_ERR
);
1125 iowrite32(MASK_INTR_REG(midch
->ch_id
),
1126 dma
->dma_base
+ MASK_TFR
);
1128 disable_dma_interrupt(midch
);
1129 list_add_tail(&midch
->chan
.device_node
, &dma
->common
.channels
);
1131 pr_debug("MDMA: Calc Mask as %x for this controller\n", dma
->intr_mask
);
1133 /*init dma structure*/
1134 dma_cap_zero(dma
->common
.cap_mask
);
1135 dma_cap_set(DMA_MEMCPY
, dma
->common
.cap_mask
);
1136 dma_cap_set(DMA_SLAVE
, dma
->common
.cap_mask
);
1137 dma_cap_set(DMA_PRIVATE
, dma
->common
.cap_mask
);
1138 dma
->common
.dev
= &pdev
->dev
;
1139 dma
->common
.chancnt
= dma
->max_chan
;
1141 dma
->common
.device_alloc_chan_resources
=
1142 intel_mid_dma_alloc_chan_resources
;
1143 dma
->common
.device_free_chan_resources
=
1144 intel_mid_dma_free_chan_resources
;
1146 dma
->common
.device_tx_status
= intel_mid_dma_tx_status
;
1147 dma
->common
.device_prep_dma_memcpy
= intel_mid_dma_prep_memcpy
;
1148 dma
->common
.device_issue_pending
= intel_mid_dma_issue_pending
;
1149 dma
->common
.device_prep_slave_sg
= intel_mid_dma_prep_slave_sg
;
1150 dma
->common
.device_control
= intel_mid_dma_device_control
;
1152 /*enable dma cntrl*/
1153 iowrite32(REG_BIT0
, dma
->dma_base
+ DMA_CFG
);
1156 if (dma
->pimr_mask
) {
1157 pr_debug("MDMA:Requesting irq shared for DMAC1\n");
1158 err
= request_irq(pdev
->irq
, intel_mid_dma_interrupt1
,
1159 IRQF_SHARED
, "INTEL_MID_DMAC1", dma
);
1163 dma
->intr_mask
= 0x03;
1164 pr_debug("MDMA:Requesting irq for DMAC2\n");
1165 err
= request_irq(pdev
->irq
, intel_mid_dma_interrupt2
,
1166 IRQF_SHARED
, "INTEL_MID_DMAC2", dma
);
1170 /*register device w/ engine*/
1171 err
= dma_async_device_register(&dma
->common
);
1173 pr_err("ERR_MDMA:device_register failed: %d\n", err
);
1176 if (dma
->pimr_mask
) {
1177 pr_debug("setting up tasklet1 for DMAC1\n");
1178 tasklet_init(&dma
->tasklet
, dma_tasklet1
, (unsigned long)dma
);
1180 pr_debug("setting up tasklet2 for DMAC2\n");
1181 tasklet_init(&dma
->tasklet
, dma_tasklet2
, (unsigned long)dma
);
1186 free_irq(pdev
->irq
, dma
);
1188 pci_pool_destroy(dma
->dma_pool
);
1191 pr_err("ERR_MDMA:setup_dma failed: %d\n", err
);
1197 * middma_shutdown - Shutdown the DMA controller
1198 * @pdev: Controller PCI device structure
1201 * Unregister DMa controller, clear all structures and free interrupt
1203 static void middma_shutdown(struct pci_dev
*pdev
)
1205 struct middma_device
*device
= pci_get_drvdata(pdev
);
1207 dma_async_device_unregister(&device
->common
);
1208 pci_pool_destroy(device
->dma_pool
);
1209 if (device
->mask_reg
)
1210 iounmap(device
->mask_reg
);
1211 if (device
->dma_base
)
1212 iounmap(device
->dma_base
);
1213 free_irq(pdev
->irq
, device
);
1218 * intel_mid_dma_probe - PCI Probe
1219 * @pdev: Controller PCI device structure
1220 * @id: pci device id structure
1222 * Initilize the PCI device, map BARs, query driver data.
1223 * Call setup_dma to complete contoller and chan initilzation
1225 static int __devinit
intel_mid_dma_probe(struct pci_dev
*pdev
,
1226 const struct pci_device_id
*id
)
1228 struct middma_device
*device
;
1229 u32 base_addr
, bar_size
;
1230 struct intel_mid_dma_probe_info
*info
;
1233 pr_debug("MDMA: probe for %x\n", pdev
->device
);
1234 info
= (void *)id
->driver_data
;
1235 pr_debug("MDMA: CH %d, base %d, block len %d, Periphral mask %x\n",
1236 info
->max_chan
, info
->ch_base
,
1237 info
->block_size
, info
->pimr_mask
);
1239 err
= pci_enable_device(pdev
);
1241 goto err_enable_device
;
1243 err
= pci_request_regions(pdev
, "intel_mid_dmac");
1245 goto err_request_regions
;
1247 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
1249 goto err_set_dma_mask
;
1251 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
1253 goto err_set_dma_mask
;
1255 device
= kzalloc(sizeof(*device
), GFP_KERNEL
);
1257 pr_err("ERR_MDMA:kzalloc failed probe\n");
1261 device
->pdev
= pci_dev_get(pdev
);
1263 base_addr
= pci_resource_start(pdev
, 0);
1264 bar_size
= pci_resource_len(pdev
, 0);
1265 device
->dma_base
= ioremap_nocache(base_addr
, DMA_REG_SIZE
);
1266 if (!device
->dma_base
) {
1267 pr_err("ERR_MDMA:ioremap failed\n");
1271 pci_set_drvdata(pdev
, device
);
1272 pci_set_master(pdev
);
1273 device
->max_chan
= info
->max_chan
;
1274 device
->chan_base
= info
->ch_base
;
1275 device
->block_size
= info
->block_size
;
1276 device
->pimr_mask
= info
->pimr_mask
;
1278 err
= mid_setup_dma(pdev
);
1282 pm_runtime_set_active(&pdev
->dev
);
1283 pm_runtime_enable(&pdev
->dev
);
1284 pm_runtime_allow(&pdev
->dev
);
1288 iounmap(device
->dma_base
);
1294 pci_release_regions(pdev
);
1295 pci_disable_device(pdev
);
1296 err_request_regions
:
1298 pr_err("ERR_MDMA:Probe failed %d\n", err
);
1303 * intel_mid_dma_remove - PCI remove
1304 * @pdev: Controller PCI device structure
1306 * Free up all resources and data
1307 * Call shutdown_dma to complete contoller and chan cleanup
1309 static void __devexit
intel_mid_dma_remove(struct pci_dev
*pdev
)
1311 struct middma_device
*device
= pci_get_drvdata(pdev
);
1312 middma_shutdown(pdev
);
1315 pci_release_regions(pdev
);
1316 pci_disable_device(pdev
);
1319 /* Power Management */
1321 * dma_suspend - PCI suspend function
1323 * @pci: PCI device structure
1324 * @state: PM message
1326 * This function is called by OS when a power event occurs
1328 int dma_suspend(struct pci_dev
*pci
, pm_message_t state
)
1331 struct middma_device
*device
= pci_get_drvdata(pci
);
1332 pr_debug("MDMA: dma_suspend called\n");
1334 for (i
= 0; i
< device
->max_chan
; i
++) {
1335 if (device
->ch
[i
].in_use
)
1338 device
->state
= SUSPENDED
;
1339 pci_set_drvdata(pci
, device
);
1340 pci_save_state(pci
);
1341 pci_disable_device(pci
);
1342 pci_set_power_state(pci
, PCI_D3hot
);
1347 * dma_resume - PCI resume function
1349 * @pci: PCI device structure
1351 * This function is called by OS when a power event occurs
1353 int dma_resume(struct pci_dev
*pci
)
1356 struct middma_device
*device
= pci_get_drvdata(pci
);
1358 pr_debug("MDMA: dma_resume called\n");
1359 pci_set_power_state(pci
, PCI_D0
);
1360 pci_restore_state(pci
);
1361 ret
= pci_enable_device(pci
);
1363 pr_err("MDMA: device cant be enabled for %x\n", pci
->device
);
1366 device
->state
= RUNNING
;
1367 iowrite32(REG_BIT0
, device
->dma_base
+ DMA_CFG
);
1368 pci_set_drvdata(pci
, device
);
1372 static int dma_runtime_suspend(struct device
*dev
)
1374 struct pci_dev
*pci_dev
= to_pci_dev(dev
);
1375 return dma_suspend(pci_dev
, PMSG_SUSPEND
);
1378 static int dma_runtime_resume(struct device
*dev
)
1380 struct pci_dev
*pci_dev
= to_pci_dev(dev
);
1381 return dma_resume(pci_dev
);
1384 static int dma_runtime_idle(struct device
*dev
)
1386 struct pci_dev
*pdev
= to_pci_dev(dev
);
1387 struct middma_device
*device
= pci_get_drvdata(pdev
);
1390 for (i
= 0; i
< device
->max_chan
; i
++) {
1391 if (device
->ch
[i
].in_use
)
1395 return pm_schedule_suspend(dev
, 0);
1398 /******************************************************************************
1401 static struct pci_device_id intel_mid_dma_ids
[] = {
1402 { PCI_VDEVICE(INTEL
, INTEL_MID_DMAC1_ID
), INFO(2, 6, 4095, 0x200020)},
1403 { PCI_VDEVICE(INTEL
, INTEL_MID_DMAC2_ID
), INFO(2, 0, 2047, 0)},
1404 { PCI_VDEVICE(INTEL
, INTEL_MID_GP_DMAC2_ID
), INFO(2, 0, 2047, 0)},
1405 { PCI_VDEVICE(INTEL
, INTEL_MFLD_DMAC1_ID
), INFO(4, 0, 4095, 0x400040)},
1408 MODULE_DEVICE_TABLE(pci
, intel_mid_dma_ids
);
1410 static const struct dev_pm_ops intel_mid_dma_pm
= {
1411 .runtime_suspend
= dma_runtime_suspend
,
1412 .runtime_resume
= dma_runtime_resume
,
1413 .runtime_idle
= dma_runtime_idle
,
1416 static struct pci_driver intel_mid_dma_pci
= {
1417 .name
= "Intel MID DMA",
1418 .id_table
= intel_mid_dma_ids
,
1419 .probe
= intel_mid_dma_probe
,
1420 .remove
= __devexit_p(intel_mid_dma_remove
),
1422 .suspend
= dma_suspend
,
1423 .resume
= dma_resume
,
1425 .pm
= &intel_mid_dma_pm
,
1430 static int __init
intel_mid_dma_init(void)
1432 pr_debug("INFO_MDMA: LNW DMA Driver Version %s\n",
1433 INTEL_MID_DMA_DRIVER_VERSION
);
1434 return pci_register_driver(&intel_mid_dma_pci
);
1436 fs_initcall(intel_mid_dma_init
);
1438 static void __exit
intel_mid_dma_exit(void)
1440 pci_unregister_driver(&intel_mid_dma_pci
);
1442 module_exit(intel_mid_dma_exit
);
1444 MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
1445 MODULE_DESCRIPTION("Intel (R) MID DMAC Driver");
1446 MODULE_LICENSE("GPL v2");
1447 MODULE_VERSION(INTEL_MID_DMA_DRIVER_VERSION
);