| Gregory Bean | 1963a2a | 2010-08-28 10:05:44 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010, Code Aurora Forum. All rights reserved. | 
 | 2 |  * | 
 | 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. | 
 | 11 |  * | 
 | 12 |  * You should have received a copy of the GNU General Public License | 
 | 13 |  * along with this program; if not, write to the Free Software | 
 | 14 |  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 
 | 15 |  * 02110-1301, USA. | 
 | 16 |  */ | 
 | 17 | #ifndef __ARCH_ARM_MACH_MSM_GPIOMUX_H | 
 | 18 | #define __ARCH_ARM_MACH_MSM_GPIOMUX_H | 
 | 19 |  | 
 | 20 | #include <linux/bitops.h> | 
| Gregory Bean | ab78cde | 2010-09-01 16:26:12 -0700 | [diff] [blame] | 21 | #include <linux/errno.h> | 
| David Brown | 030a77f | 2011-05-16 13:32:15 -0700 | [diff] [blame] | 22 | #include <mach/msm_gpiomux.h> | 
| Gregory Bean | 1963a2a | 2010-08-28 10:05:44 -0700 | [diff] [blame] | 23 |  | 
 | 24 | #if defined(CONFIG_MSM_V2_TLMM) | 
 | 25 | #include "gpiomux-v2.h" | 
 | 26 | #else | 
 | 27 | #include "gpiomux-v1.h" | 
 | 28 | #endif | 
 | 29 |  | 
 | 30 | /** | 
 | 31 |  * struct msm_gpiomux_config: gpiomux settings for one gpio line. | 
 | 32 |  * | 
 | 33 |  * A complete gpiomux config is the bitwise-or of a drive-strength, | 
 | 34 |  * function, and pull.  For functions other than GPIO, the OE | 
 | 35 |  * is hard-wired according to the function.  For GPIO mode, | 
 | 36 |  * OE is controlled by gpiolib. | 
 | 37 |  * | 
 | 38 |  * Available settings differ by target; see the gpiomux header | 
 | 39 |  * specific to your target arch for available configurations. | 
 | 40 |  * | 
 | 41 |  * @active: The configuration to be installed when the line is | 
 | 42 |  * active, or its reference count is > 0. | 
 | 43 |  * @suspended: The configuration to be installed when the line | 
 | 44 |  * is suspended, or its reference count is 0. | 
 | 45 |  * @ref: The reference count of the line.  For internal use of | 
 | 46 |  * the gpiomux framework only. | 
 | 47 |  */ | 
 | 48 | struct msm_gpiomux_config { | 
 | 49 | 	gpiomux_config_t active; | 
 | 50 | 	gpiomux_config_t suspended; | 
 | 51 | 	unsigned         ref; | 
 | 52 | }; | 
 | 53 |  | 
 | 54 | /** | 
 | 55 |  * @GPIOMUX_VALID:	If set, the config field contains 'good data'. | 
 | 56 |  *                      The absence of this bit will prevent the gpiomux | 
 | 57 |  *			system from applying the configuration under all | 
 | 58 |  *			circumstances. | 
 | 59 |  */ | 
 | 60 | enum { | 
 | 61 | 	GPIOMUX_VALID	 = BIT(sizeof(gpiomux_config_t) * BITS_PER_BYTE - 1), | 
 | 62 | 	GPIOMUX_CTL_MASK = GPIOMUX_VALID, | 
 | 63 | }; | 
 | 64 |  | 
| Gregory Bean | ab78cde | 2010-09-01 16:26:12 -0700 | [diff] [blame] | 65 | #ifdef CONFIG_MSM_GPIOMUX | 
 | 66 |  | 
| Gregory Bean | 1963a2a | 2010-08-28 10:05:44 -0700 | [diff] [blame] | 67 | /* Each architecture must provide its own instance of this table. | 
 | 68 |  * To avoid having gpiomux manage any given gpio, one or both of | 
 | 69 |  * the entries can avoid setting GPIOMUX_VALID - the absence | 
 | 70 |  * of that flag will prevent the configuration from being applied | 
 | 71 |  * during state transitions. | 
 | 72 |  */ | 
 | 73 | extern struct msm_gpiomux_config msm_gpiomux_configs[GPIOMUX_NGPIOS]; | 
 | 74 |  | 
| Gregory Bean | 1963a2a | 2010-08-28 10:05:44 -0700 | [diff] [blame] | 75 | /* Install a new configuration to the gpio line.  To avoid overwriting | 
 | 76 |  * a configuration, leave the VALID bit out. | 
 | 77 |  */ | 
 | 78 | int msm_gpiomux_write(unsigned gpio, | 
 | 79 | 		      gpiomux_config_t active, | 
 | 80 | 		      gpiomux_config_t suspended); | 
 | 81 |  | 
 | 82 | /* Architecture-internal function for use by the framework only. | 
 | 83 |  * This function can assume the following: | 
 | 84 |  * - the gpio value has passed a bounds-check | 
 | 85 |  * - the gpiomux spinlock has been obtained | 
 | 86 |  * | 
 | 87 |  * This function is not for public consumption.  External users | 
 | 88 |  * should use msm_gpiomux_write. | 
 | 89 |  */ | 
 | 90 | void __msm_gpiomux_write(unsigned gpio, gpiomux_config_t val); | 
| Gregory Bean | ab78cde | 2010-09-01 16:26:12 -0700 | [diff] [blame] | 91 | #else | 
| Gregory Bean | ab78cde | 2010-09-01 16:26:12 -0700 | [diff] [blame] | 92 | static inline int msm_gpiomux_write(unsigned gpio, | 
 | 93 | 				    gpiomux_config_t active, | 
 | 94 | 				    gpiomux_config_t suspended) | 
 | 95 | { | 
 | 96 | 	return -ENOSYS; | 
 | 97 | } | 
 | 98 | #endif | 
| Gregory Bean | 1963a2a | 2010-08-28 10:05:44 -0700 | [diff] [blame] | 99 | #endif |