From patchwork Wed Feb 8 21:27:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 652021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 523A6C636D6 for ; Wed, 8 Feb 2023 21:28:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231694AbjBHV16 (ORCPT ); Wed, 8 Feb 2023 16:27:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231623AbjBHV1y (ORCPT ); Wed, 8 Feb 2023 16:27:54 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90A8518145; Wed, 8 Feb 2023 13:27:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675891673; x=1707427673; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8vcWMBKlz+OO3heBJN0y+bDZXQvJoEQwiD8J8LdmTHI=; b=FqPo+8zIPBnkZ8TRFi3TSd23L1ZSbRcOod04vGHwhKUdiUwM5MHet115 GlVqoq3cfN2waa6iOo/anbXnLglybO95t4e54lMm9iddX3Pc9UqibZzlQ PIO4A7mhPWvGZPJtR/rMuQZ1/BqdgkJjyxBxbcARUmHC+ljr+4BTrRN+Y LvBlM57nStzMkFwImLICyyk3LrQCHJO7ql2580sx/wKsoI0I9Fc+BQfrZ kjIq09G6sm2EoAGWcWmkoMCQH6CQPFWFLsX6pB1Rzg+O1PXKCImWnHDFt F5yK+V9aHLnQHplUkrE7HkDg7FumN5eN0iHTHEEq3E5bFXIQBwuGmJeqf Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="313566176" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="313566176" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 13:27:51 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="756180455" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="756180455" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 13:27:49 -0800 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by kekkonen.fi.intel.com (Postfix) with ESMTP id AF862122808; Wed, 8 Feb 2023 23:27:47 +0200 (EET) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1pPryM-00DMZA-P5; Wed, 08 Feb 2023 23:27:22 +0200 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-media@vger.kernel.org, rafael@kernel.org, andriy.shevchenko@linux.intel.com, heikki.krogerus@linux.intel.com Subject: [PATCH v5 1/8] ACPI: property: Parse data node string references in properties Date: Wed, 8 Feb 2023 23:27:05 +0200 Message-Id: <20230208212712.3184953-2-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230208212712.3184953-1-sakari.ailus@linux.intel.com> References: <20230208212712.3184953-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add support for parsing property references using strings, besides reference objects that were previously supported. This allows also referencing data nodes which was not possible with reference objects. Also add pr_fmt() macro to prefix printouts. While at it, update copyright. Signed-off-by: Sakari Ailus --- drivers/acpi/property.c | 110 ++++++++++++++++++++++++++++++++++------ 1 file changed, 94 insertions(+), 16 deletions(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index b8d9eb9a433ed..4db7701aeaf5c 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -2,14 +2,17 @@ /* * ACPI device specific properties support. * - * Copyright (C) 2014, Intel Corporation + * Copyright (C) 2014-2023, Intel Corporation * All rights reserved. * * Authors: Mika Westerberg - * Darren Hart - * Rafael J. Wysocki + * Darren Hart + * Rafael J. Wysocki + * Sakari Ailus */ +#define pr_fmt(fmt) "ACPI: " fmt + #include #include #include @@ -795,7 +798,8 @@ acpi_fwnode_get_named_child_node(const struct fwnode_handle *fwnode, static int acpi_get_ref_args(struct fwnode_reference_args *args, struct fwnode_handle *ref_fwnode, const union acpi_object **element, - const union acpi_object *end, size_t num_args) + const union acpi_object *end, size_t num_args, + bool subnode_string) { u32 nargs = 0, i; @@ -803,13 +807,16 @@ static int acpi_get_ref_args(struct fwnode_reference_args *args, * Find the referred data extension node under the * referred device node. */ - for (; *element < end && (*element)->type == ACPI_TYPE_STRING; - (*element)++) { - const char *child_name = (*element)->string.pointer; - - ref_fwnode = acpi_fwnode_get_named_child_node(ref_fwnode, child_name); - if (!ref_fwnode) - return -EINVAL; + if (subnode_string) { + for (; *element < end && (*element)->type == ACPI_TYPE_STRING; + (*element)++) { + const char *child_name = (*element)->string.pointer; + + ref_fwnode = acpi_fwnode_get_named_child_node(ref_fwnode, + child_name); + if (!ref_fwnode) + return -EINVAL; + } } /* @@ -820,7 +827,8 @@ static int acpi_get_ref_args(struct fwnode_reference_args *args, for (i = 0; (*element) + i < end && i < num_args; i++) { acpi_object_type type = (*element)[i].type; - if (type == ACPI_TYPE_LOCAL_REFERENCE) + if (type == ACPI_TYPE_LOCAL_REFERENCE || + (!subnode_string && type == ACPI_TYPE_STRING)) break; if (type == ACPI_TYPE_INTEGER) @@ -844,6 +852,43 @@ static int acpi_get_ref_args(struct fwnode_reference_args *args, return 0; } +static struct fwnode_handle * +acpi_parse_string_ref(const struct fwnode_handle *fwnode, const char *refstring) +{ + acpi_handle scope, handle; + struct acpi_data_node *dn; + struct acpi_device *device; + acpi_status status; + + if (is_acpi_device_node(fwnode)) { + scope = to_acpi_device_node(fwnode)->handle; + } else if (is_acpi_data_node(fwnode)) { + scope = to_acpi_data_node(fwnode)->handle; + } else { + pr_err("bad node type for node %pfw\n", fwnode); + return ERR_PTR(-EINVAL); + } + + status = acpi_get_handle(scope, refstring, &handle); + if (ACPI_FAILURE(status)) { + acpi_handle_debug(scope, "can't get handle for %s", refstring); + return ERR_PTR(-EINVAL); + } + + device = acpi_fetch_acpi_dev(handle); + if (device) + return acpi_fwnode_handle(device); + + status = acpi_get_data_full(handle, acpi_nondev_subnode_tag, + (void **)&dn, NULL); + if (ACPI_FAILURE(status) || !dn) { + acpi_handle_debug(handle, "can't find subnode"); + return ERR_PTR(-EINVAL); + } + + return &dn->fwnode; +} + /** * __acpi_node_get_property_reference - returns handle to the referenced object * @fwnode: Firmware node to get the property from @@ -886,6 +931,7 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, const union acpi_object *element, *end; const union acpi_object *obj; const struct acpi_device_data *data; + struct fwnode_handle *ref_fwnode; struct acpi_device *device; int ret, idx = 0; @@ -909,16 +955,29 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, args->fwnode = acpi_fwnode_handle(device); args->nargs = 0; + return 0; + case ACPI_TYPE_STRING: + if (index) + return -ENOENT; + + ref_fwnode = acpi_parse_string_ref(fwnode, obj->string.pointer); + if (IS_ERR(ref_fwnode)) + return PTR_ERR(ref_fwnode); + + args->fwnode = ref_fwnode; + args->nargs = 0; + return 0; case ACPI_TYPE_PACKAGE: /* * If it is not a single reference, then it is a package of - * references followed by number of ints as follows: + * references, followed by number of ints as follows: * * Package () { REF, INT, REF, INT, INT } * - * The index argument is then used to determine which reference - * the caller wants (along with the arguments). + * Here, REF may be either a local reference or a string. The + * index argument is then used to determine which reference the + * caller wants (along with the arguments). */ break; default: @@ -942,7 +1001,26 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, ret = acpi_get_ref_args(idx == index ? args : NULL, acpi_fwnode_handle(device), - &element, end, num_args); + &element, end, num_args, true); + if (ret < 0) + return ret; + + if (idx == index) + return 0; + + break; + case ACPI_TYPE_STRING: + ref_fwnode = + acpi_parse_string_ref(fwnode, + element->string.pointer); + if (IS_ERR(ref_fwnode)) + return PTR_ERR(ref_fwnode); + + element++; + + ret = acpi_get_ref_args(idx == index ? args : NULL, + ref_fwnode, &element, end, + num_args, false); if (ret < 0) return ret; From patchwork Wed Feb 8 21:27:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 652022 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86331C636D6 for ; Wed, 8 Feb 2023 21:27:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231641AbjBHV1y (ORCPT ); Wed, 8 Feb 2023 16:27:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbjBHV1x (ORCPT ); Wed, 8 Feb 2023 16:27:53 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E0461C7DB; Wed, 8 Feb 2023 13:27:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675891673; x=1707427673; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4Omzh3EBkFsKkaEjSu30BIFaElbuCTq5BekfLAtiEko=; b=k3IitpGLQuuENP62H3hDzsW6Fwpl9/UBG2+el0x3A+wFMNb0Qvn/6cUf 34UFOMfUOHuW7mehtn628Gb2x54HG+11o86HfKXhG/F8n02nkhY61hoeT NrqD5JQH+1dnrmVvKo6tV6RfyUr37g2fOql5pc+AfTYC7AicxJyZ+K7H0 AKKw4qj4ZxhT1r+U4nBFm/qMOI3QgdNfq+TEQBTXcIrpx400FpOj7F5rr mkHalSXzUMKKwKc639JkyFrOzLOm0nbllyu4kH2TLks9GSmvGBy5ZIJbF TnkgFVG0Txj9C0m+xaHxkjTUEYgGlsVvxrJK8k77AesKWumQqpAijDfBx g==; X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="313566169" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="313566169" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 13:27:51 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="756180456" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="756180456" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 13:27:49 -0800 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by kekkonen.fi.intel.com (Postfix) with ESMTP id B619C122811; Wed, 8 Feb 2023 23:27:47 +0200 (EET) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1pPryM-00DMZG-Qi; Wed, 08 Feb 2023 23:27:22 +0200 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-media@vger.kernel.org, rafael@kernel.org, andriy.shevchenko@linux.intel.com, heikki.krogerus@linux.intel.com Subject: [PATCH v5 3/8] device property: Add SOFTWARE_NODE() macro for defining software nodes Date: Wed, 8 Feb 2023 23:27:07 +0200 Message-Id: <20230208212712.3184953-4-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230208212712.3184953-1-sakari.ailus@linux.intel.com> References: <20230208212712.3184953-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add SOFTWARE_NODE() macro in order to make defining software nodes look nicer. This is analogous to different PROPERTY_ENTRY_*() macros for defining properties. Signed-off-by: Sakari Ailus Reviewed-by: Andy Shevchenko Reviewed-by: Heikki Krogerus --- include/linux/property.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/property.h b/include/linux/property.h index 37179e3abad5c..6745a86bc9b97 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -477,6 +477,13 @@ struct software_node { const struct property_entry *properties; }; +#define SOFTWARE_NODE(_name_, _properties_, _parent_) \ + (struct software_node) { \ + .name = _name_, \ + .properties = _properties_, \ + .parent = _parent_, \ + } + bool is_software_node(const struct fwnode_handle *fwnode); const struct software_node * to_software_node(const struct fwnode_handle *fwnode); From patchwork Wed Feb 8 21:27:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 652020 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C9F0C05027 for ; Wed, 8 Feb 2023 21:28:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231731AbjBHV2F (ORCPT ); Wed, 8 Feb 2023 16:28:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231489AbjBHV15 (ORCPT ); Wed, 8 Feb 2023 16:27:57 -0500 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FA8F1EBCA; Wed, 8 Feb 2023 13:27:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675891676; x=1707427676; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FaTgRfZ4Xtjvs+w3o38crr9RxbAl9moVLRuSOPlk7u0=; b=L+Ioxvuy/CxM7aG2lkSv79uLki9vUR011s/533wi+sfg553dYTrnibjM SghuEB+jBGrj6JuLOknuYs9GST67WYtsRhTJm2EN8mo9pJ4Zam3BHP5t9 5/Xy851movwaAPCoaoBAOPLwFUTDAZIwyqlwicsWsMObiIBRmGnLVDey1 SI+VReSgCM11FbuaQ25YOqe3zExw/FNBhyykyQuKh4JnKtzqY9Sezk5sT HAJD0VQAA+R2En3n2iD+ghssotRsqBuUkN+YKciN7e24W81li9arprsz+ ZPpnZJweJtemGUQukSd73xYr8KNuneIuU74n+OsCFooenmB06h58crhuN g==; X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="327625778" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="327625778" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 13:27:55 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="667394086" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="667394086" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 13:27:54 -0800 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by kekkonen.fi.intel.com (Postfix) with ESMTP id C6B72122887; Wed, 8 Feb 2023 23:27:47 +0200 (EET) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1pPryM-00DMZM-Sb; Wed, 08 Feb 2023 23:27:22 +0200 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-media@vger.kernel.org, rafael@kernel.org, andriy.shevchenko@linux.intel.com, heikki.krogerus@linux.intel.com Subject: [PATCH v5 5/8] ACPI: property: Dig "rotation" property for devices with CSI2 _CRS Date: Wed, 8 Feb 2023 23:27:09 +0200 Message-Id: <20230208212712.3184953-6-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230208212712.3184953-1-sakari.ailus@linux.intel.com> References: <20230208212712.3184953-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Dig "rotation" property value for devices with _CRS CSI2 resource descriptor. The value comes from _PLD (physical location of device) object, if it exists for the device. This way camera sensor drivers that know the "rotation" property do not need to care about _PLD on ACPI. Signed-off-by: Sakari Ailus --- drivers/acpi/mipi.c | 17 +++++++++++++++++ include/acpi/acpi_bus.h | 1 + 2 files changed, 18 insertions(+) diff --git a/drivers/acpi/mipi.c b/drivers/acpi/mipi.c index f81a3bb860609..08e67163b2b80 100644 --- a/drivers/acpi/mipi.c +++ b/drivers/acpi/mipi.c @@ -667,10 +667,12 @@ static void init_port_csi2_remote(struct acpi_device *device, */ void acpi_init_swnodes(struct acpi_device *device) { + struct fwnode_handle *fwnode = acpi_fwnode_handle(device); struct acpi_device_software_nodes *ads; struct acpi_buffer buffer = { .length = ACPI_ALLOCATE_BUFFER }; acpi_handle handle = acpi_device_handle(device); struct fwnode_handle *primary; + unsigned int prop_index = 0; acpi_status status; unsigned int i; int ret; @@ -679,6 +681,21 @@ void acpi_init_swnodes(struct acpi_device *device) if (!ads) return; + /* + * Check if "rotation" property exists and if it doesn't but there's a + * _PLD object, then get the rotation value from there. + */ + if (!fwnode_property_present(fwnode, "rotation")) { + struct acpi_pld_info *pld; + + status = acpi_get_physical_device_location(handle, &pld); + if (ACPI_SUCCESS(status)) { + ads->dev_props[NEXT_PROPERTY(prop_index, DEV_ROTATION)] = + PROPERTY_ENTRY_U32("rotation", pld->rotation * 45U); + kfree(pld); + } + } + status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); if (ACPI_FAILURE(status)) { acpi_handle_warn(handle, "cannot get path name\n"); diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index e05d1c1f6ac23..f73e65a21b894 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -361,6 +361,7 @@ struct acpi_device_data { struct acpi_gpio_mapping; enum acpi_device_swnode_dev_props { + ACPI_DEVICE_SWNODE_DEV_ROTATION, ACPI_DEVICE_SWNODE_DEV_NUM_OF, ACPI_DEVICE_SWNODE_DEV_NUM_ENTRIES }; From patchwork Wed Feb 8 21:27:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 652019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A066BC636D6 for ; Wed, 8 Feb 2023 21:28:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231854AbjBHV2L (ORCPT ); Wed, 8 Feb 2023 16:28:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231676AbjBHV16 (ORCPT ); Wed, 8 Feb 2023 16:27:58 -0500 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 395641C335; Wed, 8 Feb 2023 13:27:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675891677; x=1707427677; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HIuZulrNHf/Vm/aPuOdXIsYc/SDB35NtrWLVfpyuVUY=; b=I90EaOvao4jhiUE8uHrG/rWrnJA9lHfCH+NkvJJH5AQVWP1cA14YB2A9 0jVmju8L+d6YKTVfUciwWbJiYOppcK2BVv5D3SL2cXYv2E1LTzcXBTcHL ZswLSSoXCYn9ftQcahhbIB9+o/5BPtt4CEcg0r0rOQe5dJInNaWVuncXM CYNlyBz7oqeEXY7hNRvBNjR3lwgWOHYmhu1E3amEzsK3Coq1c3wV2kHA0 derUAA+t3cm8vD6mW94ZiV3M5r2XIbUeGBVeks4j720ZzTy7Vx/h17XcV tOprq721MIlYK9+6SWOpv12qvVtR7IBu7v/3pNQt2VXPSVPN6e9DccOHH w==; X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="327625783" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="327625783" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 13:27:56 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="667394088" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="667394088" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 13:27:54 -0800 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by kekkonen.fi.intel.com (Postfix) with ESMTP id CC8FC122888; Wed, 8 Feb 2023 23:27:47 +0200 (EET) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1pPryM-00DMZP-TF; Wed, 08 Feb 2023 23:27:22 +0200 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-media@vger.kernel.org, rafael@kernel.org, andriy.shevchenko@linux.intel.com, heikki.krogerus@linux.intel.com Subject: [PATCH v5 6/8] ACPI: property: Rename parsed MIPI DisCo for Imaging properties Date: Wed, 8 Feb 2023 23:27:10 +0200 Message-Id: <20230208212712.3184953-7-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230208212712.3184953-1-sakari.ailus@linux.intel.com> References: <20230208212712.3184953-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org MIPI DisCo for Imaging defines properties for sensor-adjacent devices such as EEPROM, LED flash or lens VCM as either device or sub-node references. This is compliant with existing DT definitions apart from property names. Rename parsed MIPI-defined properties so drivers will have a unified view of them as defined in DT and already parsed by drivers. This can be done in-place as the MIPI-defined property strings are always longer than the DT one. This also results in loss of constness in parser function arguments. Individual bindings to devices could define the references differently between MIPI DisCo for Imaging and DT, in terms of device or sub-node references. This will still need to be handled in the drivers themselves. Signed-off-by: Sakari Ailus --- drivers/acpi/internal.h | 1 + drivers/acpi/mipi.c | 36 ++++++++++++++++++++++++++++++++++++ drivers/acpi/property.c | 22 ++++++++++++---------- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index fac87404e294c..f107094bfe16f 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -289,5 +289,6 @@ static inline void acpi_init_lpit(void) { } void acpi_crs_csi2_swnodes_del_free(void); void acpi_bus_scan_crs_csi2(acpi_handle handle); void acpi_init_swnodes(struct acpi_device *device); +void acpi_properties_prepare_mipi(union acpi_object *elements); #endif /* _ACPI_INTERNAL_H_ */ diff --git a/drivers/acpi/mipi.c b/drivers/acpi/mipi.c index 08e67163b2b80..258a2b351dcf3 100644 --- a/drivers/acpi/mipi.c +++ b/drivers/acpi/mipi.c @@ -729,3 +729,39 @@ void acpi_init_swnodes(struct acpi_device *device) primary = acpi_fwnode_handle(device); primary->secondary = software_node_fwnode(ads->nodes); } + +static const struct mipi_disco_prop { + const char *mipi_prop; + const char *dt_prop; +} mipi_disco_props[] = { + { "mipi-img-lens-focus", "lens-focus" }, + { "mipi-img-flash-leds", "flash-leds" }, + { "mipi-img-clock-frequency", "clock-frequency" }, + { "mipi-img-led-max-current", "led-max-microamp" }, + { "mipi-img-flash-max-current", "flash-max-microamp" }, + { "mipi-img-flash-max-timeout", "flash-max-timeout-us" }, +}; + +/** + * acpi_properties_prepare_mipi - Rename MIPI properties as commin DT ones + * + * @elements: ACPI object containing _DSD properties for a device node + * + * Renames MIPI-defined properties as common DT ones. The pre-requisite is that + * the names of all such MIPI properties are no longer than the corresponding DT + * ones. + */ +void acpi_properties_prepare_mipi(union acpi_object *elements) +{ + char *e0 = elements[0].string.pointer; + unsigned int i; + + /* Replace MIPI DisCo for Imaging property names with DT equivalents. */ + for (i = 0; i < ARRAY_SIZE(mipi_disco_props); i++) { + if (!strcmp(mipi_disco_props[i].mipi_prop, e0)) { + WARN_ON(strscpy(e0, mipi_disco_props[i].dt_prop, + elements[0].string.length) < 0); + break; + } + } +} diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index 4db7701aeaf5c..af9cb849a73ac 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -124,7 +124,7 @@ static bool acpi_nondev_subnode_extract(union acpi_object *desc, } static bool acpi_nondev_subnode_data_ok(acpi_handle handle, - const union acpi_object *link, + union acpi_object *link, struct list_head *list, struct fwnode_handle *parent) { @@ -145,7 +145,7 @@ static bool acpi_nondev_subnode_data_ok(acpi_handle handle, } static bool acpi_nondev_subnode_ok(acpi_handle scope, - const union acpi_object *link, + union acpi_object *link, struct list_head *list, struct fwnode_handle *parent) { @@ -276,22 +276,24 @@ static bool acpi_property_value_ok(const union acpi_object *value) return false; } -static bool acpi_properties_format_valid(const union acpi_object *properties) +static bool acpi_properties_prepare(union acpi_object *properties) { - int i; + unsigned int i; for (i = 0; i < properties->package.count; i++) { - const union acpi_object *property; + union acpi_object *property = &properties->package.elements[i]; + union acpi_object *elements = property->package.elements; - property = &properties->package.elements[i]; /* * Only two elements allowed, the first one must be a string and * the second one has to satisfy certain conditions. */ - if (property->package.count != 2 - || property->package.elements[0].type != ACPI_TYPE_STRING - || !acpi_property_value_ok(&property->package.elements[1])) + if (property->package.count != 2 || + elements[0].type != ACPI_TYPE_STRING || + !acpi_property_value_ok(&elements[1])) return false; + + acpi_properties_prepare_mipi(elements); } return true; } @@ -523,7 +525,7 @@ static bool acpi_extract_properties(acpi_handle scope, union acpi_object *desc, * We found the matching GUID. Now validate the format of the * package immediately following it. */ - if (!acpi_properties_format_valid(properties)) + if (!acpi_properties_prepare(properties)) continue; acpi_data_add_props(data, (const guid_t *)guid->buffer.pointer,