Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3126122ybi; Thu, 18 Jul 2019 21:32:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1dDGORQBCt2m/zQ57fx5LAQEiwvRekGVelugmB+KKbjNZoZavZT2tHXv62Z87gbMgr4Zy X-Received: by 2002:a63:6110:: with SMTP id v16mr6228800pgb.81.1563510746474; Thu, 18 Jul 2019 21:32:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563510746; cv=none; d=google.com; s=arc-20160816; b=NbO6K4N7KjuQoAtmWnz+hQpBI5MGVR3exR51acVquejoBlFpc7UF2U7ocm5zuMlnii Q3rCVEpXQoJXSJFZX0jvA6kyS6Ysbi4pnTWNsVpx+BKEPBMCgYyiV6ITxxcofWHMTFya GC/wjQQuFrVTpFaiQuR3xinygTrH0MJSBF5kbVuwYsgsjA2MZc4ckBLSDmoujlfBCKXG ab7vcjQ1sWg/FaPHDSXTYULt2avd2UJ/iRylgBJpxHC5S7Mcew1mMhSAZR6BIbmoa9K4 IqCV8ZNffxO0GA7seTycbCJCDTIokKFgi4JFRI1JQc0QrbWv1j2TjnQ9Scjk712f99BK vKvg== 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=WXF1aa0LtGfZE3e4K2hih0gyM7dedjFVbDxdmNjkgkh0/QXnw5D2HGfJuFhOC1YxhA q2Vrddf7iA7tyL+EvXwxDLkVGoMxvMcIEVnCNoMB12hrYVbMebm5k0P2wnG1zu317mvK J0UuPUWht+0c6rns1UlcdBp9FjF1LVZGfL3J+CHOTFlg4qScvJ+a9kB2uWMgFODMCZk1 96NMmyMmDVtQog9vGWlOxAEthYe517faXkUjwW4tsbMS0MLVukHhWWa+gMBJjpra/bKW T5M4eoiykqtOpn4PxzYZdNH+q6ZCqqTdMoVE9HuduqD5QPLiRM8nctit87/38djDPIBX 0IQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B6ytaXsI; 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 o131si197735pgo.445.2019.07.18.21.32.11; Thu, 18 Jul 2019 21:32:26 -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=B6ytaXsI; 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 S1731204AbfGSEbJ (ORCPT + 99 others); Fri, 19 Jul 2019 00:31:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:37006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729532AbfGSEEp (ORCPT ); Fri, 19 Jul 2019 00:04:45 -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 14A8C218BC; Fri, 19 Jul 2019 04:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563509084; bh=ZQ3WWzSDhz3Qb1WmYN7C9YZY6kD2OJayrXx0bEgbiUo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B6ytaXsI76boPRA0oQsDjznJEuqoFkTLXojdg6Fb7tAGqmhZ36M0tfhFvEQl2XeAf TGdJjBQHA2jtuPKGp7NgP723JN+OwUkGdE21xcq1/5rJXPagJYygKMjQtL6cjtyh6b P5VYV3RHS8W3AA90gf01M2fVcaluvUanKH/gRSp0= 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.1 060/141] serial: mctrl_gpio: Check if GPIO property exisits before requesting it Date: Fri, 19 Jul 2019 00:01:25 -0400 Message-Id: <20190719040246.15945-60-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719040246.15945-1-sashal@kernel.org> References: <20190719040246.15945-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