2012-02-09 07:52:22 +07:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
*
|
|
|
|
* License terms: GNU General Public License (GPL) version 2
|
|
|
|
*/
|
|
|
|
#ifndef __LINUX_PINCTRL_CONSUMER_H
|
|
|
|
#define __LINUX_PINCTRL_CONSUMER_H
|
|
|
|
|
2012-03-03 03:05:47 +07:00
|
|
|
#include <linux/err.h>
|
2012-02-09 07:52:22 +07:00
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/seq_file.h>
|
2012-10-03 00:01:25 +07:00
|
|
|
#include <linux/pinctrl/pinctrl-state.h>
|
2012-02-09 07:52:22 +07:00
|
|
|
|
|
|
|
/* This struct is private to the core and should be regarded as a cookie */
|
2012-02-09 13:23:28 +07:00
|
|
|
struct pinctrl;
|
2012-03-03 03:05:47 +07:00
|
|
|
struct pinctrl_state;
|
2012-08-10 21:52:58 +07:00
|
|
|
struct device;
|
2012-02-09 07:52:22 +07:00
|
|
|
|
2012-02-10 01:47:48 +07:00
|
|
|
#ifdef CONFIG_PINCTRL
|
2012-02-09 07:52:22 +07:00
|
|
|
|
2012-02-10 01:47:48 +07:00
|
|
|
/* External interface to pin control */
|
2017-09-22 16:02:10 +07:00
|
|
|
extern int pinctrl_gpio_request(unsigned gpio);
|
|
|
|
extern void pinctrl_gpio_free(unsigned gpio);
|
2012-02-09 13:23:28 +07:00
|
|
|
extern int pinctrl_gpio_direction_input(unsigned gpio);
|
|
|
|
extern int pinctrl_gpio_direction_output(unsigned gpio);
|
2017-01-23 19:34:33 +07:00
|
|
|
extern int pinctrl_gpio_set_config(unsigned gpio, unsigned long config);
|
2012-03-03 03:05:47 +07:00
|
|
|
|
|
|
|
extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
|
2012-02-09 13:23:28 +07:00
|
|
|
extern void pinctrl_put(struct pinctrl *p);
|
2012-03-03 03:05:47 +07:00
|
|
|
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);
|
2012-02-09 07:52:22 +07:00
|
|
|
|
2012-04-16 23:51:00 +07:00
|
|
|
extern struct pinctrl * __must_check devm_pinctrl_get(struct device *dev);
|
|
|
|
extern void devm_pinctrl_put(struct pinctrl *p);
|
|
|
|
|
2013-06-05 20:30:33 +07:00
|
|
|
#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
|
|
|
|
|
2012-02-10 01:47:48 +07:00
|
|
|
#else /* !CONFIG_PINCTRL */
|
2012-02-09 07:52:22 +07:00
|
|
|
|
2017-09-22 16:02:10 +07:00
|
|
|
static inline int pinctrl_gpio_request(unsigned gpio)
|
2012-02-09 07:52:22 +07:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-22 16:02:10 +07:00
|
|
|
static inline void pinctrl_gpio_free(unsigned gpio)
|
2012-02-09 07:52:22 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-09 13:23:28 +07:00
|
|
|
static inline int pinctrl_gpio_direction_input(unsigned gpio)
|
2012-02-09 07:52:22 +07:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-09 13:23:28 +07:00
|
|
|
static inline int pinctrl_gpio_direction_output(unsigned gpio)
|
2012-02-09 07:52:22 +07:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-23 19:34:33 +07:00
|
|
|
static inline int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-03 03:05:47 +07:00
|
|
|
static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
|
2012-02-09 07:52:22 +07:00
|
|
|
{
|
2015-03-05 16:08:14 +07:00
|
|
|
return NULL;
|
2012-02-09 07:52:22 +07:00
|
|
|
}
|
|
|
|
|
2012-02-09 13:23:28 +07:00
|
|
|
static inline void pinctrl_put(struct pinctrl *p)
|
2012-02-09 07:52:22 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-03 03:05:47 +07:00
|
|
|
static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
|
|
|
|
struct pinctrl *p,
|
|
|
|
const char *name)
|
2012-02-09 07:52:22 +07:00
|
|
|
{
|
2015-03-05 16:08:14 +07:00
|
|
|
return NULL;
|
2012-02-09 07:52:22 +07:00
|
|
|
}
|
|
|
|
|
2012-03-03 03:05:47 +07:00
|
|
|
static inline int pinctrl_select_state(struct pinctrl *p,
|
|
|
|
struct pinctrl_state *s)
|
2012-02-09 07:52:22 +07:00
|
|
|
{
|
2012-03-03 03:05:47 +07:00
|
|
|
return 0;
|
2012-02-09 07:52:22 +07:00
|
|
|
}
|
|
|
|
|
2012-04-16 23:51:00 +07:00
|
|
|
static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev)
|
|
|
|
{
|
2015-03-05 16:08:14 +07:00
|
|
|
return NULL;
|
2012-04-16 23:51:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void devm_pinctrl_put(struct pinctrl *p)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-14 03:27:59 +07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-02-10 01:47:48 +07:00
|
|
|
#endif /* CONFIG_PINCTRL */
|
2012-02-09 07:52:22 +07:00
|
|
|
|
2012-03-03 03:05:47 +07:00
|
|
|
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);
|
2015-04-27 23:04:05 +07:00
|
|
|
return ERR_CAST(s);
|
2012-03-03 03:05:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2012-04-16 23:51:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2012-07-30 23:38:33 +07:00
|
|
|
return ERR_CAST(s);
|
2012-04-16 23:51:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2012-03-03 03:05:47 +07:00
|
|
|
}
|
|
|
|
|
2012-02-09 07:52:22 +07:00
|
|
|
#endif /* __LINUX_PINCTRL_CONSUMER_H */
|