| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Xtfpga I2S controller driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (c) 2014 Cadence Design Systems Inc. |
|---|
| 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 | 6 | */ |
|---|
| 10 | 7 | |
|---|
| 11 | 8 | #include <linux/clk.h> |
|---|
| .. | .. |
|---|
| 368 | 365 | .fifo_size = 16, |
|---|
| 369 | 366 | }; |
|---|
| 370 | 367 | |
|---|
| 371 | | -static int xtfpga_pcm_open(struct snd_pcm_substream *substream) |
|---|
| 368 | +static int xtfpga_pcm_open(struct snd_soc_component *component, |
|---|
| 369 | + struct snd_pcm_substream *substream) |
|---|
| 372 | 370 | { |
|---|
| 373 | 371 | struct snd_pcm_runtime *runtime = substream->runtime; |
|---|
| 374 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
|---|
| 372 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
|---|
| 375 | 373 | void *p; |
|---|
| 376 | 374 | |
|---|
| 377 | 375 | snd_soc_set_runtime_hwparams(substream, &xtfpga_pcm_hardware); |
|---|
| 378 | | - p = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); |
|---|
| 376 | + p = snd_soc_dai_get_dma_data(asoc_rtd_to_cpu(rtd, 0), substream); |
|---|
| 379 | 377 | runtime->private_data = p; |
|---|
| 380 | 378 | |
|---|
| 381 | 379 | return 0; |
|---|
| 382 | 380 | } |
|---|
| 383 | 381 | |
|---|
| 384 | | -static int xtfpga_pcm_close(struct snd_pcm_substream *substream) |
|---|
| 382 | +static int xtfpga_pcm_close(struct snd_soc_component *component, |
|---|
| 383 | + struct snd_pcm_substream *substream) |
|---|
| 385 | 384 | { |
|---|
| 386 | 385 | synchronize_rcu(); |
|---|
| 387 | 386 | return 0; |
|---|
| 388 | 387 | } |
|---|
| 389 | 388 | |
|---|
| 390 | | -static int xtfpga_pcm_hw_params(struct snd_pcm_substream *substream, |
|---|
| 389 | +static int xtfpga_pcm_hw_params(struct snd_soc_component *component, |
|---|
| 390 | + struct snd_pcm_substream *substream, |
|---|
| 391 | 391 | struct snd_pcm_hw_params *hw_params) |
|---|
| 392 | 392 | { |
|---|
| 393 | | - int ret; |
|---|
| 394 | 393 | struct snd_pcm_runtime *runtime = substream->runtime; |
|---|
| 395 | 394 | struct xtfpga_i2s *i2s = runtime->private_data; |
|---|
| 396 | 395 | unsigned channels = params_channels(hw_params); |
|---|
| .. | .. |
|---|
| 422 | 421 | return -EINVAL; |
|---|
| 423 | 422 | } |
|---|
| 424 | 423 | |
|---|
| 425 | | - ret = snd_pcm_lib_malloc_pages(substream, |
|---|
| 426 | | - params_buffer_bytes(hw_params)); |
|---|
| 427 | | - return ret; |
|---|
| 424 | + return 0; |
|---|
| 428 | 425 | } |
|---|
| 429 | 426 | |
|---|
| 430 | | -static int xtfpga_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
|---|
| 427 | +static int xtfpga_pcm_trigger(struct snd_soc_component *component, |
|---|
| 428 | + struct snd_pcm_substream *substream, int cmd) |
|---|
| 431 | 429 | { |
|---|
| 432 | 430 | int ret = 0; |
|---|
| 433 | 431 | struct snd_pcm_runtime *runtime = substream->runtime; |
|---|
| .. | .. |
|---|
| 455 | 453 | return ret; |
|---|
| 456 | 454 | } |
|---|
| 457 | 455 | |
|---|
| 458 | | -static snd_pcm_uframes_t xtfpga_pcm_pointer(struct snd_pcm_substream *substream) |
|---|
| 456 | +static snd_pcm_uframes_t xtfpga_pcm_pointer(struct snd_soc_component *component, |
|---|
| 457 | + struct snd_pcm_substream *substream) |
|---|
| 459 | 458 | { |
|---|
| 460 | 459 | struct snd_pcm_runtime *runtime = substream->runtime; |
|---|
| 461 | 460 | struct xtfpga_i2s *i2s = runtime->private_data; |
|---|
| .. | .. |
|---|
| 464 | 463 | return pos < runtime->buffer_size ? pos : 0; |
|---|
| 465 | 464 | } |
|---|
| 466 | 465 | |
|---|
| 467 | | -static int xtfpga_pcm_new(struct snd_soc_pcm_runtime *rtd) |
|---|
| 466 | +static int xtfpga_pcm_new(struct snd_soc_component *component, |
|---|
| 467 | + struct snd_soc_pcm_runtime *rtd) |
|---|
| 468 | 468 | { |
|---|
| 469 | 469 | struct snd_card *card = rtd->card->snd_card; |
|---|
| 470 | 470 | size_t size = xtfpga_pcm_hardware.buffer_bytes_max; |
|---|
| 471 | 471 | |
|---|
| 472 | | - return snd_pcm_lib_preallocate_pages_for_all(rtd->pcm, |
|---|
| 473 | | - SNDRV_DMA_TYPE_DEV, |
|---|
| 474 | | - card->dev, size, size); |
|---|
| 472 | + snd_pcm_set_managed_buffer_all(rtd->pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 473 | + card->dev, size, size); |
|---|
| 474 | + return 0; |
|---|
| 475 | 475 | } |
|---|
| 476 | | - |
|---|
| 477 | | -static const struct snd_pcm_ops xtfpga_pcm_ops = { |
|---|
| 478 | | - .open = xtfpga_pcm_open, |
|---|
| 479 | | - .close = xtfpga_pcm_close, |
|---|
| 480 | | - .ioctl = snd_pcm_lib_ioctl, |
|---|
| 481 | | - .hw_params = xtfpga_pcm_hw_params, |
|---|
| 482 | | - .trigger = xtfpga_pcm_trigger, |
|---|
| 483 | | - .pointer = xtfpga_pcm_pointer, |
|---|
| 484 | | -}; |
|---|
| 485 | 476 | |
|---|
| 486 | 477 | static const struct snd_soc_component_driver xtfpga_i2s_component = { |
|---|
| 487 | 478 | .name = DRV_NAME, |
|---|
| 488 | | - .pcm_new = xtfpga_pcm_new, |
|---|
| 489 | | - .ops = &xtfpga_pcm_ops, |
|---|
| 479 | + .open = xtfpga_pcm_open, |
|---|
| 480 | + .close = xtfpga_pcm_close, |
|---|
| 481 | + .hw_params = xtfpga_pcm_hw_params, |
|---|
| 482 | + .trigger = xtfpga_pcm_trigger, |
|---|
| 483 | + .pointer = xtfpga_pcm_pointer, |
|---|
| 484 | + .pcm_construct = xtfpga_pcm_new, |
|---|
| 490 | 485 | }; |
|---|
| 491 | 486 | |
|---|
| 492 | 487 | static const struct snd_soc_dai_ops xtfpga_i2s_dai_ops = { |
|---|
| .. | .. |
|---|
| 534 | 529 | static int xtfpga_i2s_probe(struct platform_device *pdev) |
|---|
| 535 | 530 | { |
|---|
| 536 | 531 | struct xtfpga_i2s *i2s; |
|---|
| 537 | | - struct resource *mem; |
|---|
| 538 | 532 | int err, irq; |
|---|
| 539 | 533 | |
|---|
| 540 | 534 | i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 546 | 540 | i2s->dev = &pdev->dev; |
|---|
| 547 | 541 | dev_dbg(&pdev->dev, "dev: %p, i2s: %p\n", &pdev->dev, i2s); |
|---|
| 548 | 542 | |
|---|
| 549 | | - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 550 | | - i2s->regs = devm_ioremap_resource(&pdev->dev, mem); |
|---|
| 543 | + i2s->regs = devm_platform_ioremap_resource(pdev, 0); |
|---|
| 551 | 544 | if (IS_ERR(i2s->regs)) { |
|---|
| 552 | 545 | err = PTR_ERR(i2s->regs); |
|---|
| 553 | 546 | goto err; |
|---|
| .. | .. |
|---|
| 575 | 568 | |
|---|
| 576 | 569 | irq = platform_get_irq(pdev, 0); |
|---|
| 577 | 570 | if (irq < 0) { |
|---|
| 578 | | - dev_err(&pdev->dev, "No IRQ resource\n"); |
|---|
| 579 | 571 | err = irq; |
|---|
| 580 | 572 | goto err; |
|---|
| 581 | 573 | } |
|---|