From patchwork Fri Dec 10 15:40:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Binding X-Patchwork-Id: 523333 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 188EDC43219 for ; Fri, 10 Dec 2021 15:42:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243028AbhLJPpq (ORCPT ); Fri, 10 Dec 2021 10:45:46 -0500 Received: from mx0b-001ae601.pphosted.com ([67.231.152.168]:22662 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242993AbhLJPpo (ORCPT ); Fri, 10 Dec 2021 10:45:44 -0500 Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1BACurAP000494; Fri, 10 Dec 2021 09:41:59 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=+LsQfNrXPpS3619hB6d32pwpbK8k5wkGpt6c1VKkZRw=; b=qSW80zPmEcedRmYnP2bpFjWEdklPcazM3jJTzqvMSOCdQ/78E8qFndDYv/16a2ZtZnvY bdYbDnoWIYe3iumKidPDAY77Ir42IClaD4tv15P+RIT71TvYq60obwutMGDY0nWjPk53 VKyW9x9Ss7sg7cVuqUghoXydppdltaxAdwLGRgn4l14FHHyKtlsCoa7Uaba4yutxnpHz LaWWqElXAUu04U+Zu9rUA5zt+ysW9HDimaMD3/Fs0AtngiiQtwcqJkSbpAn6jeIvkqT6 UH2Fr1eNtkh0liTddf00lzJGfraOsu5fRdlhIYNao1MS2F8l27c5yGqfUcuJ1JGr/dKH tg== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3cuds09y4p-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 10 Dec 2021 09:41:59 -0600 Received: from EDIEX01.ad.cirrus.com (198.61.84.80) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Fri, 10 Dec 2021 15:41:57 +0000 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Fri, 10 Dec 2021 15:41:57 +0000 Received: from LONN2DGDQ73.ad.cirrus.com (unknown [198.90.238.135]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 88249478; Fri, 10 Dec 2021 15:41:57 +0000 (UTC) From: Stefan Binding To: Mark Brown , "Rafael J . Wysocki" , Len Brown , Hans de Goede , Mark Gross CC: , , , , , Stefan Binding Subject: [PATCH v2 1/6] spi: Export acpi_spi_find_controller_by_adev to be used externally Date: Fri, 10 Dec 2021 15:40:45 +0000 Message-ID: <20211210154050.3713-2-sbinding@opensource.cirrus.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211210154050.3713-1-sbinding@opensource.cirrus.com> References: <20211210154050.3713-1-sbinding@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: UV12cpRZQDJSAQbnJVVNVO7uErIxPTTs X-Proofpoint-ORIG-GUID: UV12cpRZQDJSAQbnJVVNVO7uErIxPTTs X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org This will be used by bus-multi-instantiate to support spi. Signed-off-by: Stefan Binding --- drivers/spi/spi.c | 3 ++- include/linux/spi/spi.h | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 8726309b3eaf..9495f776e53c 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -4200,7 +4200,7 @@ static int spi_acpi_controller_match(struct device *dev, const void *data) return ACPI_COMPANION(dev->parent) == data; } -static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev) +struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev) { struct device *dev; @@ -4214,6 +4214,7 @@ static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_devic return container_of(dev, struct spi_controller, dev); } +EXPORT_SYMBOL_GPL(acpi_spi_find_controller_by_adev); static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev) { diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index eb7ac8a1e03c..8c2978853573 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -17,6 +17,7 @@ #include #include +#include struct dma_chan; struct software_node; @@ -759,6 +760,15 @@ extern int devm_spi_register_controller(struct device *dev, struct spi_controller *ctlr); extern void spi_unregister_controller(struct spi_controller *ctlr); +#if IS_ENABLED(CONFIG_ACPI) +extern struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev); +#else +static inline struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev) +{ + return ERR_PTR(-EOPNOTSUPP); +} +#endif + /* * SPI resource management while processing a SPI message */ From patchwork Fri Dec 10 15:40:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Binding X-Patchwork-Id: 522990 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 DEC8AC433F5 for ; Fri, 10 Dec 2021 15:42:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243036AbhLJPpq (ORCPT ); Fri, 10 Dec 2021 10:45:46 -0500 Received: from mx0b-001ae601.pphosted.com ([67.231.152.168]:19738 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242992AbhLJPpo (ORCPT ); Fri, 10 Dec 2021 10:45:44 -0500 Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1BACurAR000494; Fri, 10 Dec 2021 09:42:00 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=v1Qh9lWm4IKBdghH93JFeiDyjO1mi+pXvGRYPvw/xw4=; b=G3/yqbihiY+aQQMfh8mx8fHKwn337EbL3+fKRlMAd8eIK3U/ncZqBhaVvSmiRMaXwu4T GAawIk4I3qrjpc32MCN7SatZ+q3l6mBIym/VCkE4chX1Op9ploLge7Gw8Cfn+SblVKOL LBeWjBeEW+dJ4E4qM9HfXz9MVycXbgydyTHcd2xgIdSlib3xE5ZnJD6sCyG/wDJ7Gspg TEGtC83BACGF6kJDcQVO2KdUhbg+rw+8eiBFPnnVqlJKTBOC5mwGU/56PCqbPQuPvMa5 h9d8JdeWfl0gp9lAmNEYfogjAoBfVus0WD0EdyapnZ3XiCI0x1UtW6dQ18eix3pxRsg0 VA== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3cuds09y4p-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 10 Dec 2021 09:42:00 -0600 Received: from EDIEX01.ad.cirrus.com (198.61.84.80) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Fri, 10 Dec 2021 15:41:58 +0000 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Fri, 10 Dec 2021 15:41:58 +0000 Received: from LONN2DGDQ73.ad.cirrus.com (unknown [198.90.238.135]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id CE1072AA; Fri, 10 Dec 2021 15:41:57 +0000 (UTC) From: Stefan Binding To: Mark Brown , "Rafael J . Wysocki" , Len Brown , Hans de Goede , Mark Gross CC: , , , , , Stefan Binding Subject: [PATCH v2 2/6] spi: Make spi_alloc_device and spi_add_device public again Date: Fri, 10 Dec 2021 15:40:46 +0000 Message-ID: <20211210154050.3713-3-sbinding@opensource.cirrus.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211210154050.3713-1-sbinding@opensource.cirrus.com> References: <20211210154050.3713-1-sbinding@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: VNk9--TW9PrL157D9hpSAproVy37QNqJ X-Proofpoint-ORIG-GUID: VNk9--TW9PrL157D9hpSAproVy37QNqJ X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org This functions were previously made private since they were not used. However, these functions will be needed again. Partial revert of commit da21fde0fdb3 ("spi: Make several public functions private to spi.c") Signed-off-by: Stefan Binding --- drivers/spi/spi.c | 6 ++++-- include/linux/spi/spi.h | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 9495f776e53c..33ed5693560d 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -531,7 +531,7 @@ static DEFINE_MUTEX(board_lock); * * Return: a pointer to the new device, or NULL. */ -static struct spi_device *spi_alloc_device(struct spi_controller *ctlr) +struct spi_device *spi_alloc_device(struct spi_controller *ctlr) { struct spi_device *spi; @@ -556,6 +556,7 @@ static struct spi_device *spi_alloc_device(struct spi_controller *ctlr) device_initialize(&spi->dev); return spi; } +EXPORT_SYMBOL_GPL(spi_alloc_device); static void spi_dev_set_name(struct spi_device *spi) { @@ -651,7 +652,7 @@ static int __spi_add_device(struct spi_device *spi) * * Return: 0 on success; negative errno on failure */ -static int spi_add_device(struct spi_device *spi) +int spi_add_device(struct spi_device *spi) { struct spi_controller *ctlr = spi->controller; struct device *dev = ctlr->dev.parent; @@ -672,6 +673,7 @@ static int spi_add_device(struct spi_device *spi) mutex_unlock(&ctlr->add_lock); return status; } +EXPORT_SYMBOL_GPL(spi_add_device); static int spi_add_device_locked(struct spi_device *spi) { diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 8c2978853573..d70e66c712d0 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -1462,7 +1462,19 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n) * use spi_new_device() to describe each device. You can also call * spi_unregister_device() to start making that device vanish, but * normally that would be handled by spi_unregister_controller(). + * + * You can also use spi_alloc_device() and spi_add_device() to use a two + * stage registration sequence for each spi_device. This gives the caller + * some more control over the spi_device structure before it is registered, + * but requires that caller to initialize fields that would otherwise + * be defined using the board info. */ +extern struct spi_device * +spi_alloc_device(struct spi_controller *ctlr); + +extern int +spi_add_device(struct spi_device *spi); + extern struct spi_device * spi_new_device(struct spi_controller *, struct spi_board_info *); From patchwork Fri Dec 10 15:40:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Binding X-Patchwork-Id: 523332 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 E8AFFC43217 for ; Fri, 10 Dec 2021 15:42:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243048AbhLJPpr (ORCPT ); Fri, 10 Dec 2021 10:45:47 -0500 Received: from mx0b-001ae601.pphosted.com ([67.231.152.168]:59426 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243000AbhLJPpo (ORCPT ); Fri, 10 Dec 2021 10:45:44 -0500 Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1BACurAQ000494; Fri, 10 Dec 2021 09:42:00 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=XrnF6YfdnNKFeMn/V4qMHV3tDq9BK40/tRRsos4brQI=; b=RULwfwiu6IlRH07b22tAu8+T2iA3WWrxaA++ZQBUW1pYF1NmfQdrA4vOxftB0hihQnEN GpaYaIlDQYjVywMtiVORKtiUlAPbgP3REzhSU+3KRanupfVnMRm1Qv0UY0IK7UusOemN gSTZWe25qNLTwC6/nXRmk8fRO7WwPaFT8CHNnA6fhfetdRB+A00YkV1ZU+99oe7uYHX1 5PPV2/DQnGSuglUGDiSnQAaQ4v8eO+FR3ulyuPvw6/pPkgTreleBfNSue9hHHMs+B3D/ fE03NZYAzzWoZ2HAjhYGVKRK8VckVgkgUDP1ipGKJq1BUYeNL/nKLgsqsCDSSCrQXv4U BQ== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3cuds09y4q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 10 Dec 2021 09:42:00 -0600 Received: from EDIEX01.ad.cirrus.com (198.61.84.80) by EDIEX02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Fri, 10 Dec 2021 15:41:58 +0000 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Fri, 10 Dec 2021 15:41:58 +0000 Received: from LONN2DGDQ73.ad.cirrus.com (unknown [198.90.238.135]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 1F82D478; Fri, 10 Dec 2021 15:41:58 +0000 (UTC) From: Stefan Binding To: Mark Brown , "Rafael J . Wysocki" , Len Brown , Hans de Goede , Mark Gross CC: , , , , , Lucas Tanure Subject: [PATCH v2 3/6] platform/x86: i2c-multi-instantiate: Move it to drivers/acpi folder Date: Fri, 10 Dec 2021 15:40:47 +0000 Message-ID: <20211210154050.3713-4-sbinding@opensource.cirrus.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211210154050.3713-1-sbinding@opensource.cirrus.com> References: <20211210154050.3713-1-sbinding@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: iTztqA9Q0kOtUf6BmxOuBtV6T8CAT7dM X-Proofpoint-ORIG-GUID: iTztqA9Q0kOtUf6BmxOuBtV6T8CAT7dM X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org From: Lucas Tanure Moving I2C multi instantiate driver to drivers/acpi folder for upcoming conversion into a generic bus multi instantiate driver for SPI and I2C Signed-off-by: Lucas Tanure --- MAINTAINERS | 2 +- drivers/acpi/Kconfig | 11 +++++++++++ drivers/acpi/Makefile | 1 + .../{platform/x86 => acpi}/i2c-multi-instantiate.c | 0 drivers/acpi/scan.c | 2 +- drivers/platform/x86/Kconfig | 11 ----------- drivers/platform/x86/Makefile | 1 - 7 files changed, 14 insertions(+), 14 deletions(-) rename drivers/{platform/x86 => acpi}/i2c-multi-instantiate.c (100%) diff --git a/MAINTAINERS b/MAINTAINERS index cd55b83878e0..25e056854772 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -391,7 +391,7 @@ ACPI I2C MULTI INSTANTIATE DRIVER M: Hans de Goede L: platform-driver-x86@vger.kernel.org S: Maintained -F: drivers/platform/x86/i2c-multi-instantiate.c +F: drivers/acpi/i2c-multi-instantiate.c ACPI PCC(Platform Communication Channel) MAILBOX DRIVER M: Sudeep Holla diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index c97ee0cfe26e..6200d13fa97b 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -295,6 +295,17 @@ config ACPI_PROCESSOR To compile this driver as a module, choose M here: the module will be called processor. +config ACPI_I2C_MULTI_INST + tristate "I2C multi instantiate pseudo device driver" + depends on I2C + help + Some ACPI-based systems list multiple i2c-devices in a single ACPI + firmware-node. This driver will instantiate separate i2c-clients + for each device in the firmware-node. + + To compile this driver as a module, choose M here: the module + will be called i2c-multi-instantiate. + config ACPI_IPMI tristate "IPMI" depends on IPMI_HANDLER diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 3018714e87d9..98d700d55960 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -102,6 +102,7 @@ obj-$(CONFIG_ACPI_CPPC_LIB) += cppc_acpi.o obj-$(CONFIG_ACPI_SPCR_TABLE) += spcr.o obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o obj-$(CONFIG_ACPI_PPTT) += pptt.o +obj-$(CONFIG_ACPI_I2C_MULTI_INST) += i2c-multi-instantiate.o # processor has its own "processor." module_param namespace processor-y := processor_driver.o diff --git a/drivers/platform/x86/i2c-multi-instantiate.c b/drivers/acpi/i2c-multi-instantiate.c similarity index 100% rename from drivers/platform/x86/i2c-multi-instantiate.c rename to drivers/acpi/i2c-multi-instantiate.c diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 5991dddbc9ce..e5c81b3df09c 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1700,7 +1700,7 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device) * must be instantiated for each, each with its own i2c_device_id. * Normally we only instantiate an i2c-client for the first resource, * using the ACPI HID as id. These special cases are handled by the - * drivers/platform/x86/i2c-multi-instantiate.c driver, which knows + * drivers/acpi/i2c-multi-instantiate.c driver, which knows * which i2c_device_id to use for each resource. */ static const struct acpi_device_id i2c_multi_instantiate_ids[] = { diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 97e87628eb35..1596c8e5bc9b 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -958,17 +958,6 @@ config TOPSTAR_LAPTOP If you have a Topstar laptop, say Y or M here. -config I2C_MULTI_INSTANTIATE - tristate "I2C multi instantiate pseudo device driver" - depends on I2C && ACPI - help - Some ACPI-based systems list multiple i2c-devices in a single ACPI - firmware-node. This driver will instantiate separate i2c-clients - for each device in the firmware-node. - - To compile this driver as a module, choose M here: the module - will be called i2c-multi-instantiate. - config MLX_PLATFORM tristate "Mellanox Technologies platform support" depends on I2C && REGMAP diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index 219478061683..dc075a036874 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -108,7 +108,6 @@ obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o # Platform drivers obj-$(CONFIG_FW_ATTR_CLASS) += firmware_attributes_class.o -obj-$(CONFIG_I2C_MULTI_INSTANTIATE) += i2c-multi-instantiate.o obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o obj-$(CONFIG_TOUCHSCREEN_DMI) += touchscreen_dmi.o obj-$(CONFIG_WIRELESS_HOTKEY) += wireless-hotkey.o From patchwork Fri Dec 10 15:40:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Binding X-Patchwork-Id: 522989 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 D0EDDC43217 for ; Fri, 10 Dec 2021 15:42:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243063AbhLJPps (ORCPT ); Fri, 10 Dec 2021 10:45:48 -0500 Received: from mx0b-001ae601.pphosted.com ([67.231.152.168]:41548 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236812AbhLJPpq (ORCPT ); Fri, 10 Dec 2021 10:45:46 -0500 Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1BACurAS000494; Fri, 10 Dec 2021 09:42:01 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=kvJMvbHtg2to5to/eNSxSoMs65hReV5fsSJ55FJj/2w=; b=OTB2H0/9F8dosb1Ep9fSr67+tPR9ycMnIR2mOJrLoU4Y9oAybUZebQA8lxdzaJNcOOus //egE0T20QBvkZ0mFXJx2rWeAHz76gvOYyAf8ubBEzl1KvfYQTLVL8do6iba/ILH0wr3 Xu2yyUeyvKxgMf9qgtK2d88Kpaboo/cieEFtT8hjnhc8PJif2G/w8LvOuG+gFTS30dMK SOcFmsOWv+w170nMKR74L+N6LT+xxsS3XUgL4ral24zJtoW61OfX2BgJKMZj0BJAaQIK BPkAmBUVumgQz6nCmHHy7KmBW8Q/EWDS/27JSJcPAXrmxilxu0ugKUem6vSiWaymbqWP Mw== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3cuds09y4q-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 10 Dec 2021 09:42:00 -0600 Received: from EDIEX01.ad.cirrus.com (198.61.84.80) by EDIEX02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Fri, 10 Dec 2021 15:41:58 +0000 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Fri, 10 Dec 2021 15:41:58 +0000 Received: from LONN2DGDQ73.ad.cirrus.com (unknown [198.90.238.135]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 65D072AA; Fri, 10 Dec 2021 15:41:58 +0000 (UTC) From: Stefan Binding To: Mark Brown , "Rafael J . Wysocki" , Len Brown , Hans de Goede , Mark Gross CC: , , , , , Lucas Tanure Subject: [PATCH v2 4/6] ACPI: i2c-multi-instantiate: Rename it for a generic bus driver name Date: Fri, 10 Dec 2021 15:40:48 +0000 Message-ID: <20211210154050.3713-5-sbinding@opensource.cirrus.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211210154050.3713-1-sbinding@opensource.cirrus.com> References: <20211210154050.3713-1-sbinding@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: KAJFFoJozoxV2DMnPdtWewtO_6FoPgw- X-Proofpoint-ORIG-GUID: KAJFFoJozoxV2DMnPdtWewtO_6FoPgw- X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org From: Lucas Tanure Rename I2C multi instantiate driver to bus-multi-instantiate for upcoming addition of SPI support Signed-off-by: Lucas Tanure --- MAINTAINERS | 4 +- drivers/acpi/Kconfig | 4 +- drivers/acpi/Makefile | 2 +- ...-instantiate.c => bus-multi-instantiate.c} | 89 +++++++++---------- drivers/acpi/scan.c | 8 +- 5 files changed, 53 insertions(+), 54 deletions(-) rename drivers/acpi/{i2c-multi-instantiate.c => bus-multi-instantiate.c} (53%) diff --git a/MAINTAINERS b/MAINTAINERS index 25e056854772..256b44bb6773 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -387,11 +387,11 @@ L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) S: Maintained F: drivers/acpi/arm64 -ACPI I2C MULTI INSTANTIATE DRIVER +ACPI BUS MULTI INSTANTIATE DRIVER M: Hans de Goede L: platform-driver-x86@vger.kernel.org S: Maintained -F: drivers/acpi/i2c-multi-instantiate.c +F: drivers/acpi/bus-multi-instantiate.c ACPI PCC(Platform Communication Channel) MAILBOX DRIVER M: Sudeep Holla diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 6200d13fa97b..6ba47dd39eb4 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -295,7 +295,7 @@ config ACPI_PROCESSOR To compile this driver as a module, choose M here: the module will be called processor. -config ACPI_I2C_MULTI_INST +config ACPI_BUS_MULTI_INST tristate "I2C multi instantiate pseudo device driver" depends on I2C help @@ -304,7 +304,7 @@ config ACPI_I2C_MULTI_INST for each device in the firmware-node. To compile this driver as a module, choose M here: the module - will be called i2c-multi-instantiate. + will be called bus-multi-instantiate. config ACPI_IPMI tristate "IPMI" diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 98d700d55960..38cf0ecc595a 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -102,7 +102,7 @@ obj-$(CONFIG_ACPI_CPPC_LIB) += cppc_acpi.o obj-$(CONFIG_ACPI_SPCR_TABLE) += spcr.o obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o obj-$(CONFIG_ACPI_PPTT) += pptt.o -obj-$(CONFIG_ACPI_I2C_MULTI_INST) += i2c-multi-instantiate.o +obj-$(CONFIG_ACPI_BUS_MULTI_INST) += bus-multi-instantiate.o # processor has its own "processor." module_param namespace processor-y := processor_driver.o diff --git a/drivers/acpi/i2c-multi-instantiate.c b/drivers/acpi/bus-multi-instantiate.c similarity index 53% rename from drivers/acpi/i2c-multi-instantiate.c rename to drivers/acpi/bus-multi-instantiate.c index 4956a1df5b90..982dfecfd27c 100644 --- a/drivers/acpi/i2c-multi-instantiate.c +++ b/drivers/acpi/bus-multi-instantiate.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * I2C multi-instantiate driver, pseudo driver to instantiate multiple + * Bus multi-instantiate driver, pseudo driver to instantiate multiple * i2c-clients from a single fwnode. * * Copyright 2018 Hans de Goede @@ -21,29 +21,29 @@ #define IRQ_RESOURCE_GPIO 1 #define IRQ_RESOURCE_APIC 2 -struct i2c_inst_data { +struct bmi_instance { const char *type; unsigned int flags; int irq_idx; }; -struct i2c_multi_inst_data { - int num_clients; - struct i2c_client *clients[]; +struct bmi { + int i2c_num; + struct i2c_client *i2c_devs[]; }; -static int i2c_multi_inst_probe(struct platform_device *pdev) +static int bmi_probe(struct platform_device *pdev) { - struct i2c_multi_inst_data *multi; - const struct i2c_inst_data *inst_data; struct i2c_board_info board_info = {}; + const struct bmi_instance *inst; struct device *dev = &pdev->dev; struct acpi_device *adev; + struct bmi *bmi; char name[32]; int i, ret; - inst_data = device_get_match_data(dev); - if (!inst_data) { + inst = device_get_match_data(dev); + if (!inst) { dev_err(dev, "Error ACPI match data is missing\n"); return -ENODEV; } @@ -55,33 +55,32 @@ static int i2c_multi_inst_probe(struct platform_device *pdev) if (ret < 0) return ret; - multi = devm_kmalloc(dev, struct_size(multi, clients, ret), GFP_KERNEL); - if (!multi) + bmi = devm_kmalloc(dev, struct_size(bmi, i2c_devs, ret), GFP_KERNEL); + if (!bmi) return -ENOMEM; - multi->num_clients = ret; + bmi->i2c_num = ret; - for (i = 0; i < multi->num_clients && inst_data[i].type; i++) { + for (i = 0; i < bmi->i2c_num && inst[i].type; i++) { memset(&board_info, 0, sizeof(board_info)); - strlcpy(board_info.type, inst_data[i].type, I2C_NAME_SIZE); - snprintf(name, sizeof(name), "%s-%s.%d", dev_name(dev), - inst_data[i].type, i); + strlcpy(board_info.type, inst[i].type, I2C_NAME_SIZE); + snprintf(name, sizeof(name), "%s-%s.%d", dev_name(dev), inst[i].type, i); board_info.dev_name = name; - switch (inst_data[i].flags & IRQ_RESOURCE_TYPE) { + switch (inst[i].flags & IRQ_RESOURCE_TYPE) { case IRQ_RESOURCE_GPIO: - ret = acpi_dev_gpio_irq_get(adev, inst_data[i].irq_idx); + ret = acpi_dev_gpio_irq_get(adev, inst[i].irq_idx); if (ret < 0) { dev_err(dev, "Error requesting irq at index %d: %d\n", - inst_data[i].irq_idx, ret); + inst[i].irq_idx, ret); goto error; } board_info.irq = ret; break; case IRQ_RESOURCE_APIC: - ret = platform_get_irq(pdev, inst_data[i].irq_idx); + ret = platform_get_irq(pdev, inst[i].irq_idx); if (ret < 0) { dev_dbg(dev, "Error requesting irq at index %d: %d\n", - inst_data[i].irq_idx, ret); + inst[i].irq_idx, ret); goto error; } board_info.irq = ret; @@ -90,48 +89,48 @@ static int i2c_multi_inst_probe(struct platform_device *pdev) board_info.irq = 0; break; } - multi->clients[i] = i2c_acpi_new_device(dev, i, &board_info); - if (IS_ERR(multi->clients[i])) { - ret = dev_err_probe(dev, PTR_ERR(multi->clients[i]), + bmi->i2c_devs[i] = i2c_acpi_new_device(dev, i, &board_info); + if (IS_ERR(bmi->i2c_devs[i])) { + ret = dev_err_probe(dev, PTR_ERR(bmi->i2c_devs[i]), "Error creating i2c-client, idx %d\n", i); goto error; } } - if (i < multi->num_clients) { + if (i < bmi->i2c_num) { dev_err(dev, "Error finding driver, idx %d\n", i); ret = -ENODEV; goto error; } - platform_set_drvdata(pdev, multi); + platform_set_drvdata(pdev, bmi); return 0; error: while (--i >= 0) - i2c_unregister_device(multi->clients[i]); + i2c_unregister_device(bmi->i2c_devs[i]); return ret; } -static int i2c_multi_inst_remove(struct platform_device *pdev) +static int bmi_remove(struct platform_device *pdev) { - struct i2c_multi_inst_data *multi = platform_get_drvdata(pdev); + struct bmi *bmi = platform_get_drvdata(pdev); int i; - for (i = 0; i < multi->num_clients; i++) - i2c_unregister_device(multi->clients[i]); + for (i = 0; i < bmi->i2c_num; i++) + i2c_unregister_device(bmi->i2c_devs[i]); return 0; } -static const struct i2c_inst_data bsg1160_data[] = { +static const struct bmi_instance bsg1160_data[] = { { "bmc150_accel", IRQ_RESOURCE_GPIO, 0 }, { "bmc150_magn" }, { "bmg160" }, {} }; -static const struct i2c_inst_data bsg2150_data[] = { +static const struct bmi_instance bsg2150_data[] = { { "bmc150_accel", IRQ_RESOURCE_GPIO, 0 }, { "bmc150_magn" }, /* The resources describe a 3th client, but it is not really there. */ @@ -139,7 +138,7 @@ static const struct i2c_inst_data bsg2150_data[] = { {} }; -static const struct i2c_inst_data int3515_data[] = { +static const struct bmi_instance int3515_data[] = { { "tps6598x", IRQ_RESOURCE_APIC, 0 }, { "tps6598x", IRQ_RESOURCE_APIC, 1 }, { "tps6598x", IRQ_RESOURCE_APIC, 2 }, @@ -148,27 +147,27 @@ static const struct i2c_inst_data int3515_data[] = { }; /* - * Note new device-ids must also be added to i2c_multi_instantiate_ids in + * Note new device-ids must also be added to bus_multi_instantiate_ids in * drivers/acpi/scan.c: acpi_device_enumeration_by_parent(). */ -static const struct acpi_device_id i2c_multi_inst_acpi_ids[] = { +static const struct acpi_device_id bmi_acpi_ids[] = { { "BSG1160", (unsigned long)bsg1160_data }, { "BSG2150", (unsigned long)bsg2150_data }, { "INT3515", (unsigned long)int3515_data }, { } }; -MODULE_DEVICE_TABLE(acpi, i2c_multi_inst_acpi_ids); +MODULE_DEVICE_TABLE(acpi, bmi_acpi_ids); -static struct platform_driver i2c_multi_inst_driver = { +static struct platform_driver bmi_driver = { .driver = { - .name = "I2C multi instantiate pseudo device driver", - .acpi_match_table = i2c_multi_inst_acpi_ids, + .name = "Bus multi instantiate pseudo device driver", + .acpi_match_table = bmi_acpi_ids, }, - .probe = i2c_multi_inst_probe, - .remove = i2c_multi_inst_remove, + .probe = bmi_probe, + .remove = bmi_remove, }; -module_platform_driver(i2c_multi_inst_driver); +module_platform_driver(bmi_driver); -MODULE_DESCRIPTION("I2C multi instantiate pseudo device driver"); +MODULE_DESCRIPTION("Bus multi instantiate pseudo device driver"); MODULE_AUTHOR("Hans de Goede "); MODULE_LICENSE("GPL"); diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index e5c81b3df09c..969d8138d019 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1700,10 +1700,10 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device) * must be instantiated for each, each with its own i2c_device_id. * Normally we only instantiate an i2c-client for the first resource, * using the ACPI HID as id. These special cases are handled by the - * drivers/acpi/i2c-multi-instantiate.c driver, which knows + * drivers/acpi/bus-multi-instantiate.c driver, which knows * which i2c_device_id to use for each resource. */ - static const struct acpi_device_id i2c_multi_instantiate_ids[] = { + static const struct acpi_device_id bus_multi_instantiate_ids[] = { {"BSG1160", }, {"BSG2150", }, {"INT33FE", }, @@ -1721,8 +1721,8 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device) fwnode_property_present(&device->fwnode, "baud"))) return true; - /* Instantiate a pdev for the i2c-multi-instantiate drv to bind to */ - if (!acpi_match_device_ids(device, i2c_multi_instantiate_ids)) + /* Instantiate a pdev for the bus-multi-instantiate drv to bind to */ + if (!acpi_match_device_ids(device, bus_multi_instantiate_ids)) return false; INIT_LIST_HEAD(&resource_list); From patchwork Fri Dec 10 15:40:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Binding X-Patchwork-Id: 523331 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 5BB47C433FE for ; Fri, 10 Dec 2021 15:42:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243092AbhLJPpy (ORCPT ); Fri, 10 Dec 2021 10:45:54 -0500 Received: from mx0b-001ae601.pphosted.com ([67.231.152.168]:14550 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243024AbhLJPpq (ORCPT ); Fri, 10 Dec 2021 10:45:46 -0500 Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1BACurAU000494; Fri, 10 Dec 2021 09:42:02 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=FAuO5CZBOczv5RqUZtQr/W5GrYjfZN+iXeYTP1rRIUQ=; b=WcZG/VK0y16CkGxhDv7Eji5bnQxHejLLECIJeMI3YejF/JVm4U/RA4nC3rHQX8z6XMkD QXulPcOp9JR8pGAyXv5Kf8udYQ+MSF8DRw4ytim4hQfpqcY6LcyMWExV/2gnxZYWBzb2 IhFOoo/m3ME9J7yhIoqg5qsvHD+d+1ZUrpKhfI9E0j3ofko1h7KtKSHKar+/FCn66oDZ C0iZ7mnQyk6j6AqEwS+x/p5RAkMCjEskI4axk/e4uMS/K+5F774Cf8lATgZkIGG3zS6k nyUnWP0S+GXxBJhvL5q6toW8B7mnmygYnIEzCdMTp84dAdqn4yLreN+zGalatI7Gamns ZA== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3cuds09y4q-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 10 Dec 2021 09:42:01 -0600 Received: from EDIEX01.ad.cirrus.com (198.61.84.80) by EDIEX02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Fri, 10 Dec 2021 15:41:58 +0000 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Fri, 10 Dec 2021 15:41:58 +0000 Received: from LONN2DGDQ73.ad.cirrus.com (unknown [198.90.238.135]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id ABCAFB10; Fri, 10 Dec 2021 15:41:58 +0000 (UTC) From: Stefan Binding To: Mark Brown , "Rafael J . Wysocki" , Len Brown , Hans de Goede , Mark Gross CC: , , , , , Lucas Tanure Subject: [PATCH v2 5/6] ACPI: bus-multi-instantiate: Reorganize I2C functions Date: Fri, 10 Dec 2021 15:40:49 +0000 Message-ID: <20211210154050.3713-6-sbinding@opensource.cirrus.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211210154050.3713-1-sbinding@opensource.cirrus.com> References: <20211210154050.3713-1-sbinding@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: H9MR6W6Y0G9arjluncJm8D5o_EzWnd-X X-Proofpoint-ORIG-GUID: H9MR6W6Y0G9arjluncJm8D5o_EzWnd-X X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org From: Lucas Tanure Reorganize I2C functions to accommodate SPI support Split the probe and factor out parts of the code that will be used in the SPI support Signed-off-by: Lucas Tanure --- drivers/acpi/bus-multi-instantiate.c | 150 +++++++++++++++++---------- 1 file changed, 96 insertions(+), 54 deletions(-) diff --git a/drivers/acpi/bus-multi-instantiate.c b/drivers/acpi/bus-multi-instantiate.c index 982dfecfd27c..50f1540762e9 100644 --- a/drivers/acpi/bus-multi-instantiate.c +++ b/drivers/acpi/bus-multi-instantiate.c @@ -29,85 +29,129 @@ struct bmi_instance { struct bmi { int i2c_num; - struct i2c_client *i2c_devs[]; + struct i2c_client **i2c_devs; }; -static int bmi_probe(struct platform_device *pdev) +static int bmi_get_irq(struct platform_device *pdev, struct acpi_device *adev, + const struct bmi_instance *inst) +{ + int ret; + + switch (inst->flags & IRQ_RESOURCE_TYPE) { + case IRQ_RESOURCE_GPIO: + ret = acpi_dev_gpio_irq_get(adev, inst->irq_idx); + break; + case IRQ_RESOURCE_APIC: + ret = platform_get_irq(pdev, inst->irq_idx); + break; + default: + ret = 0; + break; + } + + if (ret < 0) + dev_err_probe(&pdev->dev, ret, "Error requesting irq at index %d: %d\n", + inst->irq_idx, ret); + + return ret; +} + +static void bmi_devs_unregister(struct bmi *bmi) +{ + while (bmi->i2c_num > 0) + i2c_unregister_device(bmi->i2c_devs[--bmi->i2c_num]); +} + +/** + * bmi_i2c_probe - Instantiate multiple I2C devices from inst array + * @pdev: Platform device + * @adev: ACPI device + * @bmi: Internal struct for Bus multi instantiate driver + * @inst: Array of instances to probe + * + * Returns the number of I2C devices instantiate, Zero if none is found or a negative error code. + */ +static int bmi_i2c_probe(struct platform_device *pdev, struct acpi_device *adev, struct bmi *bmi, + const struct bmi_instance *inst_array) { struct i2c_board_info board_info = {}; - const struct bmi_instance *inst; struct device *dev = &pdev->dev; - struct acpi_device *adev; - struct bmi *bmi; char name[32]; - int i, ret; + int i, ret = 0, count; - inst = device_get_match_data(dev); - if (!inst) { - dev_err(dev, "Error ACPI match data is missing\n"); - return -ENODEV; - } - - adev = ACPI_COMPANION(dev); - - /* Count number of clients to instantiate */ ret = i2c_acpi_client_count(adev); - if (ret < 0) + if (ret <= 0) return ret; + count = ret; - bmi = devm_kmalloc(dev, struct_size(bmi, i2c_devs, ret), GFP_KERNEL); - if (!bmi) + bmi->i2c_devs = devm_kcalloc(dev, count, sizeof(*bmi->i2c_devs), GFP_KERNEL); + if (!bmi->i2c_devs) return -ENOMEM; - bmi->i2c_num = ret; - - for (i = 0; i < bmi->i2c_num && inst[i].type; i++) { + for (i = 0; i < count && inst_array[i].type; i++) { memset(&board_info, 0, sizeof(board_info)); - strlcpy(board_info.type, inst[i].type, I2C_NAME_SIZE); - snprintf(name, sizeof(name), "%s-%s.%d", dev_name(dev), inst[i].type, i); + strscpy(board_info.type, inst_array[i].type, I2C_NAME_SIZE); + snprintf(name, sizeof(name), "%s-%s.%d", dev_name(dev), inst_array[i].type, i); board_info.dev_name = name; - switch (inst[i].flags & IRQ_RESOURCE_TYPE) { - case IRQ_RESOURCE_GPIO: - ret = acpi_dev_gpio_irq_get(adev, inst[i].irq_idx); - if (ret < 0) { - dev_err(dev, "Error requesting irq at index %d: %d\n", - inst[i].irq_idx, ret); - goto error; - } - board_info.irq = ret; - break; - case IRQ_RESOURCE_APIC: - ret = platform_get_irq(pdev, inst[i].irq_idx); - if (ret < 0) { - dev_dbg(dev, "Error requesting irq at index %d: %d\n", - inst[i].irq_idx, ret); - goto error; - } - board_info.irq = ret; - break; - default: - board_info.irq = 0; - break; - } + + ret = bmi_get_irq(pdev, adev, &inst_array[i]); + if (ret < 0) + goto error; + board_info.irq = ret; + bmi->i2c_devs[i] = i2c_acpi_new_device(dev, i, &board_info); if (IS_ERR(bmi->i2c_devs[i])) { ret = dev_err_probe(dev, PTR_ERR(bmi->i2c_devs[i]), "Error creating i2c-client, idx %d\n", i); goto error; } + bmi->i2c_num++; } - if (i < bmi->i2c_num) { + if (bmi->i2c_num < count) { dev_err(dev, "Error finding driver, idx %d\n", i); ret = -ENODEV; goto error; } - platform_set_drvdata(pdev, bmi); - return 0; + dev_info(dev, "Instantiate %d I2C devices.\n", bmi->i2c_num); + return bmi->i2c_num; error: - while (--i >= 0) - i2c_unregister_device(bmi->i2c_devs[i]); + dev_err_probe(dev, ret, "I2C error %d\n", ret); + bmi_devs_unregister(bmi); + + return ret; +} + +static int bmi_probe(struct platform_device *pdev) +{ + const struct bmi_instance *inst_array; + struct device *dev = &pdev->dev; + struct acpi_device *adev; + struct bmi *bmi; + int ret; + + inst_array = device_get_match_data(dev); + if (!inst_array) { + dev_err(dev, "Error ACPI match data is missing\n"); + return -ENODEV; + } + + adev = ACPI_COMPANION(dev); + if (!adev) + return -ENODEV; + + bmi = devm_kzalloc(dev, sizeof(*bmi), GFP_KERNEL); + if (!bmi) + return -ENOMEM; + + platform_set_drvdata(pdev, bmi); + + ret = bmi_i2c_probe(pdev, adev, bmi, inst_array); + if (ret > 0) + return 0; + if (ret == 0) + ret = -ENODEV; return ret; } @@ -115,10 +159,8 @@ static int bmi_probe(struct platform_device *pdev) static int bmi_remove(struct platform_device *pdev) { struct bmi *bmi = platform_get_drvdata(pdev); - int i; - for (i = 0; i < bmi->i2c_num; i++) - i2c_unregister_device(bmi->i2c_devs[i]); + bmi_devs_unregister(bmi); return 0; } From patchwork Fri Dec 10 15:40:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Binding X-Patchwork-Id: 522988 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 86C0BC43219 for ; Fri, 10 Dec 2021 15:42:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236812AbhLJPpz (ORCPT ); Fri, 10 Dec 2021 10:45:55 -0500 Received: from mx0b-001ae601.pphosted.com ([67.231.152.168]:21518 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243013AbhLJPpq (ORCPT ); Fri, 10 Dec 2021 10:45:46 -0500 Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1BACurAT000494; Fri, 10 Dec 2021 09:42:01 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=MctcL98IV3iaEfaCDdDYLNgCwqh489vrd4Gf2yASCKY=; b=fEGnJ6zZrOYfzpmKmgUhayX1NDM6vPKHYTzr9qDD3X9/h8hp7bQcTUyv25GoEp8ofyUI ghT/lvpv08xzLZ5fUFeo45RDfAJI74QTMc2TMeot8gqVBJn8BQ/UU10FjrX88x58hOtz RQ9xcRZwxfI0PaOcCSyq2b16UvgLts9ZemcVg25y/gKmASEeJTfWNO2xKJbcQ69GOebH rpfzTmdrhde5PWQW/rCnAleaJbE702I27ExlRxcP6GAGPZFTxEDWfcyZ2xWjpJjsYR84 VnU+p5KcIYmcXp0ZOyRimqu/aslGmWXNYWyPV/7oEjtQ4LIVSl95Sw6J7+O6ykQfEaBP Eg== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3cuds09y4p-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 10 Dec 2021 09:42:01 -0600 Received: from EDIEX01.ad.cirrus.com (198.61.84.80) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Fri, 10 Dec 2021 15:41:59 +0000 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Fri, 10 Dec 2021 15:41:59 +0000 Received: from LONN2DGDQ73.ad.cirrus.com (unknown [198.90.238.135]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id F122A2AA; Fri, 10 Dec 2021 15:41:58 +0000 (UTC) From: Stefan Binding To: Mark Brown , "Rafael J . Wysocki" , Len Brown , Hans de Goede , Mark Gross CC: , , , , , Stefan Binding Subject: [PATCH v2 6/6] ACPI: bus-multi-instantiate: Add SPI support Date: Fri, 10 Dec 2021 15:40:50 +0000 Message-ID: <20211210154050.3713-7-sbinding@opensource.cirrus.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211210154050.3713-1-sbinding@opensource.cirrus.com> References: <20211210154050.3713-1-sbinding@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: 6JfsD0UFRfs9G7dW9-JawkPQm232o3nX X-Proofpoint-ORIG-GUID: 6JfsD0UFRfs9G7dW9-JawkPQm232o3nX X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Add support for spi bus in bus-multi-instantiate driver Some peripherals can have either a I2C or a SPI connection to the host (but not both) but use the same HID for both types. So it is not possible to use the HID to determine whether it is I2C or SPI. The driver must check the node to see if it contains I2cSerialBus or SpiSerialBus entries. For backwards-compatibility with the existing nodes I2C is checked first and if such entries are found ONLY I2C devices are created. Since some existing nodes that were already handled by this driver could also contain unrelated SpiSerialBus nodes that were previously ignored, and this preserves that behavior. If there is ever a need to handle a node where both I2C and SPI devices must be instantiated this can be added in future. Signed-off-by: Stefan Binding --- drivers/acpi/Kconfig | 10 +- drivers/acpi/bus-multi-instantiate.c | 345 ++++++++++++++++++++++++--- drivers/acpi/scan.c | 13 +- 3 files changed, 327 insertions(+), 41 deletions(-) diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 6ba47dd39eb4..948f39d55595 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -296,12 +296,12 @@ config ACPI_PROCESSOR the module will be called processor. config ACPI_BUS_MULTI_INST - tristate "I2C multi instantiate pseudo device driver" - depends on I2C + tristate "I2C and SPI multi instantiate pseudo device driver" + depends on I2C && SPI help - Some ACPI-based systems list multiple i2c-devices in a single ACPI - firmware-node. This driver will instantiate separate i2c-clients - for each device in the firmware-node. + Some ACPI-based systems list multiple i2c/spi devices in a + single ACPI firmware-node. This driver will instantiate separate + i2c-clients or spi-devices for each device in the firmware-node. To compile this driver as a module, choose M here: the module will be called bus-multi-instantiate. diff --git a/drivers/acpi/bus-multi-instantiate.c b/drivers/acpi/bus-multi-instantiate.c index 50f1540762e9..c1306a0ee13c 100644 --- a/drivers/acpi/bus-multi-instantiate.c +++ b/drivers/acpi/bus-multi-instantiate.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ /* * Bus multi-instantiate driver, pseudo driver to instantiate multiple - * i2c-clients from a single fwnode. + * i2c-clients or spi-devices from a single fwnode. * * Copyright 2018 Hans de Goede */ @@ -14,6 +14,7 @@ #include #include #include +#include #include #define IRQ_RESOURCE_TYPE GENMASK(1, 0) @@ -21,15 +22,38 @@ #define IRQ_RESOURCE_GPIO 1 #define IRQ_RESOURCE_APIC 2 +enum bmi_bus_type { + BMI_I2C, + BMI_SPI, + BMI_AUTO_DETEC, +}; + +struct bmi_spi_acpi { + char *resource_source; + struct acpi_resource_spi_serialbus sb; +}; + +struct bmi_spi_sb_acpi { + int count; + struct bmi_spi_acpi acpi_data[]; +}; + struct bmi_instance { const char *type; unsigned int flags; int irq_idx; }; +struct bmi_node { + enum bmi_bus_type bus_type; + struct bmi_instance instances[]; +}; + struct bmi { int i2c_num; + int spi_num; struct i2c_client **i2c_devs; + struct spi_device **spi_devs; }; static int bmi_get_irq(struct platform_device *pdev, struct acpi_device *adev, @@ -60,6 +84,230 @@ static void bmi_devs_unregister(struct bmi *bmi) { while (bmi->i2c_num > 0) i2c_unregister_device(bmi->i2c_devs[--bmi->i2c_num]); + + while (bmi->spi_num > 0) + spi_unregister_device(bmi->spi_devs[--bmi->spi_num]); +} + +static int bmi_spi_count(struct acpi_resource *ares, void *data) +{ + struct acpi_resource_spi_serialbus *sb; + int *count = data; + + if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) + return 1; + + sb = &ares->data.spi_serial_bus; + if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_SPI) + return 1; + + *count = *count + 1; + + return 1; +} + +static int bmi_spi_count_resources(struct acpi_device *adev) +{ + LIST_HEAD(r); + int count = 0; + int ret; + + ret = acpi_dev_get_resources(adev, &r, bmi_spi_count, &count); + if (ret < 0) + return ret; + + acpi_dev_free_resource_list(&r); + + return count; +} + +static int bmi_spi_save_res(struct acpi_resource *ares, void *data) +{ + struct acpi_resource_spi_serialbus *sb; + struct bmi_spi_sb_acpi *resources = data; + struct bmi_spi_acpi *acpi_data; + + if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) + return 1; + + sb = &ares->data.spi_serial_bus; + if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_SPI) + return 1; + + acpi_data = &resources->acpi_data[resources->count]; + memcpy(&acpi_data->sb, sb, sizeof(*sb)); + acpi_data->resource_source = kstrndup(sb->resource_source.string_ptr, + sb->resource_source.string_length, GFP_KERNEL); + if (!acpi_data->resource_source) + return 1; + resources->count++; + + return 1; +} + +static void bmi_spi_res_free(struct bmi_spi_sb_acpi *resources) +{ + if (!resources) + return; + + while (resources->count) + kfree(resources->acpi_data[--resources->count].resource_source); + kfree(resources); +} + +static struct bmi_spi_sb_acpi *bmi_spi_get_resources(struct device *dev, + struct acpi_device *adev, int count) +{ + struct bmi_spi_sb_acpi *resources; + LIST_HEAD(r); + int ret; + + resources = kmalloc(struct_size(resources, acpi_data, count), GFP_KERNEL); + if (!resources) + return NULL; + + ret = acpi_dev_get_resources(adev, &r, bmi_spi_save_res, resources); + if (ret < 0) + goto error; + + acpi_dev_free_resource_list(&r); + + return resources; + +error: + bmi_spi_res_free(resources); + return NULL; +} + +static struct spi_controller *bmi_find_spi_controller(char *path) +{ + acpi_handle parent_handle; + struct acpi_device *adev; + acpi_status status; + + status = acpi_get_handle(NULL, path, &parent_handle); + if (ACPI_FAILURE(status)) + return NULL; + + if (acpi_bus_get_device(parent_handle, &adev)) + return NULL; + + return acpi_spi_find_controller_by_adev(adev); +} + +/** + * bmi_spi_probe - Instantiate multiple SPI devices from inst array + * @pdev: Platform device + * @adev: ACPI device + * @bmi: Internal struct for Bus multi instantiate driver + * @inst: Array of instances to probe + * + * Returns the number of SPI devices instantiate, Zero if none is found or a negative error code. + */ +static int bmi_spi_probe(struct platform_device *pdev, struct acpi_device *adev, struct bmi *bmi, + const struct bmi_instance *inst_array) +{ + struct bmi_spi_sb_acpi *acpi_data; + struct device *dev = &pdev->dev; + struct spi_controller *ctlr; + struct spi_device *spi_dev; + char name[50]; + int i, ret, count; + + ret = bmi_spi_count_resources(adev); + if (ret <= 0) + return ret; + count = ret; + + bmi->spi_devs = devm_kcalloc(dev, count, sizeof(*bmi->spi_devs), GFP_KERNEL); + if (!bmi->spi_devs) + return -ENOMEM; + + acpi_data = bmi_spi_get_resources(dev, adev, count); + if (!acpi_data) + return -ENOMEM; + + for (i = 0; i < count && inst_array[i].type; i++) { + ctlr = bmi_find_spi_controller(acpi_data->acpi_data[i].resource_source); + if (!ctlr) { + ret = -EPROBE_DEFER; + goto error; + } + + spi_dev = spi_alloc_device(ctlr); + if (!spi_dev) { + dev_err(&ctlr->dev, "failed to allocate SPI device for %s\n", + dev_name(&adev->dev)); + ret = -ENOMEM; + goto error; + } + + strscpy(spi_dev->modalias, inst_array[i].type, sizeof(spi_dev->modalias)); + + if (ctlr->fw_translate_cs) { + ret = ctlr->fw_translate_cs(ctlr, + acpi_data->acpi_data[i].sb.device_selection); + if (ret < 0) { + spi_dev_put(spi_dev); + goto error; + } + spi_dev->chip_select = ret; + } else { + spi_dev->chip_select = acpi_data->acpi_data[i].sb.device_selection; + } + + spi_dev->max_speed_hz = acpi_data->acpi_data[i].sb.connection_speed; + spi_dev->bits_per_word = acpi_data->acpi_data[i].sb.data_bit_length; + + if (acpi_data->acpi_data[i].sb.clock_phase == ACPI_SPI_SECOND_PHASE) + spi_dev->mode |= SPI_CPHA; + if (acpi_data->acpi_data[i].sb.clock_polarity == ACPI_SPI_START_HIGH) + spi_dev->mode |= SPI_CPOL; + if (acpi_data->acpi_data[i].sb.device_polarity == ACPI_SPI_ACTIVE_HIGH) + spi_dev->mode |= SPI_CS_HIGH; + + ret = bmi_get_irq(pdev, adev, &inst_array[i]); + if (ret < 0) { + spi_dev_put(spi_dev); + goto error; + } + spi_dev->irq = ret; + + snprintf(name, sizeof(name), "%s-%s-%s.%d", dev_name(&ctlr->dev), dev_name(dev), + inst_array[i].type, i); + spi_dev->dev.init_name = name; + + ret = spi_add_device(spi_dev); + if (ret) { + dev_err(&ctlr->dev, "failed to add SPI device %s from ACPI: %d\n", + dev_name(&adev->dev), ret); + spi_dev_put(spi_dev); + goto error; + } + + dev_dbg(dev, "SPI device %s using chip select %u", name, spi_dev->chip_select); + + bmi->spi_devs[i] = spi_dev; + bmi->spi_num++; + } + + if (bmi->spi_num < count) { + dev_err(dev, "Error finding driver, idx %d\n", i); + ret = -ENODEV; + goto error; + } + + dev_info(dev, "Instantiate %d SPI devices.\n", bmi->spi_num); + bmi_spi_res_free(acpi_data); + + return bmi->spi_num; +error: + bmi_spi_res_free(acpi_data); + bmi_devs_unregister(bmi); + dev_err_probe(dev, ret, "SPI error %d\n", ret); + + return ret; + } /** @@ -125,14 +373,14 @@ static int bmi_i2c_probe(struct platform_device *pdev, struct acpi_device *adev, static int bmi_probe(struct platform_device *pdev) { - const struct bmi_instance *inst_array; struct device *dev = &pdev->dev; + const struct bmi_node *node; struct acpi_device *adev; struct bmi *bmi; - int ret; + int i2c_ret = 0, spi_ret = 0; - inst_array = device_get_match_data(dev); - if (!inst_array) { + node = device_get_match_data(dev); + if (!node) { dev_err(dev, "Error ACPI match data is missing\n"); return -ENODEV; } @@ -147,13 +395,44 @@ static int bmi_probe(struct platform_device *pdev) platform_set_drvdata(pdev, bmi); - ret = bmi_i2c_probe(pdev, adev, bmi, inst_array); - if (ret > 0) + /* Each time this driver probes only one type of bus will be chosen. + * And I2C has preference, which means that if find a I2cSerialBus it assumes + * that all following devices will also be I2C. + * In case there are zero I2C devices, it assumes that all following devices are SPI. + */ + if (node->bus_type != BMI_SPI) { + i2c_ret = bmi_i2c_probe(pdev, adev, bmi, node->instances); + if (i2c_ret > 0) + return 0; + else if (i2c_ret == -EPROBE_DEFER) + return i2c_ret; + if (node->bus_type == BMI_I2C) { + if (i2c_ret == 0) + return -ENODEV; + else + return i2c_ret; + } + } + /* BMI_SPI or BMI_AUTO_DETEC */ + spi_ret = bmi_spi_probe(pdev, adev, bmi, node->instances); + if (spi_ret > 0) return 0; - if (ret == 0) - ret = -ENODEV; + else if (spi_ret == -EPROBE_DEFER) + return -EPROBE_DEFER; + if (node->bus_type == BMI_SPI) { + if (spi_ret == 0) + return -ENODEV; + else + return spi_ret; + } - return ret; + /* The only way to get here is BMI_AUTO_DETEC and i2c_ret <= 0 and spi_ret <= 0 */ + if (i2c_ret == 0 && spi_ret == 0) + return -ENODEV; + else if (i2c_ret == 0 && spi_ret) + return spi_ret; + + return i2c_ret; } static int bmi_remove(struct platform_device *pdev) @@ -165,27 +444,33 @@ static int bmi_remove(struct platform_device *pdev) return 0; } -static const struct bmi_instance bsg1160_data[] = { - { "bmc150_accel", IRQ_RESOURCE_GPIO, 0 }, - { "bmc150_magn" }, - { "bmg160" }, - {} +static const struct bmi_node bsg1160_data = { + .instances = { + { "bmc150_accel", IRQ_RESOURCE_GPIO, 0 }, + { "bmc150_magn" }, + { "bmg160" }, + {} + }, }; -static const struct bmi_instance bsg2150_data[] = { - { "bmc150_accel", IRQ_RESOURCE_GPIO, 0 }, - { "bmc150_magn" }, - /* The resources describe a 3th client, but it is not really there. */ - { "bsg2150_dummy_dev" }, - {} +static const struct bmi_node bsg2150_data = { + .instances = { + { "bmc150_accel", IRQ_RESOURCE_GPIO, 0 }, + { "bmc150_magn" }, + /* The resources describe a 3th client, but it is not really there. */ + { "bsg2150_dummy_dev" }, + {} + }, }; -static const struct bmi_instance int3515_data[] = { - { "tps6598x", IRQ_RESOURCE_APIC, 0 }, - { "tps6598x", IRQ_RESOURCE_APIC, 1 }, - { "tps6598x", IRQ_RESOURCE_APIC, 2 }, - { "tps6598x", IRQ_RESOURCE_APIC, 3 }, - {} +static const struct bmi_node int3515_data = { + .instances = { + { "tps6598x", IRQ_RESOURCE_APIC, 0 }, + { "tps6598x", IRQ_RESOURCE_APIC, 1 }, + { "tps6598x", IRQ_RESOURCE_APIC, 2 }, + { "tps6598x", IRQ_RESOURCE_APIC, 3 }, + {} + }, }; /* @@ -193,9 +478,9 @@ static const struct bmi_instance int3515_data[] = { * drivers/acpi/scan.c: acpi_device_enumeration_by_parent(). */ static const struct acpi_device_id bmi_acpi_ids[] = { - { "BSG1160", (unsigned long)bsg1160_data }, - { "BSG2150", (unsigned long)bsg2150_data }, - { "INT3515", (unsigned long)int3515_data }, + { "BSG1160", (unsigned long)&bsg1160_data }, + { "BSG2150", (unsigned long)&bsg2150_data }, + { "INT3515", (unsigned long)&int3515_data }, { } }; MODULE_DEVICE_TABLE(acpi, bmi_acpi_ids); diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 969d8138d019..8b937fc20d23 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1696,12 +1696,13 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device) struct list_head resource_list; bool is_serial_bus_slave = false; /* - * These devices have multiple I2cSerialBus resources and an i2c-client - * must be instantiated for each, each with its own i2c_device_id. - * Normally we only instantiate an i2c-client for the first resource, - * using the ACPI HID as id. These special cases are handled by the - * drivers/acpi/bus-multi-instantiate.c driver, which knows - * which i2c_device_id to use for each resource. + * These devices have multiple I2cSerialBus/SpiSerialBus resources + * and an (i2c/spi)-client must be instantiated for each, each with + * its own i2c_device_id/spi_device_id. + * Normally we only instantiate an (i2c/spi)-client for the first + * resource, using the ACPI HID as id. These special cases are handled + * by the drivers/acpi/bus-multi-instantiate.c driver, which + * knows which i2c_device_id or spi_device_id to use for each resource. */ static const struct acpi_device_id bus_multi_instantiate_ids[] = { {"BSG1160", },