linux/include/linux/pinctrl/consumer.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0-only */
   2/*
   3 * Consumer interface the pin control subsystem
   4 *
   5 * Copyright (C) 2012 ST-Ericsson SA
   6 * Written on behalf of Linaro for ST-Ericsson
   7 * Based on bits of regulator core, gpio core and clk core
   8 *
   9 * Author: Linus Walleij <linus.walleij@linaro.org>
  10 */
  11#ifndef __LINUX_PINCTRL_CONSUMER_H
  12#define __LINUX_PINCTRL_CONSUMER_H
  13
  14#include <linux/err.h>
  15#include <linux/list.h>
  16#include <linux/seq_file.h>
  17#include <linux/pinctrl/pinctrl-state.h>
  18
  19/* This struct is private to the core and should be regarded as a cookie */
  20struct pinctrl;
  21struct pinctrl_state;
  22struct device;
  23
  24#ifdef CONFIG_PINCTRL
  25
  26/* External interface to pin control */
  27extern bool pinctrl_gpio_can_use_line(unsigned gpio);
  28extern int pinctrl_gpio_request(unsigned gpio);
  29extern void pinctrl_gpio_free(unsigned gpio);
  30extern int pinctrl_gpio_direction_input(unsigned gpio);
  31extern int pinctrl_gpio_direction_output(unsigned gpio);
  32extern int pinctrl_gpio_set_config(unsigned gpio, unsigned long config);
  33
  34extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
  35extern void pinctrl_put(struct pinctrl *p);
  36extern struct pinctrl_state * __must_check pinctrl_lookup_state(
  37                                                        struct pinctrl *p,
  38                                                        const char *name);
  39extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s);
  40
  41extern struct pinctrl * __must_check devm_pinctrl_get(struct device *dev);
  42extern void devm_pinctrl_put(struct pinctrl *p);
  43extern int pinctrl_select_default_state(struct device *dev);
  44
  45#ifdef CONFIG_PM
  46extern int pinctrl_pm_select_default_state(struct device *dev);
  47extern int pinctrl_pm_select_sleep_state(struct device *dev);
  48extern int pinctrl_pm_select_idle_state(struct device *dev);
  49#else
  50static inline int pinctrl_pm_select_default_state(struct device *dev)
  51{
  52        return 0;
  53}
  54static inline int pinctrl_pm_select_sleep_state(struct device *dev)
  55{
  56        return 0;
  57}
  58static inline int pinctrl_pm_select_idle_state(struct device *dev)
  59{
  60        return 0;
  61}
  62#endif
  63
  64#else /* !CONFIG_PINCTRL */
  65
  66static inline bool pinctrl_gpio_can_use_line(unsigned gpio)
  67{
  68        return true;
  69}
  70
  71static inline int pinctrl_gpio_request(unsigned gpio)
  72{
  73        return 0;
  74}
  75
  76static inline void pinctrl_gpio_free(unsigned gpio)
  77{
  78}
  79
  80static inline int pinctrl_gpio_direction_input(unsigned gpio)
  81{
  82        return 0;
  83}
  84
  85static inline int pinctrl_gpio_direction_output(unsigned gpio)
  86{
  87        return 0;
  88}
  89
  90static inline int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
  91{
  92        return 0;
  93}
  94
  95static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
  96{
  97        return NULL;
  98}
  99
 100static inline void pinctrl_put(struct pinctrl *p)
 101{
 102}
 103
 104static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
 105                                                        struct pinctrl *p,
 106                                                        const char *name)
 107{
 108        return NULL;
 109}
 110
 111static inline int pinctrl_select_state(struct pinctrl *p,
 112                                       struct pinctrl_state *s)
 113{
 114        return 0;
 115}
 116
 117static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev)
 118{
 119        return NULL;
 120}
 121
 122static inline void devm_pinctrl_put(struct pinctrl *p)
 123{
 124}
 125
 126static inline int pinctrl_select_default_state(struct device *dev)
 127{
 128        return 0;
 129}
 130
 131static inline int pinctrl_pm_select_default_state(struct device *dev)
 132{
 133        return 0;
 134}
 135
 136static inline int pinctrl_pm_select_sleep_state(struct device *dev)
 137{
 138        return 0;
 139}
 140
 141static inline int pinctrl_pm_select_idle_state(struct device *dev)
 142{
 143        return 0;
 144}
 145
 146#endif /* CONFIG_PINCTRL */
 147
 148static inline struct pinctrl * __must_check pinctrl_get_select(
 149                                        struct device *dev, const char *name)
 150{
 151        struct pinctrl *p;
 152        struct pinctrl_state *s;
 153        int ret;
 154
 155        p = pinctrl_get(dev);
 156        if (IS_ERR(p))
 157                return p;
 158
 159        s = pinctrl_lookup_state(p, name);
 160        if (IS_ERR(s)) {
 161                pinctrl_put(p);
 162                return ERR_CAST(s);
 163        }
 164
 165        ret = pinctrl_select_state(p, s);
 166        if (ret < 0) {
 167                pinctrl_put(p);
 168                return ERR_PTR(ret);
 169        }
 170
 171        return p;
 172}
 173
 174static inline struct pinctrl * __must_check pinctrl_get_select_default(
 175                                        struct device *dev)
 176{
 177        return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
 178}
 179
 180static inline struct pinctrl * __must_check devm_pinctrl_get_select(
 181                                        struct device *dev, const char *name)
 182{
 183        struct pinctrl *p;
 184        struct pinctrl_state *s;
 185        int ret;
 186
 187        p = devm_pinctrl_get(dev);
 188        if (IS_ERR(p))
 189                return p;
 190
 191        s = pinctrl_lookup_state(p, name);
 192        if (IS_ERR(s)) {
 193                devm_pinctrl_put(p);
 194                return ERR_CAST(s);
 195        }
 196
 197        ret = pinctrl_select_state(p, s);
 198        if (ret < 0) {
 199                devm_pinctrl_put(p);
 200                return ERR_PTR(ret);
 201        }
 202
 203        return p;
 204}
 205
 206static inline struct pinctrl * __must_check devm_pinctrl_get_select_default(
 207                                        struct device *dev)
 208{
 209        return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
 210}
 211
 212#endif /* __LINUX_PINCTRL_CONSUMER_H */
 213