From patchwork Thu Aug 29 14:44: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: 172628 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp2329640ily; Thu, 29 Aug 2019 07:45:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqyH68yMgVqLXsAVSfCwHMQLuVMXpW8BHQjqBCx9V7FYcSSlfUVk6HXZw6DUqa9SFNT3j4eE X-Received: by 2002:a63:841:: with SMTP id 62mr7925136pgi.1.1567089914979; Thu, 29 Aug 2019 07:45:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567089914; cv=none; d=google.com; s=arc-20160816; b=oeelwNOVYPVIr4JVSaEgohNwfmbjdWgLEtBMSrP0xN3Im9cIBQxNOT68y0gosDQ7oG /mCYL97JxCf81NCqVxg1ifkt3KWmXtGQTRLCMX7UxkjLKU7ZWUGMkEG4mmCIIO4T8Axq cTSKyb8JK8/Jl6EkAFY+DvB5EB98ir/wJ/unzfjmTj7Oosb1jx8sN/1w+I8poPxIlpbM BDWVMCrSZBda26w8AHdACX6+ssajjwpOsDH/StzoElqSBrocTDX3NxVrEw0sHDEvDXAr O+tvx+OTH2YDOkz6kJTIi4JU4TIRhVm0c+UxvrK9m0qVCLUYCxA9XCimOmo3bTOmtGKy hMlQ== 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=0y/VQ+YRgpX5o2wxlaY+4cXYuAJOmCwTGDSCpRsawzo=; b=Hc3fLzUXLM8fvSoU6tBSg9XESv6VeQUTwQsiJLgnk5zdl0Cg5H2UnxmVjRq4aIOw7h FJUfTaOlIxkcXA8uyGxGNl2U4YYWA5SFaOHhKqsK1dW5IboXhzBP4raJRiArRymwkjRv rpuBjS4h5vPe72F5mfIMA3N2weXcAmzLKrxNxRiFWge1gOqgz9K/gyr+CR40cSh9czaB Kjc7WOVYsIxiSHzIZ6ux8bbbfvVMLzmzz6/lcPcdrdd6U571Ls3wt2nxOilM21Jcw/AD tAOqby6Ov47xgxobzPemC6FVMs+3GrCtNouJgrp5qsIqiJeeBPIhwgUWSiX06SrSOYqi 17lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NkAfVlr4; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 a10si2815890pfo.179.2019.08.29.07.45.14; Thu, 29 Aug 2019 07:45:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-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=NkAfVlr4; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 S1727066AbfH2OpO (ORCPT + 8 others); Thu, 29 Aug 2019 10:45:14 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:55442 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726973AbfH2OpE (ORCPT ); Thu, 29 Aug 2019 10:45:04 -0400 Received: by mail-wm1-f68.google.com with SMTP id g207so47680wmg.5 for ; Thu, 29 Aug 2019 07:45:02 -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=0y/VQ+YRgpX5o2wxlaY+4cXYuAJOmCwTGDSCpRsawzo=; b=NkAfVlr432msV3xiejrJCyjhA0VgLAduniaZbLpPM/u0czuJsdy92Lnf77knkplR0m dZKuZD7vEcceC66QCJQVbwtUKce/BRcvv2VgLcwP8kGTrHf6PB4IS6lxgPHup/REV7BO y3SdHAyWNGl4T8HXhXrAu3iy2nf/yslRwvGNqB/heA9Zeu3GkGCaUB53EbXjvadLXZlQ rjOaSfCQKlMOqVNf/ahb0pWn/rEKyYsNmEzbfJ/E84xbjhe7cuhxW1qSvC14i+PaEDFp X/UIOvzYNvSqtwX3I8hhWgTw4weJvEhoYblpGenKlJKfoJeeA3u3YuL7jVCFUSVYeaSD CpMQ== 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=0y/VQ+YRgpX5o2wxlaY+4cXYuAJOmCwTGDSCpRsawzo=; b=r9Cf3HsHJs1hcAh2S92WrrQtiB4YueOPMhm1j+Qnm/pmWmv4bBiIAPOVKZzUhAosy2 WU+/oVicf2qPTVLh+H8YC/8gVZpwOsq1MmahQQvV5OtT+CkLvhz8p6KFROOu8HvQAm8B 5mPULr1cP0IFST3NwsSeEhrTA6L4Wko/1pETwqp95GCIKo4emg/btTSWcEmx93Cs6fI2 eyl5hY4ybEmPTOLoUuhA1SYMy33v0pm/wSCQFEy4n398DlYM7vw9JXPx1gQu4FV5DdzA d24ZBVZ6gdLe55ksVjWyWbusFqI+2v9CTiqO5XBAiCGaNpEuSuQKfYEka29oMpl4wOKg rrKw== X-Gm-Message-State: APjAAAV8/lZuItzKOns6Tg58W+93YHo8hli/eN+63pPoSXOwOH6Lz4SL aJ8X025enLhbo/24sumguOt3AQ== X-Received: by 2002:a05:600c:22c6:: with SMTP id 6mr3555569wmg.5.1567089901850; Thu, 29 Aug 2019 07:45:01 -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 p7sm3923492wmh.38.2019.08.29.07.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 07:45:01 -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: [PATCH v5 2/4] soundwire: core: add device tree support for slave devices Date: Thu, 29 Aug 2019 15:44:40 +0100 Message-Id: <20190829144442.6210-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190829144442.6210-1-srinivas.kandagatla@linaro.org> References: <20190829144442.6210-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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 728db3ebad6e..d83d89b3b15a 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -79,6 +79,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 9d6ea7e447ff..cb482da914da 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 4b522f6d1238..48a63ca130d2 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; @@ -113,3 +115,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 Link and Instance ID\n"); + continue; + } + + link_id = be32_to_cpup(addr++); + id.unique_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; +}