2012-06-30 16:12:56 +00:00
|
|
|
#ifndef __GPIO_H
|
|
|
|
#define __GPIO_H
|
|
|
|
|
2015-08-06 10:57:13 +00:00
|
|
|
#ifdef CONFIG_GENERIC_GPIO
|
|
|
|
void gpio_set_value(unsigned gpio, int value);
|
|
|
|
int gpio_get_value(unsigned gpio);
|
|
|
|
int gpio_direction_output(unsigned gpio, int value);
|
|
|
|
int gpio_direction_input(unsigned gpio);
|
|
|
|
#else
|
|
|
|
static inline void gpio_set_value(unsigned gpio, int value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
static inline int gpio_get_value(unsigned gpio)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static inline int gpio_direction_output(unsigned gpio, int value)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
static inline int gpio_direction_input(unsigned gpio)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
2012-06-30 16:12:56 +00:00
|
|
|
|
2014-11-28 06:42:42 +00:00
|
|
|
#define ARCH_NR_GPIOS 256
|
|
|
|
|
|
|
|
static inline int gpio_is_valid(int gpio)
|
|
|
|
{
|
|
|
|
if (gpio < 0)
|
|
|
|
return 0;
|
|
|
|
if (gpio < ARCH_NR_GPIOS)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-21 20:11:23 +00:00
|
|
|
#define GPIOF_DIR_OUT (0 << 0)
|
|
|
|
#define GPIOF_DIR_IN (1 << 0)
|
2013-11-09 13:24:07 +00:00
|
|
|
|
2013-11-21 20:11:24 +00:00
|
|
|
#define GPIOF_INIT_LOW (0 << 1)
|
|
|
|
#define GPIOF_INIT_HIGH (1 << 1)
|
|
|
|
|
|
|
|
#define GPIOF_IN (GPIOF_DIR_IN)
|
|
|
|
#define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
|
|
|
|
#define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct gpio - a structure describing a GPIO with configuration
|
|
|
|
* @gpio: the GPIO number
|
|
|
|
* @flags: GPIO configuration as specified by GPIOF_*
|
|
|
|
* @label: a literal description string of this GPIO
|
|
|
|
*/
|
|
|
|
struct gpio {
|
|
|
|
unsigned gpio;
|
|
|
|
unsigned long flags;
|
|
|
|
const char *label;
|
|
|
|
};
|
|
|
|
|
2012-12-21 13:26:08 +00:00
|
|
|
#ifndef CONFIG_GPIOLIB
|
2012-06-30 16:12:56 +00:00
|
|
|
static inline int gpio_request(unsigned gpio, const char *label)
|
|
|
|
{
|
2013-05-12 06:57:16 +00:00
|
|
|
return 0;
|
2012-06-30 16:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void gpio_free(unsigned gpio)
|
|
|
|
{
|
|
|
|
}
|
2013-11-21 20:11:24 +00:00
|
|
|
|
|
|
|
static inline int gpio_request_one(unsigned gpio,
|
|
|
|
unsigned long flags, const char *label)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int gpio_request_array(const struct gpio *array, size_t num)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void gpio_free_array(const struct gpio *array, size_t num)
|
|
|
|
{
|
|
|
|
/* GPIO can never have been requested */
|
|
|
|
WARN_ON(1);
|
|
|
|
}
|
2012-12-21 13:26:08 +00:00
|
|
|
#else
|
|
|
|
int gpio_request(unsigned gpio, const char *label);
|
|
|
|
void gpio_free(unsigned gpio);
|
2013-11-21 20:11:24 +00:00
|
|
|
int gpio_request_one(unsigned gpio, unsigned long flags, const char *label);
|
|
|
|
int gpio_request_array(const struct gpio *array, size_t num);
|
|
|
|
void gpio_free_array(const struct gpio *array, size_t num);
|
2012-12-21 13:26:08 +00:00
|
|
|
#endif
|
2012-09-03 08:18:08 +00:00
|
|
|
|
|
|
|
struct gpio_chip;
|
|
|
|
|
|
|
|
struct gpio_ops {
|
2012-12-21 13:26:08 +00:00
|
|
|
int (*request)(struct gpio_chip *chip, unsigned offset);
|
|
|
|
void (*free)(struct gpio_chip *chip, unsigned offset);
|
2012-09-03 08:18:08 +00:00
|
|
|
int (*direction_input)(struct gpio_chip *chip, unsigned offset);
|
|
|
|
int (*direction_output)(struct gpio_chip *chip, unsigned offset, int value);
|
2013-11-09 13:24:07 +00:00
|
|
|
int (*get_direction)(struct gpio_chip *chip, unsigned offset);
|
2012-09-03 08:18:08 +00:00
|
|
|
int (*get)(struct gpio_chip *chip, unsigned offset);
|
|
|
|
void (*set)(struct gpio_chip *chip, unsigned offset, int value);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gpio_chip {
|
|
|
|
struct device_d *dev;
|
|
|
|
|
|
|
|
int base;
|
|
|
|
int ngpio;
|
|
|
|
|
|
|
|
struct gpio_ops *ops;
|
|
|
|
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
int gpiochip_add(struct gpio_chip *chip);
|
2013-03-11 09:26:36 +00:00
|
|
|
void gpiochip_remove(struct gpio_chip *chip);
|
2012-09-03 08:18:08 +00:00
|
|
|
|
|
|
|
int gpio_get_num(struct device_d *dev, int gpio);
|
|
|
|
|
2012-06-30 16:12:56 +00:00
|
|
|
#endif /* __GPIO_H */
|