From patchwork Tue Jun 11 10:40:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 166384 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2182358ilk; Tue, 11 Jun 2019 03:41:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwoNI/kOHfzer/4Jq2PP5yTuvKRNoH6lRIoV5OXo003l2usGXrYSer2zr/DLKjxIwA1oGfo X-Received: by 2002:a62:78c2:: with SMTP id t185mr9784839pfc.142.1560249682650; Tue, 11 Jun 2019 03:41:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560249682; cv=none; d=google.com; s=arc-20160816; b=KwS2DjMxqjv9F8kMovmzkBKGqbQHCLx8gPmntzkHtWXr9SZOOqMMH79Y7E6xQAcmff FjtJJlDANOWvXa/Gnzt7K1A0Bjdia5WgHn2G34M5PdhkITzWp75XmUwQcmtXtUakbTwy QBDEGvMEj8BYkT12a6YJGKlnacgsKTyp9RAZDlOp/lTYIGnwEiGSbWKtnTV24nYAEDXg Q2k6PGwmNurZ49p0M1x+WE1LwiD7fFf73kgkv+OC/IC9EjTIVkAMhjV01tSqqprxuR6s 3YmbpWILyeXCLUpF8hKinuJ9greaOC7POq/gS3nFMNdaWOb9yraG+Wg3fQ8BTAzzPwAL Vk6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fJU4aHR0rVsdWBrGZXQ39RDqJgxX93qjHiD8SWybkaM=; b=0Px42TrXteDUej0L3deDr8lwcFdk7FzJ7lOcvm3LQ3bQFKCFapaOkVH6zm38UK+Cd/ Deey0EsNMITCwGx1F68FQBvrul74BCJxpxcWRB/rAWgxrAmAvkmMeMzsYcto3k6e1ARF +Ruo4VdRgu+M7IKnlO3m9yzfeaj4qTAa6WYP+KkkX3Cu6LJPLT2k1JffN2KpAqA2wo/W KUIzv2RBx4fIRA/7mgRQJaSBhAiP7TU6kaLomrJrxW2Q4tj3gxbNU/Ampqx3OpwfZ1JU 0ChtcETnyT3L74GXadSzEU+2OCFzksRSpm6LozcEWdaVek9s9Rp4SO8Z1Oj3p5187Fo0 n0iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="RPRC/yHe"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j17si1933505pfn.278.2019.06.11.03.41.21; Tue, 11 Jun 2019 03:41:22 -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; dkim=pass header.i=@linaro.org header.s=google header.b="RPRC/yHe"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387787AbfFKKlV (ORCPT + 30 others); Tue, 11 Jun 2019 06:41:21 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46908 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387527AbfFKKlC (ORCPT ); Tue, 11 Jun 2019 06:41:02 -0400 Received: by mail-wr1-f68.google.com with SMTP id n4so12390125wrw.13 for ; Tue, 11 Jun 2019 03:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fJU4aHR0rVsdWBrGZXQ39RDqJgxX93qjHiD8SWybkaM=; b=RPRC/yHewHSIblBTN67aXej0xEEkdQgIhaXh2ybmwsLf+Cosr6xLs0PO0YCnzb4o9k hlOqYHb92RjF3YMh/W5dtVSKpxn1JWJgg4bgrkWwd0QG5AP7pmR+x9UINg0gQii3+2RW s/jWdAPSOCHS7BQT9tvgNRvplvmqo249sSbf4qNAGHLGchiXPe4LYcigmjeLns/Y2wC0 qOAwzOhQmMREdx13qIPdtFt50qam581ngygcDOwI0c9qRZDQ7kbuWZI58J1g0iiiYwaW Rl7ycVEk7dq0+DngyU+xk7UQo+kQ/3liwt4BsZn//8XZxoAggzsOqjY5BRnMYPLuVhFe 0UcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fJU4aHR0rVsdWBrGZXQ39RDqJgxX93qjHiD8SWybkaM=; b=DZI2SY0sWosV3F29p60Cc2EmoAjvctCOEG1hUjhDRFOXCe8HxuSHIMuVMytTWRgxMs GXbw06RmkFc1oMS0Cjg3vn6RS9LMsEbhuoviwezuk50t+ySyzi6FdSk4jEO1uZD9a34d 0HfLIWLR4tIKYSyWVEJHq/pU/wkbnFT9PNBwvokjyIzBJgK5IoInFtkNZHB0eLZuqANH f5nMQrijHyU2srHF60GS+PjJQ36NaHtFlxjsZCy6pe3S9zEieC8VPXtLWyoR9Jo8LaE6 fXparXb8qiOXiZKzIMKIAXqwJZm5fYNCOz1pY/4pD35SB1Cz7JlgbfYxfX/JQrA/h4/s Q0dg== X-Gm-Message-State: APjAAAUKtIFQzGKM/KyTIo63i8tIhjjXfsRjPNdWhPwkWGa7sARRZGX4 ViDO3kDGZulCO7qqO8anXmwyQQ== X-Received: by 2002:adf:e8cb:: with SMTP id k11mr48143892wrn.244.1560249660756; Tue, 11 Jun 2019 03:41:00 -0700 (PDT) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id c65sm2359614wma.44.2019.06.11.03.40.59 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 11 Jun 2019 03:41:00 -0700 (PDT) From: Srinivas Kandagatla To: broonie@kernel.org, vkoul@kernel.org Cc: robh+dt@kernel.org, devicetree@vger.kernel.org, mark.rutland@arm.com, pierre-louis.bossart@linux.intel.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, bgoswami@quicinc.com, Srinivas Kandagatla Subject: [RFC PATCH 2/5] soundwire: core: add device tree support for slave devices Date: Tue, 11 Jun 2019 11:40:40 +0100 Message-Id: <20190611104043.22181-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190611104043.22181-1-srinivas.kandagatla@linaro.org> References: <20190611104043.22181-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds support to parsing device tree based SoundWire slave devices. Signed-off-by: Srinivas Kandagatla --- drivers/soundwire/bus.c | 2 +- drivers/soundwire/bus.h | 1 + drivers/soundwire/slave.c | 54 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 2 deletions(-) -- 2.21.0 diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index fe745830a261..20f26cf4ba74 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -78,7 +78,7 @@ int sdw_add_bus_master(struct sdw_bus *bus) if (IS_ENABLED(CONFIG_ACPI) && ACPI_HANDLE(bus->dev)) ret = sdw_acpi_find_slaves(bus); else - ret = -ENOTSUPP; /* No ACPI/DT so error out */ + ret = sdw_of_find_slaves(bus); if (ret) { dev_err(bus->dev, "Finding slaves failed:%d\n", ret); diff --git a/drivers/soundwire/bus.h b/drivers/soundwire/bus.h index 3048ca153f22..ee46befedbd1 100644 --- a/drivers/soundwire/bus.h +++ b/drivers/soundwire/bus.h @@ -15,6 +15,7 @@ static inline int sdw_acpi_find_slaves(struct sdw_bus *bus) } #endif +int sdw_of_find_slaves(struct sdw_bus *bus); void sdw_extract_slave_id(struct sdw_bus *bus, u64 addr, struct sdw_slave_id *id); diff --git a/drivers/soundwire/slave.c b/drivers/soundwire/slave.c index f39a5815e25d..6e7f5cfeb854 100644 --- a/drivers/soundwire/slave.c +++ b/drivers/soundwire/slave.c @@ -2,6 +2,7 @@ // Copyright(c) 2015-17 Intel Corporation. #include +#include #include #include #include "bus.h" @@ -28,13 +29,14 @@ static int sdw_slave_add(struct sdw_bus *bus, slave->dev.parent = bus->dev; slave->dev.fwnode = fwnode; - /* name shall be sdw:link:mfg:part:class:unique */ + /* name shall be sdw:link:mfg:part:class */ dev_set_name(&slave->dev, "sdw:%x:%x:%x:%x:%x", bus->link_id, id->mfg_id, id->part_id, id->class_id, id->unique_id); slave->dev.release = sdw_slave_release; slave->dev.bus = &sdw_bus_type; + slave->dev.of_node = of_node_get(to_of_node(fwnode)); slave->bus = bus; slave->status = SDW_SLAVE_UNATTACHED; slave->dev_num = 0; @@ -112,3 +114,53 @@ int sdw_acpi_find_slaves(struct sdw_bus *bus) } #endif + +#if IS_ENABLED(CONFIG_OF) +/* + * sdw_of_find_slaves() - Find Slave devices in master device tree node + * @bus: SDW bus instance + * + * Scans Master DT node for SDW child Slave devices and registers it. + */ +int sdw_of_find_slaves(struct sdw_bus *bus) +{ + struct device *dev = bus->dev; + struct device_node *node; + + if (!bus->dev->of_node) + return 0; + + for_each_child_of_node(bus->dev->of_node, node) { + struct sdw_slave_id id; + const char *compat = NULL; + int unique_id, ret; + int ver, mfg_id, part_id, class_id; + compat = of_get_property(node, "compatible", NULL); + if (!compat) + continue; + + ret = sscanf(compat, "sdw%x,%x,%x,%x", + &ver, &mfg_id, &part_id, &class_id); + if (ret != 4) { + dev_err(dev, "Manf ID & Product code not found %s\n", + compat); + continue; + } + + ret = of_property_read_u32(node, "sdw-instance-id", &unique_id); + if (ret) { + dev_err(dev, "Instance id not found:%d\n", ret); + continue; + } + + id.sdw_version = ver - 0xF; + id.unique_id = unique_id; + id.mfg_id = mfg_id; + id.part_id = part_id; + id.class_id = class_id; + sdw_slave_add(bus, &id, of_fwnode_handle(node)); + } + return 0; +} + +#endif