From nobody Wed Apr 8 06:11:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE3ACC25B08 for ; Tue, 23 Aug 2022 04:46:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239658AbiHWEqV (ORCPT ); Tue, 23 Aug 2022 00:46:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239292AbiHWEqR (ORCPT ); Tue, 23 Aug 2022 00:46:17 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9ECF52FEE for ; Mon, 22 Aug 2022 21:46:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661229976; x=1692765976; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IPnnb0fU/qVJlOwgD1izgy0CaO2aldoMjVq4ZHg4Azw=; b=aUifaUWa+1n45Omla3+aDpL51Q5KH0zpvNWZGhHWXoBkjwUE6lnSuF06 GGnqVHSAD4Si1Cq6r6RQ2xMDSkY/u2lB9fmxR0rrK9TlfNZULWwQadhg5 WtM1+yogXg99n9J5m4ViUGNsrhRZiEIs3U6li9yeihn6dYnVqNnCDSE5+ FL/mJyHc0oRvCO+zKolKFK57VqftiFBw7bW/qhQR9jdtkQxdArHT9Dvu/ bPduXDjeZ6C0I6CBy7y/AqZzAp/9ZYMoeJFo18ZuH7TXDBKnZsosrorFp H8vyQCYrFAEacbc+wWeJ75yzzx8eIPtH6mkPeB3YyqpOR0j3PqvmwMwwG w==; X-IronPort-AV: E=McAfee;i="6500,9779,10447"; a="291146781" X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="291146781" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2022 21:46:16 -0700 X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="669855093" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2022 21:46:15 -0700 From: Bard Liao To: alsa-devel@alsa-project.org, vkoul@kernel.org Cc: vinod.koul@linaro.org, linux-kernel@vger.kernel.org, pierre-louis.bossart@linux.intel.com, bard.liao@intel.com Subject: [PATCH 1/3] soundwire: bus: rename sdw_ida as sdw_bus_ida Date: Tue, 23 Aug 2022 12:50:02 +0800 Message-Id: <20220823045004.2670658-2-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220823045004.2670658-1-yung-chuan.liao@linux.intel.com> References: <20220823045004.2670658-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Pierre-Louis Bossart To avoid confusions with follow-up patches using a IDA mechanism for peripheral 'device number' allocation, rename sdw_ida as sdw_bus_ida. Pure rename, no functionality change. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Ranjani Sridharan Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- drivers/soundwire/bus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 8d4000664fa3..37638c20c804 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -11,11 +11,11 @@ #include "bus.h" #include "sysfs_local.h" =20 -static DEFINE_IDA(sdw_ida); +static DEFINE_IDA(sdw_bus_ida); =20 static int sdw_get_id(struct sdw_bus *bus) { - int rc =3D ida_alloc(&sdw_ida, GFP_KERNEL); + int rc =3D ida_alloc(&sdw_bus_ida, GFP_KERNEL); =20 if (rc < 0) return rc; @@ -179,7 +179,7 @@ void sdw_bus_master_delete(struct sdw_bus *bus) sdw_master_device_del(bus); =20 sdw_bus_debugfs_exit(bus); - ida_free(&sdw_ida, bus->id); + ida_free(&sdw_bus_ida, bus->id); } EXPORT_SYMBOL(sdw_bus_master_delete); =20 --=20 2.25.1 From nobody Wed Apr 8 06:11:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B985C25B08 for ; Tue, 23 Aug 2022 04:46:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239727AbiHWEq0 (ORCPT ); Tue, 23 Aug 2022 00:46:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239586AbiHWEqT (ORCPT ); Tue, 23 Aug 2022 00:46:19 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC31053005 for ; Mon, 22 Aug 2022 21:46:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661229978; x=1692765978; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ge8z9tQugUy9cTnjB8duw2RGaf7wv9bBNLATuLcW9CY=; b=elrrfJM3eZYdgPKBkZRFAh8d2PCPSOReWZhPprKdzbZFqynsCSa2dwbh yoXywks9Ib0f6jEcIIf557P9ViwwfwAcBbUQ7E6IhsQSmRJLUAKzr3wZN znT1E4r+Qn9dsCsbDdx97K5ijNC4HRRkD/1/X7SN8OdBJWC4rOVGJJeeS IU7iTUvpvjk7BIj+cXf5HzXN/SivEwxXJFqxOdKr0npip4UteruxzBi+B kJdA8fN3920NFW6nTI2hZsibfWi15Gk6Zqjcz/QJSJhHovJ/eoedhiiT1 FsEfjVWBpbNxEcYsa3oMg4JAF/6kRlo2IXKU5XmoQKSJamYQ7Tiem6fZj A==; X-IronPort-AV: E=McAfee;i="6500,9779,10447"; a="291146794" X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="291146794" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2022 21:46:18 -0700 X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="669855099" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2022 21:46:16 -0700 From: Bard Liao To: alsa-devel@alsa-project.org, vkoul@kernel.org Cc: vinod.koul@linaro.org, linux-kernel@vger.kernel.org, pierre-louis.bossart@linux.intel.com, bard.liao@intel.com Subject: [PATCH 2/3] soundwire: bus: allow device number to be unique at system level Date: Tue, 23 Aug 2022 12:50:03 +0800 Message-Id: <20220823045004.2670658-3-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220823045004.2670658-1-yung-chuan.liao@linux.intel.com> References: <20220823045004.2670658-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Pierre-Louis Bossart The SoundWire specification allows the device number to be allocated at will. When a system includes multiple SoundWire links, the device number scope is limited to the link to which the device is attached. However, for integration/debug it can be convenient to have a unique device number across the system. This patch adds a 'dev_num_ida_min' field at the bus level, which when set will be used to allocate an IDA. The allocation happens when a hardware device reports as ATTACHED. If any error happens during the enumeration, the allocated IDA is not freed - the device number will be reused if/when the device re-joins the bus. The IDA is only freed when the Linux device is unregistered. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Ranjani Sridharan Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- drivers/soundwire/bus.c | 23 +++++++++++++++++------ include/linux/soundwire/sdw.h | 4 ++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 37638c20c804..8970f8560766 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -12,6 +12,7 @@ #include "sysfs_local.h" =20 static DEFINE_IDA(sdw_bus_ida); +static DEFINE_IDA(sdw_peripheral_ida); =20 static int sdw_get_id(struct sdw_bus *bus) { @@ -157,9 +158,11 @@ static int sdw_delete_slave(struct device *dev, void *= data) =20 mutex_lock(&bus->bus_lock); =20 - if (slave->dev_num) /* clear dev_num if assigned */ + if (slave->dev_num) { /* clear dev_num if assigned */ clear_bit(slave->dev_num, bus->assigned); - + if (bus->dev_num_ida_min) + ida_free(&sdw_peripheral_ida, slave->dev_num); + } list_del_init(&slave->node); mutex_unlock(&bus->bus_lock); =20 @@ -639,10 +642,18 @@ static int sdw_get_device_num(struct sdw_slave *slave) { int bit; =20 - bit =3D find_first_zero_bit(slave->bus->assigned, SDW_MAX_DEVICES); - if (bit =3D=3D SDW_MAX_DEVICES) { - bit =3D -ENODEV; - goto err; + if (slave->bus->dev_num_ida_min) { + bit =3D ida_alloc_range(&sdw_peripheral_ida, + slave->bus->dev_num_ida_min, SDW_MAX_DEVICES, + GFP_KERNEL); + if (bit < 0) + goto err; + } else { + bit =3D find_first_zero_bit(slave->bus->assigned, SDW_MAX_DEVICES); + if (bit =3D=3D SDW_MAX_DEVICES) { + bit =3D -ENODEV; + goto err; + } } =20 /* diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h index 39058c841469..a2b31d25ea27 100644 --- a/include/linux/soundwire/sdw.h +++ b/include/linux/soundwire/sdw.h @@ -889,6 +889,9 @@ struct sdw_master_ops { * meaningful if multi_link is set. If set to 1, hardware-based * synchronization will be used even if a stream only uses a single * SoundWire segment. + * @dev_num_ida_min: if set, defines the minimum values for the IDA + * used to allocate system-unique device numbers. This value needs to be + * identical across all SoundWire bus in the system. */ struct sdw_bus { struct device *dev; @@ -913,6 +916,7 @@ struct sdw_bus { u32 bank_switch_timeout; bool multi_link; int hw_sync_min_links; + int dev_num_ida_min; }; =20 int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent, --=20 2.25.1 From nobody Wed Apr 8 06:11:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2907C25B08 for ; Tue, 23 Aug 2022 04:46:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239755AbiHWEqb (ORCPT ); Tue, 23 Aug 2022 00:46:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239646AbiHWEqV (ORCPT ); Tue, 23 Aug 2022 00:46:21 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A2D654C8E for ; Mon, 22 Aug 2022 21:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661229980; x=1692765980; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aOGj0K2ETS0PToUhNjSmBRGkI427Kgkon4oqhCsUotM=; b=Kxw90btpNoYxDcI1EoWUYwvxb8KAc6FsCo7s9uJYky7ASlYFtvNeF3bm hdKWinzraT5ok+I/VDNpHaKpTVDSgtWh517ZvuvHfjN9Psj01BL90IF1l qeY5muJXFK3XIIQ+Alc+xhH683zQF2QXQQdekjCSABjfyLTxVgLw6U/Jh NeON7SL9s32zQAJ7ZnAzziEOGRipyonQOacApu/xG7+Yya/CukP7gT+oH RLQKAkucQ3Jkk2QGYUr4HTRhduKA9Br1GukLmMdEObmS5TvW8gfWAurCe 4HeYohuhuNxiUjHdlVnUQa6yA6/qdUXqYyD/9k7ESJkvRjzph+FaRXVUk g==; X-IronPort-AV: E=McAfee;i="6500,9779,10447"; a="291146804" X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="291146804" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2022 21:46:20 -0700 X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="669855112" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2022 21:46:18 -0700 From: Bard Liao To: alsa-devel@alsa-project.org, vkoul@kernel.org Cc: vinod.koul@linaro.org, linux-kernel@vger.kernel.org, pierre-louis.bossart@linux.intel.com, bard.liao@intel.com Subject: [PATCH 3/3] soundwire: intel: set dev_num_ida_min Date: Tue, 23 Aug 2022 12:50:04 +0800 Message-Id: <20220823045004.2670658-4-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220823045004.2670658-1-yung-chuan.liao@linux.intel.com> References: <20220823045004.2670658-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Pierre-Louis Bossart The allowed values for SoundWire device numbers are between 1 and 11 (inclusive). HDaudio/iDISP codecs typically use SDI values 0..3 (inclusive). To allow for a unique peripheral SDI/dev_number across HDaudio and SoundWire buses, we set the minimum base to 4. This still allows for 8 SoundWire peripherals in the system, currently more than needed in actual products. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Ranjani Sridharan Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- drivers/soundwire/intel.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c index 89d1d0d021fc..3e372599a8c3 100644 --- a/drivers/soundwire/intel.c +++ b/drivers/soundwire/intel.c @@ -22,6 +22,9 @@ #include "bus.h" #include "intel.h" =20 +/* IDA min selected to avoid conflicts with HDaudio/iDISP SDI values */ +#define INTEL_DEV_NUM_IDA_MIN 4 + #define INTEL_MASTER_SUSPEND_DELAY_MS 3000 #define INTEL_MASTER_RESET_ITERATIONS 10 =20 @@ -1307,6 +1310,7 @@ static int intel_link_probe(struct auxiliary_device *= auxdev, cdns->msg_count =3D 0; =20 bus->link_id =3D auxdev->id; + bus->dev_num_ida_min =3D INTEL_DEV_NUM_IDA_MIN; =20 sdw_cdns_probe(cdns); =20 --=20 2.25.1