at v3.4 3.5 kB view raw
1/* 2 * Consumer interface the pin control subsystem 3 * 4 * Copyright (C) 2012 ST-Ericsson SA 5 * Written on behalf of Linaro for ST-Ericsson 6 * Based on bits of regulator core, gpio core and clk core 7 * 8 * Author: Linus Walleij <linus.walleij@linaro.org> 9 * 10 * License terms: GNU General Public License (GPL) version 2 11 */ 12#ifndef __LINUX_PINCTRL_CONSUMER_H 13#define __LINUX_PINCTRL_CONSUMER_H 14 15#include <linux/err.h> 16#include <linux/list.h> 17#include <linux/seq_file.h> 18#include "pinctrl-state.h" 19 20/* This struct is private to the core and should be regarded as a cookie */ 21struct pinctrl; 22struct pinctrl_state; 23 24#ifdef CONFIG_PINCTRL 25 26/* External interface to pin control */ 27extern int pinctrl_request_gpio(unsigned gpio); 28extern void pinctrl_free_gpio(unsigned gpio); 29extern int pinctrl_gpio_direction_input(unsigned gpio); 30extern int pinctrl_gpio_direction_output(unsigned gpio); 31 32extern struct pinctrl * __must_check pinctrl_get(struct device *dev); 33extern void pinctrl_put(struct pinctrl *p); 34extern struct pinctrl_state * __must_check pinctrl_lookup_state( 35 struct pinctrl *p, 36 const char *name); 37extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s); 38 39#else /* !CONFIG_PINCTRL */ 40 41static inline int pinctrl_request_gpio(unsigned gpio) 42{ 43 return 0; 44} 45 46static inline void pinctrl_free_gpio(unsigned gpio) 47{ 48} 49 50static inline int pinctrl_gpio_direction_input(unsigned gpio) 51{ 52 return 0; 53} 54 55static inline int pinctrl_gpio_direction_output(unsigned gpio) 56{ 57 return 0; 58} 59 60static inline struct pinctrl * __must_check pinctrl_get(struct device *dev) 61{ 62 return NULL; 63} 64 65static inline void pinctrl_put(struct pinctrl *p) 66{ 67} 68 69static inline struct pinctrl_state * __must_check pinctrl_lookup_state( 70 struct pinctrl *p, 71 const char *name) 72{ 73 return NULL; 74} 75 76static inline int pinctrl_select_state(struct pinctrl *p, 77 struct pinctrl_state *s) 78{ 79 return 0; 80} 81 82#endif /* CONFIG_PINCTRL */ 83 84static inline struct pinctrl * __must_check pinctrl_get_select( 85 struct device *dev, const char *name) 86{ 87 struct pinctrl *p; 88 struct pinctrl_state *s; 89 int ret; 90 91 p = pinctrl_get(dev); 92 if (IS_ERR(p)) 93 return p; 94 95 s = pinctrl_lookup_state(p, name); 96 if (IS_ERR(s)) { 97 pinctrl_put(p); 98 return ERR_PTR(PTR_ERR(s)); 99 } 100 101 ret = pinctrl_select_state(p, s); 102 if (ret < 0) { 103 pinctrl_put(p); 104 return ERR_PTR(ret); 105 } 106 107 return p; 108} 109 110static inline struct pinctrl * __must_check pinctrl_get_select_default( 111 struct device *dev) 112{ 113 return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT); 114} 115 116#ifdef CONFIG_PINCONF 117 118extern int pin_config_get(const char *dev_name, const char *name, 119 unsigned long *config); 120extern int pin_config_set(const char *dev_name, const char *name, 121 unsigned long config); 122extern int pin_config_group_get(const char *dev_name, 123 const char *pin_group, 124 unsigned long *config); 125extern int pin_config_group_set(const char *dev_name, 126 const char *pin_group, 127 unsigned long config); 128 129#else 130 131static inline int pin_config_get(const char *dev_name, const char *name, 132 unsigned long *config) 133{ 134 return 0; 135} 136 137static inline int pin_config_set(const char *dev_name, const char *name, 138 unsigned long config) 139{ 140 return 0; 141} 142 143static inline int pin_config_group_get(const char *dev_name, 144 const char *pin_group, 145 unsigned long *config) 146{ 147 return 0; 148} 149 150static inline int pin_config_group_set(const char *dev_name, 151 const char *pin_group, 152 unsigned long config) 153{ 154 return 0; 155} 156 157#endif 158 159#endif /* __LINUX_PINCTRL_CONSUMER_H */