From patchwork Tue May 12 09:26:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xing Zheng X-Patchwork-Id: 6386721 Return-Path: X-Original-To: patchwork-linux-rockchip@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 D929CBEEE1 for ; Tue, 12 May 2015 09:31:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B8256203B5 for ; Tue, 12 May 2015 09:31:38 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 584EE203F4 for ; Tue, 12 May 2015 09:31:37 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ys6XI-0004L1-MF; Tue, 12 May 2015 09:31:36 +0000 Received: from mail-pa0-x22a.google.com ([2607:f8b0:400e:c03::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ys6X4-0004B8-5k; Tue, 12 May 2015 09:31:23 +0000 Received: by pabtp1 with SMTP id tp1so2227766pab.2; Tue, 12 May 2015 02:31:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6X8wp1OypDfPebYl0B0/gCW+PMZgdnp9yt7ffi+R7IE=; b=qiYzui41u0VPh8XxuGRlYaz9uNTwweAocvtumay/r6gpjZwTLnKRAn+S4VNC73fwQK u/INI8CsaLbPCiHrsZicordX05KWAziZxnmWUXAcEQNDdfVo/tmWD978pfjEbNt9WBj2 Zn7nkttbSPJt0D+F1vhYHUUuBCi2Ol1a4QG5CSjbN94kcmhc4ttDgAMRBm9Q3XuryywT M8wBXIWgzNMywIS8GdM5/gi+9bX/ZVuFb/VZBmt5GNdBBiUwFikeTpEdS+9udEUdwVt1 pUrWnLsVFxrg3DCRuCZ5JuWI0w54w86QKSURjp0rlDOSnJ++FtEq5nCdR70FX7RJtXUU QFwA== X-Received: by 10.66.66.108 with SMTP id e12mr27061308pat.155.1431423060770; Tue, 12 May 2015 02:31:00 -0700 (PDT) Received: from localhost.localdomain ([103.47.144.18]) by mx.google.com with ESMTPSA id pw9sm15635818pac.27.2015.05.12.02.30.53 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 12 May 2015 02:30:59 -0700 (PDT) From: Xing Zheng X-Google-Original-From: Xing Zheng To: dgreid@chromium.org, dianders@chromium.org, heiko@sntech.de, sonnyrao@chromium.org Subject: [PATCH 1/4] ASoC: rockchip: add rockchip machine driver Date: Tue, 12 May 2015 17:26:34 +0800 Message-Id: <1431422797-31903-2-git-send-email-zhengxing@rock-chips.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1431422797-31903-1-git-send-email-zhengxing@rock-chips.com> References: <1431422797-31903-1-git-send-email-zhengxing@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150512_023122_366100_2CCD9D53 X-CRM114-Status: GOOD ( 20.24 ) X-Spam-Score: 0.9 (/) Cc: alsa-devel@alsa-project.org, zhengxing , Takashi Iwai , linux-kernel@vger.kernel.org, Liam Girdwood , Jaroslav Kysela , linux-rockchip@lists.infradead.org, Mark Brown , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY,URIBL_BLACK autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: zhengxing In most cases, we maybe use simple-card as generic machine driver on next kernel, but there are some issue that jack detection and widgets extandable on simple-card. Own machine drvier can select one valid codec from supported codecs, and add needful function from dts on rockchip platform. Signed-off-by: zhengxing --- sound/soc/rockchip/Kconfig | 7 + sound/soc/rockchip/Makefile | 5 + sound/soc/rockchip/rockchip_machine_driver.c | 210 ++++++++++++++++++++++++++ sound/soc/rockchip/rockchip_machine_driver.h | 30 ++++ 4 files changed, 252 insertions(+) create mode 100644 sound/soc/rockchip/rockchip_machine_driver.c create mode 100644 sound/soc/rockchip/rockchip_machine_driver.h diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig index e181826..e3f51cf 100644 --- a/sound/soc/rockchip/Kconfig +++ b/sound/soc/rockchip/Kconfig @@ -14,3 +14,10 @@ config SND_SOC_ROCKCHIP_I2S Say Y or M if you want to add support for I2S driver for Rockchip I2S device. The device supports upto maximum of 8 channels each for play and record. + +config SND_SOC_ROCKCHIP_MACHINE + tristate "Rockchip Generic Machine Driver" + depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP + help + Say Y or M if you want to add support for Machine driver + for Rockchip I2S device. diff --git a/sound/soc/rockchip/Makefile b/sound/soc/rockchip/Makefile index b921909..47d7c84 100644 --- a/sound/soc/rockchip/Makefile +++ b/sound/soc/rockchip/Makefile @@ -2,3 +2,8 @@ snd-soc-i2s-objs := rockchip_i2s.o obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-i2s.o + +# ROCKCHIP Machine Support +snd-soc-rockchip-machine-objs := rockchip_machine_driver.o + +obj-$(CONFIG_SND_SOC_ROCKCHIP_MACHINE) += snd-soc-rockchip-machine.o diff --git a/sound/soc/rockchip/rockchip_machine_driver.c b/sound/soc/rockchip/rockchip_machine_driver.c new file mode 100644 index 0000000..34cae3f --- /dev/null +++ b/sound/soc/rockchip/rockchip_machine_driver.c @@ -0,0 +1,210 @@ +/* + * Rockchip machine ASoC driver for boards for multi-codecs. + * + * Copyright (c) 2015, ROCKCHIP CORPORATION. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rockchip_i2s.h" +#include "rockchip_machine_driver.h" + +#define DRV_NAME "rockchip-snd-machine" + +/* the sound cards of rockchp supports. */ +static struct rk_snd_soc_cards rk_snd_cards[] = { +}; + +static int snd_rk_mc_preinit(void) +{ + int id, ret; + + for (id = 0; id < ARRAY_SIZE(rk_snd_cards); ++id) { + struct rk_snd_soc_cards *rk_snd_card = &rk_snd_cards[id]; + + ret = rk_snd_card->preinit(rk_snd_card); + if (ret < 0) + pr_warn("card: %s preinit failed!\n", + rk_snd_card->name); + } + + return 0; +} + +static int snd_rk_mc_probe(struct platform_device *pdev) +{ + struct rk_mc_private *drv; + struct snd_soc_card *card; + struct device_node *parent = pdev->dev.of_node; + struct device_node *node; + int found = 0; + int ret; + + /* pre-init sound cards that rockchip supports. */ + snd_rk_mc_preinit(); + + drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); + if (!drv) + return -ENOMEM; + + /* attach matched codec. */ + for_each_available_child_of_node(parent, node) { + int id; + + for (id = 0; id < ARRAY_SIZE(rk_snd_cards); ++id) { + struct rk_snd_soc_cards *rk_snd_card = + &rk_snd_cards[id]; + + ret = of_device_is_compatible(node, + rk_snd_card->compatible); + if (ret) { + /* match compatible. */ + card = rk_snd_card->card; + if (!card || !card->dai_link) { + dev_err(&pdev->dev, + "card or dai_link is null!\n"); + continue; + } + + card->dev = &pdev->dev; + platform_set_drvdata(pdev, card); + snd_soc_card_set_drvdata(card, drv); + + /* set dai link node. */ + card->dai_link->codec_of_node = + of_parse_phandle(node, + "rockchip,audio-codec", + 0); + if (!card->dai_link->codec_of_node) { + dev_err(&pdev->dev, + "rockchip,audio-codec invalid\n"); + continue; + } + + card->dai_link->cpu_of_node = + of_parse_phandle(node, + "rockchip,i2s-controller", + 0); + if (!card->dai_link->cpu_of_node) { + dev_err(&pdev->dev, + "rockchip,i2s-controller invalid\n"); + continue; + } + + if (card->aux_dev) { + /* set aux_dev for max98090. */ + card->aux_dev->codec_of_node = + of_parse_phandle(node, + "rockchip,headset-codec", + 0); + if (!card->aux_dev->codec_of_node) { + dev_err(&pdev->dev, + "rockchip,headset-codec invalid\n"); + continue; + } + } + + card->dai_link->platform_of_node = + card->dai_link->cpu_of_node; + + ret = snd_soc_of_parse_card_name(card, + "rockchip,model"); + if (ret) + continue; + + /* register the soc card. */ + ret = snd_soc_register_card(card); + if (!ret) { + /* + * register sound card ok, + * and found matched codec. + */ + dev_info(&pdev->dev, + "card:[%s] register success!\n", + card->name); + + found = 1; + goto found_codec; + } else { + /* register sound card failed */ + dev_err(&pdev->dev, + "card:[%s] register failed(%d)!\n", + card->name, ret); + + card->dev = NULL; + } + } + } + } + + if (!found) { + dev_err(&pdev->dev, + "Not found matched codec!\n"); + return -ENODEV; + } + +found_codec: + dev_info(&pdev->dev, + "Found matched codec: %s!\n", + card->name); + + return 0; +} + +static int snd_rk_mc_remove(struct platform_device *pdev) +{ + struct snd_soc_card *card = platform_get_drvdata(pdev); + + snd_soc_card_set_drvdata(card, NULL); + snd_soc_unregister_card(card); + platform_set_drvdata(pdev, NULL); + + return 0; +} + +static const struct of_device_id rockchip_machine_of_match[] = { + { .compatible = "rockchip,rockchip-audio-machine", }, + {}, +}; + +static struct platform_driver snd_rk_mc_driver = { + .probe = snd_rk_mc_probe, + .remove = snd_rk_mc_remove, + .driver = { + .name = DRV_NAME, + .owner = THIS_MODULE, + .pm = &snd_soc_pm_ops, + .of_match_table = rockchip_machine_of_match, + }, +}; + +module_platform_driver(snd_rk_mc_driver); + +MODULE_AUTHOR("Xing Zheng "); +MODULE_DESCRIPTION("Rockchip general machine ASoC driver"); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:" DRV_NAME); +MODULE_DEVICE_TABLE(of, rockchip_machine_of_match); diff --git a/sound/soc/rockchip/rockchip_machine_driver.h b/sound/soc/rockchip/rockchip_machine_driver.h new file mode 100644 index 0000000..39a7a77 --- /dev/null +++ b/sound/soc/rockchip/rockchip_machine_driver.h @@ -0,0 +1,30 @@ +/* + * sound/soc/rockchip/rockchip_machine_driver.h + * + * ALSA SoC Audio Layer - Rockchip Machine driver + * + * Copyright (c) 2015 Rockchip Electronics Co. Ltd. + * Author: Xing Zheng + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __ROCKCHIP_MACHINE_DRIVER_H__ +#define __ROCKCHIP_MACHINE_DRIVER_H__ + +struct rk_mc_private { + struct snd_soc_jack headphone_jack; + struct snd_soc_jack mic_jack; + struct snd_soc_jack btn_jack; +}; + +struct rk_snd_soc_cards { + char name[32]; + char compatible[128]; + struct snd_soc_card *card; + int (*preinit)(struct rk_snd_soc_cards *soc_card); +}; + +#endif /* __ROCKCHIP_MACHINE_DRIVER_H__ */