[PATCH 13/21] ARM: ux500: sensors: Update with gpio handling

Naga RADHESH Y naga.radheshy at stericsson.com
Tue Feb 14 06:47:00 UTC 2012


From: Jonas Aaberg <jonas.aberg at stericsson.com>

Update the gpio-keyboard use of hal and proximity sensors to
use the ux500 pin framework.

ST-Ericsson Linux next: -
ST-Ericsson ID: -
ST-Ericsson FOSS-OUT ID: Trivial

Change-Id: I409d9734c3995d6cfdfff8c7196624a4f89b3e2d
Signed-off-by: Jonas Aaberg <jonas.aberg at stericsson.com>
---
 arch/arm/configs/u8500_defconfig        |    1 +
 arch/arm/mach-ux500/Kconfig             |    6 +++
 arch/arm/mach-ux500/board-mop500-pins.c |   43 +++++++++++++++++-----
 arch/arm/mach-ux500/board-mop500.c      |   60 +++++++++++++++++++++---------
 4 files changed, 83 insertions(+), 27 deletions(-)

diff --git a/arch/arm/configs/u8500_defconfig b/arch/arm/configs/u8500_defconfig
index 5bfa635..fde66da 100755
--- a/arch/arm/configs/u8500_defconfig
+++ b/arch/arm/configs/u8500_defconfig
@@ -30,6 +30,7 @@ CONFIG_DISPLAY_GENERIC_DSI_PRIMARY_VSYNC=y
 CONFIG_DISPLAY_SONY_ACX424AKP_DSI_PRIMARY=y
 CONFIG_DISPLAY_AV8100_TERTIARY=y
 CONFIG_DISPLAY_AV8100_TRIPPLE_BUFFER=y
+CONFIG_UX500_GPIO_KEYS=y
 CONFIG_UX500_SUSPEND=y
 CONFIG_UX500_SUSPEND_STANDBY=y
 CONFIG_UX500_SUSPEND_MEM=y
diff --git a/arch/arm/mach-ux500/Kconfig b/arch/arm/mach-ux500/Kconfig
index 92a85c2..626154f 100644
--- a/arch/arm/mach-ux500/Kconfig
+++ b/arch/arm/mach-ux500/Kconfig
@@ -80,6 +80,12 @@ config UX500_DEBUG_UART
 	  Choose the UART on which kernel low-level debug messages should be
 	  output.
 
+config UX500_GPIO_KEYS
+        bool "Use gpio-keys for proximity and hal sensors"
+        depends on KEYBOARD_GPIO
+        help
+	  Add proximity and hal sensors as a gpio keyboard.
+
 config SENSORS1P_MOP
 	tristate "HAL and Proximity sensors support"
 	depends on REGULATOR && (GPIO_STMPE2401 || GPIO_TC35892)
diff --git a/arch/arm/mach-ux500/board-mop500-pins.c b/arch/arm/mach-ux500/board-mop500-pins.c
index 276305e..2fc6c4b 100644
--- a/arch/arm/mach-ux500/board-mop500-pins.c
+++ b/arch/arm/mach-ux500/board-mop500-pins.c
@@ -19,7 +19,7 @@
 
 #include "pins-db8500.h"
 #include "pins.h"
