Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Duy Truong | f3ac7b3 | 2013-02-13 01:07:28 -0800 | [diff] [blame] | 5 | * Copyright (c) 2009-2010, The Linux Foundation. All rights reserved. |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 6 | * |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in |
| 14 | * the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 20 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 21 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 23 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 24 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 27 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 | * SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Chandan Uddaraju | 14e57eb | 2010-06-28 12:11:06 -0700 | [diff] [blame] | 31 | #ifndef __PLATFORM_MSM7X30_GPIO_HW_H |
| 32 | #define __PLATFORM_MSM7X30_GPIO_HW_H |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 33 | |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 34 | #define MSM_GPIO1_BASE 0xAC001000 |
| 35 | #define MSM_GPIO2_BASE 0xAC101000 |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 36 | |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 37 | #define GPIO1_REG(off) (MSM_GPIO1_BASE + (off)) |
| 38 | #define GPIO2_REG(off) (MSM_GPIO2_BASE + 0x400 + (off)) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 39 | |
| 40 | /* output value */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 41 | #define GPIO_OUT_0 GPIO1_REG(0x00) /* gpio 15-0 */ |
| 42 | #define GPIO_OUT_1 GPIO2_REG(0x00) /* gpio 43-16 */ |
| 43 | #define GPIO_OUT_2 GPIO1_REG(0x04) /* gpio 67-44 */ |
| 44 | #define GPIO_OUT_3 GPIO1_REG(0x08) /* gpio 94-68 */ |
| 45 | #define GPIO_OUT_4 GPIO1_REG(0x0C) /* gpio 106-95 */ |
| 46 | #define GPIO_OUT_5 GPIO1_REG(0x50) /* gpio 133-107 */ |
| 47 | #define GPIO_OUT_6 GPIO1_REG(0xC4) /* gpio 150-134 */ |
| 48 | #define GPIO_OUT_7 GPIO1_REG(0x214) /* gpio 181-151 */ |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 49 | |
| 50 | /* same pin map as above, output enable */ |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 51 | #define GPIO_OE_0 GPIO1_REG(0x10) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 52 | #define GPIO_OE_1 GPIO2_REG(0x08) |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 53 | #define GPIO_OE_2 GPIO1_REG(0x14) |
| 54 | #define GPIO_OE_3 GPIO1_REG(0x18) |
| 55 | #define GPIO_OE_4 GPIO1_REG(0x1C) |
| 56 | #define GPIO_OE_5 GPIO1_REG(0x54) |
| 57 | #define GPIO_OE_6 GPIO1_REG(0xC8) |
| 58 | #define GPIO_OE_7 GPIO1_REG(0x218) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 59 | |
| 60 | /* same pin map as above, input read */ |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 61 | #define GPIO_IN_0 GPIO1_REG(0x34) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 62 | #define GPIO_IN_1 GPIO2_REG(0x20) |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 63 | #define GPIO_IN_2 GPIO1_REG(0x38) |
| 64 | #define GPIO_IN_3 GPIO1_REG(0x3C) |
| 65 | #define GPIO_IN_4 GPIO1_REG(0x40) |
| 66 | #define GPIO_IN_5 GPIO1_REG(0x44) |
| 67 | #define GPIO_IN_6 GPIO1_REG(0xCC) |
| 68 | #define GPIO_IN_7 GPIO1_REG(0x21C) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 69 | |
| 70 | /* same pin map as above, 1=edge 0=level interrup */ |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 71 | #define GPIO_INT_EDGE_0 GPIO1_REG(0x60) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 72 | #define GPIO_INT_EDGE_1 GPIO2_REG(0x50) |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 73 | #define GPIO_INT_EDGE_2 GPIO1_REG(0x64) |
| 74 | #define GPIO_INT_EDGE_3 GPIO1_REG(0x68) |
| 75 | #define GPIO_INT_EDGE_4 GPIO1_REG(0x6C) |
| 76 | #define GPIO_INT_EDGE_5 GPIO1_REG(0xC0) |
| 77 | #define GPIO_INT_EDGE_6 GPIO1_REG(0xD0) |
| 78 | #define GPIO_INT_EDGE_7 GPIO1_REG(0x240) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 79 | |
| 80 | /* same pin map as above, 1=positive 0=negative */ |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 81 | #define GPIO_INT_POS_0 GPIO1_REG(0x70) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 82 | #define GPIO_INT_POS_1 GPIO2_REG(0x58) |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 83 | #define GPIO_INT_POS_2 GPIO1_REG(0x74) |
| 84 | #define GPIO_INT_POS_3 GPIO1_REG(0x78) |
| 85 | #define GPIO_INT_POS_4 GPIO1_REG(0x7C) |
| 86 | #define GPIO_INT_POS_5 GPIO1_REG(0xBC) |
| 87 | #define GPIO_INT_POS_6 GPIO1_REG(0xD4) |
| 88 | #define GPIO_INT_POS_7 GPIO1_REG(0x228) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 89 | |
| 90 | /* same pin map as above, interrupt enable */ |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 91 | #define GPIO_INT_EN_0 GPIO1_REG(0x80) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 92 | #define GPIO_INT_EN_1 GPIO2_REG(0x60) |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 93 | #define GPIO_INT_EN_2 GPIO1_REG(0x84) |
| 94 | #define GPIO_INT_EN_3 GPIO1_REG(0x88) |
| 95 | #define GPIO_INT_EN_4 GPIO1_REG(0x8C) |
| 96 | #define GPIO_INT_EN_5 GPIO1_REG(0xB8) |
| 97 | #define GPIO_INT_EN_6 GPIO1_REG(0xD8) |
| 98 | #define GPIO_INT_EN_7 GPIO1_REG(0x22C) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 99 | |
| 100 | /* same pin map as above, write 1 to clear interrupt */ |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 101 | #define GPIO_INT_CLEAR_0 GPIO1_REG(0x90) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 102 | #define GPIO_INT_CLEAR_1 GPIO2_REG(0x68) |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 103 | #define GPIO_INT_CLEAR_2 GPIO1_REG(0x94) |
| 104 | #define GPIO_INT_CLEAR_3 GPIO1_REG(0x98) |
| 105 | #define GPIO_INT_CLEAR_4 GPIO1_REG(0x9C) |
| 106 | #define GPIO_INT_CLEAR_5 GPIO1_REG(0xB4) |
| 107 | #define GPIO_INT_CLEAR_6 GPIO1_REG(0xDC) |
| 108 | #define GPIO_INT_CLEAR_7 GPIO1_REG(0x230) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 109 | |
| 110 | /* same pin map as above, 1=interrupt pending */ |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 111 | #define GPIO_INT_STATUS_0 GPIO1_REG(0xA0) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 112 | #define GPIO_INT_STATUS_1 GPIO2_REG(0x70) |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 113 | #define GPIO_INT_STATUS_2 GPIO1_REG(0xA4) |
| 114 | #define GPIO_INT_STATUS_3 GPIO1_REG(0xA8) |
| 115 | #define GPIO_INT_STATUS_4 GPIO1_REG(0xAC) |
| 116 | #define GPIO_INT_STATUS_5 GPIO1_REG(0xB0) |
| 117 | #define GPIO_INT_STATUS_6 GPIO1_REG(0xE0) |
| 118 | #define GPIO_INT_STATUS_7 GPIO1_REG(0x234) |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 119 | |
Chandan Uddaraju | 14e57eb | 2010-06-28 12:11:06 -0700 | [diff] [blame] | 120 | #define GPIO_OUT_VAL_REG_BASE 0xABC00000 |
| 121 | #define GPIO_ALT_FUNC_PAGE_REG (GPIO_OUT_VAL_REG_BASE + 0x20) |
| 122 | #define GPIO_ALT_FUNC_CFG_REG (GPIO_OUT_VAL_REG_BASE + 0x24) |
| 123 | |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 124 | /* GPIO TLMM: Direction */ |
| 125 | #define GPIO_INPUT 0 |
| 126 | #define GPIO_OUTPUT 1 |
| 127 | |
| 128 | /* GPIO TLMM: Pullup/Pulldown */ |
| 129 | #define GPIO_NO_PULL 0 |
| 130 | #define GPIO_PULL_DOWN 1 |
| 131 | #define GPIO_KEEPER 2 |
| 132 | #define GPIO_PULL_UP 3 |
| 133 | |
| 134 | /* GPIO TLMM: Drive Strength */ |
| 135 | #define GPIO_2MA 0 |
| 136 | #define GPIO_4MA 1 |
| 137 | #define GPIO_6MA 2 |
| 138 | #define GPIO_8MA 3 |
| 139 | #define GPIO_10MA 4 |
| 140 | #define GPIO_12MA 5 |
| 141 | #define GPIO_14MA 6 |
| 142 | #define GPIO_16MA 7 |
| 143 | |
Chandan Uddaraju | c009e4d | 2010-09-08 17:06:45 -0700 | [diff] [blame] | 144 | #define GPIO38_GPIO_CNTRL 0x175 |
| 145 | |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 146 | /* GPIO TLMM: Status */ |
| 147 | #define GPIO_ENABLE 0 |
| 148 | #define GPIO_DISABLE 1 |
| 149 | |
| 150 | #define GPIO_CFG(gpio, func, dir, pull, drvstr) \ |
| 151 | ((((gpio) & 0x3FF) << 4) | \ |
| 152 | ((func) & 0xf) | \ |
| 153 | (((dir) & 0x1) << 14) | \ |
| 154 | (((pull) & 0x3) << 15) | \ |
| 155 | (((drvstr) & 0xF) << 17)) |
| 156 | |
| 157 | /** |
| 158 | * struct msm_gpio - GPIO pin description |
| 159 | * @gpio_cfg - configuration bitmap, as per gpio_tlmm_config() |
| 160 | * @label - textual label |
| 161 | * |
| 162 | * Usually, GPIO's are operated by sets. |
| 163 | * This struct accumulate all GPIO information in single source |
| 164 | * and facilitete group operations provided by msm_gpios_xxx() |
| 165 | */ |
| 166 | struct msm_gpio { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 167 | unsigned gpio_cfg; |
| 168 | const char *label; |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | /** |
| 172 | * extract GPIO pin from bit-field used for gpio_tlmm_config |
| 173 | */ |
| 174 | #define GPIO_PIN(gpio_cfg) (((gpio_cfg) >> 4) & 0x3ff) |
| 175 | #define GPIO_FUNC(gpio_cfg) (((gpio_cfg) >> 0) & 0xf) |
| 176 | #define GPIO_DIR(gpio_cfg) (((gpio_cfg) >> 14) & 0x1) |
| 177 | #define GPIO_PULL(gpio_cfg) (((gpio_cfg) >> 15) & 0x3) |
| 178 | #define GPIO_DRVSTR(gpio_cfg) (((gpio_cfg) >> 17) & 0xf) |
| 179 | |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 180 | #endif |