From patchwork Wed Mar 27 16:43:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 10873765 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B3DC1874 for ; Wed, 27 Mar 2019 16:44:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06DF6289A1 for ; Wed, 27 Mar 2019 16:44:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF89328A49; Wed, 27 Mar 2019 16:44:01 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham 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 B3658289A1 for ; Wed, 27 Mar 2019 16:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727993AbfC0Qnr (ORCPT ); Wed, 27 Mar 2019 12:43:47 -0400 Received: from mga12.intel.com ([192.55.52.136]:62434 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727917AbfC0Qnq (ORCPT ); Wed, 27 Mar 2019 12:43:46 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Mar 2019 09:43:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,277,1549958400"; d="scan'208";a="158912696" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Mar 2019 09:43:42 -0700 From: Heikki Krogerus To: "Rafael J. Wysocki" Cc: Greg Kroah-Hartman , Andy Shevchenko , Chunfeng Yun , Biju Das , Hans de Goede , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] device property: Add fwnode_is_compatible() and device_is_compatible() helpers Date: Wed, 27 Mar 2019 19:43:37 +0300 Message-Id: <20190327164339.31205-2-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327164339.31205-1-heikki.krogerus@linux.intel.com> References: <20190327164339.31205-1-heikki.krogerus@linux.intel.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since there are also some ACPI platforms where the "compatible" property is used, introducing a generic helper function fwnode_is_compatible() that can be used with DT, ACPI and swnodes, and a wrapper function device_is_compatible() with it. The function calls of_device_is_comaptible() with OF nodes, and with ACPI and swnodes it matches the given string against the "compatible" string property array. Signed-off-by: Heikki Krogerus --- drivers/base/property.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/property.h | 3 +++ 2 files changed, 38 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index 8b91ab380d14..af9f5aac5d02 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1006,3 +1006,38 @@ const void *device_get_match_data(struct device *dev) return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev); } EXPORT_SYMBOL_GPL(device_get_match_data); + +/** + * fwnode_is_compatible - Check does fwnode have the given compatible string + * @fwnode: fwnode with the "compatible" property + * @compat: The compatible string + * + * Match the compatible strings of @fwnode against @compat. Returns positive + * value on match, and 0 when no matching compatible string is found. + */ +int fwnode_is_compatible(struct fwnode_handle *fwnode, const char *compat) +{ + int ret; + + if (is_of_node(fwnode)) + return of_device_is_compatible(to_of_node(fwnode), compat); + + ret = fwnode_property_match_string(fwnode, "compatible", compat); + + return ret < 0 ? 0 : 1; +} +EXPORT_SYMBOL_GPL(fwnode_is_compatible); + +/** + * device_is_compatible - Check does a device have the given compatible string + * @dev: Device with the "compatible" property + * @compat: The compatible string + * + * Match the compatible strings of @dev against @compat. Returns positive value + * on match, and 0 when no matching compatible string is found. + */ +int device_is_compatible(struct device *dev, const char *compat) +{ + return fwnode_is_compatible(dev_fwnode(dev), compat); +} +EXPORT_SYMBOL_GPL(device_is_compatible); diff --git a/include/linux/property.h b/include/linux/property.h index 65d3420dd5d1..d22788ec36cd 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -311,6 +311,9 @@ fwnode_graph_get_remote_node(const struct fwnode_handle *fwnode, u32 port, int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, struct fwnode_endpoint *endpoint); +int fwnode_is_compatible(struct fwnode_handle *fwnode, const char *compat); +int device_is_compatible(struct device *dev, const char *compat); + /* -------------------------------------------------------------------------- */ /* Software fwnode support - when HW description is incomplete or missing */ From patchwork Wed Mar 27 16:43:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 10873759 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 586FA922 for ; Wed, 27 Mar 2019 16:44:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4430228A32 for ; Wed, 27 Mar 2019 16:44:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37FBE28AD3; Wed, 27 Mar 2019 16:44:01 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham 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 D47CD28A32 for ; Wed, 27 Mar 2019 16:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728307AbfC0Qnu (ORCPT ); Wed, 27 Mar 2019 12:43:50 -0400 Received: from mga12.intel.com ([192.55.52.136]:62434 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726740AbfC0Qnt (ORCPT ); Wed, 27 Mar 2019 12:43:49 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Mar 2019 09:43:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,277,1549958400"; d="scan'208";a="158912721" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Mar 2019 09:43:45 -0700 From: Heikki Krogerus To: "Rafael J. Wysocki" Cc: Greg Kroah-Hartman , Andy Shevchenko , Chunfeng Yun , Biju Das , Hans de Goede , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] usb: roles: Use the "compatible" property instead of a boolean property Date: Wed, 27 Mar 2019 19:43:38 +0300 Message-Id: <20190327164339.31205-3-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327164339.31205-1-heikki.krogerus@linux.intel.com> References: <20190327164339.31205-1-heikki.krogerus@linux.intel.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of searching for a boolean property, matching against the "compatible" property. Signed-off-by: Heikki Krogerus --- drivers/usb/roles/class.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index f45d8df5cfb8..3dc1e05959c1 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -101,7 +101,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep, struct device *dev; if (con->fwnode) { - if (!fwnode_property_present(con->fwnode, con->id)) + if (!fwnode_is_compatible(con->fwnode, con->id)) return NULL; dev = class_find_device(role_class, NULL, con->fwnode, From patchwork Wed Mar 27 16:43:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 10873761 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8BC9117E0 for ; Wed, 27 Mar 2019 16:44:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 773BF28A32 for ; Wed, 27 Mar 2019 16:44:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6BB1928ACB; Wed, 27 Mar 2019 16:44:01 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham 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 0A18C28A49 for ; Wed, 27 Mar 2019 16:44:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728627AbfC0Qnx (ORCPT ); Wed, 27 Mar 2019 12:43:53 -0400 Received: from mga12.intel.com ([192.55.52.136]:62434 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726740AbfC0Qnw (ORCPT ); Wed, 27 Mar 2019 12:43:52 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Mar 2019 09:43:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,277,1549958400"; d="scan'208";a="158912750" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Mar 2019 09:43:48 -0700 From: Heikki Krogerus To: "Rafael J. Wysocki" Cc: Greg Kroah-Hartman , Andy Shevchenko , Chunfeng Yun , Biju Das , Hans de Goede , linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] usb: typec: mux: Use the "compatible" property instead of a boolean property Date: Wed, 27 Mar 2019 19:43:39 +0300 Message-Id: <20190327164339.31205-4-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327164339.31205-1-heikki.krogerus@linux.intel.com> References: <20190327164339.31205-1-heikki.krogerus@linux.intel.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of searching for a boolean property, matching against the "compatible" property. Signed-off-by: Heikki Krogerus --- drivers/usb/typec/mux.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index 2ce54f3fc79c..9462b90f1c09 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -32,11 +32,7 @@ static void *typec_switch_match(struct device_connection *con, int ep, return ERR_PTR(-EPROBE_DEFER); } - /* - * With OF graph the mux node must have a boolean device property named - * "orientation-switch". - */ - if (con->id && !fwnode_property_present(con->fwnode, con->id)) + if (con->id && !fwnode_is_compatible(con->fwnode, con->id)) return NULL; list_for_each_entry(sw, &switch_list, entry) @@ -148,7 +144,7 @@ static void *typec_mux_match(struct device_connection *con, int ep, void *data) /* Accessory Mode muxes */ if (!desc) { - match = fwnode_property_present(con->fwnode, "accessory"); + match = fwnode_is_compatible(con->fwnode, "accessory"); if (match) goto find_mux; return NULL;