Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2722440imm; Tue, 4 Sep 2018 09:00:38 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ1SiVzDpMLD9mPWldeIU64rDCMczyosOWCuUQ4lNFiSqoXoi1AYt7ofc6ntBnFM9Q0lj6c X-Received: by 2002:a65:48c6:: with SMTP id o6-v6mr30907873pgs.99.1536076838706; Tue, 04 Sep 2018 09:00:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536076838; cv=none; d=google.com; s=arc-20160816; b=JGOD2YucxhCc/I8rQMWuXe4iqaItWtpB6CwafopzusQpfbm5rCdeYvxHV2NstD4XnN NZCydqbX+mx4NdS3Uu7McumY0KjKmjcBdf+GXUwlfkkIjV9xvftRR169XR8pJy3+hOh+ YDgZBkTHCmA3BQTjZiJ1F9qSi1EqfzODfB78IAU6ciIUJEMlMWEH3tIz1sfG0BiVGHCx nLocEJYYZRlGvzXyUbiBALHXU+AfCihtT9kCeDrMcX/ESPyDTGJ2L5GrHTBVwCkoP2sL sNljO0PQTxI0Ne8PBZkgCuetxAn5LhgqVOYwVtz0WIhpCnE4FHjxJMmHDeW8M5kLwelK i6Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=w55efZLiHDEGL0p+Ujg6lYAC29L5PKGZNBsatKqUV1A=; b=v9iS4k1fTWMjd3z6xLnu7Dxes0Bf8bOkUmBh6DRF2nL9qx65uFhjd5boaWP8jJ5Lov tYgWPUUEB7TIiVLHS9Wo8aG6vx/Ti+vkonaR6Cph6B0KMi7iD0eivHVT182WOPJNplN+ L3y3DxP9B+cdguMlITr8ytMaYXree83zPpvkxtymVgMEtrct+EWZgNSsiif1aqC1sm9N MShLxzNpXLwnSKUcGxogS+FcYrm+ChlvBB/2caPUOJEV3WpgdH2G7HV5b85Q9dIo1BRi wOZkbmaIqBsVb5j9KaCpSc4sOuCXvkjo6C7u7YGBjj/zTM5e8LwYpjJ8Lu3jrbjO5Q74 c2Mw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h23-v6si3432854pgv.356.2018.09.04.09.00.22; Tue, 04 Sep 2018 09:00:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728006AbeIDUYx (ORCPT + 99 others); Tue, 4 Sep 2018 16:24:53 -0400 Received: from mx2.suse.de ([195.135.220.15]:51016 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727802AbeIDUYv (ORCPT ); Tue, 4 Sep 2018 16:24:51 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id ECF2EB0B6; Tue, 4 Sep 2018 15:59:02 +0000 (UTC) From: Takashi Iwai To: Greg Kroah-Hartman Cc: Eric Anholt , Stefan Wahren , linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 27/29] staging: bcm2835-audio: Simplify PCM creation helpers Date: Tue, 4 Sep 2018 17:58:56 +0200 Message-Id: <20180904155858.8001-28-tiwai@suse.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904155858.8001-1-tiwai@suse.de> References: <20180904155858.8001-1-tiwai@suse.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org All three functions to create PCM objects are fairly resemble, and can be unified to a single common helper. Signed-off-by: Takashi Iwai --- .../vc04_services/bcm2835-audio/bcm2835-pcm.c | 87 ++++--------------- .../vc04_services/bcm2835-audio/bcm2835.c | 17 +++- .../vc04_services/bcm2835-audio/bcm2835.h | 9 +- 3 files changed, 32 insertions(+), 81 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c index 5ddb8ee93cb2..98480d97cc2e 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c @@ -324,91 +324,36 @@ static const struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = { }; /* create a pcm device */ -int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, u32 numchannels) +int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, const char *name, + int idx, enum snd_bcm2835_route route, + u32 numchannels, bool spdif) { struct snd_pcm *pcm; int err; - err = snd_pcm_new(chip->card, "bcm2835 ALSA", 0, numchannels, 0, &pcm); - if (err < 0) - return err; - pcm->private_data = chip; - pcm->nonatomic = true; - strcpy(pcm->name, "bcm2835 ALSA"); - chip->pcm = pcm; - chip->dest = AUDIO_DEST_AUTO; - chip->volume = 0; - chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */ - /* set operators */ - snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, - &snd_bcm2835_playback_ops); - - /* pre-allocation of buffers */ - /* NOTE: this may fail */ - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, - chip->card->dev->parent, - snd_bcm2835_playback_hw.buffer_bytes_max, - snd_bcm2835_playback_hw.buffer_bytes_max); - - return 0; -} - -int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip) -{ - struct snd_pcm *pcm; - int err; - - err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm); - if (err < 0) - return err; - - pcm->private_data = chip; - pcm->nonatomic = true; - strcpy(pcm->name, "bcm2835 IEC958/HDMI"); - chip->pcm_spdif = pcm; - snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, - &snd_bcm2835_playback_spdif_ops); - - /* pre-allocation of buffers */ - /* NOTE: this may fail */ - snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, - chip->card->dev->parent, - snd_bcm2835_playback_spdif_hw.buffer_bytes_max, snd_bcm2835_playback_spdif_hw.buffer_bytes_max); - - return 0; -} - -int snd_bcm2835_new_simple_pcm(struct bcm2835_chip *chip, - const char *name, - enum snd_bcm2835_route route, - u32 numchannels) -{ - struct snd_pcm *pcm; - int err; - - err = snd_pcm_new(chip->card, name, 0, numchannels, - 0, &pcm); + err = snd_pcm_new(chip->card, name, idx, numchannels, 0, &pcm); if (err) return err; pcm->private_data = chip; pcm->nonatomic = true; strcpy(pcm->name, name); - chip->pcm = pcm; - chip->dest = route; - chip->volume = 0; - chip->mute = CTRL_VOL_UNMUTE; + if (!spdif) { + chip->dest = route; + chip->volume = 0; + chip->mute = CTRL_VOL_UNMUTE; + } snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, + spdif ? &snd_bcm2835_playback_spdif_ops : &snd_bcm2835_playback_ops); - snd_pcm_lib_preallocate_pages_for_all( - pcm, - SNDRV_DMA_TYPE_DEV, - chip->card->dev->parent, - snd_bcm2835_playback_hw.buffer_bytes_max, - snd_bcm2835_playback_hw.buffer_bytes_max); + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, + chip->card->dev->parent, 128 * 1024, 128 * 1024); + if (spdif) + chip->pcm_spdif = pcm; + else + chip->pcm = pcm; return 0; } - diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c index 8a87c33b1ea9..2869f310086f 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c @@ -138,17 +138,26 @@ static int bcm2835_audio_alsa_newpcm(struct bcm2835_chip *chip, { int err; - err = snd_bcm2835_new_pcm(chip, numchannels - 1); + err = snd_bcm2835_new_pcm(chip, "bcm2835 ALSA", 0, AUDIO_DEST_AUTO, + numchannels - 1, false); if (err) return err; - err = snd_bcm2835_new_spdif_pcm(chip); + err = snd_bcm2835_new_pcm(chip, "bcm2835 IEC958/HDMI", 1, 0, 1, true); if (err) return err; return 0; } +static int bcm2835_audio_simple_newpcm(struct bcm2835_chip *chip, + const char *name, + enum snd_bcm2835_route route, + u32 numchannels) +{ + return snd_bcm2835_new_pcm(chip, name, 0, route, numchannels, false); +} + static struct bcm2835_audio_driver bcm2835_audio_alsa = { .driver = { .name = "bcm2835_alsa", @@ -169,7 +178,7 @@ static struct bcm2835_audio_driver bcm2835_audio_hdmi = { .shortname = "bcm2835 HDMI", .longname = "bcm2835 HDMI", .minchannels = 1, - .newpcm = snd_bcm2835_new_simple_pcm, + .newpcm = bcm2835_audio_simple_newpcm, .newctl = snd_bcm2835_new_hdmi_ctl, .route = AUDIO_DEST_HDMI }; @@ -182,7 +191,7 @@ static struct bcm2835_audio_driver bcm2835_audio_headphones = { .shortname = "bcm2835 Headphones", .longname = "bcm2835 Headphones", .minchannels = 1, - .newpcm = snd_bcm2835_new_simple_pcm, + .newpcm = bcm2835_audio_simple_newpcm, .newctl = snd_bcm2835_new_headphones_ctl, .route = AUDIO_DEST_HEADPHONES }; diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h index 4e41069dc22a..e13435d1c205 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h @@ -84,12 +84,9 @@ struct bcm2835_alsa_stream { }; int snd_bcm2835_new_ctl(struct bcm2835_chip *chip); -int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, u32 numchannels); -int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip); -int snd_bcm2835_new_simple_pcm(struct bcm2835_chip *chip, - const char *name, - enum snd_bcm2835_route route, - u32 numchannels); +int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, const char *name, + int idx, enum snd_bcm2835_route route, + u32 numchannels, bool spdif); int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip); int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip); -- 2.18.0