-
+#include "board-mop500.h"
 #include "board-pins-sleep-force.h"
 
 enum custom_pin_cfg_t {
@@ -162,9 +162,6 @@ static pin_cfg_t mop500_pins_hrefv60[] = {
 	/* DiPro Sensor Interface */
 	GPIO139_GPIO	| PIN_INPUT_PULLUP, /* DIPRO_INT */
 
-	/* HAL SWITCH INTERFACE */
-	GPIO145_GPIO	| PIN_INPUT_PULLDOWN,/* HAL_SW */
-
 	/* Audio Amplifier Interface */
 	GPIO149_GPIO	| PIN_OUTPUT_HIGH, /* VAUDIO_HF_EN, enable MAX8968 */
 
@@ -178,9 +175,6 @@ static pin_cfg_t mop500_pins_hrefv60[] = {
 	GPIO82_GPIO		| PIN_INPUT_PULLUP, /* ACC_INT1 */
 	GPIO83_GPIO		| PIN_INPUT_PULLUP, /* ACC_INT2 */
 
-	/* Proximity Sensor */
-	GPIO217_GPIO		| PIN_INPUT_PULLUP,
-
 	/* SD card detect */
 	GPIO95_GPIO	| PIN_INPUT_PULLUP,
 };
@@ -420,7 +414,19 @@ static UX500_PINS(mop500_pins_spi2,
 	GPIO217_SPI2_CLK        | PIN_OUTPUT_LOW,
 );
 
-static struct ux500_pin_lookup mop500_pins[] = {
+static UX500_PINS(mop500_pins_sensors1p,
+	GPIO217_GPIO| PIN_INPUT_PULLUP |
+		  PIN_SLPM_GPIO | PIN_SLPM_INPUT_NOPULL,
+	GPIO145_GPIO | PIN_INPUT_PULLDOWN |
+		  PIN_SLPM_GPIO | PIN_SLPM_INPUT_NOPULL,
+);
+
+static UX500_PINS(mop500_pins_sensors1p_old,
+	PIN_CFG_INPUT(GPIO_PROX_SENSOR, GPIO, NOPULL),
+	PIN_CFG_INPUT(GPIO_HAL_SENSOR, GPIO, NOPULL),
+);
+
+static struct ux500_pin_lookup mop500_runtime_pins[] = {
 	PIN_LOOKUP("mcde-dpi", &mop500_pins_mcde_dpi),
 	PIN_LOOKUP("mcde-tvout", &mop500_pins_mcde_tvout),
 	PIN_LOOKUP("av8100-hdmi", &mop500_pins_mcde_hdmi),
@@ -437,6 +443,14 @@ static struct ux500_pin_lookup mop500_pins[] = {
 	PIN_LOOKUP("spi2", &mop500_pins_spi2),
 };
 
+static struct ux500_pin_lookup mop500_runtime_pins_v60[] = {
+	PIN_LOOKUP("gpio-keys.0", &mop500_pins_sensors1p),
+};
+
+static struct ux500_pin_lookup mop500_runtime_pins_old[] = {
+	PIN_LOOKUP("gpio-keys.0", &mop500_pins_sensors1p_old),
+};
+
 /*
  * Sleep pin configuration for u8500 platform.
  * If another HW is used the GPIO's must be configured
@@ -647,7 +661,9 @@ static pin_cfg_t mop500_pins_common_power_save_bank4[] = {
 	GPIO143_GPIO | PIN_SLPM_OUTPUT_LOW | PIN_SLPM_WAKEUP_ENABLE | PIN_SLPM_PDIS_DISABLED,
 
 	GPIO144_GPIO | PIN_SLPM_OUTPUT_HIGH | PIN_SLPM_WAKEUP_ENABLE | PIN_SLPM_PDIS_DISABLED,
+	/* 145 - HAL sensor (on v60 and later) */
 	GPIO145_GPIO | PIN_SLPM_DIR_INPUT | PIN_SLPM_WAKEUP_ENABLE | PIN_SLPM_PDIS_DISABLED,
+
 	GPIO146_GPIO | PIN_SLPM_OUTPUT_LOW | PIN_SLPM_WAKEUP_ENABLE | PIN_SLPM_PDIS_DISABLED,
 	GPIO147_GPIO | PIN_SLPM_DIR_INPUT | PIN_SLPM_WAKEUP_ENABLE | PIN_SLPM_PDIS_DISABLED,
 
@@ -775,7 +791,9 @@ static pin_cfg_t mop500_pins_common_power_save_bank6_href60[] = {
 	GPIO215_GPIO | PIN_SLPM_OUTPUT_LOW | PIN_SLPM_WAKEUP_ENABLE | PIN_SLPM_PDIS_DISABLED,
 
 	GPIO216_GPIO | PIN_SLPM_DIR_INPUT | PIN_SLPM_WAKEUP_ENABLE | PIN_SLPM_PDIS_DISABLED,
+	/* 217 - Proximity */
 	GPIO217_GPIO | PIN_SLPM_WAKEUP_ENABLE | PIN_SLPM_PDIS_DISABLED,
+
 	GPIO218_GPIO | PIN_SLPM_DIR_INPUT | PIN_SLPM_WAKEUP_ENABLE | PIN_SLPM_PDIS_DISABLED,
 	GPIO219_GPIO | PIN_SLPM_OUTPUT_LOW | PIN_SLPM_WAKEUP_ENABLE | PIN_SLPM_PDIS_DISABLED,
 
@@ -938,7 +956,14 @@ void __init mop500_pins_init(void)
 	nmk_config_pins(mop500_pins_common,
 				ARRAY_SIZE(mop500_pins_common));
 
-	ux500_pins_add(mop500_pins, ARRAY_SIZE(mop500_pins));
+	ux500_pins_add(mop500_runtime_pins, ARRAY_SIZE(mop500_runtime_pins));
+
+	if (machine_is_hrefv60())
+		ux500_pins_add(mop500_runtime_pins_v60,
+			       ARRAY_SIZE(mop500_runtime_pins_v60));
+	else
+		ux500_pins_add(mop500_runtime_pins_old,
+			       ARRAY_SIZE(mop500_runtime_pins_old));
 
 	switch (pinsfor) {
 	case PINS_FOR_U9500:
diff --git a/arch/arm/mach-ux500/board-mop500.c b/arch/arm/mach-ux500/board-mop500.c
index b8855d6..9b3cbfd 100644
--- a/arch/arm/mach-ux500/board-mop500.c
+++ b/arch/arm/mach-ux500/board-mop500.c
@@ -648,6 +648,7 @@ static void __init mop500_i2c_init(void)
 	db8500_add_i2c3(&u8500_i2c3_data);
 }
 
+#ifdef CONFIG_UX500_GPIO_KEYS
 static struct gpio_keys_button mop500_gpio_keys[] = {
 	{
 		.desc			= "SFH7741 Proximity Sensor",
@@ -666,6 +667,7 @@ static struct gpio_keys_button mop500_gpio_keys[] = {
 };
 
 static struct regulator *sensors1p_regulator;
+struct ux500_pins *sensors1p_pins;
 static int mop500_sensors1p_activate(struct device *dev);
 static void mop500_sensors1p_deactivate(struct device *dev);
 
@@ -704,6 +706,11 @@ static struct platform_device snowball_gpio_en_3v3_regulator_device = {
 
 static int mop500_sensors1p_activate(struct device *dev)
 {
+	if (sensors1p_pins == NULL)
+		return -EINVAL;
+
+	ux500_pins_enable(sensors1p_pins);
+
 	sensors1p_regulator = regulator_get(&mop500_gpio_keys_device.dev,
 						"vcc");
 	if (IS_ERR(sensors1p_regulator)) {
@@ -711,15 +718,42 @@ static int mop500_sensors1p_activate(struct device *dev)
 		return PTR_ERR(sensors1p_regulator);
 	}
 	regulator_enable(sensors1p_regulator);
+
+	/*
+	 * Please be aware that the start-up time of the SFH7741 is
+	 * 120 ms and during that time the output is undefined.
+	 */
+
 	return 0;
 }
 
 static void mop500_sensors1p_deactivate(struct device *dev)
 {
-	regulator_disable(sensors1p_regulator);
-	regulator_put(sensors1p_regulator);
+	if (!IS_ERR(sensors1p_regulator)) {
+		regulator_disable(sensors1p_regulator);
+		regulator_put(sensors1p_regulator);
+	}
+
+	if (sensors1p_pins != NULL)
+		ux500_pins_disable(sensors1p_pins);
 }
 
+static __init void mop500_sensors1p_init(void)
+{
+	sensors1p_pins = ux500_pins_get("gpio-keys.0");
+
+	if (sensors1p_pins == NULL) {
+		pr_err("sensors1p: Fail to get keys\n");
+		return;
+	}
+
+	mop500_gpio_keys[0].gpio = PIN_NUM(sensors1p_pins->cfg[0]);
+	mop500_gpio_keys[1].gpio = PIN_NUM(sensors1p_pins->cfg[1]);
+}
+#else
+static inline void mop500_sensors1p_init(void) { }
+#endif
+
 #ifdef CONFIG_LEDS_PWM
 static struct led_pwm pwm_leds_data[] = {
 	[0] = {
@@ -951,7 +985,9 @@ static struct platform_device *mop500_platform_devs[] __initdata = {
 #ifdef CONFIG_STE_TRACE_MODEM
 	&u8500_trace_modem,
 #endif
+#ifdef CONFIG_UX500_GPIO_KEYS
 	&mop500_gpio_keys_device,
+#endif
 #ifdef CONFIG_LEDS_PWM
 	&ux500_leds_device,
 #endif
@@ -1219,20 +1255,6 @@ static void accessory_detect_config(void)
 
 static void __init mop500_init_machine(void)
 {
-	/*
-	 * The HREFv60 board removed a GPIO expander and routed
-	 * all these GPIO pins to the internal GPIO controller
-	 * instead.
-	 */
-	if (!machine_is_snowball()) {
-		if (machine_is_hrefv60()) {
-			mop500_gpio_keys[0].gpio = HREFV60_PROX_SENSE_GPIO;
-			mop500_gpio_keys[1].gpio = HREFV60_HAL_SW_GPIO;
-		} else {
-			mop500_gpio_keys[0].gpio = GPIO_PROX_SENSOR;
-			mop500_gpio_keys[1].gpio = GPIO_HAL_SENSOR;
-		}
-	}
 
 	accessory_detect_config();
 
@@ -1249,12 +1271,14 @@ static void __init mop500_init_machine(void)
 				ARRAY_SIZE(u8500_hsi_devices));
 #endif
 
-	if (machine_is_snowball())
+	if (machine_is_snowball()) {
 		platform_add_devices(snowball_platform_devs,
 					ARRAY_SIZE(snowball_platform_devs));
-	else
+	} else {
+		mop500_sensors1p_init();
 		platform_add_devices(mop500_platform_devs,
 					ARRAY_SIZE(mop500_platform_devs));
+	}
 
 	mop500_i2c_init();
 	mop500_sdi_init();
-- 
1.7.4.3



More information about the kernel mailing list