From patchwork Mon Jan 18 00:34:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 1427921 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=oQUa3mMc; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DJtDP6Sdvz9sW0 for ; Mon, 18 Jan 2021 11:37:57 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730744AbhARAha (ORCPT ); Sun, 17 Jan 2021 19:37:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730494AbhARAfX (ORCPT ); Sun, 17 Jan 2021 19:35:23 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CA06C061574; Sun, 17 Jan 2021 16:34:43 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id i63so12122218wma.4; Sun, 17 Jan 2021 16:34:42 -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=RJZvDTx1XXuRYdw+x5NTve2jp5kyClRdRV3Lu9KCjgs=; b=oQUa3mMcz+3upwqceaYIYRZIPID3stOz5WpURqI035bd8f2KVT+dpBhLzXD1SbKt6Q qyMdu2e/DQD1FdM3y7glCrF3aMJ+5NVw8j4UBjpp0L7MJZt1SWvkcyk/GFf1FUxWZqxO VYpidYR8r3YgjnBp338CY+TV5RHYukzEy0VQFgR/SZh4iBFT9060FePLHePwR34mmgjX lJc21ic5z5fIEv7Um5yk7hfcZPL4YajPxr+sz39Rc0D7cQVpGMZZo1HyJReL+n9LHUxW sd7M2hUxWmdKcM9tRFH2iZt5rcBWOVsoPqIegyi1lVAVLxSZsEni4xBQzFnWnCqwEIAb Id6g== 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=RJZvDTx1XXuRYdw+x5NTve2jp5kyClRdRV3Lu9KCjgs=; b=e/E0e9dsplSJlTdc0o4jVTSVUOH+iliHFKkRENxOkBykIpepryGBbrFJgNfasWIuBF 6XntzpHB+8N0upaXJnsIvyp1ts+Z7gg2CXhglnVKs5sNa+87r45Bg4oelcYECloufM8y GB49nG12FCQq5Ezb6KAcz6Upmzj7/tDYuoNJHi0ECwXInX4y4VsGEZQsO77fkBJEzos6 5CxttUDA+VzC4r/0+1vnCec3Gnjm3RVWP3vr7k4qBbJ1SLKrtiuuwyMR3cV7JtP5pBtq K4j7ZQ+Dd9DcFoEHtDCfEeEB6LdItPc9itAcBYAjDrBrJ06LxgGDDMeL/dwgYKNt7Kna xlQA== X-Gm-Message-State: AOAM531w3H6uXEIZxJ3YIMO/623/T0hqpwZY/WwbIO/70EW9MlI07Lti L2HgJwlAHvEyxeDhv8rqegiHf326mo/mhw== X-Google-Smtp-Source: ABdhPJyrmuivtQjmF+XMSkLSEA6I51KLLylqniCHheFrZI1/FrzwXPkC+Th8A3ZsNVw8ZM7E+RbEXg== X-Received: by 2002:a7b:ca4d:: with SMTP id m13mr15551546wml.28.1610930081761; Sun, 17 Jan 2021 16:34:41 -0800 (PST) Received: from valhalla.home ([2.29.208.120]) by smtp.gmail.com with ESMTPSA id o124sm23642040wmb.5.2021.01.17.16.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jan 2021 16:34:41 -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, platform-driver-x86@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, andy@kernel.org, mika.westerberg@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, lee.jones@linaro.org, hdegoede@redhat.com, mgross@linux.intel.com, robert.moore@intel.com, erik.kaneda@intel.com, sakari.ailus@linux.intel.com, andriy.shevchenko@linux.intel.com, laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com Subject: [PATCH v2 1/7] acpi: utils: move acpi_lpss_dep() to utils Date: Mon, 18 Jan 2021 00:34:22 +0000 Message-Id: <20210118003428.568892-2-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210118003428.568892-1-djrscally@gmail.com> References: <20210118003428.568892-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org I need to be able to identify devices which declare themselves to be dependent on other devices through _DEP; add this function to utils.c and export it to the rest of the ACPI layer. Suggested-by: Andy Shevchenko Signed-off-by: Daniel Scally Reviewed-by: Andy Shevchenko --- Changes in v2: - Introduced drivers/acpi/acpi_lpss.c | 24 ------------------------ drivers/acpi/internal.h | 1 + drivers/acpi/utils.c | 24 ++++++++++++++++++++++++ 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c index be73974ce449..70c7d9a3f715 100644 --- a/drivers/acpi/acpi_lpss.c +++ b/drivers/acpi/acpi_lpss.c @@ -543,30 +543,6 @@ static struct device *acpi_lpss_find_device(const char *hid, const char *uid) return bus_find_device(&pci_bus_type, NULL, &data, match_hid_uid); } -static bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle) -{ - struct acpi_handle_list dep_devices; - acpi_status status; - int i; - - if (!acpi_has_method(adev->handle, "_DEP")) - return false; - - status = acpi_evaluate_reference(adev->handle, "_DEP", NULL, - &dep_devices); - if (ACPI_FAILURE(status)) { - dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n"); - return false; - } - - for (i = 0; i < dep_devices.count; i++) { - if (dep_devices.handles[i] == handle) - return true; - } - - return false; -} - static void acpi_lpss_link_consumer(struct device *dev1, const struct lpss_device_links *link) { diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index cb229e24c563..ee62c0973576 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -79,6 +79,7 @@ static inline void acpi_lpss_init(void) {} #endif void acpi_apd_init(void); +bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle); acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src); bool acpi_queue_hotplug_work(struct work_struct *work); diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index ddca1550cce6..78b38775f18b 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -807,6 +807,30 @@ static int acpi_dev_match_cb(struct device *dev, const void *data) return hrv == match->hrv; } +bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle) +{ + struct acpi_handle_list dep_devices; + acpi_status status; + int i; + + if (!acpi_has_method(adev->handle, "_DEP")) + return false; + + status = acpi_evaluate_reference(adev->handle, "_DEP", NULL, + &dep_devices); + if (ACPI_FAILURE(status)) { + dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n"); + return false; + } + + for (i = 0; i < dep_devices.count; i++) { + if (dep_devices.handles[i] == handle) + return true; + } + + return false; +} + /** * acpi_dev_present - Detect that a given ACPI device is present * @hid: Hardware ID of the device. From patchwork Mon Jan 18 00:34:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 1427923 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=QzL/Nu1C; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DJtDt2Xq3z9sW0 for ; Mon, 18 Jan 2021 11:38:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730732AbhARAh1 (ORCPT ); Sun, 17 Jan 2021 19:37:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730507AbhARAfY (ORCPT ); Sun, 17 Jan 2021 19:35:24 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54217C061575; Sun, 17 Jan 2021 16:34:44 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id c5so14846553wrp.6; Sun, 17 Jan 2021 16:34:44 -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=oxyOObT1sg5s9bWkUVceIGz0KKXfziZMqNtmhxIBUsg=; b=QzL/Nu1C+vMnHFaRThEDIZe5Ncq5Of2W3gkYCJnm8AmU7SESXNgasBnk8UNZDddGaQ NY2UFS1U4m8+RsHxWIsXCuHC55DliW48CVdjoyr/Hcn1plYmlhE+l47VbBxLoz8itTu2 aZo45y9QldNIOq5Rzwd+s1ivBqcKHiGqlxioGfubLKYAdjh4m37/fcMJWFQus9zOugXS c2PKC6sAQ6Am6/ejcfKwnxansf6BufsA8GzXsQYwjgJtbZ4C5jlb8HNHBXaD+lJ3jQiN ZY1wZFnmzKWrxFBPslIqd9GIVPEHI3y+LjYJCjN6WD5tpfhV22TIdQt7X/v833C874MM pfbg== 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=oxyOObT1sg5s9bWkUVceIGz0KKXfziZMqNtmhxIBUsg=; b=NyUYXtlmW9rx/aHp6K/xozCJP1rNchifLWx8LL2ebFjUiWvoVSLsk1RbIDOvTeQ24j j10xNCp0SgDwk49PNcAHhCB4fw2fGb9cw3FaTOGpA8qyTcDO/6FY3GxVj7tiayEApjzA S+e6qmLaINLFsTsEBgKVFvYBtG79IFxlTd0bHCsCCmKko13TKEssjxzDWrQ55oG1wiKo Rld9R4CZwZ33/2j8tk4TPi1b+SFyulvutqvwuL1TiHMXeB1UptDCe3fJBeGH+R7raLSt uklrwOV/GOc18nJmXmaBcqOYr7yw8TNYOAiFWQkZgzE4wcio3kkU5hfQ6xNU2Lt/jDwU 2gGA== X-Gm-Message-State: AOAM530nHKW984q5KIRC22FxPYRyxBzOE9tmt8LOu364uVfUnYKkXtbx Gvlk/LFBsz5Gwrztb6GyYckTT3dA2ylOwA== X-Google-Smtp-Source: ABdhPJwP8X4dWttjUj1Bb2v8rxhV65TD73lpEEX+TkikPku+vK0TaGlSy9mss5ow/8gIZF3SXV9r4Q== X-Received: by 2002:adf:cc81:: with SMTP id p1mr23185951wrj.339.1610930083018; Sun, 17 Jan 2021 16:34:43 -0800 (PST) Received: from valhalla.home ([2.29.208.120]) by smtp.gmail.com with ESMTPSA id o124sm23642040wmb.5.2021.01.17.16.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jan 2021 16:34:42 -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, platform-driver-x86@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, andy@kernel.org, mika.westerberg@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, lee.jones@linaro.org, hdegoede@redhat.com, mgross@linux.intel.com, robert.moore@intel.com, erik.kaneda@intel.com, sakari.ailus@linux.intel.com, andriy.shevchenko@linux.intel.com, laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com Subject: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices Date: Mon, 18 Jan 2021 00:34:23 +0000 Message-Id: <20210118003428.568892-3-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210118003428.568892-1-djrscally@gmail.com> References: <20210118003428.568892-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org In some ACPI tables we encounter, devices use the _DEP method to assert a dependence on other ACPI devices as opposed to the OpRegions that the specification intends. We need to be able to find those devices "from" the dependee, so add a function to parse all ACPI Devices and check if the include the handle of the dependee device in their _DEP buffer. Signed-off-by: Daniel Scally Reviewed-by: Laurent Pinchart --- Changes in v2: - Used acpi_lpss_dep() as Andy suggested. drivers/acpi/utils.c | 34 ++++++++++++++++++++++++++++++++++ include/acpi/acpi_bus.h | 2 ++ 2 files changed, 36 insertions(+) diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 78b38775f18b..ec6a2406a886 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -831,6 +831,18 @@ bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle) return false; } +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; + acpi_handle handle = dependee->handle; + + if (acpi_lpss_dep(adev, handle)) + return 1; + + return 0; +} + /** * acpi_dev_present - Detect that a given ACPI device is present * @hid: Hardware ID of the device. @@ -866,6 +878,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 02a716a0af5d..33deb22294f2 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -683,6 +683,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 Jan 18 00:34:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 1427912 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=rsflLZaE; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DJtBr2T0dz9sVs for ; Mon, 18 Jan 2021 11:36:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730543AbhARAfe (ORCPT ); Sun, 17 Jan 2021 19:35:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730523AbhARAfZ (ORCPT ); Sun, 17 Jan 2021 19:35:25 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69DC5C061757; Sun, 17 Jan 2021 16:34:45 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id u14so8206655wmq.4; Sun, 17 Jan 2021 16:34:45 -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=uWwlR2JD3sOpBYSIkzbMOHTkmK2E7HCQ52xgimQRdfg=; b=rsflLZaEbKqnXrB4MxHq/6ALeOIvbtVotESsfAL8Quyuk/od9smrl6iVXp1IWaUVHX jUDc02ydCwfsG6f0AbYuIK6i8atPZ5y1I2KvW0fj2hN85afmKU+4kSXcVsIoA2ZuGEHD zSr0V9b9TyYFSOdN9nEHQ9d6qDaI3oy0Z4mPQWys2nhdN9SelkoKbD5zKnK8c5JzmFfd 4AlPyXhFMxqK3lGUXdFjMj2ilM061a+5FhN/J4t2kUvTamvB7+KvIkKLef9oyxPiQjQY Cw1g34ACjN0mVyAguZ9caUZ/0cHF4EO+lk5K8NVdBOGZFDmAFdEEBZ+7aeF3wPHRo2Fi VBEw== 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=uWwlR2JD3sOpBYSIkzbMOHTkmK2E7HCQ52xgimQRdfg=; b=L+kXO46+KAsoTW4puWIGBk4ZTeF2PXheGn2PVKIhKu/frTGpGV6YtYfhPYg5b0lFAq BeLpbltK5D/meYAiNcNr2uiTo/3PHYwAbSmhIMAibreqP+9ryj/yNaxBHeTk7+F9WbmW X1joeiTU3T8fg0p+YoyHzcLwA637hRC2/Amgwiw+q7BBob1wiqHCUJHh2i5FUiBrXy// zDl3w/o71BERV0vf46XYX75zUM0kzfWAV3bGA6TBs7R59JwtSR4EHm0zDN/JxITXpiLj lk6KdCfgzPAGdkVFGG5/KBnfviVJtQoVzrVUe/DKaOb2ArpQY1TG/vK34S/8iOgjmWhg 6jHw== X-Gm-Message-State: AOAM533nHfVSN31AR+DayGVAamSkNCBSagqiLxDvm7e+3ECrTuW1d9kt /6b8zC12J9zOFodYCFkQfX6vaVWStKbhnA== X-Google-Smtp-Source: ABdhPJzzh1BsCeWgvlBnbQCml4lrvnEv9WKpVfMy088N7PBSItV0kmvjQmp/Q0r+cm5G47ymrl7pUA== X-Received: by 2002:a05:600c:258:: with SMTP id 24mr18752269wmj.16.1610930084256; Sun, 17 Jan 2021 16:34:44 -0800 (PST) Received: from valhalla.home ([2.29.208.120]) by smtp.gmail.com with ESMTPSA id o124sm23642040wmb.5.2021.01.17.16.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jan 2021 16:34:43 -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, platform-driver-x86@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, andy@kernel.org, mika.westerberg@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, lee.jones@linaro.org, hdegoede@redhat.com, mgross@linux.intel.com, robert.moore@intel.com, erik.kaneda@intel.com, sakari.ailus@linux.intel.com, andriy.shevchenko@linux.intel.com, laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com Subject: [PATCH v2 3/7] i2c: i2c-core-base: Use format macro in i2c_dev_set_name() Date: Mon, 18 Jan 2021 00:34:24 +0000 Message-Id: <20210118003428.568892-4-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210118003428.568892-1-djrscally@gmail.com> References: <20210118003428.568892-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Some places in the kernel allow users to map resources to a device using device name (for example, gpiod_lookup_table). Currently this involves waiting for the i2c_client to have been registered so we can use dev_name(&client->dev). We want to add a function to allow users to refer to an i2c device by name before it has been instantiated, so create a macro for the format that's accessible outside the i2c layer and use it in i2c_dev_set_name() Suggested-by: Andy Shevchenko Signed-off-by: Daniel Scally Reviewed-by: Laurent Pinchart Acked-by: Sakari Ailus Reviewed-by: Sakari Ailus Reviewed-by: Andy Shevchenko --- - Used format macro in i2c_dev_set_name() instead of sub func drivers/i2c/i2c-core-base.c | 4 ++-- include/linux/i2c.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 63ebf722a424..547b8926cac8 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -811,12 +811,12 @@ static void i2c_dev_set_name(struct i2c_adapter *adap, struct acpi_device *adev = ACPI_COMPANION(&client->dev); if (info && info->dev_name) { - dev_set_name(&client->dev, "i2c-%s", info->dev_name); + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, info->dev_name); return; } if (adev) { - dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev)); + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev)); return; } diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 56622658b215..4d40a4b46810 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -39,6 +39,9 @@ enum i2c_slave_event; typedef int (*i2c_slave_cb_t)(struct i2c_client *client, enum i2c_slave_event event, u8 *val); +/* I2C Device Name Format - to maintain consistency outside the i2c layer */ +#define I2C_DEV_NAME_FORMAT "i2c-%s" + /* I2C Frequency Modes */ #define I2C_MAX_STANDARD_MODE_FREQ 100000 #define I2C_MAX_FAST_MODE_FREQ 400000 From patchwork Mon Jan 18 00:34:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 1427913 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=aK2h+ZKG; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DJtBr6bszz9sW0 for ; Mon, 18 Jan 2021 11:36:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730535AbhARAfc (ORCPT ); Sun, 17 Jan 2021 19:35:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730532AbhARAf2 (ORCPT ); Sun, 17 Jan 2021 19:35:28 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B19A7C0613C1; Sun, 17 Jan 2021 16:34:46 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id y17so14846229wrr.10; Sun, 17 Jan 2021 16:34:46 -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=PbvX9p++F2mDiu44jiSND5knwA5OcZJgkRIiG9x4IPE=; b=aK2h+ZKGBqLjK+HOsK8Eb94wCvZZPHTRYUej+vcgRDgyBKsMIHmwfl+IK5pu94V0EG 9C86oP5mfCuSSVn/H1QmrHiJ3FwAa8iwt4W1Y5CUXK121frgvoxSGe26vlzjHr9+S1A0 5+dc9s6vi3u2Q6RbKUHK5s7YKhgotybEZC5+ukSDjW5rq2fyhTSDCa4X3hp8Gc73fLYy gR24PgQGPz7T+Wi6P8qE7VmyNzvNV4IdO1vLa5sT/JjIEvtwG9z6ag6rD/hBdLTPICsB eP4KcjnTjj5JY4AwJ6FQLaPn+sjG3uHR7GO/IdszjqJsnOtt+/09bNFcvozu8LaoE67L YRVA== 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=PbvX9p++F2mDiu44jiSND5knwA5OcZJgkRIiG9x4IPE=; b=Sry+6HM0bI3M3s45VmNvcM4yO9fCyaqet2ZqIQjC5JU3Zug3Yh3NnV5GcXXvE6XwJZ e2q5ZUL3gEzPhYIqP0tlU3n/WxE6PrE41ngOi6NZ7iERMgMJcuWjPWfttwaoFhCX2fHq G+6MQN/W65MXlQKK9NQy71prCBc9AiPWUDPy2Gydqgajmja5Ca5QTOT27k9uEr7uoaYk 4CJEMohWqrcafhuX7oMPoZL3FVjCWBPgbxqMwI+Qw8Qlx0K97h+1InYyAqIgJ9f+TvQH cthkilRnWPZe78xG8ieQ8tRr5vJHHAtME/83RnWZKcnA32tbMPXWZtYdLq7D7ujcN4KU ViAQ== X-Gm-Message-State: AOAM531L0E0ZN6lvUMp8LFVRBGXnoYtcwN4ukUosRewjFtdE/1zCShkZ x0C6GuSYLeOKwOuqWvxIbnyUNzhUwH/Rpw== X-Google-Smtp-Source: ABdhPJzn7m9FqPVHSUWMPIKCaOySd8Kyzq/uVeNq66KJG9h3ejnku8fB0HiFon0VF+qkXnVSKChDFA== X-Received: by 2002:a05:6000:104d:: with SMTP id c13mr22897288wrx.127.1610930085498; Sun, 17 Jan 2021 16:34:45 -0800 (PST) Received: from valhalla.home ([2.29.208.120]) by smtp.gmail.com with ESMTPSA id o124sm23642040wmb.5.2021.01.17.16.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jan 2021 16:34:44 -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, platform-driver-x86@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, andy@kernel.org, mika.westerberg@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, lee.jones@linaro.org, hdegoede@redhat.com, mgross@linux.intel.com, robert.moore@intel.com, erik.kaneda@intel.com, sakari.ailus@linux.intel.com, andriy.shevchenko@linux.intel.com, laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com Subject: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name() Date: Mon, 18 Jan 2021 00:34:25 +0000 Message-Id: <20210118003428.568892-5-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210118003428.568892-1-djrscally@gmail.com> References: <20210118003428.568892-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org We want to refer to an i2c device by name before it has been created by the kernel; add a function that constructs the name from the acpi device instead. Signed-off-by: Daniel Scally Reviewed-by: Andy Shevchenko --- Changes in v2: - Stopped using devm_kasprintf() drivers/i2c/i2c-core-acpi.c | 16 ++++++++++++++++ include/linux/i2c.h | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c index 37c510d9347a..98c3ba9a2350 100644 --- a/drivers/i2c/i2c-core-acpi.c +++ b/drivers/i2c/i2c-core-acpi.c @@ -497,6 +497,22 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index, } EXPORT_SYMBOL_GPL(i2c_acpi_new_device); +/** + * i2c_acpi_dev_name - Construct i2c device name for devs sourced from ACPI + * @adev: ACPI device to construct the name for + * + * Constructs the name of an i2c device matching the format used by + * i2c_dev_set_name() to allow users to refer to an i2c device by name even + * before they have been instantiated. + * + * The caller is responsible for freeing the returned pointer. + */ +char *i2c_acpi_dev_name(struct acpi_device *adev) +{ + return kasprintf(GFP_KERNEL, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev)); +} +EXPORT_SYMBOL_GPL(i2c_acpi_dev_name); + #ifdef CONFIG_ACPI_I2C_OPREGION static int acpi_gsb_i2c_read_bytes(struct i2c_client *client, u8 cmd, u8 *data, u8 data_len) diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 4d40a4b46810..b82aac05b17f 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -998,6 +998,7 @@ bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, u32 i2c_acpi_find_bus_speed(struct device *dev); struct i2c_client *i2c_acpi_new_device(struct device *dev, int index, struct i2c_board_info *info); +char *i2c_acpi_dev_name(struct acpi_device *adev); struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle); #else static inline bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, @@ -1014,6 +1015,10 @@ static inline struct i2c_client *i2c_acpi_new_device(struct device *dev, { return ERR_PTR(-ENODEV); } +static inline char *i2c_acpi_dev_name(struct acpi_device *adev) +{ + return NULL; +} static inline struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle) { return NULL; From patchwork Mon Jan 18 00:34:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 1427915 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=qBC/1udN; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DJtBs51j4z9sWL for ; Mon, 18 Jan 2021 11:36:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730640AbhARAg0 (ORCPT ); Sun, 17 Jan 2021 19:36:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730523AbhARAgC (ORCPT ); Sun, 17 Jan 2021 19:36:02 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E507DC0613CF; Sun, 17 Jan 2021 16:34:47 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id e15so6003753wme.0; Sun, 17 Jan 2021 16:34:47 -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=xaT2dcHZPdRJ0y4idc+VOXuKF4+lYQ1c3wtupWCa5lw=; b=qBC/1udNWoM7qwWbUL53JFbD0+wuAlegkZZd6nQPdTzEf8VEioBlYOhTtgItMm83km 9vsAnmj3el0tQo0TY1ruwGWcgVTO+1OVFwIXiZahVjWp1KnVk0DA7pdpAUvbv41ObjZN ntapD1w2UYh8DzrNTu6EMdsxulygorhg/zv4w3b66L1JzZXKMD4KbnRC+8criP5nsgu5 wLeZ5dDBEvEIKdYcvwzqGL8jnvmUeS9gTe/7+9nIOe/26W2KmGAUWog8XrpGO2l1MvXO w/ikXOuDH1EfJ4fl0v16j4HvdHcHM6lLNkxgk0t9H5fX7qJvloyoysnmvnlfUZKl5rO6 4yiQ== 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=xaT2dcHZPdRJ0y4idc+VOXuKF4+lYQ1c3wtupWCa5lw=; b=MzpwN/IVrlHLWNlI0cbzKUM+QR6+0d3YkiQq3fXSHeniMaFodSrQtgRFT7hbggEzdb 4v6QW7fMbes+zTa6AKLuTRNxqx8aTcm51+i+oTVXnlM5JSoA3O6xSZOC1PVoz/3dmvOj fqPPbNKTw99eVfTo+GM1/fPpmE5sX+GMnwkpHMhVU6As9XdJSBwkDRivUE5cMJ1ZNt7u wZ1XC+sF6lGWGSdIJrL2s1256TUNfuPQsLucOZTTRyOGZDLbDTpfkfsipqcOqZTdXAqi 7Q3OsBQLsp7Gylz31rZLZevE0ZakI5X7EdDjOmYGxj5pBMtx1YuI42FPREg2/TMAvzW+ lCKg== X-Gm-Message-State: AOAM530wmeY/mc5h87OdFiS1J415/asMo2Ij1hAuSZ6iOt76MDbC6LLW kvu+h/iSVjWzofLwpXbeHq5rLMRAhoLgQQ== X-Google-Smtp-Source: ABdhPJwbFdX9FL2YemiaSMI9/cbs6Jpg4yHjtWaPhHc4xRuVvJSfIVyI4sfsixU+kk04jRuT88Ygyw== X-Received: by 2002:a1c:6a13:: with SMTP id f19mr18019473wmc.10.1610930086718; Sun, 17 Jan 2021 16:34:46 -0800 (PST) Received: from valhalla.home ([2.29.208.120]) by smtp.gmail.com with ESMTPSA id o124sm23642040wmb.5.2021.01.17.16.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jan 2021 16:34:46 -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, platform-driver-x86@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, andy@kernel.org, mika.westerberg@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, lee.jones@linaro.org, hdegoede@redhat.com, mgross@linux.intel.com, robert.moore@intel.com, erik.kaneda@intel.com, sakari.ailus@linux.intel.com, andriy.shevchenko@linux.intel.com, laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com Subject: [PATCH v2 5/7] gpio: gpiolib-acpi: Export acpi_get_gpiod() Date: Mon, 18 Jan 2021 00:34:26 +0000 Message-Id: <20210118003428.568892-6-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210118003428.568892-1-djrscally@gmail.com> References: <20210118003428.568892-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@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 Reviewed-by: Laurent Pinchart --- Changes in v2: -None 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 e37a57d0a2f0..83f9f85cd0ab 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 2630c2e953f7..5cd272326eb7 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 Jan 18 00:34:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 1427917 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=epPoEHoz; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DJtCQ6KbYz9sWL for ; Mon, 18 Jan 2021 11:37:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730689AbhARAgq (ORCPT ); Sun, 17 Jan 2021 19:36:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730625AbhARAgC (ORCPT ); Sun, 17 Jan 2021 19:36:02 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60163C0613D3; Sun, 17 Jan 2021 16:34:49 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id h17so11934020wmq.1; Sun, 17 Jan 2021 16:34:49 -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=jpCb7UcIWwYohaNkDcpMUvMsDr2JCxErFFTlyvJA9c8=; b=epPoEHozhiiE8OyZ57fxhVX9L3aw3WUaGAm+ZJOcSL7U0nwfr+hAD2YQ8J8dd0nZWy QyWfqAZzKTQGL/FxYPPyHGkPw9kdvktwtlk4sqiIhqA5U1mFtM3VfGdjeuCdsIGMfJSC 1dzL9lOQNEukUzNvy5GZFG8yK1Qgo+IWTE33MvFG21Oh6lvo/0lF4IfpXxK3S4zgI99B ya0LL3He6eNK/3TaIGlescqU4Ee2rBjXN/HAvNKwTvEWD+AT8f6J0CXl0dEx5IE/DALd eTQ0MRZClE1invKIhiM8AWpJwdJ5CAH4lkXMnTko49dubuExMM5sWTrwBisE0Z/qU91y XG2w== 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=jpCb7UcIWwYohaNkDcpMUvMsDr2JCxErFFTlyvJA9c8=; b=bogHKBnlOnsAg1G+EE1ADBoHYbvH2Cb/XxDdy6XfKk+b/WYAoV4KJF2iQyvGN51lNZ XtSovMxDzfsNIaMcF17YxWE9q4AJ0MUmzEtsDaRm4tG//LR2Ic82sfgK2izY8WDV04lM qzGS65Mt/j7f2s6QQOMrR8SjX0EceTgHtAArxWsc2noLKYOk7FmszPehaSX+4dj0DMK7 MhSXfkY/HEInzuf3rG01VJ62/esKiCrTPuWJAbKm1b/y5B5HOen0uNczvGI1ygjHfKSu jJgazsktyahkr+wQ6CBhiprfOYIhOeobSrRcJ6HW7S0iH8byLTLHKs3lj0jgBdvDh709 lrVQ== X-Gm-Message-State: AOAM532rG0pRo0MBmgXbihG/6LWVkxKjv5m1HzTz9V3R2n6w6czJ+WxD UtIHcDYr5Cfun6W80bWZ8+0L7KHfiCFjvA== X-Google-Smtp-Source: ABdhPJzvMx+gFmb983v9YNRNS5Aen5kn7Url4JAlJiooOlYZe13vZbToaZ7sx+cHZ5qZxYvLN7VBxg== X-Received: by 2002:a7b:cc0a:: with SMTP id f10mr17996848wmh.6.1610930087973; Sun, 17 Jan 2021 16:34:47 -0800 (PST) Received: from valhalla.home ([2.29.208.120]) by smtp.gmail.com with ESMTPSA id o124sm23642040wmb.5.2021.01.17.16.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jan 2021 16:34:47 -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, platform-driver-x86@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, andy@kernel.org, mika.westerberg@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, lee.jones@linaro.org, hdegoede@redhat.com, mgross@linux.intel.com, robert.moore@intel.com, erik.kaneda@intel.com, sakari.ailus@linux.intel.com, andriy.shevchenko@linux.intel.com, laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com Subject: [PATCH v2 6/7] platform: x86: Add intel_skl_int3472 driver Date: Mon, 18 Jan 2021 00:34:27 +0000 Message-Id: <20210118003428.568892-7-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210118003428.568892-1-djrscally@gmail.com> References: <20210118003428.568892-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org ACPI devices with _HID INT3472 are currently matched to the tps68470 driver, however this does not cover all situations in which that _HID occurs. We've encountered three possibilities: 1. On Chrome OS devices, an ACPI device with _HID INT3472 (representing a physical tps68470 device) that requires a GPIO and OpRegion driver 2. On devices designed for Windows, an ACPI device with _HID INT3472 (again representing a physical tps68470 device) which requires GPIO, Clock and Regulator drivers. 3. On other devices designed for Windows, an ACPI device with _HID INT3472 which does NOT represent a physical tps68470, and is instead used as a dummy device to group some system GPIO lines which are meant to be consumed by the sensor that is dependent on this entry. This commit adds a new module, registering a platform driver to deal with the 3rd scenario plus an i2c-driver to deal with #1 and #2, by querying the CLDB buffer found against INT3472 entries to determine which is most appropriate. Suggested-by: Laurent Pinchart Signed-off-by: Daniel Scally --- Changes in v2: - Switched to a module registering a platform driver to run the dummy ACPI devices, plus an i2c driver to replace and extend the existing tps68470 driver - Added clock handling functions to the int3472-discrete driver - A whole bunch of other changes too numerous to enumerate MAINTAINERS | 5 + drivers/platform/x86/Kconfig | 25 + drivers/platform/x86/Makefile | 4 + .../platform/x86/intel_skl_int3472_common.c | 100 ++++ .../platform/x86/intel_skl_int3472_common.h | 100 ++++ .../platform/x86/intel_skl_int3472_discrete.c | 496 ++++++++++++++++++ .../platform/x86/intel_skl_int3472_tps68470.c | 145 +++++ 7 files changed, 875 insertions(+) create mode 100644 drivers/platform/x86/intel_skl_int3472_common.c create mode 100644 drivers/platform/x86/intel_skl_int3472_common.h create mode 100644 drivers/platform/x86/intel_skl_int3472_discrete.c create mode 100644 drivers/platform/x86/intel_skl_int3472_tps68470.c diff --git a/MAINTAINERS b/MAINTAINERS index a091b496fdd8..c4ed8c3bc58e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9147,6 +9147,11 @@ S: Maintained F: arch/x86/include/asm/intel_scu_ipc.h F: drivers/platform/x86/intel_scu_* +INTEL SKL INT3472 ACPI DEVICE DRIVER +M: Daniel Scally +S: Maintained +F: drivers/platform/x86/intel_skl_int3472_* + INTEL SPEED SELECT TECHNOLOGY M: Srinivas Pandruvada L: platform-driver-x86@vger.kernel.org diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 91e6176cdfbd..916b077df2d5 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -844,6 +844,31 @@ config INTEL_CHT_INT33FE device and CONFIG_TYPEC_FUSB302=m and CONFIG_BATTERY_MAX17042=m for Type-C device. +config INTEL_SKL_INT3472 + tristate "Intel SkyLake ACPI INT3472 Driver" + depends on X86 && ACPI + select REGMAP_I2C + help + This driver adds support for the INT3472 ACPI devices found on some + Intel SkyLake devices. + + There are 3 kinds of INT3472 ACPI device possible; two for devices + designed for Windows (either with or without a physical tps68470 + PMIC) and one designed for Chrome OS. This driver handles all three + situations by discovering information it needs to discern them at + runtime. + + If your device was designed for Chrome OS, this driver will provide + an ACPI operation region, which must be available before any of the + devices using this are probed. For this reason, you should select Y + if your device was designed for ChromeOS. This option also configures + the designware-i2c driver to be built-in, for the same reason. + + Say Y or M here if you have a SkyLake device designed for use + with Windows or ChromeOS. Say N here if you are not sure. + + The module will be named "intel-skl-int3472" + config INTEL_HID_EVENT tristate "INTEL HID Event" depends on ACPI diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index 581475f59819..ae29c66842ca 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -86,6 +86,10 @@ obj-$(CONFIG_INTEL_HID_EVENT) += intel-hid.o obj-$(CONFIG_INTEL_INT0002_VGPIO) += intel_int0002_vgpio.o obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o obj-$(CONFIG_INTEL_OAKTRAIL) += intel_oaktrail.o +obj-$(CONFIG_INTEL_SKL_INT3472) += intel_skl_int3472.o +intel_skl_int3472-objs := intel_skl_int3472_common.o \ + intel_skl_int3472_discrete.o \ + intel_skl_int3472_tps68470.o obj-$(CONFIG_INTEL_VBTN) += intel-vbtn.o # MSI diff --git a/drivers/platform/x86/intel_skl_int3472_common.c b/drivers/platform/x86/intel_skl_int3472_common.c new file mode 100644 index 000000000000..08cb9d3c06aa --- /dev/null +++ b/drivers/platform/x86/intel_skl_int3472_common.c @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Author: Dan Scally */ + +#include +#include +#include + +#include "intel_skl_int3472_common.h" + +int skl_int3472_get_cldb_buffer(struct acpi_device *adev, + struct int3472_cldb *cldb) +{ + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + acpi_handle handle = adev->handle; + union acpi_object *obj; + acpi_status status; + int ret = 0; + + status = acpi_evaluate_object(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); + +out_free_buff: + kfree(buffer.pointer); + return ret; +} + +static const struct acpi_device_id int3472_device_id[] = { + { "INT3472", 0 }, + { }, +}; +MODULE_DEVICE_TABLE(acpi, int3472_device_id); + +static struct platform_driver int3472_discrete = { + .driver = { + .name = "int3472-discrete", + .acpi_match_table = int3472_device_id, + }, + .probe = skl_int3472_discrete_probe, + .remove = skl_int3472_discrete_remove, +}; + +static struct i2c_driver int3472_tps68470 = { + .driver = { + .name = "int3472-tps68470", + .acpi_match_table = int3472_device_id, + }, + .probe_new = skl_int3472_tps68470_probe, +}; + +static int skl_int3472_init(void) +{ + int ret = 0; + + ret = platform_driver_register(&int3472_discrete); + if (ret) + return ret; + + ret = i2c_register_driver(THIS_MODULE, &int3472_tps68470); + if (ret) + goto err_unregister_plat_drv; + + return 0; + +err_unregister_plat_drv: + platform_driver_unregister(&int3472_discrete); + return ret; +} +module_init(skl_int3472_init); + +static void skl_int3472_exit(void) +{ + platform_driver_unregister(&int3472_discrete); + i2c_del_driver(&int3472_tps68470); +} +module_exit(skl_int3472_exit); + +MODULE_DESCRIPTION("Intel SkyLake INT3472 ACPI Device Driver"); +MODULE_AUTHOR("Daniel Scally "); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/platform/x86/intel_skl_int3472_common.h b/drivers/platform/x86/intel_skl_int3472_common.h new file mode 100644 index 000000000000..9acd0ce7aed9 --- /dev/null +++ b/drivers/platform/x86/intel_skl_int3472_common.h @@ -0,0 +1,100 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Author: Dan Scally */ +#include +#include +#include +#include +#include + +/* PMIC GPIO Types */ +#define INT3472_GPIO_TYPE_RESET 0x00 +#define INT3472_GPIO_TYPE_POWERDOWN 0x01 +#define INT3472_GPIO_TYPE_CLK_ENABLE 0x0c +#define INT3472_GPIO_TYPE_POWER_ENABLE 0x0b +#define INT3472_GPIO_TYPE_PRIVACY_LED 0x0d +#define INT3472_PDEV_MAX_NAME_LEN 23 +#define INT3472_MAX_SENSOR_GPIOS 3 +#define GPIO_REGULATOR_NAME_LENGTH 27 +#define GPIO_REGULATOR_SUPPLY_NAME_LENGTH 9 + +#define INT3472_REGULATOR(_NAME, _SUPPLY, _OPS) \ + (const struct regulator_desc) { \ + .name = _NAME, \ + .supply_name = _SUPPLY, \ + .id = 0, \ + .type = REGULATOR_VOLTAGE, \ + .ops = _OPS, \ + .owner = THIS_MODULE, \ + } + +#define INT3472_GPIO_FUNCTION_REMAP(_PIN, _FUNCTION) \ + (const struct int3472_gpio_function_remap) { \ + .documented = _PIN, \ + .actual = _FUNCTION \ + } + +#define to_int3472_clk(hw) \ + container_of(hw, struct int3472_gpio_clock, clk_hw) + +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_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 int3472_gpio_clock { + struct clk *clk; + struct clk_hw clk_hw; + struct clk_lookup *cl; + struct gpio_desc *gpio; +}; + +struct int3472_device { + struct acpi_device *adev; + struct platform_device *pdev; + struct acpi_device *sensor; + char *sensor_name; + + unsigned int n_gpios; /* how many GPIOs have we seen */ + + struct int3472_gpio_regulator regulator; + struct int3472_gpio_clock clock; + + unsigned int n_sensor_gpios; /* how many have we mapped to sensor */ + bool gpios_mapped; + struct gpiod_lookup_table gpios; +}; + +struct int3472_gpio_function_remap { + char *documented; + char *actual; +}; + +struct int3472_sensor_config { + char *sensor_module_name; + struct regulator_consumer_supply supply_map; + const struct int3472_gpio_function_remap *function_maps; +}; + +int skl_int3472_discrete_probe(struct platform_device *pdev); +int skl_int3472_discrete_remove(struct platform_device *pdev); +int skl_int3472_tps68470_probe(struct i2c_client *client); +int skl_int3472_get_cldb_buffer(struct acpi_device *adev, + struct int3472_cldb *cldb); diff --git a/drivers/platform/x86/intel_skl_int3472_discrete.c b/drivers/platform/x86/intel_skl_int3472_discrete.c new file mode 100644 index 000000000000..93d250dca92f --- /dev/null +++ b/drivers/platform/x86/intel_skl_int3472_discrete.c @@ -0,0 +1,496 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Author: Dan Scally */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "intel_skl_int3472_common.h" + +/* 79234640-9e10-4fea-a5c1-b5aa8b19756f */ +static const guid_t int3472_gpio_guid = + GUID_INIT(0x79234640, 0x9e10, 0x4fea, + 0xa5, 0xc1, 0xb5, 0xaa, 0x8b, 0x19, 0x75, 0x6f); + +/* 822ace8f-2814-4174-a56b-5f029fe079ee */ +static const guid_t cio2_sensor_module_guid = + GUID_INIT(0x822ace8f, 0x2814, 0x4174, + 0xa5, 0x6b, 0x5f, 0x02, 0x9f, 0xe0, 0x79, 0xee); + +/* + * Here follows platform specific mapping information that we can pass to + * the functions mapping resources to the sensors. Where the sensors have + * a power enable pin defined in DSDT we need to provide a supply name so + * the sensor drivers can find the regulator. Optionally, we can provide a + * NULL terminated array of function name mappings to deal with any platform + * specific deviations from the documented behaviour of GPIOs. + * + * Map a GPIO function name to NULL to prevent the driver from mapping that + * GPIO at all. + */ + +static const struct int3472_gpio_function_remap ov2680_gpio_function_remaps[] = { + INT3472_GPIO_FUNCTION_REMAP("reset", NULL), + INT3472_GPIO_FUNCTION_REMAP("powerdown", "reset"), + { } +}; + +static struct int3472_sensor_config int3472_sensor_configs[] = { + /* Lenovo Miix 510-12ISK - OV2680, Front */ + { "GNDF140809R", { 0 }, ov2680_gpio_function_remaps}, + /* Lenovo Miix 510-12ISK - OV5648, Rear */ + { "GEFF150023R", REGULATOR_SUPPLY("avdd", "i2c-OVTI5648:00"), NULL}, + /* Surface Go 1&2 - OV5693, Front */ + { "YHCU", REGULATOR_SUPPLY("avdd", "i2c-INT33BE:00"), NULL}, +}; + +/* + * 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 skl_int3472_clk_enable(struct clk_hw *hw) +{ + struct int3472_gpio_clock *clk = to_int3472_clk(hw); + + gpiod_set_value(clk->gpio, 1); + + return 0; +} + +static void skl_int3472_clk_disable(struct clk_hw *hw) +{ + struct int3472_gpio_clock *clk = to_int3472_clk(hw); + + gpiod_set_value(clk->gpio, 0); +} + +static int skl_int3472_clk_prepare(struct clk_hw *hw) +{ + /* + * We're just turning a GPIO on to enable, so nothing to do here, but + * we want to provide the op so prepare_enable() works. + */ + return 0; +} + +static void skl_int3472_clk_unprepare(struct clk_hw *hw) +{ + /* Likewise, nothing to do here... */ +} + +static const struct clk_ops skl_int3472_clock_ops = { + .prepare = skl_int3472_clk_prepare, + .unprepare = skl_int3472_clk_unprepare, + .enable = skl_int3472_clk_enable, + .disable = skl_int3472_clk_disable, +}; + +static struct int3472_sensor_config * +skl_int3472_get_sensor_module_config(struct int3472_device *int3472) +{ + unsigned int i = ARRAY_SIZE(int3472_sensor_configs); + struct int3472_sensor_config *ret; + union acpi_object *obj; + + obj = acpi_evaluate_dsm_typed(int3472->sensor->handle, + &cio2_sensor_module_guid, 0x00, + 0x01, NULL, ACPI_TYPE_STRING); + + if (!obj) { + dev_err(&int3472->pdev->dev, + "Failed to get sensor module string from _DSM\n"); + return ERR_PTR(-ENODEV); + } + + if (obj->string.type != ACPI_TYPE_STRING) { + dev_err(&int3472->pdev->dev, + "Sensor _DSM returned a non-string value\n"); + ret = ERR_PTR(-EINVAL); + goto out_free_obj; + } + + ret = ERR_PTR(-ENODEV); + while (i--) { + if (!strcmp(int3472_sensor_configs[i].sensor_module_name, + obj->string.pointer)) { + ret = &int3472_sensor_configs[i]; + goto out_free_obj; + } + } + +out_free_obj: + ACPI_FREE(obj); + return ret; +} + +static int skl_int3472_map_gpio_to_sensor(struct int3472_device *int3472, + struct acpi_resource *ares, + char *func, u32 polarity) +{ + char *path = ares->data.gpio.resource_source.string_ptr; + struct int3472_sensor_config *sensor_config; + struct gpiod_lookup table_entry; + struct acpi_device *adev; + acpi_handle handle; + acpi_status status; + int ret; + + sensor_config = skl_int3472_get_sensor_module_config(int3472); + if (!IS_ERR(sensor_config) && sensor_config->function_maps) { + unsigned int i = 0; + + while (sensor_config->function_maps[i].documented) { + if (!strcmp(func, sensor_config->function_maps[i].documented)) { + func = sensor_config->function_maps[i].actual; + + break; + } + + i++; + } + } + + if (!func) + return 0; + + if (int3472->n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS) { + dev_warn(&int3472->pdev->dev, "Too many GPIOs mapped\n"); + return -EINVAL; + } + + 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, polarity); + + memcpy(&int3472->gpios.table[int3472->n_sensor_gpios], &table_entry, + sizeof(table_entry)); + + int3472->n_sensor_gpios++; + + return 0; +} + +static int skl_int3472_register_clock(struct int3472_device *int3472, + struct acpi_resource *ares) +{ + char *path = ares->data.gpio.resource_source.string_ptr; + struct clk_init_data init = { }; + int ret = 0; + + init.name = kasprintf(GFP_KERNEL, "%s-clk", + acpi_dev_name(int3472->adev)); + init.ops = &skl_int3472_clock_ops; + + int3472->clock.gpio = acpi_get_gpiod(path, + ares->data.gpio.pin_table[0]); + if (IS_ERR(int3472->clock.gpio)) { + ret = PTR_ERR(int3472->clock.gpio); + goto out_free_init_name; + } + + int3472->clock.clk_hw.init = &init; + int3472->clock.clk = clk_register(&int3472->adev->dev, + &int3472->clock.clk_hw); + if (IS_ERR(int3472->clock.clk)) { + ret = PTR_ERR(int3472->clock.clk); + goto err_put_gpio; + } + + int3472->clock.cl = clkdev_create(int3472->clock.clk, "xvclk", + int3472->sensor_name); + if (IS_ERR_OR_NULL(int3472->clock.cl)) + goto err_unregister_clk; + + goto out_free_init_name; + +err_unregister_clk: + clk_unregister(int3472->clock.clk); +err_put_gpio: + gpiod_put(int3472->clock.gpio); +out_free_init_name: + kfree(init.name); + + return ret; +} + +static int skl_int3472_register_regulator(struct int3472_device *int3472, + struct acpi_resource *ares) +{ + char *path = ares->data.gpio.resource_source.string_ptr; + struct int3472_sensor_config *sensor_config; + struct regulator_init_data init_data = { }; + struct regulator_config cfg = { }; + int ret; + + sensor_config = skl_int3472_get_sensor_module_config(int3472); + if (IS_ERR_OR_NULL(sensor_config)) { + dev_err(&int3472->pdev->dev, "No sensor module config\n"); + return PTR_ERR(sensor_config); + } + + if (!sensor_config->supply_map.supply) { + dev_err(&int3472->pdev->dev, "No supply name defined\n"); + return -ENODEV; + } + + init_data.supply_regulator = NULL; + init_data.constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS; + init_data.num_consumer_supplies = 1; + init_data.consumer_supplies = &sensor_config->supply_map; + + snprintf(int3472->regulator.regulator_name, + GPIO_REGULATOR_NAME_LENGTH, "int3472-discrete-regulator"); + snprintf(int3472->regulator.supply_name, + GPIO_REGULATOR_SUPPLY_NAME_LENGTH, "supply-0"); + + int3472->regulator.rdesc = INT3472_REGULATOR( + int3472->regulator.regulator_name, + int3472->regulator.supply_name, + &int3472_gpio_regulator_ops); + + int3472->regulator.gpio = acpi_get_gpiod(path, + ares->data.gpio.pin_table[0]); + if (IS_ERR(int3472->regulator.gpio)) { + dev_err(&int3472->pdev->dev, "Failed to get GPIO line\n"); + return PTR_ERR(int3472->regulator.gpio); + } + + cfg.dev = &int3472->adev->dev; + cfg.init_data = &init_data; + cfg.ena_gpiod = int3472->regulator.gpio; + + int3472->regulator.rdev = regulator_register(&int3472->regulator.rdesc, + &cfg); + if (IS_ERR(int3472->regulator.rdev)) { + ret = PTR_ERR(int3472->regulator.rdev); + goto err_free_gpio; + } + + return 0; + +err_free_gpio: + gpiod_put(int3472->regulator.gpio); + + return ret; +} + +/** + * skl_int3472_handle_gpio_resources: maps PMIC resources to consuming sensor + * @ares: A pointer to a &struct acpi_resource + * @data: A pointer to a &struct int3472_device + * + * This function handles GPIO resources that are against an INT3472 + * ACPI device, by checking the value of the corresponding _DSM entry. + * This will return a 32bit int, where the lowest byte represents the + * function of the GPIO pin: + * + * 0x00 Reset + * 0x01 Power down + * 0x0b Power enable + * 0x0c Clock enable + * 0x0d Privacy LED + * + * There are some known platform specific quirks where that does not quite + * hold up; for example where a pin with type 0x01 (Power down) is mapped to + * a sensor pin that performs a reset function or entries in _CRS and _DSM that + * do not actually correspond to a physical connection. These will be handled by + * the mapping sub-functions. + * + * GPIOs will either be mapped directly to the sensor device or else used + * to create clocks and regulators via the usual frameworks. + * + * Return: + * * 0 - When all resources found are handled properly. + * * -EINVAL - If the resource is not a GPIO IO resource + * * -ENODEV - If the resource has no corresponding _DSM entry + * * -Other - Errors propagated from one of the sub-functions. + */ +static int skl_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 so parsing continues */ + + /* + * 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->pdev->dev, + "No _DSM entry for this GPIO pin\n"); + return ENODEV; + } + + switch (obj->integer.value & 0xff) { + case INT3472_GPIO_TYPE_RESET: + ret = skl_int3472_map_gpio_to_sensor(int3472, ares, "reset", + GPIO_ACTIVE_LOW); + if (ret) + dev_err(&int3472->pdev->dev, + "Failed to map reset pin to sensor\n"); + + break; + case INT3472_GPIO_TYPE_POWERDOWN: + ret = skl_int3472_map_gpio_to_sensor(int3472, ares, "powerdown", + GPIO_ACTIVE_LOW); + if (ret) + dev_err(&int3472->pdev->dev, + "Failed to map powerdown pin to sensor\n"); + + break; + case INT3472_GPIO_TYPE_CLK_ENABLE: + ret = skl_int3472_register_clock(int3472, ares); + if (ret) + dev_err(&int3472->pdev->dev, + "Failed to map clock to sensor\n"); + + break; + case INT3472_GPIO_TYPE_POWER_ENABLE: + ret = skl_int3472_register_regulator(int3472, ares); + if (ret) { + dev_err(&int3472->pdev->dev, + "Failed to map regulator to sensor\n"); + } + + break; + case INT3472_GPIO_TYPE_PRIVACY_LED: + ret = skl_int3472_map_gpio_to_sensor(int3472, ares, + "indicator-led", + GPIO_ACTIVE_HIGH); + if (ret) + dev_err(&int3472->pdev->dev, + "Failed to map indicator led to sensor\n"); + + break; + default: + dev_warn(&int3472->pdev->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 ret; +} + +static int skl_int3472_parse_crs(struct int3472_device *int3472) +{ + struct list_head resource_list; + int ret = 0; + + INIT_LIST_HEAD(&resource_list); + + ret = acpi_dev_get_resources(int3472->adev, &resource_list, + skl_int3472_handle_gpio_resources, + int3472); + + if (!ret) { + gpiod_add_lookup_table(&int3472->gpios); + int3472->gpios_mapped = true; + } + + acpi_dev_free_resource_list(&resource_list); + + return ret; +} + +int skl_int3472_discrete_probe(struct platform_device *pdev) +{ + struct acpi_device *adev = ACPI_COMPANION(&pdev->dev); + struct int3472_device *int3472; + struct int3472_cldb cldb; + int ret = 0; + + ret = skl_int3472_get_cldb_buffer(adev, &cldb); + if (ret || cldb.control_logic_type != 1) + return -EINVAL; + + int3472 = kzalloc(sizeof(*int3472) + + ((INT3472_MAX_SENSOR_GPIOS + 1) * sizeof(struct gpiod_lookup)), + GFP_KERNEL); + if (!int3472) + return -ENOMEM; + + int3472->adev = adev; + int3472->pdev = pdev; + platform_set_drvdata(pdev, int3472); + + int3472->sensor = acpi_dev_get_next_dep_dev(adev, NULL); + if (!int3472->sensor) { + dev_err(&pdev->dev, + "This INT3472 entry seems to have no dependents.\n"); + ret = -ENODEV; + goto err_free_int3472; + } + int3472->sensor_name = i2c_acpi_dev_name(int3472->sensor); + int3472->gpios.dev_id = int3472->sensor_name; + + ret = skl_int3472_parse_crs(int3472); + if (ret) { + skl_int3472_discrete_remove(pdev); + goto err_return_ret; + } + + return 0; + +err_free_int3472: + kfree(int3472); +err_return_ret: + return ret; +} + +int skl_int3472_discrete_remove(struct platform_device *pdev) +{ + struct int3472_device *int3472; + + int3472 = platform_get_drvdata(pdev); + + if (int3472->gpios_mapped) + gpiod_remove_lookup_table(&int3472->gpios); + + if (!IS_ERR_OR_NULL(int3472->regulator.rdev)) { + gpiod_put(int3472->regulator.gpio); + regulator_unregister(int3472->regulator.rdev); + } + + if (!IS_ERR_OR_NULL(int3472->clock.clk)) { + gpiod_put(int3472->clock.gpio); + clk_unregister(int3472->clock.clk); + clkdev_drop(int3472->clock.cl); + } + + acpi_dev_put(int3472->sensor); + + kfree(int3472->sensor_name); + kfree(int3472); + + return 0; +} diff --git a/drivers/platform/x86/intel_skl_int3472_tps68470.c b/drivers/platform/x86/intel_skl_int3472_tps68470.c new file mode 100644 index 000000000000..9bda65d34987 --- /dev/null +++ b/drivers/platform/x86/intel_skl_int3472_tps68470.c @@ -0,0 +1,145 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Author: Dan Scally */ + +#include +#include +#include +#include + +#include "intel_skl_int3472_common.h" + +static const struct regmap_config tps68470_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = TPS68470_REG_MAX, +}; + +static int tps68470_chip_init(struct device *dev, struct regmap *regmap) +{ + unsigned int version; + int ret; + + /* Force software reset */ + ret = regmap_write(regmap, TPS68470_REG_RESET, TPS68470_REG_RESET_MASK); + if (ret) + return ret; + + ret = regmap_read(regmap, TPS68470_REG_REVID, &version); + if (ret) { + dev_err(dev, "Failed to read revision register: %d\n", ret); + return ret; + } + + dev_info(dev, "TPS68470 REVID: 0x%x\n", version); + + return 0; +} + +static struct platform_device * +skl_int3472_register_pdev(const char *name, struct device *parent) +{ + struct platform_device *pdev; + int ret; + + pdev = platform_device_alloc(name, PLATFORM_DEVID_NONE); + if (IS_ERR_OR_NULL(pdev)) + return ERR_PTR(-ENOMEM); + + pdev->dev.parent = parent; + pdev->driver_override = kstrndup(pdev->name, INT3472_PDEV_MAX_NAME_LEN, + GFP_KERNEL); + + ret = platform_device_add(pdev); + if (ret) { + platform_device_put(pdev); + return ERR_PTR(ret); + } + + return pdev; +} + +int skl_int3472_tps68470_probe(struct i2c_client *client) +{ + struct acpi_device *adev = ACPI_COMPANION(&client->dev); + struct platform_device *regulator_dev; + struct platform_device *opregion_dev; + struct platform_device *gpio_dev; + struct int3472_cldb cldb = { 0 }; + struct platform_device *clk_dev; + bool cldb_present = true; + struct regmap *regmap; + int ret = 0; + + regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config); + if (IS_ERR(regmap)) { + dev_err(&client->dev, "devm_regmap_init_i2c Error %ld\n", + PTR_ERR(regmap)); + return PTR_ERR(regmap); + } + + i2c_set_clientdata(client, regmap); + + ret = tps68470_chip_init(&client->dev, regmap); + if (ret < 0) { + dev_err(&client->dev, "TPS68470 Init Error %d\n", ret); + return ret; + } + + /* + * Check CLDB buffer against the PMIC's adev. If present, then we check + * the value of control_logic_type field and follow one of the + * following scenarios: + * + * 1. No CLDB - likely ACPI tables designed for ChromeOS. We + * create platform devices for the GPIOs and OpRegion drivers. + * + * 2. CLDB, with control_logic_type = 2 - probably ACPI tables + * made for Windows 2-in-1 platforms. Register pdevs for GPIO, + * Clock and Regulator drivers to bind to. + * + * 3. Any other value in control_logic_type, we should never have + * gotten to this point; crash and burn. + */ + ret = skl_int3472_get_cldb_buffer(adev, &cldb); + if (!ret && cldb.control_logic_type != 2) + return -EINVAL; + + if (ret) + cldb_present = false; + + gpio_dev = skl_int3472_register_pdev("tps68470-gpio", &client->dev); + if (IS_ERR(gpio_dev)) + return PTR_ERR(gpio_dev); + + if (cldb_present) { + clk_dev = skl_int3472_register_pdev("tps68470-clk", + &client->dev); + if (IS_ERR(clk_dev)) { + ret = PTR_ERR(clk_dev); + goto err_free_gpio; + } + + regulator_dev = skl_int3472_register_pdev("tps68470-regulator", + &client->dev); + if (IS_ERR(regulator_dev)) { + ret = PTR_ERR(regulator_dev); + goto err_free_clk; + } + } else { + opregion_dev = skl_int3472_register_pdev("tps68470_pmic_opregion", + &client->dev); + if (IS_ERR(opregion_dev)) { + ret = PTR_ERR(opregion_dev); + goto err_free_gpio; + } + } + + return 0; + +err_free_clk: + platform_device_put(clk_dev); +err_free_gpio: + platform_device_put(gpio_dev); + + return ret; +} From patchwork Mon Jan 18 00:34:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 1427918 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=VrAfmWLT; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4DJtCS0350z9sWb for ; Mon, 18 Jan 2021 11:37:08 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730675AbhARAgo (ORCPT ); Sun, 17 Jan 2021 19:36:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730626AbhARAgF (ORCPT ); Sun, 17 Jan 2021 19:36:05 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BCCCC0613D6; Sun, 17 Jan 2021 16:34:50 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id w5so14830373wrm.11; Sun, 17 Jan 2021 16:34:50 -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=I7uHwYNq+oq3Qo4LDfQKxz4Sys/YpiIugxE1gLa7uoM=; b=VrAfmWLT9ljjajymnJ+1h4KnGQfVkpnRpnmRXKy7nEcxcB7fLLYC38/g8BcOGztSPQ MHtgtiyEjFxput1wxQKPCawW5mzr2HZitqm+t/eLLND87xdOgZXAwjIzI4q37M6FeXmI 4CDMNIshj59G4heHU3rxKLMYgImi/efUrg41QKHzSgKhMLppd0f/W6/K9ED/EQb/YfP0 ZD84gHzRpnD2290+czvSIum1//E+M6g8ZWLyJZC7QSM0KqIHa+3DxpC0Vt/Ok6zxwfjk s72nLDF7zTACYRxa0jJ2aLswnZHbFPtB8C7oQe/Qqm6ZVXCwFtHUhLcqufnIdMKZ6pRF CE0Q== 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=I7uHwYNq+oq3Qo4LDfQKxz4Sys/YpiIugxE1gLa7uoM=; b=KLjalNa0jmwOjhAdJue8E1IlCc5NcPMTD2aAD03YTyTgPh0HO2b51MRTCZ9R1mIdzu 3JZi3FJnG5qMsDLoI6OyKOZK+EHjTegV+VHkZyHB+Mk0bIy9r+B/dkjbuACCip2Z0XDx FAsYNLMzqHlvBRCF23SgYfUTCQBtHBwZ41sHclisbK5AC8JwdGklSR9mgiiyb6h1swFm 1ThWDF43M9Bz/5ZK78B2WQDuP9dDCm1B/piancPQK49HbUAMuwDfiMoDOr0qNuMeTCeI CV1MBN3ewHEYNYc9bv4HC0XvhOgZKFbSQ0U7+NKHVf3/FNfyLKDEAcE01EAw9Uw7Ebli QC3Q== X-Gm-Message-State: AOAM533WFnKcoSCemk5Cdmic5rSy7FWIhnylrVdTDQEUn6u9TzxhK+xh mrakoLpxk3j/Dpi7fRBGE0H4FPk5YtUE7A== X-Google-Smtp-Source: ABdhPJyLd/H27HPqd9sv3qdz0VTNxUsAeofXHAZDj26T+BZkVnMy8WrsCi9zsX8ecrpXqDN1Q0RJcg== X-Received: by 2002:adf:fe05:: with SMTP id n5mr23756481wrr.9.1610930089201; Sun, 17 Jan 2021 16:34:49 -0800 (PST) Received: from valhalla.home ([2.29.208.120]) by smtp.gmail.com with ESMTPSA id o124sm23642040wmb.5.2021.01.17.16.34.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jan 2021 16:34:48 -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, platform-driver-x86@vger.kernel.org, devel@acpica.org Cc: rjw@rjwysocki.net, lenb@kernel.org, andy@kernel.org, mika.westerberg@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, lee.jones@linaro.org, hdegoede@redhat.com, mgross@linux.intel.com, robert.moore@intel.com, erik.kaneda@intel.com, sakari.ailus@linux.intel.com, andriy.shevchenko@linux.intel.com, laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com Subject: [PATCH v2 7/7] mfd: Remove tps68470 MFD driver Date: Mon, 18 Jan 2021 00:34:28 +0000 Message-Id: <20210118003428.568892-8-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210118003428.568892-1-djrscally@gmail.com> References: <20210118003428.568892-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This driver only covered one scenario in which ACPI devices with _HID INT3472 are found, and its functionality has been taken over by the intel-skl-int3472 module, so remove it. Signed-off-by: Daniel Scally Reviewed-by: Laurent Pinchart --- Changes in v2: - Introduced drivers/acpi/pmic/Kconfig | 1 - drivers/gpio/Kconfig | 1 - drivers/mfd/Kconfig | 18 -------- drivers/mfd/Makefile | 1 - drivers/mfd/tps68470.c | 97 --------------------------------------- 5 files changed, 118 deletions(-) delete mode 100644 drivers/mfd/tps68470.c diff --git a/drivers/acpi/pmic/Kconfig b/drivers/acpi/pmic/Kconfig index 56bbcb2ce61b..e27d8ef3a32c 100644 --- a/drivers/acpi/pmic/Kconfig +++ b/drivers/acpi/pmic/Kconfig @@ -52,7 +52,6 @@ endif # PMIC_OPREGION config TPS68470_PMIC_OPREGION bool "ACPI operation region support for TPS68470 PMIC" - depends on MFD_TPS68470 help This config adds ACPI operation region support for TI TPS68470 PMIC. TPS68470 device is an advanced power management unit that powers diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index c70f46e80a3b..07ff8f24b0d9 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1343,7 +1343,6 @@ config GPIO_TPS65912 config GPIO_TPS68470 bool "TPS68470 GPIO" - depends on MFD_TPS68470 help Select this option to enable GPIO driver for the TPS68470 chip family. diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index bdfce7b15621..9a1f648efde0 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -1520,24 +1520,6 @@ config MFD_TPS65217 This driver can also be built as a module. If so, the module will be called tps65217. -config MFD_TPS68470 - bool "TI TPS68470 Power Management / LED chips" - depends on ACPI && PCI && I2C=y - depends on I2C_DESIGNWARE_PLATFORM=y - select MFD_CORE - select REGMAP_I2C - help - If you say yes here you get support for the TPS68470 series of - Power Management / LED chips. - - These include voltage regulators, LEDs and other features - that are often used in portable devices. - - This option is a bool as it provides an ACPI operation - region, which must be available before any of the devices - using this are probed. This option also configures the - designware-i2c driver to be built-in, for the same reason. - config MFD_TI_LP873X tristate "TI LP873X Power Management IC" depends on I2C diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 14fdb188af02..5994e812f479 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -105,7 +105,6 @@ obj-$(CONFIG_MFD_TPS65910) += tps65910.o obj-$(CONFIG_MFD_TPS65912) += tps65912-core.o obj-$(CONFIG_MFD_TPS65912_I2C) += tps65912-i2c.o obj-$(CONFIG_MFD_TPS65912_SPI) += tps65912-spi.o -obj-$(CONFIG_MFD_TPS68470) += tps68470.o obj-$(CONFIG_MFD_TPS80031) += tps80031.o obj-$(CONFIG_MENELAUS) += menelaus.o diff --git a/drivers/mfd/tps68470.c b/drivers/mfd/tps68470.c deleted file mode 100644 index 4a4df4ffd18c..000000000000 --- a/drivers/mfd/tps68470.c +++ /dev/null @@ -1,97 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * TPS68470 chip Parent driver - * - * Copyright (C) 2017 Intel Corporation - * - * Authors: - * Rajmohan Mani - * Tianshu Qiu - * Jian Xu Zheng - * Yuning Pu - */ - -#include -#include -#include -#include -#include -#include -#include - -static const struct mfd_cell tps68470s[] = { - { .name = "tps68470-gpio" }, - { .name = "tps68470_pmic_opregion" }, -}; - -static const struct regmap_config tps68470_regmap_config = { - .reg_bits = 8, - .val_bits = 8, - .max_register = TPS68470_REG_MAX, -}; - -static int tps68470_chip_init(struct device *dev, struct regmap *regmap) -{ - unsigned int version; - int ret; - - /* Force software reset */ - ret = regmap_write(regmap, TPS68470_REG_RESET, TPS68470_REG_RESET_MASK); - if (ret) - return ret; - - ret = regmap_read(regmap, TPS68470_REG_REVID, &version); - if (ret) { - dev_err(dev, "Failed to read revision register: %d\n", ret); - return ret; - } - - dev_info(dev, "TPS68470 REVID: 0x%x\n", version); - - return 0; -} - -static int tps68470_probe(struct i2c_client *client) -{ - struct device *dev = &client->dev; - struct regmap *regmap; - int ret; - - regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config); - if (IS_ERR(regmap)) { - dev_err(dev, "devm_regmap_init_i2c Error %ld\n", - PTR_ERR(regmap)); - return PTR_ERR(regmap); - } - - i2c_set_clientdata(client, regmap); - - ret = tps68470_chip_init(dev, regmap); - if (ret < 0) { - dev_err(dev, "TPS68470 Init Error %d\n", ret); - return ret; - } - - ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, tps68470s, - ARRAY_SIZE(tps68470s), NULL, 0, NULL); - if (ret < 0) { - dev_err(dev, "devm_mfd_add_devices failed: %d\n", ret); - return ret; - } - - return 0; -} - -static const struct acpi_device_id tps68470_acpi_ids[] = { - {"INT3472"}, - {}, -}; - -static struct i2c_driver tps68470_driver = { - .driver = { - .name = "tps68470", - .acpi_match_table = tps68470_acpi_ids, - }, - .probe_new = tps68470_probe, -}; -builtin_i2c_driver(tps68470_driver);