1 /* 2 * Renesas R-Car Audio DMAC support 3 * 4 * Copyright (C) 2015 Renesas Electronics Corp. 5 * Copyright (c) 2015 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 */ 11 #include <linux/delay.h> 12 #include <linux/of_dma.h> 13 #include "rsnd.h" 14 15 /* 16 * Audio DMAC peri peri register 17 */ 18 #define PDMASAR 0x00 19 #define PDMADAR 0x04 20 #define PDMACHCR 0x0c 21 22 /* PDMACHCR */ 23 #define PDMACHCR_DE (1 << 0) 24 25 struct rsnd_dma_ctrl { 26 void __iomem *base; 27 int dmapp_num; 28 }; 29 30 #define rsnd_priv_to_dmac(p) ((struct rsnd_dma_ctrl *)(p)->dma) 31 32 /* 33 * Audio DMAC 34 */ 35 static void __rsnd_dmaen_complete(struct rsnd_mod *mod, 36 struct rsnd_dai_stream *io) 37 { 38 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 39 bool elapsed = false; 40 unsigned long flags; 41 42 /* 43 * Renesas sound Gen1 needs 1 DMAC, 44 * Gen2 needs 2 DMAC. 45 * In Gen2 case, it are Audio-DMAC, and Audio-DMAC-peri-peri. 46 * But, Audio-DMAC-peri-peri doesn't have interrupt, 47 * and this driver is assuming that here. 48 * 49 * If Audio-DMAC-peri-peri has interrpt, 50 * rsnd_dai_pointer_update() will be called twice, 51 * ant it will breaks io->byte_pos 52 */ 53 spin_lock_irqsave(&priv->lock, flags); 54 55 if (rsnd_io_is_working(io)) 56 elapsed = rsnd_dai_pointer_update(io, io->byte_per_period); 57 58 spin_unlock_irqrestore(&priv->lock, flags); 59 60 if (elapsed) 61 rsnd_dai_period_elapsed(io); 62 } 63 64 static void rsnd_dmaen_complete(void *data) 65 { 66 struct rsnd_mod *mod = data; 67 68 rsnd_mod_interrupt(mod, __rsnd_dmaen_complete); 69 } 70 71 static void rsnd_dmaen_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma) 72 { 73 struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma); 74 75 dmaengine_terminate_all(dmaen->chan); 76 } 77 78 static void rsnd_dmaen_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma) 79 { 80 struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma); 81 struct rsnd_mod *mod = rsnd_dma_to_mod(dma); 82 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 83 struct snd_pcm_substream *substream = io->substream; 84 struct device *dev = rsnd_priv_to_dev(priv); 85 struct dma_async_tx_descriptor *desc; 86 int is_play = rsnd_io_is_play(io); 87 88 desc = dmaengine_prep_dma_cyclic(dmaen->chan, 89 substream->runtime->dma_addr, 90 snd_pcm_lib_buffer_bytes(substream), 91 snd_pcm_lib_period_bytes(substream), 92 is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, 93 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 94 95 if (!desc) { 96 dev_err(dev, "dmaengine_prep_slave_sg() fail\n"); 97 return; 98 } 99 100 desc->callback = rsnd_dmaen_complete; 101 desc->callback_param = mod; 102 103 if (dmaengine_submit(desc) < 0) { 104 dev_err(dev, "dmaengine_submit() fail\n"); 105 return; 106 } 107 108 dma_async_issue_pending(dmaen->chan); 109 } 110 111 struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, 112 struct rsnd_mod *mod, char *name) 113 { 114 struct dma_chan *chan; 115 struct device_node *np; 116 int i = 0; 117 118 for_each_child_of_node(of_node, np) { 119 if (i == rsnd_mod_id(mod)) 120 break; 121 i++; 122 } 123 124 chan = of_dma_request_slave_channel(np, name); 125 126 of_node_put(np); 127 of_node_put(of_node); 128 129 return chan; 130 } 131 132 static struct dma_chan *rsnd_dmaen_request_channel(struct rsnd_dai_stream *io, 133 struct rsnd_mod *mod_from, 134 struct rsnd_mod *mod_to) 135 { 136 if ((!mod_from && !mod_to) || 137 (mod_from && mod_to)) 138 return NULL; 139 140 if (mod_from) 141 return rsnd_mod_dma_req(io, mod_from); 142 else 143 return rsnd_mod_dma_req(io, mod_to); 144 } 145 146 static int rsnd_dmaen_init(struct rsnd_dai_stream *io, 147 struct rsnd_dma *dma, int id, 148 struct rsnd_mod *mod_from, struct rsnd_mod *mod_to) 149 { 150 struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma); 151 struct rsnd_priv *priv = rsnd_io_to_priv(io); 152 struct device *dev = rsnd_priv_to_dev(priv); 153 struct dma_slave_config cfg = {}; 154 int is_play = rsnd_io_is_play(io); 155 int ret; 156 157 if (dmaen->chan) { 158 dev_err(dev, "it already has dma channel\n"); 159 return -EIO; 160 } 161 162 if (dev->of_node) { 163 dmaen->chan = rsnd_dmaen_request_channel(io, mod_from, mod_to); 164 } else { 165 dma_cap_mask_t mask; 166 167 dma_cap_zero(mask); 168 dma_cap_set(DMA_SLAVE, mask); 169 170 dmaen->chan = dma_request_channel(mask, shdma_chan_filter, 171 (void *)id); 172 } 173 if (IS_ERR_OR_NULL(dmaen->chan)) { 174 dmaen->chan = NULL; 175 dev_err(dev, "can't get dma channel\n"); 176 goto rsnd_dma_channel_err; 177 } 178 179 cfg.direction = is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM; 180 cfg.src_addr = dma->src_addr; 181 cfg.dst_addr = dma->dst_addr; 182 cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 183 cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 184 185 dev_dbg(dev, "dma : %pad -> %pad\n", 186 &cfg.src_addr, &cfg.dst_addr); 187 188 ret = dmaengine_slave_config(dmaen->chan, &cfg); 189 if (ret < 0) 190 goto rsnd_dma_init_err; 191 192 return 0; 193 194 rsnd_dma_init_err: 195 rsnd_dma_quit(io, dma); 196 rsnd_dma_channel_err: 197 198 /* 199 * DMA failed. try to PIO mode 200 * see 201 * rsnd_ssi_fallback() 202 * rsnd_rdai_continuance_probe() 203 */ 204 return -EAGAIN; 205 } 206 207 static void rsnd_dmaen_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma) 208 { 209 struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma); 210 211 if (dmaen->chan) 212 dma_release_channel(dmaen->chan); 213 214 dmaen->chan = NULL; 215 } 216 217 static struct rsnd_dma_ops rsnd_dmaen_ops = { 218 .start = rsnd_dmaen_start, 219 .stop = rsnd_dmaen_stop, 220 .init = rsnd_dmaen_init, 221 .quit = rsnd_dmaen_quit, 222 }; 223 224 /* 225 * Audio DMAC peri peri 226 */ 227 static const u8 gen2_id_table_ssiu[] = { 228 0x00, /* SSI00 */ 229 0x04, /* SSI10 */ 230 0x08, /* SSI20 */ 231 0x0c, /* SSI3 */ 232 0x0d, /* SSI4 */ 233 0x0e, /* SSI5 */ 234 0x0f, /* SSI6 */ 235 0x10, /* SSI7 */ 236 0x11, /* SSI8 */ 237 0x12, /* SSI90 */ 238 }; 239 static const u8 gen2_id_table_scu[] = { 240 0x2d, /* SCU_SRCI0 */ 241 0x2e, /* SCU_SRCI1 */ 242 0x2f, /* SCU_SRCI2 */ 243 0x30, /* SCU_SRCI3 */ 244 0x31, /* SCU_SRCI4 */ 245 0x32, /* SCU_SRCI5 */ 246 0x33, /* SCU_SRCI6 */ 247 0x34, /* SCU_SRCI7 */ 248 0x35, /* SCU_SRCI8 */ 249 0x36, /* SCU_SRCI9 */ 250 }; 251 static const u8 gen2_id_table_cmd[] = { 252 0x37, /* SCU_CMD0 */ 253 0x38, /* SCU_CMD1 */ 254 }; 255 256 static u32 rsnd_dmapp_get_id(struct rsnd_dai_stream *io, 257 struct rsnd_mod *mod) 258 { 259 struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io); 260 struct rsnd_mod *src = rsnd_io_to_mod_src(io); 261 struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io); 262 const u8 *entry = NULL; 263 int id = rsnd_mod_id(mod); 264 int size = 0; 265 266 if (mod == ssi) { 267 entry = gen2_id_table_ssiu; 268 size = ARRAY_SIZE(gen2_id_table_ssiu); 269 } else if (mod == src) { 270 entry = gen2_id_table_scu; 271 size = ARRAY_SIZE(gen2_id_table_scu); 272 } else if (mod == dvc) { 273 entry = gen2_id_table_cmd; 274 size = ARRAY_SIZE(gen2_id_table_cmd); 275 } 276 277 if (!entry) 278 return 0xFF; 279 280 if (size <= id) 281 return 0xFF; 282 283 return entry[id]; 284 } 285 286 static u32 rsnd_dmapp_get_chcr(struct rsnd_dai_stream *io, 287 struct rsnd_mod *mod_from, 288 struct rsnd_mod *mod_to) 289 { 290 return (rsnd_dmapp_get_id(io, mod_from) << 24) + 291 (rsnd_dmapp_get_id(io, mod_to) << 16); 292 } 293 294 #define rsnd_dmapp_addr(dmac, dma, reg) \ 295 (dmac->base + 0x20 + reg + \ 296 (0x10 * rsnd_dma_to_dmapp(dma)->dmapp_id)) 297 static void rsnd_dmapp_write(struct rsnd_dma *dma, u32 data, u32 reg) 298 { 299 struct rsnd_mod *mod = rsnd_dma_to_mod(dma); 300 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 301 struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); 302 struct device *dev = rsnd_priv_to_dev(priv); 303 304 dev_dbg(dev, "w %p : %08x\n", rsnd_dmapp_addr(dmac, dma, reg), data); 305 306 iowrite32(data, rsnd_dmapp_addr(dmac, dma, reg)); 307 } 308 309 static u32 rsnd_dmapp_read(struct rsnd_dma *dma, u32 reg) 310 { 311 struct rsnd_mod *mod = rsnd_dma_to_mod(dma); 312 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 313 struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); 314 315 return ioread32(rsnd_dmapp_addr(dmac, dma, reg)); 316 } 317 318 static void rsnd_dmapp_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma) 319 { 320 int i; 321 322 rsnd_dmapp_write(dma, 0, PDMACHCR); 323 324 for (i = 0; i < 1024; i++) { 325 if (0 == rsnd_dmapp_read(dma, PDMACHCR)) 326 return; 327 udelay(1); 328 } 329 } 330 331 static void rsnd_dmapp_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma) 332 { 333 struct rsnd_dmapp *dmapp = rsnd_dma_to_dmapp(dma); 334 335 rsnd_dmapp_write(dma, dma->src_addr, PDMASAR); 336 rsnd_dmapp_write(dma, dma->dst_addr, PDMADAR); 337 rsnd_dmapp_write(dma, dmapp->chcr, PDMACHCR); 338 } 339 340 static int rsnd_dmapp_init(struct rsnd_dai_stream *io, 341 struct rsnd_dma *dma, int id, 342 struct rsnd_mod *mod_from, struct rsnd_mod *mod_to) 343 { 344 struct rsnd_dmapp *dmapp = rsnd_dma_to_dmapp(dma); 345 struct rsnd_priv *priv = rsnd_io_to_priv(io); 346 struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); 347 struct device *dev = rsnd_priv_to_dev(priv); 348 349 dmapp->dmapp_id = dmac->dmapp_num; 350 dmapp->chcr = rsnd_dmapp_get_chcr(io, mod_from, mod_to) | PDMACHCR_DE; 351 352 dmac->dmapp_num++; 353 354 rsnd_dmapp_stop(io, dma); 355 356 dev_dbg(dev, "id/src/dst/chcr = %d/%pad/%pad/%08x\n", 357 dmapp->dmapp_id, &dma->src_addr, &dma->dst_addr, dmapp->chcr); 358 359 return 0; 360 } 361 362 static struct rsnd_dma_ops rsnd_dmapp_ops = { 363 .start = rsnd_dmapp_start, 364 .stop = rsnd_dmapp_stop, 365 .init = rsnd_dmapp_init, 366 .quit = rsnd_dmapp_stop, 367 }; 368 369 /* 370 * Common DMAC Interface 371 */ 372 373 /* 374 * DMA read/write register offset 375 * 376 * RSND_xxx_I_N for Audio DMAC input 377 * RSND_xxx_O_N for Audio DMAC output 378 * RSND_xxx_I_P for Audio DMAC peri peri input 379 * RSND_xxx_O_P for Audio DMAC peri peri output 380 * 381 * ex) R-Car H2 case 382 * mod / DMAC in / DMAC out / DMAC PP in / DMAC pp out 383 * SSI : 0xec541000 / 0xec241008 / 0xec24100c 384 * SSIU: 0xec541000 / 0xec100000 / 0xec100000 / 0xec400000 / 0xec400000 385 * SCU : 0xec500000 / 0xec000000 / 0xec004000 / 0xec300000 / 0xec304000 386 * CMD : 0xec500000 / / 0xec008000 0xec308000 387 */ 388 #define RDMA_SSI_I_N(addr, i) (addr ##_reg - 0x00300000 + (0x40 * i) + 0x8) 389 #define RDMA_SSI_O_N(addr, i) (addr ##_reg - 0x00300000 + (0x40 * i) + 0xc) 390 391 #define RDMA_SSIU_I_N(addr, i) (addr ##_reg - 0x00441000 + (0x1000 * i)) 392 #define RDMA_SSIU_O_N(addr, i) (addr ##_reg - 0x00441000 + (0x1000 * i)) 393 394 #define RDMA_SSIU_I_P(addr, i) (addr ##_reg - 0x00141000 + (0x1000 * i)) 395 #define RDMA_SSIU_O_P(addr, i) (addr ##_reg - 0x00141000 + (0x1000 * i)) 396 397 #define RDMA_SRC_I_N(addr, i) (addr ##_reg - 0x00500000 + (0x400 * i)) 398 #define RDMA_SRC_O_N(addr, i) (addr ##_reg - 0x004fc000 + (0x400 * i)) 399 400 #define RDMA_SRC_I_P(addr, i) (addr ##_reg - 0x00200000 + (0x400 * i)) 401 #define RDMA_SRC_O_P(addr, i) (addr ##_reg - 0x001fc000 + (0x400 * i)) 402 403 #define RDMA_CMD_O_N(addr, i) (addr ##_reg - 0x004f8000 + (0x400 * i)) 404 #define RDMA_CMD_O_P(addr, i) (addr ##_reg - 0x001f8000 + (0x400 * i)) 405 406 static dma_addr_t 407 rsnd_gen2_dma_addr(struct rsnd_dai_stream *io, 408 struct rsnd_mod *mod, 409 int is_play, int is_from) 410 { 411 struct rsnd_priv *priv = rsnd_io_to_priv(io); 412 struct device *dev = rsnd_priv_to_dev(priv); 413 phys_addr_t ssi_reg = rsnd_gen_get_phy_addr(priv, RSND_GEN2_SSI); 414 phys_addr_t src_reg = rsnd_gen_get_phy_addr(priv, RSND_GEN2_SCU); 415 int is_ssi = !!(rsnd_io_to_mod_ssi(io) == mod); 416 int use_src = !!rsnd_io_to_mod_src(io); 417 int use_dvc = !!rsnd_io_to_mod_dvc(io); 418 int id = rsnd_mod_id(mod); 419 struct dma_addr { 420 dma_addr_t out_addr; 421 dma_addr_t in_addr; 422 } dma_addrs[3][2][3] = { 423 /* SRC */ 424 {{{ 0, 0 }, 425 /* Capture */ 426 { RDMA_SRC_O_N(src, id), RDMA_SRC_I_P(src, id) }, 427 { RDMA_CMD_O_N(src, id), RDMA_SRC_I_P(src, id) } }, 428 /* Playback */ 429 {{ 0, 0, }, 430 { RDMA_SRC_O_P(src, id), RDMA_SRC_I_N(src, id) }, 431 { RDMA_CMD_O_P(src, id), RDMA_SRC_I_N(src, id) } } 432 }, 433 /* SSI */ 434 /* Capture */ 435 {{{ RDMA_SSI_O_N(ssi, id), 0 }, 436 { RDMA_SSIU_O_P(ssi, id), 0 }, 437 { RDMA_SSIU_O_P(ssi, id), 0 } }, 438 /* Playback */ 439 {{ 0, RDMA_SSI_I_N(ssi, id) }, 440 { 0, RDMA_SSIU_I_P(ssi, id) }, 441 { 0, RDMA_SSIU_I_P(ssi, id) } } 442 }, 443 /* SSIU */ 444 /* Capture */ 445 {{{ RDMA_SSIU_O_N(ssi, id), 0 }, 446 { RDMA_SSIU_O_P(ssi, id), 0 }, 447 { RDMA_SSIU_O_P(ssi, id), 0 } }, 448 /* Playback */ 449 {{ 0, RDMA_SSIU_I_N(ssi, id) }, 450 { 0, RDMA_SSIU_I_P(ssi, id) }, 451 { 0, RDMA_SSIU_I_P(ssi, id) } } }, 452 }; 453 454 /* it shouldn't happen */ 455 if (use_dvc && !use_src) 456 dev_err(dev, "DVC is selected without SRC\n"); 457 458 /* use SSIU or SSI ? */ 459 if (is_ssi && rsnd_ssi_use_busif(io, mod)) 460 is_ssi++; 461 462 return (is_from) ? 463 dma_addrs[is_ssi][is_play][use_src + use_dvc].out_addr : 464 dma_addrs[is_ssi][is_play][use_src + use_dvc].in_addr; 465 } 466 467 static dma_addr_t rsnd_dma_addr(struct rsnd_dai_stream *io, 468 struct rsnd_mod *mod, 469 int is_play, int is_from) 470 { 471 struct rsnd_priv *priv = rsnd_io_to_priv(io); 472 473 /* 474 * gen1 uses default DMA addr 475 */ 476 if (rsnd_is_gen1(priv)) 477 return 0; 478 479 if (!mod) 480 return 0; 481 482 return rsnd_gen2_dma_addr(io, mod, is_play, is_from); 483 } 484 485 #define MOD_MAX 4 /* MEM/SSI/SRC/DVC */ 486 static void rsnd_dma_of_path(struct rsnd_dma *dma, 487 struct rsnd_dai_stream *io, 488 int is_play, 489 struct rsnd_mod **mod_from, 490 struct rsnd_mod **mod_to) 491 { 492 struct rsnd_mod *this = rsnd_dma_to_mod(dma); 493 struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io); 494 struct rsnd_mod *src = rsnd_io_to_mod_src(io); 495 struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io); 496 struct rsnd_mod *mod[MOD_MAX]; 497 int i, index; 498 499 500 for (i = 0; i < MOD_MAX; i++) 501 mod[i] = NULL; 502 503 /* 504 * in play case... 505 * 506 * src -> dst 507 * 508 * mem -> SSI 509 * mem -> SRC -> SSI 510 * mem -> SRC -> DVC -> SSI 511 */ 512 mod[0] = NULL; /* for "mem" */ 513 index = 1; 514 for (i = 1; i < MOD_MAX; i++) { 515 if (!src) { 516 mod[i] = ssi; 517 } else if (!dvc) { 518 mod[i] = src; 519 src = NULL; 520 } else { 521 if ((!is_play) && (this == src)) 522 this = dvc; 523 524 mod[i] = (is_play) ? src : dvc; 525 i++; 526 mod[i] = (is_play) ? dvc : src; 527 src = NULL; 528 dvc = NULL; 529 } 530 531 if (mod[i] == this) 532 index = i; 533 534 if (mod[i] == ssi) 535 break; 536 } 537 538 if (is_play) { 539 *mod_from = mod[index - 1]; 540 *mod_to = mod[index]; 541 } else { 542 *mod_from = mod[index]; 543 *mod_to = mod[index - 1]; 544 } 545 } 546 547 void rsnd_dma_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma) 548 { 549 dma->ops->stop(io, dma); 550 } 551 552 void rsnd_dma_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma) 553 { 554 dma->ops->start(io, dma); 555 } 556 557 void rsnd_dma_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma) 558 { 559 struct rsnd_mod *mod = rsnd_dma_to_mod(dma); 560 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 561 struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); 562 563 if (!dmac) 564 return; 565 566 dma->ops->quit(io, dma); 567 } 568 569 int rsnd_dma_init(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id) 570 { 571 struct rsnd_mod *mod_from; 572 struct rsnd_mod *mod_to; 573 struct rsnd_priv *priv = rsnd_io_to_priv(io); 574 struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); 575 int is_play = rsnd_io_is_play(io); 576 577 /* 578 * DMA failed. try to PIO mode 579 * see 580 * rsnd_ssi_fallback() 581 * rsnd_rdai_continuance_probe() 582 */ 583 if (!dmac) 584 return -EAGAIN; 585 586 rsnd_dma_of_path(dma, io, is_play, &mod_from, &mod_to); 587 588 dma->src_addr = rsnd_dma_addr(io, mod_from, is_play, 1); 589 dma->dst_addr = rsnd_dma_addr(io, mod_to, is_play, 0); 590 591 /* for Gen2 */ 592 if (mod_from && mod_to) 593 dma->ops = &rsnd_dmapp_ops; 594 else 595 dma->ops = &rsnd_dmaen_ops; 596 597 /* for Gen1, overwrite */ 598 if (rsnd_is_gen1(priv)) 599 dma->ops = &rsnd_dmaen_ops; 600 601 return dma->ops->init(io, dma, id, mod_from, mod_to); 602 } 603 604 int rsnd_dma_probe(struct platform_device *pdev, 605 const struct rsnd_of_data *of_data, 606 struct rsnd_priv *priv) 607 { 608 struct device *dev = rsnd_priv_to_dev(priv); 609 struct rsnd_dma_ctrl *dmac; 610 struct resource *res; 611 612 /* 613 * for Gen1 614 */ 615 if (rsnd_is_gen1(priv)) 616 return 0; 617 618 /* 619 * for Gen2 620 */ 621 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "audmapp"); 622 dmac = devm_kzalloc(dev, sizeof(*dmac), GFP_KERNEL); 623 if (!dmac || !res) { 624 dev_err(dev, "dma allocate failed\n"); 625 return 0; /* it will be PIO mode */ 626 } 627 628 dmac->dmapp_num = 0; 629 dmac->base = devm_ioremap_resource(dev, res); 630 if (IS_ERR(dmac->base)) 631 return PTR_ERR(dmac->base); 632 633 priv->dma = dmac; 634 635 return 0; 636 } 637