From patchwork Wed Aug 8 09:41:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Ujfalusi X-Patchwork-Id: 1294141 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id AAED7DF223 for ; Wed, 8 Aug 2012 09:48:29 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Sz2ow-0000oq-Ot; Wed, 08 Aug 2012 09:44:56 +0000 Received: from na3sys009aog125.obsmtp.com ([74.125.149.153]) by merlin.infradead.org with smtps (Exim 4.76 #1 (Red Hat Linux)) id 1Sz2mQ-0007Xb-4M for linux-arm-kernel@lists.infradead.org; Wed, 08 Aug 2012 09:42:21 +0000 Received: from mail-ob0-f181.google.com ([209.85.214.181]) (using TLSv1) by na3sys009aob125.postini.com ([74.125.148.12]) with SMTP ID DSNKUCI0eHklKOlEWtGeEREd5oiESuLc8Qm8@postini.com; Wed, 08 Aug 2012 02:42:18 PDT Received: by obbup19 with SMTP id up19so979762obb.12 for ; Wed, 08 Aug 2012 02:42:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=A4ffM17vSKImswbgF2EZ446qIcxEadLZOIqT2sQxGRM=; b=js0bsU0R5s7ElWzD9Xs42WMqnb4E1LSOUeuvNCF5v68gRodrQojS4ojNA/L7dps7A1 sR0UEQRH29futP77FuAv8kCVu6iF1oygglQU1esofzlkbAN2TZg1CuLX0bbScapJ7s0c T/SRvweaOJnnLAoyvMfcIxvzm4+Hdul5ouym5H65+QtwpiS71ds8pOijecBGKWh/mOdW bwwAceYeAvDWKvSlrMAi/xBsWrdQB84jYzXjRdJadmET4JE5QRgSvwpDnDnpb96Wdzz7 8XdU7ZJ+RVS6h/PE+ZrtFIlxfAa1PwbkdPPZVTfw0+Nmv4EusoWtiE9+7uGMGpAKl6Jw WbBA== Received: by 10.60.172.101 with SMTP id bb5mr28944822oec.44.1344418936289; Wed, 08 Aug 2012 02:42:16 -0700 (PDT) Received: from barack.emea.dhcp.ti.com (dragon.ti.com. [192.94.94.33]) by mx.google.com with ESMTPS id c6sm22141308obn.13.2012.08.08.02.42.12 (version=SSLv3 cipher=OTHER); Wed, 08 Aug 2012 02:42:15 -0700 (PDT) From: Peter Ujfalusi To: Samuel Ortiz , Mark Brown , Liam Girdwood , Tony Lindgren , Dmitry Torokhov Subject: [PATCH 11/11] ASoC: twl4030: Support for DT booted kernel Date: Wed, 8 Aug 2012 12:41:27 +0300 Message-Id: <1344418887-5262-12-git-send-email-peter.ujfalusi@ti.com> X-Mailer: git-send-email 1.7.8.6 In-Reply-To: <1344418887-5262-1-git-send-email-peter.ujfalusi@ti.com> References: <1344418887-5262-1-git-send-email-peter.ujfalusi@ti.com> X-Gm-Message-State: ALoCoQmTMENQbFGFk/VUfVKIz/Rfm7gj+jUySzxIfM0gRSw7tOZRARHAjPONB2VtJTbSu6Q3GWGt X-Spam-Note: CRM114 invocation failed X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [74.125.149.153 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: alsa-devel@alsa-project.org, Benoit Cousson , devicetree-discuss@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org When the kernel has been booted with DT blob the platform data is NULL for the driver. We need to construct the pdata based on the DT information for runtime use. Signed-off-by: Peter Ujfalusi --- sound/soc/codecs/twl4030.c | 67 ++++++++++++++++++++++++++++++++++++++----- 1 files changed, 59 insertions(+), 8 deletions(-) diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c index bf0240d..68495a2 100644 --- a/sound/soc/codecs/twl4030.c +++ b/sound/soc/codecs/twl4030.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -295,13 +296,70 @@ static inline void twl4030_reset_registers(struct snd_soc_codec *codec) } -static void twl4030_init_chip(struct snd_soc_codec *codec) +static void twl4030_setup_pdata_of(struct twl4030_codec_data *pdata, + struct device_node *node) +{ + int value; + + of_property_read_u32(node, "ti,digimic_delay", + &pdata->digimic_delay); + of_property_read_u32(node, "ti,ramp_delay_value", + &pdata->ramp_delay_value); + of_property_read_u32(node, "ti,offset_cncl_path", + &pdata->offset_cncl_path); + if (!of_property_read_u32(node, "ti,hs_extmute", &value)) + pdata->hs_extmute = value; + else + pdata->hs_extmute = 0; + + if (pdata->hs_extmute) { + int ret = of_property_read_u32(node, "ti,hs_extmute_gpio", + &pdata->hs_extmute_gpio); + if (!ret) { + if (!of_property_read_u32(node, + "ti,hs_extmute_disable_level", + &value)) { + pdata->hs_extmute_disable_level = value; + } + } else { + pdata->hs_extmute_gpio = -1; + } + } +} + +static struct twl4030_codec_data *twl4030_get_pdata(struct snd_soc_codec *codec) { struct twl4030_codec_data *pdata = dev_get_platdata(codec->dev); + struct device_node *twl4030_codec_node = NULL; + +#ifdef CONFIG_OF + twl4030_codec_node = of_find_node_by_name(codec->dev->parent->of_node, + "codec"); +#endif + + if (!pdata && twl4030_codec_node) { + pdata = devm_kzalloc(codec->dev, + sizeof(struct twl4030_codec_data), + GFP_KERNEL); + if (!pdata) { + dev_err(codec->dev, "Can not allocate memory\n"); + return NULL; + } + twl4030_setup_pdata_of(pdata, twl4030_codec_node); + } + + return pdata; +} + +static void twl4030_init_chip(struct snd_soc_codec *codec) +{ + struct twl4030_codec_data *pdata; struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); u8 reg, byte; int i = 0; + pdata = twl4030_get_pdata(codec); + if (pdata && pdata->hs_extmute && gpio_is_valid(pdata->hs_extmute_gpio)) { int ret, level; @@ -2288,13 +2346,6 @@ static struct snd_soc_codec_driver soc_codec_dev_twl4030 = { static int __devinit twl4030_codec_probe(struct platform_device *pdev) { - struct twl4030_codec_data *pdata = pdev->dev.platform_data; - - if (!pdata) { - dev_err(&pdev->dev, "platform_data is missing\n"); - return -EINVAL; - } - return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_twl4030, twl4030_dai, ARRAY_SIZE(twl4030_dai)); }