From patchwork Wed Sep 17 20:14:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatol Pomozov X-Patchwork-Id: 4926611 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 C390E9F32F for ; Wed, 17 Sep 2014 20:13:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A293A2015E for ; Wed, 17 Sep 2014 20:14:58 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 0D2B82011D for ; Wed, 17 Sep 2014 20:14:57 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 02E1B265131; Wed, 17 Sep 2014 22:14:54 +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 D30AE2651AA; Wed, 17 Sep 2014 22:14:46 +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 5B09626526D; Wed, 17 Sep 2014 22:14:44 +0200 (CEST) Received: from mail-ob0-f202.google.com (mail-ob0-f202.google.com [209.85.214.202]) by alsa0.perex.cz (Postfix) with ESMTP id 2E21E2650FE for ; Wed, 17 Sep 2014 22:14:37 +0200 (CEST) Received: by mail-ob0-f202.google.com with SMTP id vb8so45774obc.3 for ; Wed, 17 Sep 2014 13:14:36 -0700 (PDT) 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=RiylV6wkZFr2glFUtcjViLQTD5747a8LAkruWjrJlv8=; b=d+W5v1H0hPHM7b3Ij1BTgjpdmUs4p9Jvwpuzl5fDw8/l1T4C2OnngNLtlWslVVyico 517PCOSZJsI8gGxnK+iHb82eFico5ar4P8XmReeuklvaiHSCVVmXt6gV8PNBG91BHCBC OO17Z/GDWDwS5QB0BMyjJtEAv4U+/QNF0TczSNf+iXE9dZgQrziT6ffnciyT8kGvVMyc rXgPe60tr7G9kZDinDMdscAgli9oJ7K9zkVVn2t02y0qvaeVSe/vGfYEO9zyjcX84Gm+ wpsojx2YwOHj5XmCV2kd4Sgnmxee4XmGyIswFhNXZpfTxzrRTi4eD0IsgIFl1rXbn3Tv GxDw== X-Gm-Message-State: ALoCoQk1wk76Coykx4uqxh8tXCVTLc10+kFVWSI+/98Fp266CBbS4Jacf5J7KcChUgwrQt43wFRQK08mFUDOJ2GtbhgouEtpTLwgme5vQPiA3ERj7rIz99793Awimuhn2EMSzpL30kDt06JaC7avASYCNDGZh4D6JXWdyF5ZlvR0JmKX7VYpl0s= X-Received: by 10.42.122.209 with SMTP id o17mr824961icr.28.1410984875712; Wed, 17 Sep 2014 13:14:35 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id n22si877338yhd.1.2014.09.17.13.14.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Sep 2014 13:14:35 -0700 (PDT) Received: from anatol.mtv.corp.google.com ([172.22.64.197]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id JFsPkvSd.1; Wed, 17 Sep 2014 13:14:35 -0700 Received: by anatol.mtv.corp.google.com (Postfix, from userid 67983) id C70481001A8; Wed, 17 Sep 2014 13:14:34 -0700 (PDT) From: Anatol Pomozov To: broonie@kernel.org, lgirdwood@gmail.com Date: Wed, 17 Sep 2014 13:14:20 -0700 Message-Id: <1410984860-40626-1-git-send-email-anatol.pomozov@gmail.com> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 Cc: oder_chiou@realtek.com, alsa-devel@alsa-project.org, Anatol Pomozov Subject: [alsa-devel] [PATCH] ASoC: rt5677: Add a configuration option for LDO2_POW pin 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 Some boards have this pin statically tied and do not require any configuration, some other boards allow to enable chip using GPIO. Add an option that tells which GPIO is used to power the audio codec. Signed-off-by: Anatol Pomozov --- Documentation/devicetree/bindings/sound/rt5677.txt | 41 ++++++++++++++++ sound/soc/codecs/rt5677.c | 54 ++++++++++++++++++++++ sound/soc/codecs/rt5677.h | 1 + 3 files changed, 96 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/rt5677.txt diff --git a/Documentation/devicetree/bindings/sound/rt5677.txt b/Documentation/devicetree/bindings/sound/rt5677.txt new file mode 100644 index 0000000..98509fb --- /dev/null +++ b/Documentation/devicetree/bindings/sound/rt5677.txt @@ -0,0 +1,41 @@ +RT5677 audio CODEC + +This device supports I2C only. + +Required properties: + +- compatible : "realtek,rt5677". + +- reg : The I2C address of the device. + +- interrupts : The CODEC's interrupt output. + +Optional properties: + +- realtek,pow-ldo2-gpio : The GPIO that controls the CODEC's POW_LDO2 pin. + +Pins on the device (for linking into audio routes): + + * IN1P + * IN1N + * IN2P + * IN2N + * MICBIAS1 + * DMIC1 + * DMIC2 + * DMIC3 + * DMIC4 + * LOUT1 + * LOUT2 + * LOUT3 + +Example: + +rt5677 { + compatible = "realtek,rt5677"; + reg = <0x2c>; + interrupt-parent = <&gpio>; + interrupts = ; + realtek,pow-ldo2-gpio = + <&gpio TEGRA_GPIO(V, 3) GPIO_ACTIVE_HIGH>; +}; diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 9847473..83785db 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -3319,6 +3320,8 @@ 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); return 0; } @@ -3330,6 +3333,8 @@ 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); return 0; } @@ -3338,6 +3343,10 @@ static int rt5677_resume(struct snd_soc_codec *codec) { struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); + if (gpio_is_valid(rt5677->pow_ldo2)) { + gpio_set_value_cansleep(rt5677->pow_ldo2, 1); + msleep(10); + } regcache_cache_only(rt5677->regmap, false); regcache_sync(rt5677->regmap); @@ -3495,6 +3504,24 @@ static const struct i2c_device_id rt5677_i2c_id[] = { }; MODULE_DEVICE_TABLE(i2c, rt5677_i2c_id); +static int rt5677_parse_dt(struct rt5677_priv *rt5677, struct device_node *np) +{ + rt5677->pow_ldo2 = of_get_named_gpio(np, + "realtek,pow-ldo2-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; + + return 0; +} + static int rt5677_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { @@ -3513,6 +3540,33 @@ static int rt5677_i2c_probe(struct i2c_client *i2c, if (pdata) rt5677->pdata = *pdata; + if (i2c->dev.of_node) { + ret = rt5677_parse_dt(rt5677, i2c->dev.of_node); + if (ret) { + dev_err(&i2c->dev, "Failed to parse device tree: %d\n", + ret); + return ret; + } + } else { + rt5677->pow_ldo2 = -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; + } + /* 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. + */ + msleep(10); + } + rt5677->regmap = devm_regmap_init_i2c(i2c, &rt5677_regmap); if (IS_ERR(rt5677->regmap)) { ret = PTR_ERR(rt5677->regmap); diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h index b61b72c..222a4137 100644 --- a/sound/soc/codecs/rt5677.h +++ b/sound/soc/codecs/rt5677.h @@ -1550,6 +1550,7 @@ struct rt5677_priv { int pll_src; int pll_in; int pll_out; + int pow_ldo2; /* POW_LDO2 pin */ #ifdef CONFIG_GPIOLIB struct gpio_chip gpio_chip; #endif