From patchwork Tue Apr 29 07:56:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 4085521 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2DB44BFF02 for ; Tue, 29 Apr 2014 07:56:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4A7E7201DE for ; Tue, 29 Apr 2014 07:56:54 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 03DFD20154 for ; Tue, 29 Apr 2014 07:56:53 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id E520E2625F3; Tue, 29 Apr 2014 09:56:51 +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 444692625FD; 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 9EABA264F0F; Tue, 29 Apr 2014 09:55:59 +0200 (CEST) Received: from gw03.mail.saunalahti.fi (gw03.mail.saunalahti.fi [195.197.172.111]) by alsa0.perex.cz (Postfix) with ESMTP id F30A02625FD for ; Tue, 29 Apr 2014 09:55:51 +0200 (CEST) Received: from localhost.localdomain (a91-152-110-231.elisa-laajakaista.fi [91.152.110.231]) by gw03.mail.saunalahti.fi (Postfix) with ESMTP id 12BEA202D5; 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 s3T7uAm9015726; Tue, 29 Apr 2014 10:56:10 +0300 Received: (from andy@localhost) by localhost.localdomain (8.14.7/8.14.7/Submit) id s3T7uAQ8015725; Tue, 29 Apr 2014 10:56:10 +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:04 +0300 Message-Id: <1398758165-15671-3-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] [PATCHv2 2/2] fm801: introduce fm801_ac97_is_ready()/fm801_ac97_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 | 79 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c index 5be910c..e8910d0 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 bool fm801_ac97_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 bool fm801_ac97_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,72 +270,53 @@ 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 (!fm801_ac97_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(chip, AC97_DATA, val); fm801_writew(chip, AC97_CMD, reg | (ac97->addr << FM801_AC97_ADDR_SHIFT)); /* * 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 (!fm801_ac97_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) { 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 (!fm801_ac97_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(chip, AC97_CMD, reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ); - for (idx = 0; idx < 100; idx++) { - if (!(fm801_readw(chip, AC97_CMD) & FM801_AC97_BUSY)) - goto ok2; - udelay(10); + if (!fm801_ac97_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 (!fm801_ac97_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); }