Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Google, Inc. |
| 3 | * Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved. |
| 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_V1_H |
| 17 | #define __ASM_ARCH_MSM_GPIO_V1_H |
| 18 | |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <asm-generic/gpio.h> |
| 21 | #include <mach/irqs.h> |
| 22 | |
| 23 | #define FIRST_BOARD_GPIO NR_GPIO_IRQS |
| 24 | |
| 25 | static inline int gpio_get_value(unsigned gpio) |
| 26 | { |
| 27 | return __gpio_get_value(gpio); |
| 28 | } |
| 29 | |
| 30 | static inline void gpio_set_value(unsigned gpio, int value) |
| 31 | { |
| 32 | __gpio_set_value(gpio, value); |
| 33 | } |
| 34 | |
| 35 | static inline int gpio_cansleep(unsigned gpio) |
| 36 | { |
| 37 | return __gpio_cansleep(gpio); |
| 38 | } |
| 39 | |
| 40 | static inline int gpio_to_irq(unsigned gpio) |
| 41 | { |
| 42 | return __gpio_to_irq(gpio); |
| 43 | } |
| 44 | |
| 45 | void msm_gpio_enter_sleep(int from_idle); |
| 46 | void msm_gpio_exit_sleep(void); |
| 47 | |
| 48 | /** |
| 49 | * struct msm_gpio - GPIO pin description |
| 50 | * @gpio_cfg - configuration bitmap, as per gpio_tlmm_config() |
| 51 | * @label - textual label |
| 52 | * |
| 53 | * Usually, GPIO's are operated by sets. |
| 54 | * This struct accumulate all GPIO information in single source |
| 55 | * and facilitete group operations provided by msm_gpios_xxx() |
| 56 | */ |
| 57 | struct msm_gpio { |
| 58 | u32 gpio_cfg; |
| 59 | const char *label; |
| 60 | }; |
| 61 | |
| 62 | /** |
| 63 | * msm_gpios_request_enable() - request and enable set of GPIOs |
| 64 | * |
| 65 | * Request and configure set of GPIO's |
| 66 | * In case of error, all operations rolled back. |
| 67 | * Return error code. |
| 68 | * |
| 69 | * @table: GPIO table |
| 70 | * @size: number of entries in @table |
| 71 | */ |
| 72 | int msm_gpios_request_enable(const struct msm_gpio *table, int size); |
| 73 | |
| 74 | /** |
| 75 | * msm_gpios_disable_free() - disable and free set of GPIOs |
| 76 | * |
| 77 | * @table: GPIO table |
| 78 | * @size: number of entries in @table |
| 79 | */ |
| 80 | void msm_gpios_disable_free(const struct msm_gpio *table, int size); |
| 81 | |
| 82 | /** |
| 83 | * msm_gpios_request() - request set of GPIOs |
| 84 | * In case of error, all operations rolled back. |
| 85 | * Return error code. |
| 86 | * |
| 87 | * @table: GPIO table |
| 88 | * @size: number of entries in @table |
| 89 | */ |
| 90 | int msm_gpios_request(const struct msm_gpio *table, int size); |
| 91 | |
| 92 | /** |
| 93 | * msm_gpios_free() - free set of GPIOs |
| 94 | * |
| 95 | * @table: GPIO table |
| 96 | * @size: number of entries in @table |
| 97 | */ |
| 98 | void msm_gpios_free(const struct msm_gpio *table, int size); |
| 99 | |
| 100 | /** |
| 101 | * msm_gpios_enable() - enable set of GPIOs |
| 102 | * In case of error, all operations rolled back. |
| 103 | * Return error code. |
| 104 | * |
| 105 | * @table: GPIO table |
| 106 | * @size: number of entries in @table |
| 107 | */ |
| 108 | int msm_gpios_enable(const struct msm_gpio *table, int size); |
| 109 | |
| 110 | /** |
| 111 | * msm_gpios_disable() - disable set of GPIOs |
| 112 | * |
| 113 | * @table: GPIO table |
| 114 | * @size: number of entries in @table |
| 115 | */ |
| 116 | int msm_gpios_disable(const struct msm_gpio *table, int size); |
| 117 | |
| 118 | /* GPIO TLMM (Top Level Multiplexing) Definitions */ |
| 119 | |
| 120 | /* GPIO TLMM: Function -- GPIO specific */ |
| 121 | |
| 122 | /* GPIO TLMM: Direction */ |
| 123 | enum { |
| 124 | GPIO_CFG_INPUT, |
| 125 | GPIO_CFG_OUTPUT, |
| 126 | }; |
| 127 | |
| 128 | /* GPIO TLMM: Pullup/Pulldown */ |
| 129 | enum { |
| 130 | GPIO_CFG_NO_PULL, |
| 131 | GPIO_CFG_PULL_DOWN, |
| 132 | GPIO_CFG_KEEPER, |
| 133 | GPIO_CFG_PULL_UP, |
| 134 | }; |
| 135 | |
| 136 | /* GPIO TLMM: Drive Strength */ |
| 137 | enum { |
| 138 | GPIO_CFG_2MA, |
| 139 | GPIO_CFG_4MA, |
| 140 | GPIO_CFG_6MA, |
| 141 | GPIO_CFG_8MA, |
| 142 | GPIO_CFG_10MA, |
| 143 | GPIO_CFG_12MA, |
| 144 | GPIO_CFG_14MA, |
| 145 | GPIO_CFG_16MA, |
| 146 | }; |
| 147 | |
| 148 | enum { |
| 149 | GPIO_CFG_ENABLE, |
| 150 | GPIO_CFG_DISABLE, |
| 151 | }; |
| 152 | |
| 153 | #define GPIO_CFG(gpio, func, dir, pull, drvstr) \ |
| 154 | ((((gpio) & 0x3FF) << 4) | \ |
| 155 | ((func) & 0xf) | \ |
| 156 | (((dir) & 0x1) << 14) | \ |
| 157 | (((pull) & 0x3) << 15) | \ |
| 158 | (((drvstr) & 0xF) << 17)) |
| 159 | |
| 160 | /** |
| 161 | * extract GPIO pin from bit-field used for gpio_tlmm_config |
| 162 | */ |
| 163 | #define GPIO_PIN(gpio_cfg) (((gpio_cfg) >> 4) & 0x3ff) |
| 164 | #define GPIO_FUNC(gpio_cfg) (((gpio_cfg) >> 0) & 0xf) |
| 165 | #define GPIO_DIR(gpio_cfg) (((gpio_cfg) >> 14) & 0x1) |
| 166 | #define GPIO_PULL(gpio_cfg) (((gpio_cfg) >> 15) & 0x3) |
| 167 | #define GPIO_DRVSTR(gpio_cfg) (((gpio_cfg) >> 17) & 0xf) |
| 168 | |
| 169 | int gpio_tlmm_config(unsigned config, unsigned disable); |
| 170 | |
| 171 | #endif /* __ASM_ARCH_MSM_GPIO_V1_H */ |