From patchwork Thu Feb 12 02:10:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kenneth Westfield X-Patchwork-Id: 5815451 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 91AEDBF440 for ; Thu, 12 Feb 2015 02:14:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A77D0200F3 for ; Thu, 12 Feb 2015 02:14:18 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 5498E201F2 for ; Thu, 12 Feb 2015 02:14:17 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 8440D265338; Thu, 12 Feb 2015 03:14:16 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id E7CE826514B; Thu, 12 Feb 2015 03:10:44 +0100 (CET) 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 F15FD265148; Thu, 12 Feb 2015 03:10:41 +0100 (CET) Received: from smtp.codeaurora.org (smtp.codeaurora.org [198.145.29.96]) by alsa0.perex.cz (Postfix) with ESMTP id A1EB82650C3 for ; Thu, 12 Feb 2015 03:10:28 +0100 (CET) Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id F1175140BAB; Thu, 12 Feb 2015 02:10:27 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 486) id E0575140C0F; Thu, 12 Feb 2015 02:10:27 +0000 (UTC) Received: from localhost (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: kwestfie@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 2EDA3140C02; Thu, 12 Feb 2015 02:10:27 +0000 (UTC) From: Kenneth Westfield To: Mark Brown , Takashi Iwai , Liam Girdwood , David Brown , Bryan Huntsman , Greg KH , Banajit Goswami , Patrick Lai Date: Wed, 11 Feb 2015 18:10:12 -0800 Message-Id: <1423707015-14527-10-git-send-email-kwestfie@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1423707015-14527-1-git-send-email-kwestfie@codeaurora.org> References: <1423707015-14527-1-git-send-email-kwestfie@codeaurora.org> X-Virus-Scanned: ClamAV using ClamSMTP Cc: Device Tree Mailing List , ALSA Mailing List , Kenneth Westfield , MSM Mailing List Subject: [alsa-devel] [Patch V5 09/12] ASoC: ipq806x: Add @max98357a machine driver 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 From: Kenneth Westfield Add machine driver for the boards with the IPQ806X SOC connected to the MAX98357A DAC. Signed-off-by: Kenneth Westfield Acked-by: Banajit Goswami --- sound/soc/qcom/ipq806x-max98357a.c | 171 +++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 sound/soc/qcom/ipq806x-max98357a.c diff --git a/sound/soc/qcom/ipq806x-max98357a.c b/sound/soc/qcom/ipq806x-max98357a.c new file mode 100644 index 0000000000000000000000000000000000000000..af92e9ffa42104d6e29160b9e0ffedc820388c7c --- /dev/null +++ b/sound/soc/qcom/ipq806x-max98357a.c @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * ipq806x-max98357a.c -- ALSA SoC machine driver for QTi ipq806x SOC with + * MAX98357a DAC + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define IPQ806X_MAX98357A_SYSCLK_MULT 4 + +static int ipq806x_max98357a_ops_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; + struct snd_soc_card *card = soc_runtime->card; + snd_pcm_format_t format = params_format(params); + unsigned int rate = params_rate(params); + unsigned int sysclk_freq; + int bitwidth, ret; + + bitwidth = snd_pcm_format_width(format); + if (bitwidth < 0) { + dev_err(card->dev, "%s() invalid bit width given: %d\n", + __func__, bitwidth); + return bitwidth; + } + + /* + * as the CPU DAI is the I2S bus master and no system clock is needed by + * the MAX98357a DAC, simply set the system clock to be a constant + * multiple of the bit clock for the clock divider + */ + sysclk_freq = rate * bitwidth * 2 * IPQ806X_MAX98357A_SYSCLK_MULT; + + ret = snd_soc_dai_set_sysclk(soc_runtime->cpu_dai, 0, sysclk_freq, 0); + if (ret) { + dev_err(card->dev, "%s() error setting sysclk to %u: %d\n", + __func__, sysclk_freq, ret); + return ret; + } + + return 0; +} + +static struct snd_soc_ops ipq806x_max98357a_soc_ops = { + .hw_params = ipq806x_max98357a_ops_hw_params, +}; + +static struct snd_soc_dai_link ipq806x_max98357a_dai_link = { + .name = "IPQ806x Media1", + .stream_name = "MultiMedia1", + .ops = &ipq806x_max98357a_soc_ops, +}; + +static struct snd_soc_card ipq806x_max98357a_soc_card = { + .name = "ipq806x-max98357a", + .dev = NULL, +}; + +static int ipq806x_max98357a_parse_of(struct snd_soc_card *card) +{ + struct snd_soc_dai_link *dai_link = card->dai_link; + struct device_node *np = card->dev->of_node; + int ret; + + dai_link->cpu_of_node = of_parse_phandle(np, "cpu", 0); + if (!dai_link->cpu_of_node) { + dev_err(card->dev, "%s() error getting cpu phandle\n", + __func__); + return -EINVAL; + } + dai_link->platform_of_node = dai_link->cpu_of_node; + + dai_link->codec_of_node = of_parse_phandle(np, "codec", 0); + if (!dai_link->codec_of_node) { + dev_err(card->dev, "%s() error getting codec phandle\n", + __func__); + return -EINVAL; + } + + ret = of_property_read_string(np, "codec-dai", + &dai_link->codec_dai_name); + if (ret) { + dev_err(card->dev, "%s() error getting codec-dai: %d\n", + __func__, ret); + return -EINVAL; + } + + return 0; +} + +static int ipq806x_max98357a_platform_probe(struct platform_device *pdev) +{ + struct snd_soc_card *card = &ipq806x_max98357a_soc_card; + int ret; + + if (card->dev) { + dev_err(&pdev->dev, "%s() error, existing soundcard\n", + __func__); + return -ENODEV; + } + card->dev = &pdev->dev; + platform_set_drvdata(pdev, card); + + ret = snd_soc_of_parse_card_name(card, "qcom,model"); + if (ret) { + dev_err(&pdev->dev, "%s() error parsing card name: %d\n", + __func__, ret); + return ret; + } + + card->dai_link = &ipq806x_max98357a_dai_link; + card->num_links = 1; + + ret = ipq806x_max98357a_parse_of(card); + if (ret) { + dev_err(&pdev->dev, "%s() error resolving dai links: %d\n", + __func__, ret); + return ret; + } + + ret = devm_snd_soc_register_card(&pdev->dev, card); + if (ret == -EPROBE_DEFER) { + card->dev = NULL; + return ret; + } else if (ret) { + dev_err(&pdev->dev, "%s() error registering soundcard: %d\n", + __func__, ret); + return ret; + } + + return 0; +} + +#ifdef CONFIG_OF +static const struct of_device_id ipq806x_max98357a_device_id[] = { + { .compatible = "qcom,ipq806x-max98357a" }, + {}, +}; +MODULE_DEVICE_TABLE(of, ipq806x_max98357a_device_id); +#endif + +static struct platform_driver ipq806x_max98357a_platform_driver = { + .driver = { + .name = "ipq806x-max98357a", + .of_match_table = + of_match_ptr(ipq806x_max98357a_device_id), + }, + .probe = ipq806x_max98357a_platform_probe, +}; +module_platform_driver(ipq806x_max98357a_platform_driver); + +MODULE_DESCRIPTION("QTi ipq806x-max98357a Machine Driver"); +MODULE_LICENSE("GPL v2");