From patchwork Sat Feb 4 08:00:26 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: 9555523 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2F29660405 for ; Sat, 4 Feb 2017 08:02:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE2D327F89 for ; Sat, 4 Feb 2017 08:02:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B32B42808F; Sat, 4 Feb 2017 08:02:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3483127F89 for ; Sat, 4 Feb 2017 08:02:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753903AbdBDICF (ORCPT ); Sat, 4 Feb 2017 03:02:05 -0500 Received: from bert.emutex.com ([91.103.1.109]:58259 "EHLO bert.emutex.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753802AbdBDIBt (ORCPT ); Sat, 4 Feb 2017 03:01:49 -0500 Received: from [92.51.199.138] (helo=statler.emutex.com) by bert.emutex.com with esmtp (Exim 4.84) (envelope-from ) id 1cZvHs-00058Y-B7; Sat, 04 Feb 2017 08:01:36 +0000 Received: from [10.10.64.18] (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 1cZvHs-00080o-3i; Sat, 04 Feb 2017 08:01:36 +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 Subject: [PATCH v5 1/3] ACPI / bus: Export acpi_of_modalias equiv of of_modalias_node Date: Sat, 4 Feb 2017 08:00:26 +0000 Message-Id: <1486195228-10929-2-git-send-email-dan@emutex.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486195228-10929-1-git-send-email-dan@emutex.com> References: <1485523815-9629-1-git-send-email-dan@emutex.com> <1486195228-10929-1-git-send-email-dan@emutex.com> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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: Dan O'Donovan Reviewed-by: Mika Westerberg Reviewed-by: Andy Shevchenko Reviewed-by: Jarkko Nikula Tested-by: Jarkko Nikula --- drivers/acpi/bus.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/acpi/acpi_bus.h | 2 ++ 2 files changed, 44 insertions(+) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 95855cb..80cb5eb 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -677,6 +677,48 @@ static bool acpi_of_match_device(struct acpi_device *adev, return false; } +static bool acpi_of_modalias(struct acpi_device *adev, + char *modalias, size_t len) +{ + 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 false; + + 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(modalias, chr ? chr + 1 : str, len); + + return true; +} + +/** + * acpi_set_modalias - Set modalias using "compatible" property or supplied ID + * @adev: ACPI device object to match + * @default_id: ID string to use as default if no compatible string found + * @modalias: Pointer to buffer that modalias value will be copied into + * @len: Length of modalias buffer + * + * This is a counterpart of of_modalias_node() for struct acpi_device objects. + * If there is a compatible string for @adev, it will be copied to @modalias + * with the vendor prefix stripped; otherwise, @default_id will be used. + */ +void acpi_set_modalias(struct acpi_device *adev, const char *default_id, + char *modalias, size_t len) +{ + if (!acpi_of_modalias(adev, modalias, len)) + strlcpy(modalias, default_id, len); +} +EXPORT_SYMBOL_GPL(acpi_set_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..ef0ae8a 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -522,6 +522,8 @@ 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); +void acpi_set_modalias(struct acpi_device *adev, const char *default_id, + char *modalias, size_t len); int acpi_create_dir(struct acpi_device *); void acpi_remove_dir(struct acpi_device *);