From patchwork Mon Jun 22 18:12:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Zhang X-Patchwork-Id: 6657401 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 42CABC05AC for ; Mon, 22 Jun 2015 18:13:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1674E205DF for ; Mon, 22 Jun 2015 18:13:33 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 788D0205DA for ; Mon, 22 Jun 2015 18:13:31 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id F1EFE26512B; Mon, 22 Jun 2015 20:13:29 +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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 0E3C72651FC; Mon, 22 Jun 2015 20:13:27 +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 D6ACB265211; Mon, 22 Jun 2015 20:13:24 +0200 (CEST) Received: from mail-ig0-f174.google.com (mail-ig0-f174.google.com [209.85.213.174]) by alsa0.perex.cz (Postfix) with ESMTP id A376926512B for ; Mon, 22 Jun 2015 20:13:19 +0200 (CEST) Received: by igblr2 with SMTP id lr2so59140351igb.0 for ; Mon, 22 Jun 2015 11:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=TsR3op2gv+PSDr/OGKwmWdI1LguHFafCzsiTQMz5sOI=; b=ayxXW/rWQttg7AWeOA5lU11n5tSFtGpiStwy2W73ipqDeHPbajH5mhRfDHWa0+/53N cveBP8wRnCztPskNdaht2n6cqT8/lr55ACIJhdg7bK4yGTR3RO9wP74CHlttHpqov/sr EsAbIlheqnGK+og488SgC7pnkN08sKbjqEsdc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=TsR3op2gv+PSDr/OGKwmWdI1LguHFafCzsiTQMz5sOI=; b=YSTHpD6ZE2CKkHhbrGwc9e8iuwAgGjyOgCUJ3bgq74hm7b4S8179UKaATwNQzOjcEn HyhCLalT1RlcbDnZn1w8d+uZ7YQm+3w87caMXkwJAVvRQplElTezz4Bswf3uBIMUXPtB LHLpdUZZYbEDjF8ptTwE6oaL6omXio67UKgOLx2/lJ1+YnDc/F2eW4LbfoGuAkvpbypq 2Vf5muRqoEflY+PVCbs76UKMeo4GwhJ6Nf2Hu0Oz6YHayMI7M+zxgfwjEk9vn/A0YD6G t9osGDdRJCSOuCtjb3y8Z7D1wsATH7HD49ff3/dgCeAuNujaVBh9VfoDseMam1Cs7ct8 yDGg== X-Gm-Message-State: ALoCoQk5sBuFbIe/WEkkkQyo7uEmVpOyIhtSH4zmoovm67kSZWxyjMR8JMCFWTxB3jmFw3IRGIKC X-Received: by 10.107.130.101 with SMTP id e98mr39388196iod.38.1434996798511; Mon, 22 Jun 2015 11:13:18 -0700 (PDT) Received: from benzh.mtv.corp.google.com ([172.22.65.67]) by mx.google.com with ESMTPSA id l128sm13234675iol.1.2015.06.22.11.13.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Jun 2015 11:13:17 -0700 (PDT) From: Ben Zhang To: Mark Brown Date: Mon, 22 Jun 2015 11:12:59 -0700 Message-Id: <1434996780-34535-1-git-send-email-benzh@chromium.org> X-Mailer: git-send-email 2.4.3.573.g4eafbef Cc: Oder Chiou , alsa-devel@alsa-project.org, Liam Girdwood , Ben Zhang , Anatol Pomozov , Bard Liao , Dylan Reid Subject: [alsa-devel] [PATCH 1/2] ASoC: rt5677: Switch to use descriptor-based gpiod API 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 This patch makes the driver use the new descriptor-based gpiod API so that gpio assignment info can be provided by Device Tree, ACPI or board files. Signed-off-by: Ben Zhang --- sound/soc/codecs/rt5677.c | 85 +++++++++++++++++------------------------------ sound/soc/codecs/rt5677.h | 5 +-- 2 files changed, 33 insertions(+), 57 deletions(-) diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index aba00fd8..c166217 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -15,13 +15,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -4761,10 +4759,10 @@ static int rt5677_remove(struct snd_soc_codec *codec) struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); regmap_write(rt5677->regmap, RT5677_RESET, 0x10ec); - if (gpio_is_valid(rt5677->pow_ldo2)) - gpio_set_value_cansleep(rt5677->pow_ldo2, 0); - if (gpio_is_valid(rt5677->reset_pin)) - gpio_set_value_cansleep(rt5677->reset_pin, 0); + if (rt5677->pow_ldo2) + gpiod_set_value_cansleep(rt5677->pow_ldo2, 0); + if (rt5677->reset_pin) + gpiod_set_value_cansleep(rt5677->reset_pin, 0); return 0; } @@ -4778,10 +4776,10 @@ static int rt5677_suspend(struct snd_soc_codec *codec) regcache_cache_only(rt5677->regmap, true); regcache_mark_dirty(rt5677->regmap); - if (gpio_is_valid(rt5677->pow_ldo2)) - gpio_set_value_cansleep(rt5677->pow_ldo2, 0); - if (gpio_is_valid(rt5677->reset_pin)) - gpio_set_value_cansleep(rt5677->reset_pin, 0); + if (rt5677->pow_ldo2) + gpiod_set_value_cansleep(rt5677->pow_ldo2, 0); + if (rt5677->reset_pin) + gpiod_set_value_cansleep(rt5677->reset_pin, 0); } return 0; @@ -4792,12 +4790,11 @@ static int rt5677_resume(struct snd_soc_codec *codec) struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); if (!rt5677->dsp_vad_en) { - if (gpio_is_valid(rt5677->pow_ldo2)) - gpio_set_value_cansleep(rt5677->pow_ldo2, 1); - if (gpio_is_valid(rt5677->reset_pin)) - gpio_set_value_cansleep(rt5677->reset_pin, 1); - if (gpio_is_valid(rt5677->pow_ldo2) || - gpio_is_valid(rt5677->reset_pin)) + if (rt5677->pow_ldo2) + gpiod_set_value_cansleep(rt5677->pow_ldo2, 1); + if (rt5677->reset_pin) + gpiod_set_value_cansleep(rt5677->reset_pin, 1); + if (rt5677->pow_ldo2 || rt5677->reset_pin) msleep(10); regcache_cache_only(rt5677->regmap, false); @@ -5034,24 +5031,6 @@ static int rt5677_parse_dt(struct rt5677_priv *rt5677, struct device_node *np) rt5677->pdata.lout3_diff = of_property_read_bool(np, "realtek,lout3-differential"); - rt5677->pow_ldo2 = of_get_named_gpio(np, - "realtek,pow-ldo2-gpio", 0); - rt5677->reset_pin = of_get_named_gpio(np, - "realtek,reset-gpio", 0); - - /* - * POW_LDO2 is optional (it may be statically tied on the board). - * -ENOENT means that the property doesn't exist, i.e. there is no - * GPIO, so is not an error. Any other error code means the property - * exists, but could not be parsed. - */ - if (!gpio_is_valid(rt5677->pow_ldo2) && - (rt5677->pow_ldo2 != -ENOENT)) - return rt5677->pow_ldo2; - if (!gpio_is_valid(rt5677->reset_pin) && - (rt5677->reset_pin != -ENOENT)) - return rt5677->reset_pin; - of_property_read_u8_array(np, "realtek,gpio-config", rt5677->pdata.gpio_config, RT5677_GPIO_NUM); @@ -5155,30 +5134,26 @@ static int rt5677_i2c_probe(struct i2c_client *i2c, rt5677->reset_pin = -EINVAL; } - if (gpio_is_valid(rt5677->pow_ldo2)) { - ret = devm_gpio_request_one(&i2c->dev, rt5677->pow_ldo2, - GPIOF_OUT_INIT_HIGH, - "RT5677 POW_LDO2"); - if (ret < 0) { - dev_err(&i2c->dev, "Failed to request POW_LDO2 %d: %d\n", - rt5677->pow_ldo2, ret); - return ret; - } + /* pow-ldo2 and reset are optional. The codec pins may be statically + * connected on the board without gpios. If the gpio device property + * isn't specified, devm_gpiod_get_optional returns NULL. + */ + rt5677->pow_ldo2 = devm_gpiod_get_optional(&i2c->dev, + "realtek,pow-ldo2", GPIOD_OUT_HIGH); + if (IS_ERR(rt5677->pow_ldo2)) { + ret = PTR_ERR(rt5677->pow_ldo2); + dev_err(&i2c->dev, "Failed to request POW_LDO2: %d\n", ret); + rt5677->pow_ldo2 = 0; } - - if (gpio_is_valid(rt5677->reset_pin)) { - ret = devm_gpio_request_one(&i2c->dev, rt5677->reset_pin, - GPIOF_OUT_INIT_HIGH, - "RT5677 RESET"); - if (ret < 0) { - dev_err(&i2c->dev, "Failed to request RESET %d: %d\n", - rt5677->reset_pin, ret); - return ret; - } + rt5677->reset_pin = devm_gpiod_get_optional(&i2c->dev, + "realtek,reset", GPIOD_OUT_HIGH); + if (IS_ERR(rt5677->reset_pin)) { + ret = PTR_ERR(rt5677->reset_pin); + dev_err(&i2c->dev, "Failed to request RESET: %d\n", ret); + rt5677->reset_pin = 0; } - if (gpio_is_valid(rt5677->pow_ldo2) || - gpio_is_valid(rt5677->reset_pin)) { + if (rt5677->pow_ldo2 || rt5677->reset_pin) { /* Wait a while until I2C bus becomes available. The datasheet * does not specify the exact we should wait but startup * sequence mentiones at least a few milliseconds. diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h index 7eca38a..d46855a 100644 --- a/sound/soc/codecs/rt5677.h +++ b/sound/soc/codecs/rt5677.h @@ -14,6 +14,7 @@ #include #include +#include /* Info */ #define RT5677_RESET 0x00 @@ -1775,8 +1776,8 @@ struct rt5677_priv { int pll_src; int pll_in; int pll_out; - int pow_ldo2; /* POW_LDO2 pin */ - int reset_pin; /* RESET pin */ + struct gpio_desc *pow_ldo2; /* POW_LDO2 pin */ + struct gpio_desc *reset_pin; /* RESET pin */ enum rt5677_type type; #ifdef CONFIG_GPIOLIB struct gpio_chip gpio_chip;