Richard Genoud | 84130aa | 2014-05-13 20:20:43 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Helpers for controlling modem lines via GPIO |
| 3 | * |
| 4 | * Copyright (C) 2014 Paratronic S.A. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #ifndef __SERIAL_MCTRL_GPIO__ |
| 19 | #define __SERIAL_MCTRL_GPIO__ |
| 20 | |
| 21 | #include <linux/err.h> |
| 22 | #include <linux/device.h> |
| 23 | #include <linux/gpio/consumer.h> |
| 24 | |
| 25 | enum mctrl_gpio_idx { |
| 26 | UART_GPIO_CTS, |
| 27 | UART_GPIO_DSR, |
| 28 | UART_GPIO_DCD, |
| 29 | UART_GPIO_RNG, |
| 30 | UART_GPIO_RI = UART_GPIO_RNG, |
| 31 | UART_GPIO_RTS, |
| 32 | UART_GPIO_DTR, |
| 33 | UART_GPIO_OUT1, |
| 34 | UART_GPIO_OUT2, |
| 35 | UART_GPIO_MAX, |
| 36 | }; |
| 37 | |
| 38 | /* |
| 39 | * Opaque descriptor for modem lines controlled by GPIOs |
| 40 | */ |
| 41 | struct mctrl_gpios; |
| 42 | |
| 43 | #ifdef CONFIG_GPIOLIB |
| 44 | |
| 45 | /* |
| 46 | * Set state of the modem control output lines via GPIOs. |
| 47 | */ |
| 48 | void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl); |
| 49 | |
| 50 | /* |
| 51 | * Get state of the modem control output lines from GPIOs. |
| 52 | * The mctrl flags are updated and returned. |
| 53 | */ |
| 54 | unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl); |
| 55 | |
| 56 | /* |
| 57 | * Returns the associated struct gpio_desc to the modem line gidx |
| 58 | */ |
| 59 | struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios, |
| 60 | enum mctrl_gpio_idx gidx); |
| 61 | |
| 62 | /* |
| 63 | * Request and set direction of modem control lines GPIOs. |
| 64 | * devm_* functions are used, so there's no need to call mctrl_gpio_free(). |
| 65 | * Returns a pointer to the allocated mctrl structure if ok, -ENOMEM on |
| 66 | * allocation error. |
| 67 | */ |
| 68 | struct mctrl_gpios *mctrl_gpio_init(struct device *dev, unsigned int idx); |
| 69 | |
| 70 | /* |
| 71 | * Free the mctrl_gpios structure. |
| 72 | * Normally, this function will not be called, as the GPIOs will |
| 73 | * be disposed of by the resource management code. |
| 74 | */ |
| 75 | void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios); |
| 76 | |
| 77 | #else /* GPIOLIB */ |
| 78 | |
| 79 | static inline |
| 80 | void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl) |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | static inline |
| 85 | unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl) |
| 86 | { |
| 87 | return *mctrl; |
| 88 | } |
| 89 | |
| 90 | static inline |
| 91 | struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios, |
| 92 | enum mctrl_gpio_idx gidx) |
| 93 | { |
| 94 | return ERR_PTR(-ENOSYS); |
| 95 | } |
| 96 | |
| 97 | static inline |
| 98 | struct mctrl_gpios *mctrl_gpio_init(struct device *dev, unsigned int idx) |
| 99 | { |
| 100 | return ERR_PTR(-ENOSYS); |
| 101 | } |
| 102 | |
| 103 | static inline |
| 104 | void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios) |
| 105 | { |
| 106 | } |
| 107 | |
| 108 | #endif /* GPIOLIB */ |
| 109 | |
| 110 | #endif |