Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp889508imm; Wed, 19 Sep 2018 08:29:34 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbcdIWI0g3rsnFeHxFzpe9zZNFeB+gpryMTcGOtiYY2xNWwkc1A9Mdh5pARFjJwoGM+v0Go X-Received: by 2002:a62:1b41:: with SMTP id b62-v6mr12922246pfb.172.1537370974264; Wed, 19 Sep 2018 08:29:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537370974; cv=none; d=google.com; s=arc-20160816; b=gbTpgVkIEwYaeaj4mPg4M9lIXlo4T7I8UesrUX6cuL4CUr7y7o9P1NJvRSKEB4PZw6 RfaTJCksRqCpJt/KU+8pNSxWkoMFBq9Vrmkwv1zrjBRA3aArSK4CNkCvKBhD0J0eH3ow lYibCVjJqGp6J0/wH+nm7BxVjNMHKRkfdq3qXoquvVprcQMqn/iowavGgFcF9n6VOcoX a4mN8CTACGdKuXCBsSsKmzO/uYEGPZzK+kBwTB0/Lf0Xe84I8beQmBN/1PVyoSw5DDck 8jphDpKypjniSabkVnbHll/FNI2ZiDeQ3vpyzfLG8aem69Mp5gloHORcM3eXvg4dm5oM n0Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=rYtbsgXM6faHoFVqp/DjvrR0gMlEmUGq2FFKHj3xnp0=; b=DUNg4ThWocQmWI8JJkBFmPD47M8zQMFvAI3WsZ6AZ4747DEmlU9L4b3PR4BXrVug4R xYSCv2UurbGM9OmRnJz3/58BigAc40bpN6JREK8Dy0RSU8znwB9gJxLUDPm/XSeex/uB ziWzxwYtqKzjCli/CVX//hvv2uztS8QDppPuytWCF1k2JFngpuu/m7ixz+7FmEB0c8CY HjJseqfTRkNj4ls3F1fkoBiBJ6TAbGwn396roubNGkzLc/8sYLD2vKtchjOlCOVsxyoN S5Fy6F67RFp/A60QKdthNAR3EwxL6e/PiR1lNdD3Q+Nhg9k2OJMp/VLAT0hYko2VjwZe NwFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YXtrluCn; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f16-v6si22825545pff.13.2018.09.19.08.29.18; Wed, 19 Sep 2018 08:29:34 -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=@gmail.com header.s=20161025 header.b=YXtrluCn; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732525AbeISVGM (ORCPT + 99 others); Wed, 19 Sep 2018 17:06:12 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:46113 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731661AbeISVGM (ORCPT ); Wed, 19 Sep 2018 17:06:12 -0400 Received: by mail-lj1-f195.google.com with SMTP id 203-v6so5431837ljj.13; Wed, 19 Sep 2018 08:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rYtbsgXM6faHoFVqp/DjvrR0gMlEmUGq2FFKHj3xnp0=; b=YXtrluCn27KB2tSF8+bhBVcnMsJKFT7AhjP3WWD3H+uRzrqXmuBCwIeGNYGhUBLRjU yyhXCwp+qIi64iPNCmMhw7PpjkZgb1CCViqgW6jZv/fsqXOyVqWBcnh8O6p/2SC/Yf+g Y4BQ8Vfz/pnH1gq+divxOXKWrxIWA3WPwUVGWcBGB4f5N8CCMG7TXBf4bSLr8iRhMB+R UmIJdHlz5Ug/xrPnHkAh2AaguekPP4pOFg85uDABmPxlhBEd4srD4gqmxeDpXDUgFAWO wNBBqfQmXHNDCNKwOGuCwV4ImY9swL166cbZHHyVitRxSCyjxQCuMkcQmUTGta9BciH1 0IBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rYtbsgXM6faHoFVqp/DjvrR0gMlEmUGq2FFKHj3xnp0=; b=Fmtnncz8M847ZhuxaN1UPjZ5gM2iovpNlQ7fsAMxeydn1rIoSE+d/05+j7ewSuGnyK VXLtM82e6fcvUkP/M8awV52XKQAZ+AMUJrBHdSMSNBSAt5Y/+KyRg3gwpAU4b+/gwBg4 8SrgnFtXlg+4eG3j5hy8s1mdmrD3xV8s/mD9A6Mqc3oledjAPIZVcZnjOdznva0K1Ch3 X7WrrLig7t8Z5Vm1DurAdjppTYXR/EE2TZ6kNfBkunTHzqebqlaFsRqJpGT0dGVL43Cd vxsSMuIXc0idWZ7nFf6qGA8CJsMu8+nmSVUdtYxpaGzWTs6ABVQvBtODcRo6am6WqKgV oeVg== X-Gm-Message-State: APzg51CLxMsr444pZ0P/TS1ImRUJNPpevZZFTxLwETDurpmNdBY4aoli CTv55FpfM0DAHBn4/a1jq3E52pkHh7lEB7g3knQ= X-Received: by 2002:a2e:2025:: with SMTP id g37-v6mr6538057ljg.40.1537370863756; Wed, 19 Sep 2018 08:27:43 -0700 (PDT) MIME-Version: 1.0 References: <20180914070839.4667-1-ricardo.ribalda@gmail.com> <20180914070839.4667-2-ricardo.ribalda@gmail.com> In-Reply-To: From: Ricardo Ribalda Delgado Date: Wed, 19 Sep 2018 17:27:26 +0200 Message-ID: Subject: Re: [PATCH] gpiolib: Show correct direction from the beginning To: timur@kernel.org Cc: Linus Walleij , Timur Tabi , swboyd@chromium.org, linux-gpio@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Timur On Wed, Sep 19, 2018 at 1:50 PM Timur Tabi wrote: > > On 9/18/18 11:04 PM, Ricardo Ribalda Delgado wrote: > > And should't that be tacked in qcom hardware with something like: > > > > if (!priv->initialized) > > return INPUT; > > > > if you or Timur point me to the harware that was crashing I would not > > mind looking into that, but the current situations seems to me like a > > hack. > > I'd say the previous code was the hack. My comment about not touching > the hardware until it is properly claimed is valid, and it applies to > all platforms. Let me explain my current setup I have a board with input and output gpios, the direction is defined via pdata. When I run gpioinfo all the gpios are shown as input, regardless if they are input or outputs: Eg: root@qt5022:/tmp# ./gpioinfo gpiochip0 - 16 lines: line 0: "PROG_B" unused input active-high line 1: "M0" unused input active-high line 2: "M1" unused input active-high line 3: "M2" unused input active-high line 4: "DIN" unused input active-high line 5: "CCLK" unused input active-high line 6: unnamed unused input active-high line 7: unnamed unused input active-high line 8: "DONE" unused input active-high line 9: "INIT_B" unused input active-high line 10: unnamed unused input active-high line 11: unnamed unused input active-high line 12: unnamed unused input active-high line 13: unnamed unused input active-high line 14: unnamed unused input active-high line 15: unnamed unused input active-high That is wrong and very confusing to the user, it can also lead to a mayor fuckup if the user decides to connect two output gpio pins because he expects that both are input. (This is the programming port, but I also have 24 V -high current GPIOs) There is a function in the API to tell libgpio if a gpio is out our in. Why not use it? - If the configuration is hardcoded, the driver will return a fixed value - If it is cheap to query the hardware, the driver will query the hardware, - If it is expensive to query the hardware the driver can either return a cached value or a fake value (current situation) From my point of view: "The get_direction callback normally triggers a read/write to hardware, but we shouldn't be touching the hardware for an individual GPIO until after it's been properly claimed." is an statement specific for your platform and should be fixed in your driver. Either that, or I have completely missunderstund the purpouse of gpiod :), and that could easily be the case. Regards! -- Ricardo Ribalda