From patchwork Mon Nov 30 13:31:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 334939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B1C2C83022 for ; Mon, 30 Nov 2020 13:32:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D83E220825 for ; Mon, 30 Nov 2020 13:32:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aCL28tM5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726822AbgK3Nci (ORCPT ); Mon, 30 Nov 2020 08:32:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725939AbgK3Ncg (ORCPT ); Mon, 30 Nov 2020 08:32:36 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CD8CC0613D2; Mon, 30 Nov 2020 05:31:55 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id a3so25181444wmb.5; Mon, 30 Nov 2020 05:31:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RJsQiHGqEJvDI1A950rE2xj0EG8wzsrrAHbyxhByNz0=; b=aCL28tM5Keans39iuF0yPmX8N2Zo6DPH4Ma7s7dw4MyY3eGABozdRLlf6DFDkUzn0k HsURvPU0p1ZOQwfMSn1dPSl7KUl4VQsA+pBuvR2GZQWvLyLTETkYDpW4pB50dJGEDAVT Gl6iinIuTEdutRdQFyoMROOJLR4pP0/11oJgm6QgsEmc0wK13XNqqHZKSO8HGXAOcBhP 4uCYVP6WetkhuOaHwSg9W0DMQni9jk5yjPGkx8IebTAGt+GcfUg9covZKsRMekzLILgF 3KA9ikRPV8GB3d3t7E+i3TsSm+P3yO8JCND8N8DtHxCJ8WPkOL/ZQN0kwVMVAMMUT/tV tkIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RJsQiHGqEJvDI1A950rE2xj0EG8wzsrrAHbyxhByNz0=; b=qkw/s5tU7x9ZX58R34bAXdSqcSsMcoCCbCx98ut4Kf3U7DUENYU/9oWNCyTP1WfwVG K3qiC+0YOVwu81v4SfuJi9JHLu0yiq/NvyHeWKua2sTpuqoeZrwq2FEaFrSmWmOQ/in1 dTqRns3EOWr+9oD7r8JoccWTtIFKA14XwTs+XTeLuH/S53vw0eMB0m5AkT8bcHV4alAN GBUWrFfNYpgIAoZPsETTyK+59mv8F1q2u27GAA6/ugV0RtpWaQvkaYUiVm5H+0ygrI48 22LYYyHe3Z8tJUMVJxHN8q8mLCKHWnR4are7A1c/MJQxFLpcC8StrNOQjCp52iKVhqYs h9WQ== X-Gm-Message-State: AOAM532QGq0W4IKF71YQNxv3rMxukllk4Tl+nwAU6iICi5bAsghFmrKz IPBNiRY0OVx9Wrr9WhXyX2UbvCWl89QW1hv4 X-Google-Smtp-Source: ABdhPJwPbNSwrCgOQ0IMIpkzz/7n/VoBoBA1eGQ5Ii7+/pXicjg96dORtNIdGwUWRytKAvCDAttg9A== X-Received: by 2002:a1c:99d3:: with SMTP id b202mr23640950wme.0.1606743113991; Mon, 30 Nov 2020 05:31:53 -0800 (PST) Received: from valhalla.home ([2.31.224.80]) by smtp.gmail.com with ESMTPSA id g192sm7452333wme.48.2020.11.30.05.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 05:31:53 -0800 (PST) From: Daniel Scally To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-media@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, gregkh@linuxfoundation.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, mchehab@kernel.org, robert.moore@intel.com, erik.kaneda@intel.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, linux@rasmusvillemoes.dk, kieran.bingham+renesas@ideasonboard.com, jacopo+renesas@jmondi.org, laurent.pinchart+renesas@ideasonboard.com, jorhand@linux.microsoft.com, kitakar@gmail.com, heikki.krogerus@linux.intel.com, Laurent Pinchart Subject: [PATCH 01/18] property: Return true in fwnode_device_is_available for node types that do not implement this operation Date: Mon, 30 Nov 2020 13:31:12 +0000 Message-Id: <20201130133129.1024662-2-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201130133129.1024662-1-djrscally@gmail.com> References: <20201130133129.1024662-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Some types of fwnode_handle do not implement the device_is_available() check, such as those created by software_nodes. There isn't really a meaningful way to check for the availability of a device that doesn't actually exist, so if the check isn't implemented just assume that the "device" is present. Suggested-by: Laurent Pinchart Signed-off-by: Daniel Scally --- Changes since RFC v3: patch introduced drivers/base/property.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index 4c43d30145c6..a5ca2306796f 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -785,9 +785,14 @@ EXPORT_SYMBOL_GPL(fwnode_handle_put); /** * fwnode_device_is_available - check if a device is available for use * @fwnode: Pointer to the fwnode of the device. + * + * For fwnode node types that don't implement the .device_is_available() + * operation, this function returns true. */ bool fwnode_device_is_available(const struct fwnode_handle *fwnode) { + if (!fwnode_has_op(fwnode, device_is_available)) + return true; return fwnode_call_bool_op(fwnode, device_is_available); } EXPORT_SYMBOL_GPL(fwnode_device_is_available); From patchwork Mon Nov 30 13:31:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 334940 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35643C8301D for ; Mon, 30 Nov 2020 13:32:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EBC3C2223C for ; Mon, 30 Nov 2020 13:32:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JVUuwkGJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726844AbgK3Ncj (ORCPT ); Mon, 30 Nov 2020 08:32:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726688AbgK3Nch (ORCPT ); Mon, 30 Nov 2020 08:32:37 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2452C0613D3; Mon, 30 Nov 2020 05:31:56 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id r3so16245414wrt.2; Mon, 30 Nov 2020 05:31:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pBmA2HioX2UOik7KR00ouIZb6c9//C/JEc7oIKLhFcY=; b=JVUuwkGJ4NaNb4HLNMLQMgIDISYvV/gUvh2+I8ROZLZfa2ArJ02t4klczA1AVqGmKA 8BhgJocg2bdn/9CLqAn59pwI/chqAFBGJitzVjZuNhPJokxYZvuiSwGIvR1kGAEPufBB 9h6zoAoKp0eoCsNVxTcNHvpcHUL1l4uT26DAtqXXhKdb3YhxrsJsn9nMR44YSaGuGqey gHJ/5b4FDD0yej47dY1G6SnhFpjVsCh4GkYVE16P9aI/K+sJ5wacNAoDQ2SnVzADnfSo QHY8qBwE9OdR/xrPm6iYuwsjLoNx2YrFmN/la1JTAMUNhTbAE+Qvr13cCPgSktyLSJ5C zZRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pBmA2HioX2UOik7KR00ouIZb6c9//C/JEc7oIKLhFcY=; b=UdF883nmhtYuFVlF4Fcei2VMg36joPnDTyJjXFpMlsDP0OLXygeFWqGGUHeSg7az1v Sz4wc57iGS1z2xhuftBKujQHtRH3gbpbAyuqetsY7TPYlmLDbSEpZfghD0BHIgaUQeCG csMrnp4o7V8Dx42GY99TRg9NDkWGZDede4zwybAQBBWk3747RPd6/OtAbJft0vupzQDK M07o+9UhqHoeHMOLcpcEhFEGwdalNxG+q+tvcAnctIgWgLb1t4Hga/X5b3czcoCKjYj8 XgXXEwkc+EzNBylL/kLFXu5CRFTKvQ5O7xsZ6RNwcPVPZFMXNbaGx2eNtjRA5YxxUCDk BIiQ== X-Gm-Message-State: AOAM5305HypKY2gFPuu2M+xF82HKllm8bPdjYB+52qEkP62gr1V8o0xm LZ6ymfcrfaRNGgzQawKEGWNBVn1zQDdYNQoW X-Google-Smtp-Source: ABdhPJwJReLGmQDmMBx5sI3o4Ddyr/ckN/oTbfZCoRx7mDtrmB/TSoplbGx15zWUvGD03E8J9yGkhA== X-Received: by 2002:adf:916e:: with SMTP id j101mr29144408wrj.55.1606743115428; Mon, 30 Nov 2020 05:31:55 -0800 (PST) Received: from valhalla.home ([2.31.224.80]) by smtp.gmail.com with ESMTPSA id g192sm7452333wme.48.2020.11.30.05.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 05:31:54 -0800 (PST) From: Daniel Scally To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-media@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, gregkh@linuxfoundation.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, mchehab@kernel.org, robert.moore@intel.com, erik.kaneda@intel.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, linux@rasmusvillemoes.dk, kieran.bingham+renesas@ideasonboard.com, jacopo+renesas@jmondi.org, laurent.pinchart+renesas@ideasonboard.com, jorhand@linux.microsoft.com, kitakar@gmail.com, heikki.krogerus@linux.intel.com Subject: [PATCH 02/18] property: Add support for calling fwnode_graph_get_endpoint_by_id() for fwnode->secondary Date: Mon, 30 Nov 2020 13:31:13 +0000 Message-Id: <20201130133129.1024662-3-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201130133129.1024662-1-djrscally@gmail.com> References: <20201130133129.1024662-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This function is used to find fwnode endpoints against a device. In some instances those endpoints are software nodes which are children of fwnode->secondary. Add support to fwnode_graph_get_endpoint_by_id() to find those endpoints by recursively calling itself passing the ptr to fwnode->secondary in the event no endpoint is found for the primary. Signed-off-by: Daniel Scally Reviewed-by: Laurent Pinchart Reviewed-by: Andy Shevchenko --- Changes since RFC v3: Patch introduced. In discussion in the last submission I noted that the CIO2 device doesn't have an ACPI fwnode - that turns out to be true for _some_ devices but not others, so we need this function to check the secondary too. drivers/base/property.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index a5ca2306796f..4ece6b086e36 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1162,6 +1162,10 @@ fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode, best_ep_id = fwnode_ep.id; } + if (!best_ep && fwnode && !IS_ERR_OR_NULL(fwnode->secondary)) + return fwnode_graph_get_endpoint_by_id(fwnode->secondary, port, + endpoint, flags); + return best_ep; } EXPORT_SYMBOL_GPL(fwnode_graph_get_endpoint_by_id); From patchwork Mon Nov 30 13:31:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 334938 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 635FDC83014 for ; Mon, 30 Nov 2020 13:33:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 104762084C for ; Mon, 30 Nov 2020 13:33:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lBnhvpDR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726961AbgK3NdT (ORCPT ); Mon, 30 Nov 2020 08:33:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725895AbgK3NdS (ORCPT ); Mon, 30 Nov 2020 08:33:18 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 900AEC061A47; Mon, 30 Nov 2020 05:32:04 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id f190so22147865wme.1; Mon, 30 Nov 2020 05:32:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v9hgkB45IAZvjm6wECtiA2RMiJReOpFXi8K4dGY5xEQ=; b=lBnhvpDR2OZilI5L1ubpeo4iuPqpqH1Xu/JaFgzgEkEpP+8cln503R/aEyo9lrCPz0 ZJK9Rae/iklw+x7E/+LJBE8tpd+PlZTK4mkth98JPSiUMwzVJyRo98+fZnwRHAfC6z16 gyQ+jRUrLYk2wo758TK7XuqFwG6Wp9fDzG8GePKFFeVhDQsZ1GIXRqAujU/ZzRl25Kdt Wo3HmXrTS3VGBclLstUuDBIRhk7rzyFhZaRDr4fb9RruJPUWkF5eTN7d4KogVnzt7rA0 zKs0K/iXyGP4E14Qt6BdMjoPrJMcS8bVib6bXm6G9ScTmQUM+SKHOitCnQahrvkcEP0u nZFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v9hgkB45IAZvjm6wECtiA2RMiJReOpFXi8K4dGY5xEQ=; b=E5Bjy7AYaY/lasTJEmtVr05Cif/PYNXJqfvZnkuXUlNQcpPZpV5UONXQLpzc32Y5qo gUWctFO9mBHNt0LPOYwl+8N6lrAfZktBbPYM1nXRA2LXYrAjbrn2VSQYxPo9XZGpG+LQ A5twWWtwQgFB1scmU5wOnfRaa7xPyjmRqODe4nomSvZa0Y0Is5OyCEoTN8zpaE9aoeSx kic61ossUnmJEgtqtn1P4hPHZY9TCQILoKOjykmcvP3GEqwH7iMk/Cc/joilXVU//aGL SBf9T8tfi2eOXXJl0U79xPh5rlNISVWw+OXNX+oWIDgimRLswfKjXTGSA+9u2Dj5hUZ7 9i6Q== X-Gm-Message-State: AOAM533hOd8tK6/YCgtnjRzwkZg0tF5PS56NgD9ClkeAPO8jFyP2IkWe RZZczE+1BUePZhbFGq3ULIOThxIs3y3iIiuW X-Google-Smtp-Source: ABdhPJwoVt5eH9bGJUi3K8IZN8T56R8RDLI8GHjsiwuH8QBPp1iY9Z0IPNQD/xZFbvLY38CW9Gq4wg== X-Received: by 2002:a05:600c:229a:: with SMTP id 26mr23827131wmf.100.1606743122966; Mon, 30 Nov 2020 05:32:02 -0800 (PST) Received: from valhalla.home ([2.31.224.80]) by smtp.gmail.com with ESMTPSA id g192sm7452333wme.48.2020.11.30.05.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 05:32:02 -0800 (PST) From: Daniel Scally To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-media@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, gregkh@linuxfoundation.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, mchehab@kernel.org, robert.moore@intel.com, erik.kaneda@intel.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, linux@rasmusvillemoes.dk, kieran.bingham+renesas@ideasonboard.com, jacopo+renesas@jmondi.org, laurent.pinchart+renesas@ideasonboard.com, jorhand@linux.microsoft.com, kitakar@gmail.com, heikki.krogerus@linux.intel.com Subject: [PATCH 07/18] software_node: Add support for fwnode_graph*() family of functions Date: Mon, 30 Nov 2020 13:31:18 +0000 Message-Id: <20201130133129.1024662-8-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201130133129.1024662-1-djrscally@gmail.com> References: <20201130133129.1024662-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Heikki Krogerus From: Heikki Krogerus This implements the remaining .graph_* callbacks in the fwnode operations vector for the software nodes. That makes the fwnode_graph*() functions available in the drivers also when software nodes are used. The implementation tries to mimic the "OF graph" as much as possible, but there is no support for the "reg" device property. The ports will need to have the index in their name which starts with "port" (for example "port0", "port1", ...) and endpoints will use the index of the software node that is given to them during creation. The port nodes can also be grouped under a specially named "ports" subnode, just like in DT, if necessary. The remote-endpoints are reference properties under the endpoint nodes that are named "remote-endpoint". Signed-off-by: Heikki Krogerus Co-developed-by: Daniel Scally Signed-off-by: Daniel Scally --- changes since RFC v3: - Simplified software_node_get_next_endpoint() a little - Squared away references in software_node_get_next_endpoint() and swnode_graph_find_next_port(), since they were affected by the change to the earlier patch that had *get_next_child() also put the previous reference. - Dropped Andy's R-b, since the code changed. changes in RFC v3: - removed software_node_device_is_available - moved the change to software_node_get_next_child to a separate patch - switched to use fwnode_handle_put() in graph_get_next_endpoint() instead of software_node_put() changes in RFC v2: - added software_node_device_is_available - altered software_node_get_next_child to get references - altered software_node_get_next_endpoint to release references to ports and avoid passing invalid combinations of swnodes to software_node_get_next_child - altered swnode_graph_find_next_port to release port rather than old drivers/base/swnode.c | 110 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 1 deletion(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 9bd0bb77ad5b..0c7a8d6b9ea8 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -540,6 +540,110 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, return 0; } +static struct fwnode_handle * +swnode_graph_find_next_port(const struct fwnode_handle *parent, + struct fwnode_handle *port) +{ + struct fwnode_handle *old = port; + + while ((port = software_node_get_next_child(parent, old))) { + if (!strncmp(to_swnode(port)->node->name, "port", 4)) + return port; + old = port; + } + + return NULL; +} + +static struct fwnode_handle * +software_node_graph_get_next_endpoint(const struct fwnode_handle *fwnode, + struct fwnode_handle *endpoint) +{ + struct swnode *swnode = to_swnode(fwnode); + struct fwnode_handle *old = endpoint; + struct fwnode_handle *parent; + struct fwnode_handle *port; + + if (!swnode) + return NULL; + + if (endpoint) { + port = software_node_get_parent(endpoint); + parent = software_node_get_parent(port); + } else { + parent = software_node_get_named_child_node(fwnode, "ports"); + if (!parent) + parent = software_node_get(&swnode->fwnode); + + port = swnode_graph_find_next_port(parent, NULL); + } + + for (; port; port = swnode_graph_find_next_port(parent, port)) { + endpoint = software_node_get_next_child(port, old); + if (endpoint) { + fwnode_handle_put(port); + break; + } + + /* No more endpoints for that port, so stop passing old */ + old = NULL; + } + + fwnode_handle_put(parent); + + return endpoint; +} + +static struct fwnode_handle * +software_node_graph_get_remote_endpoint(const struct fwnode_handle *fwnode) +{ + struct swnode *swnode = to_swnode(fwnode); + const struct software_node_ref_args *ref; + const struct property_entry *prop; + + if (!swnode) + return NULL; + + prop = property_entry_get(swnode->node->properties, "remote-endpoint"); + if (!prop || prop->type != DEV_PROP_REF || prop->is_inline) + return NULL; + + ref = prop->pointer; + + return software_node_get(software_node_fwnode(ref[0].node)); +} + +static struct fwnode_handle * +software_node_graph_get_port_parent(struct fwnode_handle *fwnode) +{ + struct swnode *swnode = to_swnode(fwnode); + struct fwnode_handle *parent; + + if (!strcmp(swnode->parent->node->name, "ports")) + parent = &swnode->parent->parent->fwnode; + else + parent = &swnode->parent->fwnode; + + return software_node_get(parent); +} + +static int +software_node_graph_parse_endpoint(const struct fwnode_handle *fwnode, + struct fwnode_endpoint *endpoint) +{ + struct swnode *swnode = to_swnode(fwnode); + int ret; + + ret = kstrtou32(swnode->parent->node->name + 4, 10, &endpoint->port); + if (ret) + return ret; + + endpoint->id = swnode->id; + endpoint->local_fwnode = fwnode; + + return 0; +} + static const struct fwnode_operations software_node_ops = { .get = software_node_get, .put = software_node_put, @@ -551,7 +655,11 @@ static const struct fwnode_operations software_node_ops = { .get_parent = software_node_get_parent, .get_next_child_node = software_node_get_next_child, .get_named_child_node = software_node_get_named_child_node, - .get_reference_args = software_node_get_reference_args + .get_reference_args = software_node_get_reference_args, + .graph_get_next_endpoint = software_node_graph_get_next_endpoint, + .graph_get_remote_endpoint = software_node_graph_get_remote_endpoint, + .graph_get_port_parent = software_node_graph_get_port_parent, + .graph_parse_endpoint = software_node_graph_parse_endpoint, }; /* -------------------------------------------------------------------------- */ From patchwork Mon Nov 30 13:31:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 334936 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D096DC64E8A for ; Mon, 30 Nov 2020 13:34:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E724207BC for ; Mon, 30 Nov 2020 13:34:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HZf90MOp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727001AbgK3NdV (ORCPT ); Mon, 30 Nov 2020 08:33:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726342AbgK3NdS (ORCPT ); Mon, 30 Nov 2020 08:33:18 -0500 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1C11C061A48; Mon, 30 Nov 2020 05:32:05 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id a3so25182137wmb.5; Mon, 30 Nov 2020 05:32:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Lrl33MwSXvMl0DHbqDMcSOWgFCmI1fsujcf0HrXSVMw=; b=HZf90MOpm4UrGQruq1FslBdjyHHJXBUpQs/+ByhkIk7fFQ6nnsiPwK5sjNVmxBNsPl GSSMpIEP1xzOtFmJA1UqlE31YHI1WyGGIOAsNq+fdUJVto3fIYNm4DujPVSOZ1nPD6wu c2CORb81pqdoXCYkd22uUWvRNQn9HMZV93W+RPpND0omHzAAUmuUUWBBV5keMl6mz1rU St+OnX6NSbau/bQr/PqRbQucbqtaD4ZserNkN05zLm1JY+DlS2WcWyi9VbZvvSwRaYQ9 yviTBPAFKTKsQW2Em2dzkE+mBF7OQQ23E8bV2tV7hT6zedqk/JMidKFLYONdoBopJQhR b8Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Lrl33MwSXvMl0DHbqDMcSOWgFCmI1fsujcf0HrXSVMw=; b=fZELRtQ7ycX8OzAskPE63P+7kB0/mLeC1bE1AtFPVpfXdCbbceGfBKGxKfZokqmdIG MWwtocyH/0KAGmdMYXpy3+j8CqI7gU4MXShtUZ3pAPwauwJp4orzIVkjlZgfb0yh9Dcw x6MiuiHVUaqPzFpUucJ2T323OfCBSUEioAe1Vq9g2IT0bwSOUNvIMDMoDDEjHvNkHfi1 l16tZI4hIcicZmSRlHBstotwQ5li6cC3lC2UF2VfAr17vw+9B+TPw5pBmfyBk6XD89Kv BSNOU3yEPVXpjoHqFu9OboIDwjfJX1bfzPCTR+5OifuDRDNtVOh60tptHv1H4RslEPwI Rreg== X-Gm-Message-State: AOAM530ceWnww04AIzTD1hPu80dwaREQBf2I0JSbeYg3VTUuXXDJo/o2 NJemfFlXKPgRNQL5EDYAjGIVFlY22swvXrdi X-Google-Smtp-Source: ABdhPJzCENcFwsD92T2J5i7GBfndY1f6FvmXomxK1QDwSugBH+f6xf6WvbLaWfVDIDSX5bobRKn1nA== X-Received: by 2002:a1c:43c6:: with SMTP id q189mr10089468wma.7.1606743124434; Mon, 30 Nov 2020 05:32:04 -0800 (PST) Received: from valhalla.home ([2.31.224.80]) by smtp.gmail.com with ESMTPSA id g192sm7452333wme.48.2020.11.30.05.32.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 05:32:03 -0800 (PST) From: Daniel Scally To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-media@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, gregkh@linuxfoundation.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, mchehab@kernel.org, robert.moore@intel.com, erik.kaneda@intel.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, linux@rasmusvillemoes.dk, kieran.bingham+renesas@ideasonboard.com, jacopo+renesas@jmondi.org, laurent.pinchart+renesas@ideasonboard.com, jorhand@linux.microsoft.com, kitakar@gmail.com, heikki.krogerus@linux.intel.com Subject: [PATCH 08/18] lib/test_printf.c: Use helper function to unwind array of software_nodes Date: Mon, 30 Nov 2020 13:31:19 +0000 Message-Id: <20201130133129.1024662-9-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201130133129.1024662-1-djrscally@gmail.com> References: <20201130133129.1024662-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Use the software_node_unregister_nodes() helper function to unwind this array in a cleaner way. Acked-by: Petr Mladek Reviewed-by: Andy Shevchenko Suggested-by: Andy Shevchenko Signed-off-by: Daniel Scally --- Changes since RFC v3: Changed the called function name - didn't drop the tags since it's such a trivial change, hope that's alright! lib/test_printf.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/test_printf.c b/lib/test_printf.c index 7ac87f18a10f..7d60f24240a4 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -644,9 +644,7 @@ static void __init fwnode_pointer(void) test(second_name, "%pfwP", software_node_fwnode(&softnodes[1])); test(third_name, "%pfwP", software_node_fwnode(&softnodes[2])); - software_node_unregister(&softnodes[2]); - software_node_unregister(&softnodes[1]); - software_node_unregister(&softnodes[0]); + software_node_unregister_nodes(softnodes); } static void __init From patchwork Mon Nov 30 13:31:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 334932 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD899C83017 for ; Mon, 30 Nov 2020 13:34:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62486207BC for ; Mon, 30 Nov 2020 13:34:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ChBEr66A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727264AbgK3NeK (ORCPT ); Mon, 30 Nov 2020 08:34:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726960AbgK3NdT (ORCPT ); Mon, 30 Nov 2020 08:33:19 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E523C061A4A; Mon, 30 Nov 2020 05:32:09 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id p8so16244124wrx.5; Mon, 30 Nov 2020 05:32:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lLPC5gReMpBQQOjOEOK+BC7l1m2aD+CFv1l1upZuyWU=; b=ChBEr66AN5CJJiiJQBZ6+iTU5ba9fDPZ4wh6Y2LJroWiyvvs8jWWsSfm0nVsNTFrmm iIQSQSR6mkP3DSzhsZPm1Trv4qs4G2OokUvsbt28cJozO1//Fg274H2TFE5azshO7AF9 MPuBmPPrPCyacfwX/hsbmd4RU+OaWnroJgJGw0gEOBGY2ojipKSGhoi4fAlyyv6FXlCv JhNI+HHHoE5fiBND0/neF5o+s5b5/JL2G/oz5DlVFyxRpwTDZV6sdgREBOazot2Tcrjw 4oRRtTheATA05iC4gSyDYzEu/PGLZnT5YX7leawx/crhZQDDzywkqwyxdxiFcNUvG2up aItQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lLPC5gReMpBQQOjOEOK+BC7l1m2aD+CFv1l1upZuyWU=; b=pxk2LtzwHt1rfUHyi4TZjzpXzHA1r45ZZ8TrmClBq5MRrfpwtVeLCnJKoxUzVg2lKF mutHv/9ZRwbfPqAIlrA6OZJPf7eU4Xej/+D7KDD0nDhCv1Yc2nJUucpM8YbcyCL14Y9+ kSwzpyEBC9YEYc63zCn/8k23Ql2Qi/fLZ6AychxFStAUVyTLFq/0KXVpqBUY4EIy7WEm 5eSdNroW5v7ndf3YvJ+N1bnKNJv0Dg75R+9scf9l5pdq16YoU/7dktPnl0YgJDub2Y2/ 20pPLtvyK7BBNd/1O9J9Gg7+zkbArt948eNcsFsdwF43+D64Fi2iFbptnK1wmQph6jHs F9/w== X-Gm-Message-State: AOAM531r/F1dIhZwkOO1H8sgfyiGVQfMxvrOaGkzeX/AzXrOOxNKZxAW hffdz41yWm+rxgWXgHqF5PTmARIP6Ai6dYEt X-Google-Smtp-Source: ABdhPJwdHT47DB4kBktF0O94g86AmqcC/kfAYNDEByp+i5WkpdWbz4M15u6JP6DBwO3wwJQKJfZhQw== X-Received: by 2002:a5d:4585:: with SMTP id p5mr28223911wrq.65.1606743127500; Mon, 30 Nov 2020 05:32:07 -0800 (PST) Received: from valhalla.home ([2.31.224.80]) by smtp.gmail.com with ESMTPSA id g192sm7452333wme.48.2020.11.30.05.32.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 05:32:06 -0800 (PST) From: Daniel Scally To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-media@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, gregkh@linuxfoundation.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, mchehab@kernel.org, robert.moore@intel.com, erik.kaneda@intel.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, linux@rasmusvillemoes.dk, kieran.bingham+renesas@ideasonboard.com, jacopo+renesas@jmondi.org, laurent.pinchart+renesas@ideasonboard.com, jorhand@linux.microsoft.com, kitakar@gmail.com, heikki.krogerus@linux.intel.com, Laurent Pinchart Subject: [PATCH 10/18] ipu3-cio2: Rename ipu3-cio2.c to allow module to be built from multiple source files retaining ipu3-cio2 name Date: Mon, 30 Nov 2020 13:31:21 +0000 Message-Id: <20201130133129.1024662-11-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201130133129.1024662-1-djrscally@gmail.com> References: <20201130133129.1024662-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org ipu3-cio2 driver needs extending with multiple files; rename the main source file and specify the renamed file in Makefile to accommodate that. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Reviewed-by: Laurent Pinchart Signed-off-by: Daniel Scally --- Changes since RFC v3: - None drivers/media/pci/intel/ipu3/Makefile | 2 ++ drivers/media/pci/intel/ipu3/{ipu3-cio2.c => ipu3-cio2-main.c} | 0 2 files changed, 2 insertions(+) rename drivers/media/pci/intel/ipu3/{ipu3-cio2.c => ipu3-cio2-main.c} (100%) diff --git a/drivers/media/pci/intel/ipu3/Makefile b/drivers/media/pci/intel/ipu3/Makefile index 98ddd5beafe0..429d516452e4 100644 --- a/drivers/media/pci/intel/ipu3/Makefile +++ b/drivers/media/pci/intel/ipu3/Makefile @@ -1,2 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2.o + +ipu3-cio2-y += ipu3-cio2-main.o diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c similarity index 100% rename from drivers/media/pci/intel/ipu3/ipu3-cio2.c rename to drivers/media/pci/intel/ipu3/ipu3-cio2-main.c From patchwork Mon Nov 30 13:31:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 334933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEC79C83012 for ; Mon, 30 Nov 2020 13:34:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 86DFD207BC for ; Mon, 30 Nov 2020 13:34:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f0hTX38W" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726989AbgK3NdU (ORCPT ); Mon, 30 Nov 2020 08:33:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726316AbgK3NdS (ORCPT ); Mon, 30 Nov 2020 08:33:18 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1539CC061A51; Mon, 30 Nov 2020 05:32:16 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id r3so16246791wrt.2; Mon, 30 Nov 2020 05:32:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g3BMXw9JzXtFm16YDoDU8hR3/fKFvazRWYpnvqcHgAY=; b=f0hTX38WWoYFOqduIv8btPWQeeYXnpvQT0AKV2DDZ116iEm5JP+YpIbA3czDOvy1oI obkFPRnUjDfiJaPS9g4M7+yHNIeMXc6tWNwgTi/ZCp/2wvvVoavHx5mJ3+T+YhlVDH4Y UlWwoPadkMAF/1W74cggIXpoD8Rx6+r1IG0mm0NLiRssof/Oo2HjpJLpfJt36TLWGCkl uvQcBwzlh794D+3V/6d4aOGSKMFglZbKF2hCdd8CJElgla5M2GilkvV6sSwXqpW/MAL8 F9sqikgb2+/DBlTINJ+Zpb0DiEHAecd+4i+A5U3QiFYX7LloHZYnR6VWHLpKkhasrEkY yYSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g3BMXw9JzXtFm16YDoDU8hR3/fKFvazRWYpnvqcHgAY=; b=T/fL5sa8bTL1QNUlynW360oRyFWrk2BBmksnygFm4Rqpi4khfZnDg5SeAU2xzma3RR njkfpoSFmujQYz/f/5iOGwHuZkZzOUh/jXE0UNckdoqlTc7ZTFgC0Is1net1FYj+G/Iv r59HEnIb+sTvuC6NsHJmcRJOX+bwfi9oZzx/puwvO4o4ohnlHSAHETCFi5tclvSk6+gu 6DAQ6HukHCWT9QC2/XzdfurmdHBEsQSyQ6onzCkgrTkgwSxTjov+Lc0SeLhahWUCjdYH +UOA19D7ly09VKrv649VMuo6U7Y9dt/O9KABozPfef6h5fNrMX3XoQbCLFOeEA8VrXnh 9jDQ== X-Gm-Message-State: AOAM531c9/rs7WGkW1fuONtjh3Pc4BrdvlW5NED3/E0vWdGG6QH/vJw7 3CPS7qeGM/TVf1gDpnjDXGzctqmh9Ik9A/5G X-Google-Smtp-Source: ABdhPJzDCcxaoTO342dCdUscQv15sIxKHbckb9UWSMvt9SP2Hs4Rezs8wWCAwD8sNCiCr+Mm4eFlHA== X-Received: by 2002:adf:ecc9:: with SMTP id s9mr28663695wro.246.1606743133595; Mon, 30 Nov 2020 05:32:13 -0800 (PST) Received: from valhalla.home ([2.31.224.80]) by smtp.gmail.com with ESMTPSA id g192sm7452333wme.48.2020.11.30.05.32.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 05:32:12 -0800 (PST) From: Daniel Scally To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-media@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, gregkh@linuxfoundation.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, mchehab@kernel.org, robert.moore@intel.com, erik.kaneda@intel.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, linux@rasmusvillemoes.dk, kieran.bingham+renesas@ideasonboard.com, jacopo+renesas@jmondi.org, laurent.pinchart+renesas@ideasonboard.com, jorhand@linux.microsoft.com, kitakar@gmail.com, heikki.krogerus@linux.intel.com Subject: [PATCH 14/18] acpi: utils: Add function to fetch dependent acpi_devices Date: Mon, 30 Nov 2020 13:31:25 +0000 Message-Id: <20201130133129.1024662-15-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201130133129.1024662-1-djrscally@gmail.com> References: <20201130133129.1024662-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org ACPI devices declare themselves dependent on other devices via the _DEP buffer. Fetching the dependee from dependent is a matter of parsing _DEP, but currently there's no method to fetch dependent from dependee. Add one, so we can parse sensors dependent on a PMIC from the PMIC's acpi_driver. Signed-off-by: Daniel Scally --- Changes since RFC v3: - Patch introduced drivers/acpi/utils.c | 68 +++++++++++++++++++++++++++++++++++++++++ include/acpi/acpi_bus.h | 2 ++ 2 files changed, 70 insertions(+) diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index c177165c8db2..7099529121db 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -807,6 +807,52 @@ static int acpi_dev_match_cb(struct device *dev, const void *data) return hrv == match->hrv; } +static int acpi_dev_match_by_dep(struct device *dev, const void *data) +{ + struct acpi_device *adev = to_acpi_device(dev); + const struct acpi_device *dependee = data; + struct acpi_handle_list dep_handles; + struct acpi_device *candidate; + acpi_handle handle; + acpi_status status; + unsigned int i; + int ret; + + handle = adev->handle; + + if (!acpi_has_method(handle, "_DEP")) + return 0; + + status = acpi_evaluate_reference(handle, "_DEP", NULL, &dep_handles); + if (ACPI_FAILURE(status)) + return 0; + + for (i = 0; i < dep_handles.count; i++) { + struct acpi_device_info *info; + + status = acpi_get_object_info(dep_handles.handles[i], &info); + if (ACPI_FAILURE(status)) + continue; + + if (info->valid & ACPI_VALID_HID) { + ret = acpi_bus_get_device(dep_handles.handles[i], &candidate); + if (ret || !candidate) { + kfree(info); + continue; + } + + if (candidate == dependee) { + acpi_dev_put(candidate); + kfree(info); + return 1; + } + + kfree(info); + } + } + return 0; +} + /** * acpi_dev_present - Detect that a given ACPI device is present * @hid: Hardware ID of the device. @@ -842,6 +888,28 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv) } EXPORT_SYMBOL(acpi_dev_present); +/** + * acpi_dev_get_next_dep_dev - Return next ACPI device dependent on input dev + * @adev: Pointer to the dependee device + * @prev: Pointer to the previous dependent device (or NULL for first match) + * + * Return the next ACPI device which declares itself dependent on @adev in + * the _DEP buffer. + * + * The caller is responsible to call put_device() on the returned device. + */ +struct acpi_device *acpi_dev_get_next_dep_dev(struct acpi_device *adev, + struct acpi_device *prev) +{ + struct device *start = prev ? &prev->dev : NULL; + struct device *dev; + + dev = bus_find_device(&acpi_bus_type, start, adev, acpi_dev_match_by_dep); + + return dev ? to_acpi_device(dev) : NULL; +} +EXPORT_SYMBOL(acpi_dev_get_next_dep_dev); + /** * acpi_dev_get_next_match_dev - Return the next match of ACPI device * @adev: Pointer to the previous acpi_device matching this hid, uid and hrv diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 0a028ba967d3..f5dfeb030b9c 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -688,6 +688,8 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev) bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2); +struct acpi_device * +acpi_dev_get_next_dep_dev(struct acpi_device *adev, struct acpi_device *prev); struct acpi_device * acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv); struct acpi_device * From patchwork Mon Nov 30 13:31:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 334935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 138EAC64E8A for ; Mon, 30 Nov 2020 13:34:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9CA0207BC for ; Mon, 30 Nov 2020 13:34:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IStKaWOi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727075AbgK3Ndb (ORCPT ); Mon, 30 Nov 2020 08:33:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727060AbgK3Nda (ORCPT ); Mon, 30 Nov 2020 08:33:30 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B1E8C061A53; Mon, 30 Nov 2020 05:32:18 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id u12so16269477wrt.0; Mon, 30 Nov 2020 05:32:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=511mzKiIywlNQYNwh+9h5lxXxDhZYNjRCyGYr9Xu0us=; b=IStKaWOiny1B/u+cgJ2LRmq2JrnYDg/dGle+7gzHXLBwYdMIXZW29V/uLypqm0eTPo qrvitPzpPhRonnvZRF52o95OdAeIlbOP1iSKfS4WXFOQ8Wq5a3Qo+vwJFono4qnqsR2Y eWDJ+gDq0UoZOK6Jh6B/SK3Gk11h69peJz4vbW/ausArC7j8ihoxiYt0rpU8lWWz3kEg 3g4Fb16amSnXdBKSGBqPuKGFRSBO33a5yjbQ7CH+bjICTludUiT8cHDShViWtX+3x/sE u7xrGB8kgvEwDVgYOdeId9xC6/v9nGi5kCFgDI2/w6T8B8Oq7Ij5Bq9LUUWj6gKl38yq nFGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=511mzKiIywlNQYNwh+9h5lxXxDhZYNjRCyGYr9Xu0us=; b=aLyyxQ2JmEgJ6/ry92boHfQrImLxThar5ibNPhKyynqdlgIgtK+rrXBFKSPOApC/93 aIhzsra6+geZRBoJhr4LVtoQYFkMOyZt0MT0DobOwG9aO6x1FVRNUJ2xFOUmeQTrssXn U/dAE4pe5hYsB7UxtdjMlCGlsdrIXyQY9iTHP/ShgT0QGudyKtZon3i6lwFHUCmjkx/p sb25FcUUNgx6ofWMsQ/eFHasKyMPuNG+2iEeFPlnFsX0ChnBCjVziZ/TVoNlg7HgyAvC Txb2HsLNEYMJyYwa+6NbEd2S96Vs0rzd7oKdIUpA+P9i2qjgReZuQRiYX8TvVOM5oVsz XlhQ== X-Gm-Message-State: AOAM532Xci+9ZZj7OSE9XPNpxjf+1ndHmAsrhWe6PW2G1Wd76dS4nD32 4vEaveYHzZ+UlW9aHQ+z+FBi9/aDnmIfzlTc X-Google-Smtp-Source: ABdhPJx4y/GNSZAZsHXT6kjUa2vcBJ/Pkj3oERILRxY3uLrk1+veimpUUUK/NR8/2AY/Mxf8b9Byeg== X-Received: by 2002:adf:d188:: with SMTP id v8mr27895510wrc.167.1606743136993; Mon, 30 Nov 2020 05:32:16 -0800 (PST) Received: from valhalla.home ([2.31.224.80]) by smtp.gmail.com with ESMTPSA id g192sm7452333wme.48.2020.11.30.05.32.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 05:32:16 -0800 (PST) From: Daniel Scally To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-media@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, gregkh@linuxfoundation.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, mchehab@kernel.org, robert.moore@intel.com, erik.kaneda@intel.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, linux@rasmusvillemoes.dk, kieran.bingham+renesas@ideasonboard.com, jacopo+renesas@jmondi.org, laurent.pinchart+renesas@ideasonboard.com, jorhand@linux.microsoft.com, kitakar@gmail.com, heikki.krogerus@linux.intel.com, Dan Scally Subject: [PATCH 16/18] i2c: i2c-core-base: Use the new i2c_acpi_dev_name() in i2c_set_dev_name() Date: Mon, 30 Nov 2020 13:31:27 +0000 Message-Id: <20201130133129.1024662-17-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201130133129.1024662-1-djrscally@gmail.com> References: <20201130133129.1024662-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Dan Scally To make sure the new i2c_acpi_dev_name() always reflects the name of i2c devices sourced from ACPI, use it in i2c_set_dev_name(). Signed-off-by: Dan Scally --- Changes since RFC v3: - Patch introduced drivers/i2c/i2c-core-base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 573b5da145d1..a6d4ceb01077 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -814,7 +814,7 @@ static void i2c_dev_set_name(struct i2c_adapter *adap, } if (adev) { - dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev)); + dev_set_name(&client->dev, i2c_acpi_dev_name(adev)); return; } From patchwork Mon Nov 30 13:31:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 334934 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73BEBC83013 for ; Mon, 30 Nov 2020 13:34:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B275207BC for ; Mon, 30 Nov 2020 13:34:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KrwSbRpk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727206AbgK3Nd5 (ORCPT ); Mon, 30 Nov 2020 08:33:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726992AbgK3Ndz (ORCPT ); Mon, 30 Nov 2020 08:33:55 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDABEC061A54; Mon, 30 Nov 2020 05:32:19 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id l1so16212740wrb.9; Mon, 30 Nov 2020 05:32:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=89ez14xq7f3eSpkmNmdtRshRAe/5L4lRl0ct9tMiZwI=; b=KrwSbRpkuu4BSm67PVspA3L973/nhfUNUj1LnrJbs+oClFQV1BrpYP88f3Tzyy/pWk S5NBRj2mZaoNXTpLnnYfPH2CZwHqnzwC5dKJDBGXb4TU0KmS/aKJ77BBi60vVxoBkE4N 8RpohPYtH2vluyjhc+Czpsk+ut8KuwuqdbRQtvfHmgxhKGWlUoioGMDYIX25ylVdkchX ujLCdCYhd56UKF876AjE7xWErdGerktBRLDrcIicF1Bp5afBX+CIRrMiJBLKbXLMr2vb zkNdXUQzblbe0w7rYpZexs7Nn+MLgLASnrmLhDzDYmZYOHd0eRBoBtddZn0RuBZ627fr hClw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=89ez14xq7f3eSpkmNmdtRshRAe/5L4lRl0ct9tMiZwI=; b=P+KNA+iNxTOCERFUWXtkeiZknXY9xtituPGXlRhMA0OUsiw3ROmbQLCmsp/Mud8+ww yOV8+YmL9/2QwEIOtZPA46c3IZcC+klhanUepZY6vIghneOcM+6dhgj9GTJ8yF3bfsi9 zrB6I6mLc8Q3uUAyjdgGbsErMuM1o/6iiF7MTdxFWSpVK9zRtGhHlGjXfnj6+zlmNDor 9CA+SzKmyzxCATYj75vNH2mNVdqXc08iUWX7sSGbGoncPC7K4MZM+KTB2hU/lQz5O1oB Xbwif+FyOAJJSsafXmxpGEKms1TyICVkTwJnZn2xN15xoDKKfsSzLVbxZwf6oDwum04w fuxw== X-Gm-Message-State: AOAM531lL9P8Hj8yVl4eNby1VYZIvAJDm2oQSJK2od5kRpWi2DRsACPj efC+DhVgsoK53HEkKSVzhED/eUoqm8eij7ba X-Google-Smtp-Source: ABdhPJzBAM0ozhvZLf9maCK2gtBJuXaIs+4FGjkWJeME4XV8dzgsQK5BHE8ux3fhzPVaBH11vNi02Q== X-Received: by 2002:adf:c452:: with SMTP id a18mr28980463wrg.189.1606743138401; Mon, 30 Nov 2020 05:32:18 -0800 (PST) Received: from valhalla.home ([2.31.224.80]) by smtp.gmail.com with ESMTPSA id g192sm7452333wme.48.2020.11.30.05.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 05:32:17 -0800 (PST) From: Daniel Scally To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-media@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, gregkh@linuxfoundation.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, mchehab@kernel.org, robert.moore@intel.com, erik.kaneda@intel.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, linux@rasmusvillemoes.dk, kieran.bingham+renesas@ideasonboard.com, jacopo+renesas@jmondi.org, laurent.pinchart+renesas@ideasonboard.com, jorhand@linux.microsoft.com, kitakar@gmail.com, heikki.krogerus@linux.intel.com Subject: [PATCH 17/18] gpio: gpiolib-acpi: Export acpi_get_gpiod() Date: Mon, 30 Nov 2020 13:31:28 +0000 Message-Id: <20201130133129.1024662-18-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201130133129.1024662-1-djrscally@gmail.com> References: <20201130133129.1024662-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org I need to be able to translate GPIO resources in an acpi_device's _CRS into gpio_descs. Those are represented in _CRS as a pathname to a GPIO device plus the pin's index number: this function is perfect for that purpose. Signed-off-by: Daniel Scally Reported-by: kernel test robot Reported-by: kernel test robot --- Changes since RFC v3: - Patch introduced drivers/gpio/gpiolib-acpi.c | 3 ++- include/linux/acpi.h | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index 834a12f3219e..cfadbc263475 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -111,7 +111,7 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) * controller does not have GPIO chip registered at the moment. This is to * support probe deferral. */ -static struct gpio_desc *acpi_get_gpiod(char *path, int pin) +struct gpio_desc *acpi_get_gpiod(char *path, int pin) { struct gpio_chip *chip; acpi_handle handle; @@ -127,6 +127,7 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin) return gpiochip_get_desc(chip, pin); } +EXPORT_SYMBOL_GPL(acpi_get_gpiod); static irqreturn_t acpi_gpio_irq_handler(int irq, void *data) { diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 39263c6b52e1..737115a93138 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1066,6 +1066,7 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c bool acpi_gpio_get_irq_resource(struct acpi_resource *ares, struct acpi_resource_gpio **agpio); int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index); +struct gpio_desc *acpi_get_gpiod(char *path, int pin); #else static inline bool acpi_gpio_get_irq_resource(struct acpi_resource *ares, struct acpi_resource_gpio **agpio) @@ -1076,6 +1077,10 @@ static inline int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index) { return -ENXIO; } +struct gpio_desc *acpi_get_gpiod(char *path, int pin) +{ + return NULL; +} #endif /* Device properties */ From patchwork Mon Nov 30 13:31:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 334937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EB55C71156 for ; Mon, 30 Nov 2020 13:33:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A0992085B for ; Mon, 30 Nov 2020 13:33:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aZl6ANtB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727127AbgK3Ndf (ORCPT ); Mon, 30 Nov 2020 08:33:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727107AbgK3Nde (ORCPT ); Mon, 30 Nov 2020 08:33:34 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09DF6C061A55; Mon, 30 Nov 2020 05:32:22 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id g25so5676165wmh.1; Mon, 30 Nov 2020 05:32:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rV7CHkG5wAxwFl+AqTH2VVVjZLQmG8MfJPPhuV61gVM=; b=aZl6ANtBKeuutB812ayQ+cysTTYPZgvfhP/d/ZuYsP7oS4xXjwSYx5C+fW8WUFD671 DYseBQlRDzFNB5/x0VGDN4OfgzU5ngnqhBn3JDBnRpRNxY4qpJT6J0dgNAnRpQW5JDoe Ib3Cg4rYXr3CQIojR0hv7TGNPiWbyu07Ys6LnGc/CE3l7Z8apwmznuDZHPlhURBTCJv0 dLT3T4cWcs8cKwOc1hx39qd94pjpCnHzd2FoG6icedVkLUQGPn5yhLCWrk6DJr+r8/F9 CUgmA3bRGWc4TIOHCMVssjkHNBub7Ib6WFBj5yqGta0ZUirBVATaajlVsIkLUix7EgoN BCjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rV7CHkG5wAxwFl+AqTH2VVVjZLQmG8MfJPPhuV61gVM=; b=m4fRPvkTheDVjH+7zRNQHZumnuIeqyJDZDnrCeBi/DwZK18YueI7jNNPM+Irp7Lhm9 xvmX0KkwFdf2wYc2h7wk9YlvaFjS7PT9GHXkjiW+ySozA6Y6aalAp35krK7xkumtcjk+ z7pAVUGzUlHyq5nYiHCYUG6AHOhrfXDN3j1+svWLdpgiNbgdDUHoPBCsVjj7fOmgpdXq SjUae2JystYle09w5hea5o8WWHxvFMfpYN6fJW8BgJblTeiZOdmugPBB2foeCluvy4o4 CboGe6lguWOENsUshIPN7lgfFxE13TUuMBXlJWlFQuKgwYLV0tDnDDuC9AcEcnSzj/Mt DxMQ== X-Gm-Message-State: AOAM531tIt3M6i0YJnO+4Swtdjwoh7dG0FZ+G0aZS8pu6O/3vcFaUweX nEUG1AF0W/KTKerRhBRURvgZQmUExBj1lwRX X-Google-Smtp-Source: ABdhPJxQyQwiR9uc69AxalIPdALusKCqQS9zU0BH7goMtWjVpybkXYmVbKnAo/XyZm6nkdguyJ5Mzw== X-Received: by 2002:a7b:c24b:: with SMTP id b11mr23247129wmj.109.1606743139970; Mon, 30 Nov 2020 05:32:19 -0800 (PST) Received: from valhalla.home ([2.31.224.80]) by smtp.gmail.com with ESMTPSA id g192sm7452333wme.48.2020.11.30.05.32.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 05:32:19 -0800 (PST) From: Daniel Scally To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-media@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, gregkh@linuxfoundation.org, mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, mchehab@kernel.org, robert.moore@intel.com, erik.kaneda@intel.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, linux@rasmusvillemoes.dk, kieran.bingham+renesas@ideasonboard.com, jacopo+renesas@jmondi.org, laurent.pinchart+renesas@ideasonboard.com, jorhand@linux.microsoft.com, kitakar@gmail.com, heikki.krogerus@linux.intel.com, Laurent Pinchart Subject: [PATCH 18/18] ipu3: Add driver for dummy INT3472 ACPI device Date: Mon, 30 Nov 2020 13:31:29 +0000 Message-Id: <20201130133129.1024662-19-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201130133129.1024662-1-djrscally@gmail.com> References: <20201130133129.1024662-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org On platforms where ACPI is designed for use with Windows, resources that are intended to be consumed by sensor devices are sometimes in the _CRS of a dummy INT3472 device upon which the sensor depends. This driver binds to the dummy acpi device (which does not represent a physical PMIC) and maps them into GPIO lines and regulators for use by the sensor device instead. Suggested-by: Laurent Pinchart Signed-off-by: Daniel Scally --- Changes since RFC v3: - Patch introduced This patch contains the bits of this process that we're least sure about. The sensors in scope for this work are called out as dependent (in their DSDT entry's _DEP) on a device with _HID INT3472. These come in at least 2 kinds; those with an I2cSerialBusV2 entry (which we presume therefore are legitimate tps68470 PMICs that need handling by those drivers - work on that in the future). And those without an I2C device. For those without an I2C device they instead have an array of GPIO pins defined in _CRS. So for example, my Lenovo Miix 510's OVTI2680 sensor is dependent on one of the _latter_ kind of INT3472 devices, with this _CRS: Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings { Name (SBUF, ResourceTemplate () { GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly, "\\_SB.PCI0.GPI0", 0x00, ResourceConsumer, , ) { // Pin list 0x0079 } GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly, "\\_SB.PCI0.GPI0", 0x00, ResourceConsumer, , ) { // Pin list 0x007A } GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly, "\\_SB.PCI0.GPI0", 0x00, ResourceConsumer, , ) { // Pin list 0x008F } }) Return (SBUF) /* \_SB_.PCI0.PMI1._CRS.SBUF */ } and the same device has a _DSM Method, which returns 32-bit ints where the second lowest byte we noticed to match the pin numbers of the GPIO lines: Method (_DSM, 4, NotSerialized) // _DSM: Device-Specific Method { If ((Arg0 == ToUUID ("79234640-9e10-4fea-a5c1-b5aa8b19756f"))) { If ((Arg2 == One)) { Return (0x03) } If ((Arg2 == 0x02)) { Return (0x01007900) } If ((Arg2 == 0x03)) { Return (0x01007A0C) } If ((Arg2 == 0x04)) { Return (0x01008F01) } } Return (Zero) } We know that at least some of those pins have to be toggled active for the sensor devices to be available in i2c, so the conclusion we came to was that those GPIO entries assigned to the INT3472 device actually represent GPIOs and regulators to be consumed by the sensors themselves. Tsuchiya noticed that the lowest byte in the return values of the _DSM method seemed to represent the type or function of the GPIO line, and we confirmed that by testing on each surface device that GPIO lines where the low byte in the _DSM entry for that pin was 0x0d controlled the privacy LED of the cameras. We're guessing as to the exact meaning of the function byte, but I conclude they're something like this: 0x00 - probably a reset GPIO 0x01 - regulator for the sensor 0x0c - regulator for the sensor 0x0b - regulator again, but for a VCM or EEPROM 0x0d - privacy led (only one we're totally confident of since we can see it happen!) After much internal debate I decided to write this as a standalone acpi_driver. Alternative options we considered: 1. Squash all this into the cio2-bridge code, which I did originally write but decided I didn't like. 2. Extend the existing tps68470 mfd driver...they share an ACPI ID so this kinda makes sense, but ultimately given there is no actual physical tps68470 in the scenario this patch handles I decided I didn't like this either. MAINTAINERS | 7 + drivers/media/pci/intel/ipu3/Kconfig | 14 + drivers/media/pci/intel/ipu3/Makefile | 1 + drivers/media/pci/intel/ipu3/int3472.c | 381 +++++++++++++++++++++++++ drivers/media/pci/intel/ipu3/int3472.h | 96 +++++++ 5 files changed, 499 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/int3472.c create mode 100644 drivers/media/pci/intel/ipu3/int3472.h diff --git a/MAINTAINERS b/MAINTAINERS index 188559a0a610..d73471f9c2a3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8753,6 +8753,13 @@ L: linux-crypto@vger.kernel.org S: Maintained F: drivers/crypto/inside-secure/ +INT3472 ACPI DEVICE DRIVER +M: Daniel Scally +L: linux-media@vger.kernel.org +S: Maintained +F: drivers/media/pci/intel/ipu3/int3472.c +F: drivers/media/pci/intel/ipu3/int3472.h + INTEGRITY MEASUREMENT ARCHITECTURE (IMA) M: Mimi Zohar M: Dmitry Kasatkin diff --git a/drivers/media/pci/intel/ipu3/Kconfig b/drivers/media/pci/intel/ipu3/Kconfig index 2b3350d042be..9dd3b280f821 100644 --- a/drivers/media/pci/intel/ipu3/Kconfig +++ b/drivers/media/pci/intel/ipu3/Kconfig @@ -34,3 +34,17 @@ config CIO2_BRIDGE - Dell 7285 If in doubt, say N here. + +config INT3472 + tristate "INT3472 Dummy ACPI Device Driver" + depends on VIDEO_IPU3_CIO2 + depends on ACPI && REGULATOR && GPIOLIB + help + This module provides an ACPI driver for INT3472 devices that do not + represent an actual physical tps68470 device. + + Say Y here if your device is a detachable / hybrid laptop that comes + with Windows installed by the OEM. + The module will be called int3472. + + If in doubt, say N here. diff --git a/drivers/media/pci/intel/ipu3/Makefile b/drivers/media/pci/intel/ipu3/Makefile index 933777e6ea8a..2285947b2bd2 100644 --- a/drivers/media/pci/intel/ipu3/Makefile +++ b/drivers/media/pci/intel/ipu3/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2.o +obj-$(CONFIG_INT3472) += int3472.o ipu3-cio2-y += ipu3-cio2-main.o ipu3-cio2-$(CONFIG_CIO2_BRIDGE) += cio2-bridge.o diff --git a/drivers/media/pci/intel/ipu3/int3472.c b/drivers/media/pci/intel/ipu3/int3472.c new file mode 100644 index 000000000000..6b0be75f7f35 --- /dev/null +++ b/drivers/media/pci/intel/ipu3/int3472.c @@ -0,0 +1,381 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Author: Dan Scally */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "int3472.h" + +/* + * The regulators have to have .ops to be valid, but the only ops we actually + * support are .enable and .disable which are handled via .ena_gpiod. Pass an + * empty struct to clear the check without lying about capabilities. + */ +static const struct regulator_ops int3472_gpio_regulator_ops = { 0 }; + +static int int3472_map_gpio_to_sensor(struct int3472_device *int3472, + struct acpi_resource *ares, char *func) +{ + char *path = ares->data.gpio.resource_source.string_ptr; + struct gpiod_lookup table_entry; + struct acpi_device *adev; + acpi_handle handle; + acpi_status status; + int ret; + + /* Make sure we don't overflow, and leave room for a terminator */ + if (int3472->n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS) { + dev_warn(&int3472->sensor->dev, "Too many GPIOs mapped\n"); + return -EINVAL; + } + + /* Fetch ACPI handle for the GPIO chip */ + status = acpi_get_handle(NULL, path, &handle); + if (ACPI_FAILURE(status)) + return -EINVAL; + + ret = acpi_bus_get_device(handle, &adev); + if (ret) + return -ENODEV; + + table_entry = (struct gpiod_lookup)GPIO_LOOKUP_IDX(acpi_dev_name(adev), + ares->data.gpio.pin_table[0], + func, 0, GPIO_ACTIVE_HIGH); + + memcpy(&int3472->gpios.table[int3472->n_sensor_gpios], &table_entry, + sizeof(table_entry)); + int3472->n_sensor_gpios++; + + return 0; +} + +static struct int3472_sensor_regulator_map * +int3472_get_sensor_supply_map(struct int3472_device *int3472) +{ + struct int3472_sensor_regulator_map *ret; + union acpi_object *obj; + unsigned int i; + + /* + * Sensor modules seem to be identified by a unique string. We use that + * to make sure we pass the right device and supply names to the new + * regulator's consumer_supplies + */ + obj = acpi_evaluate_dsm_typed(int3472->sensor->handle, + &cio2_sensor_module_guid, 0x00, + 0x01, NULL, ACPI_TYPE_STRING); + + if (!obj) { + dev_err(&int3472->sensor->dev, + "Failed to get sensor module string from _DSM\n"); + return ERR_PTR(-ENODEV); + } + + if (obj->string.type != ACPI_TYPE_STRING) { + dev_err(&int3472->sensor->dev, + "Sensor _DSM returned a non-string value\n"); + ret = ERR_PTR(-EINVAL); + goto out_free_obj; + } + + ret = ERR_PTR(-ENODEV); + for (i = 0; i < ARRAY_SIZE(int3472_sensor_regulator_maps); i++) { + if (!strcmp(int3472_sensor_regulator_maps[i].sensor_module_name, + obj->string.pointer)) { + ret = &int3472_sensor_regulator_maps[i]; + goto out_free_obj; + } + } + +out_free_obj: + ACPI_FREE(obj); + return ret; +} + +static int int3472_register_regulator(struct int3472_device *int3472, + struct acpi_resource *ares) +{ + char *path = ares->data.gpio.resource_source.string_ptr; + struct int3472_sensor_regulator_map *regulator_map; + struct regulator_init_data init_data = { }; + struct int3472_gpio_regulator *regulator; + struct regulator_config cfg = { }; + int ret; + + /* + * We lookup supply names from machine specific tables, based on a + * unique identifier in the sensor's _DSM + */ + regulator_map = int3472_get_sensor_supply_map(int3472); + if (IS_ERR_OR_NULL(regulator_map)) { + dev_err(&int3472->sensor->dev, + "Found no supplies defined for this sensor\n"); + return PTR_ERR(regulator_map); + } + + if (int3472->n_regulators >= regulator_map->n_supplies) { + dev_err(&int3472->sensor->dev, + "All known supplies are already mapped\n"); + return -EINVAL; + } + + init_data.supply_regulator = NULL; + init_data.constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS; + init_data.num_consumer_supplies = 1; + init_data.consumer_supplies = ®ulator_map->supplies[int3472->n_regulators]; + + regulator = kmalloc(sizeof(*regulator), GFP_KERNEL); + if (!regulator) + return -ENOMEM; + + snprintf(regulator->regulator_name, GPIO_REGULATOR_NAME_LENGTH, + "gpio-regulator-%d", int3472->n_regulators); + snprintf(regulator->supply_name, GPIO_REGULATOR_SUPPLY_NAME_LENGTH, + "supply-%d", int3472->n_regulators); + + regulator->rdesc = INT3472_REGULATOR(regulator->regulator_name, + regulator->supply_name, + int3472->n_regulators, + &int3472_gpio_regulator_ops); + + regulator->gpio = acpi_get_gpiod(path, ares->data.gpio.pin_table[0]); + if (IS_ERR(regulator->gpio)) { + ret = PTR_ERR(regulator->gpio); + goto err_free_regulator; + } + + cfg.dev = &int3472->adev->dev; + cfg.init_data = &init_data; + cfg.ena_gpiod = regulator->gpio; + + regulator->rdev = regulator_register(®ulator->rdesc, &cfg); + if (IS_ERR(regulator->rdev)) { + ret = PTR_ERR(regulator->rdev); + goto err_free_gpio; + } + + list_add(®ulator->list, &int3472->regulators); + int3472->n_regulators++; + + return 0; + +err_free_gpio: + gpiod_put(regulator->gpio); +err_free_regulator: + kfree(regulator); + + return ret; +} + +static int int3472_handle_gpio_resources(struct acpi_resource *ares, + void *data) +{ + struct int3472_device *int3472 = data; + union acpi_object *obj; + int ret = 0; + + if (ares->type != ACPI_RESOURCE_TYPE_GPIO || + ares->data.gpio.connection_type != ACPI_RESOURCE_GPIO_TYPE_IO) + return EINVAL; /* Deliberately positive */ + + /* + * n_gpios + 2 because the index of this _DSM function is 1-based and + * the first function is just a count. + */ + obj = acpi_evaluate_dsm_typed(int3472->adev->handle, + &int3472_gpio_guid, 0x00, + int3472->n_gpios + 2, + NULL, ACPI_TYPE_INTEGER); + + if (!obj) { + dev_warn(&int3472->adev->dev, + "No _DSM entry for this GPIO pin\n"); + return ENODEV; + } + + switch (obj->integer.value & 0xff) { /* low byte holds type data */ + case 0x00: /* Purpose unclear, possibly a reset GPIO pin */ + ret = int3472_map_gpio_to_sensor(int3472, ares, "reset"); + if (ret) + dev_warn(&int3472->adev->dev, + "Failed to map reset pin to sensor\n"); + + break; + case 0x01: /* Power regulators (we think) */ + case 0x0c: + ret = int3472_register_regulator(int3472, ares); + if (ret) + dev_warn(&int3472->adev->dev, + "Failed to map regulator to sensor\n"); + + break; + case 0x0b: /* Power regulators, but to a device separate to sensor */ + ret = int3472_register_regulator(int3472, ares); + if (ret) + dev_warn(&int3472->adev->dev, + "Failed to map regulator to sensor\n"); + + break; + case 0x0d: /* Indicator LEDs */ + ret = int3472_map_gpio_to_sensor(int3472, ares, "indicator-led"); + if (ret) + dev_warn(&int3472->adev->dev, + "Failed to map indicator led to sensor\n"); + + break; + default: + /* if we've gotten here, we're not sure what they are yet */ + dev_warn(&int3472->adev->dev, + "GPIO type 0x%llx unknown; the sensor may not work\n", + (obj->integer.value & 0xff)); + ret = EINVAL; + } + + int3472->n_gpios++; + ACPI_FREE(obj); + return abs(ret); +} + +static void int3472_parse_crs(struct int3472_device *int3472) +{ + struct list_head resource_list; + + INIT_LIST_HEAD(&resource_list); + + acpi_dev_get_resources(int3472->adev, &resource_list, + int3472_handle_gpio_resources, int3472); + + acpi_dev_free_resource_list(&resource_list); + gpiod_add_lookup_table(&int3472->gpios); +} + +static int int3472_add(struct acpi_device *adev) +{ + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + struct int3472_device *int3472; + struct int3472_cldb cldb; + union acpi_object *obj; + acpi_status status; + int ret = 0; + + /* + * This driver is only intended to support "dummy" INT3472 devices + * which appear in ACPI designed for Windows. These are distinguishable + * from INT3472 entries representing an actual tps68470 PMIC through + * the presence of a CLDB buffer with a particular value set. + */ + status = acpi_evaluate_object(adev->handle, "CLDB", NULL, &buffer); + if (ACPI_FAILURE(status)) + return -ENODEV; + + obj = buffer.pointer; + if (!obj) { + dev_err(&adev->dev, "ACPI device has no CLDB object\n"); + return -ENODEV; + } + + if (obj->type != ACPI_TYPE_BUFFER) { + dev_err(&adev->dev, "CLDB object is not an ACPI buffer\n"); + ret = -EINVAL; + goto out_free_buff; + } + + if (obj->buffer.length > sizeof(cldb)) { + dev_err(&adev->dev, "The CLDB buffer is too large\n"); + ret = -EINVAL; + goto out_free_buff; + } + + memcpy(&cldb, obj->buffer.pointer, obj->buffer.length); + + /* + * control_logic_type = 1 indicates this is a dummy INT3472 device of + * the kind we're looking for. If any other value then we shouldn't try + * to handle it + */ + if (cldb.control_logic_type != 1) { + ret = -EINVAL; + goto out_free_buff; + } + + /* Space for 4 GPIOs - one more than we've seen so far plus a null */ + int3472 = kzalloc(sizeof(*int3472) + + ((INT3472_MAX_SENSOR_GPIOS + 1) * sizeof(struct gpiod_lookup)), + GFP_KERNEL); + if (!int3472) { + ret = -ENOMEM; + goto out_free_buff; + } + + int3472->adev = adev; + adev->driver_data = int3472; + + int3472->sensor = acpi_dev_get_next_dep_dev(adev, NULL); + if (!int3472->sensor) { + dev_err(&adev->dev, + "This INT3472 entry seems to have no dependents.\n"); + ret = -ENODEV; + goto out_free_int3472; + } + + int3472->gpios.dev_id = i2c_acpi_dev_name(int3472->sensor); + + INIT_LIST_HEAD(&int3472->regulators); + + int3472_parse_crs(int3472); + + goto out_free_buff; + +out_free_int3472: + kfree(int3472); +out_free_buff: + kfree(buffer.pointer); + return ret; +} + +static int int3472_remove(struct acpi_device *adev) +{ + struct int3472_gpio_regulator *reg; + struct int3472_device *int3472; + + int3472 = acpi_driver_data(adev); + + acpi_dev_put(int3472->sensor); + gpiod_remove_lookup_table(&int3472->gpios); + + list_for_each_entry(reg, &int3472->regulators, list) { + gpiod_put(reg->gpio); + regulator_unregister(reg->rdev); + } + + kfree(int3472); + + return 0; +} + +static const struct acpi_device_id int3472_device_id[] = { + { "INT3472", 0 }, + { }, +}; +MODULE_DEVICE_TABLE(acpi, int3472_device_id); + +static struct acpi_driver int3472_driver = { + .name = "int3472", + .ids = int3472_device_id, + .ops = { + .add = int3472_add, + .remove = int3472_remove, + }, + .owner = THIS_MODULE, +}; + +module_acpi_driver(int3472_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Dan Scally "); +MODULE_DESCRIPTION("ACPI Driver for Discrete type INT3472 ACPI Devices"); diff --git a/drivers/media/pci/intel/ipu3/int3472.h b/drivers/media/pci/intel/ipu3/int3472.h new file mode 100644 index 000000000000..6964726e8e1f --- /dev/null +++ b/drivers/media/pci/intel/ipu3/int3472.h @@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Author: Dan Scally */ +#include + +#define INT3472_MAX_SENSOR_GPIOS 3 +#define GPIO_REGULATOR_NAME_LENGTH 17 +#define GPIO_REGULATOR_SUPPLY_NAME_LENGTH 9 + +#define INT3472_REGULATOR(_NAME, _SUPPLY, _ID, _OPS) \ + ((const struct regulator_desc) { \ + .name = _NAME, \ + .supply_name = _SUPPLY, \ + .id = _ID, \ + .type = REGULATOR_VOLTAGE, \ + .ops = _OPS, \ + .owner = THIS_MODULE, \ + }) + +const guid_t int3472_gpio_guid = GUID_INIT(0x79234640, 0x9e10, 0x4fea, + 0xa5, 0xc1, 0xb5, 0xaa, 0x8b, + 0x19, 0x75, 0x6f); + +const guid_t cio2_sensor_module_guid = GUID_INIT(0x822ace8f, 0x2814, 0x4174, + 0xa5, 0x6b, 0x5f, 0x02, 0x9f, + 0xe0, 0x79, 0xee); + +struct int3472_cldb { + u8 version; + /* + * control logic type + * 0: UNKNOWN + * 1: DISCRETE(CRD-D) + * 2: PMIC TPS68470 + * 3: PMIC uP6641 + */ + u8 control_logic_type; + u8 control_logic_id; + u8 sensor_card_sku; + u8 reserved[28]; +}; + +struct int3472_device { + struct acpi_device *adev; + struct acpi_device *sensor; + + unsigned int n_gpios; /* how many GPIOs have we seen */ + + unsigned int n_regulators; + struct list_head regulators; + + unsigned int n_sensor_gpios; /* how many have we mapped to sensor */ + struct gpiod_lookup_table gpios; +}; + +struct int3472_gpio_regulator { + char regulator_name[GPIO_REGULATOR_NAME_LENGTH]; + char supply_name[GPIO_REGULATOR_SUPPLY_NAME_LENGTH]; + struct gpio_desc *gpio; + struct regulator_dev *rdev; + struct regulator_desc rdesc; + struct list_head list; +}; + +struct int3472_sensor_regulator_map { + char *sensor_module_name; + unsigned int n_supplies; + struct regulator_consumer_supply *supplies; +}; + +/* + * Here follows platform specific mapping information that we can pass to + * regulator_init_data when we register our regulators. They're just mapped + * via index, I.E. the first regulator pin that the code finds for the + * i2c-OVTI2680:00 device is avdd, the second is dovdd and so on. + */ + +static struct regulator_consumer_supply miix_510_ov2680[] = { + { "i2c-OVTI2680:00", "avdd" }, + { "i2c-OVTI2680:00", "dovdd" }, +}; + +static struct regulator_consumer_supply surface_go2_ov5693[] = { + { "i2c-INT33BE:00", "avdd" }, + { "i2c-INT33BE:00", "dovdd" }, +}; + +static struct regulator_consumer_supply surface_book_ov5693[] = { + { "i2c-INT33BE:00", "avdd" }, + { "i2c-INT33BE:00", "dovdd" }, +}; + +static struct int3472_sensor_regulator_map int3472_sensor_regulator_maps[] = { + { "GNDF140809R", 2, miix_510_ov2680 }, + { "YHCU", 2, surface_go2_ov5693 }, + { "MSHW0070", 2, surface_book_ov5693 }, +};