Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1402326pxb; Fri, 21 Jan 2022 17:47:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQlz05IXqYtze47Enkpiic0oLpT8W2/twRhru1m1ZfLYvA0vO45KeVsUOjHdBNiOGqAIOg X-Received: by 2002:a63:6806:: with SMTP id d6mr4725092pgc.353.1642816025203; Fri, 21 Jan 2022 17:47:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642816025; cv=none; d=google.com; s=arc-20160816; b=e08gpozYvFV9lymxh3oTU3lhgWk4ztWJSjsWbTJnZDsSbIDRPa724Hkodr6NONUGwr yt1Uw1JJ9pZtP6DpkOhyNlfdDasVJ+hzSUy91pk9pWSZeDdn4hE0Bo5JEXLOEAgUDBob ptgWNJGF2jqO/+i/LLoFI9OTHetdgIxhACr/emRStdDLSixBLwUwUpR6iT+ZcD3lcuUG 2tPvs51/Ktbg2oPeKnLjL3Qgmk+4p6s+mfFddiVWkPGxOB5L7x242c31U7s/mqBMg+e3 IMbYYbZeXPgpFp0WEdzxRpnYQPGbziRglO9H0ZidKpB5NVxvPGL1o0SQEEBrq28MiMb8 LlJw== 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=hpkiyedjwFNaW1dW6W1BZYk7mgOTqs24UOHKVbPt4Kk=; b=tZC5OHDQbA9cn5JXwdZVy1NLvtNPqaRL9err+Wz2IrnwIZr/5SfLAmO5mz6OyQHad0 GJ64XntK+4fyFG6WrFbOGznSyY0t1Tg02j6xkUFSLrF9tm+i1aWexJXmeo19426w9Y+x h7NBJMDBVB8UsKU997xUacBX16qS5aJiuVwBEbu2bEv1+RyIkEKHkla/uxG/kpjrMuAA nqG1D+SYMFV1bZ2lQGIv9UdJq/ivzHukauT3xiJrhe2f9hHgYpjwIN6lA6xxQKc20N8N ng0bVovXiB2DRicJZg3PJJIMDbIkeNThmwmFSP1d/LIxG3A8vTELaGiSDy40Fmr4fvKK DcIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=fjgCUiYk; 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 11si7656326pfl.113.2022.01.21.17.46.53; Fri, 21 Jan 2022 17:47:05 -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=fjgCUiYk; 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 S1381248AbiAUOds (ORCPT + 99 others); Fri, 21 Jan 2022 09:33:48 -0500 Received: from mx0a-001ae601.pphosted.com ([67.231.149.25]:19104 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1381161AbiAUOdV (ORCPT ); Fri, 21 Jan 2022 09:33:21 -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 20LDS7PI017315; Fri, 21 Jan 2022 08:33: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=hpkiyedjwFNaW1dW6W1BZYk7mgOTqs24UOHKVbPt4Kk=; b=fjgCUiYkw07idAqoePK+Rxkanygu53psuOsxQeMI1+N6Wk8iy67gLNaXD7Nkkrwy0F+T WVXcWi7edj63AyraCraWQ07zs9Yzy5yZW7s6TFbZyshlERnrm2lO0ynq22nJsJ9xVUjN 0WHyN7QQycyboN+mEY9VsQmOQQIM8w9dv/ZjyEpdpWHfPFCUg4P7d+I37TRGB20vtlwz W9T+QuhB2Ks3SzkA0eiCTVo9QQSfj6XEe4IIGfPKM94Qr2ZFcYF31Y8a8hu1BzfyX6VP O/9o7hW8yfcC+Z1QNgMKc7Ha9ExBow3694O1vwFhUgws4/KWwooDT5wfj0a3Lm+rmTFD gg== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3dqhyq0up1-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 21 Jan 2022 08:32:59 -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.18; Fri, 21 Jan 2022 14:32: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.18 via Frontend Transport; Fri, 21 Jan 2022 14:32:58 +0000 Received: from LONN2DGDQ73.ad.cirrus.com (unknown [198.90.238.138]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 91E1DB0E; Fri, 21 Jan 2022 14:32:57 +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 v5 4/9] spi: Add API to count spi acpi resources Date: Fri, 21 Jan 2022 14:32:49 +0000 Message-ID: <20220121143254.6432-5-sbinding@opensource.cirrus.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220121143254.6432-1-sbinding@opensource.cirrus.com> References: <20220121143254.6432-1-sbinding@opensource.cirrus.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: YXs0xOKaxUze4Bglh0tWMW4u0kkZMcxt X-Proofpoint-ORIG-GUID: YXs0xOKaxUze4Bglh0tWMW4u0kkZMcxt 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 | 1 + 2 files changed, 41 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 06c0a308b38b..ec9f2ed579e3 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2324,6 +2324,46 @@ struct acpi_spi_lookup { int 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 e5bbb9cbd3d7..394b4241d989 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 acpi_spi_count_resources(struct acpi_device *adev); #endif /* -- 2.25.1