From patchwork Fri Apr 27 07:02:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Zhao X-Patchwork-Id: 8276 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 54F1623E42 for ; Fri, 27 Apr 2012 07:03:32 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 1DF42A18363 for ; Fri, 27 Apr 2012 07:03:32 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so866269iag.11 for ; Fri, 27 Apr 2012 00:03:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :x-spamscore:x-bigfish:x-forefront-antispam-report:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:x-originatororg:x-gm-message-state; bh=OAiBWpk/wssh06Mi0KDARzf83lixnenZW3VFiK5gZ+k=; b=heUyZHzjvlVc5W4ifVnFNpVi6coX3c/KR05TVX6ldYxstAI/uJ7soIL2S1NuvZX/WL YkM+vYk6pXhYDP0fZqsCQuekkCwr2C0hHFzyQjRAl9UekD7lPsHAJpvbioYCFkOPasxH Z3O22GbEn6j9HTqubDgJZUmov/qQqgiiOny6bvzoN94xHN2hkw5k0BEWx/Qs9sk7SF16 eiC5lFanH7hJjiVeyJZATRIfVyixJ8H7X3xUYI/15TnNuRek6BMfRumWAWVbgdMf2UYH JM0jpSxLq5v1AAYy7zjoqsYdg9PnafPjmq9pW/UpHy43D/TGCdLByxeo+L6RHhZpA44l 7jFA== Received: by 10.50.135.36 with SMTP id pp4mr900231igb.19.1335510211894; Fri, 27 Apr 2012 00:03:31 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.137.198 with SMTP id x6csp5448ibt; Fri, 27 Apr 2012 00:03:31 -0700 (PDT) Received: by 10.68.233.4 with SMTP id ts4mr10710154pbc.70.1335510211049; Fri, 27 Apr 2012 00:03:31 -0700 (PDT) Received: from va3outboundpool.messaging.microsoft.com (va3ehsobe001.messaging.microsoft.com. [216.32.180.11]) by mx.google.com with ESMTPS id o4si5915384pbi.325.2012.04.27.00.03.30 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Apr 2012 00:03:31 -0700 (PDT) Received-SPF: neutral (google.com: 216.32.180.11 is neither permitted nor denied by best guess record for domain of B20223@freescale.com) client-ip=216.32.180.11; Authentication-Results: mx.google.com; spf=neutral (google.com: 216.32.180.11 is neither permitted nor denied by best guess record for domain of B20223@freescale.com) smtp.mail=B20223@freescale.com Received: from mail32-va3-R.bigfish.com (10.7.14.254) by VA3EHSOBE002.bigfish.com (10.7.40.22) with Microsoft SMTP Server id 14.1.225.23; Fri, 27 Apr 2012 07:03:28 +0000 Received: from mail32-va3 (localhost [127.0.0.1]) by mail32-va3-R.bigfish.com (Postfix) with ESMTP id 70B4140547; Fri, 27 Apr 2012 07:03:27 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bh8275dh84d07hz2dh2a8h668h839hd24he5bh) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI Received: from mail32-va3 (localhost.localdomain [127.0.0.1]) by mail32-va3 (MessageSwitch) id 1335510205127427_2184; Fri, 27 Apr 2012 07:03:25 +0000 (UTC) Received: from VA3EHSMHS015.bigfish.com (unknown [10.7.14.239]) by mail32-va3.bigfish.com (Postfix) with ESMTP id 147C83C0115; Fri, 27 Apr 2012 07:03:25 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by VA3EHSMHS015.bigfish.com (10.7.99.25) with Microsoft SMTP Server (TLS) id 14.1.225.23; Fri, 27 Apr 2012 07:03:22 +0000 Received: from az33smr01.freescale.net (10.64.34.199) by 039-SN1MMR1-002.039d.mgd.msft.net (10.84.1.15) with Microsoft SMTP Server id 14.1.355.3; Fri, 27 Apr 2012 02:03:22 -0500 Received: from b20223-02.ap.freescale.net (b20223-02.ap.freescale.net [10.192.242.124]) by az33smr01.freescale.net (8.13.1/8.13.0) with ESMTP id q3R737LL008722; Fri, 27 Apr 2012 02:03:19 -0500 (CDT) From: Richard Zhao To: , , CC: , , , , , , , Richard Zhao , Richard Zhao Subject: [PATCH 03/11] ASoC: fsl: add sgtl5000 clock support for imx-sgtl5000 Date: Fri, 27 Apr 2012 15:02:57 +0800 Message-ID: <1335510185-7906-4-git-send-email-richard.zhao@freescale.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1335510185-7906-1-git-send-email-richard.zhao@freescale.com> References: <1335510185-7906-1-git-send-email-richard.zhao@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-Gm-Message-State: ALoCoQlj4F+V48lzg02K4R55gxVfbRCy/YPwtN24RzBvOmGdl3mwGD7CjaUlPynNvjRsN1h8Fpmx From: Richard Zhao It tries to clk_get the clock. And if it failed, it assumes the clock by default enabled. Signed-off-by: Richard Zhao --- sound/soc/fsl/imx-sgtl5000.c | 40 ++++++++++++++++++++++++++++++++-------- 1 files changed, 32 insertions(+), 8 deletions(-) diff --git a/sound/soc/fsl/imx-sgtl5000.c b/sound/soc/fsl/imx-sgtl5000.c index 73b935e..3a729ca 100644 --- a/sound/soc/fsl/imx-sgtl5000.c +++ b/sound/soc/fsl/imx-sgtl5000.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include "../codecs/sgtl5000.h" @@ -25,6 +27,7 @@ struct imx_sgtl5000_data { struct snd_soc_card card; char codec_dai_name[DAI_NAME_SIZE]; char platform_name[DAI_NAME_SIZE]; + struct clk *codec_clk; unsigned int clk_frequency; }; @@ -58,6 +61,7 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; struct device_node *ssi_np, *codec_np; struct platform_device *ssi_pdev; + struct i2c_client *codec_dev; struct imx_sgtl5000_data *data; int int_port, ext_port; int ret; @@ -113,6 +117,11 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev) ret = -EINVAL; goto fail; } + codec_dev = of_find_i2c_device_by_node(codec_np); + if (!codec_dev) { + dev_err(&pdev->dev, "failed to find codec platform device\n"); + return -EINVAL; + } data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); if (!data) { @@ -120,11 +129,20 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev) goto fail; } - ret = of_property_read_u32(codec_np, "clock-frequency", - &data->clk_frequency); - if (ret) { - dev_err(&pdev->dev, "clock-frequency missing or invalid\n"); - goto fail; + data->codec_clk = clk_get(&codec_dev->dev, NULL); + if (IS_ERR(data->codec_clk)) { + /* assuming clock enabled by default */ + data->codec_clk = NULL; + ret = of_property_read_u32(codec_np, "clock-frequency", + &data->clk_frequency); + if (ret) { + dev_err(&codec_dev->dev, + "clock-frequency missing or invalid\n"); + goto fail; + } + } else { + data->clk_frequency = clk_get_rate(data->codec_clk); + clk_prepare_enable(data->codec_clk); } data->dai.name = "HiFi"; @@ -140,10 +158,10 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev) data->card.dev = &pdev->dev; ret = snd_soc_of_parse_card_name(&data->card, "model"); if (ret) - goto fail; + goto clk_fail; ret = snd_soc_of_parse_audio_routing(&data->card, "audio-routing"); if (ret) - goto fail; + goto clk_fail; data->card.num_links = 1; data->card.dai_link = &data->dai; data->card.dapm_widgets = imx_sgtl5000_dapm_widgets; @@ -152,10 +170,12 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev) ret = snd_soc_register_card(&data->card); if (ret) { dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); - goto fail; + goto clk_fail; } platform_set_drvdata(pdev, data); +clk_fail: + clk_put(data->codec_clk); fail: if (ssi_np) of_node_put(ssi_np); @@ -169,6 +189,10 @@ static int __devexit imx_sgtl5000_remove(struct platform_device *pdev) { struct imx_sgtl5000_data *data = platform_get_drvdata(pdev); + if (data->codec_clk) { + clk_disable_unprepare(data->codec_clk); + clk_put(data->codec_clk); + } snd_soc_unregister_card(&data->card); return 0;