From patchwork Wed Jun 15 18:30:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Crestez Dan Leonard X-Patchwork-Id: 9179135 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 DD3FD60776 for ; Wed, 15 Jun 2016 18:31:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF8BE27D45 for ; Wed, 15 Jun 2016 18:31:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C102E27F07; Wed, 15 Jun 2016 18:31:38 +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 75DB827D45 for ; Wed, 15 Jun 2016 18:31:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161009AbcFOSbP (ORCPT ); Wed, 15 Jun 2016 14:31:15 -0400 Received: from mga02.intel.com ([134.134.136.20]:25013 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932885AbcFOSbF (ORCPT ); Wed, 15 Jun 2016 14:31:05 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP; 15 Jun 2016 11:31:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,477,1459839600"; d="scan'208";a="719611805" Received: from cdleonard-desk.rb.intel.com ([10.237.104.169]) by FMSMGA003.fm.intel.com with ESMTP; 15 Jun 2016 11:31:03 -0700 From: Crestez Dan Leonard To: linux-acpi@vger.kernel.org, "Rafael J. Wysocki" , Mika Westerberg Cc: Crestez Dan Leonard , Len Brown , linux-i2c@vger.kernel.org, Wolfram Sang , linux-spi@vger.kernel.org, Mark Brown , linux-kernel@vger.kernel.org, Octavian Purdila Subject: [PATCH 1/3] acpi: Export acpi_of_modalias equiv of of_modalias_node Date: Wed, 15 Jun 2016 21:30:27 +0300 Message-Id: <2cc8100c0c0f79a56163429aaefc0fcfecc808f4.1466014238.git.leonard.crestez@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: References: In-Reply-To: References: 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: Crestez Dan Leonard --- drivers/acpi/bus.c | 36 ++++++++++++++++++++++++++++++++++++ include/acpi/acpi_bus.h | 1 + 2 files changed, 37 insertions(+) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 262ca31..4208e0d 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -606,6 +606,42 @@ 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 + * + * If we have a DT id set outstr to the first compatible string with the vendor + * prefix stripped, just like of_modalias_node does for devicetree. + * + * Returns 0 on success or negative errno on failure. + */ +int acpi_of_modalias(struct acpi_device *adev, char *outstr, int 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, ','); + if (chr) + str = chr + 1; + strlcpy(outstr, 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 788c6c35..e6523de 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -515,6 +515,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, int outlen); int acpi_create_dir(struct acpi_device *); void acpi_remove_dir(struct acpi_device *);