Gregory Bean | 1de238e | 2010-04-30 22:15:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Google, Inc. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3 | * Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved. |
Gregory Bean | 1de238e | 2010-04-30 22:15:16 -0700 | [diff] [blame] | 4 | * Author: Mike Lockwood <lockwood@android.com> |
| 5 | * |
| 6 | * This software is licensed under the terms of the GNU General Public |
| 7 | * License version 2, as published by the Free Software Foundation, and |
| 8 | * may be copied, distributed, and modified under those terms. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | */ |
| 16 | #ifndef __ASM_ARCH_MSM_GPIO_H |
| 17 | #define __ASM_ARCH_MSM_GPIO_H |
| 18 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 19 | #ifdef CONFIG_ARCH_MSM8X60 |
| 20 | #define ARCH_NR_GPIOS 512 |
| 21 | #endif |
Pavel Machek | 923a081 | 2010-06-02 11:11:12 -0700 | [diff] [blame] | 22 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 23 | #include <linux/interrupt.h> |
| 24 | #include <asm-generic/gpio.h> |
| 25 | #include <mach/irqs.h> |
| 26 | |
| 27 | #define FIRST_BOARD_GPIO NR_GPIO_IRQS |
| 28 | |
| 29 | extern struct irq_chip msm_gpio_irq_extn; |
| 30 | |
| 31 | static inline int gpio_get_value(unsigned gpio) |
| 32 | { |
| 33 | return __gpio_get_value(gpio); |
| 34 | } |
| 35 | |
| 36 | static inline void gpio_set_value(unsigned gpio, int value) |
| 37 | { |
| 38 | __gpio_set_value(gpio, value); |
| 39 | } |
| 40 | |
| 41 | static inline int gpio_cansleep(unsigned gpio) |
| 42 | { |
| 43 | return __gpio_cansleep(gpio); |
| 44 | } |
| 45 | |
| 46 | static inline int gpio_to_irq(unsigned gpio) |
| 47 | { |
| 48 | return __gpio_to_irq(gpio); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * struct msm_gpio - GPIO pin description |
| 53 | * @gpio_cfg - configuration bitmap, as per gpio_tlmm_config() |
| 54 | * @label - textual label |
| 55 | * |
| 56 | * Usually, GPIO's are operated by sets. |
| 57 | * This struct accumulate all GPIO information in single source |
| 58 | * and facilitete group operations provided by msm_gpios_xxx() |
| 59 | */ |
| 60 | struct msm_gpio { |
| 61 | u32 gpio_cfg; |
| 62 | const char *label; |
| 63 | }; |
| 64 | |
| 65 | /** |
| 66 | * msm_gpios_request_enable() - request and enable set of GPIOs |
| 67 | * |
| 68 | * Request and configure set of GPIO's |
| 69 | * In case of error, all operations rolled back. |
| 70 | * Return error code. |
| 71 | * |
| 72 | * @table: GPIO table |
| 73 | * @size: number of entries in @table |
| 74 | */ |
| 75 | int msm_gpios_request_enable(const struct msm_gpio *table, int size); |
| 76 | |
| 77 | /** |
| 78 | * msm_gpios_disable_free() - disable and free set of GPIOs |
| 79 | * |
| 80 | * @table: GPIO table |
| 81 | * @size: number of entries in @table |
| 82 | */ |
| 83 | void msm_gpios_disable_free(const struct msm_gpio *table, int size); |
| 84 | |
| 85 | /** |
| 86 | * msm_gpios_request() - request set of GPIOs |
| 87 | * In case of error, all operations rolled back. |
| 88 | * Return error code. |
| 89 | * |
| 90 | * @table: GPIO table |
| 91 | * @size: number of entries in @table |
| 92 | */ |
| 93 | int msm_gpios_request(const struct msm_gpio *table, int size); |
| 94 | |
| 95 | /** |
| 96 | * msm_gpios_free() - free set of GPIOs |
| 97 | * |
| 98 | * @table: GPIO table |
| 99 | * @size: number of entries in @table |
| 100 | */ |
| 101 | void msm_gpios_free(const struct msm_gpio *table, int size); |
| 102 | |
| 103 | /** |
| 104 | * msm_gpios_enable() - enable set of GPIOs |
| 105 | * In case of error, all operations rolled back. |
| 106 | * Return error code. |
| 107 | * |
| 108 | * @table: GPIO table |
| 109 | * @size: number of entries in @table |
| 110 | */ |
| 111 | int msm_gpios_enable(const struct msm_gpio *table, int size); |
| 112 | |
| 113 | /** |
| 114 | * msm_gpios_disable() - disable set of GPIOs |
| 115 | * |
| 116 | * @table: GPIO table |
| 117 | * @size: number of entries in @table |
| 118 | */ |
| 119 | int msm_gpios_disable(const struct msm_gpio *table, int size); |
| 120 | |
| 121 | /** |
| 122 | * msm_gpios_show_resume_irq() - show the interrupts that could have triggered |
| 123 | * resume |
| 124 | */ |
| 125 | void msm_gpio_show_resume_irq(void); |
| 126 | |
| 127 | /* GPIO TLMM (Top Level Multiplexing) Definitions */ |
| 128 | |
| 129 | /* GPIO TLMM: Function -- GPIO specific */ |
| 130 | |
| 131 | /* GPIO TLMM: Direction */ |
| 132 | enum { |
| 133 | GPIO_CFG_INPUT, |
| 134 | GPIO_CFG_OUTPUT, |
| 135 | }; |
| 136 | |
| 137 | /* GPIO TLMM: Pullup/Pulldown */ |
| 138 | enum { |
| 139 | GPIO_CFG_NO_PULL, |
| 140 | GPIO_CFG_PULL_DOWN, |
| 141 | GPIO_CFG_KEEPER, |
| 142 | GPIO_CFG_PULL_UP, |
| 143 | }; |
| 144 | |
| 145 | /* GPIO TLMM: Drive Strength */ |
| 146 | enum { |
| 147 | GPIO_CFG_2MA, |
| 148 | GPIO_CFG_4MA, |
| 149 | GPIO_CFG_6MA, |
| 150 | GPIO_CFG_8MA, |
| 151 | GPIO_CFG_10MA, |
| 152 | GPIO_CFG_12MA, |
| 153 | GPIO_CFG_14MA, |
| 154 | GPIO_CFG_16MA, |
| 155 | }; |
| 156 | |
| 157 | enum { |
| 158 | GPIO_CFG_ENABLE, |
| 159 | GPIO_CFG_DISABLE, |
| 160 | }; |
| 161 | |
| 162 | #define GPIO_CFG(gpio, func, dir, pull, drvstr) \ |
| 163 | ((((gpio) & 0x3FF) << 4) | \ |
| 164 | ((func) & 0xf) | \ |
| 165 | (((dir) & 0x1) << 14) | \ |
| 166 | (((pull) & 0x3) << 15) | \ |
| 167 | (((drvstr) & 0xF) << 17)) |
| 168 | |
| 169 | /** |
| 170 | * extract GPIO pin from bit-field used for gpio_tlmm_config |
| 171 | */ |
| 172 | #define GPIO_PIN(gpio_cfg) (((gpio_cfg) >> 4) & 0x3ff) |
| 173 | #define GPIO_FUNC(gpio_cfg) (((gpio_cfg) >> 0) & 0xf) |
| 174 | #define GPIO_DIR(gpio_cfg) (((gpio_cfg) >> 14) & 0x1) |
| 175 | #define GPIO_PULL(gpio_cfg) (((gpio_cfg) >> 15) & 0x3) |
| 176 | #define GPIO_DRVSTR(gpio_cfg) (((gpio_cfg) >> 17) & 0xf) |
| 177 | |
| 178 | int gpio_tlmm_config(unsigned config, unsigned disable); |
| 179 | |
| 180 | enum msm_tlmm_hdrive_tgt { |
| 181 | TLMM_HDRV_SDC4_CLK = 0, |
| 182 | TLMM_HDRV_SDC4_CMD, |
| 183 | TLMM_HDRV_SDC4_DATA, |
| 184 | TLMM_HDRV_SDC3_CLK, |
| 185 | TLMM_HDRV_SDC3_CMD, |
| 186 | TLMM_HDRV_SDC3_DATA, |
| 187 | TLMM_HDRV_SDC1_CLK, |
| 188 | TLMM_HDRV_SDC1_CMD, |
| 189 | TLMM_HDRV_SDC1_DATA, |
| 190 | }; |
| 191 | |
| 192 | enum msm_tlmm_pull_tgt { |
| 193 | TLMM_PULL_SDC4_CMD = 0, |
| 194 | TLMM_PULL_SDC4_DATA, |
| 195 | TLMM_PULL_SDC3_CLK, |
| 196 | TLMM_PULL_SDC3_CMD, |
| 197 | TLMM_PULL_SDC3_DATA, |
| 198 | TLMM_PULL_SDC1_CLK, |
| 199 | TLMM_PULL_SDC1_CMD, |
| 200 | TLMM_PULL_SDC1_DATA, |
| 201 | }; |
| 202 | |
| 203 | #ifdef CONFIG_MSM_V2_TLMM |
| 204 | void msm_tlmm_set_hdrive(enum msm_tlmm_hdrive_tgt tgt, int drv_str); |
| 205 | void msm_tlmm_set_pull(enum msm_tlmm_pull_tgt tgt, int pull); |
| 206 | |
| 207 | /* |
| 208 | * A GPIO can be set as a direct-connect IRQ. This can be used to bypass |
| 209 | * the normal summary-interrupt mechanism for those GPIO lines deemed to be |
| 210 | * higher priority or otherwise worthy of special treatment, but resources |
| 211 | * are limited: only a few DC interrupt lines are available. |
| 212 | * Care must be taken when usurping a GPIO in this manner, as the summary |
| 213 | * interrupt controller has no idea that the GPIO has been taken away from it. |
| 214 | * Clients can still register to receive the summary interrupt assigned |
| 215 | * to that GPIO, which will uninstall it as a direct connect IRQ with |
| 216 | * no warning. |
| 217 | * |
| 218 | * The irq passed to this function is the DC IRQ number, not the |
| 219 | * irq number seen by the scorpion when the interrupt triggers. For example, |
| 220 | * if 0 is specified, then when DC IRQ 0 triggers, the scorpion will see |
| 221 | * interrupt TLMM_MSM_DIR_CONN_IRQ_0. |
| 222 | * |
| 223 | * input_polarity parameter specifies when the gpio should raise the direct |
| 224 | * interrupt. A value of 0 means that it is active low, anything else means |
| 225 | * active high |
| 226 | * |
| 227 | */ |
| 228 | int msm_gpio_install_direct_irq(unsigned gpio, unsigned irq, |
| 229 | unsigned int input_polarity); |
| 230 | #else |
| 231 | static inline void msm_tlmm_set_hdrive(enum msm_tlmm_hdrive_tgt tgt, |
| 232 | int drv_str) {} |
| 233 | static inline void msm_tlmm_set_pull(enum msm_tlmm_pull_tgt tgt, int pull) {} |
| 234 | static inline int msm_gpio_install_direct_irq(unsigned gpio, unsigned irq, |
| 235 | unsigned int input_polarity) |
| 236 | { |
| 237 | return -ENOSYS; |
| 238 | } |
| 239 | #endif |
Pavel Machek | 923a081 | 2010-06-02 11:11:12 -0700 | [diff] [blame] | 240 | |
Gregory Bean | 1de238e | 2010-04-30 22:15:16 -0700 | [diff] [blame] | 241 | #endif /* __ASM_ARCH_MSM_GPIO_H */ |