Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 5 | * Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved. |
| 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 | |
| 31 | #include <debug.h> |
| 32 | #include <reg.h> |
| 33 | #include <platform/iomap.h> |
| 34 | #include <dev/gpio.h> |
| 35 | |
| 36 | #include "gpio_hw.h" |
| 37 | |
| 38 | typedef struct gpioregs gpioregs; |
| 39 | |
| 40 | struct gpioregs |
| 41 | { |
| 42 | unsigned out; |
| 43 | unsigned in; |
| 44 | unsigned int_status; |
| 45 | unsigned int_clear; |
| 46 | unsigned int_en; |
| 47 | unsigned int_edge; |
| 48 | unsigned int_pos; |
| 49 | unsigned oe; |
| 50 | }; |
| 51 | |
| 52 | static gpioregs GPIO_REGS[] = { |
| 53 | { |
| 54 | .out = GPIO_OUT_0, |
| 55 | .in = GPIO_IN_0, |
| 56 | .int_status = GPIO_INT_STATUS_0, |
| 57 | .int_clear = GPIO_INT_CLEAR_0, |
| 58 | .int_en = GPIO_INT_EN_0, |
| 59 | .int_edge = GPIO_INT_EDGE_0, |
| 60 | .int_pos = GPIO_INT_POS_0, |
| 61 | .oe = GPIO_OE_0, |
| 62 | }, |
| 63 | { |
| 64 | .out = GPIO_OUT_1, |
| 65 | .in = GPIO_IN_1, |
| 66 | .int_status = GPIO_INT_STATUS_1, |
| 67 | .int_clear = GPIO_INT_CLEAR_1, |
| 68 | .int_en = GPIO_INT_EN_1, |
| 69 | .int_edge = GPIO_INT_EDGE_1, |
| 70 | .int_pos = GPIO_INT_POS_1, |
| 71 | .oe = GPIO_OE_1, |
| 72 | }, |
| 73 | { |
| 74 | .out = GPIO_OUT_2, |
| 75 | .in = GPIO_IN_2, |
| 76 | .int_status = GPIO_INT_STATUS_2, |
| 77 | .int_clear = GPIO_INT_CLEAR_2, |
| 78 | .int_en = GPIO_INT_EN_2, |
| 79 | .int_edge = GPIO_INT_EDGE_2, |
| 80 | .int_pos = GPIO_INT_POS_2, |
| 81 | .oe = GPIO_OE_2, |
| 82 | }, |
| 83 | { |
| 84 | .out = GPIO_OUT_3, |
| 85 | .in = GPIO_IN_3, |
| 86 | .int_status = GPIO_INT_STATUS_3, |
| 87 | .int_clear = GPIO_INT_CLEAR_3, |
| 88 | .int_en = GPIO_INT_EN_3, |
| 89 | .int_edge = GPIO_INT_EDGE_3, |
| 90 | .int_pos = GPIO_INT_POS_3, |
| 91 | .oe = GPIO_OE_3, |
| 92 | }, |
| 93 | { |
| 94 | .out = GPIO_OUT_4, |
| 95 | .in = GPIO_IN_4, |
| 96 | .int_status = GPIO_INT_STATUS_4, |
| 97 | .int_clear = GPIO_INT_CLEAR_4, |
| 98 | .int_en = GPIO_INT_EN_4, |
| 99 | .int_edge = GPIO_INT_EDGE_4, |
| 100 | .int_pos = GPIO_INT_POS_4, |
| 101 | .oe = GPIO_OE_4, |
| 102 | }, |
| 103 | { |
| 104 | .out = GPIO_OUT_5, |
| 105 | .in = GPIO_IN_5, |
| 106 | .int_status = GPIO_INT_STATUS_5, |
| 107 | .int_clear = GPIO_INT_CLEAR_5, |
| 108 | .int_en = GPIO_INT_EN_5, |
| 109 | .int_edge = GPIO_INT_EDGE_5, |
| 110 | .int_pos = GPIO_INT_POS_5, |
| 111 | .oe = GPIO_OE_5, |
| 112 | }, |
| 113 | { |
| 114 | .out = GPIO_OUT_6, |
| 115 | .in = GPIO_IN_6, |
| 116 | .int_status = GPIO_INT_STATUS_6, |
| 117 | .int_clear = GPIO_INT_CLEAR_6, |
| 118 | .int_en = GPIO_INT_EN_6, |
| 119 | .int_edge = GPIO_INT_EDGE_6, |
| 120 | .int_pos = GPIO_INT_POS_6, |
| 121 | .oe = GPIO_OE_6, |
| 122 | }, |
| 123 | { |
| 124 | .out = GPIO_OUT_7, |
| 125 | .in = GPIO_IN_7, |
| 126 | .int_status = GPIO_INT_STATUS_7, |
| 127 | .int_clear = GPIO_INT_CLEAR_7, |
| 128 | .int_en = GPIO_INT_EN_7, |
| 129 | .int_edge = GPIO_INT_EDGE_7, |
| 130 | .int_pos = GPIO_INT_POS_7, |
| 131 | .oe = GPIO_OE_7, |
| 132 | }, |
| 133 | }; |
| 134 | |
| 135 | static gpioregs *find_gpio(unsigned n, unsigned *bit) |
| 136 | { |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 137 | if(n > 150) { |
| 138 | *bit = 1 << (n - 151); |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 139 | return GPIO_REGS + 7; |
| 140 | } |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 141 | if(n > 133) { |
| 142 | *bit = 1 << (n - 134); |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 143 | return GPIO_REGS + 6; |
| 144 | } |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 145 | if(n > 106) { |
| 146 | *bit = 1 << (n - 107); |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 147 | return GPIO_REGS + 5; |
| 148 | } |
| 149 | if(n > 94) { |
| 150 | *bit = 1 << (n - 95); |
| 151 | return GPIO_REGS + 4; |
| 152 | } |
| 153 | if(n > 67) { |
| 154 | *bit = 1 << (n - 68); |
| 155 | return GPIO_REGS + 3; |
| 156 | } |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 157 | if(n > 43) { |
| 158 | *bit = 1 << (n - 44); |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 159 | return GPIO_REGS + 2; |
| 160 | } |
| 161 | if(n > 15) { |
| 162 | *bit = 1 << (n - 16); |
| 163 | return GPIO_REGS + 1; |
| 164 | } |
| 165 | *bit = 1 << n; |
| 166 | return GPIO_REGS + 0; |
| 167 | } |
| 168 | |
| 169 | int gpio_config(unsigned n, unsigned flags) |
| 170 | { |
| 171 | gpioregs *r; |
| 172 | unsigned b; |
| 173 | unsigned v; |
| 174 | |
| 175 | if ((r = find_gpio(n, &b)) == 0) |
| 176 | return -1; |
| 177 | |
| 178 | v = readl(r->oe); |
| 179 | if (flags & GPIO_OUTPUT) { |
| 180 | writel(v | b, r->oe); |
| 181 | } else { |
| 182 | writel(v & (~b), r->oe); |
| 183 | } |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | void gpio_set(unsigned n, unsigned on) |
| 188 | { |
| 189 | gpioregs *r; |
| 190 | unsigned b; |
| 191 | unsigned v; |
| 192 | |
| 193 | if((r = find_gpio(n, &b)) == 0) return; |
| 194 | |
| 195 | v = readl(r->out); |
| 196 | if(on) { |
| 197 | writel(v | b, r->out); |
| 198 | } else { |
| 199 | writel(v & (~b), r->out); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | int gpio_get(unsigned n) |
| 204 | { |
| 205 | gpioregs *r; |
| 206 | unsigned b; |
| 207 | |
| 208 | if((r = find_gpio(n, &b)) == 0) return 0; |
| 209 | |
| 210 | return (readl(r->in) & b) ? 1 : 0; |
| 211 | } |
| 212 | |
Chandan Uddaraju | 14e57eb | 2010-06-28 12:11:06 -0700 | [diff] [blame] | 213 | void platform_config_interleaved_mode_gpios(void) |
| 214 | { |
| 215 | /* configure EB2_CS1 through GPIO86 */ |
| 216 | writel (GPIO_ALT_FUNC_PAGE_REG, 0x56); |
| 217 | writel (GPIO_ALT_FUNC_CFG_REG, 0x04); |
| 218 | /* configure the EBI2_BUSY1_N through GPIO115 */ |
| 219 | writel (GPIO_ALT_FUNC_PAGE_REG, 0x73); |
| 220 | writel (GPIO_ALT_FUNC_CFG_REG, 0x08); |
| 221 | } |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 222 | |
| 223 | /* Enables all gpios passed in table*/ |
| 224 | int platform_gpios_enable(const struct msm_gpio *table, int size) |
| 225 | { |
| 226 | int rc; |
| 227 | int i; |
| 228 | const struct msm_gpio *g; |
| 229 | for (i = 0; i < size; i++) { |
| 230 | g = table + i; |
| 231 | /* Enable gpio */ |
| 232 | rc = gpio_tlmm_config(g->gpio_cfg, GPIO_ENABLE); |
| 233 | if (rc) { |
| 234 | goto err; |
| 235 | } |
| 236 | } |
| 237 | return 0; |
| 238 | err: |
| 239 | return rc; |
| 240 | } |
| 241 | |