From patchwork Fri Aug 9 13:34:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 170920 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp10015444ile; Fri, 9 Aug 2019 06:34:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqJEjSubH8+LguBcOc9Yz2eciEbwNM0t87e4NhZ6F1Ts5e/RyNgzmVul5pRkLWk0P/tiQi X-Received: by 2002:a62:3283:: with SMTP id y125mr21885222pfy.83.1565357676215; Fri, 09 Aug 2019 06:34:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565357676; cv=none; d=google.com; s=arc-20160816; b=HSQxNtVoTzVHfZz/Z51181cvrev9zagrr/f1tNZFJCJss6yqpP16lnCP3WRAiNETbB Fnwkdb1yZB3/uey7WAHUO5zvTC3kMRcahJMYOS+qc88I32FvHGVsEmozxXG5F/e96Z4Q w2K1fZhxY3qTBEV/bov4QYw1ZkQPVfmACUIT6pidY3ETPv8vLbyYRhe7BDiAF4m7kg0h 4IT0h0DBluQzv4bwQNFO7+fg4lB1IweE7RQMvHu5NJQhKSMYYO9M8aqbMWEf5SaquwPi RpeRYOPwt4xbfO/HbxBq+43wLKV1vTYWKXi8c0XG5whf7VlOI0dB00dPVlaRRgK4jSQG WGcg== 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=WSA7ezdPPag+s30NiG1INKw2c+i3SxQK3zdXCLkhRcc=; b=0cG4O2y0fZ0aCCaleedbWyTRUj7ijX7tY1CjUp5ooiDJt+tH+tLk6YZ+bwqrVRX0gm DvAzsxKCLxaKPtDSRViF2edb0LtP21P9uyIClkJPUMZdJcjhgilpOhv9L1Yil3q88SkT e4P3blPKYyH3KNy82DbJv8YlONPR1jLqlsfzvpO6qlYswG2spVf3VTDd7+gK24QcVJu8 Is7dTmRehtmf0WVaIHYmTj4cIZuWwv+Sk90n7v3ETu9nL7kvFNrnCEbedqbQm3EzHYba TPRDivEeii12/eiqh5C6E8Gk0p8tg6Ojbbi2+eSiCJX4GwNTLo71YehrHLyczld6QsaX CBuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PsLHerYo; 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 s6si40659634plq.213.2019.08.09.06.34.35; Fri, 09 Aug 2019 06:34:36 -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=PsLHerYo; 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 S2436507AbfHINee (ORCPT + 28 others); Fri, 9 Aug 2019 09:34:34 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38983 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407127AbfHINec (ORCPT ); Fri, 9 Aug 2019 09:34:32 -0400 Received: by mail-wr1-f66.google.com with SMTP id t16so8147267wra.6 for ; Fri, 09 Aug 2019 06:34:31 -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=WSA7ezdPPag+s30NiG1INKw2c+i3SxQK3zdXCLkhRcc=; b=PsLHerYoUVRKASnwTKpiAHQR0yPELiRX+g+NPh9prYQur1qyuSIfRI9PXP0Ob5CJp2 HPSso9SxnVC7il0jzaoVV9lJC6Ex7sVcFdBqN/S3qOmWNjZMJ8rm0TEGcsqbB0CAcH5K fyZbwFQD3D/CnClOZa2uSp5cr/QjbAktrc4mFi1VK8uSKqaex2aNsIEgcg7+IdI7zYi0 xJX5+xEAyIYNbHAARfShnXDBAftp15zQHxpDPB2AAU9xbMcZxVIVBcpC5QD1peeHs+TV oHBwA+QBhimbf9/kN9APXDT3/9VvtWTAOTgNcJVKr8OOeFTUSJjQNUsvDC3qBFv9B6Bf YYYA== 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=WSA7ezdPPag+s30NiG1INKw2c+i3SxQK3zdXCLkhRcc=; b=DU9+hlDr6F2SIFRqKmrdT/ATIAt0Brop6lA80DFiRaN5fXtHFwk8nndrDTEfI7Ps8C nexNkqDtv1b7fFhMH9c0Gbl9HpegZIN4P54goe24w66UOdXXlGANel9E5dI5uuX40Q/E 4O67+arVS0tONU8rwRU42qOroPG8+FqmB5juoJFtBSm3cLsCV0oO9+VYdRwYf5g7Y6xP rDBxeW5zIIpGok3/zkQgqZ5YPsY2EPHr7uHrz6UmvNKbW2ybtlaaaGjdTC+azxUxO3cN UTDOSd0SopEZeMrCUSD2idw8Xv6u7TVD6UTSgYtuGz5yeLzzlcExQa6XTYPgmB6O8Naz DrWQ== X-Gm-Message-State: APjAAAUnafcU0nLMe4vvTaxPPq7Fq2NHDQ9RrlVvepaBXSmFL3ouiQUq I5lUcpLfe1TfHDxuIzacYK0dJA== X-Received: by 2002:adf:f206:: with SMTP id p6mr24947252wro.216.1565357670593; Fri, 09 Aug 2019 06:34:30 -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 y18sm5674641wmi.23.2019.08.09.06.34.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2019 06:34:30 -0700 (PDT) From: Srinivas Kandagatla To: vkoul@kernel.org, broonie@kernel.org Cc: bgoswami@codeaurora.org, plai@codeaurora.org, pierre-louis.bossart@linux.intel.com, robh+dt@kernel.org, devicetree@vger.kernel.org, lgirdwood@gmail.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH v3 2/4] soundwire: core: add device tree support for slave devices Date: Fri, 9 Aug 2019 14:34:05 +0100 Message-Id: <20190809133407.25918-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190809133407.25918-1-srinivas.kandagatla@linaro.org> References: <20190809133407.25918-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 | 44 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) -- 2.21.0 diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index fe745830a261..324c54dc52fb 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -77,6 +77,8 @@ 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 if (IS_ENABLED(CONFIG_OF) && bus->dev->of_node) + ret = sdw_of_find_slaves(bus); else ret = -ENOTSUPP; /* No ACPI/DT so error out */ 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..c0dd79fc4fc5 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" @@ -35,6 +36,7 @@ static int sdw_slave_add(struct sdw_bus *bus, 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,45 @@ int sdw_acpi_find_slaves(struct sdw_bus *bus) } #endif + +/* + * 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; + + for_each_child_of_node(bus->dev->of_node, node) { + struct sdw_slave_id id; + const char *compat = NULL; + int unique_id, link_id, sdw_version, ret; + + compat = of_get_property(node, "compatible", NULL); + if (!compat) + continue; + + ret = sscanf(compat, "sdw%01x%01x%01x%04hx%04hx%02hhx", + &link_id, &sdw_version, &unique_id, &id.mfg_id, + &id.part_id, &id.class_id); + + if (ret != 6) { + dev_err(dev, "Invalid compatible string found %s\n", + compat); + continue; + } + + /* Check for link_id match */ + if (link_id != bus->link_id) + continue; + + id.sdw_version = sdw_version; + id.unique_id = unique_id; + sdw_slave_add(bus, &id, of_fwnode_handle(node)); + } + + return 0; +}