Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp976357imu; Sat, 17 Nov 2018 13:25:23 -0800 (PST) X-Google-Smtp-Source: AJdET5e0TanZblKtZjNPypmol9vkWdi0f1Vm48ySrUzm4BSXlBQmLvvgW/QORhKQHdxD//polIPO X-Received: by 2002:a17:902:f20b:: with SMTP id gn11mr15617397plb.93.1542489923571; Sat, 17 Nov 2018 13:25:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542489923; cv=none; d=google.com; s=arc-20160816; b=R/bdBcPy/d2PSGbAIYqLXCz5UnwohnnUYn/qKsRwfnt6HHr0/Fknl1vb0j2JRqvejP EsfPGPPGgwiAS1v+gqutgI7dhfTFbgF/4xb1NjIeLo+UpOEdh1P6Eha2ay24a/XxR8Mu DEP+ga+lxEXfsFTiMi8gaAKbIIjHgB4XE8S9/U0shCBnQGtiuwtcx3T7FU3v0gxkwvDN UFIB18NmnRWaaNxM0dbS5fq6/53zcm+C2zvqcWzWNiazVKCB2+f7cob+SqiYo70cKlXf OQ4B2lhmz+/+x4moZ8uCyysgaFAoM6xzh2k2fyadJ5rpmDw5jRpnNe8jg1w9bRx0DJi4 4r8Q== 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 :content-language:mime-version:user-agent:date:message-id:to:cc :autocrypt:openpgp:subject:from; bh=YemNlyYgryIpaqXChanPU2Ydo12JpkjGNqhk+s6aG4c=; b=Fc8N04hq3nrYhfqmzaY+zIgBh5M5fewsBF6WtlvsxABy55PDUJudj8FvfQYoNSJLpP QU/2YnivWZoPvLqCHJfffQxVYUxLRkKStpt1Kk3dPmWeHAeAAfirIIkjWWBpLXN1hDym NcSCz1LCEF+e3pwdNiOg7gbVNtg5lVbL1Kow6YRfOtkuFbasyC1gwh14BXo9Dt2Oz/qg xGwVMFd0RaC1YnpqPOhZX7G0kmqIu2jCMVNdjg3AXdLwBbFl1adPX3rNgfGQq/w6mkHa M6bOkQ1/wpQklr9XpdQ+lEtnm1wi1k3wtVMwVaKYZJ0Wcgv62ex039to7i/7RC15yOz9 hF9w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h5si33241799pgc.237.2018.11.17.13.25.07; Sat, 17 Nov 2018 13:25:23 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726932AbeKRHm0 (ORCPT + 99 others); Sun, 18 Nov 2018 02:42:26 -0500 Received: from mxf98a.netcup.net ([46.38.249.138]:50062 "EHLO mxf98a.netcup.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726034AbeKRHmZ (ORCPT ); Sun, 18 Nov 2018 02:42:25 -0500 X-Greylist: delayed 519 seconds by postgrey-1.27 at vger.kernel.org; Sun, 18 Nov 2018 02:42:23 EST Received: from [192.168.178.21] (unknown [5.63.45.188]) by mxf98a.netcup.net (Postfix) with ESMTPSA id AD71B14116E; Sat, 17 Nov 2018 22:15:44 +0100 (CET) Authentication-Results: mxf98a; spf=pass (sender IP is 5.63.45.188) smtp.mailfrom=rabel@robertabel.eu smtp.helo=[192.168.178.21] Received-SPF: pass (mxf98a: connection is authenticated) From: Robert Abel Subject: [of] deadlock b/c of gpiochip and pinctrl dependency Openpgp: preference=signencrypt Autocrypt: addr=rabel@robertabel.eu; prefer-encrypt=mutual; keydata= xsBNBFuld24BCACo/2iGEWd0080a1Kq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M35QwkGkubB1onn9mRBB2Dr/2sr73htU8cRQCQ6kZPILuV3nHMmlUr XaEdHyvufv1YEAWQdg08+Pig1ZK57zlGO4WwWUAUuT/9iQm1qzMLP2683OoWbCihbjtYGskA EQEAAcLAfAQYAQgAJhYhBAPU/UOSMYeSZeDf9jncurJ4JrbIBQJbpXduAhsMBQkDwmcAAAoJ EDncurJ4JrbI/boH/2AzoE6EfGEwkMHMTjH5lmarhDTkg9EQNwi3orH2836RYPlO1geOrItm rM9b/lX5OXrE/K24lvxviVV8EaMN9EhEuCyoo6tnv+pUni3U2qWu3WUfAIMtkKlZspa4sO4Z slCvBwZtNTb2Al6Rs/knPXnV8mcQ/gMnd99feaIRL7FvsDvlCqIh+B0785igWYQ9VsGUuDXr Dmhm/j1LMoAQS4+31+lARM4sX7pdBnlSp0OGHj7vzTMirAjGAAr/Kh7BgcfRtin7n9rAMenu 9h1RQsQoayamC18CP2SQIZHbbiquUttmrvj7tkJAI2Y7bWqgfmBHHhNsVslYkpd4wYV62uc= Cc: Linus Walleij , linux-kernel To: "linux-gpio@vger.kernel.org" Message-ID: <6409e5aa-4129-0706-2704-f5f609bb54a8@robertabel.eu> Date: Sat, 17 Nov 2018 22:15:43 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-PPP-Message-ID: <20181117211544.23253.72671@mxf98a.netcup.net> X-PPP-Vhost: robertabel.eu Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi! I found a dependency issue with gpiochip and pinctrl while using the gpio-hog feature that was implemented by Benoit Parrot in f625d4601759f. Relevant device-tree overlay shown below [3]. I ran into a deadlock situation, because adding a gpiochip requires a registered pinctrl with registered ranges, because the function to add the gpiochip will check for hogged pins and request gpio pin functionality for them. This works in situations when gpiochip and pinctrl functionality don't depend on each other. However, consider the following code, which is from the bcm2835 driver for Raspberry Pi found here [1]: pinctrl-bcm2835.c: err = gpiochip_add_data(&pc->gpio_chip, pc); if (err) { dev_err(dev, "could not add GPIO chip n"); return err; } ... pc->pctl_dev = devm_pinctrl_register(dev, &bcm2835_pinctrl_desc, pc); if (IS_ERR(pc->pctl_dev)) { gpiochip_remove(&pc->gpio_chip); return PTR_ERR(pc->pctl_dev); } ... pinctrl_add_gpio_range(pc->pctl_dev, &pc->gpio_range); It's not very obvious, that calling gpiochip_add_data should only be done after adding the required ranges to pinctrl, because the following happens: gpiochip_add_data(_with_key): of_gpiochip_add: of_gpiochip_scan_gpios: for_each_available_child_of_node(chip->of_node, np) with "gpio-hog": gpiod_hog gpiochip_request_own_desc: gpiod_request_commit: status = chip->request(chip, gpio_chip_hwgpio(desc)): gpiochip_generic_request(...): pinctrl_gpio_request: pinctrl_get_device_gpio_range: /* GPIO range not found, because it wasn't registered yet */ return -EPROBE_DEFER; This of course deadlocks my system, because everything ends up waiting on the gpiochip, which cannot ever be instantiated. I couldn't find any documentation explicitly mentioning this dependency between gpiochip and pinctrl. My workaround for the moment is to re-order the gpiochip_add_data call after the devm_pinctrl_register and pinctrl_add_gpio_range calls. I haven't observed any ill effect, but I'm not sure what other components may already act on pinctrl while gpiochip is dangling or if any of the other functions that are called by add require it as well. Obviously, this approach won't work for SoCs where setting certain pinctrl settings need to touch gpio settings to e.g. activate pull-ups. In general, I sought the same functionality that Markus Pargmann was trying to implement in 2015 [2]. That is, to name and possibly export gpios through device tree. It seems disadvantageous that one cannot currently specify pinctrl settings while hogging or export by name. Dynamic device tree overlays also don't work. Perhaps an actual driver instead of the hogging mechanism would solve all dependency issues better? Regards, Robert Please CC, as I'm off-list. [1]: https://github.com/raspberrypi/linux/blob/83ea2e93/drivers/pinctrl/bcm/pinctrl-bcm2835.c#L1027 [2]: http://lists.infradead.org/pipermail/linux-arm-kernel/2015-July/357418.html [3]: gpio-hog.dtso /dts-v1/; /plugin/; #include / { compatible = "brcm,bcm2708"; fragment@0 { target = <&gpio>; __overlay__ { myLed { gpios = <18 GPIO_ACTIVE_HIGH>; gpio-hog; output-low; }; }; }; };