mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-21 16:29:59 +00:00
![Ulf Hansson](/assets/img/avatar_default.png)
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> Link: https://lore.kernel.org/r/20191206170821.29711-2-ulf.hansson@linaro.org Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
212 lines
4.5 KiB
C
212 lines
4.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Consumer interface the pin control subsystem
|
|
*
|
|
* Copyright (C) 2012 ST-Ericsson SA
|
|
* Written on behalf of Linaro for ST-Ericsson
|
|
* Based on bits of regulator core, gpio core and clk core
|
|
*
|
|
* Author: Linus Walleij <linus.walleij@linaro.org>
|
|
*/
|
|
#ifndef __LINUX_PINCTRL_CONSUMER_H
|
|
#define __LINUX_PINCTRL_CONSUMER_H
|
|
|
|
#include <linux/err.h>
|
|
#include <linux/list.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/pinctrl/pinctrl-state.h>
|
|
|
|
/* This struct is private to the core and should be regarded as a cookie */
|
|
struct pinctrl;
|
|
struct pinctrl_state;
|
|
struct device;
|
|
|
|
#ifdef CONFIG_PINCTRL
|
|
|
|
/* External interface to pin control */
|
|
extern bool pinctrl_gpio_can_use_line(unsigned gpio);
|
|
extern int pinctrl_gpio_request(unsigned gpio);
|
|
extern void pinctrl_gpio_free(unsigned gpio);
|
|
extern int pinctrl_gpio_direction_input(unsigned gpio);
|
|
extern int pinctrl_gpio_direction_output(unsigned gpio);
|
|
extern int pinctrl_gpio_set_config(unsigned gpio, unsigned long config);
|
|
|
|
extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
|
|
extern void pinctrl_put(struct pinctrl *p);
|
|
extern struct pinctrl_state * __must_check pinctrl_lookup_state(
|
|
struct pinctrl *p,
|
|
const char *name);
|
|
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);
|
|
extern int pinctrl_pm_select_sleep_state(struct device *dev);
|
|
extern int pinctrl_pm_select_idle_state(struct device *dev);
|
|
#else
|
|
static inline int pinctrl_pm_select_default_state(struct device *dev)
|
|
{
|
|
return 0;
|
|
}
|
|
static inline int pinctrl_pm_select_sleep_state(struct device *dev)
|
|
{
|
|
return 0;
|
|
}
|
|
static inline int pinctrl_pm_select_idle_state(struct device *dev)
|
|
{
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
#else /* !CONFIG_PINCTRL */
|
|
|
|
static inline bool pinctrl_gpio_can_use_line(unsigned gpio)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static inline int pinctrl_gpio_request(unsigned gpio)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void pinctrl_gpio_free(unsigned gpio)
|
|
{
|
|
}
|
|
|
|
static inline int pinctrl_gpio_direction_input(unsigned gpio)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int pinctrl_gpio_direction_output(unsigned gpio)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline void pinctrl_put(struct pinctrl *p)
|
|
{
|
|
}
|
|
|
|
static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
|
|
struct pinctrl *p,
|
|
const char *name)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline int pinctrl_select_state(struct pinctrl *p,
|
|
struct pinctrl_state *s)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
static inline int pinctrl_pm_select_sleep_state(struct device *dev)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int pinctrl_pm_select_idle_state(struct device *dev)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
#endif /* CONFIG_PINCTRL */
|
|
|
|
static inline struct pinctrl * __must_check pinctrl_get_select(
|
|
struct device *dev, const char *name)
|
|
{
|
|
struct pinctrl *p;
|
|
struct pinctrl_state *s;
|
|
int ret;
|
|
|
|
p = pinctrl_get(dev);
|
|
if (IS_ERR(p))
|
|
return p;
|
|
|
|
s = pinctrl_lookup_state(p, name);
|
|
if (IS_ERR(s)) {
|
|
pinctrl_put(p);
|
|
return ERR_CAST(s);
|
|
}
|
|
|
|
ret = pinctrl_select_state(p, s);
|
|
if (ret < 0) {
|
|
pinctrl_put(p);
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
return p;
|
|
}
|
|
|
|
static inline struct pinctrl * __must_check pinctrl_get_select_default(
|
|
struct device *dev)
|
|
{
|
|
return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
|
|
}
|
|
|
|
static inline struct pinctrl * __must_check devm_pinctrl_get_select(
|
|
struct device *dev, const char *name)
|
|
{
|
|
struct pinctrl *p;
|
|
struct pinctrl_state *s;
|
|
int ret;
|
|
|
|
p = devm_pinctrl_get(dev);
|
|
if (IS_ERR(p))
|
|
return p;
|
|
|
|
s = pinctrl_lookup_state(p, name);
|
|
if (IS_ERR(s)) {
|
|
devm_pinctrl_put(p);
|
|
return ERR_CAST(s);
|
|
}
|
|
|
|
ret = pinctrl_select_state(p, s);
|
|
if (ret < 0) {
|
|
devm_pinctrl_put(p);
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
return p;
|
|
}
|
|
|
|
static inline struct pinctrl * __must_check devm_pinctrl_get_select_default(
|
|
struct device *dev)
|
|
{
|
|
return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
|
|
}
|
|
|
|
#endif /* __LINUX_PINCTRL_CONSUMER_H */
|