[1/9] pinctrl: core: Add pinctrl_select_default_state() and export it
diff mbox series

Message ID 20191206170821.29711-2-ulf.hansson@linaro.org
State New
Headers show
Series
  • pinctrl: Consolidate some pinctrl code for mmc
Related show

Commit Message

Ulf Hansson Dec. 6, 2019, 5:08 p.m. UTC
It has turned out that some mmc host drivers, but perhaps also others
drivers, needs to reset the pinctrl into the default state
(PINCTRL_STATE_DEFAULT). However, they can't use the existing
pinctrl_pm_select_default_state(), as that requires CONFIG_PM to be set.
This leads to open coding, as they need to look up the default state
themselves and then select it.

To avoid the open coding, let's introduce pinctrl_select_default_state()
and make it available independently of CONFIG_PM. As a matter of fact, this
makes it more consistent with the behaviour of the driver core, as it
already tries to looks up the default state during probe.

Going forward, users of pinctrl_pm_select_default_state() are encouraged to
move to pinctrl_select_default_state(), so the old API can be removed.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/pinctrl/core.c           | 33 ++++++++++++++++++--------------
 include/linux/pinctrl/consumer.h |  6 ++++++
 2 files changed, 25 insertions(+), 14 deletions(-)

Comments

Linus Walleij Dec. 16, 2019, 8:02 a.m. UTC | #1
On Fri, Dec 6, 2019 at 6:08 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:

> It has turned out that some mmc host drivers, but perhaps also others
> drivers, needs to reset the pinctrl into the default state
> (PINCTRL_STATE_DEFAULT). However, they can't use the existing
> pinctrl_pm_select_default_state(), as that requires CONFIG_PM to be set.
> This leads to open coding, as they need to look up the default state
> themselves and then select it.
>
> To avoid the open coding, let's introduce pinctrl_select_default_state()
> and make it available independently of CONFIG_PM. As a matter of fact, this
> makes it more consistent with the behaviour of the driver core, as it
> already tries to looks up the default state during probe.
>
> Going forward, users of pinctrl_pm_select_default_state() are encouraged to
> move to pinctrl_select_default_state(), so the old API can be removed.
>
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

I have put this patch on an immutable branch so that you can pull it into your
tree:
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git/log/?h=ib-pinctrl-default-state

I also pulled this immutable branch into my "devel" branch for v5.6.

I think other subsystems may need the same kind of stuff and I might need
to change code around here so I need to apply it to my tree.

Yours,
Linus Walleij
Ulf Hansson Dec. 16, 2019, 12:09 p.m. UTC | #2
On Mon, 16 Dec 2019 at 09:02, Linus Walleij <linus.walleij@linaro.org> wrote:
>
> On Fri, Dec 6, 2019 at 6:08 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> > It has turned out that some mmc host drivers, but perhaps also others
> > drivers, needs to reset the pinctrl into the default state
> > (PINCTRL_STATE_DEFAULT). However, they can't use the existing
> > pinctrl_pm_select_default_state(), as that requires CONFIG_PM to be set.
> > This leads to open coding, as they need to look up the default state
> > themselves and then select it.
> >
> > To avoid the open coding, let's introduce pinctrl_select_default_state()
> > and make it available independently of CONFIG_PM. As a matter of fact, this
> > makes it more consistent with the behaviour of the driver core, as it
> > already tries to looks up the default state during probe.
> >
> > Going forward, users of pinctrl_pm_select_default_state() are encouraged to
> > move to pinctrl_select_default_state(), so the old API can be removed.
> >
> > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>
> I have put this patch on an immutable branch so that you can pull it into your
> tree:
> https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git/log/?h=ib-pinctrl-default-state
>
> I also pulled this immutable branch into my "devel" branch for v5.6.
>
> I think other subsystems may need the same kind of stuff and I might need
> to change code around here so I need to apply it to my tree.

Thanks!

I have pulled in the branch into my tree - and applied the mmc patches
with your ack on top.

Kind regards
Uffe

Patch
diff mbox series

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 2bbd8ee93507..46600d9380ea 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1535,15 +1535,8 @@  int pinctrl_init_done(struct device *dev)
 	return ret;
 }
 
-#ifdef CONFIG_PM
-
-/**
- * pinctrl_pm_select_state() - select pinctrl state for PM
- * @dev: device to select default state for
- * @state: state to set
- */
-static int pinctrl_pm_select_state(struct device *dev,
-				   struct pinctrl_state *state)
+static int pinctrl_select_bound_state(struct device *dev,
+				      struct pinctrl_state *state)
 {
 	struct dev_pin_info *pins = dev->pins;
 	int ret;
@@ -1558,15 +1551,27 @@  static int pinctrl_pm_select_state(struct device *dev,
 }
 
 /**
- * pinctrl_pm_select_default_state() - select default pinctrl state for PM
+ * pinctrl_select_default_state() - select default pinctrl state
  * @dev: device to select default state for
  */
-int pinctrl_pm_select_default_state(struct device *dev)
+int pinctrl_select_default_state(struct device *dev)
 {
 	if (!dev->pins)
 		return 0;
 
-	return pinctrl_pm_select_state(dev, dev->pins->default_state);
+	return pinctrl_select_bound_state(dev, dev->pins->default_state);
+}
+EXPORT_SYMBOL_GPL(pinctrl_select_default_state);
+
+#ifdef CONFIG_PM
+
+/**
+ * pinctrl_pm_select_default_state() - select default pinctrl state for PM
+ * @dev: device to select default state for
+ */
+int pinctrl_pm_select_default_state(struct device *dev)
+{
+	return pinctrl_select_default_state(dev);
 }
 EXPORT_SYMBOL_GPL(pinctrl_pm_select_default_state);
 
@@ -1579,7 +1584,7 @@  int pinctrl_pm_select_sleep_state(struct device *dev)
 	if (!dev->pins)
 		return 0;
 
-	return pinctrl_pm_select_state(dev, dev->pins->sleep_state);
+	return pinctrl_select_bound_state(dev, dev->pins->sleep_state);
 }
 EXPORT_SYMBOL_GPL(pinctrl_pm_select_sleep_state);
 
@@ -1592,7 +1597,7 @@  int pinctrl_pm_select_idle_state(struct device *dev)
 	if (!dev->pins)
 		return 0;
 
-	return pinctrl_pm_select_state(dev, dev->pins->idle_state);
+	return pinctrl_select_bound_state(dev, dev->pins->idle_state);
 }
 EXPORT_SYMBOL_GPL(pinctrl_pm_select_idle_state);
 #endif
diff --git a/include/linux/pinctrl/consumer.h b/include/linux/pinctrl/consumer.h
index 7f8c7d9583d3..019fecd75d0c 100644
--- a/include/linux/pinctrl/consumer.h
+++ b/include/linux/pinctrl/consumer.h
@@ -40,6 +40,7 @@  extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s);
 
 extern struct pinctrl * __must_check devm_pinctrl_get(struct device *dev);
 extern void devm_pinctrl_put(struct pinctrl *p);
+extern int pinctrl_select_default_state(struct device *dev);
 
 #ifdef CONFIG_PM
 extern int pinctrl_pm_select_default_state(struct device *dev);
@@ -122,6 +123,11 @@  static inline void devm_pinctrl_put(struct pinctrl *p)
 {
 }
 
+static inline int pinctrl_select_default_state(struct device *dev)
+{
+	return 0;
+}
+
 static inline int pinctrl_pm_select_default_state(struct device *dev)
 {
 	return 0;