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