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 <[email protected]> 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 */ 21 struct pinctrl; 22 struct pinctrl_state; 23 24 #ifdef CONFIG_PINCTRL 25 26 /* External interface to pin control */ 27 extern int pinctrl_request_gpio(unsigned gpio); 28 extern void pinctrl_free_gpio(unsigned gpio); 29 extern int pinctrl_gpio_direction_input(unsigned gpio); 30 extern int pinctrl_gpio_direction_output(unsigned gpio); 31 32 extern struct pinctrl * __must_check pinctrl_get(struct device *dev); 33 extern void pinctrl_put(struct pinctrl *p); 34 extern struct pinctrl_state * __must_check pinctrl_lookup_state( 35 struct pinctrl *p, 36 const char *name); 37 extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s); 38 39 #else /* !CONFIG_PINCTRL */ 40 41 static inline int pinctrl_request_gpio(unsigned gpio) 42 { 43 return 0; 44 } 45 46 static inline void pinctrl_free_gpio(unsigned gpio) 47 { 48 } 49 50 static inline int pinctrl_gpio_direction_input(unsigned gpio) 51 { 52 return 0; 53 } 54 55 static inline int pinctrl_gpio_direction_output(unsigned gpio) 56 { 57 return 0; 58 } 59 60 static inline struct pinctrl * __must_check pinctrl_get(struct device *dev) 61 { 62 return NULL; 63 } 64 65 static inline void pinctrl_put(struct pinctrl *p) 66 { 67 } 68 69 static inline struct pinctrl_state * __must_check pinctrl_lookup_state( 70 struct pinctrl *p, 71 const char *name) 72 { 73 return NULL; 74 } 75 76 static inline int pinctrl_select_state(struct pinctrl *p, 77 struct pinctrl_state *s) 78 { 79 return 0; 80 } 81 82 #endif /* CONFIG_PINCTRL */ 83 84 static 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 110 static 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 118 extern int pin_config_get(const char *dev_name, const char *name, 119 unsigned long *config); 120 extern int pin_config_set(const char *dev_name, const char *name, 121 unsigned long config); 122 extern int pin_config_group_get(const char *dev_name, 123 const char *pin_group, 124 unsigned long *config); 125 extern int pin_config_group_set(const char *dev_name, 126 const char *pin_group, 127 unsigned long config); 128 129 #else 130 131 static inline int pin_config_get(const char *dev_name, const char *name, 132 unsigned long *config) 133 { 134 return 0; 135 } 136 137 static inline int pin_config_set(const char *dev_name, const char *name, 138 unsigned long config) 139 { 140 return 0; 141 } 142 143 static 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 150 static 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 */ 160