diff options
27 files changed, 947 insertions, 527 deletions
diff --git a/Documentation/devicetree/bindings/dma/brcm,bcm2835-dma.txt b/Documentation/devicetree/bindings/dma/brcm,bcm2835-dma.txt index 1396078d15ac..baf9b34d20bf 100644 --- a/Documentation/devicetree/bindings/dma/brcm,bcm2835-dma.txt +++ b/Documentation/devicetree/bindings/dma/brcm,bcm2835-dma.txt | |||
@@ -12,6 +12,10 @@ Required properties: | |||
12 | - reg: Should contain DMA registers location and length. | 12 | - reg: Should contain DMA registers location and length. |
13 | - interrupts: Should contain the DMA interrupts associated | 13 | - interrupts: Should contain the DMA interrupts associated |
14 | to the DMA channels in ascending order. | 14 | to the DMA channels in ascending order. |
15 | - interrupt-names: Should contain the names of the interrupt | ||
16 | in the form "dmaXX". | ||
17 | Use "dma-shared-all" for the common interrupt line | ||
18 | that is shared by all dma channels. | ||
15 | - #dma-cells: Must be <1>, the cell in the dmas property of the | 19 | - #dma-cells: Must be <1>, the cell in the dmas property of the |
16 | client device represents the DREQ number. | 20 | client device represents the DREQ number. |
17 | - brcm,dma-channel-mask: Bit mask representing the channels | 21 | - brcm,dma-channel-mask: Bit mask representing the channels |
@@ -34,13 +38,35 @@ dma: dma@7e007000 { | |||
34 | <1 24>, | 38 | <1 24>, |
35 | <1 25>, | 39 | <1 25>, |
36 | <1 26>, | 40 | <1 26>, |
41 | /* dma channel 11-14 share one irq */ | ||
37 | <1 27>, | 42 | <1 27>, |
43 | <1 27>, | ||
44 | <1 27>, | ||
45 | <1 27>, | ||
46 | /* unused shared irq for all channels */ | ||
38 | <1 28>; | 47 | <1 28>; |
48 | interrupt-names = "dma0", | ||
49 | "dma1", | ||
50 | "dma2", | ||
51 | "dma3", | ||
52 | "dma4", | ||
53 | "dma5", | ||
54 | "dma6", | ||
55 | "dma7", | ||
56 | "dma8", | ||
57 | "dma9", | ||
58 | "dma10", | ||
59 | "dma11", | ||
60 | "dma12", | ||
61 | "dma13", | ||
62 | "dma14", | ||
63 | "dma-shared-all"; | ||
39 | 64 | ||
40 | #dma-cells = <1>; | 65 | #dma-cells = <1>; |
41 | brcm,dma-channel-mask = <0x7f35>; | 66 | brcm,dma-channel-mask = <0x7f35>; |
42 | }; | 67 | }; |
43 | 68 | ||
69 | |||
44 | DMA clients connected to the BCM2835 DMA controller must use the format | 70 | DMA clients connected to the BCM2835 DMA controller must use the format |
45 | described in the dma.txt file, using a two-cell specifier for each channel. | 71 | described in the dma.txt file, using a two-cell specifier for each channel. |
46 | 72 | ||
diff --git a/Documentation/devicetree/bindings/dma/snps-dma.txt b/Documentation/devicetree/bindings/dma/snps-dma.txt index c261598164a7..0f5583293c9c 100644 --- a/Documentation/devicetree/bindings/dma/snps-dma.txt +++ b/Documentation/devicetree/bindings/dma/snps-dma.txt | |||
@@ -13,6 +13,11 @@ Required properties: | |||
13 | - chan_priority: priority of channels. 0 (default): increase from chan 0->n, 1: | 13 | - chan_priority: priority of channels. 0 (default): increase from chan 0->n, 1: |
14 | increase from chan n->0 | 14 | increase from chan n->0 |
15 | - block_size: Maximum block size supported by the controller | 15 | - block_size: Maximum block size supported by the controller |
16 | - data-width: Maximum data width supported by hardware per AHB master | ||
17 | (in bytes, power of 2) | ||
18 | |||
19 | |||
20 | Deprecated properties: | ||
16 | - data_width: Maximum data width supported by hardware per AHB master | 21 | - data_width: Maximum data width supported by hardware per AHB master |
17 | (0 - 8bits, 1 - 16bits, ..., 5 - 256bits) | 22 | (0 - 8bits, 1 - 16bits, ..., 5 - 256bits) |
18 | 23 | ||
@@ -38,7 +43,7 @@ Example: | |||
38 | chan_allocation_order = <1>; | 43 | chan_allocation_order = <1>; |
39 | chan_priority = <1>; | 44 | chan_priority = <1>; |
40 | block_size = <0xfff>; | 45 | block_size = <0xfff>; |
41 | data_width = <3 3>; | 46 | data-width = <8 8>; |
42 | }; | 47 | }; |
43 | 48 | ||
44 | DMA clients connected to the Designware DMA controller must use the format | 49 | DMA clients connected to the Designware DMA controller must use the format |
@@ -47,8 +52,8 @@ The four cells in order are: | |||
47 | 52 | ||
48 | 1. A phandle pointing to the DMA controller | 53 | 1. A phandle pointing to the DMA controller |
49 | 2. The DMA request line number | 54 | 2. The DMA request line number |
50 | 3. Source master for transfers on allocated channel | 55 | 3. Memory master for transfers on allocated channel |
51 | 4. Destination master for transfers on allocated channel | 56 | 4. Peripheral master for transfers on allocated channel |
52 | 57 | ||
53 | Example: | 58 | Example: |
54 | 59 | ||
diff --git a/arch/arc/boot/dts/abilis_tb10x.dtsi b/arch/arc/boot/dts/abilis_tb10x.dtsi index cfb5052239a1..2f53bedb0cde 100644 --- a/arch/arc/boot/dts/abilis_tb10x.dtsi +++ b/arch/arc/boot/dts/abilis_tb10x.dtsi | |||
@@ -112,7 +112,7 @@ | |||
112 | chan_allocation_order = <0>; | 112 | chan_allocation_order = <0>; |
113 | chan_priority = <1>; | 113 | chan_priority = <1>; |
114 | block_size = <0x7ff>; | 114 | block_size = <0x7ff>; |
115 | data_width = <2>; | 115 | data-width = <4>; |
116 | clocks = <&ahb_clk>; | 116 | clocks = <&ahb_clk>; |
117 | clock-names = "hclk"; | 117 | clock-names = "hclk"; |
118 | }; | 118 | }; |
diff --git a/arch/arm/boot/dts/bcm283x.dtsi b/arch/arm/boot/dts/bcm283x.dtsi index 8aaf193711bf..84dcf3e5c8d9 100644 --- a/arch/arm/boot/dts/bcm283x.dtsi +++ b/arch/arm/boot/dts/bcm283x.dtsi | |||
@@ -47,9 +47,29 @@ | |||
47 | <1 24>, | 47 | <1 24>, |
48 | <1 25>, | 48 | <1 25>, |
49 | <1 26>, | 49 | <1 26>, |
50 | /* dma channel 11-14 share one irq */ | ||
50 | <1 27>, | 51 | <1 27>, |
52 | <1 27>, | ||
53 | <1 27>, | ||
54 | <1 27>, | ||
55 | /* unused shared irq for all channels */ | ||
51 | <1 28>; | 56 | <1 28>; |
52 | 57 | interrupt-names = "dma0", | |
58 | "dma1", | ||
59 | "dma2", | ||
60 | "dma3", | ||
61 | "dma4", | ||
62 | "dma5", | ||
63 | "dma6", | ||
64 | "dma7", | ||
65 | "dma8", | ||
66 | "dma9", | ||
67 | "dma10", | ||
68 | "dma11", | ||
69 | "dma12", | ||
70 | "dma13", | ||
71 | "dma14", | ||
72 | "dma-shared-all"; | ||
53 | #dma-cells = <1>; | 73 | #dma-cells = <1>; |
54 | brcm,dma-channel-mask = <0x7f35>; | 74 | brcm,dma-channel-mask = <0x7f35>; |
55 | }; | 75 | }; |
diff --git a/arch/arm/boot/dts/spear13xx.dtsi b/arch/arm/boot/dts/spear13xx.dtsi index 14594ce8c18a..449acf0d8272 100644 --- a/arch/arm/boot/dts/spear13xx.dtsi +++ b/arch/arm/boot/dts/spear13xx.dtsi | |||
@@ -117,7 +117,7 @@ | |||
117 | chan_priority = <1>; | 117 | chan_priority = <1>; |
118 | block_size = <0xfff>; | 118 | block_size = <0xfff>; |
119 | dma-masters = <2>; | 119 | dma-masters = <2>; |
120 | data_width = <3 3>; | 120 | data-width = <8 8>; |
121 | }; | 121 | }; |
122 | 122 | ||
123 | dma@eb000000 { | 123 | dma@eb000000 { |
@@ -133,7 +133,7 @@ | |||
133 | chan_allocation_order = <1>; | 133 | chan_allocation_order = <1>; |
134 | chan_priority = <1>; | 134 | chan_priority = <1>; |
135 | block_size = <0xfff>; | 135 | block_size = <0xfff>; |
136 | data_width = <3 3>; | 136 | data-width = <8 8>; |
137 | }; | 137 | }; |
138 | 138 | ||
139 | fsmc: flash@b0000000 { | 139 | fsmc: flash@b0000000 { |
diff --git a/arch/avr32/mach-at32ap/at32ap700x.c b/arch/avr32/mach-at32ap/at32ap700x.c index bf445aa48282..00d6dcc1d9b6 100644 --- a/arch/avr32/mach-at32ap/at32ap700x.c +++ b/arch/avr32/mach-at32ap/at32ap700x.c | |||
@@ -1365,8 +1365,8 @@ at32_add_device_mci(unsigned int id, struct mci_platform_data *data) | |||
1365 | slave->dma_dev = &dw_dmac0_device.dev; | 1365 | slave->dma_dev = &dw_dmac0_device.dev; |
1366 | slave->src_id = 0; | 1366 | slave->src_id = 0; |
1367 | slave->dst_id = 1; | 1367 | slave->dst_id = 1; |
1368 | slave->src_master = 1; | 1368 | slave->m_master = 1; |
1369 | slave->dst_master = 0; | 1369 | slave->p_master = 0; |
1370 | 1370 | ||
1371 | data->dma_slave = slave; | 1371 | data->dma_slave = slave; |
1372 | data->dma_filter = at32_mci_dma_filter; | 1372 | data->dma_filter = at32_mci_dma_filter; |
@@ -2061,16 +2061,16 @@ at32_add_device_ac97c(unsigned int id, struct ac97c_platform_data *data, | |||
2061 | if (flags & AC97C_CAPTURE) { | 2061 | if (flags & AC97C_CAPTURE) { |
2062 | rx_dws->dma_dev = &dw_dmac0_device.dev; | 2062 | rx_dws->dma_dev = &dw_dmac0_device.dev; |
2063 | rx_dws->src_id = 3; | 2063 | rx_dws->src_id = 3; |
2064 | rx_dws->src_master = 0; | 2064 | rx_dws->m_master = 0; |
2065 | rx_dws->dst_master = 1; | 2065 | rx_dws->p_master = 1; |
2066 | } | 2066 | } |
2067 | 2067 | ||
2068 | /* Check if DMA slave interface for playback should be configured. */ | 2068 | /* Check if DMA slave interface for playback should be configured. */ |
2069 | if (flags & AC97C_PLAYBACK) { | 2069 | if (flags & AC97C_PLAYBACK) { |
2070 | tx_dws->dma_dev = &dw_dmac0_device.dev; | 2070 | tx_dws->dma_dev = &dw_dmac0_device.dev; |
2071 | tx_dws->dst_id = 4; | 2071 | tx_dws->dst_id = 4; |
2072 | tx_dws->src_master = 0; | 2072 | tx_dws->m_master = 0; |
2073 | tx_dws->dst_master = 1; | 2073 | tx_dws->p_master = 1; |
2074 | } | 2074 | } |
2075 | 2075 | ||
2076 | if (platform_device_add_data(pdev, data, | 2076 | if (platform_device_add_data(pdev, data, |
@@ -2141,8 +2141,8 @@ at32_add_device_abdac(unsigned int id, struct atmel_abdac_pdata *data) | |||
2141 | 2141 | ||
2142 | dws->dma_dev = &dw_dmac0_device.dev; | 2142 | dws->dma_dev = &dw_dmac0_device.dev; |
2143 | dws->dst_id = 2; | 2143 | dws->dst_id = 2; |
2144 | dws->src_master = 0; | 2144 | dws->m_master = 0; |
2145 | dws->dst_master = 1; | 2145 | dws->p_master = 1; |
2146 | 2146 | ||
2147 | if (platform_device_add_data(pdev, data, | 2147 | if (platform_device_add_data(pdev, data, |
2148 | sizeof(struct atmel_abdac_pdata))) | 2148 | sizeof(struct atmel_abdac_pdata))) |
diff --git a/drivers/ata/sata_dwc_460ex.c b/drivers/ata/sata_dwc_460ex.c index 902034991517..2cb6f7e04b5c 100644 --- a/drivers/ata/sata_dwc_460ex.c +++ b/drivers/ata/sata_dwc_460ex.c | |||
@@ -201,8 +201,8 @@ static struct sata_dwc_host_priv host_pvt; | |||
201 | static struct dw_dma_slave sata_dwc_dma_dws = { | 201 | static struct dw_dma_slave sata_dwc_dma_dws = { |
202 | .src_id = 0, | 202 | .src_id = 0, |
203 | .dst_id = 0, | 203 | .dst_id = 0, |
204 | .src_master = 0, | 204 | .m_master = 1, |
205 | .dst_master = 1, | 205 | .p_master = 0, |
206 | }; | 206 | }; |
207 | 207 | ||
208 | /* | 208 | /* |
@@ -1248,7 +1248,7 @@ static int sata_dwc_probe(struct platform_device *ofdev) | |||
1248 | hsdev->dma->dev = &ofdev->dev; | 1248 | hsdev->dma->dev = &ofdev->dev; |
1249 | 1249 | ||
1250 | /* Initialize AHB DMAC */ | 1250 | /* Initialize AHB DMAC */ |
1251 | err = dw_dma_probe(hsdev->dma, NULL); | 1251 | err = dw_dma_probe(hsdev->dma); |
1252 | if (err) | 1252 | if (err) |
1253 | goto error_dma_iomap; | 1253 | goto error_dma_iomap; |
1254 | 1254 | ||
diff --git a/drivers/dma/bcm2835-dma.c b/drivers/dma/bcm2835-dma.c index 996c4b00d323..6149b27c33ad 100644 --- a/drivers/dma/bcm2835-dma.c +++ b/drivers/dma/bcm2835-dma.c | |||
@@ -46,6 +46,9 @@ | |||
46 | 46 | ||
47 | #include "virt-dma.h" | 47 | #include "virt-dma.h" |
48 | 48 | ||
49 | #define BCM2835_DMA_MAX_DMA_CHAN_SUPPORTED 14 | ||
50 | #define BCM2835_DMA_CHAN_NAME_SIZE 8 | ||
51 | |||
49 | struct bcm2835_dmadev { | 52 | struct bcm2835_dmadev { |
50 | struct dma_device ddev; | 53 | struct dma_device ddev; |
51 | spinlock_t lock; | 54 | spinlock_t lock; |
@@ -73,7 +76,6 @@ struct bcm2835_chan { | |||
73 | struct list_head node; | 76 | struct list_head node; |
74 | 77 | ||
75 | struct dma_slave_config cfg; | 78 | struct dma_slave_config cfg; |
76 | bool cyclic; | ||
77 | unsigned int dreq; | 79 | unsigned int dreq; |
78 | 80 | ||
79 | int ch; | 81 | int ch; |
@@ -82,6 +84,9 @@ struct bcm2835_chan { | |||
82 | 84 | ||
83 | void __iomem *chan_base; | 85 | void __iomem *chan_base; |
84 | int irq_number; | 86 | int irq_number; |
87 | unsigned int irq_flags; | ||
88 | |||
89 | bool is_lite_channel; | ||
85 | }; | 90 | }; |
86 | 91 | ||
87 | struct bcm2835_desc { | 92 | struct bcm2835_desc { |
@@ -89,47 +94,104 @@ struct bcm2835_desc { | |||
89 | struct virt_dma_desc vd; | 94 | struct virt_dma_desc vd; |
90 | enum dma_transfer_direction dir; | 95 | enum dma_transfer_direction dir; |
91 | 96 | ||
92 | struct bcm2835_cb_entry *cb_list; | ||
93 | |||
94 | unsigned int frames; | 97 | unsigned int frames; |
95 | size_t size; | 98 | size_t size; |
99 | |||
100 | bool cyclic; | ||
101 | |||
102 | struct bcm2835_cb_entry cb_list[]; | ||
96 | }; | 103 | }; |
97 | 104 | ||
98 | #define BCM2835_DMA_CS 0x00 | 105 | #define BCM2835_DMA_CS 0x00 |
99 | #define BCM2835_DMA_ADDR 0x04 | 106 | #define BCM2835_DMA_ADDR 0x04 |
107 | #define BCM2835_DMA_TI 0x08 | ||
100 | #define BCM2835_DMA_SOURCE_AD 0x0c | 108 | #define BCM2835_DMA_SOURCE_AD 0x0c |
101 | #define BCM2835_DMA_DEST_AD 0x10 | 109 | #define BCM2835_DMA_DEST_AD 0x10 |
102 | #define BCM2835_DMA_NEXTCB 0x1C | 110 | #define BCM2835_DMA_LEN 0x14 |
111 | #define BCM2835_DMA_STRIDE 0x18 | ||
112 | #define BCM2835_DMA_NEXTCB 0x1c | ||
113 | #define BCM2835_DMA_DEBUG 0x20 | ||
103 | 114 | ||
104 | /* DMA CS Control and Status bits */ | 115 | /* DMA CS Control and Status bits */ |
105 | #define BCM2835_DMA_ACTIVE BIT(0) | 116 | #define BCM2835_DMA_ACTIVE BIT(0) /* activate the DMA */ |
106 | #define BCM2835_DMA_INT BIT(2) | 117 | #define BCM2835_DMA_END BIT(1) /* current CB has ended */ |
118 | #define BCM2835_DMA_INT BIT(2) /* interrupt status */ | ||
119 | #define BCM2835_DMA_DREQ BIT(3) /* DREQ state */ | ||
107 | #define BCM2835_DMA_ISPAUSED BIT(4) /* Pause requested or not active */ | 120 | #define BCM2835_DMA_ISPAUSED BIT(4) /* Pause requested or not active */ |
108 | #define BCM2835_DMA_ISHELD BIT(5) /* Is held by DREQ flow control */ | 121 | #define BCM2835_DMA_ISHELD BIT(5) /* Is held by DREQ flow control */ |
109 | #define BCM2835_DMA_ERR BIT(8) | 122 | #define BCM2835_DMA_WAITING_FOR_WRITES BIT(6) /* waiting for last |
123 | * AXI-write to ack | ||
124 | */ | ||
125 | #define BCM2835_DMA_ERR BIT(8) | ||
126 | #define BCM2835_DMA_PRIORITY(x) ((x & 15) << 16) /* AXI priority */ | ||
127 | #define BCM2835_DMA_PANIC_PRIORITY(x) ((x & 15) << 20) /* panic priority */ | ||
128 | /* current value of TI.BCM2835_DMA_WAIT_RESP */ | ||
129 | #define BCM2835_DMA_WAIT_FOR_WRITES BIT(28) | ||
130 | #define BCM2835_DMA_DIS_DEBUG BIT(29) /* disable debug pause signal */ | ||
110 | #define BCM2835_DMA_ABORT BIT(30) /* Stop current CB, go to next, WO */ | 131 | #define BCM2835_DMA_ABORT BIT(30) /* Stop current CB, go to next, WO */ |
111 | #define BCM2835_DMA_RESET BIT(31) /* WO, self clearing */ | 132 | #define BCM2835_DMA_RESET BIT(31) /* WO, self clearing */ |
112 | 133 | ||
134 | /* Transfer information bits - also bcm2835_cb.info field */ | ||
113 | #define BCM2835_DMA_INT_EN BIT(0) | 135 | #define BCM2835_DMA_INT_EN BIT(0) |
136 | #define BCM2835_DMA_TDMODE BIT(1) /* 2D-Mode */ | ||
137 | #define BCM2835_DMA_WAIT_RESP BIT(3) /* wait for AXI-write to be acked */ | ||
114 | #define BCM2835_DMA_D_INC BIT(4) | 138 | #define BCM2835_DMA_D_INC BIT(4) |
115 | #define BCM2835_DMA_D_DREQ BIT(6) | 139 | #define BCM2835_DMA_D_WIDTH BIT(5) /* 128bit writes if set */ |
140 | #define BCM2835_DMA_D_DREQ BIT(6) /* enable DREQ for destination */ | ||
141 | #define BCM2835_DMA_D_IGNORE BIT(7) /* ignore destination writes */ | ||
116 | #define BCM2835_DMA_S_INC BIT(8) | 142 | #define BCM2835_DMA_S_INC BIT(8) |
117 | #define BCM2835_DMA_S_DREQ BIT(10) | 143 | #define BCM2835_DMA_S_WIDTH BIT(9) /* 128bit writes if set */ |
118 | 144 | #define BCM2835_DMA_S_DREQ BIT(10) /* enable SREQ for source */ | |
119 | #define BCM2835_DMA_PER_MAP(x) ((x) << 16) | 145 | #define BCM2835_DMA_S_IGNORE BIT(11) /* ignore source reads - read 0 */ |
146 | #define BCM2835_DMA_BURST_LENGTH(x) ((x & 15) << 12) | ||
147 | #define BCM2835_DMA_PER_MAP(x) ((x & 31) << 16) /* REQ source */ | ||
148 | #define BCM2835_DMA_WAIT(x) ((x & 31) << 21) /* add DMA-wait cycles */ | ||
149 | #define BCM2835_DMA_NO_WIDE_BURSTS BIT(26) /* no 2 beat write bursts */ | ||
150 | |||
151 | /* debug register bits */ | ||
152 | #define BCM2835_DMA_DEBUG_LAST_NOT_SET_ERR BIT(0) | ||
153 | #define BCM2835_DMA_DEBUG_FIFO_ERR BIT(1) | ||
154 | #define BCM2835_DMA_DEBUG_READ_ERR BIT(2) | ||
155 | #define BCM2835_DMA_DEBUG_OUTSTANDING_WRITES_SHIFT 4 | ||
156 | #define BCM2835_DMA_DEBUG_OUTSTANDING_WRITES_BITS 4 | ||
157 | #define BCM2835_DMA_DEBUG_ID_SHIFT 16 | ||
158 | #define BCM2835_DMA_DEBUG_ID_BITS 9 | ||
159 | #define BCM2835_DMA_DEBUG_STATE_SHIFT 16 | ||
160 | #define BCM2835_DMA_DEBUG_STATE_BITS 9 | ||
161 | #define BCM2835_DMA_DEBUG_VERSION_SHIFT 25 | ||
162 | #define BCM2835_DMA_DEBUG_VERSION_BITS 3 | ||
163 | #define BCM2835_DMA_DEBUG_LITE BIT(28) | ||
164 | |||
165 | /* shared registers for all dma channels */ | ||
166 | #define BCM2835_DMA_INT_STATUS 0xfe0 | ||
167 | #define BCM2835_DMA_ENABLE 0xff0 | ||
120 | 168 | ||
121 | #define BCM2835_DMA_DATA_TYPE_S8 1 | 169 | #define BCM2835_DMA_DATA_TYPE_S8 1 |
122 | #define BCM2835_DMA_DATA_TYPE_S16 2 | 170 | #define BCM2835_DMA_DATA_TYPE_S16 2 |
123 | #define BCM2835_DMA_DATA_TYPE_S32 4 | 171 | #define BCM2835_DMA_DATA_TYPE_S32 4 |
124 | #define BCM2835_DMA_DATA_TYPE_S128 16 | 172 | #define BCM2835_DMA_DATA_TYPE_S128 16 |
125 | 173 | ||
126 | #define BCM2835_DMA_BULK_MASK BIT(0) | ||
127 | #define BCM2835_DMA_FIQ_MASK (BIT(2) | BIT(3)) | ||
128 | |||
129 | /* Valid only for channels 0 - 14, 15 has its own base address */ | 174 | /* Valid only for channels 0 - 14, 15 has its own base address */ |
130 | #define BCM2835_DMA_CHAN(n) ((n) << 8) /* Base address */ | 175 | #define BCM2835_DMA_CHAN(n) ((n) << 8) /* Base address */ |
131 | #define BCM2835_DMA_CHANIO(base, n) ((base) + BCM2835_DMA_CHAN(n)) | 176 | #define BCM2835_DMA_CHANIO(base, n) ((base) + BCM2835_DMA_CHAN(n)) |
132 | 177 | ||
178 | /* the max dma length for different channels */ | ||
179 | #define MAX_DMA_LEN SZ_1G | ||
180 | #define MAX_LITE_DMA_LEN (SZ_64K - 4) | ||
181 | |||
182 | static inline size_t bcm2835_dma_max_frame_length(struct bcm2835_chan *c) | ||
183 | { | ||
184 | /* lite and normal channels have different max frame length */ | ||
185 | return c->is_lite_channel ? MAX_LITE_DMA_LEN : MAX_DMA_LEN; | ||
186 | } | ||
187 | |||
188 | /* how many frames of max_len size do we need to transfer len bytes */ | ||
189 | static inline size_t bcm2835_dma_frames_for_length(size_t len, | ||
190 | size_t max_len) | ||
191 | { | ||
192 | return DIV_ROUND_UP(len, max_len); | ||
193 | } | ||
194 | |||
133 | static inline struct bcm2835_dmadev *to_bcm2835_dma_dev(struct dma_device *d) | 195 | static inline struct bcm2835_dmadev *to_bcm2835_dma_dev(struct dma_device *d) |
134 | { | 196 | { |
135 | return container_of(d, struct bcm2835_dmadev, ddev); | 197 | return container_of(d, struct bcm2835_dmadev, ddev); |
@@ -146,19 +208,209 @@ static inline struct bcm2835_desc *to_bcm2835_dma_desc( | |||
146 | return container_of(t, struct bcm2835_desc, vd.tx); | 208 | return container_of(t, struct bcm2835_desc, vd.tx); |
147 | } | 209 | } |
148 | 210 | ||
149 | static void bcm2835_dma_desc_free(struct virt_dma_desc *vd) | 211 | static void bcm2835_dma_free_cb_chain(struct bcm2835_desc *desc) |
150 | { | 212 | { |
151 | struct bcm2835_desc *desc = container_of(vd, struct bcm2835_desc, vd); | 213 | size_t i; |
152 | int i; | ||
153 | 214 | ||
154 | for (i = 0; i < desc->frames; i++) | 215 | for (i = 0; i < desc->frames; i++) |
155 | dma_pool_free(desc->c->cb_pool, desc->cb_list[i].cb, | 216 | dma_pool_free(desc->c->cb_pool, desc->cb_list[i].cb, |
156 | desc->cb_list[i].paddr); | 217 | desc->cb_list[i].paddr); |
157 | 218 | ||
158 | kfree(desc->cb_list); | ||
159 | kfree(desc); | 219 | kfree(desc); |
160 | } | 220 | } |
161 | 221 | ||
222 | static void bcm2835_dma_desc_free(struct virt_dma_desc *vd) | ||
223 | { | ||
224 | bcm2835_dma_free_cb_chain( | ||
225 | container_of(vd, struct bcm2835_desc, vd)); | ||
226 | } | ||
227 | |||
228 | static void bcm2835_dma_create_cb_set_length( | ||
229 | struct bcm2835_chan *chan, | ||
230 | struct bcm2835_dma_cb *control_block, | ||
231 | size_t len, | ||
232 | size_t period_len, | ||
233 | size_t *total_len, | ||
234 | u32 finalextrainfo) | ||
235 | { | ||
236 | size_t max_len = bcm2835_dma_max_frame_length(chan); | ||
237 | |||
238 | /* set the length taking lite-channel limitations into account */ | ||
239 | control_block->length = min_t(u32, len, max_len); | ||
240 | |||
241 | /* finished if we have no period_length */ | ||
242 | if (!period_len) | ||
243 | return; | ||
244 | |||
245 | /* | ||
246 | * period_len means: that we need to generate | ||
247 | * transfers that are terminating at every | ||
248 | * multiple of period_len - this is typically | ||
249 | * used to set the interrupt flag in info | ||
250 | * which is required during cyclic transfers | ||
251 | */ | ||
252 | |||
253 | /* have we filled in period_length yet? */ | ||
254 | if (*total_len + control_block->length < period_len) | ||
255 | return; | ||
256 | |||
257 | /* calculate the length that remains to reach period_length */ | ||
258 | control_block->length = period_len - *total_len; | ||
259 | |||
260 | /* reset total_length for next period */ | ||
261 | *total_len = 0; | ||
262 | |||
263 | /* add extrainfo bits in info */ | ||
264 | control_block->info |= finalextrainfo; | ||
265 | } | ||
266 | |||
267 | static inline size_t bcm2835_dma_count_frames_for_sg( | ||
268 | struct bcm2835_chan *c, | ||
269 | struct scatterlist *sgl, | ||
270 | unsigned int sg_len) | ||
271 | { | ||
272 | size_t frames = 0; | ||
273 | struct scatterlist *sgent; | ||
274 | unsigned int i; | ||
275 | size_t plength = bcm2835_dma_max_frame_length(c); | ||
276 | |||
277 | for_each_sg(sgl, sgent, sg_len, i) | ||
278 | frames += bcm2835_dma_frames_for_length( | ||
279 | sg_dma_len(sgent), plength); | ||
280 | |||
281 | return frames; | ||
282 | } | ||
283 | |||
284 | /** | ||
285 | * bcm2835_dma_create_cb_chain - create a control block and fills data in | ||
286 | * | ||
287 | * @chan: the @dma_chan for which we run this | ||
288 | * @direction: the direction in which we transfer | ||
289 | * @cyclic: it is a cyclic transfer | ||
290 | * @info: the default info bits to apply per controlblock | ||
291 | * @frames: number of controlblocks to allocate | ||
292 | * @src: the src address to assign (if the S_INC bit is set | ||
293 | * in @info, then it gets incremented) | ||
294 | * @dst: the dst address to assign (if the D_INC bit is set | ||
295 | * in @info, then it gets incremented) | ||
296 | * @buf_len: the full buffer length (may also be 0) | ||
297 | * @period_len: the period length when to apply @finalextrainfo | ||
298 | * in addition to the last transfer | ||
299 | * this will also break some control-blocks early | ||
300 | * @finalextrainfo: additional bits in last controlblock | ||
301 | * (or when period_len is reached in case of cyclic) | ||
302 | * @gfp: the GFP flag to use for allocation | ||
303 | */ | ||
304 | static struct bcm2835_desc *bcm2835_dma_create_cb_chain( | ||
305 | struct dma_chan *chan, enum dma_transfer_direction direction, | ||
306 | bool cyclic, u32 info, u32 finalextrainfo, size_t frames, | ||
307 | dma_addr_t src, dma_addr_t dst, size_t buf_len, | ||
308 | size_t period_len, gfp_t gfp) | ||
309 | { | ||
310 | struct bcm2835_chan *c = to_bcm2835_dma_chan(chan); | ||
311 | size_t len = buf_len, total_len; | ||
312 | size_t frame; | ||
313 | struct bcm2835_desc *d; | ||
314 | struct bcm2835_cb_entry *cb_entry; | ||
315 | struct bcm2835_dma_cb *control_block; | ||
316 | |||
317 | if (!frames) | ||
318 | return NULL; | ||
319 | |||
320 | /* allocate and setup the descriptor. */ | ||
321 | d = kzalloc(sizeof(*d) + frames * sizeof(struct bcm2835_cb_entry), | ||
322 | gfp); | ||
323 | if (!d) | ||
324 | return NULL; | ||
325 | |||
326 | d->c = c; | ||
327 | d->dir = direction; | ||
328 | d->cyclic = cyclic; | ||
329 | |||
330 | /* | ||
331 | * Iterate over all frames, create a control block | ||
332 | * for each frame and link them together. | ||
333 | */ | ||
334 | for (frame = 0, total_len = 0; frame < frames; d->frames++, frame++) { | ||
335 | cb_entry = &d->cb_list[frame]; | ||
336 | cb_entry->cb = dma_pool_alloc(c->cb_pool, gfp, | ||
337 | &cb_entry->paddr); | ||
338 | if (!cb_entry->cb) | ||
339 | goto error_cb; | ||
340 | |||
341 | /* fill in the control block */ | ||
342 | control_block = cb_entry->cb; | ||
343 | control_block->info = info; | ||
344 | control_block->src = src; | ||
345 | control_block->dst = dst; | ||
346 | control_block->stride = 0; | ||
347 | control_block->next = 0; | ||
348 | /* set up length in control_block if requested */ | ||
349 | if (buf_len) { | ||
350 | /* calculate length honoring period_length */ | ||
351 | bcm2835_dma_create_cb_set_length( | ||
352 | c, control_block, | ||
353 | len, period_len, &total_len, | ||
354 | cyclic ? finalextrainfo : 0); | ||
355 | |||
356 | /* calculate new remaining length */ | ||
357 | len -= control_block->length; | ||
358 | } | ||
359 | |||
360 | /* link this the last controlblock */ | ||
361 | if (frame) | ||
362 | d->cb_list[frame - 1].cb->next = cb_entry->paddr; | ||
363 | |||
364 | /* update src and dst and length */ | ||
365 | if (src && (info & BCM2835_DMA_S_INC)) | ||
366 | src += control_block->length; | ||
367 | if (dst && (info & BCM2835_DMA_D_INC)) | ||
368 | dst += control_block->length; | ||
369 | |||
370 | /* Length of total transfer */ | ||
371 | d->size += control_block->length; | ||
372 | } | ||
373 | |||
374 | /* the last frame requires extra flags */ | ||
375 | d->cb_list[d->frames - 1].cb->info |= finalextrainfo; | ||
376 | |||
377 | /* detect a size missmatch */ | ||
378 | if (buf_len && (d->size != buf_len)) | ||
379 | goto error_cb; | ||
380 | |||
381 | return d; | ||
382 | error_cb: | ||
383 | bcm2835_dma_free_cb_chain(d); | ||
384 | |||
385 | return NULL; | ||
386 | } | ||
387 | |||
388 | static void bcm2835_dma_fill_cb_chain_with_sg( | ||
389 | struct dma_chan *chan, | ||
390 | enum dma_transfer_direction direction, | ||
391 | struct bcm2835_cb_entry *cb, | ||
392 | struct scatterlist *sgl, | ||
393 | unsigned int sg_len) | ||
394 | { | ||
395 | struct bcm2835_chan *c = to_bcm2835_dma_chan(chan); | ||
396 | size_t max_len = bcm2835_dma_max_frame_length(c); | ||
397 | unsigned int i, len; | ||
398 | dma_addr_t addr; | ||
399 | struct scatterlist *sgent; | ||
400 | |||
401 | for_each_sg(sgl, sgent, sg_len, i) { | ||
402 | for (addr = sg_dma_address(sgent), len = sg_dma_len(sgent); | ||
403 | len > 0; | ||
404 | addr += cb->cb->length, len -= cb->cb->length, cb++) { | ||
405 | if (direction == DMA_DEV_TO_MEM) | ||
406 | cb->cb->dst = addr; | ||
407 | else | ||
408 | cb->cb->src = addr; | ||
409 | cb->cb->length = min(len, max_len); | ||
410 | } | ||
411 | } | ||
412 | } | ||
413 | |||
162 | static int bcm2835_dma_abort(void __iomem *chan_base) | 414 | static int bcm2835_dma_abort(void __iomem *chan_base) |
163 | { | 415 | { |
164 | unsigned long cs; | 416 | unsigned long cs; |
@@ -218,6 +470,15 @@ static irqreturn_t bcm2835_dma_callback(int irq, void *data) | |||
218 | struct bcm2835_desc *d; | 470 | struct bcm2835_desc *d; |
219 | unsigned long flags; | 471 | unsigned long flags; |
220 | 472 | ||
473 | /* check the shared interrupt */ | ||
474 | if (c->irq_flags & IRQF_SHARED) { | ||
475 | /* check if the interrupt is enabled */ | ||
476 | flags = readl(c->chan_base + BCM2835_DMA_CS); | ||
477 | /* if not set then we are not the reason for the irq */ | ||
478 | if (!(flags & BCM2835_DMA_INT)) | ||
479 | return IRQ_NONE; | ||
480 | } | ||
481 | |||
221 | spin_lock_irqsave(&c->vc.lock, flags); | 482 | spin_lock_irqsave(&c->vc.lock, flags); |
222 | 483 | ||
223 | /* Acknowledge interrupt */ | 484 | /* Acknowledge interrupt */ |
@@ -226,12 +487,18 @@ static irqreturn_t bcm2835_dma_callback(int irq, void *data) | |||
226 | d = c->desc; | 487 | d = c->desc; |
227 | 488 | ||
228 | if (d) { | 489 | if (d) { |
229 | /* TODO Only works for cyclic DMA */ | 490 | if (d->cyclic) { |
230 | vchan_cyclic_callback(&d->vd); | 491 | /* call the cyclic callback */ |
231 | } | 492 | vchan_cyclic_callback(&d->vd); |
232 | 493 | ||
233 | /* Keep the DMA engine running */ | 494 | /* Keep the DMA engine running */ |
234 | writel(BCM2835_DMA_ACTIVE, c->chan_base + BCM2835_DMA_CS); | 495 | writel(BCM2835_DMA_ACTIVE, |
496 | c->chan_base + BCM2835_DMA_CS); | ||
497 | } else { | ||
498 | vchan_cookie_complete(&c->desc->vd); | ||
499 | bcm2835_dma_start_desc(c); | ||
500 | } | ||
501 | } | ||
235 | 502 | ||
236 | spin_unlock_irqrestore(&c->vc.lock, flags); | 503 | spin_unlock_irqrestore(&c->vc.lock, flags); |
237 | 504 | ||
@@ -252,8 +519,8 @@ static int bcm2835_dma_alloc_chan_resources(struct dma_chan *chan) | |||
252 | return -ENOMEM; | 519 | return -ENOMEM; |
253 | } | 520 | } |
254 | 521 | ||
255 | return request_irq(c->irq_number, | 522 | return request_irq(c->irq_number, bcm2835_dma_callback, |
256 | bcm2835_dma_callback, 0, "DMA IRQ", c); | 523 | c->irq_flags, "DMA IRQ", c); |
257 | } | 524 | } |
258 | 525 | ||
259 | static void bcm2835_dma_free_chan_resources(struct dma_chan *chan) | 526 | static void bcm2835_dma_free_chan_resources(struct dma_chan *chan) |
@@ -339,8 +606,6 @@ static void bcm2835_dma_issue_pending(struct dma_chan *chan) | |||
339 | struct bcm2835_chan *c = to_bcm2835_dma_chan(chan); | 606 | struct bcm2835_chan *c = to_bcm2835_dma_chan(chan); |
340 | unsigned long flags; | 607 | unsigned long flags; |
341 | 608 | ||
342 | c->cyclic = true; /* Nothing else is implemented */ | ||
343 | |||
344 | spin_lock_irqsave(&c->vc.lock, flags); | 609 | spin_lock_irqsave(&c->vc.lock, flags); |
345 | if (vchan_issue_pending(&c->vc) && !c->desc) | 610 | if (vchan_issue_pending(&c->vc) && !c->desc) |
346 | bcm2835_dma_start_desc(c); | 611 | bcm2835_dma_start_desc(c); |
@@ -348,122 +613,160 @@ static void bcm2835_dma_issue_pending(struct dma_chan *chan) | |||
348 | spin_unlock_irqrestore(&c->vc.lock, flags); | 613 | spin_unlock_irqrestore(&c->vc.lock, flags); |
349 | } | 614 | } |
350 | 615 | ||
351 | static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic( | 616 | struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_memcpy( |
352 | struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, | 617 | struct dma_chan *chan, dma_addr_t dst, dma_addr_t src, |
353 | size_t period_len, enum dma_transfer_direction direction, | 618 | size_t len, unsigned long flags) |
354 | unsigned long flags) | ||
355 | { | 619 | { |
356 | struct bcm2835_chan *c = to_bcm2835_dma_chan(chan); | 620 | struct bcm2835_chan *c = to_bcm2835_dma_chan(chan); |
357 | enum dma_slave_buswidth dev_width; | ||
358 | struct bcm2835_desc *d; | 621 | struct bcm2835_desc *d; |
359 | dma_addr_t dev_addr; | 622 | u32 info = BCM2835_DMA_D_INC | BCM2835_DMA_S_INC; |
360 | unsigned int es, sync_type; | 623 | u32 extra = BCM2835_DMA_INT_EN | BCM2835_DMA_WAIT_RESP; |
361 | unsigned int frame; | 624 | size_t max_len = bcm2835_dma_max_frame_length(c); |
362 | int i; | 625 | size_t frames; |
626 | |||
627 | /* if src, dst or len is not given return with an error */ | ||
628 | if (!src || !dst || !len) | ||
629 | return NULL; | ||
630 | |||
631 | /* calculate number of frames */ | ||
632 | frames = bcm2835_dma_frames_for_length(len, max_len); | ||
633 | |||
634 | /* allocate the CB chain - this also fills in the pointers */ | ||
635 | d = bcm2835_dma_create_cb_chain(chan, DMA_MEM_TO_MEM, false, | ||
636 | info, extra, frames, | ||
637 | src, dst, len, 0, GFP_KERNEL); | ||
638 | if (!d) | ||
639 | return NULL; | ||
640 | |||
641 | return vchan_tx_prep(&c->vc, &d->vd, flags); | ||
642 | } | ||
643 | |||
644 | static struct dma_async_tx_descriptor *bcm2835_dma_prep_slave_sg( | ||
645 | struct dma_chan *chan, | ||
646 | struct scatterlist *sgl, unsigned int sg_len, | ||
647 | enum dma_transfer_direction direction, | ||
648 | unsigned long flags, void *context) | ||
649 | { | ||
650 | struct bcm2835_chan *c = to_bcm2835_dma_chan(chan); | ||
651 | struct bcm2835_desc *d; | ||
652 | dma_addr_t src = 0, dst = 0; | ||
653 | u32 info = BCM2835_DMA_WAIT_RESP; | ||
654 | u32 extra = BCM2835_DMA_INT_EN; | ||
655 | size_t frames; | ||
363 | 656 | ||
364 | /* Grab configuration */ | ||
365 | if (!is_slave_direction(direction)) { | 657 | if (!is_slave_direction(direction)) { |
366 | dev_err(chan->device->dev, "%s: bad direction?\n", __func__); | 658 | dev_err(chan->device->dev, |
659 | "%s: bad direction?\n", __func__); | ||
367 | return NULL; | 660 | return NULL; |
368 | } | 661 | } |
369 | 662 | ||
663 | if (c->dreq != 0) | ||
664 | info |= BCM2835_DMA_PER_MAP(c->dreq); | ||
665 | |||
370 | if (direction == DMA_DEV_TO_MEM) { | 666 | if (direction == DMA_DEV_TO_MEM) { |
371 | dev_addr = c->cfg.src_addr; | 667 | if (c->cfg.src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) |
372 | dev_width = c->cfg.src_addr_width; | 668 | return NULL; |
373 | sync_type = BCM2835_DMA_S_DREQ; | 669 | src = c->cfg.src_addr; |
670 | info |= BCM2835_DMA_S_DREQ | BCM2835_DMA_D_INC; | ||
374 | } else { | 671 | } else { |
375 | dev_addr = c->cfg.dst_addr; | 672 | if (c->cfg.dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) |
376 | dev_width = c->cfg.dst_addr_width; | 673 | return NULL; |
377 | sync_type = BCM2835_DMA_D_DREQ; | 674 | dst = c->cfg.dst_addr; |
675 | info |= BCM2835_DMA_D_DREQ | BCM2835_DMA_S_INC; | ||
378 | } | 676 | } |
379 | 677 | ||
380 | /* Bus width translates to the element size (ES) */ | 678 | /* count frames in sg list */ |
381 | switch (dev_width) { | 679 | frames = bcm2835_dma_count_frames_for_sg(c, sgl, sg_len); |
382 | case DMA_SLAVE_BUSWIDTH_4_BYTES: | ||
383 | es = BCM2835_DMA_DATA_TYPE_S32; | ||
384 | break; | ||
385 | default: | ||
386 | return NULL; | ||
387 | } | ||
388 | 680 | ||
389 | /* Now allocate and setup the descriptor. */ | 681 | /* allocate the CB chain */ |
390 | d = kzalloc(sizeof(*d), GFP_NOWAIT); | 682 | d = bcm2835_dma_create_cb_chain(chan, direction, false, |
683 | info, extra, | ||
684 | frames, src, dst, 0, 0, | ||
685 | GFP_KERNEL); | ||
391 | if (!d) | 686 | if (!d) |
392 | return NULL; | 687 | return NULL; |
393 | 688 | ||
394 | d->c = c; | 689 | /* fill in frames with scatterlist pointers */ |
395 | d->dir = direction; | 690 | bcm2835_dma_fill_cb_chain_with_sg(chan, direction, d->cb_list, |
396 | d->frames = buf_len / period_len; | 691 | sgl, sg_len); |
397 | 692 | ||
398 | d->cb_list = kcalloc(d->frames, sizeof(*d->cb_list), GFP_KERNEL); | 693 | return vchan_tx_prep(&c->vc, &d->vd, flags); |
399 | if (!d->cb_list) { | 694 | } |
400 | kfree(d); | 695 | |
696 | static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic( | ||
697 | struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, | ||
698 | size_t period_len, enum dma_transfer_direction direction, | ||
699 | unsigned long flags) | ||
700 | { | ||
701 | struct bcm2835_chan *c = to_bcm2835_dma_chan(chan); | ||
702 | struct bcm2835_desc *d; | ||
703 | dma_addr_t src, dst; | ||
704 | u32 info = BCM2835_DMA_WAIT_RESP; | ||
705 | u32 extra = BCM2835_DMA_INT_EN; | ||
706 | size_t max_len = bcm2835_dma_max_frame_length(c); | ||
707 | size_t frames; | ||
708 | |||
709 | /* Grab configuration */ | ||
710 | if (!is_slave_direction(direction)) { | ||
711 | dev_err(chan->device->dev, "%s: bad direction?\n", __func__); | ||
401 | return NULL; | 712 | return NULL; |
402 | } | 713 | } |
403 | /* Allocate memory for control blocks */ | ||
404 | for (i = 0; i < d->frames; i++) { | ||
405 | struct bcm2835_cb_entry *cb_entry = &d->cb_list[i]; | ||
406 | 714 | ||
407 | cb_entry->cb = dma_pool_zalloc(c->cb_pool, GFP_ATOMIC, | 715 | if (!buf_len) { |
408 | &cb_entry->paddr); | 716 | dev_err(chan->device->dev, |
409 | if (!cb_entry->cb) | 717 | "%s: bad buffer length (= 0)\n", __func__); |
410 | goto error_cb; | 718 | return NULL; |
411 | } | 719 | } |
412 | 720 | ||
413 | /* | 721 | /* |
414 | * Iterate over all frames, create a control block | 722 | * warn if buf_len is not a multiple of period_len - this may leed |
415 | * for each frame and link them together. | 723 | * to unexpected latencies for interrupts and thus audiable clicks |
416 | */ | 724 | */ |
417 | for (frame = 0; frame < d->frames; frame++) { | 725 | if (buf_len % period_len) |
418 | struct bcm2835_dma_cb *control_block = d->cb_list[frame].cb; | 726 | dev_warn_once(chan->device->dev, |
419 | 727 | "%s: buffer_length (%zd) is not a multiple of period_len (%zd)\n", | |
420 | /* Setup adresses */ | 728 | __func__, buf_len, period_len); |
421 | if (d->dir == DMA_DEV_TO_MEM) { | ||
422 | control_block->info = BCM2835_DMA_D_INC; | ||
423 | control_block->src = dev_addr; | ||
424 | control_block->dst = buf_addr + frame * period_len; | ||
425 | } else { | ||
426 | control_block->info = BCM2835_DMA_S_INC; | ||
427 | control_block->src = buf_addr + frame * period_len; | ||
428 | control_block->dst = dev_addr; | ||
429 | } | ||
430 | 729 | ||
431 | /* Enable interrupt */ | 730 | /* Setup DREQ channel */ |
432 | control_block->info |= BCM2835_DMA_INT_EN; | 731 | if (c->dreq != 0) |
732 | info |= BCM2835_DMA_PER_MAP(c->dreq); | ||
433 | 733 | ||
434 | /* Setup synchronization */ | 734 | if (direction == DMA_DEV_TO_MEM) { |
435 | if (sync_type != 0) | 735 | if (c->cfg.src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) |
436 | control_block->info |= sync_type; | 736 | return NULL; |
737 | src = c->cfg.src_addr; | ||
738 | dst = buf_addr; | ||
739 | info |= BCM2835_DMA_S_DREQ | BCM2835_DMA_D_INC; | ||
740 | } else { | ||
741 | if (c->cfg.dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) | ||
742 | return NULL; | ||
743 | dst = c->cfg.dst_addr; | ||
744 | src = buf_addr; | ||
745 | info |= BCM2835_DMA_D_DREQ | BCM2835_DMA_S_INC; | ||
746 | } | ||
437 | 747 | ||
438 | /* Setup DREQ channel */ | 748 | /* calculate number of frames */ |
439 | if (c->dreq != 0) | 749 | frames = /* number of periods */ |
440 | control_block->info |= | 750 | DIV_ROUND_UP(buf_len, period_len) * |
441 | BCM2835_DMA_PER_MAP(c->dreq); | 751 | /* number of frames per period */ |
752 | bcm2835_dma_frames_for_length(period_len, max_len); | ||
442 | 753 | ||
443 | /* Length of a frame */ | 754 | /* |
444 | control_block->length = period_len; | 755 | * allocate the CB chain |
445 | d->size += control_block->length; | 756 | * note that we need to use GFP_NOWAIT, as the ALSA i2s dmaengine |
757 | * implementation calls prep_dma_cyclic with interrupts disabled. | ||
758 | */ | ||
759 | d = bcm2835_dma_create_cb_chain(chan, direction, true, | ||
760 | info, extra, | ||
761 | frames, src, dst, buf_len, | ||
762 | period_len, GFP_NOWAIT); | ||
763 | if (!d) | ||
764 | return NULL; | ||
446 | 765 | ||
447 | /* | 766 | /* wrap around into a loop */ |
448 | * Next block is the next frame. | 767 | d->cb_list[d->frames - 1].cb->next = d->cb_list[0].paddr; |
449 | * This DMA engine driver currently only supports cyclic DMA. | ||
450 | * Therefore, wrap around at number of frames. | ||
451 | */ | ||
452 | control_block->next = d->cb_list[((frame + 1) % d->frames)].paddr; | ||
453 | } | ||
454 | 768 | ||
455 | return vchan_tx_prep(&c->vc, &d->vd, flags); | 769 | return vchan_tx_prep(&c->vc, &d->vd, flags); |
456 | error_cb: | ||
457 | i--; | ||
458 | for (; i >= 0; i--) { | ||
459 | struct bcm2835_cb_entry *cb_entry = &d->cb_list[i]; | ||
460 | |||
461 | dma_pool_free(c->cb_pool, cb_entry->cb, cb_entry->paddr); | ||
462 | } | ||
463 | |||
464 | kfree(d->cb_list); | ||
465 | kfree(d); | ||
466 | return NULL; | ||
467 | } | 770 | } |
468 | 771 | ||
469 | static int bcm2835_dma_slave_config(struct dma_chan *chan, | 772 | static int bcm2835_dma_slave_config(struct dma_chan *chan, |
@@ -529,7 +832,8 @@ static int bcm2835_dma_terminate_all(struct dma_chan *chan) | |||
529 | return 0; | 832 | return 0; |
530 | } | 833 | } |
531 | 834 | ||
532 | static int bcm2835_dma_chan_init(struct bcm2835_dmadev *d, int chan_id, int irq) | 835 | static int bcm2835_dma_chan_init(struct bcm2835_dmadev *d, int chan_id, |
836 | int irq, unsigned int irq_flags) | ||
533 | { | 837 | { |
534 | struct bcm2835_chan *c; | 838 | struct bcm2835_chan *c; |
535 | 839 | ||
@@ -544,6 +848,12 @@ static int bcm2835_dma_chan_init(struct bcm2835_dmadev *d, int chan_id, int irq) | |||
544 | c->chan_base = BCM2835_DMA_CHANIO(d->base, chan_id); | 848 | c->chan_base = BCM2835_DMA_CHANIO(d->base, chan_id); |
545 | c->ch = chan_id; | 849 | c->ch = chan_id; |
546 | c->irq_number = irq; | 850 | c->irq_number = irq; |
851 | c->irq_flags = irq_flags; | ||
852 | |||
853 | /* check in DEBUG register if this is a LITE channel */ | ||
854 | if (readl(c->chan_base + BCM2835_DMA_DEBUG) & | ||
855 | BCM2835_DMA_DEBUG_LITE) | ||
856 | c->is_lite_channel = true; | ||
547 | 857 | ||
548 | return 0; | 858 | return 0; |
549 | } | 859 | } |
@@ -587,9 +897,11 @@ static int bcm2835_dma_probe(struct platform_device *pdev) | |||
587 | struct resource *res; | 897 | struct resource *res; |
588 | void __iomem *base; | 898 | void __iomem *base; |
589 | int rc; | 899 | int rc; |
590 | int i; | 900 | int i, j; |
591 | int irq; | 901 | int irq[BCM2835_DMA_MAX_DMA_CHAN_SUPPORTED + 1]; |
902 | int irq_flags; | ||
592 | uint32_t chans_available; | 903 | uint32_t chans_available; |
904 | char chan_name[BCM2835_DMA_CHAN_NAME_SIZE]; | ||
593 | 905 | ||
594 | if (!pdev->dev.dma_mask) | 906 | if (!pdev->dev.dma_mask) |
595 | pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; | 907 | pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; |
@@ -615,16 +927,22 @@ static int bcm2835_dma_probe(struct platform_device *pdev) | |||
615 | dma_cap_set(DMA_SLAVE, od->ddev.cap_mask); | 927 | dma_cap_set(DMA_SLAVE, od->ddev.cap_mask); |
616 | dma_cap_set(DMA_PRIVATE, od->ddev.cap_mask); | 928 | dma_cap_set(DMA_PRIVATE, od->ddev.cap_mask); |
617 | dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask); | 929 | dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask); |
930 | dma_cap_set(DMA_SLAVE, od->ddev.cap_mask); | ||
931 | dma_cap_set(DMA_MEMCPY, od->ddev.cap_mask); | ||
618 | od->ddev.device_alloc_chan_resources = bcm2835_dma_alloc_chan_resources; | 932 | od->ddev.device_alloc_chan_resources = bcm2835_dma_alloc_chan_resources; |
619 | od->ddev.device_free_chan_resources = bcm2835_dma_free_chan_resources; | 933 | od->ddev.device_free_chan_resources = bcm2835_dma_free_chan_resources; |
620 | od->ddev.device_tx_status = bcm2835_dma_tx_status; | 934 | od->ddev.device_tx_status = bcm2835_dma_tx_status; |
621 | od->ddev.device_issue_pending = bcm2835_dma_issue_pending; | 935 | od->ddev.device_issue_pending = bcm2835_dma_issue_pending; |
622 | od->ddev.device_prep_dma_cyclic = bcm2835_dma_prep_dma_cyclic; | 936 | od->ddev.device_prep_dma_cyclic = bcm2835_dma_prep_dma_cyclic; |
937 | od->ddev.device_prep_slave_sg = bcm2835_dma_prep_slave_sg; | ||
938 | od->ddev.device_prep_dma_memcpy = bcm2835_dma_prep_dma_memcpy; | ||
623 | od->ddev.device_config = bcm2835_dma_slave_config; | 939 | od->ddev.device_config = bcm2835_dma_slave_config; |
624 | od->ddev.device_terminate_all = bcm2835_dma_terminate_all; | 940 | od->ddev.device_terminate_all = bcm2835_dma_terminate_all; |
625 | od->ddev.src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES); | 941 | od->ddev.src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES); |
626 | od->ddev.dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES); | 942 | od->ddev.dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES); |
627 | od->ddev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV); | 943 | od->ddev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV) | |
944 | BIT(DMA_MEM_TO_MEM); | ||
945 | od->ddev.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST; | ||
628 | od->ddev.dev = &pdev->dev; | 946 | od->ddev.dev = &pdev->dev; |
629 | INIT_LIST_HEAD(&od->ddev.channels); | 947 | INIT_LIST_HEAD(&od->ddev.channels); |
630 | spin_lock_init(&od->lock); | 948 | spin_lock_init(&od->lock); |
@@ -640,22 +958,48 @@ static int bcm2835_dma_probe(struct platform_device *pdev) | |||
640 | goto err_no_dma; | 958 | goto err_no_dma; |
641 | } | 959 | } |
642 | 960 | ||
643 | /* | 961 | /* get irqs for each channel that we support */ |
644 | * Do not use the FIQ and BULK channels, | 962 | for (i = 0; i <= BCM2835_DMA_MAX_DMA_CHAN_SUPPORTED; i++) { |
645 | * because they are used by the GPU. | 963 | /* skip masked out channels */ |
646 | */ | 964 | if (!(chans_available & (1 << i))) { |
647 | chans_available &= ~(BCM2835_DMA_FIQ_MASK | BCM2835_DMA_BULK_MASK); | 965 | irq[i] = -1; |
966 | continue; | ||
967 | } | ||
648 | 968 | ||
649 | for (i = 0; i < pdev->num_resources; i++) { | 969 | /* get the named irq */ |
650 | irq = platform_get_irq(pdev, i); | 970 | snprintf(chan_name, sizeof(chan_name), "dma%i", i); |
651 | if (irq < 0) | 971 | irq[i] = platform_get_irq_byname(pdev, chan_name); |
652 | break; | 972 | if (irq[i] >= 0) |
973 | continue; | ||
653 | 974 | ||
654 | if (chans_available & (1 << i)) { | 975 | /* legacy device tree case handling */ |
655 | rc = bcm2835_dma_chan_init(od, i, irq); | 976 | dev_warn_once(&pdev->dev, |
656 | if (rc) | 977 | "missing interrupt-names property in device tree - legacy interpretation is used\n"); |
657 | goto err_no_dma; | 978 | /* |
658 | } | 979 | * in case of channel >= 11 |
980 | * use the 11th interrupt and that is shared | ||
981 | */ | ||
982 | irq[i] = platform_get_irq(pdev, i < 11 ? i : 11); | ||
983 | } | ||
984 | |||
985 | /* get irqs for each channel */ | ||
986 | for (i = 0; i <= BCM2835_DMA_MAX_DMA_CHAN_SUPPORTED; i++) { | ||
987 | /* skip channels without irq */ | ||
988 | if (irq[i] < 0) | ||
989 | continue; | ||
990 | |||
991 | /* check if there are other channels that also use this irq */ | ||
992 | irq_flags = 0; | ||
993 | for (j = 0; j <= BCM2835_DMA_MAX_DMA_CHAN_SUPPORTED; j++) | ||
994 | if ((i != j) && (irq[j] == irq[i])) { | ||
995 | irq_flags = IRQF_SHARED; | ||
996 | break; | ||
997 | } | ||
998 | |||
999 | /* initialize the channel */ | ||
1000 | rc = bcm2835_dma_chan_init(od, i, irq[i], irq_flags); | ||
1001 | if (rc) | ||
1002 | goto err_no_dma; | ||
659 | } | 1003 | } |
660 | 1004 | ||
661 | dev_dbg(&pdev->dev, "Initialized %i DMA channels\n", i); | 1005 | dev_dbg(&pdev->dev, "Initialized %i DMA channels\n", i); |
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 0cb259c59916..8c9f45fd55fc 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c | |||
@@ -289,7 +289,7 @@ enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie) | |||
289 | do { | 289 | do { |
290 | status = dma_async_is_tx_complete(chan, cookie, NULL, NULL); | 290 | status = dma_async_is_tx_complete(chan, cookie, NULL, NULL); |
291 | if (time_after_eq(jiffies, dma_sync_wait_timeout)) { | 291 | if (time_after_eq(jiffies, dma_sync_wait_timeout)) { |
292 | pr_err("%s: timeout!\n", __func__); | 292 | dev_err(chan->device->dev, "%s: timeout!\n", __func__); |
293 | return DMA_ERROR; | 293 | return DMA_ERROR; |
294 | } | 294 | } |
295 | if (status != DMA_IN_PROGRESS) | 295 | if (status != DMA_IN_PROGRESS) |
@@ -482,7 +482,8 @@ int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps) | |||
482 | device = chan->device; | 482 | device = chan->device; |
483 | 483 | ||
484 | /* check if the channel supports slave transactions */ | 484 | /* check if the channel supports slave transactions */ |
485 | if (!test_bit(DMA_SLAVE, device->cap_mask.bits)) | 485 | if (!(test_bit(DMA_SLAVE, device->cap_mask.bits) || |
486 | test_bit(DMA_CYCLIC, device->cap_mask.bits))) | ||
486 | return -ENXIO; | 487 | return -ENXIO; |
487 | 488 | ||
488 | /* | 489 | /* |
@@ -518,7 +519,7 @@ static struct dma_chan *private_candidate(const dma_cap_mask_t *mask, | |||
518 | struct dma_chan *chan; | 519 | struct dma_chan *chan; |
519 | 520 | ||
520 | if (mask && !__dma_device_satisfies_mask(dev, mask)) { | 521 | if (mask && !__dma_device_satisfies_mask(dev, mask)) { |
521 | pr_debug("%s: wrong capabilities\n", __func__); | 522 | dev_dbg(dev->dev, "%s: wrong capabilities\n", __func__); |
522 | return NULL; | 523 | return NULL; |
523 | } | 524 | } |
524 | /* devices with multiple channels need special handling as we need to | 525 | /* devices with multiple channels need special handling as we need to |
@@ -533,12 +534,12 @@ static struct dma_chan *private_candidate(const dma_cap_mask_t *mask, | |||
533 | 534 | ||
534 | list_for_each_entry(chan, &dev->channels, device_node) { | 535 | list_for_each_entry(chan, &dev->channels, device_node) { |
535 | if (chan->client_count) { | 536 | if (chan->client_count) { |
536 | pr_debug("%s: %s busy\n", | 537 | dev_dbg(dev->dev, "%s: %s busy\n", |
537 | __func__, dma_chan_name(chan)); | 538 | __func__, dma_chan_name(chan)); |
538 | continue; | 539 | continue; |
539 | } | 540 | } |
540 | if (fn && !fn(chan, fn_param)) { | 541 | if (fn && !fn(chan, fn_param)) { |
541 | pr_debug("%s: %s filter said false\n", | 542 | dev_dbg(dev->dev, "%s: %s filter said false\n", |
542 | __func__, dma_chan_name(chan)); | 543 | __func__, dma_chan_name(chan)); |
543 | continue; | 544 | continue; |
544 | } | 545 | } |
@@ -567,11 +568,12 @@ static struct dma_chan *find_candidate(struct dma_device *device, | |||
567 | 568 | ||
568 | if (err) { | 569 | if (err) { |
569 | if (err == -ENODEV) { | 570 | if (err == -ENODEV) { |
570 | pr_debug("%s: %s module removed\n", __func__, | 571 | dev_dbg(device->dev, "%s: %s module removed\n", |
571 | dma_chan_name(chan)); | 572 | __func__, dma_chan_name(chan)); |
572 | list_del_rcu(&device->global_node); | 573 | list_del_rcu(&device->global_node); |
573 | } else | 574 | } else |
574 | pr_debug("%s: failed to get %s: (%d)\n", | 575 | dev_dbg(device->dev, |
576 | "%s: failed to get %s: (%d)\n", | ||
575 | __func__, dma_chan_name(chan), err); | 577 | __func__, dma_chan_name(chan), err); |
576 | 578 | ||
577 | if (--device->privatecnt == 0) | 579 | if (--device->privatecnt == 0) |
@@ -602,7 +604,8 @@ struct dma_chan *dma_get_slave_channel(struct dma_chan *chan) | |||
602 | device->privatecnt++; | 604 | device->privatecnt++; |
603 | err = dma_chan_get(chan); | 605 | err = dma_chan_get(chan); |
604 | if (err) { | 606 | if (err) { |
605 | pr_debug("%s: failed to get %s: (%d)\n", | 607 | dev_dbg(chan->device->dev, |
608 | "%s: failed to get %s: (%d)\n", | ||
606 | __func__, dma_chan_name(chan), err); | 609 | __func__, dma_chan_name(chan), err); |
607 | chan = NULL; | 610 | chan = NULL; |
608 | if (--device->privatecnt == 0) | 611 | if (--device->privatecnt == 0) |
@@ -814,8 +817,9 @@ void dmaengine_get(void) | |||
814 | list_del_rcu(&device->global_node); | 817 | list_del_rcu(&device->global_node); |
815 | break; | 818 | break; |
816 | } else if (err) | 819 | } else if (err) |
817 | pr_debug("%s: failed to get %s: (%d)\n", | 820 | dev_dbg(chan->device->dev, |
818 | __func__, dma_chan_name(chan), err); | 821 | "%s: failed to get %s: (%d)\n", |
822 | __func__, dma_chan_name(chan), err); | ||
819 | } | 823 | } |
820 | } | 824 | } |
821 | 825 | ||
@@ -862,12 +866,12 @@ static bool device_has_all_tx_types(struct dma_device *device) | |||
862 | return false; | 866 | return false; |
863 | #endif | 867 | #endif |
864 | 868 | ||
865 | #if defined(CONFIG_ASYNC_MEMCPY) || defined(CONFIG_ASYNC_MEMCPY_MODULE) | 869 | #if IS_ENABLED(CONFIG_ASYNC_MEMCPY) |
866 | if (!dma_has_cap(DMA_MEMCPY, device->cap_mask)) | 870 | if (!dma_has_cap(DMA_MEMCPY, device->cap_mask)) |
867 | return false; | 871 | return false; |
868 | #endif | 872 | #endif |
869 | 873 | ||
870 | #if defined(CONFIG_ASYNC_XOR) || defined(CONFIG_ASYNC_XOR_MODULE) | 874 | #if IS_ENABLED(CONFIG_ASYNC_XOR) |
871 | if (!dma_has_cap(DMA_XOR, device->cap_mask)) | 875 | if (!dma_has_cap(DMA_XOR, device->cap_mask)) |
872 | return false; | 876 | return false; |
873 | 877 | ||
@@ -877,7 +881,7 @@ static bool device_has_all_tx_types(struct dma_device *device) | |||
877 | #endif | 881 | #endif |
878 | #endif | 882 | #endif |
879 | 883 | ||
880 | #if defined(CONFIG_ASYNC_PQ) || defined(CONFIG_ASYNC_PQ_MODULE) | 884 | #if IS_ENABLED(CONFIG_ASYNC_PQ) |
881 | if (!dma_has_cap(DMA_PQ, device->cap_mask)) | 885 | if (!dma_has_cap(DMA_PQ, device->cap_mask)) |
882 | return false; | 886 | return false; |
883 | 887 | ||
@@ -1222,8 +1226,9 @@ dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx) | |||
1222 | 1226 | ||
1223 | while (tx->cookie == -EBUSY) { | 1227 | while (tx->cookie == -EBUSY) { |
1224 | if (time_after_eq(jiffies, dma_sync_wait_timeout)) { | 1228 | if (time_after_eq(jiffies, dma_sync_wait_timeout)) { |
1225 | pr_err("%s timeout waiting for descriptor submission\n", | 1229 | dev_err(tx->chan->device->dev, |
1226 | __func__); | 1230 | "%s timeout waiting for descriptor submission\n", |
1231 | __func__); | ||
1227 | return DMA_ERROR; | 1232 | return DMA_ERROR; |
1228 | } | 1233 | } |
1229 | cpu_relax(); | 1234 | cpu_relax(); |
diff --git a/drivers/dma/dw/core.c b/drivers/dma/dw/core.c index 5ad0ec1f0e29..edf053f73a49 100644 --- a/drivers/dma/dw/core.c +++ b/drivers/dma/dw/core.c | |||
@@ -45,22 +45,19 @@ | |||
45 | DW_DMA_MSIZE_16; \ | 45 | DW_DMA_MSIZE_16; \ |
46 | u8 _dmsize = _is_slave ? _sconfig->dst_maxburst : \ | 46 | u8 _dmsize = _is_slave ? _sconfig->dst_maxburst : \ |
47 | DW_DMA_MSIZE_16; \ | 47 | DW_DMA_MSIZE_16; \ |
48 | u8 _dms = (_dwc->direction == DMA_MEM_TO_DEV) ? \ | ||
49 | _dwc->p_master : _dwc->m_master; \ | ||
50 | u8 _sms = (_dwc->direction == DMA_DEV_TO_MEM) ? \ | ||
51 | _dwc->p_master : _dwc->m_master; \ | ||
48 | \ | 52 | \ |
49 | (DWC_CTLL_DST_MSIZE(_dmsize) \ | 53 | (DWC_CTLL_DST_MSIZE(_dmsize) \ |
50 | | DWC_CTLL_SRC_MSIZE(_smsize) \ | 54 | | DWC_CTLL_SRC_MSIZE(_smsize) \ |
51 | | DWC_CTLL_LLP_D_EN \ | 55 | | DWC_CTLL_LLP_D_EN \ |
52 | | DWC_CTLL_LLP_S_EN \ | 56 | | DWC_CTLL_LLP_S_EN \ |
53 | | DWC_CTLL_DMS(_dwc->dst_master) \ | 57 | | DWC_CTLL_DMS(_dms) \ |
54 | | DWC_CTLL_SMS(_dwc->src_master)); \ | 58 | | DWC_CTLL_SMS(_sms)); \ |
55 | }) | 59 | }) |
56 | 60 | ||
57 | /* | ||
58 | * Number of descriptors to allocate for each channel. This should be | ||
59 | * made configurable somehow; preferably, the clients (at least the | ||
60 | * ones using slave transfers) should be able to give us a hint. | ||
61 | */ | ||
62 | #define NR_DESCS_PER_CHANNEL 64 | ||
63 | |||
64 | /* The set of bus widths supported by the DMA controller */ | 61 | /* The set of bus widths supported by the DMA controller */ |
65 | #define DW_DMA_BUSWIDTHS \ | 62 | #define DW_DMA_BUSWIDTHS \ |
66 | BIT(DMA_SLAVE_BUSWIDTH_UNDEFINED) | \ | 63 | BIT(DMA_SLAVE_BUSWIDTH_UNDEFINED) | \ |
@@ -80,76 +77,78 @@ static struct dw_desc *dwc_first_active(struct dw_dma_chan *dwc) | |||
80 | return to_dw_desc(dwc->active_list.next); | 77 | return to_dw_desc(dwc->active_list.next); |
81 | } | 78 | } |
82 | 79 | ||
83 | static struct dw_desc *dwc_desc_get(struct dw_dma_chan *dwc) | 80 | static dma_cookie_t dwc_tx_submit(struct dma_async_tx_descriptor *tx) |
84 | { | 81 | { |
85 | struct dw_desc *desc, *_desc; | 82 | struct dw_desc *desc = txd_to_dw_desc(tx); |
86 | struct dw_desc *ret = NULL; | 83 | struct dw_dma_chan *dwc = to_dw_dma_chan(tx->chan); |
87 | unsigned int i = 0; | 84 | dma_cookie_t cookie; |
88 | unsigned long flags; | 85 | unsigned long flags; |
89 | 86 | ||
90 | spin_lock_irqsave(&dwc->lock, flags); | 87 | spin_lock_irqsave(&dwc->lock, flags); |
91 | list_for_each_entry_safe(desc, _desc, &dwc->free_list, desc_node) { | 88 | cookie = dma_cookie_assign(tx); |
92 | i++; | 89 | |
93 | if (async_tx_test_ack(&desc->txd)) { | 90 | /* |
94 | list_del(&desc->desc_node); | 91 | * REVISIT: We should attempt to chain as many descriptors as |
95 | ret = desc; | 92 | * possible, perhaps even appending to those already submitted |
96 | break; | 93 | * for DMA. But this is hard to do in a race-free manner. |
97 | } | 94 | */ |
98 | dev_dbg(chan2dev(&dwc->chan), "desc %p not ACKed\n", desc); | 95 | |
99 | } | 96 | list_add_tail(&desc->desc_node, &dwc->queue); |
100 | spin_unlock_irqrestore(&dwc->lock, flags); | 97 | spin_unlock_irqrestore(&dwc->lock, flags); |
98 | dev_vdbg(chan2dev(tx->chan), "%s: queued %u\n", | ||
99 | __func__, desc->txd.cookie); | ||
101 | 100 | ||
102 | dev_vdbg(chan2dev(&dwc->chan), "scanned %u descriptors on freelist\n", i); | 101 | return cookie; |
102 | } | ||
103 | 103 | ||
104 | return ret; | 104 | static struct dw_desc *dwc_desc_get(struct dw_dma_chan *dwc) |
105 | { | ||
106 | struct dw_dma *dw = to_dw_dma(dwc->chan.device); | ||
107 | struct dw_desc *desc; | ||
108 | dma_addr_t phys; | ||
109 | |||
110 | desc = dma_pool_zalloc(dw->desc_pool, GFP_ATOMIC, &phys); | ||
111 | if (!desc) | ||
112 | return NULL; | ||
113 | |||
114 | dwc->descs_allocated++; | ||
115 | INIT_LIST_HEAD(&desc->tx_list); | ||
116 | dma_async_tx_descriptor_init(&desc->txd, &dwc->chan); | ||
117 | desc->txd.tx_submit = dwc_tx_submit; | ||
118 | desc->txd.flags = DMA_CTRL_ACK; | ||
119 | desc->txd.phys = phys; | ||
120 | return desc; | ||
105 | } | 121 | } |
106 | 122 | ||
107 | /* | ||
108 | * Move a descriptor, including any children, to the free list. | ||
109 | * `desc' must not be on any lists. | ||
110 | */ | ||
111 | static void dwc_desc_put(struct dw_dma_chan *dwc, struct dw_desc *desc) | 123 | static void dwc_desc_put(struct dw_dma_chan *dwc, struct dw_desc *desc) |
112 | { | 124 | { |
113 | unsigned long flags; | 125 | struct dw_dma *dw = to_dw_dma(dwc->chan.device); |
126 | struct dw_desc *child, *_next; | ||
114 | 127 | ||
115 | if (desc) { | 128 | if (unlikely(!desc)) |
116 | struct dw_desc *child; | 129 | return; |
117 | 130 | ||
118 | spin_lock_irqsave(&dwc->lock, flags); | 131 | list_for_each_entry_safe(child, _next, &desc->tx_list, desc_node) { |
119 | list_for_each_entry(child, &desc->tx_list, desc_node) | 132 | list_del(&child->desc_node); |
120 | dev_vdbg(chan2dev(&dwc->chan), | 133 | dma_pool_free(dw->desc_pool, child, child->txd.phys); |
121 | "moving child desc %p to freelist\n", | 134 | dwc->descs_allocated--; |
122 | child); | ||
123 | list_splice_init(&desc->tx_list, &dwc->free_list); | ||
124 | dev_vdbg(chan2dev(&dwc->chan), "moving desc %p to freelist\n", desc); | ||
125 | list_add(&desc->desc_node, &dwc->free_list); | ||
126 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
127 | } | 135 | } |
136 | |||
137 | dma_pool_free(dw->desc_pool, desc, desc->txd.phys); | ||
138 | dwc->descs_allocated--; | ||
128 | } | 139 | } |
129 | 140 | ||
130 | static void dwc_initialize(struct dw_dma_chan *dwc) | 141 | static void dwc_initialize(struct dw_dma_chan *dwc) |
131 | { | 142 | { |
132 | struct dw_dma *dw = to_dw_dma(dwc->chan.device); | 143 | struct dw_dma *dw = to_dw_dma(dwc->chan.device); |
133 | struct dw_dma_slave *dws = dwc->chan.private; | ||
134 | u32 cfghi = DWC_CFGH_FIFO_MODE; | 144 | u32 cfghi = DWC_CFGH_FIFO_MODE; |
135 | u32 cfglo = DWC_CFGL_CH_PRIOR(dwc->priority); | 145 | u32 cfglo = DWC_CFGL_CH_PRIOR(dwc->priority); |
136 | 146 | ||
137 | if (dwc->initialized == true) | 147 | if (test_bit(DW_DMA_IS_INITIALIZED, &dwc->flags)) |
138 | return; | 148 | return; |
139 | 149 | ||
140 | if (dws) { | 150 | cfghi |= DWC_CFGH_DST_PER(dwc->dst_id); |
141 | /* | 151 | cfghi |= DWC_CFGH_SRC_PER(dwc->src_id); |
142 | * We need controller-specific data to set up slave | ||
143 | * transfers. | ||
144 | */ | ||
145 | BUG_ON(!dws->dma_dev || dws->dma_dev != dw->dma.dev); | ||
146 | |||
147 | cfghi |= DWC_CFGH_DST_PER(dws->dst_id); | ||
148 | cfghi |= DWC_CFGH_SRC_PER(dws->src_id); | ||
149 | } else { | ||
150 | cfghi |= DWC_CFGH_DST_PER(dwc->dst_id); | ||
151 | cfghi |= DWC_CFGH_SRC_PER(dwc->src_id); | ||
152 | } | ||
153 | 152 | ||
154 | channel_writel(dwc, CFG_LO, cfglo); | 153 | channel_writel(dwc, CFG_LO, cfglo); |
155 | channel_writel(dwc, CFG_HI, cfghi); | 154 | channel_writel(dwc, CFG_HI, cfghi); |
@@ -158,26 +157,11 @@ static void dwc_initialize(struct dw_dma_chan *dwc) | |||
158 | channel_set_bit(dw, MASK.XFER, dwc->mask); | 157 | channel_set_bit(dw, MASK.XFER, dwc->mask); |
159 | channel_set_bit(dw, MASK.ERROR, dwc->mask); | 158 | channel_set_bit(dw, MASK.ERROR, dwc->mask); |
160 | 159 | ||
161 | dwc->initialized = true; | 160 | set_bit(DW_DMA_IS_INITIALIZED, &dwc->flags); |
162 | } | 161 | } |
163 | 162 | ||
164 | /*----------------------------------------------------------------------*/ | 163 | /*----------------------------------------------------------------------*/ |
165 | 164 | ||
166 | static inline unsigned int dwc_fast_ffs(unsigned long long v) | ||
167 | { | ||
168 | /* | ||
169 | * We can be a lot more clever here, but this should take care | ||
170 | * of the most common optimization. | ||
171 | */ | ||
172 | if (!(v & 7)) | ||
173 | return 3; | ||
174 | else if (!(v & 3)) | ||
175 | return 2; | ||
176 | else if (!(v & 1)) | ||
177 | return 1; | ||
178 | return 0; | ||
179 | } | ||
180 | |||
181 | static inline void dwc_dump_chan_regs(struct dw_dma_chan *dwc) | 165 | static inline void dwc_dump_chan_regs(struct dw_dma_chan *dwc) |
182 | { | 166 | { |
183 | dev_err(chan2dev(&dwc->chan), | 167 | dev_err(chan2dev(&dwc->chan), |
@@ -209,12 +193,12 @@ static inline void dwc_do_single_block(struct dw_dma_chan *dwc, | |||
209 | * Software emulation of LLP mode relies on interrupts to continue | 193 | * Software emulation of LLP mode relies on interrupts to continue |
210 | * multi block transfer. | 194 | * multi block transfer. |
211 | */ | 195 | */ |
212 | ctllo = desc->lli.ctllo | DWC_CTLL_INT_EN; | 196 | ctllo = lli_read(desc, ctllo) | DWC_CTLL_INT_EN; |
213 | 197 | ||
214 | channel_writel(dwc, SAR, desc->lli.sar); | 198 | channel_writel(dwc, SAR, lli_read(desc, sar)); |
215 | channel_writel(dwc, DAR, desc->lli.dar); | 199 | channel_writel(dwc, DAR, lli_read(desc, dar)); |
216 | channel_writel(dwc, CTL_LO, ctllo); | 200 | channel_writel(dwc, CTL_LO, ctllo); |
217 | channel_writel(dwc, CTL_HI, desc->lli.ctlhi); | 201 | channel_writel(dwc, CTL_HI, lli_read(desc, ctlhi)); |
218 | channel_set_bit(dw, CH_EN, dwc->mask); | 202 | channel_set_bit(dw, CH_EN, dwc->mask); |
219 | 203 | ||
220 | /* Move pointer to next descriptor */ | 204 | /* Move pointer to next descriptor */ |
@@ -225,6 +209,7 @@ static inline void dwc_do_single_block(struct dw_dma_chan *dwc, | |||
225 | static void dwc_dostart(struct dw_dma_chan *dwc, struct dw_desc *first) | 209 | static void dwc_dostart(struct dw_dma_chan *dwc, struct dw_desc *first) |
226 | { | 210 | { |
227 | struct dw_dma *dw = to_dw_dma(dwc->chan.device); | 211 | struct dw_dma *dw = to_dw_dma(dwc->chan.device); |
212 | u8 lms = DWC_LLP_LMS(dwc->m_master); | ||
228 | unsigned long was_soft_llp; | 213 | unsigned long was_soft_llp; |
229 | 214 | ||
230 | /* ASSERT: channel is idle */ | 215 | /* ASSERT: channel is idle */ |
@@ -249,7 +234,7 @@ static void dwc_dostart(struct dw_dma_chan *dwc, struct dw_desc *first) | |||
249 | 234 | ||
250 | dwc_initialize(dwc); | 235 | dwc_initialize(dwc); |
251 | 236 | ||
252 | dwc->residue = first->total_len; | 237 | first->residue = first->total_len; |
253 | dwc->tx_node_active = &first->tx_list; | 238 | dwc->tx_node_active = &first->tx_list; |
254 | 239 | ||
255 | /* Submit first block */ | 240 | /* Submit first block */ |
@@ -260,9 +245,8 @@ static void dwc_dostart(struct dw_dma_chan *dwc, struct dw_desc *first) | |||
260 | 245 | ||
261 | dwc_initialize(dwc); | 246 | dwc_initialize(dwc); |
262 | 247 | ||
263 | channel_writel(dwc, LLP, first->txd.phys); | 248 | channel_writel(dwc, LLP, first->txd.phys | lms); |
264 | channel_writel(dwc, CTL_LO, | 249 | channel_writel(dwc, CTL_LO, DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN); |
265 | DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN); | ||
266 | channel_writel(dwc, CTL_HI, 0); | 250 | channel_writel(dwc, CTL_HI, 0); |
267 | channel_set_bit(dw, CH_EN, dwc->mask); | 251 | channel_set_bit(dw, CH_EN, dwc->mask); |
268 | } | 252 | } |
@@ -305,11 +289,7 @@ dwc_descriptor_complete(struct dw_dma_chan *dwc, struct dw_desc *desc, | |||
305 | list_for_each_entry(child, &desc->tx_list, desc_node) | 289 | list_for_each_entry(child, &desc->tx_list, desc_node) |
306 | async_tx_ack(&child->txd); | 290 | async_tx_ack(&child->txd); |
307 | async_tx_ack(&desc->txd); | 291 | async_tx_ack(&desc->txd); |
308 | 292 | dwc_desc_put(dwc, desc); | |
309 | list_splice_init(&desc->tx_list, &dwc->free_list); | ||
310 | list_move(&desc->desc_node, &dwc->free_list); | ||
311 | |||
312 | dma_descriptor_unmap(txd); | ||
313 | spin_unlock_irqrestore(&dwc->lock, flags); | 293 | spin_unlock_irqrestore(&dwc->lock, flags); |
314 | 294 | ||
315 | if (callback) | 295 | if (callback) |
@@ -380,11 +360,11 @@ static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc) | |||
380 | 360 | ||
381 | head = &desc->tx_list; | 361 | head = &desc->tx_list; |
382 | if (active != head) { | 362 | if (active != head) { |
383 | /* Update desc to reflect last sent one */ | 363 | /* Update residue to reflect last sent descriptor */ |
384 | if (active != head->next) | 364 | if (active == head->next) |
385 | desc = to_dw_desc(active->prev); | 365 | desc->residue -= desc->len; |
386 | 366 | else | |
387 | dwc->residue -= desc->len; | 367 | desc->residue -= to_dw_desc(active->prev)->len; |
388 | 368 | ||
389 | child = to_dw_desc(active); | 369 | child = to_dw_desc(active); |
390 | 370 | ||
@@ -399,8 +379,6 @@ static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc) | |||
399 | clear_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags); | 379 | clear_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags); |
400 | } | 380 | } |
401 | 381 | ||
402 | dwc->residue = 0; | ||
403 | |||
404 | spin_unlock_irqrestore(&dwc->lock, flags); | 382 | spin_unlock_irqrestore(&dwc->lock, flags); |
405 | 383 | ||
406 | dwc_complete_all(dw, dwc); | 384 | dwc_complete_all(dw, dwc); |
@@ -408,7 +386,6 @@ static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc) | |||
408 | } | 386 | } |
409 | 387 | ||
410 | if (list_empty(&dwc->active_list)) { | 388 | if (list_empty(&dwc->active_list)) { |
411 | dwc->residue = 0; | ||
412 | spin_unlock_irqrestore(&dwc->lock, flags); | 389 | spin_unlock_irqrestore(&dwc->lock, flags); |
413 | return; | 390 | return; |
414 | } | 391 | } |
@@ -423,31 +400,31 @@ static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc) | |||
423 | 400 | ||
424 | list_for_each_entry_safe(desc, _desc, &dwc->active_list, desc_node) { | 401 | list_for_each_entry_safe(desc, _desc, &dwc->active_list, desc_node) { |
425 | /* Initial residue value */ | 402 | /* Initial residue value */ |
426 | dwc->residue = desc->total_len; | 403 | desc->residue = desc->total_len; |
427 | 404 | ||
428 | /* Check first descriptors addr */ | 405 | /* Check first descriptors addr */ |
429 | if (desc->txd.phys == llp) { | 406 | if (desc->txd.phys == DWC_LLP_LOC(llp)) { |
430 | spin_unlock_irqrestore(&dwc->lock, flags); | 407 | spin_unlock_irqrestore(&dwc->lock, flags); |
431 | return; | 408 | return; |
432 | } | 409 | } |
433 | 410 | ||
434 | /* Check first descriptors llp */ | 411 | /* Check first descriptors llp */ |
435 | if (desc->lli.llp == llp) { | 412 | if (lli_read(desc, llp) == llp) { |
436 | /* This one is currently in progress */ | 413 | /* This one is currently in progress */ |
437 | dwc->residue -= dwc_get_sent(dwc); | 414 | desc->residue -= dwc_get_sent(dwc); |
438 | spin_unlock_irqrestore(&dwc->lock, flags); | 415 | spin_unlock_irqrestore(&dwc->lock, flags); |
439 | return; | 416 | return; |
440 | } | 417 | } |
441 | 418 | ||
442 | dwc->residue -= desc->len; | 419 | desc->residue -= desc->len; |
443 | list_for_each_entry(child, &desc->tx_list, desc_node) { | 420 | list_for_each_entry(child, &desc->tx_list, desc_node) { |
444 | if (child->lli.llp == llp) { | 421 | if (lli_read(child, llp) == llp) { |
445 | /* Currently in progress */ | 422 | /* Currently in progress */ |
446 | dwc->residue -= dwc_get_sent(dwc); | 423 | desc->residue -= dwc_get_sent(dwc); |
447 | spin_unlock_irqrestore(&dwc->lock, flags); | 424 | spin_unlock_irqrestore(&dwc->lock, flags); |
448 | return; | 425 | return; |
449 | } | 426 | } |
450 | dwc->residue -= child->len; | 427 | desc->residue -= child->len; |
451 | } | 428 | } |
452 | 429 | ||
453 | /* | 430 | /* |
@@ -469,10 +446,14 @@ static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc) | |||
469 | spin_unlock_irqrestore(&dwc->lock, flags); | 446 | spin_unlock_irqrestore(&dwc->lock, flags); |
470 | } | 447 | } |
471 | 448 | ||
472 | static inline void dwc_dump_lli(struct dw_dma_chan *dwc, struct dw_lli *lli) | 449 | static inline void dwc_dump_lli(struct dw_dma_chan *dwc, struct dw_desc *desc) |
473 | { | 450 | { |
474 | dev_crit(chan2dev(&dwc->chan), " desc: s0x%x d0x%x l0x%x c0x%x:%x\n", | 451 | dev_crit(chan2dev(&dwc->chan), " desc: s0x%x d0x%x l0x%x c0x%x:%x\n", |
475 | lli->sar, lli->dar, lli->llp, lli->ctlhi, lli->ctllo); | 452 | lli_read(desc, sar), |
453 | lli_read(desc, dar), | ||
454 | lli_read(desc, llp), | ||
455 | lli_read(desc, ctlhi), | ||
456 | lli_read(desc, ctllo)); | ||
476 | } | 457 | } |
477 | 458 | ||
478 | static void dwc_handle_error(struct dw_dma *dw, struct dw_dma_chan *dwc) | 459 | static void dwc_handle_error(struct dw_dma *dw, struct dw_dma_chan *dwc) |
@@ -508,9 +489,9 @@ static void dwc_handle_error(struct dw_dma *dw, struct dw_dma_chan *dwc) | |||
508 | */ | 489 | */ |
509 | dev_WARN(chan2dev(&dwc->chan), "Bad descriptor submitted for DMA!\n" | 490 | dev_WARN(chan2dev(&dwc->chan), "Bad descriptor submitted for DMA!\n" |
510 | " cookie: %d\n", bad_desc->txd.cookie); | 491 | " cookie: %d\n", bad_desc->txd.cookie); |
511 | dwc_dump_lli(dwc, &bad_desc->lli); | 492 | dwc_dump_lli(dwc, bad_desc); |
512 | list_for_each_entry(child, &bad_desc->tx_list, desc_node) | 493 | list_for_each_entry(child, &bad_desc->tx_list, desc_node) |
513 | dwc_dump_lli(dwc, &child->lli); | 494 | dwc_dump_lli(dwc, child); |
514 | 495 | ||
515 | spin_unlock_irqrestore(&dwc->lock, flags); | 496 | spin_unlock_irqrestore(&dwc->lock, flags); |
516 | 497 | ||
@@ -561,7 +542,7 @@ static void dwc_handle_cyclic(struct dw_dma *dw, struct dw_dma_chan *dwc, | |||
561 | */ | 542 | */ |
562 | if (unlikely(status_err & dwc->mask) || | 543 | if (unlikely(status_err & dwc->mask) || |
563 | unlikely(status_xfer & dwc->mask)) { | 544 | unlikely(status_xfer & dwc->mask)) { |
564 | int i; | 545 | unsigned int i; |
565 | 546 | ||
566 | dev_err(chan2dev(&dwc->chan), | 547 | dev_err(chan2dev(&dwc->chan), |
567 | "cyclic DMA unexpected %s interrupt, stopping DMA transfer\n", | 548 | "cyclic DMA unexpected %s interrupt, stopping DMA transfer\n", |
@@ -583,7 +564,7 @@ static void dwc_handle_cyclic(struct dw_dma *dw, struct dw_dma_chan *dwc, | |||
583 | dma_writel(dw, CLEAR.XFER, dwc->mask); | 564 | dma_writel(dw, CLEAR.XFER, dwc->mask); |
584 | 565 | ||
585 | for (i = 0; i < dwc->cdesc->periods; i++) | 566 | for (i = 0; i < dwc->cdesc->periods; i++) |
586 | dwc_dump_lli(dwc, &dwc->cdesc->desc[i]->lli); | 567 | dwc_dump_lli(dwc, dwc->cdesc->desc[i]); |
587 | 568 | ||
588 | spin_unlock_irqrestore(&dwc->lock, flags); | 569 | spin_unlock_irqrestore(&dwc->lock, flags); |
589 | } | 570 | } |
@@ -601,7 +582,7 @@ static void dw_dma_tasklet(unsigned long data) | |||
601 | u32 status_block; | 582 | u32 status_block; |
602 | u32 status_xfer; | 583 | u32 status_xfer; |
603 | u32 status_err; | 584 | u32 status_err; |
604 | int i; | 585 | unsigned int i; |
605 | 586 | ||
606 | status_block = dma_readl(dw, RAW.BLOCK); | 587 | status_block = dma_readl(dw, RAW.BLOCK); |
607 | status_xfer = dma_readl(dw, RAW.XFER); | 588 | status_xfer = dma_readl(dw, RAW.XFER); |
@@ -670,30 +651,6 @@ static irqreturn_t dw_dma_interrupt(int irq, void *dev_id) | |||
670 | 651 | ||
671 | /*----------------------------------------------------------------------*/ | 652 | /*----------------------------------------------------------------------*/ |
672 | 653 | ||
673 | static dma_cookie_t dwc_tx_submit(struct dma_async_tx_descriptor *tx) | ||
674 | { | ||
675 | struct dw_desc *desc = txd_to_dw_desc(tx); | ||
676 | struct dw_dma_chan *dwc = to_dw_dma_chan(tx->chan); | ||
677 | dma_cookie_t cookie; | ||
678 | unsigned long flags; | ||
679 | |||
680 | spin_lock_irqsave(&dwc->lock, flags); | ||
681 | cookie = dma_cookie_assign(tx); | ||
682 | |||
683 | /* | ||
684 | * REVISIT: We should attempt to chain as many descriptors as | ||
685 | * possible, perhaps even appending to those already submitted | ||
686 | * for DMA. But this is hard to do in a race-free manner. | ||
687 | */ | ||
688 | |||
689 | dev_vdbg(chan2dev(tx->chan), "%s: queued %u\n", __func__, desc->txd.cookie); | ||
690 | list_add_tail(&desc->desc_node, &dwc->queue); | ||
691 | |||
692 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
693 | |||
694 | return cookie; | ||
695 | } | ||
696 | |||
697 | static struct dma_async_tx_descriptor * | 654 | static struct dma_async_tx_descriptor * |
698 | dwc_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, | 655 | dwc_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, |
699 | size_t len, unsigned long flags) | 656 | size_t len, unsigned long flags) |
@@ -705,10 +662,12 @@ dwc_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, | |||
705 | struct dw_desc *prev; | 662 | struct dw_desc *prev; |
706 | size_t xfer_count; | 663 | size_t xfer_count; |
707 | size_t offset; | 664 | size_t offset; |
665 | u8 m_master = dwc->m_master; | ||
708 | unsigned int src_width; | 666 | unsigned int src_width; |
709 | unsigned int dst_width; | 667 | unsigned int dst_width; |
710 | unsigned int data_width; | 668 | unsigned int data_width = dw->pdata->data_width[m_master]; |
711 | u32 ctllo; | 669 | u32 ctllo; |
670 | u8 lms = DWC_LLP_LMS(m_master); | ||
712 | 671 | ||
713 | dev_vdbg(chan2dev(chan), | 672 | dev_vdbg(chan2dev(chan), |
714 | "%s: d%pad s%pad l0x%zx f0x%lx\n", __func__, | 673 | "%s: d%pad s%pad l0x%zx f0x%lx\n", __func__, |
@@ -721,11 +680,7 @@ dwc_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, | |||
721 | 680 | ||
722 | dwc->direction = DMA_MEM_TO_MEM; | 681 | dwc->direction = DMA_MEM_TO_MEM; |
723 | 682 | ||
724 | data_width = min_t(unsigned int, dw->data_width[dwc->src_master], | 683 | src_width = dst_width = __ffs(data_width | src | dest | len); |
725 | dw->data_width[dwc->dst_master]); | ||
726 | |||
727 | src_width = dst_width = min_t(unsigned int, data_width, | ||
728 | dwc_fast_ffs(src | dest | len)); | ||
729 | 684 | ||
730 | ctllo = DWC_DEFAULT_CTLLO(chan) | 685 | ctllo = DWC_DEFAULT_CTLLO(chan) |
731 | | DWC_CTLL_DST_WIDTH(dst_width) | 686 | | DWC_CTLL_DST_WIDTH(dst_width) |
@@ -743,27 +698,27 @@ dwc_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, | |||
743 | if (!desc) | 698 | if (!desc) |
744 | goto err_desc_get; | 699 | goto err_desc_get; |
745 | 700 | ||
746 | desc->lli.sar = src + offset; | 701 | lli_write(desc, sar, src + offset); |
747 | desc->lli.dar = dest + offset; | 702 | lli_write(desc, dar, dest + offset); |
748 | desc->lli.ctllo = ctllo; | 703 | lli_write(desc, ctllo, ctllo); |
749 | desc->lli.ctlhi = xfer_count; | 704 | lli_write(desc, ctlhi, xfer_count); |
750 | desc->len = xfer_count << src_width; | 705 | desc->len = xfer_count << src_width; |
751 | 706 | ||
752 | if (!first) { | 707 | if (!first) { |
753 | first = desc; | 708 | first = desc; |
754 | } else { | 709 | } else { |
755 | prev->lli.llp = desc->txd.phys; | 710 | lli_write(prev, llp, desc->txd.phys | lms); |
756 | list_add_tail(&desc->desc_node, | 711 | list_add_tail(&desc->desc_node, &first->tx_list); |
757 | &first->tx_list); | ||
758 | } | 712 | } |
759 | prev = desc; | 713 | prev = desc; |
760 | } | 714 | } |
761 | 715 | ||
762 | if (flags & DMA_PREP_INTERRUPT) | 716 | if (flags & DMA_PREP_INTERRUPT) |
763 | /* Trigger interrupt after last block */ | 717 | /* Trigger interrupt after last block */ |
764 | prev->lli.ctllo |= DWC_CTLL_INT_EN; | 718 | lli_set(prev, ctllo, DWC_CTLL_INT_EN); |
765 | 719 | ||
766 | prev->lli.llp = 0; | 720 | prev->lli.llp = 0; |
721 | lli_clear(prev, ctllo, DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN); | ||
767 | first->txd.flags = flags; | 722 | first->txd.flags = flags; |
768 | first->total_len = len; | 723 | first->total_len = len; |
769 | 724 | ||
@@ -785,10 +740,12 @@ dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, | |||
785 | struct dw_desc *prev; | 740 | struct dw_desc *prev; |
786 | struct dw_desc *first; | 741 | struct dw_desc *first; |
787 | u32 ctllo; | 742 | u32 ctllo; |
743 | u8 m_master = dwc->m_master; | ||
744 | u8 lms = DWC_LLP_LMS(m_master); | ||
788 | dma_addr_t reg; | 745 | dma_addr_t reg; |
789 | unsigned int reg_width; | 746 | unsigned int reg_width; |
790 | unsigned int mem_width; | 747 | unsigned int mem_width; |
791 | unsigned int data_width; | 748 | unsigned int data_width = dw->pdata->data_width[m_master]; |
792 | unsigned int i; | 749 | unsigned int i; |
793 | struct scatterlist *sg; | 750 | struct scatterlist *sg; |
794 | size_t total_len = 0; | 751 | size_t total_len = 0; |
@@ -814,8 +771,6 @@ dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, | |||
814 | ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_M2P) : | 771 | ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_M2P) : |
815 | DWC_CTLL_FC(DW_DMA_FC_D_M2P); | 772 | DWC_CTLL_FC(DW_DMA_FC_D_M2P); |
816 | 773 | ||
817 | data_width = dw->data_width[dwc->src_master]; | ||
818 | |||
819 | for_each_sg(sgl, sg, sg_len, i) { | 774 | for_each_sg(sgl, sg, sg_len, i) { |
820 | struct dw_desc *desc; | 775 | struct dw_desc *desc; |
821 | u32 len, dlen, mem; | 776 | u32 len, dlen, mem; |
@@ -823,17 +778,16 @@ dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, | |||
823 | mem = sg_dma_address(sg); | 778 | mem = sg_dma_address(sg); |
824 | len = sg_dma_len(sg); | 779 | len = sg_dma_len(sg); |
825 | 780 | ||
826 | mem_width = min_t(unsigned int, | 781 | mem_width = __ffs(data_width | mem | len); |
827 | data_width, dwc_fast_ffs(mem | len)); | ||
828 | 782 | ||
829 | slave_sg_todev_fill_desc: | 783 | slave_sg_todev_fill_desc: |
830 | desc = dwc_desc_get(dwc); | 784 | desc = dwc_desc_get(dwc); |
831 | if (!desc) | 785 | if (!desc) |
832 | goto err_desc_get; | 786 | goto err_desc_get; |
833 | 787 | ||
834 | desc->lli.sar = mem; | 788 | lli_write(desc, sar, mem); |
835 | desc->lli.dar = reg; | 789 | lli_write(desc, dar, reg); |
836 | desc->lli.ctllo = ctllo | DWC_CTLL_SRC_WIDTH(mem_width); | 790 | lli_write(desc, ctllo, ctllo | DWC_CTLL_SRC_WIDTH(mem_width)); |
837 | if ((len >> mem_width) > dwc->block_size) { | 791 | if ((len >> mem_width) > dwc->block_size) { |
838 | dlen = dwc->block_size << mem_width; | 792 | dlen = dwc->block_size << mem_width; |
839 | mem += dlen; | 793 | mem += dlen; |
@@ -843,15 +797,14 @@ slave_sg_todev_fill_desc: | |||
843 | len = 0; | 797 | len = 0; |
844 | } | 798 | } |
845 | 799 | ||
846 | desc->lli.ctlhi = dlen >> mem_width; | 800 | lli_write(desc, ctlhi, dlen >> mem_width); |
847 | desc->len = dlen; | 801 | desc->len = dlen; |
848 | 802 | ||
849 | if (!first) { | 803 | if (!first) { |
850 | first = desc; | 804 | first = desc; |
851 | } else { | 805 | } else { |
852 | prev->lli.llp = desc->txd.phys; | 806 | lli_write(prev, llp, desc->txd.phys | lms); |
853 | list_add_tail(&desc->desc_node, | 807 | list_add_tail(&desc->desc_node, &first->tx_list); |
854 | &first->tx_list); | ||
855 | } | 808 | } |
856 | prev = desc; | 809 | prev = desc; |
857 | total_len += dlen; | 810 | total_len += dlen; |
@@ -871,8 +824,6 @@ slave_sg_todev_fill_desc: | |||
871 | ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_P2M) : | 824 | ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_P2M) : |
872 | DWC_CTLL_FC(DW_DMA_FC_D_P2M); | 825 | DWC_CTLL_FC(DW_DMA_FC_D_P2M); |
873 | 826 | ||
874 | data_width = dw->data_width[dwc->dst_master]; | ||
875 | |||
876 | for_each_sg(sgl, sg, sg_len, i) { | 827 | for_each_sg(sgl, sg, sg_len, i) { |
877 | struct dw_desc *desc; | 828 | struct dw_desc *desc; |
878 | u32 len, dlen, mem; | 829 | u32 len, dlen, mem; |
@@ -880,17 +831,16 @@ slave_sg_todev_fill_desc: | |||
880 | mem = sg_dma_address(sg); | 831 | mem = sg_dma_address(sg); |
881 | len = sg_dma_len(sg); | 832 | len = sg_dma_len(sg); |
882 | 833 | ||
883 | mem_width = min_t(unsigned int, | 834 | mem_width = __ffs(data_width | mem | len); |
884 | data_width, dwc_fast_ffs(mem | len)); | ||
885 | 835 | ||
886 | slave_sg_fromdev_fill_desc: | 836 | slave_sg_fromdev_fill_desc: |
887 | desc = dwc_desc_get(dwc); | 837 | desc = dwc_desc_get(dwc); |
888 | if (!desc) | 838 | if (!desc) |
889 | goto err_desc_get; | 839 | goto err_desc_get; |
890 | 840 | ||
891 | desc->lli.sar = reg; | 841 | lli_write(desc, sar, reg); |
892 | desc->lli.dar = mem; | 842 | lli_write(desc, dar, mem); |
893 | desc->lli.ctllo = ctllo | DWC_CTLL_DST_WIDTH(mem_width); | 843 | lli_write(desc, ctllo, ctllo | DWC_CTLL_DST_WIDTH(mem_width)); |
894 | if ((len >> reg_width) > dwc->block_size) { | 844 | if ((len >> reg_width) > dwc->block_size) { |
895 | dlen = dwc->block_size << reg_width; | 845 | dlen = dwc->block_size << reg_width; |
896 | mem += dlen; | 846 | mem += dlen; |
@@ -899,15 +849,14 @@ slave_sg_fromdev_fill_desc: | |||
899 | dlen = len; | 849 | dlen = len; |
900 | len = 0; | 850 | len = 0; |
901 | } | 851 | } |
902 | desc->lli.ctlhi = dlen >> reg_width; | 852 | lli_write(desc, ctlhi, dlen >> reg_width); |
903 | desc->len = dlen; | 853 | desc->len = dlen; |
904 | 854 | ||
905 | if (!first) { | 855 | if (!first) { |
906 | first = desc; | 856 | first = desc; |
907 | } else { | 857 | } else { |
908 | prev->lli.llp = desc->txd.phys; | 858 | lli_write(prev, llp, desc->txd.phys | lms); |
909 | list_add_tail(&desc->desc_node, | 859 | list_add_tail(&desc->desc_node, &first->tx_list); |
910 | &first->tx_list); | ||
911 | } | 860 | } |
912 | prev = desc; | 861 | prev = desc; |
913 | total_len += dlen; | 862 | total_len += dlen; |
@@ -922,9 +871,10 @@ slave_sg_fromdev_fill_desc: | |||
922 | 871 | ||
923 | if (flags & DMA_PREP_INTERRUPT) | 872 | if (flags & DMA_PREP_INTERRUPT) |
924 | /* Trigger interrupt after last block */ | 873 | /* Trigger interrupt after last block */ |
925 | prev->lli.ctllo |= DWC_CTLL_INT_EN; | 874 | lli_set(prev, ctllo, DWC_CTLL_INT_EN); |
926 | 875 | ||
927 | prev->lli.llp = 0; | 876 | prev->lli.llp = 0; |
877 | lli_clear(prev, ctllo, DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN); | ||
928 | first->total_len = total_len; | 878 | first->total_len = total_len; |
929 | 879 | ||
930 | return &first->txd; | 880 | return &first->txd; |
@@ -941,7 +891,7 @@ bool dw_dma_filter(struct dma_chan *chan, void *param) | |||
941 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); | 891 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
942 | struct dw_dma_slave *dws = param; | 892 | struct dw_dma_slave *dws = param; |
943 | 893 | ||
944 | if (!dws || dws->dma_dev != chan->device->dev) | 894 | if (dws->dma_dev != chan->device->dev) |
945 | return false; | 895 | return false; |
946 | 896 | ||
947 | /* We have to copy data since dws can be temporary storage */ | 897 | /* We have to copy data since dws can be temporary storage */ |
@@ -949,8 +899,8 @@ bool dw_dma_filter(struct dma_chan *chan, void *param) | |||
949 | dwc->src_id = dws->src_id; | 899 | dwc->src_id = dws->src_id; |
950 | dwc->dst_id = dws->dst_id; | 900 | dwc->dst_id = dws->dst_id; |
951 | 901 | ||
952 | dwc->src_master = dws->src_master; | 902 | dwc->m_master = dws->m_master; |
953 | dwc->dst_master = dws->dst_master; | 903 | dwc->p_master = dws->p_master; |
954 | 904 | ||
955 | return true; | 905 | return true; |
956 | } | 906 | } |
@@ -1003,7 +953,7 @@ static int dwc_pause(struct dma_chan *chan) | |||
1003 | while (!(channel_readl(dwc, CFG_LO) & DWC_CFGL_FIFO_EMPTY) && count--) | 953 | while (!(channel_readl(dwc, CFG_LO) & DWC_CFGL_FIFO_EMPTY) && count--) |
1004 | udelay(2); | 954 | udelay(2); |
1005 | 955 | ||
1006 | dwc->paused = true; | 956 | set_bit(DW_DMA_IS_PAUSED, &dwc->flags); |
1007 | 957 | ||
1008 | spin_unlock_irqrestore(&dwc->lock, flags); | 958 | spin_unlock_irqrestore(&dwc->lock, flags); |
1009 | 959 | ||
@@ -1016,7 +966,7 @@ static inline void dwc_chan_resume(struct dw_dma_chan *dwc) | |||
1016 | 966 | ||
1017 | channel_writel(dwc, CFG_LO, cfglo & ~DWC_CFGL_CH_SUSP); | 967 | channel_writel(dwc, CFG_LO, cfglo & ~DWC_CFGL_CH_SUSP); |
1018 | 968 | ||
1019 | dwc->paused = false; | 969 | clear_bit(DW_DMA_IS_PAUSED, &dwc->flags); |
1020 | } | 970 | } |
1021 | 971 | ||
1022 | static int dwc_resume(struct dma_chan *chan) | 972 | static int dwc_resume(struct dma_chan *chan) |
@@ -1024,12 +974,10 @@ static int dwc_resume(struct dma_chan *chan) | |||
1024 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); | 974 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
1025 | unsigned long flags; | 975 | unsigned long flags; |
1026 | 976 | ||
1027 | if (!dwc->paused) | ||
1028 | return 0; | ||
1029 | |||
1030 | spin_lock_irqsave(&dwc->lock, flags); | 977 | spin_lock_irqsave(&dwc->lock, flags); |
1031 | 978 | ||
1032 | dwc_chan_resume(dwc); | 979 | if (test_bit(DW_DMA_IS_PAUSED, &dwc->flags)) |
980 | dwc_chan_resume(dwc); | ||
1033 | 981 | ||
1034 | spin_unlock_irqrestore(&dwc->lock, flags); | 982 | spin_unlock_irqrestore(&dwc->lock, flags); |
1035 | 983 | ||
@@ -1065,16 +1013,37 @@ static int dwc_terminate_all(struct dma_chan *chan) | |||
1065 | return 0; | 1013 | return 0; |
1066 | } | 1014 | } |
1067 | 1015 | ||
1068 | static inline u32 dwc_get_residue(struct dw_dma_chan *dwc) | 1016 | static struct dw_desc *dwc_find_desc(struct dw_dma_chan *dwc, dma_cookie_t c) |
1017 | { | ||
1018 | struct dw_desc *desc; | ||
1019 | |||
1020 | list_for_each_entry(desc, &dwc->active_list, desc_node) | ||
1021 | if (desc->txd.cookie == c) | ||
1022 | return desc; | ||
1023 | |||
1024 | return NULL; | ||
1025 | } | ||
1026 | |||
1027 | static u32 dwc_get_residue(struct dw_dma_chan *dwc, dma_cookie_t cookie) | ||
1069 | { | 1028 | { |
1029 | struct dw_desc *desc; | ||
1070 | unsigned long flags; | 1030 | unsigned long flags; |
1071 | u32 residue; | 1031 | u32 residue; |
1072 | 1032 | ||
1073 | spin_lock_irqsave(&dwc->lock, flags); | 1033 | spin_lock_irqsave(&dwc->lock, flags); |
1074 | 1034 | ||
1075 | residue = dwc->residue; | 1035 | desc = dwc_find_desc(dwc, cookie); |
1076 | if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags) && residue) | 1036 | if (desc) { |
1077 | residue -= dwc_get_sent(dwc); | 1037 | if (desc == dwc_first_active(dwc)) { |
1038 | residue = desc->residue; | ||
1039 | if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags) && residue) | ||
1040 | residue -= dwc_get_sent(dwc); | ||
1041 | } else { | ||
1042 | residue = desc->total_len; | ||
1043 | } | ||
1044 | } else { | ||
1045 | residue = 0; | ||
1046 | } | ||
1078 | 1047 | ||
1079 | spin_unlock_irqrestore(&dwc->lock, flags); | 1048 | spin_unlock_irqrestore(&dwc->lock, flags); |
1080 | return residue; | 1049 | return residue; |
@@ -1095,10 +1064,12 @@ dwc_tx_status(struct dma_chan *chan, | |||
1095 | dwc_scan_descriptors(to_dw_dma(chan->device), dwc); | 1064 | dwc_scan_descriptors(to_dw_dma(chan->device), dwc); |
1096 | 1065 | ||
1097 | ret = dma_cookie_status(chan, cookie, txstate); | 1066 | ret = dma_cookie_status(chan, cookie, txstate); |
1098 | if (ret != DMA_COMPLETE) | 1067 | if (ret == DMA_COMPLETE) |
1099 | dma_set_residue(txstate, dwc_get_residue(dwc)); | 1068 | return ret; |
1100 | 1069 | ||
1101 | if (dwc->paused && ret == DMA_IN_PROGRESS) | 1070 | dma_set_residue(txstate, dwc_get_residue(dwc, cookie)); |
1071 | |||
1072 | if (test_bit(DW_DMA_IS_PAUSED, &dwc->flags) && ret == DMA_IN_PROGRESS) | ||
1102 | return DMA_PAUSED; | 1073 | return DMA_PAUSED; |
1103 | 1074 | ||
1104 | return ret; | 1075 | return ret; |
@@ -1119,7 +1090,7 @@ static void dwc_issue_pending(struct dma_chan *chan) | |||
1119 | 1090 | ||
1120 | static void dw_dma_off(struct dw_dma *dw) | 1091 | static void dw_dma_off(struct dw_dma *dw) |
1121 | { | 1092 | { |
1122 | int i; | 1093 | unsigned int i; |
1123 | 1094 | ||
1124 | dma_writel(dw, CFG, 0); | 1095 | dma_writel(dw, CFG, 0); |
1125 | 1096 | ||
@@ -1133,7 +1104,7 @@ static void dw_dma_off(struct dw_dma *dw) | |||
1133 | cpu_relax(); | 1104 | cpu_relax(); |
1134 | 1105 | ||
1135 | for (i = 0; i < dw->dma.chancnt; i++) | 1106 | for (i = 0; i < dw->dma.chancnt; i++) |
1136 | dw->chan[i].initialized = false; | 1107 | clear_bit(DW_DMA_IS_INITIALIZED, &dw->chan[i].flags); |
1137 | } | 1108 | } |
1138 | 1109 | ||
1139 | static void dw_dma_on(struct dw_dma *dw) | 1110 | static void dw_dma_on(struct dw_dma *dw) |
@@ -1145,9 +1116,6 @@ static int dwc_alloc_chan_resources(struct dma_chan *chan) | |||
1145 | { | 1116 | { |
1146 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); | 1117 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
1147 | struct dw_dma *dw = to_dw_dma(chan->device); | 1118 | struct dw_dma *dw = to_dw_dma(chan->device); |
1148 | struct dw_desc *desc; | ||
1149 | int i; | ||
1150 | unsigned long flags; | ||
1151 | 1119 | ||
1152 | dev_vdbg(chan2dev(chan), "%s\n", __func__); | 1120 | dev_vdbg(chan2dev(chan), "%s\n", __func__); |
1153 | 1121 | ||
@@ -1165,53 +1133,26 @@ static int dwc_alloc_chan_resources(struct dma_chan *chan) | |||
1165 | * doesn't mean what you think it means), and status writeback. | 1133 | * doesn't mean what you think it means), and status writeback. |
1166 | */ | 1134 | */ |
1167 | 1135 | ||
1136 | /* | ||
1137 | * We need controller-specific data to set up slave transfers. | ||
1138 | */ | ||
1139 | if (chan->private && !dw_dma_filter(chan, chan->private)) { | ||
1140 | dev_warn(chan2dev(chan), "Wrong controller-specific data\n"); | ||
1141 | return -EINVAL; | ||
1142 | } | ||
1143 | |||
1168 | /* Enable controller here if needed */ | 1144 | /* Enable controller here if needed */ |
1169 | if (!dw->in_use) | 1145 | if (!dw->in_use) |
1170 | dw_dma_on(dw); | 1146 | dw_dma_on(dw); |
1171 | dw->in_use |= dwc->mask; | 1147 | dw->in_use |= dwc->mask; |
1172 | 1148 | ||
1173 | spin_lock_irqsave(&dwc->lock, flags); | 1149 | return 0; |
1174 | i = dwc->descs_allocated; | ||
1175 | while (dwc->descs_allocated < NR_DESCS_PER_CHANNEL) { | ||
1176 | dma_addr_t phys; | ||
1177 | |||
1178 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
1179 | |||
1180 | desc = dma_pool_alloc(dw->desc_pool, GFP_ATOMIC, &phys); | ||
1181 | if (!desc) | ||
1182 | goto err_desc_alloc; | ||
1183 | |||
1184 | memset(desc, 0, sizeof(struct dw_desc)); | ||
1185 | |||
1186 | INIT_LIST_HEAD(&desc->tx_list); | ||
1187 | dma_async_tx_descriptor_init(&desc->txd, chan); | ||
1188 | desc->txd.tx_submit = dwc_tx_submit; | ||
1189 | desc->txd.flags = DMA_CTRL_ACK; | ||
1190 | desc->txd.phys = phys; | ||
1191 | |||
1192 | dwc_desc_put(dwc, desc); | ||
1193 | |||
1194 | spin_lock_irqsave(&dwc->lock, flags); | ||
1195 | i = ++dwc->descs_allocated; | ||
1196 | } | ||
1197 | |||
1198 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
1199 | |||
1200 | dev_dbg(chan2dev(chan), "%s: allocated %d descriptors\n", __func__, i); | ||
1201 | |||
1202 | return i; | ||
1203 | |||
1204 | err_desc_alloc: | ||
1205 | dev_info(chan2dev(chan), "only allocated %d descriptors\n", i); | ||
1206 | |||
1207 | return i; | ||
1208 | } | 1150 | } |
1209 | 1151 | ||
1210 | static void dwc_free_chan_resources(struct dma_chan *chan) | 1152 | static void dwc_free_chan_resources(struct dma_chan *chan) |
1211 | { | 1153 | { |
1212 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); | 1154 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
1213 | struct dw_dma *dw = to_dw_dma(chan->device); | 1155 | struct dw_dma *dw = to_dw_dma(chan->device); |
1214 | struct dw_desc *desc, *_desc; | ||
1215 | unsigned long flags; | 1156 | unsigned long flags; |
1216 | LIST_HEAD(list); | 1157 | LIST_HEAD(list); |
1217 | 1158 | ||
@@ -1224,9 +1165,15 @@ static void dwc_free_chan_resources(struct dma_chan *chan) | |||
1224 | BUG_ON(dma_readl(to_dw_dma(chan->device), CH_EN) & dwc->mask); | 1165 | BUG_ON(dma_readl(to_dw_dma(chan->device), CH_EN) & dwc->mask); |
1225 | 1166 | ||
1226 | spin_lock_irqsave(&dwc->lock, flags); | 1167 | spin_lock_irqsave(&dwc->lock, flags); |
1227 | list_splice_init(&dwc->free_list, &list); | 1168 | |
1228 | dwc->descs_allocated = 0; | 1169 | /* Clear custom channel configuration */ |
1229 | dwc->initialized = false; | 1170 | dwc->src_id = 0; |
1171 | dwc->dst_id = 0; | ||
1172 | |||
1173 | dwc->m_master = 0; | ||
1174 | dwc->p_master = 0; | ||
1175 | |||
1176 | clear_bit(DW_DMA_IS_INITIALIZED, &dwc->flags); | ||
1230 | 1177 | ||
1231 | /* Disable interrupts */ | 1178 | /* Disable interrupts */ |
1232 | channel_clear_bit(dw, MASK.XFER, dwc->mask); | 1179 | channel_clear_bit(dw, MASK.XFER, dwc->mask); |
@@ -1240,11 +1187,6 @@ static void dwc_free_chan_resources(struct dma_chan *chan) | |||
1240 | if (!dw->in_use) | 1187 | if (!dw->in_use) |
1241 | dw_dma_off(dw); | 1188 | dw_dma_off(dw); |
1242 | 1189 | ||
1243 | list_for_each_entry_safe(desc, _desc, &list, desc_node) { | ||
1244 | dev_vdbg(chan2dev(chan), " freeing descriptor %p\n", desc); | ||
1245 | dma_pool_free(dw->desc_pool, desc, desc->txd.phys); | ||
1246 | } | ||
1247 | |||
1248 | dev_vdbg(chan2dev(chan), "%s: done\n", __func__); | 1190 | dev_vdbg(chan2dev(chan), "%s: done\n", __func__); |
1249 | } | 1191 | } |
1250 | 1192 | ||
@@ -1322,6 +1264,7 @@ struct dw_cyclic_desc *dw_dma_cyclic_prep(struct dma_chan *chan, | |||
1322 | struct dw_cyclic_desc *retval = NULL; | 1264 | struct dw_cyclic_desc *retval = NULL; |
1323 | struct dw_desc *desc; | 1265 | struct dw_desc *desc; |
1324 | struct dw_desc *last = NULL; | 1266 | struct dw_desc *last = NULL; |
1267 | u8 lms = DWC_LLP_LMS(dwc->m_master); | ||
1325 | unsigned long was_cyclic; | 1268 | unsigned long was_cyclic; |
1326 | unsigned int reg_width; | 1269 | unsigned int reg_width; |
1327 | unsigned int periods; | 1270 | unsigned int periods; |
@@ -1375,9 +1318,6 @@ struct dw_cyclic_desc *dw_dma_cyclic_prep(struct dma_chan *chan, | |||
1375 | 1318 | ||
1376 | retval = ERR_PTR(-ENOMEM); | 1319 | retval = ERR_PTR(-ENOMEM); |
1377 | 1320 | ||
1378 | if (periods > NR_DESCS_PER_CHANNEL) | ||
1379 | goto out_err; | ||
1380 | |||
1381 | cdesc = kzalloc(sizeof(struct dw_cyclic_desc), GFP_KERNEL); | 1321 | cdesc = kzalloc(sizeof(struct dw_cyclic_desc), GFP_KERNEL); |
1382 | if (!cdesc) | 1322 | if (!cdesc) |
1383 | goto out_err; | 1323 | goto out_err; |
@@ -1393,50 +1333,50 @@ struct dw_cyclic_desc *dw_dma_cyclic_prep(struct dma_chan *chan, | |||
1393 | 1333 | ||
1394 | switch (direction) { | 1334 | switch (direction) { |
1395 | case DMA_MEM_TO_DEV: | 1335 | case DMA_MEM_TO_DEV: |
1396 | desc->lli.dar = sconfig->dst_addr; | 1336 | lli_write(desc, dar, sconfig->dst_addr); |
1397 | desc->lli.sar = buf_addr + (period_len * i); | 1337 | lli_write(desc, sar, buf_addr + period_len * i); |
1398 | desc->lli.ctllo = (DWC_DEFAULT_CTLLO(chan) | 1338 | lli_write(desc, ctllo, (DWC_DEFAULT_CTLLO(chan) |
1399 | | DWC_CTLL_DST_WIDTH(reg_width) | 1339 | | DWC_CTLL_DST_WIDTH(reg_width) |
1400 | | DWC_CTLL_SRC_WIDTH(reg_width) | 1340 | | DWC_CTLL_SRC_WIDTH(reg_width) |
1401 | | DWC_CTLL_DST_FIX | 1341 | | DWC_CTLL_DST_FIX |
1402 | | DWC_CTLL_SRC_INC | 1342 | | DWC_CTLL_SRC_INC |
1403 | | DWC_CTLL_INT_EN); | 1343 | | DWC_CTLL_INT_EN)); |
1404 | 1344 | ||
1405 | desc->lli.ctllo |= sconfig->device_fc ? | 1345 | lli_set(desc, ctllo, sconfig->device_fc ? |
1406 | DWC_CTLL_FC(DW_DMA_FC_P_M2P) : | 1346 | DWC_CTLL_FC(DW_DMA_FC_P_M2P) : |
1407 | DWC_CTLL_FC(DW_DMA_FC_D_M2P); | 1347 | DWC_CTLL_FC(DW_DMA_FC_D_M2P)); |
1408 | 1348 | ||
1409 | break; | 1349 | break; |
1410 | case DMA_DEV_TO_MEM: | 1350 | case DMA_DEV_TO_MEM: |
1411 | desc->lli.dar = buf_addr + (period_len * i); | 1351 | lli_write(desc, dar, buf_addr + period_len * i); |
1412 | desc->lli.sar = sconfig->src_addr; | 1352 | lli_write(desc, sar, sconfig->src_addr); |
1413 | desc->lli.ctllo = (DWC_DEFAULT_CTLLO(chan) | 1353 | lli_write(desc, ctllo, (DWC_DEFAULT_CTLLO(chan) |
1414 | | DWC_CTLL_SRC_WIDTH(reg_width) | 1354 | | DWC_CTLL_SRC_WIDTH(reg_width) |
1415 | | DWC_CTLL_DST_WIDTH(reg_width) | 1355 | | DWC_CTLL_DST_WIDTH(reg_width) |
1416 | | DWC_CTLL_DST_INC | 1356 | | DWC_CTLL_DST_INC |
1417 | | DWC_CTLL_SRC_FIX | 1357 | | DWC_CTLL_SRC_FIX |
1418 | | DWC_CTLL_INT_EN); | 1358 | | DWC_CTLL_INT_EN)); |
1419 | 1359 | ||
1420 | desc->lli.ctllo |= sconfig->device_fc ? | 1360 | lli_set(desc, ctllo, sconfig->device_fc ? |
1421 | DWC_CTLL_FC(DW_DMA_FC_P_P2M) : | 1361 | DWC_CTLL_FC(DW_DMA_FC_P_P2M) : |
1422 | DWC_CTLL_FC(DW_DMA_FC_D_P2M); | 1362 | DWC_CTLL_FC(DW_DMA_FC_D_P2M)); |
1423 | 1363 | ||
1424 | break; | 1364 | break; |
1425 | default: | 1365 | default: |
1426 | break; | 1366 | break; |
1427 | } | 1367 | } |
1428 | 1368 | ||
1429 | desc->lli.ctlhi = (period_len >> reg_width); | 1369 | lli_write(desc, ctlhi, period_len >> reg_width); |
1430 | cdesc->desc[i] = desc; | 1370 | cdesc->desc[i] = desc; |
1431 | 1371 | ||
1432 | if (last) | 1372 | if (last) |
1433 | last->lli.llp = desc->txd.phys; | 1373 | lli_write(last, llp, desc->txd.phys | lms); |
1434 | 1374 | ||
1435 | last = desc; | 1375 | last = desc; |
1436 | } | 1376 | } |
1437 | 1377 | ||
1438 | /* Let's make a cyclic list */ | 1378 | /* Let's make a cyclic list */ |
1439 | last->lli.llp = cdesc->desc[0]->txd.phys; | 1379 | lli_write(last, llp, cdesc->desc[0]->txd.phys | lms); |
1440 | 1380 | ||
1441 | dev_dbg(chan2dev(&dwc->chan), | 1381 | dev_dbg(chan2dev(&dwc->chan), |
1442 | "cyclic prepared buf %pad len %zu period %zu periods %d\n", | 1382 | "cyclic prepared buf %pad len %zu period %zu periods %d\n", |
@@ -1467,7 +1407,7 @@ void dw_dma_cyclic_free(struct dma_chan *chan) | |||
1467 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); | 1407 | struct dw_dma_chan *dwc = to_dw_dma_chan(chan); |
1468 | struct dw_dma *dw = to_dw_dma(dwc->chan.device); | 1408 | struct dw_dma *dw = to_dw_dma(dwc->chan.device); |
1469 | struct dw_cyclic_desc *cdesc = dwc->cdesc; | 1409 | struct dw_cyclic_desc *cdesc = dwc->cdesc; |
1470 | int i; | 1410 | unsigned int i; |
1471 | unsigned long flags; | 1411 | unsigned long flags; |
1472 | 1412 | ||
1473 | dev_dbg(chan2dev(&dwc->chan), "%s\n", __func__); | 1413 | dev_dbg(chan2dev(&dwc->chan), "%s\n", __func__); |
@@ -1491,32 +1431,38 @@ void dw_dma_cyclic_free(struct dma_chan *chan) | |||
1491 | kfree(cdesc->desc); | 1431 | kfree(cdesc->desc); |
1492 | kfree(cdesc); | 1432 | kfree(cdesc); |
1493 | 1433 | ||
1434 | dwc->cdesc = NULL; | ||
1435 | |||
1494 | clear_bit(DW_DMA_IS_CYCLIC, &dwc->flags); | 1436 | clear_bit(DW_DMA_IS_CYCLIC, &dwc->flags); |
1495 | } | 1437 | } |
1496 | EXPORT_SYMBOL(dw_dma_cyclic_free); | 1438 | EXPORT_SYMBOL(dw_dma_cyclic_free); |
1497 | 1439 | ||
1498 | /*----------------------------------------------------------------------*/ | 1440 | /*----------------------------------------------------------------------*/ |
1499 | 1441 | ||
1500 | int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata) | 1442 | int dw_dma_probe(struct dw_dma_chip *chip) |
1501 | { | 1443 | { |
1444 | struct dw_dma_platform_data *pdata; | ||
1502 | struct dw_dma *dw; | 1445 | struct dw_dma *dw; |
1503 | bool autocfg = false; | 1446 | bool autocfg = false; |
1504 | unsigned int dw_params; | 1447 | unsigned int dw_params; |
1505 | unsigned int max_blk_size = 0; | 1448 | unsigned int i; |
1506 | int err; | 1449 | int err; |
1507 | int i; | ||
1508 | 1450 | ||
1509 | dw = devm_kzalloc(chip->dev, sizeof(*dw), GFP_KERNEL); | 1451 | dw = devm_kzalloc(chip->dev, sizeof(*dw), GFP_KERNEL); |
1510 | if (!dw) | 1452 | if (!dw) |
1511 | return -ENOMEM; | 1453 | return -ENOMEM; |
1512 | 1454 | ||
1455 | dw->pdata = devm_kzalloc(chip->dev, sizeof(*dw->pdata), GFP_KERNEL); | ||
1456 | if (!dw->pdata) | ||
1457 | return -ENOMEM; | ||
1458 | |||
1513 | dw->regs = chip->regs; | 1459 | dw->regs = chip->regs; |
1514 | chip->dw = dw; | 1460 | chip->dw = dw; |
1515 | 1461 | ||
1516 | pm_runtime_get_sync(chip->dev); | 1462 | pm_runtime_get_sync(chip->dev); |
1517 | 1463 | ||
1518 | if (!pdata) { | 1464 | if (!chip->pdata) { |
1519 | dw_params = dma_read_byaddr(chip->regs, DW_PARAMS); | 1465 | dw_params = dma_readl(dw, DW_PARAMS); |
1520 | dev_dbg(chip->dev, "DW_PARAMS: 0x%08x\n", dw_params); | 1466 | dev_dbg(chip->dev, "DW_PARAMS: 0x%08x\n", dw_params); |
1521 | 1467 | ||
1522 | autocfg = dw_params >> DW_PARAMS_EN & 1; | 1468 | autocfg = dw_params >> DW_PARAMS_EN & 1; |
@@ -1525,29 +1471,31 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata) | |||
1525 | goto err_pdata; | 1471 | goto err_pdata; |
1526 | } | 1472 | } |
1527 | 1473 | ||
1528 | pdata = devm_kzalloc(chip->dev, sizeof(*pdata), GFP_KERNEL); | 1474 | /* Reassign the platform data pointer */ |
1529 | if (!pdata) { | 1475 | pdata = dw->pdata; |
1530 | err = -ENOMEM; | ||
1531 | goto err_pdata; | ||
1532 | } | ||
1533 | 1476 | ||
1534 | /* Get hardware configuration parameters */ | 1477 | /* Get hardware configuration parameters */ |
1535 | pdata->nr_channels = (dw_params >> DW_PARAMS_NR_CHAN & 7) + 1; | 1478 | pdata->nr_channels = (dw_params >> DW_PARAMS_NR_CHAN & 7) + 1; |
1536 | pdata->nr_masters = (dw_params >> DW_PARAMS_NR_MASTER & 3) + 1; | 1479 | pdata->nr_masters = (dw_params >> DW_PARAMS_NR_MASTER & 3) + 1; |
1537 | for (i = 0; i < pdata->nr_masters; i++) { | 1480 | for (i = 0; i < pdata->nr_masters; i++) { |
1538 | pdata->data_width[i] = | 1481 | pdata->data_width[i] = |
1539 | (dw_params >> DW_PARAMS_DATA_WIDTH(i) & 3) + 2; | 1482 | 4 << (dw_params >> DW_PARAMS_DATA_WIDTH(i) & 3); |
1540 | } | 1483 | } |
1541 | max_blk_size = dma_readl(dw, MAX_BLK_SIZE); | 1484 | pdata->block_size = dma_readl(dw, MAX_BLK_SIZE); |
1542 | 1485 | ||
1543 | /* Fill platform data with the default values */ | 1486 | /* Fill platform data with the default values */ |
1544 | pdata->is_private = true; | 1487 | pdata->is_private = true; |
1545 | pdata->is_memcpy = true; | 1488 | pdata->is_memcpy = true; |
1546 | pdata->chan_allocation_order = CHAN_ALLOCATION_ASCENDING; | 1489 | pdata->chan_allocation_order = CHAN_ALLOCATION_ASCENDING; |
1547 | pdata->chan_priority = CHAN_PRIORITY_ASCENDING; | 1490 | pdata->chan_priority = CHAN_PRIORITY_ASCENDING; |
1548 | } else if (pdata->nr_channels > DW_DMA_MAX_NR_CHANNELS) { | 1491 | } else if (chip->pdata->nr_channels > DW_DMA_MAX_NR_CHANNELS) { |
1549 | err = -EINVAL; | 1492 | err = -EINVAL; |
1550 | goto err_pdata; | 1493 | goto err_pdata; |
1494 | } else { | ||
1495 | memcpy(dw->pdata, chip->pdata, sizeof(*dw->pdata)); | ||
1496 | |||
1497 | /* Reassign the platform data pointer */ | ||
1498 | pdata = dw->pdata; | ||
1551 | } | 1499 | } |
1552 | 1500 | ||
1553 | dw->chan = devm_kcalloc(chip->dev, pdata->nr_channels, sizeof(*dw->chan), | 1501 | dw->chan = devm_kcalloc(chip->dev, pdata->nr_channels, sizeof(*dw->chan), |
@@ -1557,11 +1505,6 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata) | |||
1557 | goto err_pdata; | 1505 | goto err_pdata; |
1558 | } | 1506 | } |
1559 | 1507 | ||
1560 | /* Get hardware configuration parameters */ | ||
1561 | dw->nr_masters = pdata->nr_masters; | ||
1562 | for (i = 0; i < dw->nr_masters; i++) | ||
1563 | dw->data_width[i] = pdata->data_width[i]; | ||
1564 | |||
1565 | /* Calculate all channel mask before DMA setup */ | 1508 | /* Calculate all channel mask before DMA setup */ |
1566 | dw->all_chan_mask = (1 << pdata->nr_channels) - 1; | 1509 | dw->all_chan_mask = (1 << pdata->nr_channels) - 1; |
1567 | 1510 | ||
@@ -1608,7 +1551,6 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata) | |||
1608 | 1551 | ||
1609 | INIT_LIST_HEAD(&dwc->active_list); | 1552 | INIT_LIST_HEAD(&dwc->active_list); |
1610 | INIT_LIST_HEAD(&dwc->queue); | 1553 | INIT_LIST_HEAD(&dwc->queue); |
1611 | INIT_LIST_HEAD(&dwc->free_list); | ||
1612 | 1554 | ||
1613 | channel_clear_bit(dw, CH_EN, dwc->mask); | 1555 | channel_clear_bit(dw, CH_EN, dwc->mask); |
1614 | 1556 | ||
@@ -1616,11 +1558,9 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata) | |||
1616 | 1558 | ||
1617 | /* Hardware configuration */ | 1559 | /* Hardware configuration */ |
1618 | if (autocfg) { | 1560 | if (autocfg) { |
1619 | unsigned int dwc_params; | ||
1620 | unsigned int r = DW_DMA_MAX_NR_CHANNELS - i - 1; | 1561 | unsigned int r = DW_DMA_MAX_NR_CHANNELS - i - 1; |
1621 | void __iomem *addr = chip->regs + r * sizeof(u32); | 1562 | void __iomem *addr = &__dw_regs(dw)->DWC_PARAMS[r]; |
1622 | 1563 | unsigned int dwc_params = dma_readl_native(addr); | |
1623 | dwc_params = dma_read_byaddr(addr, DWC_PARAMS); | ||
1624 | 1564 | ||
1625 | dev_dbg(chip->dev, "DWC_PARAMS[%d]: 0x%08x\n", i, | 1565 | dev_dbg(chip->dev, "DWC_PARAMS[%d]: 0x%08x\n", i, |
1626 | dwc_params); | 1566 | dwc_params); |
@@ -1631,16 +1571,15 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata) | |||
1631 | * up to 0x0a for 4095. | 1571 | * up to 0x0a for 4095. |
1632 | */ | 1572 | */ |
1633 | dwc->block_size = | 1573 | dwc->block_size = |
1634 | (4 << ((max_blk_size >> 4 * i) & 0xf)) - 1; | 1574 | (4 << ((pdata->block_size >> 4 * i) & 0xf)) - 1; |
1635 | dwc->nollp = | 1575 | dwc->nollp = |
1636 | (dwc_params >> DWC_PARAMS_MBLK_EN & 0x1) == 0; | 1576 | (dwc_params >> DWC_PARAMS_MBLK_EN & 0x1) == 0; |
1637 | } else { | 1577 | } else { |
1638 | dwc->block_size = pdata->block_size; | 1578 | dwc->block_size = pdata->block_size; |
1639 | 1579 | ||
1640 | /* Check if channel supports multi block transfer */ | 1580 | /* Check if channel supports multi block transfer */ |
1641 | channel_writel(dwc, LLP, 0xfffffffc); | 1581 | channel_writel(dwc, LLP, DWC_LLP_LOC(0xffffffff)); |
1642 | dwc->nollp = | 1582 | dwc->nollp = DWC_LLP_LOC(channel_readl(dwc, LLP)) == 0; |
1643 | (channel_readl(dwc, LLP) & 0xfffffffc) == 0; | ||
1644 | channel_writel(dwc, LLP, 0); | 1583 | channel_writel(dwc, LLP, 0); |
1645 | } | 1584 | } |
1646 | } | 1585 | } |
diff --git a/drivers/dma/dw/pci.c b/drivers/dma/dw/pci.c index 358f9689a3f5..0ae6c3b1d34e 100644 --- a/drivers/dma/dw/pci.c +++ b/drivers/dma/dw/pci.c | |||
@@ -17,8 +17,8 @@ | |||
17 | 17 | ||
18 | static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid) | 18 | static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid) |
19 | { | 19 | { |
20 | const struct dw_dma_platform_data *pdata = (void *)pid->driver_data; | ||
20 | struct dw_dma_chip *chip; | 21 | struct dw_dma_chip *chip; |
21 | struct dw_dma_platform_data *pdata = (void *)pid->driver_data; | ||
22 | int ret; | 22 | int ret; |
23 | 23 | ||
24 | ret = pcim_enable_device(pdev); | 24 | ret = pcim_enable_device(pdev); |
@@ -49,8 +49,9 @@ static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid) | |||
49 | chip->dev = &pdev->dev; | 49 | chip->dev = &pdev->dev; |
50 | chip->regs = pcim_iomap_table(pdev)[0]; | 50 | chip->regs = pcim_iomap_table(pdev)[0]; |
51 | chip->irq = pdev->irq; | 51 | chip->irq = pdev->irq; |
52 | chip->pdata = pdata; | ||
52 | 53 | ||
53 | ret = dw_dma_probe(chip, pdata); | 54 | ret = dw_dma_probe(chip); |
54 | if (ret) | 55 | if (ret) |
55 | return ret; | 56 | return ret; |
56 | 57 | ||
diff --git a/drivers/dma/dw/platform.c b/drivers/dma/dw/platform.c index 26edbe3a27ac..5bda0eb9f393 100644 --- a/drivers/dma/dw/platform.c +++ b/drivers/dma/dw/platform.c | |||
@@ -42,13 +42,13 @@ static struct dma_chan *dw_dma_of_xlate(struct of_phandle_args *dma_spec, | |||
42 | 42 | ||
43 | slave.src_id = dma_spec->args[0]; | 43 | slave.src_id = dma_spec->args[0]; |
44 | slave.dst_id = dma_spec->args[0]; | 44 | slave.dst_id = dma_spec->args[0]; |
45 | slave.src_master = dma_spec->args[1]; | 45 | slave.m_master = dma_spec->args[1]; |
46 | slave.dst_master = dma_spec->args[2]; | 46 | slave.p_master = dma_spec->args[2]; |
47 | 47 | ||
48 | if (WARN_ON(slave.src_id >= DW_DMA_MAX_NR_REQUESTS || | 48 | if (WARN_ON(slave.src_id >= DW_DMA_MAX_NR_REQUESTS || |
49 | slave.dst_id >= DW_DMA_MAX_NR_REQUESTS || | 49 | slave.dst_id >= DW_DMA_MAX_NR_REQUESTS || |
50 | slave.src_master >= dw->nr_masters || | 50 | slave.m_master >= dw->pdata->nr_masters || |
51 | slave.dst_master >= dw->nr_masters)) | 51 | slave.p_master >= dw->pdata->nr_masters)) |
52 | return NULL; | 52 | return NULL; |
53 | 53 | ||
54 | dma_cap_zero(cap); | 54 | dma_cap_zero(cap); |
@@ -66,8 +66,8 @@ static bool dw_dma_acpi_filter(struct dma_chan *chan, void *param) | |||
66 | .dma_dev = dma_spec->dev, | 66 | .dma_dev = dma_spec->dev, |
67 | .src_id = dma_spec->slave_id, | 67 | .src_id = dma_spec->slave_id, |
68 | .dst_id = dma_spec->slave_id, | 68 | .dst_id = dma_spec->slave_id, |
69 | .src_master = 1, | 69 | .m_master = 0, |
70 | .dst_master = 0, | 70 | .p_master = 1, |
71 | }; | 71 | }; |
72 | 72 | ||
73 | return dw_dma_filter(chan, &slave); | 73 | return dw_dma_filter(chan, &slave); |
@@ -103,6 +103,7 @@ dw_dma_parse_dt(struct platform_device *pdev) | |||
103 | struct device_node *np = pdev->dev.of_node; | 103 | struct device_node *np = pdev->dev.of_node; |
104 | struct dw_dma_platform_data *pdata; | 104 | struct dw_dma_platform_data *pdata; |
105 | u32 tmp, arr[DW_DMA_MAX_NR_MASTERS]; | 105 | u32 tmp, arr[DW_DMA_MAX_NR_MASTERS]; |
106 | u32 nr_masters; | ||
106 | u32 nr_channels; | 107 | u32 nr_channels; |
107 | 108 | ||
108 | if (!np) { | 109 | if (!np) { |
@@ -110,6 +111,11 @@ dw_dma_parse_dt(struct platform_device *pdev) | |||
110 | return NULL; | 111 | return NULL; |
111 | } | 112 | } |
112 | 113 | ||
114 | if (of_property_read_u32(np, "dma-masters", &nr_masters)) | ||
115 | return NULL; | ||
116 | if (nr_masters < 1 || nr_masters > DW_DMA_MAX_NR_MASTERS) | ||
117 | return NULL; | ||
118 | |||
113 | if (of_property_read_u32(np, "dma-channels", &nr_channels)) | 119 | if (of_property_read_u32(np, "dma-channels", &nr_channels)) |
114 | return NULL; | 120 | return NULL; |
115 | 121 | ||
@@ -117,6 +123,7 @@ dw_dma_parse_dt(struct platform_device *pdev) | |||
117 | if (!pdata) | 123 | if (!pdata) |
118 | return NULL; | 124 | return NULL; |
119 | 125 | ||
126 | pdata->nr_masters = nr_masters; | ||
120 | pdata->nr_channels = nr_channels; | 127 | pdata->nr_channels = nr_channels; |
121 | 128 | ||
122 | if (of_property_read_bool(np, "is_private")) | 129 | if (of_property_read_bool(np, "is_private")) |
@@ -131,17 +138,13 @@ dw_dma_parse_dt(struct platform_device *pdev) | |||
131 | if (!of_property_read_u32(np, "block_size", &tmp)) | 138 | if (!of_property_read_u32(np, "block_size", &tmp)) |
132 | pdata->block_size = tmp; | 139 | pdata->block_size = tmp; |
133 | 140 | ||
134 | if (!of_property_read_u32(np, "dma-masters", &tmp)) { | 141 | if (!of_property_read_u32_array(np, "data-width", arr, nr_masters)) { |
135 | if (tmp > DW_DMA_MAX_NR_MASTERS) | 142 | for (tmp = 0; tmp < nr_masters; tmp++) |
136 | return NULL; | ||
137 | |||
138 | pdata->nr_masters = tmp; | ||
139 | } | ||
140 | |||
141 | if (!of_property_read_u32_array(np, "data_width", arr, | ||
142 | pdata->nr_masters)) | ||
143 | for (tmp = 0; tmp < pdata->nr_masters; tmp++) | ||
144 | pdata->data_width[tmp] = arr[tmp]; | 143 | pdata->data_width[tmp] = arr[tmp]; |
144 | } else if (!of_property_read_u32_array(np, "data_width", arr, nr_masters)) { | ||
145 | for (tmp = 0; tmp < nr_masters; tmp++) | ||
146 | pdata->data_width[tmp] = BIT(arr[tmp] & 0x07); | ||
147 | } | ||
145 | 148 | ||
146 | return pdata; | 149 | return pdata; |
147 | } | 150 | } |
@@ -158,7 +161,7 @@ static int dw_probe(struct platform_device *pdev) | |||
158 | struct dw_dma_chip *chip; | 161 | struct dw_dma_chip *chip; |
159 | struct device *dev = &pdev->dev; | 162 | struct device *dev = &pdev->dev; |
160 | struct resource *mem; | 163 | struct resource *mem; |
161 | struct dw_dma_platform_data *pdata; | 164 | const struct dw_dma_platform_data *pdata; |
162 | int err; | 165 | int err; |
163 | 166 | ||
164 | chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); | 167 | chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); |
@@ -183,6 +186,7 @@ static int dw_probe(struct platform_device *pdev) | |||
183 | pdata = dw_dma_parse_dt(pdev); | 186 | pdata = dw_dma_parse_dt(pdev); |
184 | 187 | ||
185 | chip->dev = dev; | 188 | chip->dev = dev; |
189 | chip->pdata = pdata; | ||
186 | 190 | ||
187 | chip->clk = devm_clk_get(chip->dev, "hclk"); | 191 | chip->clk = devm_clk_get(chip->dev, "hclk"); |
188 | if (IS_ERR(chip->clk)) | 192 | if (IS_ERR(chip->clk)) |
@@ -193,7 +197,7 @@ static int dw_probe(struct platform_device *pdev) | |||
193 | 197 | ||
194 | pm_runtime_enable(&pdev->dev); | 198 | pm_runtime_enable(&pdev->dev); |
195 | 199 | ||
196 | err = dw_dma_probe(chip, pdata); | 200 | err = dw_dma_probe(chip); |
197 | if (err) | 201 | if (err) |
198 | goto err_dw_dma_probe; | 202 | goto err_dw_dma_probe; |
199 | 203 | ||
diff --git a/drivers/dma/dw/regs.h b/drivers/dma/dw/regs.h index 0a50c18d85b8..4b7bd7834046 100644 --- a/drivers/dma/dw/regs.h +++ b/drivers/dma/dw/regs.h | |||
@@ -114,10 +114,6 @@ struct dw_dma_regs { | |||
114 | #define dma_writel_native writel | 114 | #define dma_writel_native writel |
115 | #endif | 115 | #endif |
116 | 116 | ||
117 | /* To access the registers in early stage of probe */ | ||
118 | #define dma_read_byaddr(addr, name) \ | ||
119 | dma_readl_native((addr) + offsetof(struct dw_dma_regs, name)) | ||
120 | |||
121 | /* Bitfields in DW_PARAMS */ | 117 | /* Bitfields in DW_PARAMS */ |
122 | #define DW_PARAMS_NR_CHAN 8 /* number of channels */ | 118 | #define DW_PARAMS_NR_CHAN 8 /* number of channels */ |
123 | #define DW_PARAMS_NR_MASTER 11 /* number of AHB masters */ | 119 | #define DW_PARAMS_NR_MASTER 11 /* number of AHB masters */ |
@@ -143,6 +139,10 @@ enum dw_dma_msize { | |||
143 | DW_DMA_MSIZE_256, | 139 | DW_DMA_MSIZE_256, |
144 | }; | 140 | }; |
145 | 141 | ||
142 | /* Bitfields in LLP */ | ||
143 | #define DWC_LLP_LMS(x) ((x) & 3) /* list master select */ | ||
144 | #define DWC_LLP_LOC(x) ((x) & ~3) /* next lli */ | ||
145 | |||
146 | /* Bitfields in CTL_LO */ | 146 | /* Bitfields in CTL_LO */ |
147 | #define DWC_CTLL_INT_EN (1 << 0) /* irqs enabled? */ | 147 | #define DWC_CTLL_INT_EN (1 << 0) /* irqs enabled? */ |
148 | #define DWC_CTLL_DST_WIDTH(n) ((n)<<1) /* bytes per element */ | 148 | #define DWC_CTLL_DST_WIDTH(n) ((n)<<1) /* bytes per element */ |
@@ -216,6 +216,8 @@ enum dw_dma_msize { | |||
216 | enum dw_dmac_flags { | 216 | enum dw_dmac_flags { |
217 | DW_DMA_IS_CYCLIC = 0, | 217 | DW_DMA_IS_CYCLIC = 0, |
218 | DW_DMA_IS_SOFT_LLP = 1, | 218 | DW_DMA_IS_SOFT_LLP = 1, |
219 | DW_DMA_IS_PAUSED = 2, | ||
220 | DW_DMA_IS_INITIALIZED = 3, | ||
219 | }; | 221 | }; |
220 | 222 | ||
221 | struct dw_dma_chan { | 223 | struct dw_dma_chan { |
@@ -224,8 +226,6 @@ struct dw_dma_chan { | |||
224 | u8 mask; | 226 | u8 mask; |
225 | u8 priority; | 227 | u8 priority; |
226 | enum dma_transfer_direction direction; | 228 | enum dma_transfer_direction direction; |
227 | bool paused; | ||
228 | bool initialized; | ||
229 | 229 | ||
230 | /* software emulation of the LLP transfers */ | 230 | /* software emulation of the LLP transfers */ |
231 | struct list_head *tx_node_active; | 231 | struct list_head *tx_node_active; |
@@ -236,8 +236,6 @@ struct dw_dma_chan { | |||
236 | unsigned long flags; | 236 | unsigned long flags; |
237 | struct list_head active_list; | 237 | struct list_head active_list; |
238 | struct list_head queue; | 238 | struct list_head queue; |
239 | struct list_head free_list; | ||
240 | u32 residue; | ||
241 | struct dw_cyclic_desc *cdesc; | 239 | struct dw_cyclic_desc *cdesc; |
242 | 240 | ||
243 | unsigned int descs_allocated; | 241 | unsigned int descs_allocated; |
@@ -249,8 +247,8 @@ struct dw_dma_chan { | |||
249 | /* custom slave configuration */ | 247 | /* custom slave configuration */ |
250 | u8 src_id; | 248 | u8 src_id; |
251 | u8 dst_id; | 249 | u8 dst_id; |
252 | u8 src_master; | 250 | u8 m_master; |
253 | u8 dst_master; | 251 | u8 p_master; |
254 | 252 | ||
255 | /* configuration passed via .device_config */ | 253 | /* configuration passed via .device_config */ |
256 | struct dma_slave_config dma_sconfig; | 254 | struct dma_slave_config dma_sconfig; |
@@ -283,9 +281,8 @@ struct dw_dma { | |||
283 | u8 all_chan_mask; | 281 | u8 all_chan_mask; |
284 | u8 in_use; | 282 | u8 in_use; |
285 | 283 | ||
286 | /* hardware configuration */ | 284 | /* platform data */ |
287 | unsigned char nr_masters; | 285 | struct dw_dma_platform_data *pdata; |
288 | unsigned char data_width[DW_DMA_MAX_NR_MASTERS]; | ||
289 | }; | 286 | }; |
290 | 287 | ||
291 | static inline struct dw_dma_regs __iomem *__dw_regs(struct dw_dma *dw) | 288 | static inline struct dw_dma_regs __iomem *__dw_regs(struct dw_dma *dw) |
@@ -308,32 +305,51 @@ static inline struct dw_dma *to_dw_dma(struct dma_device *ddev) | |||
308 | return container_of(ddev, struct dw_dma, dma); | 305 | return container_of(ddev, struct dw_dma, dma); |
309 | } | 306 | } |
310 | 307 | ||
308 | #ifdef CONFIG_DW_DMAC_BIG_ENDIAN_IO | ||
309 | typedef __be32 __dw32; | ||
310 | #else | ||
311 | typedef __le32 __dw32; | ||
312 | #endif | ||
313 | |||
311 | /* LLI == Linked List Item; a.k.a. DMA block descriptor */ | 314 | /* LLI == Linked List Item; a.k.a. DMA block descriptor */ |
312 | struct dw_lli { | 315 | struct dw_lli { |
313 | /* values that are not changed by hardware */ | 316 | /* values that are not changed by hardware */ |
314 | u32 sar; | 317 | __dw32 sar; |
315 | u32 dar; | 318 | __dw32 dar; |
316 | u32 llp; /* chain to next lli */ | 319 | __dw32 llp; /* chain to next lli */ |
317 | u32 ctllo; | 320 | __dw32 ctllo; |
318 | /* values that may get written back: */ | 321 | /* values that may get written back: */ |
319 | u32 ctlhi; | 322 | __dw32 ctlhi; |
320 | /* sstat and dstat can snapshot peripheral register state. | 323 | /* sstat and dstat can snapshot peripheral register state. |
321 | * silicon config may discard either or both... | 324 | * silicon config may discard either or both... |
322 | */ | 325 | */ |
323 | u32 sstat; | 326 | __dw32 sstat; |
324 | u32 dstat; | 327 | __dw32 dstat; |
325 | }; | 328 | }; |
326 | 329 | ||
327 | struct dw_desc { | 330 | struct dw_desc { |
328 | /* FIRST values the hardware uses */ | 331 | /* FIRST values the hardware uses */ |
329 | struct dw_lli lli; | 332 | struct dw_lli lli; |
330 | 333 | ||
334 | #ifdef CONFIG_DW_DMAC_BIG_ENDIAN_IO | ||
335 | #define lli_set(d, reg, v) ((d)->lli.reg |= cpu_to_be32(v)) | ||
336 | #define lli_clear(d, reg, v) ((d)->lli.reg &= ~cpu_to_be32(v)) | ||
337 | #define lli_read(d, reg) be32_to_cpu((d)->lli.reg) | ||
338 | #define lli_write(d, reg, v) ((d)->lli.reg = cpu_to_be32(v)) | ||
339 | #else | ||
340 | #define lli_set(d, reg, v) ((d)->lli.reg |= cpu_to_le32(v)) | ||
341 | #define lli_clear(d, reg, v) ((d)->lli.reg &= ~cpu_to_le32(v)) | ||
342 | #define lli_read(d, reg) le32_to_cpu((d)->lli.reg) | ||
343 | #define lli_write(d, reg, v) ((d)->lli.reg = cpu_to_le32(v)) | ||
344 | #endif | ||
345 | |||
331 | /* THEN values for driver housekeeping */ | 346 | /* THEN values for driver housekeeping */ |
332 | struct list_head desc_node; | 347 | struct list_head desc_node; |
333 | struct list_head tx_list; | 348 | struct list_head tx_list; |
334 | struct dma_async_tx_descriptor txd; | 349 | struct dma_async_tx_descriptor txd; |
335 | size_t len; | 350 | size_t len; |
336 | size_t total_len; | 351 | size_t total_len; |
352 | u32 residue; | ||
337 | }; | 353 | }; |
338 | 354 | ||
339 | #define to_dw_desc(h) list_entry(h, struct dw_desc, desc_node) | 355 | #define to_dw_desc(h) list_entry(h, struct dw_desc, desc_node) |
diff --git a/drivers/dma/edma.c b/drivers/dma/edma.c index ee3463e774f8..694c44e487ed 100644 --- a/drivers/dma/edma.c +++ b/drivers/dma/edma.c | |||
@@ -1518,8 +1518,17 @@ static irqreturn_t dma_ccerr_handler(int irq, void *data) | |||
1518 | 1518 | ||
1519 | dev_vdbg(ecc->dev, "dma_ccerr_handler\n"); | 1519 | dev_vdbg(ecc->dev, "dma_ccerr_handler\n"); |
1520 | 1520 | ||
1521 | if (!edma_error_pending(ecc)) | 1521 | if (!edma_error_pending(ecc)) { |
1522 | /* | ||
1523 | * The registers indicate no pending error event but the irq | ||
1524 | * handler has been called. | ||
1525 | * Ask eDMA to re-evaluate the error registers. | ||
1526 | */ | ||
1527 | dev_err(ecc->dev, "%s: Error interrupt without error event!\n", | ||
1528 | __func__); | ||
1529 | edma_write(ecc, EDMA_EEVAL, 1); | ||
1522 | return IRQ_NONE; | 1530 | return IRQ_NONE; |
1531 | } | ||
1523 | 1532 | ||
1524 | while (1) { | 1533 | while (1) { |
1525 | /* Event missed register(s) */ | 1534 | /* Event missed register(s) */ |
diff --git a/drivers/dma/fsldma.c b/drivers/dma/fsldma.c index aac85c30c2cf..a8828ed639b3 100644 --- a/drivers/dma/fsldma.c +++ b/drivers/dma/fsldma.c | |||
@@ -462,13 +462,12 @@ static struct fsl_desc_sw *fsl_dma_alloc_descriptor(struct fsldma_chan *chan) | |||
462 | struct fsl_desc_sw *desc; | 462 | struct fsl_desc_sw *desc; |
463 | dma_addr_t pdesc; | 463 | dma_addr_t pdesc; |
464 | 464 | ||
465 | desc = dma_pool_alloc(chan->desc_pool, GFP_ATOMIC, &pdesc); | 465 | desc = dma_pool_zalloc(chan->desc_pool, GFP_ATOMIC, &pdesc); |
466 | if (!desc) { | 466 | if (!desc) { |
467 | chan_dbg(chan, "out of memory for link descriptor\n"); | 467 | chan_dbg(chan, "out of memory for link descriptor\n"); |
468 | return NULL; | 468 | return NULL; |
469 | } | 469 | } |
470 | 470 | ||
471 | memset(desc, 0, sizeof(*desc)); | ||
472 | INIT_LIST_HEAD(&desc->tx_list); | 471 | INIT_LIST_HEAD(&desc->tx_list); |
473 | dma_async_tx_descriptor_init(&desc->async_tx, &chan->common); | 472 | dma_async_tx_descriptor_init(&desc->async_tx, &chan->common); |
474 | desc->async_tx.tx_submit = fsl_dma_tx_submit; | 473 | desc->async_tx.tx_submit = fsl_dma_tx_submit; |
diff --git a/drivers/dma/hsu/hsu.c b/drivers/dma/hsu/hsu.c index eef145edb936..59d1e7c6fd0f 100644 --- a/drivers/dma/hsu/hsu.c +++ b/drivers/dma/hsu/hsu.c | |||
@@ -77,8 +77,8 @@ static void hsu_dma_chan_start(struct hsu_dma_chan *hsuc) | |||
77 | hsu_chan_writel(hsuc, HSU_CH_MTSR, mtsr); | 77 | hsu_chan_writel(hsuc, HSU_CH_MTSR, mtsr); |
78 | 78 | ||
79 | /* Set descriptors */ | 79 | /* Set descriptors */ |
80 | count = (desc->nents - desc->active) % HSU_DMA_CHAN_NR_DESC; | 80 | count = desc->nents - desc->active; |
81 | for (i = 0; i < count; i++) { | 81 | for (i = 0; i < count && i < HSU_DMA_CHAN_NR_DESC; i++) { |
82 | hsu_chan_writel(hsuc, HSU_CH_DxSAR(i), desc->sg[i].addr); | 82 | hsu_chan_writel(hsuc, HSU_CH_DxSAR(i), desc->sg[i].addr); |
83 | hsu_chan_writel(hsuc, HSU_CH_DxTSR(i), desc->sg[i].len); | 83 | hsu_chan_writel(hsuc, HSU_CH_DxTSR(i), desc->sg[i].len); |
84 | 84 | ||
@@ -160,7 +160,7 @@ irqreturn_t hsu_dma_irq(struct hsu_dma_chip *chip, unsigned short nr) | |||
160 | return IRQ_NONE; | 160 | return IRQ_NONE; |
161 | 161 | ||
162 | /* Timeout IRQ, need wait some time, see Errata 2 */ | 162 | /* Timeout IRQ, need wait some time, see Errata 2 */ |
163 | if (hsuc->direction == DMA_DEV_TO_MEM && (sr & HSU_CH_SR_DESCTO_ANY)) | 163 | if (sr & HSU_CH_SR_DESCTO_ANY) |
164 | udelay(2); | 164 | udelay(2); |
165 | 165 | ||
166 | sr &= ~HSU_CH_SR_DESCTO_ANY; | 166 | sr &= ~HSU_CH_SR_DESCTO_ANY; |
@@ -417,6 +417,8 @@ int hsu_dma_probe(struct hsu_dma_chip *chip) | |||
417 | 417 | ||
418 | hsu->dma.dev = chip->dev; | 418 | hsu->dma.dev = chip->dev; |
419 | 419 | ||
420 | dma_set_max_seg_size(hsu->dma.dev, HSU_CH_DxTSR_MASK); | ||
421 | |||
420 | ret = dma_async_device_register(&hsu->dma); | 422 | ret = dma_async_device_register(&hsu->dma); |
421 | if (ret) | 423 | if (ret) |
422 | return ret; | 424 | return ret; |
diff --git a/drivers/dma/hsu/hsu.h b/drivers/dma/hsu/hsu.h index 578a8ee8cd05..50a9d1bda253 100644 --- a/drivers/dma/hsu/hsu.h +++ b/drivers/dma/hsu/hsu.h | |||
@@ -55,6 +55,10 @@ | |||
55 | #define HSU_CH_DCR_CHEI BIT(23) | 55 | #define HSU_CH_DCR_CHEI BIT(23) |
56 | #define HSU_CH_DCR_CHTOI(x) BIT(24 + (x)) | 56 | #define HSU_CH_DCR_CHTOI(x) BIT(24 + (x)) |
57 | 57 | ||
58 | /* Bits in HSU_CH_DxTSR */ | ||
59 | #define HSU_CH_DxTSR_MASK GENMASK(15, 0) | ||
60 | #define HSU_CH_DxTSR_TSR(x) ((x) & HSU_CH_DxTSR_MASK) | ||
61 | |||
58 | struct hsu_dma_sg { | 62 | struct hsu_dma_sg { |
59 | dma_addr_t addr; | 63 | dma_addr_t addr; |
60 | unsigned int len; | 64 | unsigned int len; |
diff --git a/drivers/dma/ioat/init.c b/drivers/dma/ioat/init.c index efdee1a69fc4..d406056e8892 100644 --- a/drivers/dma/ioat/init.c +++ b/drivers/dma/ioat/init.c | |||
@@ -690,12 +690,11 @@ static int ioat_alloc_chan_resources(struct dma_chan *c) | |||
690 | /* allocate a completion writeback area */ | 690 | /* allocate a completion writeback area */ |
691 | /* doing 2 32bit writes to mmio since 1 64b write doesn't work */ | 691 | /* doing 2 32bit writes to mmio since 1 64b write doesn't work */ |
692 | ioat_chan->completion = | 692 | ioat_chan->completion = |
693 | dma_pool_alloc(ioat_chan->ioat_dma->completion_pool, | 693 | dma_pool_zalloc(ioat_chan->ioat_dma->completion_pool, |
694 | GFP_KERNEL, &ioat_chan->completion_dma); | 694 | GFP_KERNEL, &ioat_chan->completion_dma); |
695 | if (!ioat_chan->completion) | 695 | if (!ioat_chan->completion) |
696 | return -ENOMEM; | 696 | return -ENOMEM; |
697 | 697 | ||
698 | memset(ioat_chan->completion, 0, sizeof(*ioat_chan->completion)); | ||
699 | writel(((u64)ioat_chan->completion_dma) & 0x00000000FFFFFFFF, | 698 | writel(((u64)ioat_chan->completion_dma) & 0x00000000FFFFFFFF, |
700 | ioat_chan->reg_base + IOAT_CHANCMP_OFFSET_LOW); | 699 | ioat_chan->reg_base + IOAT_CHANCMP_OFFSET_LOW); |
701 | writel(((u64)ioat_chan->completion_dma) >> 32, | 700 | writel(((u64)ioat_chan->completion_dma) >> 32, |
@@ -1074,6 +1073,7 @@ static int ioat3_dma_probe(struct ioatdma_device *ioat_dma, int dca) | |||
1074 | struct ioatdma_chan *ioat_chan; | 1073 | struct ioatdma_chan *ioat_chan; |
1075 | bool is_raid_device = false; | 1074 | bool is_raid_device = false; |
1076 | int err; | 1075 | int err; |
1076 | u16 val16; | ||
1077 | 1077 | ||
1078 | dma = &ioat_dma->dma_dev; | 1078 | dma = &ioat_dma->dma_dev; |
1079 | dma->device_prep_dma_memcpy = ioat_dma_prep_memcpy_lock; | 1079 | dma->device_prep_dma_memcpy = ioat_dma_prep_memcpy_lock; |
@@ -1173,6 +1173,17 @@ static int ioat3_dma_probe(struct ioatdma_device *ioat_dma, int dca) | |||
1173 | if (dca) | 1173 | if (dca) |
1174 | ioat_dma->dca = ioat_dca_init(pdev, ioat_dma->reg_base); | 1174 | ioat_dma->dca = ioat_dca_init(pdev, ioat_dma->reg_base); |
1175 | 1175 | ||
1176 | /* disable relaxed ordering */ | ||
1177 | err = pcie_capability_read_word(pdev, IOAT_DEVCTRL_OFFSET, &val16); | ||
1178 | if (err) | ||
1179 | return err; | ||
1180 | |||
1181 | /* clear relaxed ordering enable */ | ||
1182 | val16 &= ~IOAT_DEVCTRL_ROE; | ||
1183 | err = pcie_capability_write_word(pdev, IOAT_DEVCTRL_OFFSET, val16); | ||
1184 | if (err) | ||
1185 | return err; | ||
1186 | |||
1176 | return 0; | 1187 | return 0; |
1177 | } | 1188 | } |
1178 | 1189 | ||
diff --git a/drivers/dma/ioat/registers.h b/drivers/dma/ioat/registers.h index 4994a3623aee..70534981a49b 100644 --- a/drivers/dma/ioat/registers.h +++ b/drivers/dma/ioat/registers.h | |||
@@ -26,6 +26,13 @@ | |||
26 | #define IOAT_PCI_CHANERR_INT_OFFSET 0x180 | 26 | #define IOAT_PCI_CHANERR_INT_OFFSET 0x180 |
27 | #define IOAT_PCI_CHANERRMASK_INT_OFFSET 0x184 | 27 | #define IOAT_PCI_CHANERRMASK_INT_OFFSET 0x184 |
28 | 28 | ||
29 | /* PCIe config registers */ | ||
30 | |||
31 | /* EXPCAPID + N */ | ||
32 | #define IOAT_DEVCTRL_OFFSET 0x8 | ||
33 | /* relaxed ordering enable */ | ||
34 | #define IOAT_DEVCTRL_ROE 0x10 | ||
35 | |||
29 | /* MMIO Device Registers */ | 36 | /* MMIO Device Registers */ |
30 | #define IOAT_CHANCNT_OFFSET 0x00 /* 8-bit */ | 37 | #define IOAT_CHANCNT_OFFSET 0x00 /* 8-bit */ |
31 | 38 | ||
diff --git a/drivers/dma/mmp_pdma.c b/drivers/dma/mmp_pdma.c index e39457f13d4d..56f1fd68b620 100644 --- a/drivers/dma/mmp_pdma.c +++ b/drivers/dma/mmp_pdma.c | |||
@@ -364,13 +364,12 @@ mmp_pdma_alloc_descriptor(struct mmp_pdma_chan *chan) | |||
364 | struct mmp_pdma_desc_sw *desc; | 364 | struct mmp_pdma_desc_sw *desc; |
365 | dma_addr_t pdesc; | 365 | dma_addr_t pdesc; |
366 | 366 | ||
367 | desc = dma_pool_alloc(chan->desc_pool, GFP_ATOMIC, &pdesc); | 367 | desc = dma_pool_zalloc(chan->desc_pool, GFP_ATOMIC, &pdesc); |
368 | if (!desc) { | 368 | if (!desc) { |
369 | dev_err(chan->dev, "out of memory for link descriptor\n"); | 369 | dev_err(chan->dev, "out of memory for link descriptor\n"); |
370 | return NULL; | 370 | return NULL; |
371 | } | 371 | } |
372 | 372 | ||
373 | memset(desc, 0, sizeof(*desc)); | ||
374 | INIT_LIST_HEAD(&desc->tx_list); | 373 | INIT_LIST_HEAD(&desc->tx_list); |
375 | dma_async_tx_descriptor_init(&desc->async_tx, &chan->chan); | 374 | dma_async_tx_descriptor_init(&desc->async_tx, &chan->chan); |
376 | /* each desc has submit */ | 375 | /* each desc has submit */ |
diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c index 1e1f2986eba8..faae0bfe1109 100644 --- a/drivers/dma/of-dma.c +++ b/drivers/dma/of-dma.c | |||
@@ -240,8 +240,9 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np, | |||
240 | struct of_phandle_args dma_spec; | 240 | struct of_phandle_args dma_spec; |
241 | struct of_dma *ofdma; | 241 | struct of_dma *ofdma; |
242 | struct dma_chan *chan; | 242 | struct dma_chan *chan; |
243 | int count, i; | 243 | int count, i, start; |
244 | int ret_no_channel = -ENODEV; | 244 | int ret_no_channel = -ENODEV; |
245 | static atomic_t last_index; | ||
245 | 246 | ||
246 | if (!np || !name) { | 247 | if (!np || !name) { |
247 | pr_err("%s: not enough information provided\n", __func__); | 248 | pr_err("%s: not enough information provided\n", __func__); |
@@ -259,8 +260,15 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np, | |||
259 | return ERR_PTR(-ENODEV); | 260 | return ERR_PTR(-ENODEV); |
260 | } | 261 | } |
261 | 262 | ||
263 | /* | ||
264 | * approximate an average distribution across multiple | ||
265 | * entries with the same name | ||
266 | */ | ||
267 | start = atomic_inc_return(&last_index); | ||
262 | for (i = 0; i < count; i++) { | 268 | for (i = 0; i < count; i++) { |
263 | if (of_dma_match_channel(np, name, i, &dma_spec)) | 269 | if (of_dma_match_channel(np, name, |
270 | (i + start) % count, | ||
271 | &dma_spec)) | ||
264 | continue; | 272 | continue; |
265 | 273 | ||
266 | mutex_lock(&of_dma_lock); | 274 | mutex_lock(&of_dma_lock); |
diff --git a/drivers/spi/spi-pxa2xx-pci.c b/drivers/spi/spi-pxa2xx-pci.c index 520ed1dd5780..4fd7f9802f1b 100644 --- a/drivers/spi/spi-pxa2xx-pci.c +++ b/drivers/spi/spi-pxa2xx-pci.c | |||
@@ -144,16 +144,16 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev, | |||
144 | struct dw_dma_slave *slave = c->tx_param; | 144 | struct dw_dma_slave *slave = c->tx_param; |
145 | 145 | ||
146 | slave->dma_dev = &dma_dev->dev; | 146 | slave->dma_dev = &dma_dev->dev; |
147 | slave->src_master = 1; | 147 | slave->m_master = 0; |
148 | slave->dst_master = 0; | 148 | slave->p_master = 1; |
149 | } | 149 | } |
150 | 150 | ||
151 | if (c->rx_param) { | 151 | if (c->rx_param) { |
152 | struct dw_dma_slave *slave = c->rx_param; | 152 | struct dw_dma_slave *slave = c->rx_param; |
153 | 153 | ||
154 | slave->dma_dev = &dma_dev->dev; | 154 | slave->dma_dev = &dma_dev->dev; |
155 | slave->src_master = 1; | 155 | slave->m_master = 0; |
156 | slave->dst_master = 0; | 156 | slave->p_master = 1; |
157 | } | 157 | } |
158 | 158 | ||
159 | spi_pdata.dma_filter = lpss_dma_filter; | 159 | spi_pdata.dma_filter = lpss_dma_filter; |
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c index 98862aa5bb58..5eea74d7f9f4 100644 --- a/drivers/tty/serial/8250/8250_pci.c +++ b/drivers/tty/serial/8250/8250_pci.c | |||
@@ -1454,13 +1454,13 @@ byt_serial_setup(struct serial_private *priv, | |||
1454 | return -EINVAL; | 1454 | return -EINVAL; |
1455 | } | 1455 | } |
1456 | 1456 | ||
1457 | rx_param->src_master = 1; | 1457 | rx_param->m_master = 0; |
1458 | rx_param->dst_master = 0; | 1458 | rx_param->p_master = 1; |
1459 | 1459 | ||
1460 | dma->rxconf.src_maxburst = 16; | 1460 | dma->rxconf.src_maxburst = 16; |
1461 | 1461 | ||
1462 | tx_param->src_master = 1; | 1462 | tx_param->m_master = 0; |
1463 | tx_param->dst_master = 0; | 1463 | tx_param->p_master = 1; |
1464 | 1464 | ||
1465 | dma->txconf.dst_maxburst = 16; | 1465 | dma->txconf.dst_maxburst = 16; |
1466 | 1466 | ||
diff --git a/include/linux/dma/dw.h b/include/linux/dma/dw.h index 71456442ebe3..f2e538aaddad 100644 --- a/include/linux/dma/dw.h +++ b/include/linux/dma/dw.h | |||
@@ -27,6 +27,7 @@ struct dw_dma; | |||
27 | * @regs: memory mapped I/O space | 27 | * @regs: memory mapped I/O space |
28 | * @clk: hclk clock | 28 | * @clk: hclk clock |
29 | * @dw: struct dw_dma that is filed by dw_dma_probe() | 29 | * @dw: struct dw_dma that is filed by dw_dma_probe() |
30 | * @pdata: pointer to platform data | ||
30 | */ | 31 | */ |
31 | struct dw_dma_chip { | 32 | struct dw_dma_chip { |
32 | struct device *dev; | 33 | struct device *dev; |
@@ -34,10 +35,12 @@ struct dw_dma_chip { | |||
34 | void __iomem *regs; | 35 | void __iomem *regs; |
35 | struct clk *clk; | 36 | struct clk *clk; |
36 | struct dw_dma *dw; | 37 | struct dw_dma *dw; |
38 | |||
39 | const struct dw_dma_platform_data *pdata; | ||
37 | }; | 40 | }; |
38 | 41 | ||
39 | /* Export to the platform drivers */ | 42 | /* Export to the platform drivers */ |
40 | int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata); | 43 | int dw_dma_probe(struct dw_dma_chip *chip); |
41 | int dw_dma_remove(struct dw_dma_chip *chip); | 44 | int dw_dma_remove(struct dw_dma_chip *chip); |
42 | 45 | ||
43 | /* DMA API extensions */ | 46 | /* DMA API extensions */ |
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h index 017433712833..30de0197263a 100644 --- a/include/linux/dmaengine.h +++ b/include/linux/dmaengine.h | |||
@@ -804,6 +804,9 @@ static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_single( | |||
804 | sg_dma_address(&sg) = buf; | 804 | sg_dma_address(&sg) = buf; |
805 | sg_dma_len(&sg) = len; | 805 | sg_dma_len(&sg) = len; |
806 | 806 | ||
807 | if (!chan || !chan->device || !chan->device->device_prep_slave_sg) | ||
808 | return NULL; | ||
809 | |||
807 | return chan->device->device_prep_slave_sg(chan, &sg, 1, | 810 | return chan->device->device_prep_slave_sg(chan, &sg, 1, |
808 | dir, flags, NULL); | 811 | dir, flags, NULL); |
809 | } | 812 | } |
@@ -812,6 +815,9 @@ static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_sg( | |||
812 | struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len, | 815 | struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len, |
813 | enum dma_transfer_direction dir, unsigned long flags) | 816 | enum dma_transfer_direction dir, unsigned long flags) |
814 | { | 817 | { |
818 | if (!chan || !chan->device || !chan->device->device_prep_slave_sg) | ||
819 | return NULL; | ||
820 | |||
815 | return chan->device->device_prep_slave_sg(chan, sgl, sg_len, | 821 | return chan->device->device_prep_slave_sg(chan, sgl, sg_len, |
816 | dir, flags, NULL); | 822 | dir, flags, NULL); |
817 | } | 823 | } |
@@ -823,6 +829,9 @@ static inline struct dma_async_tx_descriptor *dmaengine_prep_rio_sg( | |||
823 | enum dma_transfer_direction dir, unsigned long flags, | 829 | enum dma_transfer_direction dir, unsigned long flags, |
824 | struct rio_dma_ext *rio_ext) | 830 | struct rio_dma_ext *rio_ext) |
825 | { | 831 | { |
832 | if (!chan || !chan->device || !chan->device->device_prep_slave_sg) | ||
833 | return NULL; | ||
834 | |||
826 | return chan->device->device_prep_slave_sg(chan, sgl, sg_len, | 835 | return chan->device->device_prep_slave_sg(chan, sgl, sg_len, |
827 | dir, flags, rio_ext); | 836 | dir, flags, rio_ext); |
828 | } | 837 | } |
@@ -833,6 +842,9 @@ static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_cyclic( | |||
833 | size_t period_len, enum dma_transfer_direction dir, | 842 | size_t period_len, enum dma_transfer_direction dir, |
834 | unsigned long flags) | 843 | unsigned long flags) |
835 | { | 844 | { |
845 | if (!chan || !chan->device || !chan->device->device_prep_dma_cyclic) | ||
846 | return NULL; | ||
847 | |||
836 | return chan->device->device_prep_dma_cyclic(chan, buf_addr, buf_len, | 848 | return chan->device->device_prep_dma_cyclic(chan, buf_addr, buf_len, |
837 | period_len, dir, flags); | 849 | period_len, dir, flags); |
838 | } | 850 | } |
@@ -841,6 +853,9 @@ static inline struct dma_async_tx_descriptor *dmaengine_prep_interleaved_dma( | |||
841 | struct dma_chan *chan, struct dma_interleaved_template *xt, | 853 | struct dma_chan *chan, struct dma_interleaved_template *xt, |
842 | unsigned long flags) | 854 | unsigned long flags) |
843 | { | 855 | { |
856 | if (!chan || !chan->device || !chan->device->device_prep_interleaved_dma) | ||
857 | return NULL; | ||
858 | |||
844 | return chan->device->device_prep_interleaved_dma(chan, xt, flags); | 859 | return chan->device->device_prep_interleaved_dma(chan, xt, flags); |
845 | } | 860 | } |
846 | 861 | ||
@@ -848,7 +863,7 @@ static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_memset( | |||
848 | struct dma_chan *chan, dma_addr_t dest, int value, size_t len, | 863 | struct dma_chan *chan, dma_addr_t dest, int value, size_t len, |
849 | unsigned long flags) | 864 | unsigned long flags) |
850 | { | 865 | { |
851 | if (!chan || !chan->device) | 866 | if (!chan || !chan->device || !chan->device->device_prep_dma_memset) |
852 | return NULL; | 867 | return NULL; |
853 | 868 | ||
854 | return chan->device->device_prep_dma_memset(chan, dest, value, | 869 | return chan->device->device_prep_dma_memset(chan, dest, value, |
@@ -861,6 +876,9 @@ static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_sg( | |||
861 | struct scatterlist *src_sg, unsigned int src_nents, | 876 | struct scatterlist *src_sg, unsigned int src_nents, |
862 | unsigned long flags) | 877 | unsigned long flags) |
863 | { | 878 | { |
879 | if (!chan || !chan->device || !chan->device->device_prep_dma_sg) | ||
880 | return NULL; | ||
881 | |||
864 | return chan->device->device_prep_dma_sg(chan, dst_sg, dst_nents, | 882 | return chan->device->device_prep_dma_sg(chan, dst_sg, dst_nents, |
865 | src_sg, src_nents, flags); | 883 | src_sg, src_nents, flags); |
866 | } | 884 | } |
diff --git a/include/linux/platform_data/dma-dw.h b/include/linux/platform_data/dma-dw.h index 03b6095d3b18..d15d8ba8cc24 100644 --- a/include/linux/platform_data/dma-dw.h +++ b/include/linux/platform_data/dma-dw.h | |||
@@ -21,15 +21,15 @@ | |||
21 | * @dma_dev: required DMA master device | 21 | * @dma_dev: required DMA master device |
22 | * @src_id: src request line | 22 | * @src_id: src request line |
23 | * @dst_id: dst request line | 23 | * @dst_id: dst request line |
24 | * @src_master: src master for transfers on allocated channel. | 24 | * @m_master: memory master for transfers on allocated channel |
25 | * @dst_master: dest master for transfers on allocated channel. | 25 | * @p_master: peripheral master for transfers on allocated channel |
26 | */ | 26 | */ |
27 | struct dw_dma_slave { | 27 | struct dw_dma_slave { |
28 | struct device *dma_dev; | 28 | struct device *dma_dev; |
29 | u8 src_id; | 29 | u8 src_id; |
30 | u8 dst_id; | 30 | u8 dst_id; |
31 | u8 src_master; | 31 | u8 m_master; |
32 | u8 dst_master; | 32 | u8 p_master; |
33 | }; | 33 | }; |
34 | 34 | ||
35 | /** | 35 | /** |
@@ -43,7 +43,7 @@ struct dw_dma_slave { | |||
43 | * @block_size: Maximum block size supported by the controller | 43 | * @block_size: Maximum block size supported by the controller |
44 | * @nr_masters: Number of AHB masters supported by the controller | 44 | * @nr_masters: Number of AHB masters supported by the controller |
45 | * @data_width: Maximum data width supported by hardware per AHB master | 45 | * @data_width: Maximum data width supported by hardware per AHB master |
46 | * (0 - 8bits, 1 - 16bits, ..., 5 - 256bits) | 46 | * (in bytes, power of 2) |
47 | */ | 47 | */ |
48 | struct dw_dma_platform_data { | 48 | struct dw_dma_platform_data { |
49 | unsigned int nr_channels; | 49 | unsigned int nr_channels; |
@@ -55,7 +55,7 @@ struct dw_dma_platform_data { | |||
55 | #define CHAN_PRIORITY_ASCENDING 0 /* chan0 highest */ | 55 | #define CHAN_PRIORITY_ASCENDING 0 /* chan0 highest */ |
56 | #define CHAN_PRIORITY_DESCENDING 1 /* chan7 highest */ | 56 | #define CHAN_PRIORITY_DESCENDING 1 /* chan7 highest */ |
57 | unsigned char chan_priority; | 57 | unsigned char chan_priority; |
58 | unsigned short block_size; | 58 | unsigned int block_size; |
59 | unsigned char nr_masters; | 59 | unsigned char nr_masters; |
60 | unsigned char data_width[DW_DMA_MAX_NR_MASTERS]; | 60 | unsigned char data_width[DW_DMA_MAX_NR_MASTERS]; |
61 | }; | 61 | }; |
diff --git a/sound/soc/intel/common/sst-firmware.c b/sound/soc/intel/common/sst-firmware.c index ef4881e7753a..25993527370b 100644 --- a/sound/soc/intel/common/sst-firmware.c +++ b/sound/soc/intel/common/sst-firmware.c | |||
@@ -203,7 +203,7 @@ static struct dw_dma_chip *dw_probe(struct device *dev, struct resource *mem, | |||
203 | 203 | ||
204 | chip->dev = dev; | 204 | chip->dev = dev; |
205 | 205 | ||
206 | err = dw_dma_probe(chip, NULL); | 206 | err = dw_dma_probe(chip); |
207 | if (err) | 207 | if (err) |
208 | return ERR_PTR(err); | 208 | return ERR_PTR(err); |
209 | 209 | ||