Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1222962imm; Fri, 22 Jun 2018 12:31:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIIkeRMyhuGhiA1WGYL77OSt03Rxr57xFYQEj9K8bxkg0abu/J6dCjIydQWm21x2MoCbVTS X-Received: by 2002:a65:5085:: with SMTP id r5-v6mr2597813pgp.123.1529695883805; Fri, 22 Jun 2018 12:31:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529695883; cv=none; d=google.com; s=arc-20160816; b=HYW7oAewfeLQ664ofrQPUmdlhfEhxXWDFA2cjg/pAXAXaUuF3/m1Fd1PrdUgV8M9LX iH/jtZsYkEIpC7w2AMhBVCEIa8ee0rMk4ufGxNrKZ1h5ozgJclpwXVVPFD1zslb1xITH i6ucR5zrcC1CyApAXdD4SCvmUY+ZUBWyuEDHN0Jpt/bcNkZD16tbu+59XbCjXrViCQZQ 0aB3fMXTAoczfUuJnP6bjOdEAYDR9bYx5womXOHY5VGzPnOT70pO3ExF5XoLCRtMeTIv wIbEyEmGiWOqE2wdimYfBfMIYt3HDLFyblvtCva2JhFIYZi0pxTJ9bhE0efjtuFzHRJn VIcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Kr6MGHElyrlzWMB1Bxq+i3GQlyQmZ13QonOwcbI1o9I=; b=ZaOzs2bXQJtbHPSyAFRNbn5jQ+Ag3Ep2dfV+F5d701Wy0NCwoMw7noSP44CG6EHYbl /1n0V6W5D5ObuKxDljuwSzSTEkzRhAS4tTzn6Yr430VGG4AEorD61B4vXPPiKUUrlkmb Peq9A0klcLE2+7eKExc5uBG/6dnWLRS8goNj5s0pGYNzB/LX61m6IjTmwEgFP0liNdo1 ThuKU9fG1hAB3kB7U+eb+aRcsnPVMX7019ZANFyDqwzMVCa/U4/Pi0fK2EPy8arS7FAr EmEbs4Dtx4Rwe+kSEeNUCPy+9zYI9KuJtZB5SXSvOe7N8v9+ZYi5Y9Z34qhHBVGuNN1W th+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e12-v6si6562774pgt.243.2018.06.22.12.31.09; Fri, 22 Jun 2018 12:31:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934467AbeFVT3u (ORCPT + 99 others); Fri, 22 Jun 2018 15:29:50 -0400 Received: from smtp05.smtpout.orange.fr ([80.12.242.127]:31541 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933775AbeFVT3t (ORCPT ); Fri, 22 Jun 2018 15:29:49 -0400 Received: from belgarion.home ([90.55.203.186]) by mwinf5d28 with ME id 1vUj1y00T41oiFu03vVnb8; Fri, 22 Jun 2018 21:29:48 +0200 X-ME-Helo: belgarion.home X-ME-Auth: amFyem1pay5yb2JlcnRAb3JhbmdlLmZy X-ME-Date: Fri, 22 Jun 2018 21:29:48 +0200 X-ME-IP: 90.55.203.186 From: Robert Jarzmik To: Liam Girdwood , Mark Brown , Rob Herring , Mark Rutland , Jaroslav Kysela , Takashi Iwai Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Robert Jarzmik Subject: [PATCH v2 2/2] ALSA: ac97: add codecs devicetree binding Date: Fri, 22 Jun 2018 21:28:34 +0200 Message-Id: <20180622192834.7797-2-robert.jarzmik@free.fr> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180622192834.7797-1-robert.jarzmik@free.fr> References: <20180622192834.7797-1-robert.jarzmik@free.fr> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a devicetree binding for codecs. This is especially useful if the AC97 bitclk clock is provided by the codec, as it has to be described in the devicetree description for the ac97 bus code to aquire it. Signed-off-by: Robert Jarzmik --- Since v1: handle of_put_node() in codec removal --- sound/ac97/bus.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sound/ac97/bus.c b/sound/ac97/bus.c index 31f858eceffc..7a0dfca03a57 100644 --- a/sound/ac97/bus.c +++ b/sound/ac97/bus.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -68,6 +69,27 @@ ac97_codec_find(struct ac97_controller *ac97_ctrl, unsigned int codec_num) return ac97_ctrl->codecs[codec_num]; } +static struct device_node * +ac97_of_get_child_device(struct ac97_controller *ac97_ctrl, int idx, + unsigned int vendor_id) +{ + struct device_node *node; + u32 reg; + char compat[] = "ac97,0000,0000"; + + snprintf(compat, sizeof(compat), "ac97,%04x,%04x", + vendor_id >> 16, vendor_id & 0xffff); + + for_each_child_of_node(ac97_ctrl->parent->of_node, node) { + if ((idx != of_property_read_u32(node, "reg", ®)) || + !of_device_is_compatible(node, compat)) + continue; + return of_node_get(node); + } + + return NULL; +} + static void ac97_codec_release(struct device *dev) { struct ac97_codec_device *adev; @@ -76,6 +98,7 @@ static void ac97_codec_release(struct device *dev) adev = to_ac97_device(dev); ac97_ctrl = adev->ac97_ctrl; ac97_ctrl->codecs[adev->num] = NULL; + of_node_put(dev->of_node); kfree(adev); } @@ -98,6 +121,8 @@ static int ac97_codec_add(struct ac97_controller *ac97_ctrl, int idx, device_initialize(&codec->dev); dev_set_name(&codec->dev, "%s:%u", dev_name(ac97_ctrl->parent), idx); + codec->dev.of_node = ac97_of_get_child_device(ac97_ctrl, idx, + vendor_id); ret = device_add(&codec->dev); if (ret) @@ -105,6 +130,7 @@ static int ac97_codec_add(struct ac97_controller *ac97_ctrl, int idx, return 0; err_free_codec: + of_node_put(codec->dev.of_node); put_device(&codec->dev); kfree(codec); ac97_ctrl->codecs[idx] = NULL; -- 2.11.0