From patchwork Mon Jan 23 16:08:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan O'Donovan X-Patchwork-Id: 718663 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3v6cf20V0Sz9sdm for ; Tue, 24 Jan 2017 03:46:34 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750714AbdAWQqR (ORCPT ); Mon, 23 Jan 2017 11:46:17 -0500 Received: from bert.emutex.com ([91.103.1.109]:57536 "EHLO bert.emutex.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750738AbdAWQqQ (ORCPT ); Mon, 23 Jan 2017 11:46:16 -0500 Received: from [92.51.199.138] (helo=statler.emutex.com) by bert.emutex.com with esmtp (Exim 4.84) (envelope-from ) id 1cVhBT-00044V-10; Mon, 23 Jan 2017 16:09:31 +0000 Received: from [10.10.68.108] (helo=dan-Latitude-E5450.emutex.com) by statler.emutex.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84) (envelope-from ) id 1cVhBS-0002nJ-Rz; Mon, 23 Jan 2017 16:09:31 +0000 From: Dan O'Donovan To: linux-acpi@vger.kernel.org, "Rafael J . Wysocki" , Jarkko Nikula , Mika Westerberg , Mark Brown Cc: Len Brown , linux-i2c@vger.kernel.org, Wolfram Sang , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Dan O'Donovan , Crestez Dan Leonard Subject: [PATCH v3 1/3] ACPI / bus: Export acpi_of_modalias equiv of of_modalias_node Date: Mon, 23 Jan 2017 16:08:55 +0000 Message-Id: <1485187737-22414-2-git-send-email-dan@emutex.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1485187737-22414-1-git-send-email-dan@emutex.com> References: <1485187737-22414-1-git-send-email-dan@emutex.com> X-Spam-Score: -1.0 (-) X-Spam-Report: Spam detection software, running on the system "statler.emutex.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: From: Crestez Dan Leonard When using devicetree stuff like i2c_client.name or spi_device.modalias is initialized to the first DT compatible id with the vendor prefix stripped. Since some drivers rely on this try to replicate it when using ACPI with DT ids. [...] Content analysis details: (-1.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP 0.0 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Crestez Dan Leonard When using devicetree stuff like i2c_client.name or spi_device.modalias is initialized to the first DT compatible id with the vendor prefix stripped. Since some drivers rely on this try to replicate it when using ACPI with DT ids. Signed-off-by: Crestez Dan Leonard Signed-off-by: Dan O'Donovan Reviewed-by: Mika Westerberg --- drivers/acpi/bus.c | 35 +++++++++++++++++++++++++++++++++++ include/acpi/acpi_bus.h | 1 + 2 files changed, 36 insertions(+) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 95855cb..8b9657f 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -677,6 +677,41 @@ static bool acpi_of_match_device(struct acpi_device *adev, return false; } +/** + * acpi_of_modalias - Like of_modalias_node for ACPI with DT ids + * @adev: ACPI device object to match. + * @outstr: Pointer to buffer for result + * @outlen: Length of outstr value + * + * This is a counterpart of of_modalias_node() for struct acpi_device + * objects. If there is a compatible string for @adev, copy it to the + * @outstr location with the vendor prefix stripped. + * + * Returns 0 on success or negative errno on failure. + */ +int acpi_of_modalias(struct acpi_device *adev, char *outstr, size_t outlen) +{ + const union acpi_object *of_compatible; + const union acpi_object *obj; + const char *str, *chr; + + of_compatible = adev->data.of_compatible; + if (!of_compatible) + return -ENODEV; + + if (of_compatible->type == ACPI_TYPE_PACKAGE) + obj = of_compatible->package.elements; + else /* Must be ACPI_TYPE_STRING. */ + obj = of_compatible; + + str = obj->string.pointer; + chr = strchr(str, ','); + strlcpy(outstr, chr ? chr + 1 : str, outlen); + + return 0; +} +EXPORT_SYMBOL_GPL(acpi_of_modalias); + static bool __acpi_match_device_cls(const struct acpi_device_id *id, struct acpi_hardware_id *hwid) { diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 4242c31..351b4a4 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -522,6 +522,7 @@ void acpi_bus_trim(struct acpi_device *start); acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd); int acpi_match_device_ids(struct acpi_device *device, const struct acpi_device_id *ids); +int acpi_of_modalias(struct acpi_device *adev, char *outstr, size_t outlen); int acpi_create_dir(struct acpi_device *); void acpi_remove_dir(struct acpi_device *);