Message ID | 1805d1ddb5bbce8e86164e66421ddde481cce4f9.1668129763.git.william.gray@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1492867wru; Sat, 12 Nov 2022 17:10:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf7L933+sn4NFp+7PiFYCvEjtZkM8uLBJXfmOMEMO6cbJjBCRClVPOzqoCvXaI4wDWgL4zj/ X-Received: by 2002:a17:906:54cf:b0:78a:d075:98d8 with SMTP id c15-20020a17090654cf00b0078ad07598d8mr6495354ejp.324.1668301853222; Sat, 12 Nov 2022 17:10:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668301853; cv=none; d=google.com; s=arc-20160816; b=HKWC66GRy4/pIyP3bK5Hbb5BjfOAT7plXTcYt4dNCcsPgJK1JKTLPeHK4GZSZ+Tk/x BiEn8E+QXcz1MXyWXvbaboaqc8fIeJfbMR6flOZQzQNSXUV/GvmLnZai2Ijv4og/fGbQ 3IEKc/vFM9eNvRGawv+YxFB6t7trzw6ucysqDhC+s6fO9eGq+FYryiAp2PbLt5VeL8GP PEOUuoc6NHHtYSYSXdMWhrOkOceoiSfGrvRFSgISDtSM5eLI0VLUOaEhUR95mmHmqPJ/ vrHNVhPVEFOB0aQJn+aLKbkEglIlwODyfrZsR6lISS0USFBUlFFfLXA3Khv3+4hphbed OU2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y2DT+DwYAGhQmBgm02Hatyz4IgqEc7zsVJLAJJN9Ri0=; b=CshItBO0esYvXLHChrBYgX6L9XuQCjI0qawPV3OXLChyBJ901WEg8TChGu2LcjLxG9 +gLUNB8DtUN6WNAPrWbrTpI2j0NFDNJG7XHCLtRNHD7VfnZ5V/U6kxj6xdOciqVtFSBp Orh8J+is0OSN33IViDU9/oxSbhYr/M1BXApfmgKR8asLrW34U6AQuXw4JOIFiA6FV9kz abczrrhhL6Sl/5OLbhSJkfxwQf4wBjrasft83V8bXXo8/GxBa/8VA22QTq/wpUWb6VcG GD32AbFWkLqtDBFZ+/X8eJDZWRDwU3yAFXVNHkW8/OQQ858wMS9sV1FznY38F9JIPoWi 8U0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NazLy5nz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nc7-20020a1709071c0700b007adc0d5ad94si6616965ejc.938.2022.11.12.17.10.29; Sat, 12 Nov 2022 17:10:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NazLy5nz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235136AbiKMBJs (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Sat, 12 Nov 2022 20:09:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235106AbiKMBJp (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 12 Nov 2022 20:09:45 -0500 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 186CB13F1D for <linux-kernel@vger.kernel.org>; Sat, 12 Nov 2022 17:09:45 -0800 (PST) Received: by mail-qk1-x729.google.com with SMTP id x18so5520256qki.4 for <linux-kernel@vger.kernel.org>; Sat, 12 Nov 2022 17:09:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y2DT+DwYAGhQmBgm02Hatyz4IgqEc7zsVJLAJJN9Ri0=; b=NazLy5nzQlgW+6kjijqavW5qe2KAD2TLi2xDnZLX97WjnB444i4AJ0eTOg+ljoaaiB 4lhtqnfPwkdxNwPG+6gwN11mYQQCgoS1EgMxx1FgsvDq2wwQa4i+OeYxo0tA9baVeFIb f4M5v59OxUwG8cfhj//NxZOBqvFY4HxfnikrswndKvkqJr7KId7IeNcPnskg+Chffz3U CMTqI+decenIEgYGwLZ937ilUJbsSht0rkGXtHofnmatZ2NoYOAkO9lIOH/J6qNt0qE7 B46c3vEK0IWR/CjPOZS3BHVs/XGcF1g2eBRqP/79G+89/L/jfrwDIdD/VuNWkh2vDnjt sFYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y2DT+DwYAGhQmBgm02Hatyz4IgqEc7zsVJLAJJN9Ri0=; b=n0CzMM7uUYEU09o/UOB58kTMZa6Nexoi13ZwIyCIIYronV6pr9awVH5sZjOwvnz7il wFjhwkSw00NfzPkkPJb7emD4DyuHOY//4L2IPdyVD2hxZ+tJenS/iSRpwgKjjGaRP5L3 NvhJaMzv9IvorqOIRsCCR1tPJDQCN3J37zs69iFqYXzIiNj+9CBpcE/faeCa1hxxpvLj HqWtV6/84863cXHT2U2BNJ8ySQ4D/odLVHhtn6epFFfwFm7zta1S0PHs9QtLcV9mlo9I Vxl/HEKrMnyLFN/kQKyD3PHa4tUnew20WPIHKemtUAOYAFlDi18nIol3q7wXNBU6RUNb tVnA== X-Gm-Message-State: ANoB5pkg4xxCFKJehRY9zuoBU25nJ9wJEkcGwIwCRPm9nEnBvjnlIGrd zRjDU4zEqYD65RXEwBUf43oa+A== X-Received: by 2002:a37:6c83:0:b0:6fa:19a4:ab6f with SMTP id h125-20020a376c83000000b006fa19a4ab6fmr6719620qkc.759.1668301784203; Sat, 12 Nov 2022 17:09:44 -0800 (PST) Received: from fedora.attlocal.net (69-109-179-158.lightspeed.dybhfl.sbcglobal.net. [69.109.179.158]) by smtp.gmail.com with ESMTPSA id t6-20020a05622a180600b00343057845f7sm3552498qtc.20.2022.11.12.17.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Nov 2022 17:09:43 -0800 (PST) From: William Breathitt Gray <william.gray@linaro.org> To: linus.walleij@linaro.org, brgl@bgdev.pl Cc: andriy.shevchenko@linux.intel.com, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, michael@walle.cc, broonie@kernel.org, William Breathitt Gray <william.gray@linaro.org> Subject: [PATCH v2 1/4] gpio: regmap: Always set gpio_chip get_direction Date: Thu, 10 Nov 2022 20:55:50 -0500 Message-Id: <1805d1ddb5bbce8e86164e66421ddde481cce4f9.1668129763.git.william.gray@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <cover.1668129763.git.william.gray@linaro.org> References: <cover.1668129763.git.william.gray@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,DATE_IN_PAST_24_48, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749341284189291906?= X-GMAIL-MSGID: =?utf-8?q?1749341284189291906?= |
Series |
Migrate i8255 GPIO drivers to regmap API
|
|
Commit Message
William Breathitt Gray
Nov. 11, 2022, 1:55 a.m. UTC
If you only have reg_dat_base set, then it is input-only; if you only
have reg_set_base set, then it is output-only. Thus, we can always set
gpio_chip get_direction to gpio_regmap_get_direction and return
GPIO_LINE_DIRECTION_IN/GPIO_LINE_DIRECTION_OUT given the respective
register base addresses configuration.
Signed-off-by: William Breathitt Gray <william.gray@linaro.org>
---
drivers/gpio/gpio-regmap.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
Comments
On Thu, Nov 10, 2022 at 08:55:50PM -0500, William Breathitt Gray wrote: > If you only have reg_dat_base set, then it is input-only; if you only > have reg_set_base set, then it is output-only. Thus, we can always set > gpio_chip get_direction to gpio_regmap_get_direction and return > GPIO_LINE_DIRECTION_IN/GPIO_LINE_DIRECTION_OUT given the respective > register base addresses configuration. Seems legit to me. Have you checked if we have any gpio-regmap drivers that have something like this in their configuration already? In such cases we need to be sure they behave as expected. From the code perspective: Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > Signed-off-by: William Breathitt Gray <william.gray@linaro.org> > --- > drivers/gpio/gpio-regmap.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c > index 6383136cbe59..f907c9c19fce 100644 > --- a/drivers/gpio/gpio-regmap.c > +++ b/drivers/gpio/gpio-regmap.c > @@ -111,6 +111,11 @@ static int gpio_regmap_get_direction(struct gpio_chip *chip, > unsigned int base, val, reg, mask; > int invert, ret; > > + if (gpio->reg_dat_base && !gpio->reg_set_base) > + return GPIO_LINE_DIRECTION_IN; > + if (gpio->reg_set_base && !gpio->reg_dat_base) > + return GPIO_LINE_DIRECTION_OUT; > + > if (gpio->reg_dir_out_base) { > base = gpio_regmap_addr(gpio->reg_dir_out_base); > invert = 0; > @@ -265,8 +270,8 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config > else if (gpio->reg_set_base) > chip->set = gpio_regmap_set; > > + chip->get_direction = gpio_regmap_get_direction; > if (gpio->reg_dir_in_base || gpio->reg_dir_out_base) { > - chip->get_direction = gpio_regmap_get_direction; > chip->direction_input = gpio_regmap_direction_input; > chip->direction_output = gpio_regmap_direction_output; > } > -- > 2.38.1 >
On Sun, Nov 13, 2022 at 02:40:17PM +0200, Andy Shevchenko wrote: > On Thu, Nov 10, 2022 at 08:55:50PM -0500, William Breathitt Gray wrote: > > If you only have reg_dat_base set, then it is input-only; if you only > > have reg_set_base set, then it is output-only. Thus, we can always set > > gpio_chip get_direction to gpio_regmap_get_direction and return > > GPIO_LINE_DIRECTION_IN/GPIO_LINE_DIRECTION_OUT given the respective > > register base addresses configuration. > > Seems legit to me. Have you checked if we have any gpio-regmap drivers that > have something like this in their configuration already? In such cases we need > to be sure they behave as expected. > > From the code perspective: > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> I see gpio-sl28cpld has two device types SL28CPLD_GPO (output-only) and SL28CPLD_GPI (input-only); gpio-tn48m similarly has two device types TN48M_GPO (output-only) and TN48M_GPI (input-only). It doesn't look like the change in this patch will cause problems for them, but I'll let Michael Walle and Robert Marko comment if they see issues here. William Breathitt Gray > > Signed-off-by: William Breathitt Gray <william.gray@linaro.org> > > --- > > drivers/gpio/gpio-regmap.c | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c > > index 6383136cbe59..f907c9c19fce 100644 > > --- a/drivers/gpio/gpio-regmap.c > > +++ b/drivers/gpio/gpio-regmap.c > > @@ -111,6 +111,11 @@ static int gpio_regmap_get_direction(struct gpio_chip *chip, > > unsigned int base, val, reg, mask; > > int invert, ret; > > > > + if (gpio->reg_dat_base && !gpio->reg_set_base) > > + return GPIO_LINE_DIRECTION_IN; > > + if (gpio->reg_set_base && !gpio->reg_dat_base) > > + return GPIO_LINE_DIRECTION_OUT; > > + > > if (gpio->reg_dir_out_base) { > > base = gpio_regmap_addr(gpio->reg_dir_out_base); > > invert = 0; > > @@ -265,8 +270,8 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config > > else if (gpio->reg_set_base) > > chip->set = gpio_regmap_set; > > > > + chip->get_direction = gpio_regmap_get_direction; > > if (gpio->reg_dir_in_base || gpio->reg_dir_out_base) { > > - chip->get_direction = gpio_regmap_get_direction; > > chip->direction_input = gpio_regmap_direction_input; > > chip->direction_output = gpio_regmap_direction_output; > > } > > -- > > 2.38.1 > > > > -- > With Best Regards, > Andy Shevchenko > >
On Sun, Nov 13, 2022 at 2:21 PM William Breathitt Gray <william.gray@linaro.org> wrote: > > On Sun, Nov 13, 2022 at 02:40:17PM +0200, Andy Shevchenko wrote: > > On Thu, Nov 10, 2022 at 08:55:50PM -0500, William Breathitt Gray wrote: > > > If you only have reg_dat_base set, then it is input-only; if you only > > > have reg_set_base set, then it is output-only. Thus, we can always set > > > gpio_chip get_direction to gpio_regmap_get_direction and return > > > GPIO_LINE_DIRECTION_IN/GPIO_LINE_DIRECTION_OUT given the respective > > > register base addresses configuration. > > > > Seems legit to me. Have you checked if we have any gpio-regmap drivers that > > have something like this in their configuration already? In such cases we need > > to be sure they behave as expected. > > > > From the code perspective: > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > > I see gpio-sl28cpld has two device types SL28CPLD_GPO (output-only) and > SL28CPLD_GPI (input-only); gpio-tn48m similarly has two device types > TN48M_GPO (output-only) and TN48M_GPI (input-only). It doesn't look like > the change in this patch will cause problems for them, but I'll let > Michael Walle and Robert Marko comment if they see issues here. Hi, sorry for the late reply. This should work fine for TN48M. Regards, Robert > > William Breathitt Gray > > > > Signed-off-by: William Breathitt Gray <william.gray@linaro.org> > > > --- > > > drivers/gpio/gpio-regmap.c | 7 ++++++- > > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c > > > index 6383136cbe59..f907c9c19fce 100644 > > > --- a/drivers/gpio/gpio-regmap.c > > > +++ b/drivers/gpio/gpio-regmap.c > > > @@ -111,6 +111,11 @@ static int gpio_regmap_get_direction(struct gpio_chip *chip, > > > unsigned int base, val, reg, mask; > > > int invert, ret; > > > > > > + if (gpio->reg_dat_base && !gpio->reg_set_base) > > > + return GPIO_LINE_DIRECTION_IN; > > > + if (gpio->reg_set_base && !gpio->reg_dat_base) > > > + return GPIO_LINE_DIRECTION_OUT; > > > + > > > if (gpio->reg_dir_out_base) { > > > base = gpio_regmap_addr(gpio->reg_dir_out_base); > > > invert = 0; > > > @@ -265,8 +270,8 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config > > > else if (gpio->reg_set_base) > > > chip->set = gpio_regmap_set; > > > > > > + chip->get_direction = gpio_regmap_get_direction; > > > if (gpio->reg_dir_in_base || gpio->reg_dir_out_base) { > > > - chip->get_direction = gpio_regmap_get_direction; > > > chip->direction_input = gpio_regmap_direction_input; > > > chip->direction_output = gpio_regmap_direction_output; > > > } > > > -- > > > 2.38.1 > > > > > > > -- > > With Best Regards, > > Andy Shevchenko > > > >
Am 2022-11-13 14:21, schrieb William Breathitt Gray: > On Sun, Nov 13, 2022 at 02:40:17PM +0200, Andy Shevchenko wrote: >> On Thu, Nov 10, 2022 at 08:55:50PM -0500, William Breathitt Gray >> wrote: >> > If you only have reg_dat_base set, then it is input-only; if you only >> > have reg_set_base set, then it is output-only. Thus, we can always set >> > gpio_chip get_direction to gpio_regmap_get_direction and return >> > GPIO_LINE_DIRECTION_IN/GPIO_LINE_DIRECTION_OUT given the respective >> > register base addresses configuration. >> >> Seems legit to me. Have you checked if we have any gpio-regmap drivers >> that >> have something like this in their configuration already? In such cases >> we need >> to be sure they behave as expected. >> >> From the code perspective: >> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > > I see gpio-sl28cpld has two device types SL28CPLD_GPO (output-only) and > SL28CPLD_GPI (input-only); gpio-tn48m similarly has two device types > TN48M_GPO (output-only) and TN48M_GPI (input-only). It doesn't look > like > the change in this patch will cause problems for them, but I'll let > Michael Walle and Robert Marko comment if they see issues here. For the sl28cpld driver this shouldn't be a problem. So for that Acked-by: Michael Walle <michael@walle.cc> But back when I wrote gpio-regmap the bgpio served as a blue print. There is the same handling. If you look at gpiolib-sysfs.c there is a comment about the direction property: * MAY BE OMITTED if kernel won't allow direction changes So from a gpiolib/sysfs POV I'm not sure about this change. Does get_direction == NULL means setting the direction isn't possible? OTHO there is a fat "MAY" :) Which brings me to the question of "why this change?". The commit message doesn't mention it. Just out of curiosity. -michael
On Wed, Nov 16, 2022 at 04:41:30PM +0100, Michael Walle wrote: > Am 2022-11-13 14:21, schrieb William Breathitt Gray: > > On Sun, Nov 13, 2022 at 02:40:17PM +0200, Andy Shevchenko wrote: > > > On Thu, Nov 10, 2022 at 08:55:50PM -0500, William Breathitt Gray > > > wrote: > > > > If you only have reg_dat_base set, then it is input-only; if you only > > > > have reg_set_base set, then it is output-only. Thus, we can always set > > > > gpio_chip get_direction to gpio_regmap_get_direction and return > > > > GPIO_LINE_DIRECTION_IN/GPIO_LINE_DIRECTION_OUT given the respective > > > > register base addresses configuration. > > > > > > Seems legit to me. Have you checked if we have any gpio-regmap > > > drivers that > > > have something like this in their configuration already? In such > > > cases we need > > > to be sure they behave as expected. > > > > > > From the code perspective: > > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > > > > I see gpio-sl28cpld has two device types SL28CPLD_GPO (output-only) and > > SL28CPLD_GPI (input-only); gpio-tn48m similarly has two device types > > TN48M_GPO (output-only) and TN48M_GPI (input-only). It doesn't look like > > the change in this patch will cause problems for them, but I'll let > > Michael Walle and Robert Marko comment if they see issues here. > > For the sl28cpld driver this shouldn't be a problem. So for that > Acked-by: Michael Walle <michael@walle.cc> > > But back when I wrote gpio-regmap the bgpio served as a blue print. > There is the same handling. If you look at gpiolib-sysfs.c there > is a comment about the direction property: > > * MAY BE OMITTED if kernel won't allow direction changes > > So from a gpiolib/sysfs POV I'm not sure about this change. Does > get_direction == NULL means setting the direction isn't possible? > OTHO there is a fat "MAY" :) > > Which brings me to the question of "why this change?". The commit > message doesn't mention it. Just out of curiosity. Sysfs shouldn't be considered nowadays as anything but deprecated and not-to-use interface. Hence, I don't care what it tells there.
On Wed, Nov 16, 2022 at 04:41:30PM +0100, Michael Walle wrote: > Am 2022-11-13 14:21, schrieb William Breathitt Gray: > > On Sun, Nov 13, 2022 at 02:40:17PM +0200, Andy Shevchenko wrote: > > > On Thu, Nov 10, 2022 at 08:55:50PM -0500, William Breathitt Gray > > > wrote: > > > > If you only have reg_dat_base set, then it is input-only; if you only > > > > have reg_set_base set, then it is output-only. Thus, we can always set > > > > gpio_chip get_direction to gpio_regmap_get_direction and return > > > > GPIO_LINE_DIRECTION_IN/GPIO_LINE_DIRECTION_OUT given the respective > > > > register base addresses configuration. > > > > > > Seems legit to me. Have you checked if we have any gpio-regmap > > > drivers that > > > have something like this in their configuration already? In such > > > cases we need > > > to be sure they behave as expected. > > > > > > From the code perspective: > > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > > > > I see gpio-sl28cpld has two device types SL28CPLD_GPO (output-only) and > > SL28CPLD_GPI (input-only); gpio-tn48m similarly has two device types > > TN48M_GPO (output-only) and TN48M_GPI (input-only). It doesn't look like > > the change in this patch will cause problems for them, but I'll let > > Michael Walle and Robert Marko comment if they see issues here. > > For the sl28cpld driver this shouldn't be a problem. So for that > Acked-by: Michael Walle <michael@walle.cc> > > But back when I wrote gpio-regmap the bgpio served as a blue print. > There is the same handling. If you look at gpiolib-sysfs.c there > is a comment about the direction property: > > * MAY BE OMITTED if kernel won't allow direction changes > > So from a gpiolib/sysfs POV I'm not sure about this change. Does > get_direction == NULL means setting the direction isn't possible? > OTHO there is a fat "MAY" :) > > Which brings me to the question of "why this change?". The commit > message doesn't mention it. Just out of curiosity. > > -michael Currently, the 104-idi-48 module implements a get_direction() callback that is executed in situations such as gpiod_get_direction() which aren't necessarily related to sysfs. In this patch series, the 104-idi-48 module is migrated to the gpio_regmap API, but loses this get_direction() support because it's an input-only configuration. The purpose of this patch is to prevent that regression by supporting get_direction() for input-only/output-only configurations. William Breathitt Gray
Am 2022-11-17 15:22, schrieb William Breathitt Gray: >> Which brings me to the question of "why this change?". The commit >> message doesn't mention it. Just out of curiosity. >> >> -michael > > Currently, the 104-idi-48 module implements a get_direction() callback > that is executed in situations such as gpiod_get_direction() which > aren't necessarily related to sysfs. In this patch series, the > 104-idi-48 module is migrated to the gpio_regmap API, but loses this > get_direction() support because it's an input-only configuration. The > purpose of this patch is to prevent that regression by supporting > get_direction() for input-only/output-only configurations. I see, thanks for the explanation. As said before, I'm fine with the change and apparently we don't care for sysfs changes ;) -michael
diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 6383136cbe59..f907c9c19fce 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -111,6 +111,11 @@ static int gpio_regmap_get_direction(struct gpio_chip *chip, unsigned int base, val, reg, mask; int invert, ret; + if (gpio->reg_dat_base && !gpio->reg_set_base) + return GPIO_LINE_DIRECTION_IN; + if (gpio->reg_set_base && !gpio->reg_dat_base) + return GPIO_LINE_DIRECTION_OUT; + if (gpio->reg_dir_out_base) { base = gpio_regmap_addr(gpio->reg_dir_out_base); invert = 0; @@ -265,8 +270,8 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config else if (gpio->reg_set_base) chip->set = gpio_regmap_set; + chip->get_direction = gpio_regmap_get_direction; if (gpio->reg_dir_in_base || gpio->reg_dir_out_base) { - chip->get_direction = gpio_regmap_get_direction; chip->direction_input = gpio_regmap_direction_input; chip->direction_output = gpio_regmap_direction_output; }