Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1279486pxb; Fri, 21 Jan 2022 14:11:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjADT4aANWQc0zd3ILtaRnPah4kHnsdt9/+hqUHDMNV80gucEpjH39i4gb4LcfhDcTjrfZ X-Received: by 2002:a17:902:f54b:b0:14b:1651:58ca with SMTP id h11-20020a170902f54b00b0014b165158camr5828483plf.58.1642803109517; Fri, 21 Jan 2022 14:11:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642803109; cv=none; d=google.com; s=arc-20160816; b=rbr+hqN/MO1XA6fHagVpyzLyfWR686rSPtrcv9qwZEgUb1rfoYOCRNAGka5xUxOWQT vkRpeaejaLD+gNJTGtlNnA6wZ896Q7nWhxf0CxFvJVnSA40MJfL1JJZr2g39kJT94rA8 4qwLgc3YvpkTcQ4mIQsUAyCZpHb1KigFbPhaPkT4ASaoTsUYbwa5zqZyht0g3PqHICld g2q0fR6zwQc32uZtyHSFThrpfxKWAVXZsg+FArrbBg119C/aUNu/bxuvbzl4DzN3/H4V SQk4fWCpkF5pUdr51TtprXdJcspMQ9F+NQsuHvLdcaw76E6e4S/r997WPYZ/EMzT/SWk md5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pcJyyOGpZnRiEY9dUyz6ABiZtDZzkse/rMAEdl2+rng=; b=zroBz3jL3nkWiGwg5e+eAIRHnlYg1LirYpHb9OXMG4yWkIHEoYm/dJcjNciSncN+tx FEfdjAQ61opAD820zvvc+xRZZdUDRx4tvmb/7kgcTDq1RKHVnKAJ/5pn0mLf8SmkUvqk A/u/1nzlZ2Fivf9yR2hXtGk8lHzQKUyLKVB0fLvu0ZN/6hq91jbRQ9dbb/D1n2Lat2Cj O5qbtfe7IrIehnrY5IBTBh+AfkRW+jmAIWKHcYMXI5Iuf2jr2t6EGkoAdXzk2fkOe9D3 TbYAyMDYI4/0vdzkGWTJ3yusi93icS70NKC3WskYbPm2q7iBB0kH3N1LeJ7U98FnzTVn YnIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=Bp2WdrY4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g18si7575779pfv.169.2022.01.21.14.11.37; Fri, 21 Jan 2022 14:11:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=Bp2WdrY4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243162AbiATNoN (ORCPT + 99 others); Thu, 20 Jan 2022 08:44:13 -0500 Received: from mx0a-001ae601.pphosted.com ([67.231.149.25]:44494 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231321AbiATNoE (ORCPT ); Thu, 20 Jan 2022 08:44:04 -0500 Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20K6iPZE000624; Thu, 20 Jan 2022 07:43:44 -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=pcJyyOGpZnRiEY9dUyz6ABiZtDZzkse/rMAEdl2+rng=; b=Bp2WdrY4Ds6qeNdd8al8VbHmN9ym14iSyPm+26FzxoU93gtXFHF8Ov+vEUD+HD5gkXX7 cirhjLUr5oUJM+GfmJj6LetFM8ueTS3pnm1D+kPJOTD6SYk2cizq3usqwE3pLvNGYNNN dLLyNVqWU1Ny/F7P+1NBPR2DKPdMhY76/fsbUFsISkaeWCNCRmceeJ4Jcll+9E28jqTZ lpSlu4t8fCrezG++VlyfmzwJzQ3/qVWt0MTwsznsKMe6jDuqBWVBg9oHXjesW7bvspZ6 9o8bfM+OtG5U4X0uBG46Lpp82+eB9T6tYLZwT6I4beNyjadhBXZlSj3pWk8z9jEjw0yG 4g== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3dpms0h5y2-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 20 Jan 2022 07:43:44 -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.18; Thu, 20 Jan 2022 13:43:41 +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.18 via Frontend Transport; Thu, 20 Jan 2022 13:43:41 +0000 Received: from LONN2DGDQ73.ad.cirrus.com (unknown [198.90.238.138]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 3A530B13; Thu, 20 Jan 2022 13:43:41 +0000 (UTC) From: Stefan Binding To: Mark Brown , "Rafael J . Wysocki" , Len Brown , Hans de Goede , Mark Gross , Jaroslav Kysela , Takashi Iwai CC: , , , , , , Stefan Binding Subject: [PATCH v4 4/9] spi: Add API to count spi acpi resources Date: Thu, 20 Jan 2022 13:43:21 +0000 Message-ID: <20220120134326.5295-5-sbinding@opensource.cirrus.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220120134326.5295-1-sbinding@opensource.cirrus.com> References: <20220120134326.5295-1-sbinding@opensource.cirrus.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: t_619-WIORaFDQVjXif4y_SGULipdfrR X-Proofpoint-GUID: t_619-WIORaFDQVjXif4y_SGULipdfrR X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some ACPI nodes may have more than one Spi Resource. To be able to handle these case, its necessary to have a way of counting these resources. Signed-off-by: Stefan Binding --- drivers/spi/spi.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/spi/spi.h | 6 ++++++ 2 files changed, 46 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 898cc9931490..8c0c2e26609a 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2325,6 +2325,46 @@ struct acpi_spi_lookup { int irq_index; }; +static int acpi_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; +} + +/** + * acpi_spi_count_resources - Count the number of SpiSerialBus resources + * @adev: ACPI device + * + * Returns the number of SpiSerialBus resources in the ACPI-device's + * resource-list; or a negative error code. + */ +int acpi_spi_count_resources(struct acpi_device *adev) +{ + LIST_HEAD(r); + int count = 0; + int ret; + + ret = acpi_dev_get_resources(adev, &r, acpi_spi_count, &count); + if (ret < 0) + return ret; + + acpi_dev_free_resource_list(&r); + + return count; +} +EXPORT_SYMBOL_GPL(acpi_spi_count_resources); + static void acpi_spi_parse_apple_properties(struct acpi_device *dev, struct acpi_spi_lookup *lookup) { diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 1a34fd0f6ca2..25a82729f8da 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -764,6 +764,7 @@ extern void spi_unregister_controller(struct spi_controller *ctlr); extern struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr, struct acpi_device *adev, int index, int irq_index); +int acpi_spi_count_resources(struct acpi_device *adev); #else static inline struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr, struct acpi_device *adev, @@ -771,6 +772,11 @@ static inline struct spi_device *acpi_spi_device_alloc(struct spi_controller *ct { return ERR_PTR(-EOPNOTSUPP); } + +int acpi_spi_count_resources(struct acpi_device *adev) +{ + return -EOPNOTSUPP; +} #endif /* -- 2.25.1