Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'dmaengine' of git://git.linaro.org/people/rmk/linux-arm

Pull ARM DMA engine updates from Russell King:
"This looks scary at first glance, but what it is is:
- a rework of the sa11x0 DMA engine driver merged during the previous
cycle, to extract a common set of helper functions for DMA engine
implementations.
- conversion of amba-pl08x.c to use these helper functions.
- addition of OMAP DMA engine driver (using these helper functions),
and conversion of some of the OMAP DMA users to use DMA engine.

Nothing in the helper functions is ARM specific, so I hope that other
implementations can consolidate some of their code by making use of
these helpers.

This has been sitting in linux-next most of the merge cycle, and has
been tested by several OMAP folk. I've tested it on sa11x0 platforms,
and given it my best shot on my broken platforms which have the
amba-pl08x controller.

The last point is the addition to feature-removal-schedule.txt, which
will have a merge conflict. Between myself and TI, we're planning to
remove the old TI DMA implementation next year."

Fix up trivial add/add conflicts in Documentation/feature-removal-schedule.txt
and drivers/dma/{Kconfig,Makefile}

* 'dmaengine' of git://git.linaro.org/people/rmk/linux-arm: (53 commits)
ARM: 7481/1: OMAP2+: omap2plus_defconfig: enable OMAP DMA engine
ARM: 7464/1: mmc: omap_hsmmc: ensure probe returns error if DMA channel request fails
Add feature removal of old OMAP private DMA implementation
mtd: omap2: remove private DMA API implementation
mtd: omap2: add DMA engine support
spi: omap2-mcspi: remove private DMA API implementation
spi: omap2-mcspi: add DMA engine support
ARM: omap: remove mmc platform data dma_mask and initialization
mmc: omap: remove private DMA API implementation
mmc: omap: add DMA engine support
mmc: omap_hsmmc: remove private DMA API implementation
mmc: omap_hsmmc: add DMA engine support
dmaengine: omap: add support for cyclic DMA
dmaengine: omap: add support for setting fi
dmaengine: omap: add support for returning residue in tx_state method
dmaengine: add OMAP DMA engine driver
dmaengine: sa11x0-dma: add cyclic DMA support
dmaengine: sa11x0-dma: fix DMA residue support
dmaengine: PL08x: ensure all descriptors are freed when channel is released
dmaengine: PL08x: get rid of write only pool_ctr and free_txd locking
...

