From patchwork Tue Apr 29 07:56:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 4085531 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 088CA9F38E for ; Tue, 29 Apr 2014 07:57:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 31F7C201F5 for ; Tue, 29 Apr 2014 07:57:30 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 1E1E5201F2 for ; Tue, 29 Apr 2014 07:57:29 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 32666264F0F; Tue, 29 Apr 2014 09:57:28 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id D3D5E264F1D; Tue, 29 Apr 2014 09:56:02 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id B5454264F10; Tue, 29 Apr 2014 09:55:59 +0200 (CEST) Received: from gw01.mail.saunalahti.fi (gw01.mail.saunalahti.fi [195.197.172.115]) by alsa0.perex.cz (Postfix) with ESMTP id 3A8E8262600 for ; Tue, 29 Apr 2014 09:55:52 +0200 (CEST) Received: from localhost.localdomain (a91-152-110-231.elisa-laajakaista.fi [91.152.110.231]) by gw01.mail.saunalahti.fi (Postfix) with ESMTP id C28C2406CB; Tue, 29 Apr 2014 10:55:48 +0300 (EEST) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.14.7/8.14.7) with ESMTP id s3T7uBZd015730; Tue, 29 Apr 2014 10:56:11 +0300 Received: (from andy@localhost) by localhost.localdomain (8.14.7/8.14.7/Submit) id s3T7uBpP015729; Tue, 29 Apr 2014 10:56:11 +0300 X-Authentication-Warning: localhost.localdomain: andy set sender to andy.shevchenko@gmail.com using -f From: Andy Shevchenko To: alsa-devel@alsa-project.org, Takashi Iwai Date: Tue, 29 Apr 2014 10:56:05 +0300 Message-Id: <1398758165-15671-4-git-send-email-andy.shevchenko@gmail.com> X-Mailer: git-send-email 1.8.3.101.g727a46b In-Reply-To: <1398758165-15671-1-git-send-email-andy.shevchenko@gmail.com> References: <1398758165-15671-1-git-send-email-andy.shevchenko@gmail.com> Cc: Andy Shevchenko Subject: [alsa-devel] [PATCH 2/2] fm801: introduce __is_ready()/__is_valid() helpers X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP The introduced functios check AC97 if it's ready for communication and read data is valid. Signed-off-by: Andy Shevchenko --- sound/pci/fm801.c | 86 +++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c index 8418484..4417409 100644 --- a/sound/pci/fm801.c +++ b/sound/pci/fm801.c @@ -224,6 +224,30 @@ MODULE_DEVICE_TABLE(pci, snd_fm801_ids); * common I/O routines */ +static inline bool __is_ready(struct fm801 *chip, unsigned int iterations) +{ + unsigned int idx; + + for (idx = 0; idx < iterations; idx++) { + if (!(fm801_readw(chip, AC97_CMD) & FM801_AC97_BUSY)) + return true; + udelay(10); + } + return false; +} + +static inline bool __is_valid(struct fm801 *chip, unsigned int iterations) +{ + unsigned int idx; + + for (idx = 0; idx < iterations; idx++) { + if (!(fm801_readw(chip, AC97_CMD) & FM801_AC97_VALID)) + return true; + udelay(10); + } + return false; +} + static int snd_fm801_update_bits(struct fm801 *chip, unsigned short reg, unsigned short mask, unsigned short value) { @@ -246,32 +270,19 @@ static void snd_fm801_codec_write(struct snd_ac97 *ac97, unsigned short val) { struct fm801 *chip = ac97->private_data; - int idx; - /* - * Wait until the codec interface is not ready.. - */ - for (idx = 0; idx < 100; idx++) { - if (!(fm801_readw(chip, AC97_CMD) & FM801_AC97_BUSY)) - goto ok1; - udelay(10); + if (!__is_ready(chip, 100)) { + dev_err(chip->card->dev, "AC'97 interface is busy (1)\n"); + return; } - dev_err(chip->card->dev, "AC'97 interface is busy (1)\n"); - return; - ok1: /* write data and address */ fm801_writew(val, chip, AC97_DATA); fm801_writew(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT), chip, AC97_CMD); - /* - * Wait until the write command is not completed.. - */ - for (idx = 0; idx < 1000; idx++) { - if (!(fm801_readw(chip, AC97_CMD) & FM801_AC97_BUSY)) - return; - udelay(10); - } - dev_err(chip->card->dev, "AC'97 interface #%d is busy (2)\n", ac97->num); + + if (!__is_ready(chip, 1000)) + dev_err(chip->card->dev, "AC'97 interface #%d is busy (2)\n", + ac97->num); } static unsigned short snd_fm801_codec_read(struct snd_ac97 *ac97, unsigned short reg) @@ -279,39 +290,26 @@ static unsigned short snd_fm801_codec_read(struct snd_ac97 *ac97, unsigned short struct fm801 *chip = ac97->private_data; int idx; - /* - * Wait until the codec interface is not ready.. - */ - for (idx = 0; idx < 100; idx++) { - if (!(fm801_readw(chip, AC97_CMD) & FM801_AC97_BUSY)) - goto ok1; - udelay(10); + if (!__is_ready(chip, 100)) { + dev_err(chip->card->dev, "AC'97 interface is busy (1)\n"); + return 0; } - dev_err(chip->card->dev, "AC'97 interface is busy (1)\n"); - return 0; - ok1: /* read command */ fm801_writew(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ, chip, AC97_CMD); - for (idx = 0; idx < 100; idx++) { - if (!(fm801_readw(chip, AC97_CMD) & FM801_AC97_BUSY)) - goto ok2; - udelay(10); + if (!__is_ready(chip, 100)) { + dev_err(chip->card->dev, "AC'97 interface #%d is busy (2)\n", + ac97->num); + return 0; } - dev_err(chip->card->dev, "AC'97 interface #%d is busy (2)\n", ac97->num); - return 0; - ok2: - for (idx = 0; idx < 1000; idx++) { - if (fm801_readw(chip, AC97_CMD) & FM801_AC97_VALID) - goto ok3; - udelay(10); + if (!__is_valid(chip, 1000)) { + dev_err(chip->card->dev, + "AC'97 interface #%d is not valid (2)\n", ac97->num); + return 0; } - dev_err(chip->card->dev, "AC'97 interface #%d is not valid (2)\n", ac97->num); - return 0; - ok3: return fm801_readw(chip, AC97_DATA); }