From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6337DC433EF for ; Sat, 2 Apr 2022 09:11:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244053AbiDBJNd (ORCPT ); Sat, 2 Apr 2022 05:13:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234483AbiDBJNc (ORCPT ); Sat, 2 Apr 2022 05:13:32 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D871C31374 for ; Sat, 2 Apr 2022 02:11:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648890697; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hdYYYw2Bwu1tlZ9upbRt1lVqbBiz/tTX6P5x7gBMpWQ=; b=WfMcN35w/Zru/kdAQpU671ZMEDmPi0CICzVj2FVaH2Esh6zKJCB+rsj0uTzPqzyKDDokfW 5kurk6Apk1eHuJCMTWjW5I/psvJa/c59T/LdOpM4rh7wwzl6pS7AUhNuYI1ZdbWsmaMXeb w7ILTPSMmq1RSegqnSTG33/3Pe+8JbY= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636--nzufWuZMZacQg3tGM-dIQ-1; Sat, 02 Apr 2022 05:11:35 -0400 X-MC-Unique: -nzufWuZMZacQg3tGM-dIQ-1 Received: by mail-ej1-f69.google.com with SMTP id gn11-20020a1709070d0b00b006e6e59438f8so214943ejc.1 for ; Sat, 02 Apr 2022 02:11:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=hdYYYw2Bwu1tlZ9upbRt1lVqbBiz/tTX6P5x7gBMpWQ=; b=gDtdxWfJBOuByOvYsUeHRf90cysPFibHqLZqHlbH4pAg17//MfP6w2OP383B8VXxBF +eBxb3tV+GY/1vW/NjuURKrjIJorwjPaCmvTsUSKX/axfD2JXDLilixw9gw60Ruied3R CATHO7NQ8+yelacEShSlyj9XnkoDosVZggT3SaKTug0F90pldbuEb7m6ZRWNnX1XjZpn 2d5JToCE8A399S/vNuWg96Z0vgy9qRtYI3MtG4TtwlQqsxblhblAiVVakAY1/ZIiDSq9 LIBhi5OWr2WzMWTg7Y5ktkF/MnEEhUBaSucaZ4MLo4vqMJc0tY22N+Hfhd74IvK5ofwA C3Aw== X-Gm-Message-State: AOAM533vMT1oPqbUE/6hb0G9RhUaXOJ+nWDfnYEUSgSTo7XTcWgLlqHY Sw7PSmp1JyaZR1FlU6C6QKwwFC3RK3qS68s9iBiTBHtekc9ohYRl1nidVRMyzeJrOfiiniyeswe F4rni2Btj24iE++TXBuXdnQ== X-Received: by 2002:a50:9f64:0:b0:410:801c:4e2f with SMTP id b91-20020a509f64000000b00410801c4e2fmr24251355edf.179.1648890694008; Sat, 02 Apr 2022 02:11:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwa1+qSoqVTsU6yGwkBllkrc+DliBYdxIM3SN+mqODcuGAzBGk/8IRHLejoEZ6DF8H4uXJBJA== X-Received: by 2002:a50:9f64:0:b0:410:801c:4e2f with SMTP id b91-20020a509f64000000b00410801c4e2fmr24251342edf.179.1648890693652; Sat, 02 Apr 2022 02:11:33 -0700 (PDT) Received: from ?IPV6:2001:1c00:c1e:bf00:1db8:22d3:1bc9:8ca1? (2001-1c00-0c1e-bf00-1db8-22d3-1bc9-8ca1.cable.dynamic.v6.ziggo.nl. [2001:1c00:c1e:bf00:1db8:22d3:1bc9:8ca1]) by smtp.gmail.com with ESMTPSA id v10-20020a170906380a00b006a68610908asm1895616ejc.24.2022.04.02.02.11.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Apr 2022 02:11:33 -0700 (PDT) Message-ID: <90f7d9eb-935b-3803-1531-65bd20418bc3@redhat.com> Date: Sat, 2 Apr 2022 11:11:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: gpiolib: why does gpio_set_bias() suppress ENOTSUPP? Content-Language: en-US To: Kent Gibson Cc: Andy Shevchenko , linux-gpio@vger.kernel.org, brgl@bgdev.pl, thomas.petazzoni@bootlin.com, linus.walleij@linaro.org References: <20220331025203.GA53907@sol> <20220331141524.GA93836@sol> <49e5857d-1438-cd5d-b4f2-b374f01e2596@redhat.com> <20220402014510.GA7939@sol> From: Hans de Goede In-Reply-To: <20220402014510.GA7939@sol> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Hi, On 4/2/22 03:45, Kent Gibson wrote: > On Fri, Apr 01, 2022 at 12:36:57PM +0200, Hans de Goede wrote: >> Hi Kent, >> >> On 3/31/22 16:15, Kent Gibson wrote: >>> On Thu, Mar 31, 2022 at 04:53:23PM +0300, Andy Shevchenko wrote: >>>> On Thu, Mar 31, 2022 at 10:52:03AM +0800, Kent Gibson wrote: >>>>> Hi all, >>>> >>>> +Cc: Hans >>>> >>>>> It has recently come to my attention that the setting of bias by the >>>>> cdev uAPI is a best effort operation that quietly succeeds if bias is >>>>> not supported by the hardware. That strikes me as being a bug. >>>>> It seems I was aware of this when adding bias to the uAPI and intended >>>>> to fix it, as shown in the comments of v4 of the corrsponding patch >>>>> series[1]: >>>> >>>>>>> The setting of bias is performed by gpio_set_bias, which is hooked into >>>>>>> gpiod_direction_input and gpiod_direction_output. It extends the setting >>>>>>> of bias that was already present in gpiod_direction_input. >>>>>>> In keeping with the existing behaviour, the bias is set on a best-effort >>>>>>> basis - no error is returned to the user if an error is returned by the >>>>>>> pinctrl driver. Returning an error makes sense to me, particularly for >>>>>>> the uAPI, but that conflicts with the existing gpiod_direction_input >>>>>>> behaviour. So leave as best-effort, change gpiod_direction_input >>>>>>> behaviour, or restructure to support both behaviours? >>>>> >>>>>> Thomas: is there any reason not to check the return value of these >>>>>> calls for errors other than -EOPNOTSUPP? >>>>> >>>>> that being my comment, and Bart's followup question to Thomas. >>>>> >>>>> That went unanswered AFAICT and the issue subsequently fell through the >>>>> cracks. >>>> >>>> My understanding that all constraints we have in kernel is due to >>>> in-kernel use and possible (non-critical) issues. >>>> >>>> For example, driver can set only selected values of bias. What to do when >>>> the given value is not supported by hardware? >>>> >>>> Followup question: Why do you think your choice is any better than another >>>> one? >>>> >>> >>> I'm probably missing your point here. >>> >>> What makes gpiolib best placed to decide that bias not being supported >>> by hardware is non-critical? Why not just propagate the ENOTSUPP to the >>> caller and let them decide? >>> >>> Is it because setting bias is piggy-backed onto >>> gpiod_direction_input() rather than being separate, so then you can't >>> tell whether it is input or bias that is not supported? >> >> Right, gpiod_direction_input() check if there is a bias described for >> the pin in the firmware description of the pin (devicetree or ACPI) and >> those might contain a bias setting even if the pinctrl/gpio chip is not >> capable of it (and instead it is actually e.g. applied by external >> resistors on the PCB). >> > > So the pin description may extend beyond the gpio chip itself, and > describe part of the external circuit? It is not necessary / really supposed to, but copy and paste from previous platforms may lead to this. Also something like the active low/high bit of the pin description may take the presence of an external (inverting) buffer/level-convertor into account. So yes it is somewhat tied to the external circuit too. Because it e.g. also tells the kernel if the pin should be driven electrically low/high to make it logically high which may depend on external circuitry. > Ok, hadn't considered that a possibility. > >> The idea behind this is to make things just work for most >> drivers using/consuming GPIOS without the drivers needing to know >> about the firmware description details. >> >> To make sure this actually just works and does not cause drivers >> to see unexpected (and usually not a problem) errors the ENOTSUPP >> error from the set bias call is not propagated from >> gpiod_direction_input(). >> > > Ok, just to make sure I have this straight: > > The drivers get their pin description from devicetree or ACPI and > then apply it using gpiod_direction_input() or gpiod_direction_output(), > as appropriate. Yes, but note that it is not the drivers which interpret the firmware data, this is all done in the core code. A driver basically says give me my