+2131 -1422
+11
Documentation/feature-removal-schedule.txt
··· 626 626 Who: Sylwester Nawrocki <s.nawrocki@samsung.com> 627 627 628 628 ---------------------------- 629 + 630 + What: OMAP private DMA implementation 631 + When: 2013 632 + Why: We have a DMA engine implementation; all users should be updated 633 + to use this rather than persisting with the old APIs. The old APIs 634 + block merging the old DMA engine implementation into the DMA 635 + engine driver. 636 + Who: Russell King <linux@arm.linux.org.uk>, 637 + Santosh Shilimkar <santosh.shilimkar@ti.com> 638 + 639 + ----------------------------
+2
arch/arm/configs/omap2plus_defconfig
··· 193 193 CONFIG_RTC_CLASS=y 194 194 CONFIG_RTC_DRV_TWL92330=y 195 195 CONFIG_RTC_DRV_TWL4030=y 196 + CONFIG_DMADEVICES=y 197 + CONFIG_DMA_OMAP=y 196 198 CONFIG_EXT2_FS=y 197 199 CONFIG_EXT3_FS=y 198 200 # CONFIG_EXT3_FS_XATTR is not set
-1
arch/arm/mach-omap1/board-h2-mmc.c
··· 54 54 .nr_slots = 1, 55 55 .init = mmc_late_init, 56 56 .cleanup = mmc_cleanup, 57 - .dma_mask = 0xffffffff, 58 57 .slots[0] = { 59 58 .set_power = mmc_set_power, 60 59 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
-1
arch/arm/mach-omap1/board-h3-mmc.c
··· 36 36 */ 37 37 static struct omap_mmc_platform_data mmc1_data = { 38 38 .nr_slots = 1, 39 - .dma_mask = 0xffffffff, 40 39 .slots[0] = { 41 40 .set_power = mmc_set_power, 42 41 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
-1
arch/arm/mach-omap1/board-nokia770.c
··· 185 185 186 186 static struct omap_mmc_platform_data nokia770_mmc2_data = { 187 187 .nr_slots = 1, 188 - .dma_mask = 0xffffffff, 189 188 .max_freq = 12000000, 190 189 .slots[0] = { 191 190 .set_power = nokia770_mmc_set_power,
-1
arch/arm/mach-omap2/board-n8x0.c
··· 468 468 .cleanup = n8x0_mmc_cleanup, 469 469 .shutdown = n8x0_mmc_shutdown, 470 470 .max_freq = 24000000, 471 - .dma_mask = 0xffffffff, 472 471 .slots[0] = { 473 472 .wires = 4, 474 473 .set_power = n8x0_mmc_set_power,
-1
arch/arm/mach-omap2/hsmmc.c
··· 315 315 mmc->slots[0].caps = c->caps; 316 316 mmc->slots[0].pm_caps = c->pm_caps; 317 317 mmc->slots[0].internal_clock = !c->ext_clock; 318 - mmc->dma_mask = 0xffffffff; 319 318 mmc->max_freq = c->max_freq; 320 319 if (cpu_is_omap44xx()) 321 320 mmc->reg_offset = OMAP4_MMC_REG_OFFSET;
-26
arch/arm/mach-spear3xx/spear300.c
··· 120 120 .min_signal = 2, 121 121 .max_signal = 2, 122 122 .muxval = 0, 123 - .cctl = 0, 124 123 .periph_buses = PL08X_AHB1, 125 124 }, { 126 125 .bus_id = "uart0_tx", 127 126 .min_signal = 3, 128 127 .max_signal = 3, 129 128 .muxval = 0, 130 - .cctl = 0, 131 129 .periph_buses = PL08X_AHB1, 132 130 }, { 133 131 .bus_id = "ssp0_rx", 134 132 .min_signal = 8, 135 133 .max_signal = 8, 136 134 .muxval = 0, 137 - .cctl = 0, 138 135 .periph_buses = PL08X_AHB1, 139 136 }, { 140 137 .bus_id = "ssp0_tx", 141 138 .min_signal = 9, 142 139 .max_signal = 9, 143 140 .muxval = 0, 144 - .cctl = 0, 145 141 .periph_buses = PL08X_AHB1, 146 142 }, { 147 143 .bus_id = "i2c_rx", 148 144 .min_signal = 10, 149 145 .max_signal = 10, 150 146 .muxval = 0, 151 - .cctl = 0, 152 147 .periph_buses = PL08X_AHB1, 153 148 }, { 154 149 .bus_id = "i2c_tx", 155 150 .min_signal = 11, 156 151 .max_signal = 11, 157 152 .muxval = 0, 158 - .cctl = 0, 159 153 .periph_buses = PL08X_AHB1, 160 154 }, { 161 155 .bus_id = "irda", 162 156 .min_signal = 12, 163 157 .max_signal = 12, 164 158 .muxval = 0, 165 - .cctl = 0, 166 159 .periph_buses = PL08X_AHB1, 167 160 }, { 168 161 .bus_id = "adc", 169 162 .min_signal = 13, 170 163 .max_signal = 13, 171 164 .muxval = 0, 172 - .cctl = 0, 173 165 .periph_buses = PL08X_AHB1, 174 166 }, { 175 167 .bus_id = "to_jpeg", 176 168 .min_signal = 14, 177 169 .max_signal = 14, 178 170 .muxval = 0, 179 - .cctl = 0, 180 171 .periph_buses = PL08X_AHB1, 181 172 }, { 182 173 .bus_id = "from_jpeg", 183 174 .min_signal = 15, 184 175 .max_signal = 15, 185 176 .muxval = 0, 186 - .cctl = 0, 187 177 .periph_buses = PL08X_AHB1, 188 178 }, { 189 179 .bus_id = "ras0_rx", 190 180 .min_signal = 0, 191 181 .max_signal = 0, 192 182 .muxval = 1, 193 - .cctl = 0, 194 183 .periph_buses = PL08X_AHB1, 195 184 }, { 196 185 .bus_id = "ras0_tx", 197 186 .min_signal = 1, 198 187 .max_signal = 1, 199 188 .muxval = 1, 200 - .cctl = 0, 201 189 .periph_buses = PL08X_AHB1, 202 190 }, { 203 191 .bus_id = "ras1_rx", 204 192 .min_signal = 2, 205 193 .max_signal = 2, 206 194 .muxval = 1, 207 - .cctl = 0, 208 195 .periph_buses = PL08X_AHB1, 209 196 }, { 210 197 .bus_id = "ras1_tx", 211 198 .min_signal = 3, 212 199 .max_signal = 3, 213 200 .muxval = 1, 214 - .cctl = 0, 215 201 .periph_buses = PL08X_AHB1, 216 202 }, { 217 203 .bus_id = "ras2_rx", 218 204 .min_signal = 4, 219 205 .max_signal = 4, 220 206 .muxval = 1, 221 - .cctl = 0, 222 207 .periph_buses = PL08X_AHB1, 223 208 }, { 224 209 .bus_id = "ras2_tx", 225 210 .min_signal = 5, 226 211 .max_signal = 5, 227 212 .muxval = 1, 228 - .cctl = 0, 229 213 .periph_buses = PL08X_AHB1, 230 214 }, { 231 215 .bus_id = "ras3_rx", 232 216 .min_signal = 6, 233 217 .max_signal = 6, 234 218 .muxval = 1, 235 - .cctl = 0, 236 219 .periph_buses = PL08X_AHB1, 237 220 }, { 238 221 .bus_id = "ras3_tx", 239 222 .min_signal = 7, 240 223 .max_signal = 7, 241 224 .muxval = 1, 242 - .cctl = 0, 243 225 .periph_buses = PL08X_AHB1, 244 226 }, { 245 227 .bus_id = "ras4_rx", 246 228 .min_signal = 8, 247 229 .max_signal = 8, 248 230 .muxval = 1, 249 - .cctl = 0, 250 231 .periph_buses = PL08X_AHB1, 251 232 }, { 252 233 .bus_id = "ras4_tx", 253 234 .min_signal = 9, 254 235 .max_signal = 9, 255 236 .muxval = 1, 256 - .cctl = 0, 257 237 .periph_buses = PL08X_AHB1, 258 238 }, { 259 239 .bus_id = "ras5_rx", 260 240 .min_signal = 10, 261 241 .max_signal = 10, 262 242 .muxval = 1, 263 - .cctl = 0, 264 243 .periph_buses = PL08X_AHB1, 265 244 }, { 266 245 .bus_id = "ras5_tx", 267 246 .min_signal = 11, 268 247 .max_signal = 11, 269 248 .muxval = 1, 270 - .cctl = 0, 271 249 .periph_buses = PL08X_AHB1, 272 250 }, { 273 251 .bus_id = "ras6_rx", 274 252 .min_signal = 12, 275 253 .max_signal = 12, 276 254 .muxval = 1, 277 - .cctl = 0, 278 255 .periph_buses = PL08X_AHB1, 279 256 }, { 280 257 .bus_id = "ras6_tx", 281 258 .min_signal = 13, 282 259 .max_signal = 13, 283 260 .muxval = 1, 284 - .cctl = 0, 285 261 .periph_buses = PL08X_AHB1, 286 262 }, { 287 263 .bus_id = "ras7_rx", 288 264 .min_signal = 14, 289 265 .max_signal = 14, 290 266 .muxval = 1, 291 - .cctl = 0, 292 267 .periph_buses = PL08X_AHB1, 293 268 }, { 294 269 .bus_id = "ras7_tx", 295 270 .min_signal = 15, 296 271 .max_signal = 15, 297 272 .muxval = 1, 298 - .cctl = 0, 299 273 .periph_buses = PL08X_AHB1, 300 274 }, 301 275 };
-26
arch/arm/mach-spear3xx/spear310.c
··· 205 205 .min_signal = 2, 206 206 .max_signal = 2, 207 207 .muxval = 0, 208 - .cctl = 0, 209 208 .periph_buses = PL08X_AHB1, 210 209 }, { 211 210 .bus_id = "uart0_tx", 212 211 .min_signal = 3, 213 212 .max_signal = 3, 214 213 .muxval = 0, 215 - .cctl = 0, 216 214 .periph_buses = PL08X_AHB1, 217 215 }, { 218 216 .bus_id = "ssp0_rx", 219 217 .min_signal = 8, 220 218 .max_signal = 8, 221 219 .muxval = 0, 222 - .cctl = 0, 223 220 .periph_buses = PL08X_AHB1, 224 221 }, { 225 222 .bus_id = "ssp0_tx", 226 223 .min_signal = 9, 227 224 .max_signal = 9, 228 225 .muxval = 0, 229 - .cctl = 0, 230 226 .periph_buses = PL08X_AHB1, 231 227 }, { 232 228 .bus_id = "i2c_rx", 233 229 .min_signal = 10, 234 230 .max_signal = 10, 235 231 .muxval = 0, 236 - .cctl = 0, 237 232 .periph_buses = PL08X_AHB1, 238 233 }, { 239 234 .bus_id = "i2c_tx", 240 235 .min_signal = 11, 241 236 .max_signal = 11, 242 237 .muxval = 0, 243 - .cctl = 0, 244 238 .periph_buses = PL08X_AHB1, 245 239 }, { 246 240 .bus_id = "irda", 247 241 .min_signal = 12, 248 242 .max_signal = 12, 249 243 .muxval = 0, 250 - .cctl = 0, 251 244 .periph_buses = PL08X_AHB1, 252 245 }, { 253 246 .bus_id = "adc", 254 247 .min_signal = 13, 255 248 .max_signal = 13, 256 249 .muxval = 0, 257 - .cctl = 0, 258 250 .periph_buses = PL08X_AHB1, 259 251 }, { 260 252 .bus_id = "to_jpeg", 261 253 .min_signal = 14, 262 254 .max_signal = 14, 263 255 .muxval = 0, 264 - .cctl = 0, 265 256 .periph_buses = PL08X_AHB1, 266 257 }, { 267 258 .bus_id = "from_jpeg", 268 259 .min_signal = 15, 269 260 .max_signal = 15, 270 261 .muxval = 0, 271 - .cctl = 0, 272 262 .periph_buses = PL08X_AHB1, 273 263 }, { 274 264 .bus_id = "uart1_rx", 275 265 .min_signal = 0, 276 266 .max_signal = 0, 277 267 .muxval = 1, 278 - .cctl = 0, 279 268 .periph_buses = PL08X_AHB1, 280 269 }, { 281 270 .bus_id = "uart1_tx", 282 271 .min_signal = 1, 283 272 .max_signal = 1, 284 273 .muxval = 1, 285 - .cctl = 0, 286 274 .periph_buses = PL08X_AHB1, 287 275 }, { 288 276 .bus_id = "uart2_rx", 289 277 .min_signal = 2, 290 278 .max_signal = 2, 291 279 .muxval = 1, 292 - .cctl = 0, 293 280 .periph_buses = PL08X_AHB1, 294 281 }, { 295 282 .bus_id = "uart2_tx", 296 283 .min_signal = 3, 297 284 .max_signal = 3, 298 285 .muxval = 1, 299 - .cctl = 0, 300 286 .periph_buses = PL08X_AHB1, 301 287 }, { 302 288 .bus_id = "uart3_rx", 303 289 .min_signal = 4, 304 290 .max_signal = 4, 305 291 .muxval = 1, 306 - .cctl = 0, 307 292 .periph_buses = PL08X_AHB1, 308 293 }, { 309 294 .bus_id = "uart3_tx", 310 295 .min_signal = 5, 311 296 .max_signal = 5, 312 297 .muxval = 1, 313 - .cctl = 0, 314 298 .periph_buses = PL08X_AHB1, 315 299 }, { 316 300 .bus_id = "uart4_rx", 317 301 .min_signal = 6, 318 302 .max_signal = 6, 319 303 .muxval = 1, 320 - .cctl = 0, 321 304 .periph_buses = PL08X_AHB1, 322 305 }, { 323 306 .bus_id = "uart4_tx", 324 307 .min_signal = 7, 325 308 .max_signal = 7, 326 309 .muxval = 1, 327 - .cctl = 0, 328 310 .periph_buses = PL08X_AHB1, 329 311 }, { 330 312 .bus_id = "uart5_rx", 331 313 .min_signal = 8, 332 314 .max_signal = 8, 333 315 .muxval = 1, 334 - .cctl = 0, 335 316 .periph_buses = PL08X_AHB1, 336 317 }, { 337 318 .bus_id = "uart5_tx", 338 319 .min_signal = 9, 339 320 .max_signal = 9, 340 321 .muxval = 1, 341 - .cctl = 0, 342 322 .periph_buses = PL08X_AHB1, 343 323 }, { 344 324 .bus_id = "ras5_rx", 345 325 .min_signal = 10, 346 326 .max_signal = 10, 347 327 .muxval = 1, 348 - .cctl = 0, 349 328 .periph_buses = PL08X_AHB1, 350 329 }, { 351 330 .bus_id = "ras5_tx", 352 331 .min_signal = 11, 353 332 .max_signal = 11, 354 333 .muxval = 1, 355 - .cctl = 0, 356 334 .periph_buses = PL08X_AHB1, 357 335 }, { 358 336 .bus_id = "ras6_rx", 359 337 .min_signal = 12, 360 338 .max_signal = 12, 361 339 .muxval = 1, 362 - .cctl = 0, 363 340 .periph_buses = PL08X_AHB1, 364 341 }, { 365 342 .bus_id = "ras6_tx", 366 343 .min_signal = 13, 367 344 .max_signal = 13, 368 345 .muxval = 1, 369 - .cctl = 0, 370 346 .periph_buses = PL08X_AHB1, 371 347 }, { 372 348 .bus_id = "ras7_rx", 373 349 .min_signal = 14, 374 350 .max_signal = 14, 375 351 .muxval = 1, 376 - .cctl = 0, 377 352 .periph_buses = PL08X_AHB1, 378 353 }, { 379 354 .bus_id = "ras7_tx", 380 355 .min_signal = 15, 381 356 .max_signal = 15, 382 357 .muxval = 1, 383 - .cctl = 0, 384 358 .periph_buses = PL08X_AHB1, 385 359 }, 386 360 };
-26
arch/arm/mach-spear3xx/spear320.c
··· 213 213 .min_signal = 2, 214 214 .max_signal = 2, 215 215 .muxval = 0, 216 - .cctl = 0, 217 216 .periph_buses = PL08X_AHB1, 218 217 }, { 219 218 .bus_id = "uart0_tx", 220 219 .min_signal = 3, 221 220 .max_signal = 3, 222 221 .muxval = 0, 223 - .cctl = 0, 224 222 .periph_buses = PL08X_AHB1, 225 223 }, { 226 224 .bus_id = "ssp0_rx", 227 225 .min_signal = 8, 228 226 .max_signal = 8, 229 227 .muxval = 0, 230 - .cctl = 0, 231 228 .periph_buses = PL08X_AHB1, 232 229 }, { 233 230 .bus_id = "ssp0_tx", 234 231 .min_signal = 9, 235 232 .max_signal = 9, 236 233 .muxval = 0, 237 - .cctl = 0, 238 234 .periph_buses = PL08X_AHB1, 239 235 }, { 240 236 .bus_id = "i2c0_rx", 241 237 .min_signal = 10, 242 238 .max_signal = 10, 243 239 .muxval = 0, 244 - .cctl = 0, 245 240 .periph_buses = PL08X_AHB1, 246 241 }, { 247 242 .bus_id = "i2c0_tx", 248 243 .min_signal = 11, 249 244 .max_signal = 11, 250 245 .muxval = 0, 251 - .cctl = 0, 252 246 .periph_buses = PL08X_AHB1, 253 247 }, { 254 248 .bus_id = "irda", 255 249 .min_signal = 12, 256 250 .max_signal = 12, 257 251 .muxval = 0, 258 - .cctl = 0, 259 252 .periph_buses = PL08X_AHB1, 260 253 }, { 261 254 .bus_id = "adc", 262 255 .min_signal = 13, 263 256 .max_signal = 13, 264 257 .muxval = 0, 265 - .cctl = 0, 266 258 .periph_buses = PL08X_AHB1, 267 259 }, { 268 260 .bus_id = "to_jpeg", 269 261 .min_signal = 14, 270 262 .max_signal = 14, 271 263 .muxval = 0, 272 - .cctl = 0, 273 264 .periph_buses = PL08X_AHB1, 274 265 }, { 275 266 .bus_id = "from_jpeg", 276 267 .min_signal = 15, 277 268 .max_signal = 15, 278 269 .muxval = 0, 279 - .cctl = 0, 280 270 .periph_buses = PL08X_AHB1, 281 271 }, { 282 272 .bus_id = "ssp1_rx", 283 273 .min_signal = 0, 284 274 .max_signal = 0, 285 275 .muxval = 1, 286 - .cctl = 0, 287 276 .periph_buses = PL08X_AHB2, 288 277 }, { 289 278 .bus_id = "ssp1_tx", 290 279 .min_signal = 1, 291 280 .max_signal = 1, 292 281 .muxval = 1, 293 - .cctl = 0, 294 282 .periph_buses = PL08X_AHB2, 295 283 }, { 296 284 .bus_id = "ssp2_rx", 297 285 .min_signal = 2, 298 286 .max_signal = 2, 299 287 .muxval = 1, 300 - .cctl = 0, 301 288 .periph_buses = PL08X_AHB2, 302 289 }, { 303 290 .bus_id = "ssp2_tx", 304 291 .min_signal = 3, 305 292 .max_signal = 3, 306 293 .muxval = 1, 307 - .cctl = 0, 308 294 .periph_buses = PL08X_AHB2, 309 295 }, { 310 296 .bus_id = "uart1_rx", 311 297 .min_signal = 4, 312 298 .max_signal = 4, 313 299 .muxval = 1, 314 - .cctl = 0, 315 300 .periph_buses = PL08X_AHB2, 316 301 }, { 317 302 .bus_id = "uart1_tx", 318 303 .min_signal = 5, 319 304 .max_signal = 5, 320 305 .muxval = 1, 321 - .cctl = 0, 322 306 .periph_buses = PL08X_AHB2, 323 307 }, { 324 308 .bus_id = "uart2_rx", 325 309 .min_signal = 6, 326 310 .max_signal = 6, 327 311 .muxval = 1, 328 - .cctl = 0, 329 312 .periph_buses = PL08X_AHB2, 330 313 }, { 331 314 .bus_id = "uart2_tx", 332 315 .min_signal = 7, 333 316 .max_signal = 7, 334 317 .muxval = 1, 335 - .cctl = 0, 336 318 .periph_buses = PL08X_AHB2, 337 319 }, { 338 320 .bus_id = "i2c1_rx", 339 321 .min_signal = 8, 340 322 .max_signal = 8, 341 323 .muxval = 1, 342 - .cctl = 0, 343 324 .periph_buses = PL08X_AHB2, 344 325 }, { 345 326 .bus_id = "i2c1_tx", 346 327 .min_signal = 9, 347 328 .max_signal = 9, 348 329 .muxval = 1, 349 - .cctl = 0, 350 330 .periph_buses = PL08X_AHB2, 351 331 }, { 352 332 .bus_id = "i2c2_rx", 353 333 .min_signal = 10, 354 334 .max_signal = 10, 355 335 .muxval = 1, 356 - .cctl = 0, 357 336 .periph_buses = PL08X_AHB2, 358 337 }, { 359 338 .bus_id = "i2c2_tx", 360 339 .min_signal = 11, 361 340 .max_signal = 11, 362 341 .muxval = 1, 363 - .cctl = 0, 364 342 .periph_buses = PL08X_AHB2, 365 343 }, { 366 344 .bus_id = "i2s_rx", 367 345 .min_signal = 12, 368 346 .max_signal = 12, 369 347 .muxval = 1, 370 - .cctl = 0, 371 348 .periph_buses = PL08X_AHB2, 372 349 }, { 373 350 .bus_id = "i2s_tx", 374 351 .min_signal = 13, 375 352 .max_signal = 13, 376 353 .muxval = 1, 377 - .cctl = 0, 378 354 .periph_buses = PL08X_AHB2, 379 355 }, { 380 356 .bus_id = "rs485_rx", 381 357 .min_signal = 14, 382 358 .max_signal = 14, 383 359 .muxval = 1, 384 - .cctl = 0, 385 360 .periph_buses = PL08X_AHB2, 386 361 }, { 387 362 .bus_id = "rs485_tx", 388 363 .min_signal = 15, 389 364 .max_signal = 15, 390 365 .muxval = 1, 391 - .cctl = 0, 392 366 .periph_buses = PL08X_AHB2, 393 367 }, 394 368 };
+2 -1
arch/arm/mach-spear3xx/spear3xx.c
··· 46 46 struct pl08x_platform_data pl080_plat_data = { 47 47 .memcpy_channel = { 48 48 .bus_id = "memcpy", 49 - .cctl = (PL080_BSIZE_16 << PL080_CONTROL_SB_SIZE_SHIFT | \ 49 + .cctl_memcpy = 50 + (PL080_BSIZE_16 << PL080_CONTROL_SB_SIZE_SHIFT | \ 50 51 PL080_BSIZE_16 << PL080_CONTROL_DB_SIZE_SHIFT | \ 51 52 PL080_WIDTH_32BIT << PL080_CONTROL_SWIDTH_SHIFT | \ 52 53 PL080_WIDTH_32BIT << PL080_CONTROL_DWIDTH_SHIFT | \
+2 -49
arch/arm/mach-spear6xx/spear6xx.c
··· 36 36 .min_signal = 0, 37 37 .max_signal = 0, 38 38 .muxval = 0, 39 - .cctl = 0, 40 39 .periph_buses = PL08X_AHB1, 41 40 }, { 42 41 .bus_id = "ssp1_tx", 43 42 .min_signal = 1, 44 43 .max_signal = 1, 45 44 .muxval = 0, 46 - .cctl = 0, 47 45 .periph_buses = PL08X_AHB1, 48 46 }, { 49 47 .bus_id = "uart0_rx", 50 48 .min_signal = 2, 51 49 .max_signal = 2, 52 50 .muxval = 0, 53 - .cctl = 0, 54 51 .periph_buses = PL08X_AHB1, 55 52 }, { 56 53 .bus_id = "uart0_tx", 57 54 .min_signal = 3, 58 55 .max_signal = 3, 59 56 .muxval = 0, 60 - .cctl = 0, 61 57 .periph_buses = PL08X_AHB1, 62 58 }, { 63 59 .bus_id = "uart1_rx", 64 60 .min_signal = 4, 65 61 .max_signal = 4, 66 62 .muxval = 0, 67 - .cctl = 0, 68 63 .periph_buses = PL08X_AHB1, 69 64 }, { 70 65 .bus_id = "uart1_tx", 71 66 .min_signal = 5, 72 67 .max_signal = 5, 73 68 .muxval = 0, 74 - .cctl = 0, 75 69 .periph_buses = PL08X_AHB1, 76 70 }, { 77 71 .bus_id = "ssp2_rx", 78 72 .min_signal = 6, 79 73 .max_signal = 6, 80 74 .muxval = 0, 81 - .cctl = 0, 82 75 .periph_buses = PL08X_AHB2, 83 76 }, { 84 77 .bus_id = "ssp2_tx", 85 78 .min_signal = 7, 86 79 .max_signal = 7, 87 80 .muxval = 0, 88 - .cctl = 0, 89 81 .periph_buses = PL08X_AHB2, 90 82 }, { 91 83 .bus_id = "ssp0_rx", 92 84 .min_signal = 8, 93 85 .max_signal = 8, 94 86 .muxval = 0, 95 - .cctl = 0, 96 87 .periph_buses = PL08X_AHB1, 97 88 }, { 98 89 .bus_id = "ssp0_tx", 99 90 .min_signal = 9, 100 91 .max_signal = 9, 101 92 .muxval = 0, 102 - .cctl = 0, 103 93 .periph_buses = PL08X_AHB1, 104 94 }, { 105 95 .bus_id = "i2c_rx", 106 96 .min_signal = 10, 107 97 .max_signal = 10, 108 98 .muxval = 0, 109 - .cctl = 0, 110 99 .periph_buses = PL08X_AHB1, 111 100 }, { 112 101 .bus_id = "i2c_tx", 113 102 .min_signal = 11, 114 103 .max_signal = 11, 115 104 .muxval = 0, 116 - .cctl = 0, 117 105 .periph_buses = PL08X_AHB1, 118 106 }, { 119 107 .bus_id = "irda", 120 108 .min_signal = 12, 121 109 .max_signal = 12, 122 110 .muxval = 0, 123 - .cctl = 0, 124 111 .periph_buses = PL08X_AHB1, 125 112 }, { 126 113 .bus_id = "adc", 127 114 .min_signal = 13, 128 115 .max_signal = 13, 129 116 .muxval = 0, 130 - .cctl = 0, 131 117 .periph_buses = PL08X_AHB2, 132 118 }, { 133 119 .bus_id = "to_jpeg", 134 120 .min_signal = 14, 135 121 .max_signal = 14, 136 122 .muxval = 0, 137 - .cctl = 0, 138 123 .periph_buses = PL08X_AHB1, 139 124 }, { 140 125 .bus_id = "from_jpeg", 141 126 .min_signal = 15, 142 127 .max_signal = 15, 143 128 .muxval = 0, 144 - .cctl = 0, 145 129 .periph_buses = PL08X_AHB1, 146 130 }, { 147 131 .bus_id = "ras0_rx", 148 132 .min_signal = 0, 149 133 .max_signal = 0, 150 134 .muxval = 1, 151 - .cctl = 0, 152 135 .periph_buses = PL08X_AHB1, 153 136 }, { 154 137 .bus_id = "ras0_tx", 155 138 .min_signal = 1, 156 139 .max_signal = 1, 157 140 .muxval = 1, 158 - .cctl = 0, 159 141 .periph_buses = PL08X_AHB1, 160 142 }, { 161 143 .bus_id = "ras1_rx", 162 144 .min_signal = 2, 163 145 .max_signal = 2, 164 146 .muxval = 1, 165 - .cctl = 0, 166 147 .periph_buses = PL08X_AHB1, 167 148 }, { 168 149 .bus_id = "ras1_tx", 169 150 .min_signal = 3, 170 151 .max_signal = 3, 171 152 .muxval = 1, 172 - .cctl = 0, 173 153 .periph_buses = PL08X_AHB1, 174 154 }, { 175 155 .bus_id = "ras2_rx", 176 156 .min_signal = 4, 177 157 .max_signal = 4, 178 158 .muxval = 1, 179 - .cctl = 0, 180 159 .periph_buses = PL08X_AHB1, 181 160 }, { 182 161 .bus_id = "ras2_tx", 183 162 .min_signal = 5, 184 163 .max_signal = 5, 185 164 .muxval = 1, 186 - .cctl = 0, 187 165 .periph_buses = PL08X_AHB1, 188 166 }, { 189 167 .bus_id = "ras3_rx", 190 168 .min_signal = 6, 191 169 .max_signal = 6, 192 170 .muxval = 1, 193 - .cctl = 0, 194 171 .periph_buses = PL08X_AHB1, 195 172 }, { 196 173 .bus_id = "ras3_tx", 197 174 .min_signal = 7, 198 175 .max_signal = 7, 199 176 .muxval = 1, 200 - .cctl = 0, 201 177 .periph_buses = PL08X_AHB1, 202 178 }, { 203 179 .bus_id = "ras4_rx", 204 180 .min_signal = 8, 205 181 .max_signal = 8, 206 182 .muxval = 1, 207 - .cctl = 0, 208 183 .periph_buses = PL08X_AHB1, 209 184 }, { 210 185 .bus_id = "ras4_tx", 211 186 .min_signal = 9, 212 187 .max_signal = 9, 213 188 .muxval = 1, 214 - .cctl = 0, 215 189 .periph_buses = PL08X_AHB1, 216 190 }, { 217 191 .bus_id = "ras5_rx", 218 192 .min_signal = 10, 219 193 .max_signal = 10, 220 194 .muxval = 1, 221 - .cctl = 0, 222 195 .periph_buses = PL08X_AHB1, 223 196 }, { 224 197 .bus_id = "ras5_tx", 225 198 .min_signal = 11, 226 199 .max_signal = 11, 227 200 .muxval = 1, 228 - .cctl = 0, 229 201 .periph_buses = PL08X_AHB1, 230 202 }, { 231 203 .bus_id = "ras6_rx", 232 204 .min_signal = 12, 233 205 .max_signal = 12, 234 206 .muxval = 1, 235 - .cctl = 0, 236 207 .periph_buses = PL08X_AHB1, 237 208 }, { 238 209 .bus_id = "ras6_tx", 239 210 .min_signal = 13, 240 211 .max_signal = 13, 241 212 .muxval = 1, 242 - .cctl = 0, 243 213 .periph_buses = PL08X_AHB1, 244 214 }, { 245 215 .bus_id = "ras7_rx", 246 216 .min_signal = 14, 247 217 .max_signal = 14, 248 218 .muxval = 1, 249 - .cctl = 0, 250 219 .periph_buses = PL08X_AHB1, 251 220 }, { 252 221 .bus_id = "ras7_tx", 253 222 .min_signal = 15, 254 223 .max_signal = 15, 255 224 .muxval = 1, 256 - .cctl = 0, 257 225 .periph_buses = PL08X_AHB1, 258 226 }, { 259 227 .bus_id = "ext0_rx", 260 228 .min_signal = 0, 261 229 .max_signal = 0, 262 230 .muxval = 2, 263 - .cctl = 0, 264 231 .periph_buses = PL08X_AHB2, 265 232 }, { 266 233 .bus_id = "ext0_tx", 267 234 .min_signal = 1, 268 235 .max_signal = 1, 269 236 .muxval = 2, 270 - .cctl = 0, 271 237 .periph_buses = PL08X_AHB2, 272 238 }, { 273 239 .bus_id = "ext1_rx", 274 240 .min_signal = 2, 275 241 .max_signal = 2, 276 242 .muxval = 2, 277 - .cctl = 0, 278 243 .periph_buses = PL08X_AHB2, 279 244 }, { 280 245 .bus_id = "ext1_tx", 281 246 .min_signal = 3, 282 247 .max_signal = 3, 283 248 .muxval = 2, 284 - .cctl = 0, 285 249 .periph_buses = PL08X_AHB2, 286 250 }, { 287 251 .bus_id = "ext2_rx", 288 252 .min_signal = 4, 289 253 .max_signal = 4, 290 254 .muxval = 2, 291 - .cctl = 0, 292 255 .periph_buses = PL08X_AHB2, 293 256 }, { 294 257 .bus_id = "ext2_tx", 295 258 .min_signal = 5, 296 259 .max_signal = 5, 297 260 .muxval = 2, 298 - .cctl = 0, 299 261 .periph_buses = PL08X_AHB2, 300 262 }, { 301 263 .bus_id = "ext3_rx", 302 264 .min_signal = 6, 303 265 .max_signal = 6, 304 266 .muxval = 2, 305 - .cctl = 0, 306 267 .periph_buses = PL08X_AHB2, 307 268 }, { 308 269 .bus_id = "ext3_tx", 309 270 .min_signal = 7, 310 271 .max_signal = 7, 311 272 .muxval = 2, 312 - .cctl = 0, 313 273 .periph_buses = PL08X_AHB2, 314 274 }, { 315 275 .bus_id = "ext4_rx", 316 276 .min_signal = 8, 317 277 .max_signal = 8, 318 278 .muxval = 2, 319 - .cctl = 0, 320 279 .periph_buses = PL08X_AHB2, 321 280 }, { 322 281 .bus_id = "ext4_tx", 323 282 .min_signal = 9, 324 283 .max_signal = 9, 325 284 .muxval = 2, 326 - .cctl = 0, 327 285 .periph_buses = PL08X_AHB2, 328 286 }, { 329 287 .bus_id = "ext5_rx", 330 288 .min_signal = 10, 331 289 .max_signal = 10, 332 290 .muxval = 2, 333 - .cctl = 0, 334 291 .periph_buses = PL08X_AHB2, 335 292 }, { 336 293 .bus_id = "ext5_tx", 337 294 .min_signal = 11, 338 295 .max_signal = 11, 339 296 .muxval = 2, 340 - .cctl = 0, 341 297 .periph_buses = PL08X_AHB2, 342 298 }, { 343 299 .bus_id = "ext6_rx", 344 300 .min_signal = 12, 345 301 .max_signal = 12, 346 302 .muxval = 2, 347 - .cctl = 0, 348 303 .periph_buses = PL08X_AHB2, 349 304 }, { 350 305 .bus_id = "ext6_tx", 351 306 .min_signal = 13, 352 307 .max_signal = 13, 353 308 .muxval = 2, 354 - .cctl = 0, 355 309 .periph_buses = PL08X_AHB2, 356 310 }, { 357 311 .bus_id = "ext7_rx", 358 312 .min_signal = 14, 359 313 .max_signal = 14, 360 314 .muxval = 2, 361 - .cctl = 0, 362 315 .periph_buses = PL08X_AHB2, 363 316 }, { 364 317 .bus_id = "ext7_tx", 365 318 .min_signal = 15, 366 319 .max_signal = 15, 367 320 .muxval = 2, 368 - .cctl = 0, 369 321 .periph_buses = PL08X_AHB2, 370 322 }, 371 323 }; ··· 325 373 struct pl08x_platform_data pl080_plat_data = { 326 374 .memcpy_channel = { 327 375 .bus_id = "memcpy", 328 - .cctl = (PL080_BSIZE_16 << PL080_CONTROL_SB_SIZE_SHIFT | \ 376 + .cctl_memcpy = 377 + (PL080_BSIZE_16 << PL080_CONTROL_SB_SIZE_SHIFT | \ 329 378 PL080_BSIZE_16 << PL080_CONTROL_DB_SIZE_SHIFT | \ 330 379 PL080_WIDTH_32BIT << PL080_CONTROL_SWIDTH_SHIFT | \ 331 380 PL080_WIDTH_32BIT << PL080_CONTROL_DWIDTH_SHIFT | \
-2
arch/arm/plat-omap/include/plat/mmc.h
··· 81 81 /* Return context loss count due to PM states changing */ 82 82 int (*get_context_loss_count)(struct device *dev); 83 83 84 - u64 dma_mask; 85 - 86 84 /* Integrating attributes from the omap_hwmod layer */ 87 85 u8 controller_flags; 88 86
+3 -3
arch/arm/plat-spear/include/plat/pl080.h
··· 14 14 #ifndef __PLAT_PL080_H 15 15 #define __PLAT_PL080_H 16 16 17 - struct pl08x_dma_chan; 18 - int pl080_get_signal(struct pl08x_dma_chan *ch); 19 - void pl080_put_signal(struct pl08x_dma_chan *ch); 17 + struct pl08x_channel_data; 18 + int pl080_get_signal(const struct pl08x_channel_data *cd); 19 + void pl080_put_signal(const struct pl08x_channel_data *cd, int signal); 20 20 21 21 #endif /* __PLAT_PL080_H */
+4 -6
arch/arm/plat-spear/pl080.c
··· 27 27 unsigned char val; 28 28 } signals[16] = {{0, 0}, }; 29 29 30 - int pl080_get_signal(struct pl08x_dma_chan *ch) 30 + int pl080_get_signal(const struct pl08x_channel_data *cd) 31 31 { 32 - const struct pl08x_channel_data *cd = ch->cd; 33 32 unsigned int signal = cd->min_signal, val; 34 33 unsigned long flags; 35 34 ··· 62 63 return signal; 63 64 } 64 65 65 - void pl080_put_signal(struct pl08x_dma_chan *ch) 66 + void pl080_put_signal(const struct pl08x_channel_data *cd, int signal) 66 67 { 67 - const struct pl08x_channel_data *cd = ch->cd; 68 68 unsigned long flags; 69 69 70 70 spin_lock_irqsave(&lock, flags); 71 71 72 72 /* if signal is not used */ 73 - if (!signals[cd->min_signal].busy) 73 + if (!signals[signal].busy) 74 74 BUG(); 75 75 76 - signals[cd->min_signal].busy--; 76 + signals[signal].busy--; 77 77 78 78 spin_unlock_irqrestore(&lock, flags); 79 79 }
+11
drivers/dma/Kconfig
··· 53 53 bool "ARM PrimeCell PL080 or PL081 support" 54 54 depends on ARM_AMBA && EXPERIMENTAL 55 55 select DMA_ENGINE 56 + select DMA_VIRTUAL_CHANNELS 56 57 help 57 58 Platform has a PL08x DMAC device 58 59 which can provide DMA engine support ··· 270 269 tristate "SA-11x0 DMA support" 271 270 depends on ARCH_SA1100 272 271 select DMA_ENGINE 272 + select DMA_VIRTUAL_CHANNELS 273 273 help 274 274 Support the DMA engine found on Intel StrongARM SA-1100 and 275 275 SA-1110 SoCs. This DMA engine can only be used with on-chip ··· 286 284 287 285 Say Y here if you enabled MMP ADMA, otherwise say N. 288 286 287 + config DMA_OMAP 288 + tristate "OMAP DMA support" 289 + depends on ARCH_OMAP 290 + select DMA_ENGINE 291 + select DMA_VIRTUAL_CHANNELS 292 + 289 293 config DMA_ENGINE 290 294 bool 295 + 296 + config DMA_VIRTUAL_CHANNELS 297 + tristate 291 298 292 299 comment "DMA Clients" 293 300 depends on DMA_ENGINE
+2
drivers/dma/Makefile
··· 2 2 ccflags-$(CONFIG_DMADEVICES_VDEBUG) += -DVERBOSE_DEBUG 3 3 4 4 obj-$(CONFIG_DMA_ENGINE) += dmaengine.o 5 + obj-$(CONFIG_DMA_VIRTUAL_CHANNELS) += virt-dma.o 5 6 obj-$(CONFIG_NET_DMA) += iovlock.o 6 7 obj-$(CONFIG_INTEL_MID_DMAC) += intel_mid_dma.o 7 8 obj-$(CONFIG_DMATEST) += dmatest.o ··· 31 30 obj-$(CONFIG_EP93XX_DMA) += ep93xx_dma.o 32 31 obj-$(CONFIG_DMA_SA11X0) += sa11x0-dma.o 33 32 obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o 33 + obj-$(CONFIG_DMA_OMAP) += omap-dma.o
+478 -473
drivers/dma/amba-pl08x.c
··· 86 86 #include <asm/hardware/pl080.h> 87 87 88 88 #include "dmaengine.h" 89 + #include "virt-dma.h" 89 90 90 91 #define DRIVER_NAME "pl08xdmac" 91 92 92 93 static struct amba_driver pl08x_amba_driver; 94 + struct pl08x_driver_data; 93 95 94 96 /** 95 97 * struct vendor_data - vendor-specific config parameters for PL08x derivatives ··· 121 119 }; 122 120 123 121 /** 122 + * struct pl08x_bus_data - information of source or destination 123 + * busses for a transfer 124 + * @addr: current address 125 + * @maxwidth: the maximum width of a transfer on this bus 126 + * @buswidth: the width of this bus in bytes: 1, 2 or 4 127 + */ 128 + struct pl08x_bus_data { 129 + dma_addr_t addr; 130 + u8 maxwidth; 131 + u8 buswidth; 132 + }; 133 + 134 + /** 135 + * struct pl08x_phy_chan - holder for the physical channels 136 + * @id: physical index to this channel 137 + * @lock: a lock to use when altering an instance of this struct 138 + * @serving: the virtual channel currently being served by this physical 139 + * channel 140 + * @locked: channel unavailable for the system, e.g. dedicated to secure 141 + * world 142 + */ 143 + struct pl08x_phy_chan { 144 + unsigned int id; 145 + void __iomem *base; 146 + spinlock_t lock; 147 + struct pl08x_dma_chan *serving; 148 + bool locked; 149 + }; 150 + 151 + /** 152 + * struct pl08x_sg - structure containing data per sg 153 + * @src_addr: src address of sg 154 + * @dst_addr: dst address of sg 155 + * @len: transfer len in bytes 156 + * @node: node for txd's dsg_list 157 + */ 158 + struct pl08x_sg { 159 + dma_addr_t src_addr; 160 + dma_addr_t dst_addr; 161 + size_t len; 162 + struct list_head node; 163 + }; 164 + 165 + /** 166 + * struct pl08x_txd - wrapper for struct dma_async_tx_descriptor 167 + * @vd: virtual DMA descriptor 168 + * @dsg_list: list of children sg's 169 + * @llis_bus: DMA memory address (physical) start for the LLIs 170 + * @llis_va: virtual memory address start for the LLIs 171 + * @cctl: control reg values for current txd 172 + * @ccfg: config reg values for current txd 173 + * @done: this marks completed descriptors, which should not have their 174 + * mux released. 175 + */ 176 + struct pl08x_txd { 177 + struct virt_dma_desc vd; 178 + struct list_head dsg_list; 179 + dma_addr_t llis_bus; 180 + struct pl08x_lli *llis_va; 181 + /* Default cctl value for LLIs */ 182 + u32 cctl; 183 + /* 184 + * Settings to be put into the physical channel when we 185 + * trigger this txd. Other registers are in llis_va[0]. 186 + */ 187 + u32 ccfg; 188 + bool done; 189 + }; 190 + 191 + /** 192 + * struct pl08x_dma_chan_state - holds the PL08x specific virtual channel 193 + * states 194 + * @PL08X_CHAN_IDLE: the channel is idle 195 + * @PL08X_CHAN_RUNNING: the channel has allocated a physical transport 196 + * channel and is running a transfer on it 197 + * @PL08X_CHAN_PAUSED: the channel has allocated a physical transport 198 + * channel, but the transfer is currently paused 199 + * @PL08X_CHAN_WAITING: the channel is waiting for a physical transport 200 + * channel to become available (only pertains to memcpy channels) 201 + */ 202 + enum pl08x_dma_chan_state { 203 + PL08X_CHAN_IDLE, 204 + PL08X_CHAN_RUNNING, 205 + PL08X_CHAN_PAUSED, 206 + PL08X_CHAN_WAITING, 207 + }; 208 + 209 + /** 210 + * struct pl08x_dma_chan - this structure wraps a DMA ENGINE channel 211 + * @vc: wrappped virtual channel 212 + * @phychan: the physical channel utilized by this channel, if there is one 213 + * @name: name of channel 214 + * @cd: channel platform data 215 + * @runtime_addr: address for RX/TX according to the runtime config 216 + * @at: active transaction on this channel 217 + * @lock: a lock for this channel data 218 + * @host: a pointer to the host (internal use) 219 + * @state: whether the channel is idle, paused, running etc 220 + * @slave: whether this channel is a device (slave) or for memcpy 221 + * @signal: the physical DMA request signal which this channel is using 222 + * @mux_use: count of descriptors using this DMA request signal setting 223 + */ 224 + struct pl08x_dma_chan { 225 + struct virt_dma_chan vc; 226 + struct pl08x_phy_chan *phychan; 227 + const char *name; 228 + const struct pl08x_channel_data *cd; 229 + struct dma_slave_config cfg; 230 + struct pl08x_txd *at; 231 + struct pl08x_driver_data *host; 232 + enum pl08x_dma_chan_state state; 233 + bool slave; 234 + int signal; 235 + unsigned mux_use; 236 + }; 237 + 238 + /** 124 239 * struct pl08x_driver_data - the local state holder for the PL08x 125 240 * @slave: slave engine for this instance 126 241 * @memcpy: memcpy engine for this instance ··· 247 128 * @pd: platform data passed in from the platform/machine 248 129 * @phy_chans: array of data for the physical channels 249 130 * @pool: a pool for the LLI descriptors 250 - * @pool_ctr: counter of LLIs in the pool 251 131 * @lli_buses: bitmask to or in to LLI pointer selecting AHB port for LLI 252 132 * fetches 253 133 * @mem_buses: set to indicate memory transfers on AHB2. ··· 261 143 struct pl08x_platform_data *pd; 262 144 struct pl08x_phy_chan *phy_chans; 263 145 struct dma_pool *pool; 264 - int pool_ctr; 265 146 u8 lli_buses; 266 147 u8 mem_buses; 267 - spinlock_t lock; 268 148 }; 269 149 270 150 /* ··· 278 162 279 163 static inline struct pl08x_dma_chan *to_pl08x_chan(struct dma_chan *chan) 280 164 { 281 - return container_of(chan, struct pl08x_dma_chan, chan); 165 + return container_of(chan, struct pl08x_dma_chan, vc.chan); 282 166 } 283 167 284 168 static inline struct pl08x_txd *to_pl08x_txd(struct dma_async_tx_descriptor *tx) 285 169 { 286 - return container_of(tx, struct pl08x_txd, tx); 170 + return container_of(tx, struct pl08x_txd, vd.tx); 171 + } 172 + 173 + /* 174 + * Mux handling. 175 + * 176 + * This gives us the DMA request input to the PL08x primecell which the 177 + * peripheral described by the channel data will be routed to, possibly 178 + * via a board/SoC specific external MUX. One important point to note 179 + * here is that this does not depend on the physical channel. 180 + */ 181 + static int pl08x_request_mux(struct pl08x_dma_chan *plchan) 182 + { 183 + const struct pl08x_platform_data *pd = plchan->host->pd; 184 + int ret; 185 + 186 + if (plchan->mux_use++ == 0 && pd->get_signal) { 187 + ret = pd->get_signal(plchan->cd); 188 + if (ret < 0) { 189 + plchan->mux_use = 0; 190 + return ret; 191 + } 192 + 193 + plchan->signal = ret; 194 + } 195 + return 0; 196 + } 197 + 198 + static void pl08x_release_mux(struct pl08x_dma_chan *plchan) 199 + { 200 + const struct pl08x_platform_data *pd = plchan->host->pd; 201 + 202 + if (plchan->signal >= 0) { 203 + WARN_ON(plchan->mux_use == 0); 204 + 205 + if (--plchan->mux_use == 0 && pd->put_signal) { 206 + pd->put_signal(plchan->cd, plchan->signal); 207 + plchan->signal = -1; 208 + } 209 + } 287 210 } 288 211 289 212 /* ··· 344 189 * been set when the LLIs were constructed. Poke them into the hardware 345 190 * and start the transfer. 346 191 */ 347 - static void pl08x_start_txd(struct pl08x_dma_chan *plchan, 348 - struct pl08x_txd *txd) 192 + static void pl08x_start_next_txd(struct pl08x_dma_chan *plchan) 349 193 { 350 194 struct pl08x_driver_data *pl08x = plchan->host; 351 195 struct pl08x_phy_chan *phychan = plchan->phychan; 352 - struct pl08x_lli *lli = &txd->llis_va[0]; 196 + struct virt_dma_desc *vd = vchan_next_desc(&plchan->vc); 197 + struct pl08x_txd *txd = to_pl08x_txd(&vd->tx); 198 + struct pl08x_lli *lli; 353 199 u32 val; 200 + 201 + list_del(&txd->vd.node); 354 202 355 203 plchan->at = txd; 356 204 357 205 /* Wait for channel inactive */ 358 206 while (pl08x_phy_channel_busy(phychan)) 359 207 cpu_relax(); 208 + 209 + lli = &txd->llis_va[0]; 360 210 361 211 dev_vdbg(&pl08x->adev->dev, 362 212 "WRITE channel %d: csrc=0x%08x, cdst=0x%08x, " ··· 471 311 { 472 312 struct pl08x_phy_chan *ch; 473 313 struct pl08x_txd *txd; 474 - unsigned long flags; 475 314 size_t bytes = 0; 476 315 477 - spin_lock_irqsave(&plchan->lock, flags); 478 316 ch = plchan->phychan; 479 317 txd = plchan->at; 480 318 ··· 512 354 } 513 355 } 514 356 515 - /* Sum up all queued transactions */ 516 - if (!list_empty(&plchan->pend_list)) { 517 - struct pl08x_txd *txdi; 518 - list_for_each_entry(txdi, &plchan->pend_list, node) { 519 - struct pl08x_sg *dsg; 520 - list_for_each_entry(dsg, &txd->dsg_list, node) 521 - bytes += dsg->len; 522 - } 523 - } 524 - 525 - spin_unlock_irqrestore(&plchan->lock, flags); 526 - 527 357 return bytes; 528 358 } 529 359 ··· 537 391 538 392 if (!ch->locked && !ch->serving) { 539 393 ch->serving = virt_chan; 540 - ch->signal = -1; 541 394 spin_unlock_irqrestore(&ch->lock, flags); 542 395 break; 543 396 } ··· 549 404 return NULL; 550 405 } 551 406 552 - pm_runtime_get_sync(&pl08x->adev->dev); 553 407 return ch; 554 408 } 555 409 410 + /* Mark the physical channel as free. Note, this write is atomic. */ 556 411 static inline void pl08x_put_phy_channel(struct pl08x_driver_data *pl08x, 557 412 struct pl08x_phy_chan *ch) 558 413 { 559 - unsigned long flags; 560 - 561 - spin_lock_irqsave(&ch->lock, flags); 562 - 563 - /* Stop the channel and clear its interrupts */ 564 - pl08x_terminate_phy_chan(pl08x, ch); 565 - 566 - pm_runtime_put(&pl08x->adev->dev); 567 - 568 - /* Mark it as free */ 569 414 ch->serving = NULL; 570 - spin_unlock_irqrestore(&ch->lock, flags); 415 + } 416 + 417 + /* 418 + * Try to allocate a physical channel. When successful, assign it to 419 + * this virtual channel, and initiate the next descriptor. The 420 + * virtual channel lock must be held at this point. 421 + */ 422 + static void pl08x_phy_alloc_and_start(struct pl08x_dma_chan *plchan) 423 + { 424 + struct pl08x_driver_data *pl08x = plchan->host; 425 + struct pl08x_phy_chan *ch; 426 + 427 + ch = pl08x_get_phy_channel(pl08x, plchan); 428 + if (!ch) { 429 + dev_dbg(&pl08x->adev->dev, "no physical channel available for xfer on %s\n", plchan->name); 430 + plchan->state = PL08X_CHAN_WAITING; 431 + return; 432 + } 433 + 434 + dev_dbg(&pl08x->adev->dev, "allocated physical channel %d for xfer on %s\n", 435 + ch->id, plchan->name); 436 + 437 + plchan->phychan = ch; 438 + plchan->state = PL08X_CHAN_RUNNING; 439 + pl08x_start_next_txd(plchan); 440 + } 441 + 442 + static void pl08x_phy_reassign_start(struct pl08x_phy_chan *ch, 443 + struct pl08x_dma_chan *plchan) 444 + { 445 + struct pl08x_driver_data *pl08x = plchan->host; 446 + 447 + dev_dbg(&pl08x->adev->dev, "reassigned physical channel %d for xfer on %s\n", 448 + ch->id, plchan->name); 449 + 450 + /* 451 + * We do this without taking the lock; we're really only concerned 452 + * about whether this pointer is NULL or not, and we're guaranteed 453 + * that this will only be called when it _already_ is non-NULL. 454 + */ 455 + ch->serving = plchan; 456 + plchan->phychan = ch; 457 + plchan->state = PL08X_CHAN_RUNNING; 458 + pl08x_start_next_txd(plchan); 459 + } 460 + 461 + /* 462 + * Free a physical DMA channel, potentially reallocating it to another 463 + * virtual channel if we have any pending. 464 + */ 465 + static void pl08x_phy_free(struct pl08x_dma_chan *plchan) 466 + { 467 + struct pl08x_driver_data *pl08x = plchan->host; 468 + struct pl08x_dma_chan *p, *next; 469 + 470 + retry: 471 + next = NULL; 472 + 473 + /* Find a waiting virtual channel for the next transfer. */ 474 + list_for_each_entry(p, &pl08x->memcpy.channels, vc.chan.device_node) 475 + if (p->state == PL08X_CHAN_WAITING) { 476 + next = p; 477 + break; 478 + } 479 + 480 + if (!next) { 481 + list_for_each_entry(p, &pl08x->slave.channels, vc.chan.device_node) 482 + if (p->state == PL08X_CHAN_WAITING) { 483 + next = p; 484 + break; 485 + } 486 + } 487 + 488 + /* Ensure that the physical channel is stopped */ 489 + pl08x_terminate_phy_chan(pl08x, plchan->phychan); 490 + 491 + if (next) { 492 + bool success; 493 + 494 + /* 495 + * Eww. We know this isn't going to deadlock 496 + * but lockdep probably doesn't. 497 + */ 498 + spin_lock(&next->vc.lock); 499 + /* Re-check the state now that we have the lock */ 500 + success = next->state == PL08X_CHAN_WAITING; 501 + if (success) 502 + pl08x_phy_reassign_start(plchan->phychan, next); 503 + spin_unlock(&next->vc.lock); 504 + 505 + /* If the state changed, try to find another channel */ 506 + if (!success) 507 + goto retry; 508 + } else { 509 + /* No more jobs, so free up the physical channel */ 510 + pl08x_put_phy_channel(pl08x, plchan->phychan); 511 + } 512 + 513 + plchan->phychan = NULL; 514 + plchan->state = PL08X_CHAN_IDLE; 571 515 } 572 516 573 517 /* ··· 818 584 dev_err(&pl08x->adev->dev, "%s no memory for llis\n", __func__); 819 585 return 0; 820 586 } 821 - 822 - pl08x->pool_ctr++; 823 587 824 588 bd.txd = txd; 825 589 bd.lli_bus = (pl08x->lli_buses & PL08X_AHB2) ? PL080_LLI_LM_AHB2 : 0; ··· 1034 802 return num_llis; 1035 803 } 1036 804 1037 - /* You should call this with the struct pl08x lock held */ 1038 805 static void pl08x_free_txd(struct pl08x_driver_data *pl08x, 1039 806 struct pl08x_txd *txd) 1040 807 { 1041 808 struct pl08x_sg *dsg, *_dsg; 1042 809 1043 - /* Free the LLI */ 1044 810 if (txd->llis_va) 1045 811 dma_pool_free(pl08x->pool, txd->llis_va, txd->llis_bus); 1046 - 1047 - pl08x->pool_ctr--; 1048 812 1049 813 list_for_each_entry_safe(dsg, _dsg, &txd->dsg_list, node) { 1050 814 list_del(&dsg->node); ··· 1050 822 kfree(txd); 1051 823 } 1052 824 825 + static void pl08x_unmap_buffers(struct pl08x_txd *txd) 826 + { 827 + struct device *dev = txd->vd.tx.chan->device->dev; 828 + struct pl08x_sg *dsg; 829 + 830 + if (!(txd->vd.tx.flags & DMA_COMPL_SKIP_SRC_UNMAP)) { 831 + if (txd->vd.tx.flags & DMA_COMPL_SRC_UNMAP_SINGLE) 832 + list_for_each_entry(dsg, &txd->dsg_list, node) 833 + dma_unmap_single(dev, dsg->src_addr, dsg->len, 834 + DMA_TO_DEVICE); 835 + else { 836 + list_for_each_entry(dsg, &txd->dsg_list, node) 837 + dma_unmap_page(dev, dsg->src_addr, dsg->len, 838 + DMA_TO_DEVICE); 839 + } 840 + } 841 + if (!(txd->vd.tx.flags & DMA_COMPL_SKIP_DEST_UNMAP)) { 842 + if (txd->vd.tx.flags & DMA_COMPL_DEST_UNMAP_SINGLE) 843 + list_for_each_entry(dsg, &txd->dsg_list, node) 844 + dma_unmap_single(dev, dsg->dst_addr, dsg->len, 845 + DMA_FROM_DEVICE); 846 + else 847 + list_for_each_entry(dsg, &txd->dsg_list, node) 848 + dma_unmap_page(dev, dsg->dst_addr, dsg->len, 849 + DMA_FROM_DEVICE); 850 + } 851 + } 852 + 853 + static void pl08x_desc_free(struct virt_dma_desc *vd) 854 + { 855 + struct pl08x_txd *txd = to_pl08x_txd(&vd->tx); 856 + struct pl08x_dma_chan *plchan = to_pl08x_chan(vd->tx.chan); 857 + 858 + if (!plchan->slave) 859 + pl08x_unmap_buffers(txd); 860 + 861 + if (!txd->done) 862 + pl08x_release_mux(plchan); 863 + 864 + pl08x_free_txd(plchan->host, txd); 865 + } 866 + 1053 867 static void pl08x_free_txd_list(struct pl08x_driver_data *pl08x, 1054 868 struct pl08x_dma_chan *plchan) 1055 869 { 1056 - struct pl08x_txd *txdi = NULL; 1057 - struct pl08x_txd *next; 870 + LIST_HEAD(head); 871 + struct pl08x_txd *txd; 1058 872 1059 - if (!list_empty(&plchan->pend_list)) { 1060 - list_for_each_entry_safe(txdi, 1061 - next, &plchan->pend_list, node) { 1062 - list_del(&txdi->node); 1063 - pl08x_free_txd(pl08x, txdi); 1064 - } 873 + vchan_get_all_descriptors(&plchan->vc, &head); 874 + 875 + while (!list_empty(&head)) { 876 + txd = list_first_entry(&head, struct pl08x_txd, vd.node); 877 + list_del(&txd->vd.node); 878 + pl08x_desc_free(&txd->vd); 1065 879 } 1066 880 } 1067 881 ··· 1117 847 1118 848 static void pl08x_free_chan_resources(struct dma_chan *chan) 1119 849 { 1120 - } 1121 - 1122 - /* 1123 - * This should be called with the channel plchan->lock held 1124 - */ 1125 - static int prep_phy_channel(struct pl08x_dma_chan *plchan, 1126 - struct pl08x_txd *txd) 1127 - { 1128 - struct pl08x_driver_data *pl08x = plchan->host; 1129 - struct pl08x_phy_chan *ch; 1130 - int ret; 1131 - 1132 - /* Check if we already have a channel */ 1133 - if (plchan->phychan) { 1134 - ch = plchan->phychan; 1135 - goto got_channel; 1136 - } 1137 - 1138 - ch = pl08x_get_phy_channel(pl08x, plchan); 1139 - if (!ch) { 1140 - /* No physical channel available, cope with it */ 1141 - dev_dbg(&pl08x->adev->dev, "no physical channel available for xfer on %s\n", plchan->name); 1142 - return -EBUSY; 1143 - } 1144 - 1145 - /* 1146 - * OK we have a physical channel: for memcpy() this is all we 1147 - * need, but for slaves the physical signals may be muxed! 1148 - * Can the platform allow us to use this channel? 1149 - */ 1150 - if (plchan->slave && pl08x->pd->get_signal) { 1151 - ret = pl08x->pd->get_signal(plchan); 1152 - if (ret < 0) { 1153 - dev_dbg(&pl08x->adev->dev, 1154 - "unable to use physical channel %d for transfer on %s due to platform restrictions\n", 1155 - ch->id, plchan->name); 1156 - /* Release physical channel & return */ 1157 - pl08x_put_phy_channel(pl08x, ch); 1158 - return -EBUSY; 1159 - } 1160 - ch->signal = ret; 1161 - } 1162 - 1163 - plchan->phychan = ch; 1164 - dev_dbg(&pl08x->adev->dev, "allocated physical channel %d and signal %d for xfer on %s\n", 1165 - ch->id, 1166 - ch->signal, 1167 - plchan->name); 1168 - 1169 - got_channel: 1170 - /* Assign the flow control signal to this channel */ 1171 - if (txd->direction == DMA_MEM_TO_DEV) 1172 - txd->ccfg |= ch->signal << PL080_CONFIG_DST_SEL_SHIFT; 1173 - else if (txd->direction == DMA_DEV_TO_MEM) 1174 - txd->ccfg |= ch->signal << PL080_CONFIG_SRC_SEL_SHIFT; 1175 - 1176 - plchan->phychan_hold++; 1177 - 1178 - return 0; 1179 - } 1180 - 1181 - static void release_phy_channel(struct pl08x_dma_chan *plchan) 1182 - { 1183 - struct pl08x_driver_data *pl08x = plchan->host; 1184 - 1185 - if ((plchan->phychan->signal >= 0) && pl08x->pd->put_signal) { 1186 - pl08x->pd->put_signal(plchan); 1187 - plchan->phychan->signal = -1; 1188 - } 1189 - pl08x_put_phy_channel(pl08x, plchan->phychan); 1190 - plchan->phychan = NULL; 1191 - } 1192 - 1193 - static dma_cookie_t pl08x_tx_submit(struct dma_async_tx_descriptor *tx) 1194 - { 1195 - struct pl08x_dma_chan *plchan = to_pl08x_chan(tx->chan); 1196 - struct pl08x_txd *txd = to_pl08x_txd(tx); 1197 - unsigned long flags; 1198 - dma_cookie_t cookie; 1199 - 1200 - spin_lock_irqsave(&plchan->lock, flags); 1201 - cookie = dma_cookie_assign(tx); 1202 - 1203 - /* Put this onto the pending list */ 1204 - list_add_tail(&txd->node, &plchan->pend_list); 1205 - 1206 - /* 1207 - * If there was no physical channel available for this memcpy, 1208 - * stack the request up and indicate that the channel is waiting 1209 - * for a free physical channel. 1210 - */ 1211 - if (!plchan->slave && !plchan->phychan) { 1212 - /* Do this memcpy whenever there is a channel ready */ 1213 - plchan->state = PL08X_CHAN_WAITING; 1214 - plchan->waiting = txd; 1215 - } else { 1216 - plchan->phychan_hold--; 1217 - } 1218 - 1219 - spin_unlock_irqrestore(&plchan->lock, flags); 1220 - 1221 - return cookie; 850 + /* Ensure all queued descriptors are freed */ 851 + vchan_free_chan_resources(to_virt_chan(chan)); 1222 852 } 1223 853 1224 854 static struct dma_async_tx_descriptor *pl08x_prep_dma_interrupt( ··· 1138 968 dma_cookie_t cookie, struct dma_tx_state *txstate) 1139 969 { 1140 970 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 971 + struct virt_dma_desc *vd; 972 + unsigned long flags; 1141 973 enum dma_status ret; 974 + size_t bytes = 0; 1142 975 1143 976 ret = dma_cookie_status(chan, cookie, txstate); 1144 977 if (ret == DMA_SUCCESS) 1145 978 return ret; 1146 979 1147 980 /* 981 + * There's no point calculating the residue if there's 982 + * no txstate to store the value. 983 + */ 984 + if (!txstate) { 985 + if (plchan->state == PL08X_CHAN_PAUSED) 986 + ret = DMA_PAUSED; 987 + return ret; 988 + } 989 + 990 + spin_lock_irqsave(&plchan->vc.lock, flags); 991 + ret = dma_cookie_status(chan, cookie, txstate); 992 + if (ret != DMA_SUCCESS) { 993 + vd = vchan_find_desc(&plchan->vc, cookie); 994 + if (vd) { 995 + /* On the issued list, so hasn't been processed yet */ 996 + struct pl08x_txd *txd = to_pl08x_txd(&vd->tx); 997 + struct pl08x_sg *dsg; 998 + 999 + list_for_each_entry(dsg, &txd->dsg_list, node) 1000 + bytes += dsg->len; 1001 + } else { 1002 + bytes = pl08x_getbytes_chan(plchan); 1003 + } 1004 + } 1005 + spin_unlock_irqrestore(&plchan->vc.lock, flags); 1006 + 1007 + /* 1148 1008 * This cookie not complete yet 1149 1009 * Get number of bytes left in the active transactions and queue 1150 1010 */ 1151 - dma_set_residue(txstate, pl08x_getbytes_chan(plchan)); 1011 + dma_set_residue(txstate, bytes); 1152 1012 1153 - if (plchan->state == PL08X_CHAN_PAUSED) 1154 - return DMA_PAUSED; 1013 + if (plchan->state == PL08X_CHAN_PAUSED && ret == DMA_IN_PROGRESS) 1014 + ret = DMA_PAUSED; 1155 1015 1156 1016 /* Whether waiting or running, we're in progress */ 1157 - return DMA_IN_PROGRESS; 1017 + return ret; 1158 1018 } 1159 1019 1160 1020 /* PrimeCell DMA extension */ ··· 1280 1080 return burst_sizes[i].reg; 1281 1081 } 1282 1082 1283 - static int dma_set_runtime_config(struct dma_chan *chan, 1284 - struct dma_slave_config *config) 1083 + static u32 pl08x_get_cctl(struct pl08x_dma_chan *plchan, 1084 + enum dma_slave_buswidth addr_width, u32 maxburst) 1285 1085 { 1286 - struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 1287 - struct pl08x_driver_data *pl08x = plchan->host; 1288 - enum dma_slave_buswidth addr_width; 1289 - u32 width, burst, maxburst; 1290 - u32 cctl = 0; 1291 - 1292 - if (!plchan->slave) 1293 - return -EINVAL; 1294 - 1295 - /* Transfer direction */ 1296 - plchan->runtime_direction = config->direction; 1297 - if (config->direction == DMA_MEM_TO_DEV) { 1298 - addr_width = config->dst_addr_width; 1299 - maxburst = config->dst_maxburst; 1300 - } else if (config->direction == DMA_DEV_TO_MEM) { 1301 - addr_width = config->src_addr_width; 1302 - maxburst = config->src_maxburst; 1303 - } else { 1304 - dev_err(&pl08x->adev->dev, 1305 - "bad runtime_config: alien transfer direction\n"); 1306 - return -EINVAL; 1307 - } 1086 + u32 width, burst, cctl = 0; 1308 1087 1309 1088 width = pl08x_width(addr_width); 1310 - if (width == ~0) { 1311 - dev_err(&pl08x->adev->dev, 1312 - "bad runtime_config: alien address width\n"); 1313 - return -EINVAL; 1314 - } 1089 + if (width == ~0) 1090 + return ~0; 1315 1091 1316 1092 cctl |= width << PL080_CONTROL_SWIDTH_SHIFT; 1317 1093 cctl |= width << PL080_CONTROL_DWIDTH_SHIFT; ··· 1304 1128 cctl |= burst << PL080_CONTROL_SB_SIZE_SHIFT; 1305 1129 cctl |= burst << PL080_CONTROL_DB_SIZE_SHIFT; 1306 1130 1307 - plchan->device_fc = config->device_fc; 1131 + return pl08x_cctl(cctl); 1132 + } 1308 1133 1309 - if (plchan->runtime_direction == DMA_DEV_TO_MEM) { 1310 - plchan->src_addr = config->src_addr; 1311 - plchan->src_cctl = pl08x_cctl(cctl) | PL080_CONTROL_DST_INCR | 1312 - pl08x_select_bus(plchan->cd->periph_buses, 1313 - pl08x->mem_buses); 1314 - } else { 1315 - plchan->dst_addr = config->dst_addr; 1316 - plchan->dst_cctl = pl08x_cctl(cctl) | PL080_CONTROL_SRC_INCR | 1317 - pl08x_select_bus(pl08x->mem_buses, 1318 - plchan->cd->periph_buses); 1319 - } 1134 + static int dma_set_runtime_config(struct dma_chan *chan, 1135 + struct dma_slave_config *config) 1136 + { 1137 + struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 1320 1138 1321 - dev_dbg(&pl08x->adev->dev, 1322 - "configured channel %s (%s) for %s, data width %d, " 1323 - "maxburst %d words, LE, CCTL=0x%08x\n", 1324 - dma_chan_name(chan), plchan->name, 1325 - (config->direction == DMA_DEV_TO_MEM) ? "RX" : "TX", 1326 - addr_width, 1327 - maxburst, 1328 - cctl); 1139 + if (!plchan->slave) 1140 + return -EINVAL; 1141 + 1142 + /* Reject definitely invalid configurations */ 1143 + if (config->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES || 1144 + config->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES) 1145 + return -EINVAL; 1146 + 1147 + plchan->cfg = *config; 1329 1148 1330 1149 return 0; 1331 1150 } ··· 1334 1163 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 1335 1164 unsigned long flags; 1336 1165 1337 - spin_lock_irqsave(&plchan->lock, flags); 1338 - /* Something is already active, or we're waiting for a channel... */ 1339 - if (plchan->at || plchan->state == PL08X_CHAN_WAITING) { 1340 - spin_unlock_irqrestore(&plchan->lock, flags); 1341 - return; 1166 + spin_lock_irqsave(&plchan->vc.lock, flags); 1167 + if (vchan_issue_pending(&plchan->vc)) { 1168 + if (!plchan->phychan && plchan->state != PL08X_CHAN_WAITING) 1169 + pl08x_phy_alloc_and_start(plchan); 1342 1170 } 1343 - 1344 - /* Take the first element in the queue and execute it */ 1345 - if (!list_empty(&plchan->pend_list)) { 1346 - struct pl08x_txd *next; 1347 - 1348 - next = list_first_entry(&plchan->pend_list, 1349 - struct pl08x_txd, 1350 - node); 1351 - list_del(&next->node); 1352 - plchan->state = PL08X_CHAN_RUNNING; 1353 - 1354 - pl08x_start_txd(plchan, next); 1355 - } 1356 - 1357 - spin_unlock_irqrestore(&plchan->lock, flags); 1171 + spin_unlock_irqrestore(&plchan->vc.lock, flags); 1358 1172 } 1359 1173 1360 - static int pl08x_prep_channel_resources(struct pl08x_dma_chan *plchan, 1361 - struct pl08x_txd *txd) 1362 - { 1363 - struct pl08x_driver_data *pl08x = plchan->host; 1364 - unsigned long flags; 1365 - int num_llis, ret; 1366 - 1367 - num_llis = pl08x_fill_llis_for_desc(pl08x, txd); 1368 - if (!num_llis) { 1369 - spin_lock_irqsave(&plchan->lock, flags); 1370 - pl08x_free_txd(pl08x, txd); 1371 - spin_unlock_irqrestore(&plchan->lock, flags); 1372 - return -EINVAL; 1373 - } 1374 - 1375 - spin_lock_irqsave(&plchan->lock, flags); 1376 - 1377 - /* 1378 - * See if we already have a physical channel allocated, 1379 - * else this is the time to try to get one. 1380 - */ 1381 - ret = prep_phy_channel(plchan, txd); 1382 - if (ret) { 1383 - /* 1384 - * No physical channel was available. 1385 - * 1386 - * memcpy transfers can be sorted out at submission time. 1387 - * 1388 - * Slave transfers may have been denied due to platform 1389 - * channel muxing restrictions. Since there is no guarantee 1390 - * that this will ever be resolved, and the signal must be 1391 - * acquired AFTER acquiring the physical channel, we will let 1392 - * them be NACK:ed with -EBUSY here. The drivers can retry 1393 - * the prep() call if they are eager on doing this using DMA. 1394 - */ 1395 - if (plchan->slave) { 1396 - pl08x_free_txd_list(pl08x, plchan); 1397 - pl08x_free_txd(pl08x, txd); 1398 - spin_unlock_irqrestore(&plchan->lock, flags); 1399 - return -EBUSY; 1400 - } 1401 - } else 1402 - /* 1403 - * Else we're all set, paused and ready to roll, status 1404 - * will switch to PL08X_CHAN_RUNNING when we call 1405 - * issue_pending(). If there is something running on the 1406 - * channel already we don't change its state. 1407 - */ 1408 - if (plchan->state == PL08X_CHAN_IDLE) 1409 - plchan->state = PL08X_CHAN_PAUSED; 1410 - 1411 - spin_unlock_irqrestore(&plchan->lock, flags); 1412 - 1413 - return 0; 1414 - } 1415 - 1416 - static struct pl08x_txd *pl08x_get_txd(struct pl08x_dma_chan *plchan, 1417 - unsigned long flags) 1174 + static struct pl08x_txd *pl08x_get_txd(struct pl08x_dma_chan *plchan) 1418 1175 { 1419 1176 struct pl08x_txd *txd = kzalloc(sizeof(*txd), GFP_NOWAIT); 1420 1177 1421 1178 if (txd) { 1422 - dma_async_tx_descriptor_init(&txd->tx, &plchan->chan); 1423 - txd->tx.flags = flags; 1424 - txd->tx.tx_submit = pl08x_tx_submit; 1425 - INIT_LIST_HEAD(&txd->node); 1426 1179 INIT_LIST_HEAD(&txd->dsg_list); 1427 1180 1428 1181 /* Always enable error and terminal interrupts */ ··· 1369 1274 struct pl08x_sg *dsg; 1370 1275 int ret; 1371 1276 1372 - txd = pl08x_get_txd(plchan, flags); 1277 + txd = pl08x_get_txd(plchan); 1373 1278 if (!txd) { 1374 1279 dev_err(&pl08x->adev->dev, 1375 1280 "%s no memory for descriptor\n", __func__); ··· 1385 1290 } 1386 1291 list_add_tail(&dsg->node, &txd->dsg_list); 1387 1292 1388 - txd->direction = DMA_NONE; 1389 1293 dsg->src_addr = src; 1390 1294 dsg->dst_addr = dest; 1391 1295 dsg->len = len; 1392 1296 1393 1297 /* Set platform data for m2m */ 1394 1298 txd->ccfg |= PL080_FLOW_MEM2MEM << PL080_CONFIG_FLOW_CONTROL_SHIFT; 1395 - txd->cctl = pl08x->pd->memcpy_channel.cctl & 1299 + txd->cctl = pl08x->pd->memcpy_channel.cctl_memcpy & 1396 1300 ~(PL080_CONTROL_DST_AHB2 | PL080_CONTROL_SRC_AHB2); 1397 1301 1398 1302 /* Both to be incremented or the code will break */ ··· 1401 1307 txd->cctl |= pl08x_select_bus(pl08x->mem_buses, 1402 1308 pl08x->mem_buses); 1403 1309 1404 - ret = pl08x_prep_channel_resources(plchan, txd); 1405 - if (ret) 1310 + ret = pl08x_fill_llis_for_desc(plchan->host, txd); 1311 + if (!ret) { 1312 + pl08x_free_txd(pl08x, txd); 1406 1313 return NULL; 1314 + } 1407 1315 1408 - return &txd->tx; 1316 + return vchan_tx_prep(&plchan->vc, &txd->vd, flags); 1409 1317 } 1410 1318 1411 1319 static struct dma_async_tx_descriptor *pl08x_prep_slave_sg( ··· 1420 1324 struct pl08x_txd *txd; 1421 1325 struct pl08x_sg *dsg; 1422 1326 struct scatterlist *sg; 1327 + enum dma_slave_buswidth addr_width; 1423 1328 dma_addr_t slave_addr; 1424 1329 int ret, tmp; 1330 + u8 src_buses, dst_buses; 1331 + u32 maxburst, cctl; 1425 1332 1426 1333 dev_dbg(&pl08x->adev->dev, "%s prepare transaction of %d bytes from %s\n", 1427 1334 __func__, sg_dma_len(sgl), plchan->name); 1428 1335 1429 - txd = pl08x_get_txd(plchan, flags); 1336 + txd = pl08x_get_txd(plchan); 1430 1337 if (!txd) { 1431 1338 dev_err(&pl08x->adev->dev, "%s no txd\n", __func__); 1432 1339 return NULL; 1433 1340 } 1434 - 1435 - if (direction != plchan->runtime_direction) 1436 - dev_err(&pl08x->adev->dev, "%s DMA setup does not match " 1437 - "the direction configured for the PrimeCell\n", 1438 - __func__); 1439 1341 1440 1342 /* 1441 1343 * Set up addresses, the PrimeCell configured address 1442 1344 * will take precedence since this may configure the 1443 1345 * channel target address dynamically at runtime. 1444 1346 */ 1445 - txd->direction = direction; 1446 - 1447 1347 if (direction == DMA_MEM_TO_DEV) { 1448 - txd->cctl = plchan->dst_cctl; 1449 - slave_addr = plchan->dst_addr; 1348 + cctl = PL080_CONTROL_SRC_INCR; 1349 + slave_addr = plchan->cfg.dst_addr; 1350 + addr_width = plchan->cfg.dst_addr_width; 1351 + maxburst = plchan->cfg.dst_maxburst; 1352 + src_buses = pl08x->mem_buses; 1353 + dst_buses = plchan->cd->periph_buses; 1450 1354 } else if (direction == DMA_DEV_TO_MEM) { 1451 - txd->cctl = plchan->src_cctl; 1452 - slave_addr = plchan->src_addr; 1355 + cctl = PL080_CONTROL_DST_INCR; 1356 + slave_addr = plchan->cfg.src_addr; 1357 + addr_width = plchan->cfg.src_addr_width; 1358 + maxburst = plchan->cfg.src_maxburst; 1359 + src_buses = plchan->cd->periph_buses; 1360 + dst_buses = pl08x->mem_buses; 1453 1361 } else { 1454 1362 pl08x_free_txd(pl08x, txd); 1455 1363 dev_err(&pl08x->adev->dev, ··· 1461 1361 return NULL; 1462 1362 } 1463 1363 1464 - if (plchan->device_fc) 1364 + cctl |= pl08x_get_cctl(plchan, addr_width, maxburst); 1365 + if (cctl == ~0) { 1366 + pl08x_free_txd(pl08x, txd); 1367 + dev_err(&pl08x->adev->dev, 1368 + "DMA slave configuration botched?\n"); 1369 + return NULL; 1370 + } 1371 + 1372 + txd->cctl = cctl | pl08x_select_bus(src_buses, dst_buses); 1373 + 1374 + if (plchan->cfg.device_fc) 1465 1375 tmp = (direction == DMA_MEM_TO_DEV) ? PL080_FLOW_MEM2PER_PER : 1466 1376 PL080_FLOW_PER2MEM_PER; 1467 1377 else ··· 1480 1370 1481 1371 txd->ccfg |= tmp << PL080_CONFIG_FLOW_CONTROL_SHIFT; 1482 1372 1373 + ret = pl08x_request_mux(plchan); 1374 + if (ret < 0) { 1375 + pl08x_free_txd(pl08x, txd); 1376 + dev_dbg(&pl08x->adev->dev, 1377 + "unable to mux for transfer on %s due to platform restrictions\n", 1378 + plchan->name); 1379 + return NULL; 1380 + } 1381 + 1382 + dev_dbg(&pl08x->adev->dev, "allocated DMA request signal %d for xfer on %s\n", 1383 + plchan->signal, plchan->name); 1384 + 1385 + /* Assign the flow control signal to this channel */ 1386 + if (direction == DMA_MEM_TO_DEV) 1387 + txd->ccfg |= plchan->signal << PL080_CONFIG_DST_SEL_SHIFT; 1388 + else 1389 + txd->ccfg |= plchan->signal << PL080_CONFIG_SRC_SEL_SHIFT; 1390 + 1483 1391 for_each_sg(sgl, sg, sg_len, tmp) { 1484 1392 dsg = kzalloc(sizeof(struct pl08x_sg), GFP_NOWAIT); 1485 1393 if (!dsg) { 1394 + pl08x_release_mux(plchan); 1486 1395 pl08x_free_txd(pl08x, txd); 1487 1396 dev_err(&pl08x->adev->dev, "%s no mem for pl080 sg\n", 1488 1397 __func__); ··· 1519 1390 } 1520 1391 } 1521 1392 1522 - ret = pl08x_prep_channel_resources(plchan, txd); 1523 - if (ret) 1393 + ret = pl08x_fill_llis_for_desc(plchan->host, txd); 1394 + if (!ret) { 1395 + pl08x_release_mux(plchan); 1396 + pl08x_free_txd(pl08x, txd); 1524 1397 return NULL; 1398 + } 1525 1399 1526 - return &txd->tx; 1400 + return vchan_tx_prep(&plchan->vc, &txd->vd, flags); 1527 1401 } 1528 1402 1529 1403 static int pl08x_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, ··· 1547 1415 * Anything succeeds on channels with no physical allocation and 1548 1416 * no queued transfers. 1549 1417 */ 1550 - spin_lock_irqsave(&plchan->lock, flags); 1418 + spin_lock_irqsave(&plchan->vc.lock, flags); 1551 1419 if (!plchan->phychan && !plchan->at) { 1552 - spin_unlock_irqrestore(&plchan->lock, flags); 1420 + spin_unlock_irqrestore(&plchan->vc.lock, flags); 1553 1421 return 0; 1554 1422 } 1555 1423 ··· 1558 1426 plchan->state = PL08X_CHAN_IDLE; 1559 1427 1560 1428 if (plchan->phychan) { 1561 - pl08x_terminate_phy_chan(pl08x, plchan->phychan); 1562 - 1563 1429 /* 1564 1430 * Mark physical channel as free and free any slave 1565 1431 * signal 1566 1432 */ 1567 - release_phy_channel(plchan); 1568 - plchan->phychan_hold = 0; 1433 + pl08x_phy_free(plchan); 1569 1434 } 1570 1435 /* Dequeue jobs and free LLIs */ 1571 1436 if (plchan->at) { 1572 - pl08x_free_txd(pl08x, plchan->at); 1437 + pl08x_desc_free(&plchan->at->vd); 1573 1438 plchan->at = NULL; 1574 1439 } 1575 1440 /* Dequeue jobs not yet fired as well */ ··· 1586 1457 break; 1587 1458 } 1588 1459 1589 - spin_unlock_irqrestore(&plchan->lock, flags); 1460 + spin_unlock_irqrestore(&plchan->vc.lock, flags); 1590 1461 1591 1462 return ret; 1592 1463 } ··· 1623 1494 writel(PL080_CONFIG_ENABLE, pl08x->base + PL080_CONFIG); 1624 1495 } 1625 1496 1626 - static void pl08x_unmap_buffers(struct pl08x_txd *txd) 1627 - { 1628 - struct device *dev = txd->tx.chan->device->dev; 1629 - struct pl08x_sg *dsg; 1630 - 1631 - if (!(txd->tx.flags & DMA_COMPL_SKIP_SRC_UNMAP)) { 1632 - if (txd->tx.flags & DMA_COMPL_SRC_UNMAP_SINGLE) 1633 - list_for_each_entry(dsg, &txd->dsg_list, node) 1634 - dma_unmap_single(dev, dsg->src_addr, dsg->len, 1635 - DMA_TO_DEVICE); 1636 - else { 1637 - list_for_each_entry(dsg, &txd->dsg_list, node) 1638 - dma_unmap_page(dev, dsg->src_addr, dsg->len, 1639 - DMA_TO_DEVICE); 1640 - } 1641 - } 1642 - if (!(txd->tx.flags & DMA_COMPL_SKIP_DEST_UNMAP)) { 1643 - if (txd->tx.flags & DMA_COMPL_DEST_UNMAP_SINGLE) 1644 - list_for_each_entry(dsg, &txd->dsg_list, node) 1645 - dma_unmap_single(dev, dsg->dst_addr, dsg->len, 1646 - DMA_FROM_DEVICE); 1647 - else 1648 - list_for_each_entry(dsg, &txd->dsg_list, node) 1649 - dma_unmap_page(dev, dsg->dst_addr, dsg->len, 1650 - DMA_FROM_DEVICE); 1651 - } 1652 - } 1653 - 1654 - static void pl08x_tasklet(unsigned long data) 1655 - { 1656 - struct pl08x_dma_chan *plchan = (struct pl08x_dma_chan *) data; 1657 - struct pl08x_driver_data *pl08x = plchan->host; 1658 - struct pl08x_txd *txd; 1659 - unsigned long flags; 1660 - 1661 - spin_lock_irqsave(&plchan->lock, flags); 1662 - 1663 - txd = plchan->at; 1664 - plchan->at = NULL; 1665 - 1666 - if (txd) { 1667 - /* Update last completed */ 1668 - dma_cookie_complete(&txd->tx); 1669 - } 1670 - 1671 - /* If a new descriptor is queued, set it up plchan->at is NULL here */ 1672 - if (!list_empty(&plchan->pend_list)) { 1673 - struct pl08x_txd *next; 1674 - 1675 - next = list_first_entry(&plchan->pend_list, 1676 - struct pl08x_txd, 1677 - node); 1678 - list_del(&next->node); 1679 - 1680 - pl08x_start_txd(plchan, next); 1681 - } else if (plchan->phychan_hold) { 1682 - /* 1683 - * This channel is still in use - we have a new txd being 1684 - * prepared and will soon be queued. Don't give up the 1685 - * physical channel. 1686 - */ 1687 - } else { 1688 - struct pl08x_dma_chan *waiting = NULL; 1689 - 1690 - /* 1691 - * No more jobs, so free up the physical channel 1692 - * Free any allocated signal on slave transfers too 1693 - */ 1694 - release_phy_channel(plchan); 1695 - plchan->state = PL08X_CHAN_IDLE; 1696 - 1697 - /* 1698 - * And NOW before anyone else can grab that free:d up 1699 - * physical channel, see if there is some memcpy pending 1700 - * that seriously needs to start because of being stacked 1701 - * up while we were choking the physical channels with data. 1702 - */ 1703 - list_for_each_entry(waiting, &pl08x->memcpy.channels, 1704 - chan.device_node) { 1705 - if (waiting->state == PL08X_CHAN_WAITING && 1706 - waiting->waiting != NULL) { 1707 - int ret; 1708 - 1709 - /* This should REALLY not fail now */ 1710 - ret = prep_phy_channel(waiting, 1711 - waiting->waiting); 1712 - BUG_ON(ret); 1713 - waiting->phychan_hold--; 1714 - waiting->state = PL08X_CHAN_RUNNING; 1715 - waiting->waiting = NULL; 1716 - pl08x_issue_pending(&waiting->chan); 1717 - break; 1718 - } 1719 - } 1720 - } 1721 - 1722 - spin_unlock_irqrestore(&plchan->lock, flags); 1723 - 1724 - if (txd) { 1725 - dma_async_tx_callback callback = txd->tx.callback; 1726 - void *callback_param = txd->tx.callback_param; 1727 - 1728 - /* Don't try to unmap buffers on slave channels */ 1729 - if (!plchan->slave) 1730 - pl08x_unmap_buffers(txd); 1731 - 1732 - /* Free the descriptor */ 1733 - spin_lock_irqsave(&plchan->lock, flags); 1734 - pl08x_free_txd(pl08x, txd); 1735 - spin_unlock_irqrestore(&plchan->lock, flags); 1736 - 1737 - /* Callback to signal completion */ 1738 - if (callback) 1739 - callback(callback_param); 1740 - } 1741 - } 1742 - 1743 1497 static irqreturn_t pl08x_irq(int irq, void *dev) 1744 1498 { 1745 1499 struct pl08x_driver_data *pl08x = dev; ··· 1647 1635 /* Locate physical channel */ 1648 1636 struct pl08x_phy_chan *phychan = &pl08x->phy_chans[i]; 1649 1637 struct pl08x_dma_chan *plchan = phychan->serving; 1638 + struct pl08x_txd *tx; 1650 1639 1651 1640 if (!plchan) { 1652 1641 dev_err(&pl08x->adev->dev, ··· 1656 1643 continue; 1657 1644 } 1658 1645 1659 - /* Schedule tasklet on this channel */ 1660 - tasklet_schedule(&plchan->tasklet); 1646 + spin_lock(&plchan->vc.lock); 1647 + tx = plchan->at; 1648 + if (tx) { 1649 + plchan->at = NULL; 1650 + /* 1651 + * This descriptor is done, release its mux 1652 + * reservation. 1653 + */ 1654 + pl08x_release_mux(plchan); 1655 + tx->done = true; 1656 + vchan_cookie_complete(&tx->vd); 1657 + 1658 + /* 1659 + * And start the next descriptor (if any), 1660 + * otherwise free this channel. 1661 + */ 1662 + if (vchan_next_desc(&plchan->vc)) 1663 + pl08x_start_next_txd(plchan); 1664 + else 1665 + pl08x_phy_free(plchan); 1666 + } 1667 + spin_unlock(&plchan->vc.lock); 1668 + 1661 1669 mask |= (1 << i); 1662 1670 } 1663 1671 } ··· 1688 1654 1689 1655 static void pl08x_dma_slave_init(struct pl08x_dma_chan *chan) 1690 1656 { 1691 - u32 cctl = pl08x_cctl(chan->cd->cctl); 1692 - 1693 1657 chan->slave = true; 1694 1658 chan->name = chan->cd->bus_id; 1695 - chan->src_addr = chan->cd->addr; 1696 - chan->dst_addr = chan->cd->addr; 1697 - chan->src_cctl = cctl | PL080_CONTROL_DST_INCR | 1698 - pl08x_select_bus(chan->cd->periph_buses, chan->host->mem_buses); 1699 - chan->dst_cctl = cctl | PL080_CONTROL_SRC_INCR | 1700 - pl08x_select_bus(chan->host->mem_buses, chan->cd->periph_buses); 1659 + chan->cfg.src_addr = chan->cd->addr; 1660 + chan->cfg.dst_addr = chan->cd->addr; 1701 1661 } 1702 1662 1703 1663 /* ··· 1721 1693 1722 1694 chan->host = pl08x; 1723 1695 chan->state = PL08X_CHAN_IDLE; 1696 + chan->signal = -1; 1724 1697 1725 1698 if (slave) { 1726 1699 chan->cd = &pl08x->pd->slave_channels[i]; ··· 1734 1705 return -ENOMEM; 1735 1706 } 1736 1707 } 1737 - if (chan->cd->circular_buffer) { 1738 - dev_err(&pl08x->adev->dev, 1739 - "channel %s: circular buffers not supported\n", 1740 - chan->name); 1741 - kfree(chan); 1742 - continue; 1743 - } 1744 1708 dev_dbg(&pl08x->adev->dev, 1745 1709 "initialize virtual channel \"%s\"\n", 1746 1710 chan->name); 1747 1711 1748 - chan->chan.device = dmadev; 1749 - dma_cookie_init(&chan->chan); 1750 - 1751 - spin_lock_init(&chan->lock); 1752 - INIT_LIST_HEAD(&chan->pend_list); 1753 - tasklet_init(&chan->tasklet, pl08x_tasklet, 1754 - (unsigned long) chan); 1755 - 1756 - list_add_tail(&chan->chan.device_node, &dmadev->channels); 1712 + chan->vc.desc_free = pl08x_desc_free; 1713 + vchan_init(&chan->vc, dmadev); 1757 1714 } 1758 1715 dev_info(&pl08x->adev->dev, "initialized %d virtual %s channels\n", 1759 1716 i, slave ? "slave" : "memcpy"); ··· 1752 1737 struct pl08x_dma_chan *next; 1753 1738 1754 1739 list_for_each_entry_safe(chan, 1755 - next, &dmadev->channels, chan.device_node) { 1756 - list_del(&chan->chan.device_node); 1740 + next, &dmadev->channels, vc.chan.device_node) { 1741 + list_del(&chan->vc.chan.device_node); 1757 1742 kfree(chan); 1758 1743 } 1759 1744 } ··· 1806 1791 seq_printf(s, "\nPL08x virtual memcpy channels:\n"); 1807 1792 seq_printf(s, "CHANNEL:\tSTATE:\n"); 1808 1793 seq_printf(s, "--------\t------\n"); 1809 - list_for_each_entry(chan, &pl08x->memcpy.channels, chan.device_node) { 1794 + list_for_each_entry(chan, &pl08x->memcpy.channels, vc.chan.device_node) { 1810 1795 seq_printf(s, "%s\t\t%s\n", chan->name, 1811 1796 pl08x_state_str(chan->state)); 1812 1797 } ··· 1814 1799 seq_printf(s, "\nPL08x virtual slave channels:\n"); 1815 1800 seq_printf(s, "CHANNEL:\tSTATE:\n"); 1816 1801 seq_printf(s, "--------\t------\n"); 1817 - list_for_each_entry(chan, &pl08x->slave.channels, chan.device_node) { 1802 + list_for_each_entry(chan, &pl08x->slave.channels, vc.chan.device_node) { 1818 1803 seq_printf(s, "%s\t\t%s\n", chan->name, 1819 1804 pl08x_state_str(chan->state)); 1820 1805 } ··· 1866 1851 goto out_no_pl08x; 1867 1852 } 1868 1853 1869 - pm_runtime_set_active(&adev->dev); 1870 - pm_runtime_enable(&adev->dev); 1871 - 1872 1854 /* Initialize memcpy engine */ 1873 1855 dma_cap_set(DMA_MEMCPY, pl08x->memcpy.cap_mask); 1874 1856 pl08x->memcpy.dev = &adev->dev; ··· 1915 1903 goto out_no_lli_pool; 1916 1904 } 1917 1905 1918 - spin_lock_init(&pl08x->lock); 1919 - 1920 1906 pl08x->base = ioremap(adev->res.start, resource_size(&adev->res)); 1921 1907 if (!pl08x->base) { 1922 1908 ret = -ENOMEM; ··· 1952 1942 ch->id = i; 1953 1943 ch->base = pl08x->base + PL080_Cx_BASE(i); 1954 1944 spin_lock_init(&ch->lock); 1955 - ch->signal = -1; 1956 1945 1957 1946 /* 1958 1947 * Nomadik variants can have channels that are locked ··· 2016 2007 amba_part(adev), amba_rev(adev), 2017 2008 (unsigned long long)adev->res.start, adev->irq[0]); 2018 2009 2019 - pm_runtime_put(&adev->dev); 2020 2010 return 0; 2021 2011 2022 2012 out_no_slave_reg: ··· 2034 2026 dma_pool_destroy(pl08x->pool); 2035 2027 out_no_lli_pool: 2036 2028 out_no_platdata: 2037 - pm_runtime_put(&adev->dev); 2038 - pm_runtime_disable(&adev->dev); 2039 - 2040 2029 kfree(pl08x); 2041 2030 out_no_pl08x: 2042 2031 amba_release_regions(adev);
+669
drivers/dma/omap-dma.c
··· 1 + /* 2 + * OMAP DMAengine support 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + */ 8 + #include <linux/dmaengine.h> 9 + #include <linux/dma-mapping.h> 10 + #include <linux/err.h> 11 + #include <linux/init.h> 12 + #include <linux/interrupt.h> 13 + #include <linux/list.h> 14 + #include <linux/module.h> 15 + #include <linux/omap-dma.h> 16 + #include <linux/platform_device.h> 17 + #include <linux/slab.h> 18 + #include <linux/spinlock.h> 19 + 20 + #include "virt-dma.h" 21 + #include <plat/dma.h> 22 + 23 + struct omap_dmadev { 24 + struct dma_device ddev; 25 + spinlock_t lock; 26 + struct tasklet_struct task; 27 + struct list_head pending; 28 + }; 29 + 30 + struct omap_chan { 31 + struct virt_dma_chan vc; 32 + struct list_head node; 33 + 34 + struct dma_slave_config cfg; 35 + unsigned dma_sig; 36 + bool cyclic; 37 + 38 + int dma_ch; 39 + struct omap_desc *desc; 40 + unsigned sgidx; 41 + }; 42 + 43 + struct omap_sg { 44 + dma_addr_t addr; 45 + uint32_t en; /* number of elements (24-bit) */ 46 + uint32_t fn; /* number of frames (16-bit) */ 47 + }; 48 + 49 + struct omap_desc { 50 + struct virt_dma_desc vd; 51 + enum dma_transfer_direction dir; 52 + dma_addr_t dev_addr; 53 + 54 + int16_t fi; /* for OMAP_DMA_SYNC_PACKET */ 55 + uint8_t es; /* OMAP_DMA_DATA_TYPE_xxx */ 56 + uint8_t sync_mode; /* OMAP_DMA_SYNC_xxx */ 57 + uint8_t sync_type; /* OMAP_DMA_xxx_SYNC* */ 58 + uint8_t periph_port; /* Peripheral port */ 59 + 60 + unsigned sglen; 61 + struct omap_sg sg[0]; 62 + }; 63 + 64 + static const unsigned es_bytes[] = { 65 + [OMAP_DMA_DATA_TYPE_S8] = 1, 66 + [OMAP_DMA_DATA_TYPE_S16] = 2, 67 + [OMAP_DMA_DATA_TYPE_S32] = 4, 68 + }; 69 + 70 + static inline struct omap_dmadev *to_omap_dma_dev(struct dma_device *d) 71 + { 72 + return container_of(d, struct omap_dmadev, ddev); 73 + } 74 + 75 + static inline struct omap_chan *to_omap_dma_chan(struct dma_chan *c) 76 + { 77 + return container_of(c, struct omap_chan, vc.chan); 78 + } 79 + 80 + static inline struct omap_desc *to_omap_dma_desc(struct dma_async_tx_descriptor *t) 81 + { 82 + return container_of(t, struct omap_desc, vd.tx); 83 + } 84 + 85 + static void omap_dma_desc_free(struct virt_dma_desc *vd) 86 + { 87 + kfree(container_of(vd, struct omap_desc, vd)); 88 + } 89 + 90 + static void omap_dma_start_sg(struct omap_chan *c, struct omap_desc *d, 91 + unsigned idx) 92 + { 93 + struct omap_sg *sg = d->sg + idx; 94 + 95 + if (d->dir == DMA_DEV_TO_MEM) 96 + omap_set_dma_dest_params(c->dma_ch, OMAP_DMA_PORT_EMIFF, 97 + OMAP_DMA_AMODE_POST_INC, sg->addr, 0, 0); 98 + else 99 + omap_set_dma_src_params(c->dma_ch, OMAP_DMA_PORT_EMIFF, 100 + OMAP_DMA_AMODE_POST_INC, sg->addr, 0, 0); 101 + 102 + omap_set_dma_transfer_params(c->dma_ch, d->es, sg->en, sg->fn, 103 + d->sync_mode, c->dma_sig, d->sync_type); 104 + 105 + omap_start_dma(c->dma_ch); 106 + } 107 + 108 + static void omap_dma_start_desc(struct omap_chan *c) 109 + { 110 + struct virt_dma_desc *vd = vchan_next_desc(&c->vc); 111 + struct omap_desc *d; 112 + 113 + if (!vd) { 114 + c->desc = NULL; 115 + return; 116 + } 117 + 118 + list_del(&vd->node); 119 + 120 + c->desc = d = to_omap_dma_desc(&vd->tx); 121 + c->sgidx = 0; 122 + 123 + if (d->dir == DMA_DEV_TO_MEM) 124 + omap_set_dma_src_params(c->dma_ch, d->periph_port, 125 + OMAP_DMA_AMODE_CONSTANT, d->dev_addr, 0, d->fi); 126 + else 127 + omap_set_dma_dest_params(c->dma_ch, d->periph_port, 128 + OMAP_DMA_AMODE_CONSTANT, d->dev_addr, 0, d->fi); 129 + 130 + omap_dma_start_sg(c, d, 0); 131 + } 132 + 133 + static void omap_dma_callback(int ch, u16 status, void *data) 134 + { 135 + struct omap_chan *c = data; 136 + struct omap_desc *d; 137 + unsigned long flags; 138 + 139 + spin_lock_irqsave(&c->vc.lock, flags); 140 + d = c->desc; 141 + if (d) { 142 + if (!c->cyclic) { 143 + if (++c->sgidx < d->sglen) { 144 + omap_dma_start_sg(c, d, c->sgidx); 145 + } else { 146 + omap_dma_start_desc(c); 147 + vchan_cookie_complete(&d->vd); 148 + } 149 + } else { 150 + vchan_cyclic_callback(&d->vd); 151 + } 152 + } 153 + spin_unlock_irqrestore(&c->vc.lock, flags); 154 + } 155 + 156 + /* 157 + * This callback schedules all pending channels. We could be more 158 + * clever here by postponing allocation of the real DMA channels to 159 + * this point, and freeing them when our virtual channel becomes idle. 160 + * 161 + * We would then need to deal with 'all channels in-use' 162 + */ 163 + static void omap_dma_sched(unsigned long data) 164 + { 165 + struct omap_dmadev *d = (struct omap_dmadev *)data; 166 + LIST_HEAD(head); 167 + 168 + spin_lock_irq(&d->lock); 169 + list_splice_tail_init(&d->pending, &head); 170 + spin_unlock_irq(&d->lock); 171 + 172 + while (!list_empty(&head)) { 173 + struct omap_chan *c = list_first_entry(&head, 174 + struct omap_chan, node); 175 + 176 + spin_lock_irq(&c->vc.lock); 177 + list_del_init(&c->node); 178 + omap_dma_start_desc(c); 179 + spin_unlock_irq(&c->vc.lock); 180 + } 181 + } 182 + 183 + static int omap_dma_alloc_chan_resources(struct dma_chan *chan) 184 + { 185 + struct omap_chan *c = to_omap_dma_chan(chan); 186 + 187 + dev_info(c->vc.chan.device->dev, "allocating channel for %u\n", c->dma_sig); 188 + 189 + return omap_request_dma(c->dma_sig, "DMA engine", 190 + omap_dma_callback, c, &c->dma_ch); 191 + } 192 + 193 + static void omap_dma_free_chan_resources(struct dma_chan *chan) 194 + { 195 + struct omap_chan *c = to_omap_dma_chan(chan); 196 + 197 + vchan_free_chan_resources(&c->vc); 198 + omap_free_dma(c->dma_ch); 199 + 200 + dev_info(c->vc.chan.device->dev, "freeing channel for %u\n", c->dma_sig); 201 + } 202 + 203 + static size_t omap_dma_sg_size(struct omap_sg *sg) 204 + { 205 + return sg->en * sg->fn; 206 + } 207 + 208 + static size_t omap_dma_desc_size(struct omap_desc *d) 209 + { 210 + unsigned i; 211 + size_t size; 212 + 213 + for (size = i = 0; i < d->sglen; i++) 214 + size += omap_dma_sg_size(&d->sg[i]); 215 + 216 + return size * es_bytes[d->es]; 217 + } 218 + 219 + static size_t omap_dma_desc_size_pos(struct omap_desc *d, dma_addr_t addr) 220 + { 221 + unsigned i; 222 + size_t size, es_size = es_bytes[d->es]; 223 + 224 + for (size = i = 0; i < d->sglen; i++) { 225 + size_t this_size = omap_dma_sg_size(&d->sg[i]) * es_size; 226 + 227 + if (size) 228 + size += this_size; 229 + else if (addr >= d->sg[i].addr && 230 + addr < d->sg[i].addr + this_size) 231 + size += d->sg[i].addr + this_size - addr; 232 + } 233 + return size; 234 + } 235 + 236 + static enum dma_status omap_dma_tx_status(struct dma_chan *chan, 237 + dma_cookie_t cookie, struct dma_tx_state *txstate) 238 + { 239 + struct omap_chan *c = to_omap_dma_chan(chan); 240 + struct virt_dma_desc *vd; 241 + enum dma_status ret; 242 + unsigned long flags; 243 + 244 + ret = dma_cookie_status(chan, cookie, txstate); 245 + if (ret == DMA_SUCCESS || !txstate) 246 + return ret; 247 + 248 + spin_lock_irqsave(&c->vc.lock, flags); 249 + vd = vchan_find_desc(&c->vc, cookie); 250 + if (vd) { 251 + txstate->residue = omap_dma_desc_size(to_omap_dma_desc(&vd->tx)); 252 + } else if (c->desc && c->desc->vd.tx.cookie == cookie) { 253 + struct omap_desc *d = c->desc; 254 + dma_addr_t pos; 255 + 256 + if (d->dir == DMA_MEM_TO_DEV) 257 + pos = omap_get_dma_src_pos(c->dma_ch); 258 + else if (d->dir == DMA_DEV_TO_MEM) 259 + pos = omap_get_dma_dst_pos(c->dma_ch); 260 + else 261 + pos = 0; 262 + 263 + txstate->residue = omap_dma_desc_size_pos(d, pos); 264 + } else { 265 + txstate->residue = 0; 266 + } 267 + spin_unlock_irqrestore(&c->vc.lock, flags); 268 + 269 + return ret; 270 + } 271 + 272 + static void omap_dma_issue_pending(struct dma_chan *chan) 273 + { 274 + struct omap_chan *c = to_omap_dma_chan(chan); 275 + unsigned long flags; 276 + 277 + spin_lock_irqsave(&c->vc.lock, flags); 278 + if (vchan_issue_pending(&c->vc) && !c->desc) { 279 + struct omap_dmadev *d = to_omap_dma_dev(chan->device); 280 + spin_lock(&d->lock); 281 + if (list_empty(&c->node)) 282 + list_add_tail(&c->node, &d->pending); 283 + spin_unlock(&d->lock); 284 + tasklet_schedule(&d->task); 285 + } 286 + spin_unlock_irqrestore(&c->vc.lock, flags); 287 + } 288 + 289 + static struct dma_async_tx_descriptor *omap_dma_prep_slave_sg( 290 + struct dma_chan *chan, struct scatterlist *sgl, unsigned sglen, 291 + enum dma_transfer_direction dir, unsigned long tx_flags, void *context) 292 + { 293 + struct omap_chan *c = to_omap_dma_chan(chan); 294 + enum dma_slave_buswidth dev_width; 295 + struct scatterlist *sgent; 296 + struct omap_desc *d; 297 + dma_addr_t dev_addr; 298 + unsigned i, j = 0, es, en, frame_bytes, sync_type; 299 + u32 burst; 300 + 301 + if (dir == DMA_DEV_TO_MEM) { 302 + dev_addr = c->cfg.src_addr; 303 + dev_width = c->cfg.src_addr_width; 304 + burst = c->cfg.src_maxburst; 305 + sync_type = OMAP_DMA_SRC_SYNC; 306 + } else if (dir == DMA_MEM_TO_DEV) { 307 + dev_addr = c->cfg.dst_addr; 308 + dev_width = c->cfg.dst_addr_width; 309 + burst = c->cfg.dst_maxburst; 310 + sync_type = OMAP_DMA_DST_SYNC; 311 + } else { 312 + dev_err(chan->device->dev, "%s: bad direction?\n", __func__); 313 + return NULL; 314 + } 315 + 316 + /* Bus width translates to the element size (ES) */ 317 + switch (dev_width) { 318 + case DMA_SLAVE_BUSWIDTH_1_BYTE: 319 + es = OMAP_DMA_DATA_TYPE_S8; 320 + break; 321 + case DMA_SLAVE_BUSWIDTH_2_BYTES: 322 + es = OMAP_DMA_DATA_TYPE_S16; 323 + break; 324 + case DMA_SLAVE_BUSWIDTH_4_BYTES: 325 + es = OMAP_DMA_DATA_TYPE_S32; 326 + break; 327 + default: /* not reached */ 328 + return NULL; 329 + } 330 + 331 + /* Now allocate and setup the descriptor. */ 332 + d = kzalloc(sizeof(*d) + sglen * sizeof(d->sg[0]), GFP_ATOMIC); 333 + if (!d) 334 + return NULL; 335 + 336 + d->dir = dir; 337 + d->dev_addr = dev_addr; 338 + d->es = es; 339 + d->sync_mode = OMAP_DMA_SYNC_FRAME; 340 + d->sync_type = sync_type; 341 + d->periph_port = OMAP_DMA_PORT_TIPB; 342 + 343 + /* 344 + * Build our scatterlist entries: each contains the address, 345 + * the number of elements (EN) in each frame, and the number of 346 + * frames (FN). Number of bytes for this entry = ES * EN * FN. 347 + * 348 + * Burst size translates to number of elements with frame sync. 349 + * Note: DMA engine defines burst to be the number of dev-width 350 + * transfers. 351 + */ 352 + en = burst; 353 + frame_bytes = es_bytes[es] * en; 354 + for_each_sg(sgl, sgent, sglen, i) { 355 + d->sg[j].addr = sg_dma_address(sgent); 356 + d->sg[j].en = en; 357 + d->sg[j].fn = sg_dma_len(sgent) / frame_bytes; 358 + j++; 359 + } 360 + 361 + d->sglen = j; 362 + 363 + return vchan_tx_prep(&c->vc, &d->vd, tx_flags); 364 + } 365 + 366 + static struct dma_async_tx_descriptor *omap_dma_prep_dma_cyclic( 367 + struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, 368 + size_t period_len, enum dma_transfer_direction dir, void *context) 369 + { 370 + struct omap_chan *c = to_omap_dma_chan(chan); 371 + enum dma_slave_buswidth dev_width; 372 + struct omap_desc *d; 373 + dma_addr_t dev_addr; 374 + unsigned es, sync_type; 375 + u32 burst; 376 + 377 + if (dir == DMA_DEV_TO_MEM) { 378 + dev_addr = c->cfg.src_addr; 379 + dev_width = c->cfg.src_addr_width; 380 + burst = c->cfg.src_maxburst; 381 + sync_type = OMAP_DMA_SRC_SYNC; 382 + } else if (dir == DMA_MEM_TO_DEV) { 383 + dev_addr = c->cfg.dst_addr; 384 + dev_width = c->cfg.dst_addr_width; 385 + burst = c->cfg.dst_maxburst; 386 + sync_type = OMAP_DMA_DST_SYNC; 387 + } else { 388 + dev_err(chan->device->dev, "%s: bad direction?\n", __func__); 389 + return NULL; 390 + } 391 + 392 + /* Bus width translates to the element size (ES) */ 393 + switch (dev_width) { 394 + case DMA_SLAVE_BUSWIDTH_1_BYTE: 395 + es = OMAP_DMA_DATA_TYPE_S8; 396 + break; 397 + case DMA_SLAVE_BUSWIDTH_2_BYTES: 398 + es = OMAP_DMA_DATA_TYPE_S16; 399 + break; 400 + case DMA_SLAVE_BUSWIDTH_4_BYTES: 401 + es = OMAP_DMA_DATA_TYPE_S32; 402 + break; 403 + default: /* not reached */ 404 + return NULL; 405 + } 406 + 407 + /* Now allocate and setup the descriptor. */ 408 + d = kzalloc(sizeof(*d) + sizeof(d->sg[0]), GFP_ATOMIC); 409 + if (!d) 410 + return NULL; 411 + 412 + d->dir = dir; 413 + d->dev_addr = dev_addr; 414 + d->fi = burst; 415 + d->es = es; 416 + d->sync_mode = OMAP_DMA_SYNC_PACKET; 417 + d->sync_type = sync_type; 418 + d->periph_port = OMAP_DMA_PORT_MPUI; 419 + d->sg[0].addr = buf_addr; 420 + d->sg[0].en = period_len / es_bytes[es]; 421 + d->sg[0].fn = buf_len / period_len; 422 + d->sglen = 1; 423 + 424 + if (!c->cyclic) { 425 + c->cyclic = true; 426 + omap_dma_link_lch(c->dma_ch, c->dma_ch); 427 + omap_enable_dma_irq(c->dma_ch, OMAP_DMA_FRAME_IRQ); 428 + omap_disable_dma_irq(c->dma_ch, OMAP_DMA_BLOCK_IRQ); 429 + } 430 + 431 + if (!cpu_class_is_omap1()) { 432 + omap_set_dma_src_burst_mode(c->dma_ch, OMAP_DMA_DATA_BURST_16); 433 + omap_set_dma_dest_burst_mode(c->dma_ch, OMAP_DMA_DATA_BURST_16); 434 + } 435 + 436 + return vchan_tx_prep(&c->vc, &d->vd, DMA_CTRL_ACK | DMA_PREP_INTERRUPT); 437 + } 438 + 439 + static int omap_dma_slave_config(struct omap_chan *c, struct dma_slave_config *cfg) 440 + { 441 + if (cfg->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES || 442 + cfg->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES) 443 + return -EINVAL; 444 + 445 + memcpy(&c->cfg, cfg, sizeof(c->cfg)); 446 + 447 + return 0; 448 + } 449 + 450 + static int omap_dma_terminate_all(struct omap_chan *c) 451 + { 452 + struct omap_dmadev *d = to_omap_dma_dev(c->vc.chan.device); 453 + unsigned long flags; 454 + LIST_HEAD(head); 455 + 456 + spin_lock_irqsave(&c->vc.lock, flags); 457 + 458 + /* Prevent this channel being scheduled */ 459 + spin_lock(&d->lock); 460 + list_del_init(&c->node); 461 + spin_unlock(&d->lock); 462 + 463 + /* 464 + * Stop DMA activity: we assume the callback will not be called 465 + * after omap_stop_dma() returns (even if it does, it will see 466 + * c->desc is NULL and exit.) 467 + */ 468 + if (c->desc) { 469 + c->desc = NULL; 470 + omap_stop_dma(c->dma_ch); 471 + } 472 + 473 + if (c->cyclic) { 474 + c->cyclic = false; 475 + omap_dma_unlink_lch(c->dma_ch, c->dma_ch); 476 + } 477 + 478 + vchan_get_all_descriptors(&c->vc, &head); 479 + spin_unlock_irqrestore(&c->vc.lock, flags); 480 + vchan_dma_desc_free_list(&c->vc, &head); 481 + 482 + return 0; 483 + } 484 + 485 + static int omap_dma_pause(struct omap_chan *c) 486 + { 487 + /* FIXME: not supported by platform private API */ 488 + return -EINVAL; 489 + } 490 + 491 + static int omap_dma_resume(struct omap_chan *c) 492 + { 493 + /* FIXME: not supported by platform private API */ 494 + return -EINVAL; 495 + } 496 + 497 + static int omap_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, 498 + unsigned long arg) 499 + { 500 + struct omap_chan *c = to_omap_dma_chan(chan); 501 + int ret; 502 + 503 + switch (cmd) { 504 + case DMA_SLAVE_CONFIG: 505 + ret = omap_dma_slave_config(c, (struct dma_slave_config *)arg); 506 + break; 507 + 508 + case DMA_TERMINATE_ALL: 509 + ret = omap_dma_terminate_all(c); 510 + break; 511 + 512 + case DMA_PAUSE: 513 + ret = omap_dma_pause(c); 514 + break; 515 + 516 + case DMA_RESUME: 517 + ret = omap_dma_resume(c); 518 + break; 519 + 520 + default: 521 + ret = -ENXIO; 522 + break; 523 + } 524 + 525 + return ret; 526 + } 527 + 528 + static int omap_dma_chan_init(struct omap_dmadev *od, int dma_sig) 529 + { 530 + struct omap_chan *c; 531 + 532 + c = kzalloc(sizeof(*c), GFP_KERNEL); 533 + if (!c) 534 + return -ENOMEM; 535 + 536 + c->dma_sig = dma_sig; 537 + c->vc.desc_free = omap_dma_desc_free; 538 + vchan_init(&c->vc, &od->ddev); 539 + INIT_LIST_HEAD(&c->node); 540 + 541 + od->ddev.chancnt++; 542 + 543 + return 0; 544 + } 545 + 546 + static void omap_dma_free(struct omap_dmadev *od) 547 + { 548 + tasklet_kill(&od->task); 549 + while (!list_empty(&od->ddev.channels)) { 550 + struct omap_chan *c = list_first_entry(&od->ddev.channels, 551 + struct omap_chan, vc.chan.device_node); 552 + 553 + list_del(&c->vc.chan.device_node); 554 + tasklet_kill(&c->vc.task); 555 + kfree(c); 556 + } 557 + kfree(od); 558 + } 559 + 560 + static int omap_dma_probe(struct platform_device *pdev) 561 + { 562 + struct omap_dmadev *od; 563 + int rc, i; 564 + 565 + od = kzalloc(sizeof(*od), GFP_KERNEL); 566 + if (!od) 567 + return -ENOMEM; 568 + 569 + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask); 570 + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask); 571 + od->ddev.device_alloc_chan_resources = omap_dma_alloc_chan_resources; 572 + od->ddev.device_free_chan_resources = omap_dma_free_chan_resources; 573 + od->ddev.device_tx_status = omap_dma_tx_status; 574 + od->ddev.device_issue_pending = omap_dma_issue_pending; 575 + od->ddev.device_prep_slave_sg = omap_dma_prep_slave_sg; 576 + od->ddev.device_prep_dma_cyclic = omap_dma_prep_dma_cyclic; 577 + od->ddev.device_control = omap_dma_control; 578 + od->ddev.dev = &pdev->dev; 579 + INIT_LIST_HEAD(&od->ddev.channels); 580 + INIT_LIST_HEAD(&od->pending); 581 + spin_lock_init(&od->lock); 582 + 583 + tasklet_init(&od->task, omap_dma_sched, (unsigned long)od); 584 + 585 + for (i = 0; i < 127; i++) { 586 + rc = omap_dma_chan_init(od, i); 587 + if (rc) { 588 + omap_dma_free(od); 589 + return rc; 590 + } 591 + } 592 + 593 + rc = dma_async_device_register(&od->ddev); 594 + if (rc) { 595 + pr_warn("OMAP-DMA: failed to register slave DMA engine device: %d\n", 596 + rc); 597 + omap_dma_free(od); 598 + } else { 599 + platform_set_drvdata(pdev, od); 600 + } 601 + 602 + dev_info(&pdev->dev, "OMAP DMA engine driver\n"); 603 + 604 + return rc; 605 + } 606 + 607 + static int omap_dma_remove(struct platform_device *pdev) 608 + { 609 + struct omap_dmadev *od = platform_get_drvdata(pdev); 610 + 611 + dma_async_device_unregister(&od->ddev); 612 + omap_dma_free(od); 613 + 614 + return 0; 615 + } 616 + 617 + static struct platform_driver omap_dma_driver = { 618 + .probe = omap_dma_probe, 619 + .remove = omap_dma_remove, 620 + .driver = { 621 + .name = "omap-dma-engine", 622 + .owner = THIS_MODULE, 623 + }, 624 + }; 625 + 626 + bool omap_dma_filter_fn(struct dma_chan *chan, void *param) 627 + { 628 + if (chan->device->dev->driver == &omap_dma_driver.driver) { 629 + struct omap_chan *c = to_omap_dma_chan(chan); 630 + unsigned req = *(unsigned *)param; 631 + 632 + return req == c->dma_sig; 633 + } 634 + return false; 635 + } 636 + EXPORT_SYMBOL_GPL(omap_dma_filter_fn); 637 + 638 + static struct platform_device *pdev; 639 + 640 + static const struct platform_device_info omap_dma_dev_info = { 641 + .name = "omap-dma-engine", 642 + .id = -1, 643 + .dma_mask = DMA_BIT_MASK(32), 644 + }; 645 + 646 + static int omap_dma_init(void) 647 + { 648 + int rc = platform_driver_register(&omap_dma_driver); 649 + 650 + if (rc == 0) { 651 + pdev = platform_device_register_full(&omap_dma_dev_info); 652 + if (IS_ERR(pdev)) { 653 + platform_driver_unregister(&omap_dma_driver); 654 + rc = PTR_ERR(pdev); 655 + } 656 + } 657 + return rc; 658 + } 659 + subsys_initcall(omap_dma_init); 660 + 661 + static void __exit omap_dma_exit(void) 662 + { 663 + platform_device_unregister(pdev); 664 + platform_driver_unregister(&omap_dma_driver); 665 + } 666 + module_exit(omap_dma_exit); 667 + 668 + MODULE_AUTHOR("Russell King"); 669 + MODULE_LICENSE("GPL");
+193 -197
drivers/dma/sa11x0-dma.c
··· 21 21 #include <linux/slab.h> 22 22 #include <linux/spinlock.h> 23 23 24 + #include "virt-dma.h" 25 + 24 26 #define NR_PHY_CHAN 6 25 27 #define DMA_ALIGN 3 26 28 #define DMA_MAX_SIZE 0x1fff ··· 74 72 }; 75 73 76 74 struct sa11x0_dma_desc { 77 - struct dma_async_tx_descriptor tx; 75 + struct virt_dma_desc vd; 76 + 78 77 u32 ddar; 79 78 size_t size; 79 + unsigned period; 80 + bool cyclic; 80 81 81 - /* maybe protected by c->lock */ 82 - struct list_head node; 83 82 unsigned sglen; 84 83 struct sa11x0_dma_sg sg[0]; 85 84 }; ··· 88 85 struct sa11x0_dma_phy; 89 86 90 87 struct sa11x0_dma_chan { 91 - struct dma_chan chan; 92 - spinlock_t lock; 93 - dma_cookie_t lc; 88 + struct virt_dma_chan vc; 94 89 95 - /* protected by c->lock */ 90 + /* protected by c->vc.lock */ 96 91 struct sa11x0_dma_phy *phy; 97 92 enum dma_status status; 98 - struct list_head desc_submitted; 99 - struct list_head desc_issued; 100 93 101 94 /* protected by d->lock */ 102 95 struct list_head node; ··· 108 109 109 110 struct sa11x0_dma_chan *vchan; 110 111 111 - /* Protected by c->lock */ 112 + /* Protected by c->vc.lock */ 112 113 unsigned sg_load; 113 114 struct sa11x0_dma_desc *txd_load; 114 115 unsigned sg_done; ··· 126 127 spinlock_t lock; 127 128 struct tasklet_struct task; 128 129 struct list_head chan_pending; 129 - struct list_head desc_complete; 130 130 struct sa11x0_dma_phy phy[NR_PHY_CHAN]; 131 131 }; 132 132 133 133 static struct sa11x0_dma_chan *to_sa11x0_dma_chan(struct dma_chan *chan) 134 134 { 135 - return container_of(chan, struct sa11x0_dma_chan, chan); 135 + return container_of(chan, struct sa11x0_dma_chan, vc.chan); 136 136 } 137 137 138 138 static struct sa11x0_dma_dev *to_sa11x0_dma(struct dma_device *dmadev) ··· 139 141 return container_of(dmadev, struct sa11x0_dma_dev, slave); 140 142 } 141 143 142 - static struct sa11x0_dma_desc *to_sa11x0_dma_tx(struct dma_async_tx_descriptor *tx) 143 - { 144 - return container_of(tx, struct sa11x0_dma_desc, tx); 145 - } 146 - 147 144 static struct sa11x0_dma_desc *sa11x0_dma_next_desc(struct sa11x0_dma_chan *c) 148 145 { 149 - if (list_empty(&c->desc_issued)) 150 - return NULL; 146 + struct virt_dma_desc *vd = vchan_next_desc(&c->vc); 151 147 152 - return list_first_entry(&c->desc_issued, struct sa11x0_dma_desc, node); 148 + return vd ? container_of(vd, struct sa11x0_dma_desc, vd) : NULL; 149 + } 150 + 151 + static void sa11x0_dma_free_desc(struct virt_dma_desc *vd) 152 + { 153 + kfree(container_of(vd, struct sa11x0_dma_desc, vd)); 153 154 } 154 155 155 156 static void sa11x0_dma_start_desc(struct sa11x0_dma_phy *p, struct sa11x0_dma_desc *txd) 156 157 { 157 - list_del(&txd->node); 158 + list_del(&txd->vd.node); 158 159 p->txd_load = txd; 159 160 p->sg_load = 0; 160 161 161 162 dev_vdbg(p->dev->slave.dev, "pchan %u: txd %p[%x]: starting: DDAR:%x\n", 162 - p->num, txd, txd->tx.cookie, txd->ddar); 163 + p->num, &txd->vd, txd->vd.tx.cookie, txd->ddar); 163 164 } 164 165 165 166 static void noinline sa11x0_dma_start_sg(struct sa11x0_dma_phy *p, ··· 180 183 return; 181 184 182 185 if (p->sg_load == txd->sglen) { 183 - struct sa11x0_dma_desc *txn = sa11x0_dma_next_desc(c); 186 + if (!txd->cyclic) { 187 + struct sa11x0_dma_desc *txn = sa11x0_dma_next_desc(c); 184 188 185 - /* 186 - * We have reached the end of the current descriptor. 187 - * Peek at the next descriptor, and if compatible with 188 - * the current, start processing it. 189 - */ 190 - if (txn && txn->ddar == txd->ddar) { 191 - txd = txn; 192 - sa11x0_dma_start_desc(p, txn); 189 + /* 190 + * We have reached the end of the current descriptor. 191 + * Peek at the next descriptor, and if compatible with 192 + * the current, start processing it. 193 + */ 194 + if (txn && txn->ddar == txd->ddar) { 195 + txd = txn; 196 + sa11x0_dma_start_desc(p, txn); 197 + } else { 198 + p->txd_load = NULL; 199 + return; 200 + } 193 201 } else { 194 - p->txd_load = NULL; 195 - return; 202 + /* Cyclic: reset back to beginning */ 203 + p->sg_load = 0; 196 204 } 197 205 } 198 206 ··· 231 229 struct sa11x0_dma_desc *txd = p->txd_done; 232 230 233 231 if (++p->sg_done == txd->sglen) { 234 - struct sa11x0_dma_dev *d = p->dev; 232 + if (!txd->cyclic) { 233 + vchan_cookie_complete(&txd->vd); 235 234 236 - dev_vdbg(d->slave.dev, "pchan %u: txd %p[%x]: completed\n", 237 - p->num, p->txd_done, p->txd_done->tx.cookie); 235 + p->sg_done = 0; 236 + p->txd_done = p->txd_load; 238 237 239 - c->lc = txd->tx.cookie; 238 + if (!p->txd_done) 239 + tasklet_schedule(&p->dev->task); 240 + } else { 241 + if ((p->sg_done % txd->period) == 0) 242 + vchan_cyclic_callback(&txd->vd); 240 243 241 - spin_lock(&d->lock); 242 - list_add_tail(&txd->node, &d->desc_complete); 243 - spin_unlock(&d->lock); 244 - 245 - p->sg_done = 0; 246 - p->txd_done = p->txd_load; 247 - 248 - tasklet_schedule(&d->task); 244 + /* Cyclic: reset back to beginning */ 245 + p->sg_done = 0; 246 + } 249 247 } 250 248 251 249 sa11x0_dma_start_sg(p, c); ··· 282 280 if (c) { 283 281 unsigned long flags; 284 282 285 - spin_lock_irqsave(&c->lock, flags); 283 + spin_lock_irqsave(&c->vc.lock, flags); 286 284 /* 287 285 * Now that we're holding the lock, check that the vchan 288 286 * really is associated with this pchan before touching the ··· 296 294 if (dcsr & DCSR_DONEB) 297 295 sa11x0_dma_complete(p, c); 298 296 } 299 - spin_unlock_irqrestore(&c->lock, flags); 297 + spin_unlock_irqrestore(&c->vc.lock, flags); 300 298 } 301 299 302 300 return IRQ_HANDLED; ··· 334 332 struct sa11x0_dma_dev *d = (struct sa11x0_dma_dev *)arg; 335 333 struct sa11x0_dma_phy *p; 336 334 struct sa11x0_dma_chan *c; 337 - struct sa11x0_dma_desc *txd, *txn; 338 - LIST_HEAD(head); 339 335 unsigned pch, pch_alloc = 0; 340 336 341 337 dev_dbg(d->slave.dev, "tasklet enter\n"); 342 338 343 - /* Get the completed tx descriptors */ 344 - spin_lock_irq(&d->lock); 345 - list_splice_init(&d->desc_complete, &head); 346 - spin_unlock_irq(&d->lock); 347 - 348 - list_for_each_entry(txd, &head, node) { 349 - c = to_sa11x0_dma_chan(txd->tx.chan); 350 - 351 - dev_dbg(d->slave.dev, "vchan %p: txd %p[%x] completed\n", 352 - c, txd, txd->tx.cookie); 353 - 354 - spin_lock_irq(&c->lock); 339 + list_for_each_entry(c, &d->slave.channels, vc.chan.device_node) { 340 + spin_lock_irq(&c->vc.lock); 355 341 p = c->phy; 356 - if (p) { 357 - if (!p->txd_done) 358 - sa11x0_dma_start_txd(c); 342 + if (p && !p->txd_done) { 343 + sa11x0_dma_start_txd(c); 359 344 if (!p->txd_done) { 360 345 /* No current txd associated with this channel */ 361 346 dev_dbg(d->slave.dev, "pchan %u: free\n", p->num); ··· 352 363 p->vchan = NULL; 353 364 } 354 365 } 355 - spin_unlock_irq(&c->lock); 366 + spin_unlock_irq(&c->vc.lock); 356 367 } 357 368 358 369 spin_lock_irq(&d->lock); ··· 369 380 /* Mark this channel allocated */ 370 381 p->vchan = c; 371 382 372 - dev_dbg(d->slave.dev, "pchan %u: alloc vchan %p\n", pch, c); 383 + dev_dbg(d->slave.dev, "pchan %u: alloc vchan %p\n", pch, &c->vc); 373 384 } 374 385 } 375 386 spin_unlock_irq(&d->lock); ··· 379 390 p = &d->phy[pch]; 380 391 c = p->vchan; 381 392 382 - spin_lock_irq(&c->lock); 393 + spin_lock_irq(&c->vc.lock); 383 394 c->phy = p; 384 395 385 396 sa11x0_dma_start_txd(c); 386 - spin_unlock_irq(&c->lock); 397 + spin_unlock_irq(&c->vc.lock); 387 398 } 388 - } 389 - 390 - /* Now free the completed tx descriptor, and call their callbacks */ 391 - list_for_each_entry_safe(txd, txn, &head, node) { 392 - dma_async_tx_callback callback = txd->tx.callback; 393 - void *callback_param = txd->tx.callback_param; 394 - 395 - dev_dbg(d->slave.dev, "txd %p[%x]: callback and free\n", 396 - txd, txd->tx.cookie); 397 - 398 - kfree(txd); 399 - 400 - if (callback) 401 - callback(callback_param); 402 399 } 403 400 404 401 dev_dbg(d->slave.dev, "tasklet exit\n"); 405 402 } 406 403 407 - 408 - static void sa11x0_dma_desc_free(struct sa11x0_dma_dev *d, struct list_head *head) 409 - { 410 - struct sa11x0_dma_desc *txd, *txn; 411 - 412 - list_for_each_entry_safe(txd, txn, head, node) { 413 - dev_dbg(d->slave.dev, "txd %p: freeing\n", txd); 414 - kfree(txd); 415 - } 416 - } 417 404 418 405 static int sa11x0_dma_alloc_chan_resources(struct dma_chan *chan) 419 406 { ··· 401 436 struct sa11x0_dma_chan *c = to_sa11x0_dma_chan(chan); 402 437 struct sa11x0_dma_dev *d = to_sa11x0_dma(chan->device); 403 438 unsigned long flags; 404 - LIST_HEAD(head); 405 439 406 - spin_lock_irqsave(&c->lock, flags); 407 - spin_lock(&d->lock); 440 + spin_lock_irqsave(&d->lock, flags); 408 441 list_del_init(&c->node); 409 - spin_unlock(&d->lock); 442 + spin_unlock_irqrestore(&d->lock, flags); 410 443 411 - list_splice_tail_init(&c->desc_submitted, &head); 412 - list_splice_tail_init(&c->desc_issued, &head); 413 - spin_unlock_irqrestore(&c->lock, flags); 414 - 415 - sa11x0_dma_desc_free(d, &head); 444 + vchan_free_chan_resources(&c->vc); 416 445 } 417 446 418 447 static dma_addr_t sa11x0_dma_pos(struct sa11x0_dma_phy *p) ··· 431 472 struct sa11x0_dma_chan *c = to_sa11x0_dma_chan(chan); 432 473 struct sa11x0_dma_dev *d = to_sa11x0_dma(chan->device); 433 474 struct sa11x0_dma_phy *p; 434 - struct sa11x0_dma_desc *txd; 435 - dma_cookie_t last_used, last_complete; 475 + struct virt_dma_desc *vd; 436 476 unsigned long flags; 437 477 enum dma_status ret; 438 - size_t bytes = 0; 439 478 440 - last_used = c->chan.cookie; 441 - last_complete = c->lc; 442 - 443 - ret = dma_async_is_complete(cookie, last_complete, last_used); 444 - if (ret == DMA_SUCCESS) { 445 - dma_set_tx_state(state, last_complete, last_used, 0); 479 + ret = dma_cookie_status(&c->vc.chan, cookie, state); 480 + if (ret == DMA_SUCCESS) 446 481 return ret; 447 - } 448 482 449 - spin_lock_irqsave(&c->lock, flags); 483 + if (!state) 484 + return c->status; 485 + 486 + spin_lock_irqsave(&c->vc.lock, flags); 450 487 p = c->phy; 451 - ret = c->status; 452 - if (p) { 453 - dma_addr_t addr = sa11x0_dma_pos(p); 454 488 455 - dev_vdbg(d->slave.dev, "tx_status: addr:%x\n", addr); 489 + /* 490 + * If the cookie is on our issue queue, then the residue is 491 + * its total size. 492 + */ 493 + vd = vchan_find_desc(&c->vc, cookie); 494 + if (vd) { 495 + state->residue = container_of(vd, struct sa11x0_dma_desc, vd)->size; 496 + } else if (!p) { 497 + state->residue = 0; 498 + } else { 499 + struct sa11x0_dma_desc *txd; 500 + size_t bytes = 0; 456 501 457 - txd = p->txd_done; 502 + if (p->txd_done && p->txd_done->vd.tx.cookie == cookie) 503 + txd = p->txd_done; 504 + else if (p->txd_load && p->txd_load->vd.tx.cookie == cookie) 505 + txd = p->txd_load; 506 + else 507 + txd = NULL; 508 + 509 + ret = c->status; 458 510 if (txd) { 511 + dma_addr_t addr = sa11x0_dma_pos(p); 459 512 unsigned i; 513 + 514 + dev_vdbg(d->slave.dev, "tx_status: addr:%x\n", addr); 460 515 461 516 for (i = 0; i < txd->sglen; i++) { 462 517 dev_vdbg(d->slave.dev, "tx_status: [%u] %x+%x\n", ··· 494 521 bytes += txd->sg[i].len; 495 522 } 496 523 } 497 - if (txd != p->txd_load && p->txd_load) 498 - bytes += p->txd_load->size; 524 + state->residue = bytes; 499 525 } 500 - list_for_each_entry(txd, &c->desc_issued, node) { 501 - bytes += txd->size; 502 - } 503 - spin_unlock_irqrestore(&c->lock, flags); 526 + spin_unlock_irqrestore(&c->vc.lock, flags); 504 527 505 - dma_set_tx_state(state, last_complete, last_used, bytes); 506 - 507 - dev_vdbg(d->slave.dev, "tx_status: bytes 0x%zx\n", bytes); 528 + dev_vdbg(d->slave.dev, "tx_status: bytes 0x%zx\n", state->residue); 508 529 509 530 return ret; 510 531 } ··· 514 547 struct sa11x0_dma_dev *d = to_sa11x0_dma(chan->device); 515 548 unsigned long flags; 516 549 517 - spin_lock_irqsave(&c->lock, flags); 518 - list_splice_tail_init(&c->desc_submitted, &c->desc_issued); 519 - if (!list_empty(&c->desc_issued)) { 520 - spin_lock(&d->lock); 521 - if (!c->phy && list_empty(&c->node)) { 522 - list_add_tail(&c->node, &d->chan_pending); 523 - tasklet_schedule(&d->task); 524 - dev_dbg(d->slave.dev, "vchan %p: issued\n", c); 550 + spin_lock_irqsave(&c->vc.lock, flags); 551 + if (vchan_issue_pending(&c->vc)) { 552 + if (!c->phy) { 553 + spin_lock(&d->lock); 554 + if (list_empty(&c->node)) { 555 + list_add_tail(&c->node, &d->chan_pending); 556 + tasklet_schedule(&d->task); 557 + dev_dbg(d->slave.dev, "vchan %p: issued\n", &c->vc); 558 + } 559 + spin_unlock(&d->lock); 525 560 } 526 - spin_unlock(&d->lock); 527 561 } else 528 - dev_dbg(d->slave.dev, "vchan %p: nothing to issue\n", c); 529 - spin_unlock_irqrestore(&c->lock, flags); 530 - } 531 - 532 - static dma_cookie_t sa11x0_dma_tx_submit(struct dma_async_tx_descriptor *tx) 533 - { 534 - struct sa11x0_dma_chan *c = to_sa11x0_dma_chan(tx->chan); 535 - struct sa11x0_dma_desc *txd = to_sa11x0_dma_tx(tx); 536 - unsigned long flags; 537 - 538 - spin_lock_irqsave(&c->lock, flags); 539 - c->chan.cookie += 1; 540 - if (c->chan.cookie < 0) 541 - c->chan.cookie = 1; 542 - txd->tx.cookie = c->chan.cookie; 543 - 544 - list_add_tail(&txd->node, &c->desc_submitted); 545 - spin_unlock_irqrestore(&c->lock, flags); 546 - 547 - dev_dbg(tx->chan->device->dev, "vchan %p: txd %p[%x]: submitted\n", 548 - c, txd, txd->tx.cookie); 549 - 550 - return txd->tx.cookie; 562 + dev_dbg(d->slave.dev, "vchan %p: nothing to issue\n", &c->vc); 563 + spin_unlock_irqrestore(&c->vc.lock, flags); 551 564 } 552 565 553 566 static struct dma_async_tx_descriptor *sa11x0_dma_prep_slave_sg( ··· 543 596 /* SA11x0 channels can only operate in their native direction */ 544 597 if (dir != (c->ddar & DDAR_RW ? DMA_DEV_TO_MEM : DMA_MEM_TO_DEV)) { 545 598 dev_err(chan->device->dev, "vchan %p: bad DMA direction: DDAR:%08x dir:%u\n", 546 - c, c->ddar, dir); 599 + &c->vc, c->ddar, dir); 547 600 return NULL; 548 601 } 549 602 ··· 559 612 j += DIV_ROUND_UP(len, DMA_MAX_SIZE & ~DMA_ALIGN) - 1; 560 613 if (addr & DMA_ALIGN) { 561 614 dev_dbg(chan->device->dev, "vchan %p: bad buffer alignment: %08x\n", 562 - c, addr); 615 + &c->vc, addr); 563 616 return NULL; 564 617 } 565 618 } 566 619 567 620 txd = kzalloc(sizeof(*txd) + j * sizeof(txd->sg[0]), GFP_ATOMIC); 568 621 if (!txd) { 569 - dev_dbg(chan->device->dev, "vchan %p: kzalloc failed\n", c); 622 + dev_dbg(chan->device->dev, "vchan %p: kzalloc failed\n", &c->vc); 570 623 return NULL; 571 624 } 572 625 ··· 602 655 } while (len); 603 656 } 604 657 605 - dma_async_tx_descriptor_init(&txd->tx, &c->chan); 606 - txd->tx.flags = flags; 607 - txd->tx.tx_submit = sa11x0_dma_tx_submit; 608 658 txd->ddar = c->ddar; 609 659 txd->size = size; 610 660 txd->sglen = j; 611 661 612 662 dev_dbg(chan->device->dev, "vchan %p: txd %p: size %u nr %u\n", 613 - c, txd, txd->size, txd->sglen); 663 + &c->vc, &txd->vd, txd->size, txd->sglen); 614 664 615 - return &txd->tx; 665 + return vchan_tx_prep(&c->vc, &txd->vd, flags); 666 + } 667 + 668 + static struct dma_async_tx_descriptor *sa11x0_dma_prep_dma_cyclic( 669 + struct dma_chan *chan, dma_addr_t addr, size_t size, size_t period, 670 + enum dma_transfer_direction dir, void *context) 671 + { 672 + struct sa11x0_dma_chan *c = to_sa11x0_dma_chan(chan); 673 + struct sa11x0_dma_desc *txd; 674 + unsigned i, j, k, sglen, sgperiod; 675 + 676 + /* SA11x0 channels can only operate in their native direction */ 677 + if (dir != (c->ddar & DDAR_RW ? DMA_DEV_TO_MEM : DMA_MEM_TO_DEV)) { 678 + dev_err(chan->device->dev, "vchan %p: bad DMA direction: DDAR:%08x dir:%u\n", 679 + &c->vc, c->ddar, dir); 680 + return NULL; 681 + } 682 + 683 + sgperiod = DIV_ROUND_UP(period, DMA_MAX_SIZE & ~DMA_ALIGN); 684 + sglen = size * sgperiod / period; 685 + 686 + /* Do not allow zero-sized txds */ 687 + if (sglen == 0) 688 + return NULL; 689 + 690 + txd = kzalloc(sizeof(*txd) + sglen * sizeof(txd->sg[0]), GFP_ATOMIC); 691 + if (!txd) { 692 + dev_dbg(chan->device->dev, "vchan %p: kzalloc failed\n", &c->vc); 693 + return NULL; 694 + } 695 + 696 + for (i = k = 0; i < size / period; i++) { 697 + size_t tlen, len = period; 698 + 699 + for (j = 0; j < sgperiod; j++, k++) { 700 + tlen = len; 701 + 702 + if (tlen > DMA_MAX_SIZE) { 703 + unsigned mult = DIV_ROUND_UP(tlen, DMA_MAX_SIZE & ~DMA_ALIGN); 704 + tlen = (tlen / mult) & ~DMA_ALIGN; 705 + } 706 + 707 + txd->sg[k].addr = addr; 708 + txd->sg[k].len = tlen; 709 + addr += tlen; 710 + len -= tlen; 711 + } 712 + 713 + WARN_ON(len != 0); 714 + } 715 + 716 + WARN_ON(k != sglen); 717 + 718 + txd->ddar = c->ddar; 719 + txd->size = size; 720 + txd->sglen = sglen; 721 + txd->cyclic = 1; 722 + txd->period = sgperiod; 723 + 724 + return vchan_tx_prep(&c->vc, &txd->vd, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 616 725 } 617 726 618 727 static int sa11x0_dma_slave_config(struct sa11x0_dma_chan *c, struct dma_slave_config *cfg) ··· 698 695 if (maxburst == 8) 699 696 ddar |= DDAR_BS; 700 697 701 - dev_dbg(c->chan.device->dev, "vchan %p: dma_slave_config addr %x width %u burst %u\n", 702 - c, addr, width, maxburst); 698 + dev_dbg(c->vc.chan.device->dev, "vchan %p: dma_slave_config addr %x width %u burst %u\n", 699 + &c->vc, addr, width, maxburst); 703 700 704 701 c->ddar = ddar | (addr & 0xf0000000) | (addr & 0x003ffffc) << 6; 705 702 ··· 721 718 return sa11x0_dma_slave_config(c, (struct dma_slave_config *)arg); 722 719 723 720 case DMA_TERMINATE_ALL: 724 - dev_dbg(d->slave.dev, "vchan %p: terminate all\n", c); 721 + dev_dbg(d->slave.dev, "vchan %p: terminate all\n", &c->vc); 725 722 /* Clear the tx descriptor lists */ 726 - spin_lock_irqsave(&c->lock, flags); 727 - list_splice_tail_init(&c->desc_submitted, &head); 728 - list_splice_tail_init(&c->desc_issued, &head); 723 + spin_lock_irqsave(&c->vc.lock, flags); 724 + vchan_get_all_descriptors(&c->vc, &head); 729 725 730 726 p = c->phy; 731 727 if (p) { 732 - struct sa11x0_dma_desc *txd, *txn; 733 - 734 728 dev_dbg(d->slave.dev, "pchan %u: terminating\n", p->num); 735 729 /* vchan is assigned to a pchan - stop the channel */ 736 730 writel(DCSR_RUN | DCSR_IE | ··· 735 735 DCSR_STRTB | DCSR_DONEB, 736 736 p->base + DMA_DCSR_C); 737 737 738 - list_for_each_entry_safe(txd, txn, &d->desc_complete, node) 739 - if (txd->tx.chan == &c->chan) 740 - list_move(&txd->node, &head); 741 - 742 738 if (p->txd_load) { 743 739 if (p->txd_load != p->txd_done) 744 - list_add_tail(&p->txd_load->node, &head); 740 + list_add_tail(&p->txd_load->vd.node, &head); 745 741 p->txd_load = NULL; 746 742 } 747 743 if (p->txd_done) { 748 - list_add_tail(&p->txd_done->node, &head); 744 + list_add_tail(&p->txd_done->vd.node, &head); 749 745 p->txd_done = NULL; 750 746 } 751 747 c->phy = NULL; ··· 750 754 spin_unlock(&d->lock); 751 755 tasklet_schedule(&d->task); 752 756 } 753 - spin_unlock_irqrestore(&c->lock, flags); 754 - sa11x0_dma_desc_free(d, &head); 757 + spin_unlock_irqrestore(&c->vc.lock, flags); 758 + vchan_dma_desc_free_list(&c->vc, &head); 755 759 ret = 0; 756 760 break; 757 761 758 762 case DMA_PAUSE: 759 - dev_dbg(d->slave.dev, "vchan %p: pause\n", c); 760 - spin_lock_irqsave(&c->lock, flags); 763 + dev_dbg(d->slave.dev, "vchan %p: pause\n", &c->vc); 764 + spin_lock_irqsave(&c->vc.lock, flags); 761 765 if (c->status == DMA_IN_PROGRESS) { 762 766 c->status = DMA_PAUSED; 763 767 ··· 770 774 spin_unlock(&d->lock); 771 775 } 772 776 } 773 - spin_unlock_irqrestore(&c->lock, flags); 777 + spin_unlock_irqrestore(&c->vc.lock, flags); 774 778 ret = 0; 775 779 break; 776 780 777 781 case DMA_RESUME: 778 - dev_dbg(d->slave.dev, "vchan %p: resume\n", c); 779 - spin_lock_irqsave(&c->lock, flags); 782 + dev_dbg(d->slave.dev, "vchan %p: resume\n", &c->vc); 783 + spin_lock_irqsave(&c->vc.lock, flags); 780 784 if (c->status == DMA_PAUSED) { 781 785 c->status = DMA_IN_PROGRESS; 782 786 783 787 p = c->phy; 784 788 if (p) { 785 789 writel(DCSR_RUN | DCSR_IE, p->base + DMA_DCSR_S); 786 - } else if (!list_empty(&c->desc_issued)) { 790 + } else if (!list_empty(&c->vc.desc_issued)) { 787 791 spin_lock(&d->lock); 788 792 list_add_tail(&c->node, &d->chan_pending); 789 793 spin_unlock(&d->lock); 790 794 } 791 795 } 792 - spin_unlock_irqrestore(&c->lock, flags); 796 + spin_unlock_irqrestore(&c->vc.lock, flags); 793 797 ret = 0; 794 798 break; 795 799 ··· 849 853 return -ENOMEM; 850 854 } 851 855 852 - c->chan.device = dmadev; 853 856 c->status = DMA_IN_PROGRESS; 854 857 c->ddar = chan_desc[i].ddar; 855 858 c->name = chan_desc[i].name; 856 - spin_lock_init(&c->lock); 857 - INIT_LIST_HEAD(&c->desc_submitted); 858 - INIT_LIST_HEAD(&c->desc_issued); 859 859 INIT_LIST_HEAD(&c->node); 860 - list_add_tail(&c->chan.device_node, &dmadev->channels); 860 + 861 + c->vc.desc_free = sa11x0_dma_free_desc; 862 + vchan_init(&c->vc, dmadev); 861 863 } 862 864 863 865 return dma_async_device_register(dmadev); ··· 884 890 { 885 891 struct sa11x0_dma_chan *c, *cn; 886 892 887 - list_for_each_entry_safe(c, cn, &dmadev->channels, chan.device_node) { 888 - list_del(&c->chan.device_node); 893 + list_for_each_entry_safe(c, cn, &dmadev->channels, vc.chan.device_node) { 894 + list_del(&c->vc.chan.device_node); 895 + tasklet_kill(&c->vc.task); 889 896 kfree(c); 890 897 } 891 898 } ··· 910 915 911 916 spin_lock_init(&d->lock); 912 917 INIT_LIST_HEAD(&d->chan_pending); 913 - INIT_LIST_HEAD(&d->desc_complete); 914 918 915 919 d->base = ioremap(res->start, resource_size(res)); 916 920 if (!d->base) { ··· 941 947 } 942 948 943 949 dma_cap_set(DMA_SLAVE, d->slave.cap_mask); 950 + dma_cap_set(DMA_CYCLIC, d->slave.cap_mask); 944 951 d->slave.device_prep_slave_sg = sa11x0_dma_prep_slave_sg; 952 + d->slave.device_prep_dma_cyclic = sa11x0_dma_prep_dma_cyclic; 945 953 ret = sa11x0_dma_init_dmadev(&d->slave, &pdev->dev); 946 954 if (ret) { 947 955 dev_warn(d->slave.dev, "failed to register slave async device: %d\n",
+123
drivers/dma/virt-dma.c
··· 1 + /* 2 + * Virtual DMA channel support for DMAengine 3 + * 4 + * Copyright (C) 2012 Russell King 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + */ 10 + #include <linux/device.h> 11 + #include <linux/dmaengine.h> 12 + #include <linux/module.h> 13 + #include <linux/spinlock.h> 14 + 15 + #include "virt-dma.h" 16 + 17 + static struct virt_dma_desc *to_virt_desc(struct dma_async_tx_descriptor *tx) 18 + { 19 + return container_of(tx, struct virt_dma_desc, tx); 20 + } 21 + 22 + dma_cookie_t vchan_tx_submit(struct dma_async_tx_descriptor *tx) 23 + { 24 + struct virt_dma_chan *vc = to_virt_chan(tx->chan); 25 + struct virt_dma_desc *vd = to_virt_desc(tx); 26 + unsigned long flags; 27 + dma_cookie_t cookie; 28 + 29 + spin_lock_irqsave(&vc->lock, flags); 30 + cookie = dma_cookie_assign(tx); 31 + 32 + list_add_tail(&vd->node, &vc->desc_submitted); 33 + spin_unlock_irqrestore(&vc->lock, flags); 34 + 35 + dev_dbg(vc->chan.device->dev, "vchan %p: txd %p[%x]: submitted\n", 36 + vc, vd, cookie); 37 + 38 + return cookie; 39 + } 40 + EXPORT_SYMBOL_GPL(vchan_tx_submit); 41 + 42 + struct virt_dma_desc *vchan_find_desc(struct virt_dma_chan *vc, 43 + dma_cookie_t cookie) 44 + { 45 + struct virt_dma_desc *vd; 46 + 47 + list_for_each_entry(vd, &vc->desc_issued, node) 48 + if (vd->tx.cookie == cookie) 49 + return vd; 50 + 51 + return NULL; 52 + } 53 + EXPORT_SYMBOL_GPL(vchan_find_desc); 54 + 55 + /* 56 + * This tasklet handles the completion of a DMA descriptor by 57 + * calling its callback and freeing it. 58 + */ 59 + static void vchan_complete(unsigned long arg) 60 + { 61 + struct virt_dma_chan *vc = (struct virt_dma_chan *)arg; 62 + struct virt_dma_desc *vd; 63 + dma_async_tx_callback cb = NULL; 64 + void *cb_data = NULL; 65 + LIST_HEAD(head); 66 + 67 + spin_lock_irq(&vc->lock); 68 + list_splice_tail_init(&vc->desc_completed, &head); 69 + vd = vc->cyclic; 70 + if (vd) { 71 + vc->cyclic = NULL; 72 + cb = vd->tx.callback; 73 + cb_data = vd->tx.callback_param; 74 + } 75 + spin_unlock_irq(&vc->lock); 76 + 77 + if (cb) 78 + cb(cb_data); 79 + 80 + while (!list_empty(&head)) { 81 + vd = list_first_entry(&head, struct virt_dma_desc, node); 82 + cb = vd->tx.callback; 83 + cb_data = vd->tx.callback_param; 84 + 85 + list_del(&vd->node); 86 + 87 + vc->desc_free(vd); 88 + 89 + if (cb) 90 + cb(cb_data); 91 + } 92 + } 93 + 94 + void vchan_dma_desc_free_list(struct virt_dma_chan *vc, struct list_head *head) 95 + { 96 + while (!list_empty(head)) { 97 + struct virt_dma_desc *vd = list_first_entry(head, 98 + struct virt_dma_desc, node); 99 + list_del(&vd->node); 100 + dev_dbg(vc->chan.device->dev, "txd %p: freeing\n", vd); 101 + vc->desc_free(vd); 102 + } 103 + } 104 + EXPORT_SYMBOL_GPL(vchan_dma_desc_free_list); 105 + 106 + void vchan_init(struct virt_dma_chan *vc, struct dma_device *dmadev) 107 + { 108 + dma_cookie_init(&vc->chan); 109 + 110 + spin_lock_init(&vc->lock); 111 + INIT_LIST_HEAD(&vc->desc_submitted); 112 + INIT_LIST_HEAD(&vc->desc_issued); 113 + INIT_LIST_HEAD(&vc->desc_completed); 114 + 115 + tasklet_init(&vc->task, vchan_complete, (unsigned long)vc); 116 + 117 + vc->chan.device = dmadev; 118 + list_add_tail(&vc->chan.device_node, &dmadev->channels); 119 + } 120 + EXPORT_SYMBOL_GPL(vchan_init); 121 + 122 + MODULE_AUTHOR("Russell King"); 123 + MODULE_LICENSE("GPL");
+152
drivers/dma/virt-dma.h
··· 1 + /* 2 + * Virtual DMA channel support for DMAengine 3 + * 4 + * Copyright (C) 2012 Russell King 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + */ 10 + #ifndef VIRT_DMA_H 11 + #define VIRT_DMA_H 12 + 13 + #include <linux/dmaengine.h> 14 + #include <linux/interrupt.h> 15 + 16 + #include "dmaengine.h" 17 + 18 + struct virt_dma_desc { 19 + struct dma_async_tx_descriptor tx; 20 + /* protected by vc.lock */ 21 + struct list_head node; 22 + }; 23 + 24 + struct virt_dma_chan { 25 + struct dma_chan chan; 26 + struct tasklet_struct task; 27 + void (*desc_free)(struct virt_dma_desc *); 28 + 29 + spinlock_t lock; 30 + 31 + /* protected by vc.lock */ 32 + struct list_head desc_submitted; 33 + struct list_head desc_issued; 34 + struct list_head desc_completed; 35 + 36 + struct virt_dma_desc *cyclic; 37 + }; 38 + 39 + static inline struct virt_dma_chan *to_virt_chan(struct dma_chan *chan) 40 + { 41 + return container_of(chan, struct virt_dma_chan, chan); 42 + } 43 + 44 + void vchan_dma_desc_free_list(struct virt_dma_chan *vc, struct list_head *head); 45 + void vchan_init(struct virt_dma_chan *vc, struct dma_device *dmadev); 46 + struct virt_dma_desc *vchan_find_desc(struct virt_dma_chan *, dma_cookie_t); 47 + 48 + /** 49 + * vchan_tx_prep - prepare a descriptor 50 + * vc: virtual channel allocating this descriptor 51 + * vd: virtual descriptor to prepare 52 + * tx_flags: flags argument passed in to prepare function 53 + */ 54 + static inline struct dma_async_tx_descriptor *vchan_tx_prep(struct virt_dma_chan *vc, 55 + struct virt_dma_desc *vd, unsigned long tx_flags) 56 + { 57 + extern dma_cookie_t vchan_tx_submit(struct dma_async_tx_descriptor *); 58 + 59 + dma_async_tx_descriptor_init(&vd->tx, &vc->chan); 60 + vd->tx.flags = tx_flags; 61 + vd->tx.tx_submit = vchan_tx_submit; 62 + 63 + return &vd->tx; 64 + } 65 + 66 + /** 67 + * vchan_issue_pending - move submitted descriptors to issued list 68 + * vc: virtual channel to update 69 + * 70 + * vc.lock must be held by caller 71 + */ 72 + static inline bool vchan_issue_pending(struct virt_dma_chan *vc) 73 + { 74 + list_splice_tail_init(&vc->desc_submitted, &vc->desc_issued); 75 + return !list_empty(&vc->desc_issued); 76 + } 77 + 78 + /** 79 + * vchan_cookie_complete - report completion of a descriptor 80 + * vd: virtual descriptor to update 81 + * 82 + * vc.lock must be held by caller 83 + */ 84 + static inline void vchan_cookie_complete(struct virt_dma_desc *vd) 85 + { 86 + struct virt_dma_chan *vc = to_virt_chan(vd->tx.chan); 87 + 88 + dma_cookie_complete(&vd->tx); 89 + dev_vdbg(vc->chan.device->dev, "txd %p[%x]: marked complete\n", 90 + vd, vd->tx.cookie); 91 + list_add_tail(&vd->node, &vc->desc_completed); 92 + 93 + tasklet_schedule(&vc->task); 94 + } 95 + 96 + /** 97 + * vchan_cyclic_callback - report the completion of a period 98 + * vd: virtual descriptor 99 + */ 100 + static inline void vchan_cyclic_callback(struct virt_dma_desc *vd) 101 + { 102 + struct virt_dma_chan *vc = to_virt_chan(vd->tx.chan); 103 + 104 + vc->cyclic = vd; 105 + tasklet_schedule(&vc->task); 106 + } 107 + 108 + /** 109 + * vchan_next_desc - peek at the next descriptor to be processed 110 + * vc: virtual channel to obtain descriptor from 111 + * 112 + * vc.lock must be held by caller 113 + */ 114 + static inline struct virt_dma_desc *vchan_next_desc(struct virt_dma_chan *vc) 115 + { 116 + if (list_empty(&vc->desc_issued)) 117 + return NULL; 118 + 119 + return list_first_entry(&vc->desc_issued, struct virt_dma_desc, node); 120 + } 121 + 122 + /** 123 + * vchan_get_all_descriptors - obtain all submitted and issued descriptors 124 + * vc: virtual channel to get descriptors from 125 + * head: list of descriptors found 126 + * 127 + * vc.lock must be held by caller 128 + * 129 + * Removes all submitted and issued descriptors from internal lists, and 130 + * provides a list of all descriptors found 131 + */ 132 + static inline void vchan_get_all_descriptors(struct virt_dma_chan *vc, 133 + struct list_head *head) 134 + { 135 + list_splice_tail_init(&vc->desc_submitted, head); 136 + list_splice_tail_init(&vc->desc_issued, head); 137 + list_splice_tail_init(&vc->desc_completed, head); 138 + } 139 + 140 + static inline void vchan_free_chan_resources(struct virt_dma_chan *vc) 141 + { 142 + unsigned long flags; 143 + LIST_HEAD(head); 144 + 145 + spin_lock_irqsave(&vc->lock, flags); 146 + vchan_get_all_descriptors(vc, &head); 147 + spin_unlock_irqrestore(&vc->lock, flags); 148 + 149 + vchan_dma_desc_free_list(vc, &head); 150 + } 151 + 152 + #endif
+160 -204
drivers/mmc/host/omap.c
··· 17 17 #include <linux/ioport.h> 18 18 #include <linux/platform_device.h> 19 19 #include <linux/interrupt.h> 20 + #include <linux/dmaengine.h> 20 21 #include <linux/dma-mapping.h> 21 22 #include <linux/delay.h> 22 23 #include <linux/spinlock.h> 23 24 #include <linux/timer.h> 25 + #include <linux/omap-dma.h> 24 26 #include <linux/mmc/host.h> 25 27 #include <linux/mmc/card.h> 26 28 #include <linux/clk.h> ··· 130 128 unsigned char id; /* 16xx chips have 2 MMC blocks */ 131 129 struct clk * iclk; 132 130 struct clk * fclk; 131 + struct dma_chan *dma_rx; 132 + u32 dma_rx_burst; 133 + struct dma_chan *dma_tx; 134 + u32 dma_tx_burst; 133 135 struct resource *mem_res; 134 136 void __iomem *virt_base; 135 137 unsigned int phys_base; ··· 159 153 160 154 unsigned use_dma:1; 161 155 unsigned brs_received:1, dma_done:1; 162 - unsigned dma_is_read:1; 163 156 unsigned dma_in_use:1; 164 - int dma_ch; 165 157 spinlock_t dma_lock; 166 - struct timer_list dma_timer; 167 - unsigned dma_len; 168 158 169 159 struct mmc_omap_slot *slots[OMAP_MMC_MAX_SLOTS]; 170 160 struct mmc_omap_slot *current_slot; ··· 408 406 int abort) 409 407 { 410 408 enum dma_data_direction dma_data_dir; 409 + struct device *dev = mmc_dev(host->mmc); 410 + struct dma_chan *c; 411 411 412 - BUG_ON(host->dma_ch < 0); 413 - if (data->error) 414 - omap_stop_dma(host->dma_ch); 415 - /* Release DMA channel lazily */ 416 - mod_timer(&host->dma_timer, jiffies + HZ); 417 - if (data->flags & MMC_DATA_WRITE) 412 + if (data->flags & MMC_DATA_WRITE) { 418 413 dma_data_dir = DMA_TO_DEVICE; 419 - else 414 + c = host->dma_tx; 415 + } else { 420 416 dma_data_dir = DMA_FROM_DEVICE; 421 - dma_unmap_sg(mmc_dev(host->mmc), data->sg, host->sg_len, 422 - dma_data_dir); 417 + c = host->dma_rx; 418 + } 419 + if (c) { 420 + if (data->error) { 421 + dmaengine_terminate_all(c); 422 + /* Claim nothing transferred on error... */ 423 + data->bytes_xfered = 0; 424 + } 425 + dev = c->device->dev; 426 + } 427 + dma_unmap_sg(dev, data->sg, host->sg_len, dma_data_dir); 423 428 } 424 429 425 430 static void mmc_omap_send_stop_work(struct work_struct *work) ··· 531 522 spin_unlock_irqrestore(&host->dma_lock, flags); 532 523 if (done) 533 524 mmc_omap_xfer_done(host, data); 534 - } 535 - 536 - static void 537 - mmc_omap_dma_timer(unsigned long data) 538 - { 539 - struct mmc_omap_host *host = (struct mmc_omap_host *) data; 540 - 541 - BUG_ON(host->dma_ch < 0); 542 - omap_free_dma(host->dma_ch); 543 - host->dma_ch = -1; 544 525 } 545 526 546 527 static void ··· 890 891 jiffies + msecs_to_jiffies(OMAP_MMC_COVER_POLL_DELAY)); 891 892 } 892 893 893 - /* Prepare to transfer the next segment of a scatterlist */ 894 - static void 895 - mmc_omap_prepare_dma(struct mmc_omap_host *host, struct mmc_data *data) 894 + static void mmc_omap_dma_callback(void *priv) 896 895 { 897 - int dma_ch = host->dma_ch; 898 - unsigned long data_addr; 899 - u16 buf, frame; 900 - u32 count; 901 - struct scatterlist *sg = &data->sg[host->sg_idx]; 902 - int src_port = 0; 903 - int dst_port = 0; 904 - int sync_dev = 0; 896 + struct mmc_omap_host *host = priv; 897 + struct mmc_data *data = host->data; 905 898 906 - data_addr = host->phys_base + OMAP_MMC_REG(host, DATA); 907 - frame = data->blksz; 908 - count = sg_dma_len(sg); 899 + /* If we got to the end of DMA, assume everything went well */ 900 + data->bytes_xfered += data->blocks * data->blksz; 909 901 910 - if ((data->blocks == 1) && (count > data->blksz)) 911 - count = frame; 912 - 913 - host->dma_len = count; 914 - 915 - /* FIFO is 16x2 bytes on 15xx, and 32x2 bytes on 16xx and 24xx. 916 - * Use 16 or 32 word frames when the blocksize is at least that large. 917 - * Blocksize is usually 512 bytes; but not for some SD reads. 918 - */ 919 - if (cpu_is_omap15xx() && frame > 32) 920 - frame = 32; 921 - else if (frame > 64) 922 - frame = 64; 923 - count /= frame; 924 - frame >>= 1; 925 - 926 - if (!(data->flags & MMC_DATA_WRITE)) { 927 - buf = 0x800f | ((frame - 1) << 8); 928 - 929 - if (cpu_class_is_omap1()) { 930 - src_port = OMAP_DMA_PORT_TIPB; 931 - dst_port = OMAP_DMA_PORT_EMIFF; 932 - } 933 - if (cpu_is_omap24xx()) 934 - sync_dev = OMAP24XX_DMA_MMC1_RX; 935 - 936 - omap_set_dma_src_params(dma_ch, src_port, 937 - OMAP_DMA_AMODE_CONSTANT, 938 - data_addr, 0, 0); 939 - omap_set_dma_dest_params(dma_ch, dst_port, 940 - OMAP_DMA_AMODE_POST_INC, 941 - sg_dma_address(sg), 0, 0); 942 - omap_set_dma_dest_data_pack(dma_ch, 1); 943 - omap_set_dma_dest_burst_mode(dma_ch, OMAP_DMA_DATA_BURST_4); 944 - } else { 945 - buf = 0x0f80 | ((frame - 1) << 0); 946 - 947 - if (cpu_class_is_omap1()) { 948 - src_port = OMAP_DMA_PORT_EMIFF; 949 - dst_port = OMAP_DMA_PORT_TIPB; 950 - } 951 - if (cpu_is_omap24xx()) 952 - sync_dev = OMAP24XX_DMA_MMC1_TX; 953 - 954 - omap_set_dma_dest_params(dma_ch, dst_port, 955 - OMAP_DMA_AMODE_CONSTANT, 956 - data_addr, 0, 0); 957 - omap_set_dma_src_params(dma_ch, src_port, 958 - OMAP_DMA_AMODE_POST_INC, 959 - sg_dma_address(sg), 0, 0); 960 - omap_set_dma_src_data_pack(dma_ch, 1); 961 - omap_set_dma_src_burst_mode(dma_ch, OMAP_DMA_DATA_BURST_4); 962 - } 963 - 964 - /* Max limit for DMA frame count is 0xffff */ 965 - BUG_ON(count > 0xffff); 966 - 967 - OMAP_MMC_WRITE(host, BUF, buf); 968 - omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S16, 969 - frame, count, OMAP_DMA_SYNC_FRAME, 970 - sync_dev, 0); 971 - } 972 - 973 - /* A scatterlist segment completed */ 974 - static void mmc_omap_dma_cb(int lch, u16 ch_status, void *data) 975 - { 976 - struct mmc_omap_host *host = (struct mmc_omap_host *) data; 977 - struct mmc_data *mmcdat = host->data; 978 - 979 - if (unlikely(host->dma_ch < 0)) { 980 - dev_err(mmc_dev(host->mmc), 981 - "DMA callback while DMA not enabled\n"); 982 - return; 983 - } 984 - /* FIXME: We really should do something to _handle_ the errors */ 985 - if (ch_status & OMAP1_DMA_TOUT_IRQ) { 986 - dev_err(mmc_dev(host->mmc),"DMA timeout\n"); 987 - return; 988 - } 989 - if (ch_status & OMAP_DMA_DROP_IRQ) { 990 - dev_err(mmc_dev(host->mmc), "DMA sync error\n"); 991 - return; 992 - } 993 - if (!(ch_status & OMAP_DMA_BLOCK_IRQ)) { 994 - return; 995 - } 996 - mmcdat->bytes_xfered += host->dma_len; 997 - host->sg_idx++; 998 - if (host->sg_idx < host->sg_len) { 999 - mmc_omap_prepare_dma(host, host->data); 1000 - omap_start_dma(host->dma_ch); 1001 - } else 1002 - mmc_omap_dma_done(host, host->data); 1003 - } 1004 - 1005 - static int mmc_omap_get_dma_channel(struct mmc_omap_host *host, struct mmc_data *data) 1006 - { 1007 - const char *dma_dev_name; 1008 - int sync_dev, dma_ch, is_read, r; 1009 - 1010 - is_read = !(data->flags & MMC_DATA_WRITE); 1011 - del_timer_sync(&host->dma_timer); 1012 - if (host->dma_ch >= 0) { 1013 - if (is_read == host->dma_is_read) 1014 - return 0; 1015 - omap_free_dma(host->dma_ch); 1016 - host->dma_ch = -1; 1017 - } 1018 - 1019 - if (is_read) { 1020 - if (host->id == 0) { 1021 - sync_dev = OMAP_DMA_MMC_RX; 1022 - dma_dev_name = "MMC1 read"; 1023 - } else { 1024 - sync_dev = OMAP_DMA_MMC2_RX; 1025 - dma_dev_name = "MMC2 read"; 1026 - } 1027 - } else { 1028 - if (host->id == 0) { 1029 - sync_dev = OMAP_DMA_MMC_TX; 1030 - dma_dev_name = "MMC1 write"; 1031 - } else { 1032 - sync_dev = OMAP_DMA_MMC2_TX; 1033 - dma_dev_name = "MMC2 write"; 1034 - } 1035 - } 1036 - r = omap_request_dma(sync_dev, dma_dev_name, mmc_omap_dma_cb, 1037 - host, &dma_ch); 1038 - if (r != 0) { 1039 - dev_dbg(mmc_dev(host->mmc), "omap_request_dma() failed with %d\n", r); 1040 - return r; 1041 - } 1042 - host->dma_ch = dma_ch; 1043 - host->dma_is_read = is_read; 1044 - 1045 - return 0; 902 + mmc_omap_dma_done(host, data); 1046 903 } 1047 904 1048 905 static inline void set_cmd_timeout(struct mmc_omap_host *host, struct mmc_request *req) ··· 973 1118 974 1119 host->sg_idx = 0; 975 1120 if (use_dma) { 976 - if (mmc_omap_get_dma_channel(host, data) == 0) { 977 - enum dma_data_direction dma_data_dir; 1121 + enum dma_data_direction dma_data_dir; 1122 + struct dma_async_tx_descriptor *tx; 1123 + struct dma_chan *c; 1124 + u32 burst, *bp; 1125 + u16 buf; 978 1126 979 - if (data->flags & MMC_DATA_WRITE) 980 - dma_data_dir = DMA_TO_DEVICE; 981 - else 982 - dma_data_dir = DMA_FROM_DEVICE; 1127 + /* 1128 + * FIFO is 16x2 bytes on 15xx, and 32x2 bytes on 16xx 1129 + * and 24xx. Use 16 or 32 word frames when the 1130 + * blocksize is at least that large. Blocksize is 1131 + * usually 512 bytes; but not for some SD reads. 1132 + */ 1133 + burst = cpu_is_omap15xx() ? 32 : 64; 1134 + if (burst > data->blksz) 1135 + burst = data->blksz; 983 1136 984 - host->sg_len = dma_map_sg(mmc_dev(host->mmc), data->sg, 985 - sg_len, dma_data_dir); 986 - host->total_bytes_left = 0; 987 - mmc_omap_prepare_dma(host, req->data); 988 - host->brs_received = 0; 989 - host->dma_done = 0; 990 - host->dma_in_use = 1; 991 - } else 992 - use_dma = 0; 1137 + burst >>= 1; 1138 + 1139 + if (data->flags & MMC_DATA_WRITE) { 1140 + c = host->dma_tx; 1141 + bp = &host->dma_tx_burst; 1142 + buf = 0x0f80 | (burst - 1) << 0; 1143 + dma_data_dir = DMA_TO_DEVICE; 1144 + } else { 1145 + c = host->dma_rx; 1146 + bp = &host->dma_rx_burst; 1147 + buf = 0x800f | (burst - 1) << 8; 1148 + dma_data_dir = DMA_FROM_DEVICE; 1149 + } 1150 + 1151 + if (!c) 1152 + goto use_pio; 1153 + 1154 + /* Only reconfigure if we have a different burst size */ 1155 + if (*bp != burst) { 1156 + struct dma_slave_config cfg; 1157 + 1158 + cfg.src_addr = host->phys_base + OMAP_MMC_REG(host, DATA); 1159 + cfg.dst_addr = host->phys_base + OMAP_MMC_REG(host, DATA); 1160 + cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; 1161 + cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; 1162 + cfg.src_maxburst = burst; 1163 + cfg.dst_maxburst = burst; 1164 + 1165 + if (dmaengine_slave_config(c, &cfg)) 1166 + goto use_pio; 1167 + 1168 + *bp = burst; 1169 + } 1170 + 1171 + host->sg_len = dma_map_sg(c->device->dev, data->sg, sg_len, 1172 + dma_data_dir); 1173 + if (host->sg_len == 0) 1174 + goto use_pio; 1175 + 1176 + tx = dmaengine_prep_slave_sg(c, data->sg, host->sg_len, 1177 + data->flags & MMC_DATA_WRITE ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, 1178 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 1179 + if (!tx) 1180 + goto use_pio; 1181 + 1182 + OMAP_MMC_WRITE(host, BUF, buf); 1183 + 1184 + tx->callback = mmc_omap_dma_callback; 1185 + tx->callback_param = host; 1186 + dmaengine_submit(tx); 1187 + host->brs_received = 0; 1188 + host->dma_done = 0; 1189 + host->dma_in_use = 1; 1190 + return; 993 1191 } 1192 + use_pio: 994 1193 995 1194 /* Revert to PIO? */ 996 - if (!use_dma) { 997 - OMAP_MMC_WRITE(host, BUF, 0x1f1f); 998 - host->total_bytes_left = data->blocks * block_size; 999 - host->sg_len = sg_len; 1000 - mmc_omap_sg_to_buf(host); 1001 - host->dma_in_use = 0; 1002 - } 1195 + OMAP_MMC_WRITE(host, BUF, 0x1f1f); 1196 + host->total_bytes_left = data->blocks * block_size; 1197 + host->sg_len = sg_len; 1198 + mmc_omap_sg_to_buf(host); 1199 + host->dma_in_use = 0; 1003 1200 } 1004 1201 1005 1202 static void mmc_omap_start_request(struct mmc_omap_host *host, ··· 1064 1157 /* only touch fifo AFTER the controller readies it */ 1065 1158 mmc_omap_prepare_data(host, req); 1066 1159 mmc_omap_start_command(host, req->cmd); 1067 - if (host->dma_in_use) 1068 - omap_start_dma(host->dma_ch); 1160 + if (host->dma_in_use) { 1161 + struct dma_chan *c = host->data->flags & MMC_DATA_WRITE ? 1162 + host->dma_tx : host->dma_rx; 1163 + 1164 + dma_async_issue_pending(c); 1165 + } 1069 1166 } 1070 1167 1071 1168 static void mmc_omap_request(struct mmc_host *mmc, struct mmc_request *req) ··· 1311 1400 struct omap_mmc_platform_data *pdata = pdev->dev.platform_data; 1312 1401 struct mmc_omap_host *host = NULL; 1313 1402 struct resource *res; 1403 + dma_cap_mask_t mask; 1404 + unsigned sig; 1314 1405 int i, ret = 0; 1315 1406 int irq; 1316 1407 ··· 1352 1439 setup_timer(&host->clk_timer, mmc_omap_clk_timer, (unsigned long) host); 1353 1440 1354 1441 spin_lock_init(&host->dma_lock); 1355 - setup_timer(&host->dma_timer, mmc_omap_dma_timer, (unsigned long) host); 1356 1442 spin_lock_init(&host->slot_lock); 1357 1443 init_waitqueue_head(&host->slot_wq); 1358 1444 ··· 1362 1450 host->id = pdev->id; 1363 1451 host->mem_res = res; 1364 1452 host->irq = irq; 1365 - 1366 1453 host->use_dma = 1; 1367 - host->dev->dma_mask = &pdata->dma_mask; 1368 - host->dma_ch = -1; 1369 - 1370 1454 host->irq = irq; 1371 1455 host->phys_base = host->mem_res->start; 1372 1456 host->virt_base = ioremap(res->start, resource_size(res)); ··· 1382 1474 goto err_free_iclk; 1383 1475 } 1384 1476 1477 + dma_cap_zero(mask); 1478 + dma_cap_set(DMA_SLAVE, mask); 1479 + 1480 + host->dma_tx_burst = -1; 1481 + host->dma_rx_burst = -1; 1482 + 1483 + if (cpu_is_omap24xx()) 1484 + sig = host->id == 0 ? OMAP24XX_DMA_MMC1_TX : OMAP24XX_DMA_MMC2_TX; 1485 + else 1486 + sig = host->id == 0 ? OMAP_DMA_MMC_TX : OMAP_DMA_MMC2_TX; 1487 + host->dma_tx = dma_request_channel(mask, omap_dma_filter_fn, &sig); 1488 + #if 0 1489 + if (!host->dma_tx) { 1490 + dev_err(host->dev, "unable to obtain TX DMA engine channel %u\n", 1491 + sig); 1492 + goto err_dma; 1493 + } 1494 + #else 1495 + if (!host->dma_tx) 1496 + dev_warn(host->dev, "unable to obtain TX DMA engine channel %u\n", 1497 + sig); 1498 + #endif 1499 + if (cpu_is_omap24xx()) 1500 + sig = host->id == 0 ? OMAP24XX_DMA_MMC1_RX : OMAP24XX_DMA_MMC2_RX; 1501 + else 1502 + sig = host->id == 0 ? OMAP_DMA_MMC_RX : OMAP_DMA_MMC2_RX; 1503 + host->dma_rx = dma_request_channel(mask, omap_dma_filter_fn, &sig); 1504 + #if 0 1505 + if (!host->dma_rx) { 1506 + dev_err(host->dev, "unable to obtain RX DMA engine channel %u\n", 1507 + sig); 1508 + goto err_dma; 1509 + } 1510 + #else 1511 + if (!host->dma_rx) 1512 + dev_warn(host->dev, "unable to obtain RX DMA engine channel %u\n", 1513 + sig); 1514 + #endif 1515 + 1385 1516 ret = request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host); 1386 1517 if (ret) 1387 - goto err_free_fclk; 1518 + goto err_free_dma; 1388 1519 1389 1520 if (pdata->init != NULL) { 1390 1521 ret = pdata->init(&pdev->dev); ··· 1457 1510 pdata->cleanup(&pdev->dev); 1458 1511 err_free_irq: 1459 1512 free_irq(host->irq, host); 1460 - err_free_fclk: 1513 + err_free_dma: 1514 + if (host->dma_tx) 1515 + dma_release_channel(host->dma_tx); 1516 + if (host->dma_rx) 1517 + dma_release_channel(host->dma_rx); 1461 1518 clk_put(host->fclk); 1462 1519 err_free_iclk: 1463 1520 clk_disable(host->iclk); ··· 1495 1544 clk_put(host->fclk); 1496 1545 clk_disable(host->iclk); 1497 1546 clk_put(host->iclk); 1547 + 1548 + if (host->dma_tx) 1549 + dma_release_channel(host->dma_tx); 1550 + if (host->dma_rx) 1551 + dma_release_channel(host->dma_rx); 1498 1552 1499 1553 iounmap(host->virt_base); 1500 1554 release_mem_region(pdev->resource[0].start,
+104 -102
drivers/mmc/host/omap_hsmmc.c
··· 19 19 #include <linux/init.h> 20 20 #include <linux/kernel.h> 21 21 #include <linux/debugfs.h> 22 + #include <linux/dmaengine.h> 22 23 #include <linux/seq_file.h> 23 24 #include <linux/interrupt.h> 24 25 #include <linux/delay.h> ··· 30 29 #include <linux/of.h> 31 30 #include <linux/of_gpio.h> 32 31 #include <linux/of_device.h> 32 + #include <linux/omap-dma.h> 33 33 #include <linux/mmc/host.h> 34 34 #include <linux/mmc/core.h> 35 35 #include <linux/mmc/mmc.h> ··· 39 37 #include <linux/gpio.h> 40 38 #include <linux/regulator/consumer.h> 41 39 #include <linux/pm_runtime.h> 42 - #include <plat/dma.h> 43 40 #include <mach/hardware.h> 44 41 #include <plat/board.h> 45 42 #include <plat/mmc.h> ··· 167 166 int suspended; 168 167 int irq; 169 168 int use_dma, dma_ch; 170 - int dma_line_tx, dma_line_rx; 169 + struct dma_chan *tx_chan; 170 + struct dma_chan *rx_chan; 171 171 int slot_id; 172 172 int response_busy; 173 173 int context_loss; ··· 799 797 return DMA_FROM_DEVICE; 800 798 } 801 799 800 + static struct dma_chan *omap_hsmmc_get_dma_chan(struct omap_hsmmc_host *host, 801 + struct mmc_data *data) 802 + { 803 + return data->flags & MMC_DATA_WRITE ? host->tx_chan : host->rx_chan; 804 + } 805 + 802 806 static void omap_hsmmc_request_done(struct omap_hsmmc_host *host, struct mmc_request *mrq) 803 807 { 804 808 int dma_ch; ··· 897 889 spin_unlock_irqrestore(&host->irq_lock, flags); 898 890 899 891 if (host->use_dma && dma_ch != -1) { 900 - dma_unmap_sg(mmc_dev(host->mmc), host->data->sg, 901 - host->data->sg_len, 892 + struct dma_chan *chan = omap_hsmmc_get_dma_chan(host, host->data); 893 + 894 + dmaengine_terminate_all(chan); 895 + dma_unmap_sg(chan->device->dev, 896 + host->data->sg, host->data->sg_len, 902 897 omap_hsmmc_get_dma_dir(host, host->data)); 903 - omap_free_dma(dma_ch); 898 + 904 899 host->data->host_cookie = 0; 905 900 } 906 901 host->data = NULL; ··· 1201 1190 return IRQ_HANDLED; 1202 1191 } 1203 1192 1204 - static int omap_hsmmc_get_dma_sync_dev(struct omap_hsmmc_host *host, 1205 - struct mmc_data *data) 1193 + static void omap_hsmmc_dma_callback(void *param) 1206 1194 { 1207 - int sync_dev; 1208 - 1209 - if (data->flags & MMC_DATA_WRITE) 1210 - sync_dev = host->dma_line_tx; 1211 - else 1212 - sync_dev = host->dma_line_rx; 1213 - return sync_dev; 1214 - } 1215 - 1216 - static void omap_hsmmc_config_dma_params(struct omap_hsmmc_host *host, 1217 - struct mmc_data *data, 1218 - struct scatterlist *sgl) 1219 - { 1220 - int blksz, nblk, dma_ch; 1221 - 1222 - dma_ch = host->dma_ch; 1223 - if (data->flags & MMC_DATA_WRITE) { 1224 - omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT, 1225 - (host->mapbase + OMAP_HSMMC_DATA), 0, 0); 1226 - omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC, 1227 - sg_dma_address(sgl), 0, 0); 1228 - } else { 1229 - omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT, 1230 - (host->mapbase + OMAP_HSMMC_DATA), 0, 0); 1231 - omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC, 1232 - sg_dma_address(sgl), 0, 0); 1233 - } 1234 - 1235 - blksz = host->data->blksz; 1236 - nblk = sg_dma_len(sgl) / blksz; 1237 - 1238 - omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S32, 1239 - blksz / 4, nblk, OMAP_DMA_SYNC_FRAME, 1240 - omap_hsmmc_get_dma_sync_dev(host, data), 1241 - !(data->flags & MMC_DATA_WRITE)); 1242 - 1243 - omap_start_dma(dma_ch); 1244 - } 1245 - 1246 - /* 1247 - * DMA call back function 1248 - */ 1249 - static void omap_hsmmc_dma_cb(int lch, u16 ch_status, void *cb_data) 1250 - { 1251 - struct omap_hsmmc_host *host = cb_data; 1195 + struct omap_hsmmc_host *host = param; 1196 + struct dma_chan *chan; 1252 1197 struct mmc_data *data; 1253 - int dma_ch, req_in_progress; 1254 - unsigned long flags; 1198 + int req_in_progress; 1255 1199 1256 - if (!(ch_status & OMAP_DMA_BLOCK_IRQ)) { 1257 - dev_warn(mmc_dev(host->mmc), "unexpected dma status %x\n", 1258 - ch_status); 1259 - return; 1260 - } 1261 - 1262 - spin_lock_irqsave(&host->irq_lock, flags); 1200 + spin_lock_irq(&host->irq_lock); 1263 1201 if (host->dma_ch < 0) { 1264 - spin_unlock_irqrestore(&host->irq_lock, flags); 1202 + spin_unlock_irq(&host->irq_lock); 1265 1203 return; 1266 1204 } 1267 1205 1268 1206 data = host->mrq->data; 1269 - host->dma_sg_idx++; 1270 - if (host->dma_sg_idx < host->dma_len) { 1271 - /* Fire up the next transfer. */ 1272 - omap_hsmmc_config_dma_params(host, data, 1273 - data->sg + host->dma_sg_idx); 1274 - spin_unlock_irqrestore(&host->irq_lock, flags); 1275 - return; 1276 - } 1277 - 1207 + chan = omap_hsmmc_get_dma_chan(host, data); 1278 1208 if (!data->host_cookie) 1279 - dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, 1209 + dma_unmap_sg(chan->device->dev, 1210 + data->sg, data->sg_len, 1280 1211 omap_hsmmc_get_dma_dir(host, data)); 1281 1212 1282 1213 req_in_progress = host->req_in_progress; 1283 - dma_ch = host->dma_ch; 1284 1214 host->dma_ch = -1; 1285 - spin_unlock_irqrestore(&host->irq_lock, flags); 1286 - 1287 - omap_free_dma(dma_ch); 1215 + spin_unlock_irq(&host->irq_lock); 1288 1216 1289 1217 /* If DMA has finished after TC, complete the request */ 1290 1218 if (!req_in_progress) { ··· 1236 1286 1237 1287 static int omap_hsmmc_pre_dma_transfer(struct omap_hsmmc_host *host, 1238 1288 struct mmc_data *data, 1239 - struct omap_hsmmc_next *next) 1289 + struct omap_hsmmc_next *next, 1290 + struct dma_chan *chan) 1240 1291 { 1241 1292 int dma_len; 1242 1293 ··· 1252 1301 /* Check if next job is already prepared */ 1253 1302 if (next || 1254 1303 (!next && data->host_cookie != host->next_data.cookie)) { 1255 - dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg, 1256 - data->sg_len, 1304 + dma_len = dma_map_sg(chan->device->dev, data->sg, data->sg_len, 1257 1305 omap_hsmmc_get_dma_dir(host, data)); 1258 1306 1259 1307 } else { ··· 1279 1329 static int omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host, 1280 1330 struct mmc_request *req) 1281 1331 { 1282 - int dma_ch = 0, ret = 0, i; 1332 + struct dma_slave_config cfg; 1333 + struct dma_async_tx_descriptor *tx; 1334 + int ret = 0, i; 1283 1335 struct mmc_data *data = req->data; 1336 + struct dma_chan *chan; 1284 1337 1285 1338 /* Sanity check: all the SG entries must be aligned by block size. */ 1286 1339 for (i = 0; i < data->sg_len; i++) { ··· 1301 1348 1302 1349 BUG_ON(host->dma_ch != -1); 1303 1350 1304 - ret = omap_request_dma(omap_hsmmc_get_dma_sync_dev(host, data), 1305 - "MMC/SD", omap_hsmmc_dma_cb, host, &dma_ch); 1306 - if (ret != 0) { 1307 - dev_err(mmc_dev(host->mmc), 1308 - "%s: omap_request_dma() failed with %d\n", 1309 - mmc_hostname(host->mmc), ret); 1310 - return ret; 1311 - } 1312 - ret = omap_hsmmc_pre_dma_transfer(host, data, NULL); 1351 + chan = omap_hsmmc_get_dma_chan(host, data); 1352 + 1353 + cfg.src_addr = host->mapbase + OMAP_HSMMC_DATA; 1354 + cfg.dst_addr = host->mapbase + OMAP_HSMMC_DATA; 1355 + cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 1356 + cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 1357 + cfg.src_maxburst = data->blksz / 4; 1358 + cfg.dst_maxburst = data->blksz / 4; 1359 + 1360 + ret = dmaengine_slave_config(chan, &cfg); 1313 1361 if (ret) 1314 1362 return ret; 1315 1363 1316 - host->dma_ch = dma_ch; 1317 - host->dma_sg_idx = 0; 1364 + ret = omap_hsmmc_pre_dma_transfer(host, data, NULL, chan); 1365 + if (ret) 1366 + return ret; 1318 1367 1319 - omap_hsmmc_config_dma_params(host, data, data->sg); 1368 + tx = dmaengine_prep_slave_sg(chan, data->sg, data->sg_len, 1369 + data->flags & MMC_DATA_WRITE ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, 1370 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 1371 + if (!tx) { 1372 + dev_err(mmc_dev(host->mmc), "prep_slave_sg() failed\n"); 1373 + /* FIXME: cleanup */ 1374 + return -1; 1375 + } 1376 + 1377 + tx->callback = omap_hsmmc_dma_callback; 1378 + tx->callback_param = host; 1379 + 1380 + /* Does not fail */ 1381 + dmaengine_submit(tx); 1382 + 1383 + host->dma_ch = 1; 1384 + 1385 + dma_async_issue_pending(chan); 1320 1386 1321 1387 return 0; 1322 1388 } ··· 1417 1445 struct omap_hsmmc_host *host = mmc_priv(mmc); 1418 1446 struct mmc_data *data = mrq->data; 1419 1447 1420 - if (host->use_dma) { 1421 - if (data->host_cookie) 1422 - dma_unmap_sg(mmc_dev(host->mmc), data->sg, 1423 - data->sg_len, 1424 - omap_hsmmc_get_dma_dir(host, data)); 1448 + if (host->use_dma && data->host_cookie) { 1449 + struct dma_chan *c = omap_hsmmc_get_dma_chan(host, data); 1450 + 1451 + dma_unmap_sg(c->device->dev, data->sg, data->sg_len, 1452 + omap_hsmmc_get_dma_dir(host, data)); 1425 1453 data->host_cookie = 0; 1426 1454 } 1427 1455 } ··· 1436 1464 return ; 1437 1465 } 1438 1466 1439 - if (host->use_dma) 1467 + if (host->use_dma) { 1468 + struct dma_chan *c = omap_hsmmc_get_dma_chan(host, mrq->data); 1469 + 1440 1470 if (omap_hsmmc_pre_dma_transfer(host, mrq->data, 1441 - &host->next_data)) 1471 + &host->next_data, c)) 1442 1472 mrq->data->host_cookie = 0; 1473 + } 1443 1474 } 1444 1475 1445 1476 /* ··· 1775 1800 struct resource *res; 1776 1801 int ret, irq; 1777 1802 const struct of_device_id *match; 1803 + dma_cap_mask_t mask; 1804 + unsigned tx_req, rx_req; 1778 1805 1779 1806 match = of_match_device(of_match_ptr(omap_mmc_of_match), &pdev->dev); 1780 1807 if (match) { ··· 1821 1844 host->pdata = pdata; 1822 1845 host->dev = &pdev->dev; 1823 1846 host->use_dma = 1; 1824 - host->dev->dma_mask = &pdata->dma_mask; 1825 1847 host->dma_ch = -1; 1826 1848 host->irq = irq; 1827 1849 host->slot_id = 0; ··· 1910 1934 ret = -ENXIO; 1911 1935 goto err_irq; 1912 1936 } 1913 - host->dma_line_tx = res->start; 1937 + tx_req = res->start; 1914 1938 1915 1939 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); 1916 1940 if (!res) { ··· 1918 1942 ret = -ENXIO; 1919 1943 goto err_irq; 1920 1944 } 1921 - host->dma_line_rx = res->start; 1945 + rx_req = res->start; 1946 + 1947 + dma_cap_zero(mask); 1948 + dma_cap_set(DMA_SLAVE, mask); 1949 + 1950 + host->rx_chan = dma_request_channel(mask, omap_dma_filter_fn, &rx_req); 1951 + if (!host->rx_chan) { 1952 + dev_err(mmc_dev(host->mmc), "unable to obtain RX DMA engine channel %u\n", rx_req); 1953 + ret = -ENXIO; 1954 + goto err_irq; 1955 + } 1956 + 1957 + host->tx_chan = dma_request_channel(mask, omap_dma_filter_fn, &tx_req); 1958 + if (!host->tx_chan) { 1959 + dev_err(mmc_dev(host->mmc), "unable to obtain TX DMA engine channel %u\n", tx_req); 1960 + ret = -ENXIO; 1961 + goto err_irq; 1962 + } 1922 1963 1923 1964 /* Request IRQ for MMC operations */ 1924 1965 ret = request_irq(host->irq, omap_hsmmc_irq, 0, ··· 2014 2021 err_irq_cd_init: 2015 2022 free_irq(host->irq, host); 2016 2023 err_irq: 2024 + if (host->tx_chan) 2025 + dma_release_channel(host->tx_chan); 2026 + if (host->rx_chan) 2027 + dma_release_channel(host->rx_chan); 2017 2028 pm_runtime_put_sync(host->dev); 2018 2029 pm_runtime_disable(host->dev); 2019 2030 clk_put(host->fclk); ··· 2052 2055 free_irq(host->irq, host); 2053 2056 if (mmc_slot(host).card_detect_irq) 2054 2057 free_irq(mmc_slot(host).card_detect_irq, host); 2058 + 2059 + if (host->tx_chan) 2060 + dma_release_channel(host->tx_chan); 2061 + if (host->rx_chan) 2062 + dma_release_channel(host->rx_chan); 2055 2063 2056 2064 pm_runtime_put_sync(host->dev); 2057 2065 pm_runtime_disable(host->dev);
+55 -49
drivers/mtd/nand/omap2.c
··· 9 9 */ 10 10 11 11 #include <linux/platform_device.h> 12 + #include <linux/dmaengine.h> 12 13 #include <linux/dma-mapping.h> 13 14 #include <linux/delay.h> 14 15 #include <linux/module.h> ··· 19 18 #include <linux/mtd/mtd.h> 20 19 #include <linux/mtd/nand.h> 21 20 #include <linux/mtd/partitions.h> 21 + #include <linux/omap-dma.h> 22 22 #include <linux/io.h> 23 23 #include <linux/slab.h> 24 24 ··· 125 123 int gpmc_cs; 126 124 unsigned long phys_base; 127 125 struct completion comp; 128 - int dma_ch; 126 + struct dma_chan *dma; 129 127 int gpmc_irq; 130 128 enum { 131 129 OMAP_NAND_IO_READ = 0, /* read */ ··· 338 336 } 339 337 340 338 /* 341 - * omap_nand_dma_cb: callback on the completion of dma transfer 342 - * @lch: logical channel 343 - * @ch_satuts: channel status 339 + * omap_nand_dma_callback: callback on the completion of dma transfer 344 340 * @data: pointer to completion data structure 345 341 */ 346 - static void omap_nand_dma_cb(int lch, u16 ch_status, void *data) 342 + static void omap_nand_dma_callback(void *data) 347 343 { 348 344 complete((struct completion *) data); 349 345 } ··· 358 358 { 359 359 struct omap_nand_info *info = container_of(mtd, 360 360 struct omap_nand_info, mtd); 361 + struct dma_async_tx_descriptor *tx; 361 362 enum dma_data_direction dir = is_write ? DMA_TO_DEVICE : 362 363 DMA_FROM_DEVICE; 363 - dma_addr_t dma_addr; 364 - int ret; 364 + struct scatterlist sg; 365 365 unsigned long tim, limit; 366 - 367 - /* The fifo depth is 64 bytes max. 368 - * But configure the FIFO-threahold to 32 to get a sync at each frame 369 - * and frame length is 32 bytes. 370 - */ 371 - int buf_len = len >> 6; 366 + unsigned n; 367 + int ret; 372 368 373 369 if (addr >= high_memory) { 374 370 struct page *p1; ··· 378 382 addr = page_address(p1) + ((size_t)addr & ~PAGE_MASK); 379 383 } 380 384 381 - dma_addr = dma_map_single(&info->pdev->dev, addr, len, dir); 382 - if (dma_mapping_error(&info->pdev->dev, dma_addr)) { 385 + sg_init_one(&sg, addr, len); 386 + n = dma_map_sg(info->dma->device->dev, &sg, 1, dir); 387 + if (n == 0) { 383 388 dev_err(&info->pdev->dev, 384 389 "Couldn't DMA map a %d byte buffer\n", len); 385 390 goto out_copy; 386 391 } 387 392 388 - if (is_write) { 389 - omap_set_dma_dest_params(info->dma_ch, 0, OMAP_DMA_AMODE_CONSTANT, 390 - info->phys_base, 0, 0); 391 - omap_set_dma_src_params(info->dma_ch, 0, OMAP_DMA_AMODE_POST_INC, 392 - dma_addr, 0, 0); 393 - omap_set_dma_transfer_params(info->dma_ch, OMAP_DMA_DATA_TYPE_S32, 394 - 0x10, buf_len, OMAP_DMA_SYNC_FRAME, 395 - OMAP24XX_DMA_GPMC, OMAP_DMA_DST_SYNC); 396 - } else { 397 - omap_set_dma_src_params(info->dma_ch, 0, OMAP_DMA_AMODE_CONSTANT, 398 - info->phys_base, 0, 0); 399 - omap_set_dma_dest_params(info->dma_ch, 0, OMAP_DMA_AMODE_POST_INC, 400 - dma_addr, 0, 0); 401 - omap_set_dma_transfer_params(info->dma_ch, OMAP_DMA_DATA_TYPE_S32, 402 - 0x10, buf_len, OMAP_DMA_SYNC_FRAME, 403 - OMAP24XX_DMA_GPMC, OMAP_DMA_SRC_SYNC); 404 - } 405 - /* configure and start prefetch transfer */ 393 + tx = dmaengine_prep_slave_sg(info->dma, &sg, n, 394 + is_write ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, 395 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 396 + if (!tx) 397 + goto out_copy_unmap; 398 + 399 + tx->callback = omap_nand_dma_callback; 400 + tx->callback_param = &info->comp; 401 + dmaengine_submit(tx); 402 + 403 + /* configure and start prefetch transfer */ 406 404 ret = gpmc_prefetch_enable(info->gpmc_cs, 407 - PREFETCH_FIFOTHRESHOLD_MAX, 0x1, len, is_write); 405 + PREFETCH_FIFOTHRESHOLD_MAX, 0x1, len, is_write); 408 406 if (ret) 409 407 /* PFPW engine is busy, use cpu copy method */ 410 408 goto out_copy_unmap; 411 409 412 410 init_completion(&info->comp); 413 - 414 - omap_start_dma(info->dma_ch); 411 + dma_async_issue_pending(info->dma); 415 412 416 413 /* setup and start DMA using dma_addr */ 417 414 wait_for_completion(&info->comp); ··· 416 427 /* disable and stop the PFPW engine */ 417 428 gpmc_prefetch_reset(info->gpmc_cs); 418 429 419 - dma_unmap_single(&info->pdev->dev, dma_addr, len, dir); 430 + dma_unmap_sg(info->dma->device->dev, &sg, 1, dir); 420 431 return 0; 421 432 422 433 out_copy_unmap: 423 - dma_unmap_single(&info->pdev->dev, dma_addr, len, dir); 434 + dma_unmap_sg(info->dma->device->dev, &sg, 1, dir); 424 435 out_copy: 425 436 if (info->nand.options & NAND_BUSWIDTH_16) 426 437 is_write == 0 ? omap_read_buf16(mtd, (u_char *) addr, len) ··· 1153 1164 struct omap_nand_platform_data *pdata; 1154 1165 int err; 1155 1166 int i, offset; 1167 + dma_cap_mask_t mask; 1168 + unsigned sig; 1156 1169 1157 1170 pdata = pdev->dev.platform_data; 1158 1171 if (pdata == NULL) { ··· 1235 1244 break; 1236 1245 1237 1246 case NAND_OMAP_PREFETCH_DMA: 1238 - err = omap_request_dma(OMAP24XX_DMA_GPMC, "NAND", 1239 - omap_nand_dma_cb, &info->comp, &info->dma_ch); 1240 - if (err < 0) { 1241 - info->dma_ch = -1; 1242 - dev_err(&pdev->dev, "DMA request failed!\n"); 1247 + dma_cap_zero(mask); 1248 + dma_cap_set(DMA_SLAVE, mask); 1249 + sig = OMAP24XX_DMA_GPMC; 1250 + info->dma = dma_request_channel(mask, omap_dma_filter_fn, &sig); 1251 + if (!info->dma) { 1252 + dev_err(&pdev->dev, "DMA engine request failed\n"); 1253 + err = -ENXIO; 1243 1254 goto out_release_mem_region; 1244 1255 } else { 1245 - omap_set_dma_dest_burst_mode(info->dma_ch, 1246 - OMAP_DMA_DATA_BURST_16); 1247 - omap_set_dma_src_burst_mode(info->dma_ch, 1248 - OMAP_DMA_DATA_BURST_16); 1256 + struct dma_slave_config cfg; 1257 + int rc; 1249 1258 1259 + memset(&cfg, 0, sizeof(cfg)); 1260 + cfg.src_addr = info->phys_base; 1261 + cfg.dst_addr = info->phys_base; 1262 + cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 1263 + cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 1264 + cfg.src_maxburst = 16; 1265 + cfg.dst_maxburst = 16; 1266 + rc = dmaengine_slave_config(info->dma, &cfg); 1267 + if (rc) { 1268 + dev_err(&pdev->dev, "DMA engine slave config failed: %d\n", 1269 + rc); 1270 + goto out_release_mem_region; 1271 + } 1250 1272 info->nand.read_buf = omap_read_buf_dma_pref; 1251 1273 info->nand.write_buf = omap_write_buf_dma_pref; 1252 1274 } ··· 1362 1358 return 0; 1363 1359 1364 1360 out_release_mem_region: 1361 + if (info->dma) 1362 + dma_release_channel(info->dma); 1365 1363 release_mem_region(info->phys_base, NAND_IO_SIZE); 1366 1364 out_free_info: 1367 1365 kfree(info); ··· 1379 1373 omap3_free_bch(&info->mtd); 1380 1374 1381 1375 platform_set_drvdata(pdev, NULL); 1382 - if (info->dma_ch != -1) 1383 - omap_free_dma(info->dma_ch); 1376 + if (info->dma) 1377 + dma_release_channel(info->dma); 1384 1378 1385 1379 if (info->gpmc_irq) 1386 1380 free_irq(info->gpmc_irq, info);
+130 -105
drivers/spi/spi-omap2-mcspi.c
··· 28 28 #include <linux/device.h> 29 29 #include <linux/delay.h> 30 30 #include <linux/dma-mapping.h> 31 + #include <linux/dmaengine.h> 32 + #include <linux/omap-dma.h> 31 33 #include <linux/platform_device.h> 32 34 #include <linux/err.h> 33 35 #include <linux/clk.h> ··· 41 39 42 40 #include <linux/spi/spi.h> 43 41 44 - #include <plat/dma.h> 45 42 #include <plat/clock.h> 46 43 #include <plat/mcspi.h> 47 44 ··· 94 93 95 94 /* We have 2 DMA channels per CS, one for RX and one for TX */ 96 95 struct omap2_mcspi_dma { 97 - int dma_tx_channel; 98 - int dma_rx_channel; 96 + struct dma_chan *dma_tx; 97 + struct dma_chan *dma_rx; 99 98 100 99 int dma_tx_sync_dev; 101 100 int dma_rx_sync_dev; ··· 301 300 return 0; 302 301 } 303 302 303 + static void omap2_mcspi_rx_callback(void *data) 304 + { 305 + struct spi_device *spi = data; 306 + struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master); 307 + struct omap2_mcspi_dma *mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 308 + 309 + complete(&mcspi_dma->dma_rx_completion); 310 + 311 + /* We must disable the DMA RX request */ 312 + omap2_mcspi_set_dma_req(spi, 1, 0); 313 + } 314 + 315 + static void omap2_mcspi_tx_callback(void *data) 316 + { 317 + struct spi_device *spi = data; 318 + struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master); 319 + struct omap2_mcspi_dma *mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 320 + 321 + complete(&mcspi_dma->dma_tx_completion); 322 + 323 + /* We must disable the DMA TX request */ 324 + omap2_mcspi_set_dma_req(spi, 0, 0); 325 + } 326 + 304 327 static unsigned 305 328 omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) 306 329 { 307 330 struct omap2_mcspi *mcspi; 308 331 struct omap2_mcspi_cs *cs = spi->controller_state; 309 332 struct omap2_mcspi_dma *mcspi_dma; 310 - unsigned int count, c; 311 - unsigned long base, tx_reg, rx_reg; 312 - int word_len, data_type, element_count; 333 + unsigned int count; 334 + int word_len, element_count; 313 335 int elements = 0; 314 336 u32 l; 315 337 u8 * rx; 316 338 const u8 * tx; 317 339 void __iomem *chstat_reg; 340 + struct dma_slave_config cfg; 341 + enum dma_slave_buswidth width; 342 + unsigned es; 318 343 319 344 mcspi = spi_master_get_devdata(spi->master); 320 345 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; ··· 348 321 349 322 chstat_reg = cs->base + OMAP2_MCSPI_CHSTAT0; 350 323 324 + if (cs->word_len <= 8) { 325 + width = DMA_SLAVE_BUSWIDTH_1_BYTE; 326 + es = 1; 327 + } else if (cs->word_len <= 16) { 328 + width = DMA_SLAVE_BUSWIDTH_2_BYTES; 329 + es = 2; 330 + } else { 331 + width = DMA_SLAVE_BUSWIDTH_4_BYTES; 332 + es = 4; 333 + } 334 + 335 + memset(&cfg, 0, sizeof(cfg)); 336 + cfg.src_addr = cs->phys + OMAP2_MCSPI_RX0; 337 + cfg.dst_addr = cs->phys + OMAP2_MCSPI_TX0; 338 + cfg.src_addr_width = width; 339 + cfg.dst_addr_width = width; 340 + cfg.src_maxburst = 1; 341 + cfg.dst_maxburst = 1; 342 + 343 + if (xfer->tx_buf && mcspi_dma->dma_tx) { 344 + struct dma_async_tx_descriptor *tx; 345 + struct scatterlist sg; 346 + 347 + dmaengine_slave_config(mcspi_dma->dma_tx, &cfg); 348 + 349 + sg_init_table(&sg, 1); 350 + sg_dma_address(&sg) = xfer->tx_dma; 351 + sg_dma_len(&sg) = xfer->len; 352 + 353 + tx = dmaengine_prep_slave_sg(mcspi_dma->dma_tx, &sg, 1, 354 + DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 355 + if (tx) { 356 + tx->callback = omap2_mcspi_tx_callback; 357 + tx->callback_param = spi; 358 + dmaengine_submit(tx); 359 + } else { 360 + /* FIXME: fall back to PIO? */ 361 + } 362 + } 363 + 364 + if (xfer->rx_buf && mcspi_dma->dma_rx) { 365 + struct dma_async_tx_descriptor *tx; 366 + struct scatterlist sg; 367 + size_t len = xfer->len - es; 368 + 369 + dmaengine_slave_config(mcspi_dma->dma_rx, &cfg); 370 + 371 + if (l & OMAP2_MCSPI_CHCONF_TURBO) 372 + len -= es; 373 + 374 + sg_init_table(&sg, 1); 375 + sg_dma_address(&sg) = xfer->rx_dma; 376 + sg_dma_len(&sg) = len; 377 + 378 + tx = dmaengine_prep_slave_sg(mcspi_dma->dma_rx, &sg, 1, 379 + DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 380 + if (tx) { 381 + tx->callback = omap2_mcspi_rx_callback; 382 + tx->callback_param = spi; 383 + dmaengine_submit(tx); 384 + } else { 385 + /* FIXME: fall back to PIO? */ 386 + } 387 + } 388 + 351 389 count = xfer->len; 352 - c = count; 353 390 word_len = cs->word_len; 354 391 355 - base = cs->phys; 356 - tx_reg = base + OMAP2_MCSPI_TX0; 357 - rx_reg = base + OMAP2_MCSPI_RX0; 358 392 rx = xfer->rx_buf; 359 393 tx = xfer->tx_buf; 360 394 361 395 if (word_len <= 8) { 362 - data_type = OMAP_DMA_DATA_TYPE_S8; 363 396 element_count = count; 364 397 } else if (word_len <= 16) { 365 - data_type = OMAP_DMA_DATA_TYPE_S16; 366 398 element_count = count >> 1; 367 399 } else /* word_len <= 32 */ { 368 - data_type = OMAP_DMA_DATA_TYPE_S32; 369 400 element_count = count >> 2; 370 401 } 371 402 372 403 if (tx != NULL) { 373 - omap_set_dma_transfer_params(mcspi_dma->dma_tx_channel, 374 - data_type, element_count, 1, 375 - OMAP_DMA_SYNC_ELEMENT, 376 - mcspi_dma->dma_tx_sync_dev, 0); 377 - 378 - omap_set_dma_dest_params(mcspi_dma->dma_tx_channel, 0, 379 - OMAP_DMA_AMODE_CONSTANT, 380 - tx_reg, 0, 0); 381 - 382 - omap_set_dma_src_params(mcspi_dma->dma_tx_channel, 0, 383 - OMAP_DMA_AMODE_POST_INC, 384 - xfer->tx_dma, 0, 0); 385 - } 386 - 387 - if (rx != NULL) { 388 - elements = element_count - 1; 389 - if (l & OMAP2_MCSPI_CHCONF_TURBO) 390 - elements--; 391 - 392 - omap_set_dma_transfer_params(mcspi_dma->dma_rx_channel, 393 - data_type, elements, 1, 394 - OMAP_DMA_SYNC_ELEMENT, 395 - mcspi_dma->dma_rx_sync_dev, 1); 396 - 397 - omap_set_dma_src_params(mcspi_dma->dma_rx_channel, 0, 398 - OMAP_DMA_AMODE_CONSTANT, 399 - rx_reg, 0, 0); 400 - 401 - omap_set_dma_dest_params(mcspi_dma->dma_rx_channel, 0, 402 - OMAP_DMA_AMODE_POST_INC, 403 - xfer->rx_dma, 0, 0); 404 - } 405 - 406 - if (tx != NULL) { 407 - omap_start_dma(mcspi_dma->dma_tx_channel); 404 + dma_async_issue_pending(mcspi_dma->dma_tx); 408 405 omap2_mcspi_set_dma_req(spi, 0, 1); 409 406 } 410 407 411 408 if (rx != NULL) { 412 - omap_start_dma(mcspi_dma->dma_rx_channel); 409 + dma_async_issue_pending(mcspi_dma->dma_rx); 413 410 omap2_mcspi_set_dma_req(spi, 1, 1); 414 411 } 415 412 ··· 459 408 DMA_FROM_DEVICE); 460 409 omap2_mcspi_set_enable(spi, 0); 461 410 411 + elements = element_count - 1; 412 + 462 413 if (l & OMAP2_MCSPI_CHCONF_TURBO) { 414 + elements--; 463 415 464 416 if (likely(mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHSTAT0) 465 417 & OMAP2_MCSPI_CHSTAT_RXS)) { ··· 779 725 return 0; 780 726 } 781 727 782 - static void omap2_mcspi_dma_rx_callback(int lch, u16 ch_status, void *data) 783 - { 784 - struct spi_device *spi = data; 785 - struct omap2_mcspi *mcspi; 786 - struct omap2_mcspi_dma *mcspi_dma; 787 - 788 - mcspi = spi_master_get_devdata(spi->master); 789 - mcspi_dma = &(mcspi->dma_channels[spi->chip_select]); 790 - 791 - complete(&mcspi_dma->dma_rx_completion); 792 - 793 - /* We must disable the DMA RX request */ 794 - omap2_mcspi_set_dma_req(spi, 1, 0); 795 - } 796 - 797 - static void omap2_mcspi_dma_tx_callback(int lch, u16 ch_status, void *data) 798 - { 799 - struct spi_device *spi = data; 800 - struct omap2_mcspi *mcspi; 801 - struct omap2_mcspi_dma *mcspi_dma; 802 - 803 - mcspi = spi_master_get_devdata(spi->master); 804 - mcspi_dma = &(mcspi->dma_channels[spi->chip_select]); 805 - 806 - complete(&mcspi_dma->dma_tx_completion); 807 - 808 - /* We must disable the DMA TX request */ 809 - omap2_mcspi_set_dma_req(spi, 0, 0); 810 - } 811 - 812 728 static int omap2_mcspi_request_dma(struct spi_device *spi) 813 729 { 814 730 struct spi_master *master = spi->master; 815 731 struct omap2_mcspi *mcspi; 816 732 struct omap2_mcspi_dma *mcspi_dma; 733 + dma_cap_mask_t mask; 734 + unsigned sig; 817 735 818 736 mcspi = spi_master_get_devdata(master); 819 737 mcspi_dma = mcspi->dma_channels + spi->chip_select; 820 738 821 - if (omap_request_dma(mcspi_dma->dma_rx_sync_dev, "McSPI RX", 822 - omap2_mcspi_dma_rx_callback, spi, 823 - &mcspi_dma->dma_rx_channel)) { 824 - dev_err(&spi->dev, "no RX DMA channel for McSPI\n"); 825 - return -EAGAIN; 826 - } 827 - 828 - if (omap_request_dma(mcspi_dma->dma_tx_sync_dev, "McSPI TX", 829 - omap2_mcspi_dma_tx_callback, spi, 830 - &mcspi_dma->dma_tx_channel)) { 831 - omap_free_dma(mcspi_dma->dma_rx_channel); 832 - mcspi_dma->dma_rx_channel = -1; 833 - dev_err(&spi->dev, "no TX DMA channel for McSPI\n"); 834 - return -EAGAIN; 835 - } 836 - 837 739 init_completion(&mcspi_dma->dma_rx_completion); 838 740 init_completion(&mcspi_dma->dma_tx_completion); 741 + 742 + dma_cap_zero(mask); 743 + dma_cap_set(DMA_SLAVE, mask); 744 + sig = mcspi_dma->dma_rx_sync_dev; 745 + mcspi_dma->dma_rx = dma_request_channel(mask, omap_dma_filter_fn, &sig); 746 + if (!mcspi_dma->dma_rx) { 747 + dev_err(&spi->dev, "no RX DMA engine channel for McSPI\n"); 748 + return -EAGAIN; 749 + } 750 + 751 + sig = mcspi_dma->dma_tx_sync_dev; 752 + mcspi_dma->dma_tx = dma_request_channel(mask, omap_dma_filter_fn, &sig); 753 + if (!mcspi_dma->dma_tx) { 754 + dev_err(&spi->dev, "no TX DMA engine channel for McSPI\n"); 755 + dma_release_channel(mcspi_dma->dma_rx); 756 + mcspi_dma->dma_rx = NULL; 757 + return -EAGAIN; 758 + } 839 759 840 760 return 0; 841 761 } ··· 842 814 list_add_tail(&cs->node, &ctx->cs); 843 815 } 844 816 845 - if (mcspi_dma->dma_rx_channel == -1 846 - || mcspi_dma->dma_tx_channel == -1) { 817 + if (!mcspi_dma->dma_rx || !mcspi_dma->dma_tx) { 847 818 ret = omap2_mcspi_request_dma(spi); 848 819 if (ret < 0) 849 820 return ret; ··· 877 850 if (spi->chip_select < spi->master->num_chipselect) { 878 851 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 879 852 880 - if (mcspi_dma->dma_rx_channel != -1) { 881 - omap_free_dma(mcspi_dma->dma_rx_channel); 882 - mcspi_dma->dma_rx_channel = -1; 853 + if (mcspi_dma->dma_rx) { 854 + dma_release_channel(mcspi_dma->dma_rx); 855 + mcspi_dma->dma_rx = NULL; 883 856 } 884 - if (mcspi_dma->dma_tx_channel != -1) { 885 - omap_free_dma(mcspi_dma->dma_tx_channel); 886 - mcspi_dma->dma_tx_channel = -1; 857 + if (mcspi_dma->dma_tx) { 858 + dma_release_channel(mcspi_dma->dma_tx); 859 + mcspi_dma->dma_tx = NULL; 887 860 } 888 861 } 889 862 } ··· 1203 1176 break; 1204 1177 } 1205 1178 1206 - mcspi->dma_channels[i].dma_rx_channel = -1; 1207 1179 mcspi->dma_channels[i].dma_rx_sync_dev = dma_res->start; 1208 1180 sprintf(dma_ch_name, "tx%d", i); 1209 1181 dma_res = platform_get_resource_byname(pdev, IORESOURCE_DMA, ··· 1213 1187 break; 1214 1188 } 1215 1189 1216 - mcspi->dma_channels[i].dma_tx_channel = -1; 1217 1190 mcspi->dma_channels[i].dma_tx_sync_dev = dma_res->start; 1218 1191 } 1219 1192
+8 -148
include/linux/amba/pl08x.h
··· 21 21 #include <linux/dmaengine.h> 22 22 #include <linux/interrupt.h> 23 23 24 - struct pl08x_lli; 25 24 struct pl08x_driver_data; 25 + struct pl08x_phy_chan; 26 + struct pl08x_txd; 26 27 27 28 /* Bitmasks for selecting AHB ports for DMA transfers */ 28 29 enum { ··· 47 46 * devices with static assignments 48 47 * @muxval: a number usually used to poke into some mux regiser to 49 48 * mux in the signal to this channel 50 - * @cctl_opt: default options for the channel control register 49 + * @cctl_memcpy: options for the channel control register for memcpy 50 + * *** not used for slave channels *** 51 51 * @addr: source/target address in physical memory for this DMA channel, 52 52 * can be the address of a FIFO register for burst requests for example. 53 53 * This can be left undefined if the PrimeCell API is used for configuring 54 54 * this. 55 - * @circular_buffer: whether the buffer passed in is circular and 56 - * shall simply be looped round round (like a record baby round 57 - * round round round) 58 55 * @single: the device connected to this channel will request single DMA 59 56 * transfers, not bursts. (Bursts are default.) 60 57 * @periph_buses: the device connected to this channel is accessible via 61 58 * these buses (use PL08X_AHB1 | PL08X_AHB2). 62 59 */ 63 60 struct pl08x_channel_data { 64 - char *bus_id; 61 + const char *bus_id; 65 62 int min_signal; 66 63 int max_signal; 67 64 u32 muxval; 68 - u32 cctl; 65 + u32 cctl_memcpy; 69 66 dma_addr_t addr; 70 - bool circular_buffer; 71 67 bool single; 72 68 u8 periph_buses; 73 - }; 74 - 75 - /** 76 - * Struct pl08x_bus_data - information of source or destination 77 - * busses for a transfer 78 - * @addr: current address 79 - * @maxwidth: the maximum width of a transfer on this bus 80 - * @buswidth: the width of this bus in bytes: 1, 2 or 4 81 - */ 82 - struct pl08x_bus_data { 83 - dma_addr_t addr; 84 - u8 maxwidth; 85 - u8 buswidth; 86 - }; 87 - 88 - /** 89 - * struct pl08x_phy_chan - holder for the physical channels 90 - * @id: physical index to this channel 91 - * @lock: a lock to use when altering an instance of this struct 92 - * @signal: the physical signal (aka channel) serving this physical channel 93 - * right now 94 - * @serving: the virtual channel currently being served by this physical 95 - * channel 96 - * @locked: channel unavailable for the system, e.g. dedicated to secure 97 - * world 98 - */ 99 - struct pl08x_phy_chan { 100 - unsigned int id; 101 - void __iomem *base; 102 - spinlock_t lock; 103 - int signal; 104 - struct pl08x_dma_chan *serving; 105 - bool locked; 106 - }; 107 - 108 - /** 109 - * struct pl08x_sg - structure containing data per sg 110 - * @src_addr: src address of sg 111 - * @dst_addr: dst address of sg 112 - * @len: transfer len in bytes 113 - * @node: node for txd's dsg_list 114 - */ 115 - struct pl08x_sg { 116 - dma_addr_t src_addr; 117 - dma_addr_t dst_addr; 118 - size_t len; 119 - struct list_head node; 120 - }; 121 - 122 - /** 123 - * struct pl08x_txd - wrapper for struct dma_async_tx_descriptor 124 - * @tx: async tx descriptor 125 - * @node: node for txd list for channels 126 - * @dsg_list: list of children sg's 127 - * @direction: direction of transfer 128 - * @llis_bus: DMA memory address (physical) start for the LLIs 129 - * @llis_va: virtual memory address start for the LLIs 130 - * @cctl: control reg values for current txd 131 - * @ccfg: config reg values for current txd 132 - */ 133 - struct pl08x_txd { 134 - struct dma_async_tx_descriptor tx; 135 - struct list_head node; 136 - struct list_head dsg_list; 137 - enum dma_transfer_direction direction; 138 - dma_addr_t llis_bus; 139 - struct pl08x_lli *llis_va; 140 - /* Default cctl value for LLIs */ 141 - u32 cctl; 142 - /* 143 - * Settings to be put into the physical channel when we 144 - * trigger this txd. Other registers are in llis_va[0]. 145 - */ 146 - u32 ccfg; 147 - }; 148 - 149 - /** 150 - * struct pl08x_dma_chan_state - holds the PL08x specific virtual channel 151 - * states 152 - * @PL08X_CHAN_IDLE: the channel is idle 153 - * @PL08X_CHAN_RUNNING: the channel has allocated a physical transport 154 - * channel and is running a transfer on it 155 - * @PL08X_CHAN_PAUSED: the channel has allocated a physical transport 156 - * channel, but the transfer is currently paused 157 - * @PL08X_CHAN_WAITING: the channel is waiting for a physical transport 158 - * channel to become available (only pertains to memcpy channels) 159 - */ 160 - enum pl08x_dma_chan_state { 161 - PL08X_CHAN_IDLE, 162 - PL08X_CHAN_RUNNING, 163 - PL08X_CHAN_PAUSED, 164 - PL08X_CHAN_WAITING, 165 - }; 166 - 167 - /** 168 - * struct pl08x_dma_chan - this structure wraps a DMA ENGINE channel 169 - * @chan: wrappped abstract channel 170 - * @phychan: the physical channel utilized by this channel, if there is one 171 - * @phychan_hold: if non-zero, hold on to the physical channel even if we 172 - * have no pending entries 173 - * @tasklet: tasklet scheduled by the IRQ to handle actual work etc 174 - * @name: name of channel 175 - * @cd: channel platform data 176 - * @runtime_addr: address for RX/TX according to the runtime config 177 - * @runtime_direction: current direction of this channel according to 178 - * runtime config 179 - * @pend_list: queued transactions pending on this channel 180 - * @at: active transaction on this channel 181 - * @lock: a lock for this channel data 182 - * @host: a pointer to the host (internal use) 183 - * @state: whether the channel is idle, paused, running etc 184 - * @slave: whether this channel is a device (slave) or for memcpy 185 - * @device_fc: Flow Controller Settings for ccfg register. Only valid for slave 186 - * channels. Fill with 'true' if peripheral should be flow controller. Direction 187 - * will be selected at Runtime. 188 - * @waiting: a TX descriptor on this channel which is waiting for a physical 189 - * channel to become available 190 - */ 191 - struct pl08x_dma_chan { 192 - struct dma_chan chan; 193 - struct pl08x_phy_chan *phychan; 194 - int phychan_hold; 195 - struct tasklet_struct tasklet; 196 - char *name; 197 - const struct pl08x_channel_data *cd; 198 - dma_addr_t src_addr; 199 - dma_addr_t dst_addr; 200 - u32 src_cctl; 201 - u32 dst_cctl; 202 - enum dma_transfer_direction runtime_direction; 203 - struct list_head pend_list; 204 - struct pl08x_txd *at; 205 - spinlock_t lock; 206 - struct pl08x_driver_data *host; 207 - enum pl08x_dma_chan_state state; 208 - bool slave; 209 - bool device_fc; 210 - struct pl08x_txd *waiting; 211 69 }; 212 70 213 71 /** ··· 89 229 const struct pl08x_channel_data *slave_channels; 90 230 unsigned int num_slave_channels; 91 231 struct pl08x_channel_data memcpy_channel; 92 - int (*get_signal)(struct pl08x_dma_chan *); 93 - void (*put_signal)(struct pl08x_dma_chan *); 232 + int (*get_signal)(const struct pl08x_channel_data *); 233 + void (*put_signal)(const struct pl08x_channel_data *, int); 94 234 u8 lli_buses; 95 235 u8 mem_buses; 96 236 };
+22
include/linux/omap-dma.h
··· 1 + /* 2 + * OMAP DMA Engine support 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + */ 8 + #ifndef __LINUX_OMAP_DMA_H 9 + #define __LINUX_OMAP_DMA_H 10 + 11 + struct dma_chan; 12 + 13 + #if defined(CONFIG_DMA_OMAP) || defined(CONFIG_DMA_OMAP_MODULE) 14 + bool omap_dma_filter_fn(struct dma_chan *, void *); 15 + #else 16 + static inline bool omap_dma_filter_fn(struct dma_chan *c, void *d) 17 + { 18 + return false; 19 + } 20 + #endif 21 + 22 + #endif