diff options
-rw-r--r-- | arch/arm/mach-msm/gpio.c | 85 | ||||
-rw-r--r-- | arch/arm/mach-msm/include/mach/gpio.h | 142 |
2 files changed, 227 insertions, 0 deletions
diff --git a/arch/arm/mach-msm/gpio.c b/arch/arm/mach-msm/gpio.c new file mode 100644 index 000000000000..bc32c845c7b0 --- /dev/null +++ b/arch/arm/mach-msm/gpio.c | |||
@@ -0,0 +1,85 @@ | |||
1 | /* linux/arch/arm/mach-msm/gpio.c | ||
2 | * | ||
3 | * Copyright (C) 2007 Google, Inc. | ||
4 | * Copyright (c) 2009, Code Aurora Forum. All rights reserved. | ||
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 | |||
17 | #include <linux/module.h> | ||
18 | #include <mach/gpio.h> | ||
19 | #include "proc_comm.h" | ||
20 | |||
21 | int gpio_tlmm_config(unsigned config, unsigned disable) | ||
22 | { | ||
23 | return msm_proc_comm(PCOM_RPC_GPIO_TLMM_CONFIG_EX, &config, &disable); | ||
24 | } | ||
25 | EXPORT_SYMBOL(gpio_tlmm_config); | ||
26 | |||
27 | int msm_gpios_enable(const struct msm_gpio *table, int size) | ||
28 | { | ||
29 | int rc; | ||
30 | int i; | ||
31 | const struct msm_gpio *g; | ||
32 | for (i = 0; i < size; i++) { | ||
33 | g = table + i; | ||
34 | rc = gpio_tlmm_config(g->gpio_cfg, GPIO_ENABLE); | ||
35 | if (rc) { | ||
36 | pr_err("gpio_tlmm_config(0x%08x, GPIO_ENABLE)" | ||
37 | " <%s> failed: %d\n", | ||
38 | g->gpio_cfg, g->label ?: "?", rc); | ||
39 | pr_err("pin %d func %d dir %d pull %d drvstr %d\n", | ||
40 | GPIO_PIN(g->gpio_cfg), GPIO_FUNC(g->gpio_cfg), | ||
41 | GPIO_DIR(g->gpio_cfg), GPIO_PULL(g->gpio_cfg), | ||
42 | GPIO_DRVSTR(g->gpio_cfg)); | ||
43 | goto err; | ||
44 | } | ||
45 | } | ||
46 | return 0; | ||
47 | err: | ||
48 | msm_gpios_disable(table, i); | ||
49 | return rc; | ||
50 | } | ||
51 | EXPORT_SYMBOL(msm_gpios_enable); | ||
52 | |||
53 | void msm_gpios_disable(const struct msm_gpio *table, int size) | ||
54 | { | ||
55 | int rc; | ||
56 | int i; | ||
57 | const struct msm_gpio *g; | ||
58 | for (i = size-1; i >= 0; i--) { | ||
59 | g = table + i; | ||
60 | rc = gpio_tlmm_config(g->gpio_cfg, GPIO_DISABLE); | ||
61 | if (rc) { | ||
62 | pr_err("gpio_tlmm_config(0x%08x, GPIO_DISABLE)" | ||
63 | " <%s> failed: %d\n", | ||
64 | g->gpio_cfg, g->label ?: "?", rc); | ||
65 | pr_err("pin %d func %d dir %d pull %d drvstr %d\n", | ||
66 | GPIO_PIN(g->gpio_cfg), GPIO_FUNC(g->gpio_cfg), | ||
67 | GPIO_DIR(g->gpio_cfg), GPIO_PULL(g->gpio_cfg), | ||
68 | GPIO_DRVSTR(g->gpio_cfg)); | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | EXPORT_SYMBOL(msm_gpios_disable); | ||
73 | |||
74 | int msm_gpios_request_enable(const struct msm_gpio *table, int size) | ||
75 | { | ||
76 | int rc = msm_gpios_enable(table, size); | ||
77 | return rc; | ||
78 | } | ||
79 | EXPORT_SYMBOL(msm_gpios_request_enable); | ||
80 | |||
81 | void msm_gpios_disable_free(const struct msm_gpio *table, int size) | ||
82 | { | ||
83 | msm_gpios_disable(table, size); | ||
84 | } | ||
85 | EXPORT_SYMBOL(msm_gpios_disable_free); | ||
diff --git a/arch/arm/mach-msm/include/mach/gpio.h b/arch/arm/mach-msm/include/mach/gpio.h new file mode 100644 index 000000000000..262b441b4374 --- /dev/null +++ b/arch/arm/mach-msm/include/mach/gpio.h | |||
@@ -0,0 +1,142 @@ | |||
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_H | ||
17 | #define __ASM_ARCH_MSM_GPIO_H | ||
18 | |||
19 | /** | ||
20 | * struct msm_gpio - GPIO pin description | ||
21 | * @gpio_cfg - configuration bitmap, as per gpio_tlmm_config() | ||
22 | * @label - textual label | ||
23 | * | ||
24 | * Usually, GPIO's are operated by sets. | ||
25 | * This struct accumulate all GPIO information in single source | ||
26 | * and facilitete group operations provided by msm_gpios_xxx() | ||
27 | */ | ||
28 | struct msm_gpio { | ||
29 | u32 gpio_cfg; | ||
30 | const char *label; | ||
31 | }; | ||
32 | |||
33 | /** | ||
34 | * msm_gpios_request_enable() - request and enable set of GPIOs | ||
35 | * | ||
36 | * Request and configure set of GPIO's | ||
37 | * In case of error, all operations rolled back. | ||
38 | * Return error code. | ||
39 | * | ||
40 | * @table: GPIO table | ||
41 | * @size: number of entries in @table | ||
42 | */ | ||
43 | int msm_gpios_request_enable(const struct msm_gpio *table, int size); | ||
44 | |||
45 | /** | ||
46 | * msm_gpios_disable_free() - disable and free set of GPIOs | ||
47 | * | ||
48 | * @table: GPIO table | ||
49 | * @size: number of entries in @table | ||
50 | */ | ||
51 | void msm_gpios_disable_free(const struct msm_gpio *table, int size); | ||
52 | |||
53 | /** | ||
54 | * msm_gpios_request() - request set of GPIOs | ||
55 | * In case of error, all operations rolled back. | ||
56 | * Return error code. | ||
57 | * | ||
58 | * @table: GPIO table | ||
59 | * @size: number of entries in @table | ||
60 | */ | ||
61 | int msm_gpios_request(const struct msm_gpio *table, int size); | ||
62 | |||
63 | /** | ||
64 | * msm_gpios_free() - free set of GPIOs | ||
65 | * | ||
66 | * @table: GPIO table | ||
67 | * @size: number of entries in @table | ||
68 | */ | ||
69 | void msm_gpios_free(const struct msm_gpio *table, int size); | ||
70 | |||
71 | /** | ||
72 | * msm_gpios_enable() - enable set of GPIOs | ||
73 | * In case of error, all operations rolled back. | ||
74 | * Return error code. | ||
75 | * | ||
76 | * @table: GPIO table | ||
77 | * @size: number of entries in @table | ||
78 | */ | ||
79 | int msm_gpios_enable(const struct msm_gpio *table, int size); | ||
80 | |||
81 | /** | ||
82 | * msm_gpios_disable() - disable set of GPIOs | ||
83 | * | ||
84 | * @table: GPIO table | ||
85 | * @size: number of entries in @table | ||
86 | */ | ||
87 | void msm_gpios_disable(const struct msm_gpio *table, int size); | ||
88 | |||
89 | /* GPIO TLMM (Top Level Multiplexing) Definitions */ | ||
90 | |||
91 | /* GPIO TLMM: Function -- GPIO specific */ | ||
92 | |||
93 | /* GPIO TLMM: Direction */ | ||
94 | enum { | ||
95 | GPIO_INPUT, | ||
96 | GPIO_OUTPUT, | ||
97 | }; | ||
98 | |||
99 | /* GPIO TLMM: Pullup/Pulldown */ | ||
100 | enum { | ||
101 | GPIO_NO_PULL, | ||
102 | GPIO_PULL_DOWN, | ||
103 | GPIO_KEEPER, | ||
104 | GPIO_PULL_UP, | ||
105 | }; | ||
106 | |||
107 | /* GPIO TLMM: Drive Strength */ | ||
108 | enum { | ||
109 | GPIO_2MA, | ||
110 | GPIO_4MA, | ||
111 | GPIO_6MA, | ||
112 | GPIO_8MA, | ||
113 | GPIO_10MA, | ||
114 | GPIO_12MA, | ||
115 | GPIO_14MA, | ||
116 | GPIO_16MA, | ||
117 | }; | ||
118 | |||
119 | enum { | ||
120 | GPIO_ENABLE, | ||
121 | GPIO_DISABLE, | ||
122 | }; | ||
123 | |||
124 | #define GPIO_CFG(gpio, func, dir, pull, drvstr) \ | ||
125 | ((((gpio) & 0x3FF) << 4) | \ | ||
126 | ((func) & 0xf) | \ | ||
127 | (((dir) & 0x1) << 14) | \ | ||
128 | (((pull) & 0x3) << 15) | \ | ||
129 | (((drvstr) & 0xF) << 17)) | ||
130 | |||
131 | /** | ||
132 | * extract GPIO pin from bit-field used for gpio_tlmm_config | ||
133 | */ | ||
134 | #define GPIO_PIN(gpio_cfg) (((gpio_cfg) >> 4) & 0x3ff) | ||
135 | #define GPIO_FUNC(gpio_cfg) (((gpio_cfg) >> 0) & 0xf) | ||
136 | #define GPIO_DIR(gpio_cfg) (((gpio_cfg) >> 14) & 0x1) | ||
137 | #define GPIO_PULL(gpio_cfg) (((gpio_cfg) >> 15) & 0x3) | ||
138 | #define GPIO_DRVSTR(gpio_cfg) (((gpio_cfg) >> 17) & 0xf) | ||
139 | |||
140 | int gpio_tlmm_config(unsigned config, unsigned disable); | ||
141 | |||
142 | #endif /* __ASM_ARCH_MSM_GPIO_H */ | ||