linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan O'Donovan <dan@emutex.com>
To: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: linus.walleij@linaro.org, heikki.krogerus@linux.intel.com,
	linux-gpio@vger.kernel.org
Subject: Re: [PATCH 5/5] pinctrl: cherryview: restore padctrl1 reg when gpio is disabled
Date: Thu, 9 Jun 2016 17:41:04 +0100	[thread overview]
Message-ID: <57599C20.2030908@emutex.com> (raw)
In-Reply-To: <20160606104052.GX1743@lahna.fi.intel.com>

On 06/06/2016 11:40 AM, Mika Westerberg wrote:
> On Thu, Jun 02, 2016 at 10:55:43PM +0100, Dan O'Donovan wrote:
>> chv_gpio_request_enable() clears some bits in the padctrl1 register
>> when GPIO mode is selected, but these bits are not restored by
>> chv_gpio_disable_free() when GPIO mode is unselected and this can
>> prevent other pin modes (e.g. I2C) from functioning correctly
>> thereafter on that pin.  This patch adds saving/restoring of those
>> bits.
> Not sure how useful this is. If you want to mux I2C out of pins (even if
> they were previosly configured as GPIO), you should call pinctrl to do
> that (or let the core to do that automatically). Expecting that certain
> (possibly unknown state) is restored does seem fragile to me.
Perhaps my description of the change was misleading.  Consider this scenario:
 * chv_pinmux_set_mux() is invoked at start-up (triggered by registering a pin map), and this sets a pin to an alternate mode (e.g. I2C, PWM, whatever).
   - For some pins/modes, this may set the INVRXTX bits in the PADCTRL1 register.  These bits may have also been set early by the BIOS.
 * some time later, the user exports the pin via sysfs for use as a GPIO, which triggers chv_gpio_request_enable()
   - chv_gpio_request_enable() clears some bits in the PADCTRL1 register (including INVRXTX)
 * later again, the user unexports the GPIO pin, which triggers chv_gpio_disable_free().
   - this returns the pin to its previously-selected alternate mode (GPIO is disabled).  However, the INVRXTX bits are not restored here, so the alternate mode no longer works.

>From the way the driver is written (possibly influenced by the hardware design), it appears that this can be a valid usage scenario - i.e. the pin can optionally be set to an alternate mode initially, but the user can bring it in/out of GPIO mode thereafter.  But, because the entry and exit from GPIO mode is not "symmetrical", it loses some configuration that was previously set for the alternate mode.

Admittedly, I've only encountered this scenario in validation testing - I'm not sure if there is a real use-case that would require this - so I can certainly drop this patch if you feel that a fix isn't warranted here.
>
> Also what happens if the pin was originally muxed as GPIO?
This shouldn't make any difference, I think.  The change here is just attempting to make chv_gpio_disable_free() reverse the action of chv_gpio_request_enable() - by restoring PADCTRL register fields to their previous state (whatever that was) before chv_gpio_request_enable() was called.

  reply	other threads:[~2016-06-09 16:41 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-02 21:55 [PATCH 0/5] pinctrl: cherryview: fixes and enhancements Dan O'Donovan
2016-06-02 21:55 ` [PATCH 1/5] pinctrl: cherryview: convert bare unsigned to unsigned int Dan O'Donovan
2016-06-06 10:28   ` Mika Westerberg
2016-06-09 16:04     ` Dan O'Donovan
2016-06-02 21:55 ` [PATCH 2/5] pinctrl: cherryview: add option to set open-drain pin config Dan O'Donovan
2016-06-06 10:32   ` Mika Westerberg
2016-06-02 21:55 ` [PATCH 3/5] pinctrl: cherryview: add handlers for pin_config_group_get/set Dan O'Donovan
2016-06-02 21:55 ` [PATCH 4/5] pinctrl: cherryview: prevent concurrent access to GPIO controllers Dan O'Donovan
2016-06-06 10:31   ` Mika Westerberg
2016-06-09 16:11     ` Dan O'Donovan
2016-06-02 21:55 ` [PATCH 5/5] pinctrl: cherryview: restore padctrl1 reg when gpio is disabled Dan O'Donovan
2016-06-06 10:40   ` Mika Westerberg
2016-06-09 16:41     ` Dan O'Donovan [this message]
2016-06-10  6:00       ` Mika Westerberg
2016-06-10  8:43         ` Dan O'Donovan
2016-06-08  8:32 ` [PATCH 0/5] pinctrl: cherryview: fixes and enhancements Linus Walleij
2016-06-10 12:23 ` [PATCH v2 0/3] " Dan O'Donovan
2016-06-10 12:23   ` [PATCH v2 1/3] pinctrl: cherryview: prevent concurrent access to GPIO controllers Dan O'Donovan
2016-06-13 12:23     ` Linus Walleij
2016-06-13 12:30       ` Dan O'Donovan
2016-06-10 12:23   ` [PATCH v2 2/3] pinctrl: cherryview: add option to set open-drain pin config Dan O'Donovan
2016-06-13 12:25     ` Linus Walleij
2016-06-10 12:23   ` [PATCH v2 3/3] pinctrl: cherryview: add handlers for pin_config_group_get/set Dan O'Donovan
2016-06-13 12:26     ` Linus Walleij
2016-06-13  9:21   ` [PATCH v2 0/3] pinctrl: cherryview: fixes and enhancements Mika Westerberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57599C20.2030908@emutex.com \
    --to=dan@emutex.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).