Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3100065ybi; Thu, 18 Jul 2019 21:02:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+s+a572fiaIhLOs2FV31Wa0j2nIMyQqq8GuLI/kYsA0Sc6dFPYX8yt9zzAAhZXQnYXeue X-Received: by 2002:a17:90a:1a45:: with SMTP id 5mr56324980pjl.43.1563508929081; Thu, 18 Jul 2019 21:02:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563508929; cv=none; d=google.com; s=arc-20160816; b=hEH9CsbPaeMpgH714sHPlHKTmVLw7SQaEc3/x+mJT8sed24HBV93+OLj0dbyGWcFpP QWz79OT+lufZY666JnVde3ergrasebPbM3zjT1D/tYa7tulLf4w0g4Vqus+RjticBFoc ajnlwewA6ZXsMXihMquzaB4H6Hs0PMrOFfRHzbA3Rmukqz5kNP07bqOToCFjFd3pcyIR 7EkNzitqbucH6BkgLiR2DZSNM+UJoaS74kwgArqSk6Ke9Ypkoyq8VdjGsh4dYe3m0Tlm /i/wNoef1T5FNOKbe/yk3kYATbawUY4NhTXc97VKB40ccvcAK7C0r7xkbHSW5It1JHS+ Xk3A== 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=IBL0JCQfZJil17le8G3quPndDT3dDfxM57CyYhgjhOQ=; b=XJyHi3pw5ZUgFS+lwEu785uIY6VMiJvVUR8jnTVZpdLZiB6kIO/+/o/dS0WCf6B9PL IvysrvC7x9Jq8n8ELHfb38XUPLR/sN1suODCZCnlcoYu+mhP3WsVOrwnGNAvkGAa7o1P /PGKnMTarnSf3twgiWjKqu7s5SWDYISAH1xKMThe7odtpzZrZvffOY/5pSk4ezoeHuuH +hlJmdUX9rfYZk+6OxZ5X9KjaOE45WJRc95hIqwKhkGfPN0gl6YOa1Br1AFcyrg4jAJW hFuuEMIq+ELJvzPNADhQXobOIFL2tXydMtVY3ZSY4Rv87UZImO/uZF76X9QBwG+0l7us mMSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yfB1GatY; 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 d7si90823plr.18.2019.07.18.21.01.54; Thu, 18 Jul 2019 21:02:09 -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=yfB1GatY; 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 S1728767AbfGSD7d (ORCPT + 99 others); Thu, 18 Jul 2019 23:59:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:59074 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728729AbfGSD73 (ORCPT ); Thu, 18 Jul 2019 23:59:29 -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 2F8E421873; Fri, 19 Jul 2019 03:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508768; bh=ZQ3WWzSDhz3Qb1WmYN7C9YZY6kD2OJayrXx0bEgbiUo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yfB1GatYlURKFt5r51m31XsyTry31v2XrT1qCC/h5Rxtp4ZYcWuZR70DDht2CU766 LS9783YYRl9njmzaTqtShLqTL8xIj9e9c+0Uc1c+UkoLYp0lfve5t+GD6mFGI+Q6WG OesBbx+1ew8HeGfrdLqe3WV8IEBMjvt+0HqdpH64= 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 5.2 079/171] serial: mctrl_gpio: Check if GPIO property exisits before requesting it Date: Thu, 18 Jul 2019 23:55:10 -0400 Message-Id: <20190719035643.14300-79-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-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 39ed56214cd3..2b400189be91 100644 --- a/drivers/tty/serial/serial_mctrl_gpio.c +++ b/drivers/tty/serial/serial_mctrl_gpio.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "serial_mctrl_gpio.h" @@ -116,6 +117,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