Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2205947imm; Thu, 21 Jun 2018 08:46:14 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLKwA3tVofAeKNq9Nr69t5vlHrEY4V7PTq1llzpfJ7Do5b07kMgyW7RViA0aZ9TougrieXz X-Received: by 2002:a62:9e0b:: with SMTP id s11-v6mr28063590pfd.198.1529595974519; Thu, 21 Jun 2018 08:46:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529595974; cv=none; d=google.com; s=arc-20160816; b=o7OGAFMFdJ20QRlFjlafV+mmBO3LCk0DG/vYnGoz7KYX0MvVPoyru7LlOrOkkRnhFn EofWMZaRBnm9FkrpImf45CVYx5T5IGFWjne+XwN1ZrApaFHKFcjwLkuqmoJq7fXsPOJX hOIUvRUGXgW4yDwB+L5CZIe2pjxo9h/BDxoKQOzk7P4osVGiLq/YAMEMTkYr0wk1RDWP Dy4YhieQI+CiKsKz9Hd1KMfjgXITXQisvi4FNKAsGSW4JoxREunyripf3L72gzqgJexZ Shql5uWfKrD4T8Mh9DWhHtpsmGlBnribktdqLjkgTP56xKDbEB+EJnoYsyMLwPmqPauR jbWQ== 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=WWFmMB5NDb+qnGeA0GVa/M90ygN6XuwtUsX0ueZBZSA=; b=khN20xtzJxzxbbl8aCZsE2rXtGMFTvVZNghshXxccOl47Qo02q9dozWYWVfXouAU2d 7PqcRKygvj+MlWuradLgxbmEtyNjU8hQOeQ3fVsFukhNA9nnJ8XS1wlopI+hYTrZi0U8 uRnCIZM3CK/X5876OkgOiTpBKK7beMu95TYnRROq2N5hvJ0C39cXd4tbHNMpnd0j9uwD YDwsdBmYLqCuuAMGgSYw7G5ZkIrkH2+C0eKTdbwwir7jr4giWwyEiEAmPf9E6ZIexm0N vunq1XojDQWIO+QVFZnxmgCSKNlInvTBYQJXdoE3cV2yMxA4na3ye6FolMdKNxixecnM llKQ== 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 b59-v6si5237046plb.107.2018.06.21.08.45.59; Thu, 21 Jun 2018 08:46:14 -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 S933312AbeFUPoY (ORCPT + 99 others); Thu, 21 Jun 2018 11:44:24 -0400 Received: from smtp02.smtpout.orange.fr ([80.12.242.124]:45946 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933246AbeFUPoM (ORCPT ); Thu, 21 Jun 2018 11:44:12 -0400 Received: from belgarion.home ([90.55.203.186]) by mwinf5d49 with ME id 1Tk01y00E41oiFu03TkAfA; Thu, 21 Jun 2018 17:44:10 +0200 X-ME-Helo: belgarion.home X-ME-Auth: amFyem1pay5yb2JlcnRAb3JhbmdlLmZy X-ME-Date: Thu, 21 Jun 2018 17:44:10 +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 2/2] ALSA: ac97: add codecs devicetree binding Date: Thu, 21 Jun 2018 17:43:56 +0200 Message-Id: <20180621154356.5438-2-robert.jarzmik@free.fr> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180621154356.5438-1-robert.jarzmik@free.fr> References: <20180621154356.5438-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 --- Special review query: review the "return of_node_get(node)", which assumes that upon device removal, of_put_node(dev.of_node) will be called... --- sound/ac97/bus.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/sound/ac97/bus.c b/sound/ac97/bus.c index 31f858eceffc..c8e20dd8786f 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; @@ -98,6 +120,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) -- 2.11.0