Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Freescale Semiconductor, Inc. All rights reserved. |
| 3 | * |
| 4 | * Author: |
| 5 | * Zhang Wei <wei.zhang@freescale.com>, Jul 2007 |
| 6 | * Ebony Zhu <ebony.zhu@freescale.com>, May 2007 |
| 7 | * |
| 8 | * This is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | */ |
| 14 | #ifndef __DMA_FSLDMA_H |
| 15 | #define __DMA_FSLDMA_H |
| 16 | |
| 17 | #include <linux/device.h> |
| 18 | #include <linux/dmapool.h> |
| 19 | #include <linux/dmaengine.h> |
| 20 | |
| 21 | /* Define data structures needed by Freescale |
| 22 | * MPC8540 and MPC8349 DMA controller. |
| 23 | */ |
| 24 | #define FSL_DMA_MR_CS 0x00000001 |
| 25 | #define FSL_DMA_MR_CC 0x00000002 |
| 26 | #define FSL_DMA_MR_CA 0x00000008 |
| 27 | #define FSL_DMA_MR_EIE 0x00000040 |
| 28 | #define FSL_DMA_MR_XFE 0x00000020 |
| 29 | #define FSL_DMA_MR_EOLNIE 0x00000100 |
| 30 | #define FSL_DMA_MR_EOLSIE 0x00000080 |
| 31 | #define FSL_DMA_MR_EOSIE 0x00000200 |
| 32 | #define FSL_DMA_MR_CDSM 0x00000010 |
| 33 | #define FSL_DMA_MR_CTM 0x00000004 |
| 34 | #define FSL_DMA_MR_EMP_EN 0x00200000 |
| 35 | #define FSL_DMA_MR_EMS_EN 0x00040000 |
| 36 | #define FSL_DMA_MR_DAHE 0x00002000 |
| 37 | #define FSL_DMA_MR_SAHE 0x00001000 |
| 38 | |
| 39 | /* Special MR definition for MPC8349 */ |
| 40 | #define FSL_DMA_MR_EOTIE 0x00000080 |
Ira W. Snyder | a7aea37 | 2009-04-23 16:17:54 -0700 | [diff] [blame] | 41 | #define FSL_DMA_MR_PRC_RM 0x00000800 |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 42 | |
| 43 | #define FSL_DMA_SR_CH 0x00000020 |
Zhang Wei | f79abb6 | 2008-03-18 18:45:00 -0700 | [diff] [blame] | 44 | #define FSL_DMA_SR_PE 0x00000010 |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 45 | #define FSL_DMA_SR_CB 0x00000004 |
| 46 | #define FSL_DMA_SR_TE 0x00000080 |
| 47 | #define FSL_DMA_SR_EOSI 0x00000002 |
| 48 | #define FSL_DMA_SR_EOLSI 0x00000001 |
| 49 | #define FSL_DMA_SR_EOCDI 0x00000001 |
| 50 | #define FSL_DMA_SR_EOLNI 0x00000008 |
| 51 | |
| 52 | #define FSL_DMA_SATR_SBPATMU 0x20000000 |
| 53 | #define FSL_DMA_SATR_STRANSINT_RIO 0x00c00000 |
| 54 | #define FSL_DMA_SATR_SREADTYPE_SNOOP_READ 0x00050000 |
| 55 | #define FSL_DMA_SATR_SREADTYPE_BP_IORH 0x00020000 |
| 56 | #define FSL_DMA_SATR_SREADTYPE_BP_NREAD 0x00040000 |
| 57 | #define FSL_DMA_SATR_SREADTYPE_BP_MREAD 0x00070000 |
| 58 | |
| 59 | #define FSL_DMA_DATR_DBPATMU 0x20000000 |
| 60 | #define FSL_DMA_DATR_DTRANSINT_RIO 0x00c00000 |
| 61 | #define FSL_DMA_DATR_DWRITETYPE_SNOOP_WRITE 0x00050000 |
| 62 | #define FSL_DMA_DATR_DWRITETYPE_BP_FLUSH 0x00010000 |
| 63 | |
| 64 | #define FSL_DMA_EOL ((u64)0x1) |
| 65 | #define FSL_DMA_SNEN ((u64)0x10) |
| 66 | #define FSL_DMA_EOSIE 0x8 |
| 67 | #define FSL_DMA_NLDA_MASK (~(u64)0x1f) |
| 68 | |
| 69 | #define FSL_DMA_BCR_MAX_CNT 0x03ffffffu |
| 70 | |
| 71 | #define FSL_DMA_DGSR_TE 0x80 |
| 72 | #define FSL_DMA_DGSR_CH 0x20 |
| 73 | #define FSL_DMA_DGSR_PE 0x10 |
| 74 | #define FSL_DMA_DGSR_EOLNI 0x08 |
| 75 | #define FSL_DMA_DGSR_CB 0x04 |
| 76 | #define FSL_DMA_DGSR_EOSI 0x02 |
| 77 | #define FSL_DMA_DGSR_EOLSI 0x01 |
| 78 | |
Al Viro | a4e6d5d | 2008-03-29 03:10:18 +0000 | [diff] [blame] | 79 | typedef u64 __bitwise v64; |
| 80 | typedef u32 __bitwise v32; |
| 81 | |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 82 | struct fsl_dma_ld_hw { |
Al Viro | a4e6d5d | 2008-03-29 03:10:18 +0000 | [diff] [blame] | 83 | v64 src_addr; |
| 84 | v64 dst_addr; |
| 85 | v64 next_ln_addr; |
| 86 | v32 count; |
| 87 | v32 reserve; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 88 | } __attribute__((aligned(32))); |
| 89 | |
| 90 | struct fsl_desc_sw { |
| 91 | struct fsl_dma_ld_hw hw; |
| 92 | struct list_head node; |
Dan Williams | eda3423 | 2009-09-08 17:53:02 -0700 | [diff] [blame] | 93 | struct list_head tx_list; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 94 | struct dma_async_tx_descriptor async_tx; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 95 | } __attribute__((aligned(32))); |
| 96 | |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 97 | struct fsldma_chan_regs { |
Al Viro | a4e6d5d | 2008-03-29 03:10:18 +0000 | [diff] [blame] | 98 | u32 mr; /* 0x00 - Mode Register */ |
| 99 | u32 sr; /* 0x04 - Status Register */ |
| 100 | u64 cdar; /* 0x08 - Current descriptor address register */ |
| 101 | u64 sar; /* 0x10 - Source Address Register */ |
| 102 | u64 dar; /* 0x18 - Destination Address Register */ |
| 103 | u32 bcr; /* 0x20 - Byte Count Register */ |
| 104 | u64 ndar; /* 0x24 - Next Descriptor Address Register */ |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 107 | struct fsldma_chan; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 108 | #define FSL_DMA_MAX_CHANS_PER_DEVICE 4 |
| 109 | |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 110 | struct fsldma_device { |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 111 | void __iomem *reg_base; /* DGSR register base */ |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 112 | struct device *dev; |
| 113 | struct dma_device common; |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 114 | struct fsldma_chan *chan[FSL_DMA_MAX_CHANS_PER_DEVICE]; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 115 | u32 feature; /* The same as DMA channels */ |
Timur Tabi | 77cd62e | 2008-09-26 17:00:11 -0700 | [diff] [blame] | 116 | int irq; /* Channel IRQ */ |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 119 | /* Define macros for fsldma_chan->feature property */ |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 120 | #define FSL_DMA_LITTLE_ENDIAN 0x00000000 |
| 121 | #define FSL_DMA_BIG_ENDIAN 0x00000001 |
| 122 | |
| 123 | #define FSL_DMA_IP_MASK 0x00000ff0 |
| 124 | #define FSL_DMA_IP_85XX 0x00000010 |
| 125 | #define FSL_DMA_IP_83XX 0x00000020 |
| 126 | |
| 127 | #define FSL_DMA_CHAN_PAUSE_EXT 0x00001000 |
| 128 | #define FSL_DMA_CHAN_START_EXT 0x00002000 |
| 129 | |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 130 | struct fsldma_chan { |
| 131 | struct fsldma_chan_regs __iomem *reg_base; |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 132 | dma_cookie_t completed_cookie; /* The maximum cookie completed */ |
| 133 | spinlock_t desc_lock; /* Descriptor operation lock */ |
| 134 | struct list_head ld_queue; /* Link descriptors queue */ |
| 135 | struct dma_chan common; /* DMA common channel */ |
| 136 | struct dma_pool *desc_pool; /* Descriptors pool */ |
| 137 | struct device *dev; /* Channel device */ |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 138 | int irq; /* Channel IRQ */ |
| 139 | int id; /* Raw id of this channel */ |
| 140 | struct tasklet_struct tasklet; |
| 141 | u32 feature; |
| 142 | |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 143 | void (*toggle_ext_pause)(struct fsldma_chan *fsl_chan, int enable); |
| 144 | void (*toggle_ext_start)(struct fsldma_chan *fsl_chan, int enable); |
| 145 | void (*set_src_loop_size)(struct fsldma_chan *fsl_chan, int size); |
Ira Snyder | 738f5f7 | 2010-01-06 13:34:02 +0000 | [diff] [blame^] | 146 | void (*set_dst_loop_size)(struct fsldma_chan *fsl_chan, int size); |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 147 | void (*set_request_count)(struct fsldma_chan *fsl_chan, int size); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 148 | }; |
| 149 | |
Ira Snyder | a4f56d4 | 2010-01-06 13:34:01 +0000 | [diff] [blame] | 150 | #define to_fsl_chan(chan) container_of(chan, struct fsldma_chan, common) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 151 | #define to_fsl_desc(lh) container_of(lh, struct fsl_desc_sw, node) |
| 152 | #define tx_to_fsl_desc(tx) container_of(tx, struct fsl_desc_sw, async_tx) |
| 153 | |
| 154 | #ifndef __powerpc64__ |
| 155 | static u64 in_be64(const u64 __iomem *addr) |
| 156 | { |
Al Viro | a4e6d5d | 2008-03-29 03:10:18 +0000 | [diff] [blame] | 157 | return ((u64)in_be32((u32 __iomem *)addr) << 32) | |
| 158 | (in_be32((u32 __iomem *)addr + 1)); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static void out_be64(u64 __iomem *addr, u64 val) |
| 162 | { |
Al Viro | a4e6d5d | 2008-03-29 03:10:18 +0000 | [diff] [blame] | 163 | out_be32((u32 __iomem *)addr, val >> 32); |
| 164 | out_be32((u32 __iomem *)addr + 1, (u32)val); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /* There is no asm instructions for 64 bits reverse loads and stores */ |
| 168 | static u64 in_le64(const u64 __iomem *addr) |
| 169 | { |
Al Viro | a4e6d5d | 2008-03-29 03:10:18 +0000 | [diff] [blame] | 170 | return ((u64)in_le32((u32 __iomem *)addr + 1) << 32) | |
| 171 | (in_le32((u32 __iomem *)addr)); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static void out_le64(u64 __iomem *addr, u64 val) |
| 175 | { |
Al Viro | a4e6d5d | 2008-03-29 03:10:18 +0000 | [diff] [blame] | 176 | out_le32((u32 __iomem *)addr + 1, val >> 32); |
| 177 | out_le32((u32 __iomem *)addr, (u32)val); |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 178 | } |
| 179 | #endif |
| 180 | |
| 181 | #define DMA_IN(fsl_chan, addr, width) \ |
| 182 | (((fsl_chan)->feature & FSL_DMA_BIG_ENDIAN) ? \ |
| 183 | in_be##width(addr) : in_le##width(addr)) |
| 184 | #define DMA_OUT(fsl_chan, addr, val, width) \ |
| 185 | (((fsl_chan)->feature & FSL_DMA_BIG_ENDIAN) ? \ |
| 186 | out_be##width(addr, val) : out_le##width(addr, val)) |
| 187 | |
| 188 | #define DMA_TO_CPU(fsl_chan, d, width) \ |
| 189 | (((fsl_chan)->feature & FSL_DMA_BIG_ENDIAN) ? \ |
Al Viro | a4e6d5d | 2008-03-29 03:10:18 +0000 | [diff] [blame] | 190 | be##width##_to_cpu((__force __be##width)(v##width)d) : \ |
| 191 | le##width##_to_cpu((__force __le##width)(v##width)d)) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 192 | #define CPU_TO_DMA(fsl_chan, c, width) \ |
| 193 | (((fsl_chan)->feature & FSL_DMA_BIG_ENDIAN) ? \ |
Al Viro | a4e6d5d | 2008-03-29 03:10:18 +0000 | [diff] [blame] | 194 | (__force v##width)cpu_to_be##width(c) : \ |
| 195 | (__force v##width)cpu_to_le##width(c)) |
Zhang Wei | 173acc7 | 2008-03-01 07:42:48 -0700 | [diff] [blame] | 196 | |
| 197 | #endif /* __DMA_FSLDMA_H */ |