From patchwork Mon Sep 10 10:46:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Ujfalusi X-Patchwork-Id: 1431351 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id F24B4DF28C for ; Mon, 10 Sep 2012 10:47:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757040Ab2IJKrP (ORCPT ); Mon, 10 Sep 2012 06:47:15 -0400 Received: from na3sys009aog136.obsmtp.com ([74.125.149.85]:58120 "EHLO na3sys009aog136.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757353Ab2IJKq6 (ORCPT ); Mon, 10 Sep 2012 06:46:58 -0400 Received: from mail-ob0-f174.google.com ([209.85.214.174]) (using TLSv1) by na3sys009aob136.postini.com ([74.125.148.12]) with SMTP ID DSNKUE3FId9FVm14aCpCD/cw2T4iRCx1ZHld@postini.com; Mon, 10 Sep 2012 03:46:57 PDT Received: by obbuo13 with SMTP id uo13so2659178obb.19 for ; Mon, 10 Sep 2012 03:46:56 -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=2PZOSOhr8okszxO+DwqbOJDSxkf9xqiU6gi3GiVQyhg=; b=cPTYvsRdSXKM8h/EWn+qYmVVawu4EB8f5iBpK6KTa0k2U9nSeDLgSvvedxTgpYYp/O jTcR9yis8JKTXXKe3CzwXgQ9Z8hBFAfRdXSFmivAOKATDPycSLEMEyvJrhIhdz29CSQh ZUnLbNZ7b+gkGP2jQt0UYnPD+OCNqHBCI4OHdP1eWZmJvvitITdhBVWxZ6MRV00dh3b8 +L3IWMnFEHbZK9+PzKLv6YPXt2BY7rNXKhvYBLB/Xirbp2nXFHBz7fw8y/h6Ow4rWzsM +oAYrXZQdbOTf59PiCmIMCblJlTosvn1yus8s/GXpLr1LOrW0DicwV30CtYztf08x1MJ 4e8g== Received: by 10.182.44.7 with SMTP id a7mr13637207obm.80.1347274016862; Mon, 10 Sep 2012 03:46:56 -0700 (PDT) Received: from barack.emea.dhcp.ti.com (dragon.ti.com. [192.94.94.33]) by mx.google.com with ESMTPS id 5sm8888098oeq.4.2012.09.10.03.46.53 (version=SSLv3 cipher=OTHER); Mon, 10 Sep 2012 03:46:56 -0700 (PDT) From: Peter Ujfalusi To: Mark Brown , Liam Girdwood , Tony Lindgren , Samuel Ortiz , Dmitry Torokhov , Grant Likely , Rob Herring Cc: Tero Kristo , alsa-devel@alsa-project.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree-discuss@lists.ozlabs.org, Benoit Cousson , linux-kernel@vger.kernel.org Subject: [PATCH v4 14/14] ASoC: twl4030: Support for DT booted kernel Date: Mon, 10 Sep 2012 13:46:32 +0300 Message-Id: <1347273992-9107-15-git-send-email-peter.ujfalusi@ti.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1347273992-9107-1-git-send-email-peter.ujfalusi@ti.com> References: <1347273992-9107-1-git-send-email-peter.ujfalusi@ti.com> X-Gm-Message-State: ALoCoQkRvwMxVMi0gQwDZ/fVLQiK4vWV7KYXj5hlyUqwJ7FEg+Ey91zGzK1NrZcFP2pjRpbKygbY Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.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 | 55 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c index 8b13d50..8405ab9 100644 --- a/sound/soc/codecs/twl4030.c +++ b/sound/soc/codecs/twl4030.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include #include @@ -295,13 +297,57 @@ 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; + + pdata->hs_extmute_gpio = of_get_named_gpio(node, + "ti,hs_extmute_gpio", 0); + if (gpio_is_valid(pdata->hs_extmute_gpio)) + pdata->hs_extmute = 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; + + twl4030_codec_node = of_find_node_by_name(codec->dev->parent->of_node, + "codec"); + + 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; @@ -2284,13 +2330,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)); }