All of lore.kernel.org
 help / color / mirror / Atom feed
From: swarren@wwwdotorg.org (Stephen Warren)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/3] drivers: pinctrl sleep and idle states in the core
Date: Thu, 13 Jun 2013 16:02:00 -0600	[thread overview]
Message-ID: <51BA4158.906@wwwdotorg.org> (raw)
In-Reply-To: <CACRpkdY_s_RkErKLqVOWdE-A80CZOq7+VZSE8jcYSUbYkvsYYQ@mail.gmail.com>

On 06/11/2013 02:28 AM, Linus Walleij wrote:
> On Wed, Jun 5, 2013 at 7:22 PM, Stephen Warren <swarren@wwwdotorg.org> wrote:
> 
>>> diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
>>
>>> +int pinctrl_pm_select_default_state(struct device *dev)
>>
>>> +int pinctrl_pm_select_sleep_state(struct device *dev)
>>
>>> +int pinctrl_pm_select_idle_state(struct device *dev)
>>
>> The implementation of those 3 functions is basically identical. I'd be
>> inclined to move it to a helper function, and just pass (dev,
>> pins->xxx_state) to it.
> 
> Just to follow up on this now that I'm adding one more state.
> 
> I tried to create a refactoring patch for this but couldn't come
> up with anything apropriate along the lines above. For example
> this function:
...

Don't you just want something very roughly like:

int pinctrl_pm_select_xxx_state(struct device *dev,
		unsigned long offset, char *name)
{
	struct dev_pin_info *pins = dev->pins;
	struct pinctrl_state **s = (void *)(((char *)pins) + offset)
	int ret;

	if (!pins)
		return 0;
	if (IS_ERR(*s))
		return 0; /* No default state */
	ret = pinctrl_select_state(pins->p, *s);
	if (ret)
		dev_err(dev, "failed to activate %s pinctrl state\n",
			name);
	return ret;
}

int pinctrl_pm_select_default_state(struct device *dev)
{
    return pinctrl_pm_select_xxx_state(dev,
		offsetof(struct dev_pin_info, default_state),
		"default");
}

WARNING: multiple messages have this Message-ID (diff)
From: Stephen Warren <swarren@wwwdotorg.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Linus Walleij <linus.walleij@stericsson.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Stephen Warren <swarren@nvidia.com>,
	Kevin Hilman <khilman@linaro.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	Hebbar Gururaja <gururaja.hebbar@ti.com>,
	Mark Brown <broonie@kernel.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Wolfram Sang <wsa@the-dreams.de>
Subject: Re: [PATCH 1/3] drivers: pinctrl sleep and idle states in the core
Date: Thu, 13 Jun 2013 16:02:00 -0600	[thread overview]
Message-ID: <51BA4158.906@wwwdotorg.org> (raw)
In-Reply-To: <CACRpkdY_s_RkErKLqVOWdE-A80CZOq7+VZSE8jcYSUbYkvsYYQ@mail.gmail.com>

On 06/11/2013 02:28 AM, Linus Walleij wrote:
> On Wed, Jun 5, 2013 at 7:22 PM, Stephen Warren <swarren@wwwdotorg.org> wrote:
> 
>>> diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
>>
>>> +int pinctrl_pm_select_default_state(struct device *dev)
>>
>>> +int pinctrl_pm_select_sleep_state(struct device *dev)
>>
>>> +int pinctrl_pm_select_idle_state(struct device *dev)
>>
>> The implementation of those 3 functions is basically identical. I'd be
>> inclined to move it to a helper function, and just pass (dev,
>> pins->xxx_state) to it.
> 
> Just to follow up on this now that I'm adding one more state.
> 
> I tried to create a refactoring patch for this but couldn't come
> up with anything apropriate along the lines above. For example
> this function:
...

Don't you just want something very roughly like:

int pinctrl_pm_select_xxx_state(struct device *dev,
		unsigned long offset, char *name)
{
	struct dev_pin_info *pins = dev->pins;
	struct pinctrl_state **s = (void *)(((char *)pins) + offset)
	int ret;

	if (!pins)
		return 0;
	if (IS_ERR(*s))
		return 0; /* No default state */
	ret = pinctrl_select_state(pins->p, *s);
	if (ret)
		dev_err(dev, "failed to activate %s pinctrl state\n",
			name);
	return ret;
}

int pinctrl_pm_select_default_state(struct device *dev)
{
    return pinctrl_pm_select_xxx_state(dev,
		offsetof(struct dev_pin_info, default_state),
		"default");
}


  reply	other threads:[~2013-06-13 22:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-05 13:44 [PATCH 1/3] drivers: pinctrl sleep and idle states in the core Linus Walleij
2013-06-05 13:44 ` Linus Walleij
2013-06-05 13:44 ` [PATCH 2/3] tty: serial: modify PL011 driver to use pinctrl PM helpers Linus Walleij
2013-06-05 13:44   ` Linus Walleij
2013-06-05 18:54   ` Greg Kroah-Hartman
2013-06-05 18:54     ` Greg Kroah-Hartman
2013-06-05 13:44 ` [PATCH 3/3] i2c: nomadik: " Linus Walleij
2013-06-05 13:44   ` Linus Walleij
2013-06-05 16:34   ` Kevin Hilman
2013-06-05 16:34     ` Kevin Hilman
2013-06-07  8:33     ` Linus Walleij
2013-06-07  8:33       ` Linus Walleij
2013-06-07 14:31       ` Kevin Hilman
2013-06-07 14:31         ` Kevin Hilman
2013-06-05 14:03 ` [PATCH 1/3] drivers: pinctrl sleep and idle states in the core Wolfram Sang
2013-06-05 14:03   ` Wolfram Sang
2013-06-05 14:47 ` Mark Brown
2013-06-05 14:47   ` Mark Brown
2013-06-05 15:57 ` Kevin Hilman
2013-06-05 15:57   ` Kevin Hilman
2013-06-05 17:22 ` Stephen Warren
2013-06-05 17:22   ` Stephen Warren
2013-06-07  7:53   ` Linus Walleij
2013-06-07  7:53     ` Linus Walleij
2013-06-11  8:28   ` Linus Walleij
2013-06-11  8:28     ` Linus Walleij
2013-06-13 22:02     ` Stephen Warren [this message]
2013-06-13 22:02       ` Stephen Warren
2013-06-16 10:55       ` Linus Walleij
2013-06-16 10:55         ` Linus Walleij
2013-06-05 18:54 ` Greg Kroah-Hartman
2013-06-05 18:54   ` Greg Kroah-Hartman
2013-06-17 15:12 ` [PATCH] pinctrl: export pinctrl_pm_select_*_state Arnd Bergmann
2013-06-17 15:12   ` Arnd Bergmann
2013-06-17 16:30   ` Linus Walleij
2013-06-17 16:30     ` Linus Walleij

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=51BA4158.906@wwwdotorg.org \
    --to=swarren@wwwdotorg.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.