blob: 9aae3fbd8b2afe6839913375a595f5c91e3a35cb [file] [log] [blame]
Rohit Vaswaniaf4a6d62013-02-22 12:19:58 -08001/* Copyright (c) 2010-2011,2013, The Linux Foundation. All rights reserved.
Gregory Bean1963a2a2010-08-28 10:05:44 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
Gregory Bean1963a2a2010-08-28 10:05:44 -070011 */
12#ifndef __ARCH_ARM_MACH_MSM_GPIOMUX_H
13#define __ARCH_ARM_MACH_MSM_GPIOMUX_H
14
15#include <linux/bitops.h>
Gregory Beanab78cde2010-09-01 16:26:12 -070016#include <linux/errno.h>
Gregory Bean1963a2a2010-08-28 10:05:44 -070017
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070018enum msm_gpiomux_setting {
19 GPIOMUX_ACTIVE = 0,
20 GPIOMUX_SUSPENDED,
21 GPIOMUX_NSETTINGS
22};
23
24enum gpiomux_drv {
25 GPIOMUX_DRV_2MA = 0,
26 GPIOMUX_DRV_4MA,
27 GPIOMUX_DRV_6MA,
28 GPIOMUX_DRV_8MA,
29 GPIOMUX_DRV_10MA,
30 GPIOMUX_DRV_12MA,
31 GPIOMUX_DRV_14MA,
32 GPIOMUX_DRV_16MA,
33};
34
35enum gpiomux_func {
36 GPIOMUX_FUNC_GPIO = 0,
37 GPIOMUX_FUNC_1,
38 GPIOMUX_FUNC_2,
39 GPIOMUX_FUNC_3,
40 GPIOMUX_FUNC_4,
41 GPIOMUX_FUNC_5,
42 GPIOMUX_FUNC_6,
43 GPIOMUX_FUNC_7,
44 GPIOMUX_FUNC_8,
45 GPIOMUX_FUNC_9,
46 GPIOMUX_FUNC_A,
47 GPIOMUX_FUNC_B,
48 GPIOMUX_FUNC_C,
49 GPIOMUX_FUNC_D,
50 GPIOMUX_FUNC_E,
51 GPIOMUX_FUNC_F,
52};
53
54enum gpiomux_pull {
55 GPIOMUX_PULL_NONE = 0,
56 GPIOMUX_PULL_DOWN,
57 GPIOMUX_PULL_KEEPER,
58 GPIOMUX_PULL_UP,
59};
60
61/* Direction settings are only meaningful when GPIOMUX_FUNC_GPIO is selected.
62 * This element is ignored for all other FUNC selections, as the output-
63 * enable pin is not under software control in those cases. See the SWI
64 * for your target for more details.
65 */
66enum gpiomux_dir {
67 GPIOMUX_IN = 0,
68 GPIOMUX_OUT_HIGH,
69 GPIOMUX_OUT_LOW,
70};
71
72struct gpiomux_setting {
73 enum gpiomux_func func;
74 enum gpiomux_drv drv;
75 enum gpiomux_pull pull;
76 enum gpiomux_dir dir;
77};
Gregory Bean1963a2a2010-08-28 10:05:44 -070078
79/**
80 * struct msm_gpiomux_config: gpiomux settings for one gpio line.
81 *
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070082 * A complete gpiomux config is the combination of a drive-strength,
83 * function, pull, and (sometimes) direction. For functions other than GPIO,
84 * the input/output setting is hard-wired according to the function.
Gregory Bean1963a2a2010-08-28 10:05:44 -070085 *
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070086 * @gpio: The index number of the gpio being described.
87 * @settings: The settings to be installed, specifically:
88 * GPIOMUX_ACTIVE: The setting to be installed when the
89 * line is active, or its reference count is > 0.
90 * GPIOMUX_SUSPENDED: The setting to be installed when
91 * the line is suspended, or its reference count is 0.
Gregory Bean1963a2a2010-08-28 10:05:44 -070092 */
93struct msm_gpiomux_config {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070094 unsigned gpio;
95 struct gpiomux_setting *settings[GPIOMUX_NSETTINGS];
Gregory Bean1963a2a2010-08-28 10:05:44 -070096};
97
98/**
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070099 * struct msm_gpiomux_configs: a collection of gpiomux configs.
100 *
101 * It is so common to manage blocks of gpiomux configs that the data structure
102 * for doing so has been standardized here as a convenience.
103 *
104 * @cfg: A pointer to the first config in an array of configs.
105 * @ncfg: The number of configs in the array.
Gregory Bean1963a2a2010-08-28 10:05:44 -0700106 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700107struct msm_gpiomux_configs {
108 struct msm_gpiomux_config *cfg;
109 size_t ncfg;
Gregory Bean1963a2a2010-08-28 10:05:44 -0700110};
111
Rohit Vaswanibb62f3e2013-03-01 14:14:48 -0800112/* Provide an enum and an API to write to misc TLMM registers */
113enum msm_tlmm_misc_reg {
114 TLMM_ETM_MODE_REG = 0x2014,
115 TLMM_SDC2_HDRV_PULL_CTL = 0x2048,
116};
117
118void msm_tlmm_misc_reg_write(enum msm_tlmm_misc_reg misc_reg, int val);
119
Gregory Beanab78cde2010-09-01 16:26:12 -0700120#ifdef CONFIG_MSM_GPIOMUX
121
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700122/* Before using gpiomux, initialize the subsystem by telling it how many
123 * gpios are going to be managed. Calling any other gpiomux functions before
124 * msm_gpiomux_init is unsupported.
Gregory Bean1963a2a2010-08-28 10:05:44 -0700125 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700126int msm_gpiomux_init(size_t ngpio);
127
Rohit Vaswani341c2032012-11-08 18:49:29 -0800128/* DT Variant of msm_gpiomux_init. This will look up the number of gpios from
129 * device tree rather than relying on NR_GPIO_IRQS
130 */
131int msm_gpiomux_init_dt(void);
132
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700133/* Install a block of gpiomux configurations in gpiomux. This is functionally
134 * identical to calling msm_gpiomux_write many times.
135 */
136void msm_gpiomux_install(struct msm_gpiomux_config *configs, unsigned nconfigs);
Gregory Bean1963a2a2010-08-28 10:05:44 -0700137
Rohit Vaswaniaf4a6d62013-02-22 12:19:58 -0800138/* Install a block of gpiomux configurations in gpiomux. Do not however write
139 * to hardware. Just store the settings to be retrieved at a later time
140 */
141void msm_gpiomux_install_nowrite(struct msm_gpiomux_config *configs,
142 unsigned nconfigs);
143
Gregory Bean1963a2a2010-08-28 10:05:44 -0700144/* Increment a gpio's reference count, possibly activating the line. */
145int __must_check msm_gpiomux_get(unsigned gpio);
146
147/* Decrement a gpio's reference count, possibly suspending the line. */
148int msm_gpiomux_put(unsigned gpio);
149
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700150/* Install a new setting in a gpio. To erase a slot, use NULL.
151 * The old setting that was overwritten can be passed back to the caller
152 * old_setting can be NULL if the caller is not interested in the previous
153 * setting
154 * If a previous setting was not available to return (NULL configuration)
155 * - the function returns 1
156 * else function returns 0
Gregory Bean1963a2a2010-08-28 10:05:44 -0700157 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700158int msm_gpiomux_write(unsigned gpio, enum msm_gpiomux_setting which,
159 struct gpiomux_setting *setting, struct gpiomux_setting *old_setting);
Gregory Bean1963a2a2010-08-28 10:05:44 -0700160
161/* Architecture-internal function for use by the framework only.
162 * This function can assume the following:
163 * - the gpio value has passed a bounds-check
164 * - the gpiomux spinlock has been obtained
165 *
166 * This function is not for public consumption. External users
167 * should use msm_gpiomux_write.
168 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700169void __msm_gpiomux_write(unsigned gpio, struct gpiomux_setting val);
Gregory Beanab78cde2010-09-01 16:26:12 -0700170#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700171static inline int msm_gpiomux_init(size_t ngpio)
172{
173 return -ENOSYS;
174}
175
176static inline void
177msm_gpiomux_install(struct msm_gpiomux_config *configs, unsigned nconfigs) {}
178
Gregory Beanab78cde2010-09-01 16:26:12 -0700179static inline int __must_check msm_gpiomux_get(unsigned gpio)
180{
181 return -ENOSYS;
182}
Gregory Bean1963a2a2010-08-28 10:05:44 -0700183
Gregory Beanab78cde2010-09-01 16:26:12 -0700184static inline int msm_gpiomux_put(unsigned gpio)
185{
186 return -ENOSYS;
187}
188
189static inline int msm_gpiomux_write(unsigned gpio,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700190 enum msm_gpiomux_setting which, struct gpiomux_setting *setting,
191 struct gpiomux_setting *old_setting)
Gregory Beanab78cde2010-09-01 16:26:12 -0700192{
193 return -ENOSYS;
194}
195#endif
Gregory Bean1963a2a2010-08-28 10:05:44 -0700196#endif