From patchwork Thu Aug 22 23:37:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 172071 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1569021ily; Thu, 22 Aug 2019 16:38:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqyboQcJ5xTkmS2+vBk1juGIdvEikNGmGdi5LX+43Ek1tW3LQrvy36aktnww2CkQoBSRjWNe X-Received: by 2002:a17:902:d883:: with SMTP id b3mr204915plz.323.1566517108738; Thu, 22 Aug 2019 16:38:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566517108; cv=none; d=google.com; s=arc-20160816; b=1GmpRY/lqpzVaZbvUrb+L1+xZrHCwlOl7+6ZBUprepeEFXHLUWgXAReVn3dJHeY8Bz QqEBByPImiSdac0MqCwi9KI3z4cz9Rm1jIBSrpz/aG4upIwsn7Ea6C8G374ltg3E/tvU AsD+uhT2o/+OsWf1COB4kuCPjY7lcFPPNgOcNrm2+CZ9VW+7g3CnNiEHorUjhgLcEmgD xj64v68UDJUMBjNCKx4o/SRch5FDFCY9oCeP1f5PMz7Wh+D4dS3gMQdhhvVAkp+Oup/Y A2XHw9PjafHFvb/cnnZ8S4VAI7Me4njlQtIof1DKmylwMaamY8N2m1U9N1BawFD5E7iB zypg== 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=wEysXn0BHtJ7BnPMP+dSrHUvSy8/goLl6VzMxecNkns=; b=0q9G0uRpIiWUvjJfwGror1ZAiOvH5jUJATrog07C8TAxigXRLi/3mM15Vxwy0qXh34 BIRtiMElc4rzms5Zyt5SgVjKY1kgE1Z3kU7FoWPr4vMPDq3M/FcApcKvlcfh4Acl4NNA L3aHMnvw8P5A2Ds27aVlLKtgbQxEAFJf59OJ+cIePTHo/K7Tdiuzp6lqkB4JBJ3xtrS4 WsLiQK9Av39H+lusBWDo5QyVkB9OGUELkeA8NhpAvtQz0LWoMUmXKIFxJrlr1mA6TV2R zrRAFxKGEArr/ZsrQNexvPenlapvDZcNRk7iMJT8S9B8xEr0l40CMEHPjLQu1MKaBA2h SZnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hdh1e0vd; 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 w19si564061pga.462.2019.08.22.16.38.28; Thu, 22 Aug 2019 16:38:28 -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=Hdh1e0vd; 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 S1726989AbfHVXi1 (ORCPT + 28 others); Thu, 22 Aug 2019 19:38:27 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35456 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726936AbfHVXiY (ORCPT ); Thu, 22 Aug 2019 19:38:24 -0400 Received: by mail-wr1-f65.google.com with SMTP id k2so6957796wrq.2 for ; Thu, 22 Aug 2019 16:38:22 -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=wEysXn0BHtJ7BnPMP+dSrHUvSy8/goLl6VzMxecNkns=; b=Hdh1e0vdmHrJYBwIbbD5Lk9wGK6lz7Ln0Rumc29tiH3kGuxJc4cez410CygTt5ia79 1qGOwO5JqHDlNYihAcM4LfArfFjrHJ7KMoy41e1BfMa0FreZb+4ZwB83/udYC3o0ce7f nTuNvc2XyCAZY99sKdEoNXSwXuHg+1ngQ0LxU7sOHytsV1RPiFhch4Xys2EOX1I0kPtH zoZpJ4/r+81lE4nsK0ZKPvcRIBMEun/4m7sp5iGSQIBYbJ+uGUrRZSQseALCx9mYMIT6 MK2Jayx4cFOHWwHXOuD3e/evySK1baODNGro19U/e/hrXAXJoOs/AmupLx/q/QcW+a4w SLTg== 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=wEysXn0BHtJ7BnPMP+dSrHUvSy8/goLl6VzMxecNkns=; b=kkfnTp6FW/mVejlUKuDgJqUISmSD+CuCPd59b8aasW5tO1ks5PBiqoUYCzaKDpfUzj 7ogWHZn7MP9lbdLfNZI4HG2V6alaP8RU5+RXQ3Q6x+ZRqj/Mn386xQZoUiI8o9JsHUsV y+SCDd26eZHDQ2VlmLAgE9gl2e0dTbIpeJm7hfWBbte54bYtEl9pUevHXPaGfHfOHxCI yR1J34lm9uKrzF4tjyFg/brjaqu5D5QjNOOKrOjutRqvpA6oc4i3o/ji6CAqC/nmyScI MP2HjY1SxBgU8PFb+SomLCKkwMLvIGKCu91gDXPWPammt1TGgm83UTpfMkiB5HsY2COX 82tg== X-Gm-Message-State: APjAAAWjEuBQHbWWosqWjnJvOHFljHulpRErhP7KUIrnso86JocwXezv OXNvIAiJ4dLaN3/a8zZeOJNyxA== X-Received: by 2002:adf:dbcd:: with SMTP id e13mr1250035wrj.314.1566517102181; Thu, 22 Aug 2019 16:38:22 -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 f134sm1705157wmg.20.2019.08.22.16.38.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2019 16:38:21 -0700 (PDT) From: Srinivas Kandagatla To: broonie@kernel.org, robh+dt@kernel.org, vkoul@kernel.org Cc: spapothi@codeaurora.org, bgoswami@codeaurora.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, devicetree@vger.kernel.org, Srinivas Kandagatla Subject: [RESEND PATCH v4 2/4] soundwire: core: add device tree support for slave devices Date: Fri, 23 Aug 2019 00:37:57 +0100 Message-Id: <20190822233759.12663-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190822233759.12663-1-srinivas.kandagatla@linaro.org> References: <20190822233759.12663-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 | 52 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) -- 2.21.0 diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 49f64b2115b9..c2eaeb5c38ed 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..3ef265d2ee89 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,53 @@ 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) { + int link_id, sdw_version, ret, len; + const char *compat = NULL; + struct sdw_slave_id id; + const __be32 *addr; + + compat = of_get_property(node, "compatible", NULL); + if (!compat) + continue; + + ret = sscanf(compat, "sdw%01x%04hx%04hx%02hhx", &sdw_version, + &id.mfg_id, &id.part_id, &id.class_id); + + if (ret != 4) { + dev_err(dev, "Invalid compatible string found %s\n", + compat); + continue; + } + + addr = of_get_property(node, "reg", &len); + if (!addr || (len < 2 * sizeof(u32))) { + dev_err(dev, "Invalid Instance and Link ID\n"); + continue; + } + + id.unique_id = be32_to_cpup(addr++); + link_id = be32_to_cpup(addr); + id.sdw_version = sdw_version; + + /* Check for link_id match */ + if (link_id != bus->link_id) + continue; + + sdw_slave_add(bus, &id, of_fwnode_handle(node)); + } + + return 0; +}