From patchwork Fri Apr 27 06:55:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Zhao X-Patchwork-Id: 8240 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 D080B24007 for ; Fri, 27 Apr 2012 06:56:38 +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 996FFA186F2 for ; Fri, 27 Apr 2012 06:56:38 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so857924iag.11 for ; Thu, 26 Apr 2012 23:56:38 -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=ifxID0fLagMyTL4WzZ+O6WRaCU1B9vYzQhJo0J8zu8Uk+cedE7X4zvnm/NVemLTIvs JCBBp7qkp+Z3AlBdcKzPsGtFB/tf6rK/gLOdS4Zw3CNo3CE9pFubAvk1Fg/y6hNkGbxb GY/gzKGgqroMISRHu6Yjb0vBE4gWeHm5wv7UCU7qsRdWwn7GDt0fYut51BVZKru86voa EQT+mbwld7pBjs2GENfxHctFdH4BcCkstLVqkErXY1uRalLBnepKt7Nawt7HDqLfRuZt R5RnWrKTbb1Dw582qfsRDDQhRVeNnNxfqC4MQKxBVC2Jx4fnseg72f4F60fiZrLvveGR md2g== Received: by 10.50.41.201 with SMTP id h9mr886986igl.19.1335509798420; Thu, 26 Apr 2012 23:56:38 -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 x6csp5112ibt; Thu, 26 Apr 2012 23:56:37 -0700 (PDT) Received: by 10.216.135.66 with SMTP id t44mr261977wei.8.1335509795696; Thu, 26 Apr 2012 23:56:35 -0700 (PDT) Received: from am1outboundpool.messaging.microsoft.com (am1ehsobe003.messaging.microsoft.com. [213.199.154.206]) by mx.google.com with ESMTPS id bz1si1267533wib.46.2012.04.26.23.56.35 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 Apr 2012 23:56:35 -0700 (PDT) Received-SPF: neutral (google.com: 213.199.154.206 is neither permitted nor denied by best guess record for domain of B20223@freescale.com) client-ip=213.199.154.206; Authentication-Results: mx.google.com; spf=neutral (google.com: 213.199.154.206 is neither permitted nor denied by best guess record for domain of B20223@freescale.com) smtp.mail=B20223@freescale.com Received: from mail110-am1-R.bigfish.com (10.3.201.248) by AM1EHSOBE003.bigfish.com (10.3.204.23) with Microsoft SMTP Server id 14.1.225.23; Fri, 27 Apr 2012 06:56:33 +0000 Received: from mail110-am1 (localhost [127.0.0.1]) by mail110-am1-R.bigfish.com (Postfix) with ESMTP id C8CD72205C1; Fri, 27 Apr 2012 06:56:32 +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 mail110-am1 (localhost.localdomain [127.0.0.1]) by mail110-am1 (MessageSwitch) id 1335509790432544_5098; Fri, 27 Apr 2012 06:56:30 +0000 (UTC) Received: from AM1EHSMHS017.bigfish.com (unknown [10.3.201.253]) by mail110-am1.bigfish.com (Postfix) with ESMTP id 6209530008B; Fri, 27 Apr 2012 06:56:30 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by AM1EHSMHS017.bigfish.com (10.3.207.155) with Microsoft SMTP Server (TLS) id 14.1.225.23; Fri, 27 Apr 2012 06:56:29 +0000 Received: from az33smr01.freescale.net (10.64.34.199) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server id 14.1.355.3; Fri, 27 Apr 2012 01:56:30 -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 q3R6uBpl008244; Fri, 27 Apr 2012 01:56:27 -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 14:55:54 +0800 Message-ID: <1335509762-7777-4-git-send-email-richard.zhao@freescale.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1335509762-7777-1-git-send-email-richard.zhao@freescale.com> References: <1335509762-7777-1-git-send-email-richard.zhao@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-Gm-Message-State: ALoCoQkH8uVZXyJ76HAPIR7KdymbJYA1Ver+8+LoYqJMFilTSMoKK2VFri2pgV/p2lKg4eSgUkP9 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;