Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3119048ybi; Thu, 18 Jul 2019 21:23:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+L9oiwkFKSHqN0kM5TvusHqdYG/PMFE95ryViEhgXpp5DHz9scMQPBG6TZSM7oiLBKjGQ X-Received: by 2002:a63:c1c:: with SMTP id b28mr19600623pgl.354.1563510223248; Thu, 18 Jul 2019 21:23:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563510223; cv=none; d=google.com; s=arc-20160816; b=W5QfrflNMqXP2tUOZ49yxGSLJ/nEE7UJHOh6rPF3Fwg/lEjAVgkf+BAv9Dy8+v62fC 1l6xa7GiCYuybtTmhyh+HVsvSujw7Cn6ifoDqiOpJ/SuskIsphWU5V9b63YRcc3aYjD6 Z59KopyOr/otqyiuG6EmPTQ3lv1UMb6z1OcgAX4HOhnWIzeCF96R/gkHh8TV5fD5ku6g CLjIamCadyQ6Vnjy0CK0IOk6QD8NAcAeeTUs8OBiuDG8vFfE72zd0pKeyJAT5EJndqGs TXjojuOWETxVR34/SAuinA/dC+OfmusaDkFnob354tM9n62MvBPV6JVl5XrDupFwYlFJ HN1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Wf5aOXfJ5eaEjOYQuU+7mFLPkKgWPWx27MGIJa4VIRc=; b=JibauYYtbA737eVZzfpdebkCrOUlYairvWEO88Ia5RbFiHcijW849j01TjXUe+QopU TWXHX/40X1yP4WFN5ObPsULkDKCWBfVXL4nY+F/cZAbCd/Dv5xGiS3xNiXn3XK7aGjA9 vIdS6jKRjvG2N09rshr0ZU4ZaXvnWmqfkRO6+6I9qNkj8NenmrICzegsOFnDHUnVdwr1 m/bfrUVhkvrT/b+jaaCgXe/b23ROpsYm70Qn7BDR+hqf71CEZEzU8ae9OP9OmFduHMAv vxEabqx2S51uDOb0KfxaHRF6csxusvcvZJmgDpkU/pS5z2pE9rBU9FYm4aQKV7DNhTtD pTSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Vl/kFkia"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f61si1461788plf.258.2019.07.18.21.23.28; Thu, 18 Jul 2019 21:23:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Vl/kFkia"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387907AbfGSEV3 (ORCPT + 99 others); Fri, 19 Jul 2019 00:21:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:47050 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733229AbfGSEL4 (ORCPT ); Fri, 19 Jul 2019 00:11:56 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 72A6B218B6; Fri, 19 Jul 2019 04:11:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563509515; bh=/DdxJL1LLAB2tS480dyuM+iB+a8uE32uVTEz/woicc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vl/kFkiaTSF0Rzru/a7ZAMHCIpT+ImNeuGSv5WCFRghWDY6IpSp76IaMXTiDnl4/S L73eLmrpYWp91p3S6ukq8St1uapqkdnHFF3UjPtygkyjTSeqn22ef44GkhlMLI/yxO 3mIkH7qqYNS5NpAF2kCAZCsC9CfUti1rFEHHb1VQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Stefan Roese , Mika Westerberg , Andy Shevchenko , Yegor Yefremov , Greg Kroah-Hartman , Giulio Benetti , Sasha Levin , linux-serial@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 25/60] serial: mctrl_gpio: Check if GPIO property exisits before requesting it Date: Fri, 19 Jul 2019 00:10:34 -0400 Message-Id: <20190719041109.18262-25-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719041109.18262-1-sashal@kernel.org> References: <20190719041109.18262-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stefan Roese [ Upstream commit d99482673f950817b30caf3fcdfb31179b050ce1 ] This patch adds a check for the GPIOs property existence, before the GPIO is requested. This fixes an issue seen when the 8250 mctrl_gpio support is added (2nd patch in this patch series) on x86 platforms using ACPI. Here Mika's comments from 2016-08-09: " I noticed that with v4.8-rc1 serial console of some of our Broxton systems does not work properly anymore. I'm able to see output but input does not work. I bisected it down to commit 4ef03d328769eddbfeca1f1c958fdb181a69c341 ("tty/serial/8250: use mctrl_gpio helpers"). The reason why it fails is that in ACPI we do not have names for GPIOs (except when _DSD is used) so we use the "idx" to index into _CRS GPIO resources. Now mctrl_gpio_init_noauto() goes through a list of GPIOs calling devm_gpiod_get_index_optional() passing "idx" of 0 for each. The UART device in Broxton has following (simplified) ACPI description: Device (URT4) { ... Name (_CRS, ResourceTemplate () { GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly, "\\_SB.GPO0", 0x00, ResourceConsumer) { 0x003A } GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly, "\\_SB.GPO0", 0x00, ResourceConsumer) { 0x003D } }) In this case it finds the first GPIO (0x003A which happens to be RX pin for that UART), turns it into GPIO which then breaks input for the UART device. This also breaks systems with bluetooth connected to UART (those typically have some GPIOs in their _CRS). Any ideas how to fix this? We cannot just drop the _CRS index lookup fallback because that would break many existing machines out there so maybe we can limit this to only DT enabled machines. Or alternatively probe if the property first exists before trying to acquire the GPIOs (using device_property_present()). " This patch implements the fix suggested by Mika in his statement above. Signed-off-by: Stefan Roese Reviewed-by: Mika Westerberg Reviewed-by: Andy Shevchenko Tested-by: Yegor Yefremov Cc: Mika Westerberg Cc: Andy Shevchenko Cc: Yegor Yefremov Cc: Greg Kroah-Hartman Cc: Giulio Benetti Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/serial_mctrl_gpio.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c index d2da6aa7f27d..42e42e3e7a6e 100644 --- a/drivers/tty/serial/serial_mctrl_gpio.c +++ b/drivers/tty/serial/serial_mctrl_gpio.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "serial_mctrl_gpio.h" @@ -124,6 +125,19 @@ struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx) for (i = 0; i < UART_GPIO_MAX; i++) { enum gpiod_flags flags; + char *gpio_str; + bool present; + + /* Check if GPIO property exists and continue if not */ + gpio_str = kasprintf(GFP_KERNEL, "%s-gpios", + mctrl_gpios_desc[i].name); + if (!gpio_str) + continue; + + present = device_property_present(dev, gpio_str); + kfree(gpio_str); + if (!present) + continue; if (mctrl_gpios_desc[i].dir_out) flags = GPIOD_OUT_LOW; -- 2.20.1