From patchwork Sun Jan 14 11:54:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 10162593 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6BDE660245 for ; Sun, 14 Jan 2018 11:54:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5724C28923 for ; Sun, 14 Jan 2018 11:54:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 493D728AEF; Sun, 14 Jan 2018 11:54:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1011528923 for ; Sun, 14 Jan 2018 11:54:18 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 895D8267198; Sun, 14 Jan 2018 12:54:16 +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 6DE5B2671F2; Sun, 14 Jan 2018 12:54:10 +0100 (CET) Received: from cvs.linux-mips.org (eddie.linux-mips.org [148.251.95.138]) by alsa0.perex.cz (Postfix) with ESMTP id 1C117266CFE for ; Sun, 14 Jan 2018 12:54:06 +0100 (CET) Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23990439AbeANLyBs3iFm (ORCPT ); Sun, 14 Jan 2018 12:54:01 +0100 Date: Sun, 14 Jan 2018 12:54:00 +0100 From: Ladislav Michl To: alsa-devel@alsa-project.org Message-ID: <20180114115400.GA5867@lenoch> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) Cc: Liam Girdwood , Nicolas Ferre , Takashi Iwai , Mark Brown , Alexandre Belloni Subject: [alsa-devel] ASoC: How to write new (atmel) 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Hi there! I've got new at91sam9g20 board with max9867 codec (*), so I wanted to get inspiration from other drivers in sound/soc/atmel. Indeed, there are three of them: atmel_wm8904.c sam9g20_wm8731.c sam9x5_wm8731.c Now, looking at sound/soc/tegra, sound/soc/mediatek, etc. most drivers seems to be created by copy, modify (mostly find&replace), commit. There are so many of them, that it is probably impossible to fix them all (consider for example patch bellow to be done several times for different drivers) (**) So is sound/soc/generic preferred solution these days? Btw, generic drivers are calling of_node_put before they are done dealing with that node. And if above is preferred solution what about all those already created drivers? Fix them all or covert to generic one by introducing DT fixups for all those over the time created DT properties? At least for atmel drivers that seems to be doable as atmel_ssc_dai needs to be modified to get it work under generic framework and keeping old interface would needlesly complicate things - unless I miss something obvious of course :) (*) for now I wrote driver using copy&modify, but that does not seem to be the right solution anymore (**) almost two decades ago I rather wrote OSS driver for the very same reasons, but now OSS is gone... diff --git a/sound/soc/atmel/sam9x5_wm8731.c b/sound/soc/atmel/sam9x5_wm8731.c index 9db08826b32a..11e2c37a2e42 100644 --- a/sound/soc/atmel/sam9x5_wm8731.c +++ b/sound/soc/atmel/sam9x5_wm8731.c @@ -78,7 +78,6 @@ static const struct snd_soc_dapm_widget sam9x5_dapm_widgets[] = { static int sam9x5_wm8731_driver_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; - struct device_node *codec_np, *cpu_np; struct snd_soc_card *card; struct snd_soc_dai_link *dai; struct sam9x5_drvdata *priv; @@ -122,23 +121,20 @@ static int sam9x5_wm8731_driver_probe(struct platform_device *pdev) goto out; } - codec_np = of_parse_phandle(np, "atmel,audio-codec", 0); - if (!codec_np) { + dai->codec_of_node = of_parse_phandle(np, "atmel,audio-codec", 0); + if (!dai->codec_of_node) { dev_err(&pdev->dev, "atmel,audio-codec node missing\n"); ret = -EINVAL; goto out; } - dai->codec_of_node = codec_np; - - cpu_np = of_parse_phandle(np, "atmel,ssc-controller", 0); - if (!cpu_np) { + dai->cpu_of_node = of_parse_phandle(np, "atmel,ssc-controller", 0); + if (!dai->cpu_of_node) { dev_err(&pdev->dev, "atmel,ssc-controller node missing\n"); ret = -EINVAL; - goto out; + goto out_put_codec; } - dai->cpu_of_node = cpu_np; - dai->platform_of_node = cpu_np; + dai->platform_of_node = dai->cpu_of_node; priv->ssc_id = of_alias_get_id(cpu_np, "ssc"); @@ -146,12 +142,9 @@ static int sam9x5_wm8731_driver_probe(struct platform_device *pdev) if (ret != 0) { dev_err(&pdev->dev, "Failed to set SSC %d for audio: %d\n", ret, priv->ssc_id); - goto out; + goto out_put_cpu; } - of_node_put(codec_np); - of_node_put(cpu_np); - ret = snd_soc_register_card(card); if (ret) { dev_err(&pdev->dev, "Platform device allocation failed\n"); @@ -164,6 +157,10 @@ static int sam9x5_wm8731_driver_probe(struct platform_device *pdev) out_put_audio: atmel_ssc_put_audio(priv->ssc_id); +out_put_cpu: + of_node_put(dai->cpu_of_node); +out_put_codec: + of_node_put(dai->codec_of_node); out: return ret; }