RE: [PATCH v2] omap: 4430sdp board support for the the GPIO keys
-Original Message- From: Gopinath, Thara Subject: RE: [PATCH v2] omap: 4430sdp board support for the the GPIO keys -Original Message- From: linux-omap-ow...@vger.kernel.org [mailto:linux-omap- ow...@vger.kernel.org] On Behalf Of Shubhrajyoti D Sent: Tuesday, August 24, 2010 10:58 AM To: linux-omap@vger.kernel.org Cc: Datta, Shubhrajyoti Subject: [PATCH v2] omap: 4430sdp board support for the the GPIO keys omap 4430sdp board support for the GPIO keys. The proximity sensor is connected to GPIO and is registered as a GPIO key. - Making the default state of the sensor off at bootup Signed-off-by: Shubhrajyoti D shubhrajy...@ti.com --- arch/arm/mach-omap2/board-4430sdp.c | 61 +++ 1 files changed, 61 insertions(+), 0 deletions(-) diff --git a/arch/arm/mach-omap2/board-4430sdp.c b/arch/arm/mach- omap2/board-4430sdp.c index 9447644..85b0e0c 100644 --- a/arch/arm/mach-omap2/board-4430sdp.c +++ b/arch/arm/mach-omap2/board-4430sdp.c @@ -20,6 +20,7 @@ #include linux/usb/otg.h #include linux/spi/spi.h #include linux/i2c/twl.h +#include linux/gpio_keys.h #include linux/regulator/machine.h #include linux/leds.h @@ -40,6 +41,8 @@ #define ETH_KS8851_IRQ 34 #define ETH_KS8851_POWER_ON48 #define ETH_KS8851_QUART 138 +#define OMAP4_SFH7741_SENSOR_OUTPUT_GPIO 184 +#define OMAP4_SFH7741_ENABLE_GPIO 188 static struct gpio_led sdp4430_gpio_leds[] = { { @@ -77,11 +80,47 @@ static struct gpio_led sdp4430_gpio_leds[] = { }; +static struct gpio_keys_button sdp4430_gpio_keys[] = { + { + .desc = Proximity Sensor, + .type = EV_SW, + .code = SW_FRONT_PROXIMITY, + .gpio = OMAP4_SFH7741_SENSOR_OUTPUT_GPIO, + .active_low = 0, + } +}; + static struct gpio_led_platform_data sdp4430_led_data = { .leds = sdp4430_gpio_leds, .num_leds = ARRAY_SIZE(sdp4430_gpio_leds), }; +static int omap_prox_activate(struct device *dev) +{ + gpio_set_value(OMAP4_SFH7741_ENABLE_GPIO , 1); + return 0; +} + +static void omap_prox_deactivate(struct device *dev) +{ + gpio_set_value(OMAP4_SFH7741_ENABLE_GPIO , 0); +} + +static struct gpio_keys_platform_data sdp4430_gpio_keys_data = { + .buttons= sdp4430_gpio_keys, + .nbuttons = ARRAY_SIZE(sdp4430_gpio_keys), + .enable = omap_prox_activate, + .disable= omap_prox_deactivate, +}; + +static struct platform_device sdp4430_gpio_keys_device = { + .name = gpio-keys, + .id = -1, + .dev= { + .platform_data = sdp4430_gpio_keys_data, + }, +}; + static struct platform_device sdp4430_leds_gpio = { .name = leds-gpio, .id = -1, @@ -161,6 +200,7 @@ static struct platform_device sdp4430_lcd_device = { static struct platform_device *sdp4430_devices[] __initdata = { sdp4430_lcd_device, + sdp4430_gpio_keys_device, sdp4430_leds_gpio, }; @@ -426,6 +466,26 @@ static int __init omap4_i2c_init(void) omap_register_i2c_bus(4, 400, NULL, 0); return 0; } + +static void __init omap_sfh7741prox_init(void) +{ + int error; + + error = gpio_request(OMAP4_SFH7741_ENABLE_GPIO, sfh7741); + if (error 0) { + pr_err(%s:failed to request GPIO %d, error %d\n, + __func__, OMAP4_SFH7741_ENABLE_GPIO, error); + return; + } + + error = gpio_direction_output(OMAP4_SFH7741_ENABLE_GPIO , 0); + if (error 0) { + pr_err(%s: GPIO configuration failed: GPIO %d,error %d\n, +__func__, OMAP4_SFH7741_ENABLE_GPIO, error); + gpio_free(OMAP4_SFH7741_ENABLE_GPIO); + } +} + static void __init omap_4430sdp_init(void) { int status; @@ -448,6 +508,7 @@ static void __init omap_4430sdp_init(void) spi_register_board_info(sdp4430_spi_board_info, ARRAY_SIZE(sdp4430_spi_board_info)); } + omap_sfh7741prox_init(); Hello Shubro, I believe you are calling omap_sfh7741prox_init at the end of omap_4430sdp_init which means your sdp4430_gpio_keys_device is registered much before this. This could mean that the probe of your gpio-keys driver could get called before omap_sfh7741prox_init. Assume this is the case and your probe calls into pdata-enable or pdata-disable which is omap_prox_activate/omap_prox_deactivate as per this patch, these API's will try accessing gpio APIs for OMAP4_SFH7741_ENABLE_GPIO without a gpio_request happening for this pin as omap_sfh7741prox_init is called later. Maybe such a case might never arise. But I would say you should do a request_gpio for OMAP4_SFH7741_ENABLE_GPIO before the driver probe is called. Hi Thara, Thanks for your review. Will send another patch. Regards Thara
RE: [PATCH v2] omap: 4430sdp board support for the the GPIO keys
-Original Message- From: linux-omap-ow...@vger.kernel.org [mailto:linux-omap-ow...@vger.kernel.org] On Behalf Of Shubhrajyoti D Sent: Tuesday, August 24, 2010 10:58 AM To: linux-omap@vger.kernel.org Cc: Datta, Shubhrajyoti Subject: [PATCH v2] omap: 4430sdp board support for the the GPIO keys omap 4430sdp board support for the GPIO keys. The proximity sensor is connected to GPIO and is registered as a GPIO key. - Making the default state of the sensor off at bootup Signed-off-by: Shubhrajyoti D shubhrajy...@ti.com --- arch/arm/mach-omap2/board-4430sdp.c | 61 +++ 1 files changed, 61 insertions(+), 0 deletions(-) diff --git a/arch/arm/mach-omap2/board-4430sdp.c b/arch/arm/mach-omap2/board-4430sdp.c index 9447644..85b0e0c 100644 --- a/arch/arm/mach-omap2/board-4430sdp.c +++ b/arch/arm/mach-omap2/board-4430sdp.c @@ -20,6 +20,7 @@ #include linux/usb/otg.h #include linux/spi/spi.h #include linux/i2c/twl.h +#include linux/gpio_keys.h #include linux/regulator/machine.h #include linux/leds.h @@ -40,6 +41,8 @@ #define ETH_KS8851_IRQ 34 #define ETH_KS8851_POWER_ON 48 #define ETH_KS8851_QUART 138 +#define OMAP4_SFH7741_SENSOR_OUTPUT_GPIO 184 +#define OMAP4_SFH7741_ENABLE_GPIO188 static struct gpio_led sdp4430_gpio_leds[] = { { @@ -77,11 +80,47 @@ static struct gpio_led sdp4430_gpio_leds[] = { }; +static struct gpio_keys_button sdp4430_gpio_keys[] = { + { + .desc = Proximity Sensor, + .type = EV_SW, + .code = SW_FRONT_PROXIMITY, + .gpio = OMAP4_SFH7741_SENSOR_OUTPUT_GPIO, + .active_low = 0, + } +}; + static struct gpio_led_platform_data sdp4430_led_data = { .leds = sdp4430_gpio_leds, .num_leds = ARRAY_SIZE(sdp4430_gpio_leds), }; +static int omap_prox_activate(struct device *dev) +{ + gpio_set_value(OMAP4_SFH7741_ENABLE_GPIO , 1); + return 0; +} + +static void omap_prox_deactivate(struct device *dev) +{ + gpio_set_value(OMAP4_SFH7741_ENABLE_GPIO , 0); +} + +static struct gpio_keys_platform_data sdp4430_gpio_keys_data = { + .buttons= sdp4430_gpio_keys, + .nbuttons = ARRAY_SIZE(sdp4430_gpio_keys), + .enable = omap_prox_activate, + .disable= omap_prox_deactivate, +}; + +static struct platform_device sdp4430_gpio_keys_device = { + .name = gpio-keys, + .id = -1, + .dev= { + .platform_data = sdp4430_gpio_keys_data, + }, +}; + static struct platform_device sdp4430_leds_gpio = { .name = leds-gpio, .id = -1, @@ -161,6 +200,7 @@ static struct platform_device sdp4430_lcd_device = { static struct platform_device *sdp4430_devices[] __initdata = { sdp4430_lcd_device, + sdp4430_gpio_keys_device, sdp4430_leds_gpio, }; @@ -426,6 +466,26 @@ static int __init omap4_i2c_init(void) omap_register_i2c_bus(4, 400, NULL, 0); return 0; } + +static void __init omap_sfh7741prox_init(void) +{ + int error; + + error = gpio_request(OMAP4_SFH7741_ENABLE_GPIO, sfh7741); + if (error 0) { + pr_err(%s:failed to request GPIO %d, error %d\n, + __func__, OMAP4_SFH7741_ENABLE_GPIO, error); + return; + } + + error = gpio_direction_output(OMAP4_SFH7741_ENABLE_GPIO , 0); + if (error 0) { + pr_err(%s: GPIO configuration failed: GPIO %d,error %d\n, + __func__, OMAP4_SFH7741_ENABLE_GPIO, error); + gpio_free(OMAP4_SFH7741_ENABLE_GPIO); + } +} + static void __init omap_4430sdp_init(void) { int status; @@ -448,6 +508,7 @@ static void __init omap_4430sdp_init(void) spi_register_board_info(sdp4430_spi_board_info, ARRAY_SIZE(sdp4430_spi_board_info)); } + omap_sfh7741prox_init(); Hello Shubro, I believe you are calling omap_sfh7741prox_init at the end of omap_4430sdp_init which means your sdp4430_gpio_keys_device is registered much before this. This could mean that the probe of your gpio-keys driver could get called before omap_sfh7741prox_init. Assume this is the case and your probe calls into pdata-enable or pdata-disable which is omap_prox_activate/omap_prox_deactivate as per this patch, these API's will try accessing gpio APIs for OMAP4_SFH7741_ENABLE_GPIO without a gpio_request happening for this pin as omap_sfh7741prox_init is called later. Maybe such a case might never arise. But I would say you should do a request_gpio for OMAP4_SFH7741_ENABLE_GPIO before the driver probe is called. Regards Thara -- To unsubscribe from this list: send the line unsubscribe linux-omap in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2] omap: 4430sdp board support for the the GPIO keys
omap 4430sdp board support for the GPIO keys. The proximity sensor is connected to GPIO and is registered as a GPIO key. - Making the default state of the sensor off at bootup Signed-off-by: Shubhrajyoti D shubhrajy...@ti.com --- arch/arm/mach-omap2/board-4430sdp.c | 61 +++ 1 files changed, 61 insertions(+), 0 deletions(-) diff --git a/arch/arm/mach-omap2/board-4430sdp.c b/arch/arm/mach-omap2/board-4430sdp.c index 9447644..85b0e0c 100644 --- a/arch/arm/mach-omap2/board-4430sdp.c +++ b/arch/arm/mach-omap2/board-4430sdp.c @@ -20,6 +20,7 @@ #include linux/usb/otg.h #include linux/spi/spi.h #include linux/i2c/twl.h +#include linux/gpio_keys.h #include linux/regulator/machine.h #include linux/leds.h @@ -40,6 +41,8 @@ #define ETH_KS8851_IRQ 34 #define ETH_KS8851_POWER_ON48 #define ETH_KS8851_QUART 138 +#define OMAP4_SFH7741_SENSOR_OUTPUT_GPIO 184 +#define OMAP4_SFH7741_ENABLE_GPIO 188 static struct gpio_led sdp4430_gpio_leds[] = { { @@ -77,11 +80,47 @@ static struct gpio_led sdp4430_gpio_leds[] = { }; +static struct gpio_keys_button sdp4430_gpio_keys[] = { + { + .desc = Proximity Sensor, + .type = EV_SW, + .code = SW_FRONT_PROXIMITY, + .gpio = OMAP4_SFH7741_SENSOR_OUTPUT_GPIO, + .active_low = 0, + } +}; + static struct gpio_led_platform_data sdp4430_led_data = { .leds = sdp4430_gpio_leds, .num_leds = ARRAY_SIZE(sdp4430_gpio_leds), }; +static int omap_prox_activate(struct device *dev) +{ + gpio_set_value(OMAP4_SFH7741_ENABLE_GPIO , 1); + return 0; +} + +static void omap_prox_deactivate(struct device *dev) +{ + gpio_set_value(OMAP4_SFH7741_ENABLE_GPIO , 0); +} + +static struct gpio_keys_platform_data sdp4430_gpio_keys_data = { + .buttons= sdp4430_gpio_keys, + .nbuttons = ARRAY_SIZE(sdp4430_gpio_keys), + .enable = omap_prox_activate, + .disable= omap_prox_deactivate, +}; + +static struct platform_device sdp4430_gpio_keys_device = { + .name = gpio-keys, + .id = -1, + .dev= { + .platform_data = sdp4430_gpio_keys_data, + }, +}; + static struct platform_device sdp4430_leds_gpio = { .name = leds-gpio, .id = -1, @@ -161,6 +200,7 @@ static struct platform_device sdp4430_lcd_device = { static struct platform_device *sdp4430_devices[] __initdata = { sdp4430_lcd_device, + sdp4430_gpio_keys_device, sdp4430_leds_gpio, }; @@ -426,6 +466,26 @@ static int __init omap4_i2c_init(void) omap_register_i2c_bus(4, 400, NULL, 0); return 0; } + +static void __init omap_sfh7741prox_init(void) +{ + int error; + + error = gpio_request(OMAP4_SFH7741_ENABLE_GPIO, sfh7741); + if (error 0) { + pr_err(%s:failed to request GPIO %d, error %d\n, + __func__, OMAP4_SFH7741_ENABLE_GPIO, error); + return; + } + + error = gpio_direction_output(OMAP4_SFH7741_ENABLE_GPIO , 0); + if (error 0) { + pr_err(%s: GPIO configuration failed: GPIO %d,error %d\n, +__func__, OMAP4_SFH7741_ENABLE_GPIO, error); + gpio_free(OMAP4_SFH7741_ENABLE_GPIO); + } +} + static void __init omap_4430sdp_init(void) { int status; @@ -448,6 +508,7 @@ static void __init omap_4430sdp_init(void) spi_register_board_info(sdp4430_spi_board_info, ARRAY_SIZE(sdp4430_spi_board_info)); } + omap_sfh7741prox_init(); } static void __init omap_4430sdp_map_io(void) -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe linux-omap in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2] omap: 4430sdp board support for the the GPIO keys
omap 4430sdp board support for the GPIO keys. The proximity sensor is connected to GPIO and is registered as a GPIO key. Signed-off-by: Shubhrajyoti D shubhrajy...@ti.com --- arch/arm/mach-omap2/board-4430sdp.c | 64 +++ 1 files changed, 64 insertions(+), 0 deletions(-) diff --git a/arch/arm/mach-omap2/board-4430sdp.c b/arch/arm/mach-omap2/board-4430sdp.c index 9447644..699620d 100644 --- a/arch/arm/mach-omap2/board-4430sdp.c +++ b/arch/arm/mach-omap2/board-4430sdp.c @@ -20,6 +20,7 @@ #include linux/usb/otg.h #include linux/spi/spi.h #include linux/i2c/twl.h +#include linux/gpio_keys.h #include linux/regulator/machine.h #include linux/leds.h @@ -40,6 +41,11 @@ #define ETH_KS8851_IRQ 34 #define ETH_KS8851_POWER_ON48 #define ETH_KS8851_QUART 138 +#define OMAP4_SFH7741_SENSOR_OUTPUT_GPIO 184 +#define OMAP4_SFH7741_ENABLE_GPIO 188 + +static int omap_prox_activate(struct device *dev); +static void omap_prox_deactivate(struct device *dev); static struct gpio_led sdp4430_gpio_leds[] = { { @@ -77,11 +83,36 @@ static struct gpio_led sdp4430_gpio_leds[] = { }; +static struct gpio_keys_button sdp4430_gpio_keys[] = { + { + .desc = Proximity Sensor, + .type = EV_SW, + .code = SW_FRONT_PROXIMITY, + .gpio = OMAP4_SFH7741_SENSOR_OUTPUT_GPIO, + .active_low = 0, + } +}; + static struct gpio_led_platform_data sdp4430_led_data = { .leds = sdp4430_gpio_leds, .num_leds = ARRAY_SIZE(sdp4430_gpio_leds), }; +static struct gpio_keys_platform_data sdp4430_gpio_keys_data = { + .buttons= sdp4430_gpio_keys, + .nbuttons = ARRAY_SIZE(sdp4430_gpio_keys), + .enable = omap_prox_activate, + .disable= omap_prox_deactivate, +}; + +static struct platform_device sdp4430_gpio_keys_device = { + .name = gpio-keys, + .id = -1, + .dev= { + .platform_data = sdp4430_gpio_keys_data, + }, +}; + static struct platform_device sdp4430_leds_gpio = { .name = leds-gpio, .id = -1, @@ -161,6 +192,7 @@ static struct platform_device sdp4430_lcd_device = { static struct platform_device *sdp4430_devices[] __initdata = { sdp4430_lcd_device, + sdp4430_gpio_keys_device, sdp4430_leds_gpio, }; @@ -426,6 +458,37 @@ static int __init omap4_i2c_init(void) omap_register_i2c_bus(4, 400, NULL, 0); return 0; } + +static int omap_prox_activate(struct device *dev) +{ + gpio_set_value(OMAP4_SFH7741_ENABLE_GPIO , 1); + return 0; +} + +static void omap_prox_deactivate(struct device *dev) +{ + gpio_set_value(OMAP4_SFH7741_ENABLE_GPIO , 0); +} + +static void omap_sfh7741prox_init(void) +{ + int error; + + error = gpio_request(OMAP4_SFH7741_ENABLE_GPIO, sfh7741); + if (error 0) { + pr_err(failed to request GPIO %d, error %d\n, + OMAP4_SFH7741_ENABLE_GPIO, error); + return; + } + + error = gpio_direction_output(OMAP4_SFH7741_ENABLE_GPIO , 1); + if (error 0) { + pr_err(%s: GPIO configuration failed: GPIO %d,error %d\n, +__func__, OMAP4_SFH7741_ENABLE_GPIO, error); + gpio_free(OMAP4_SFH7741_ENABLE_GPIO); + } +} + static void __init omap_4430sdp_init(void) { int status; @@ -448,6 +511,7 @@ static void __init omap_4430sdp_init(void) spi_register_board_info(sdp4430_spi_board_info, ARRAY_SIZE(sdp4430_spi_board_info)); } + omap_sfh7741prox_init(); } static void __init omap_4430sdp_map_io(void) -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe linux-omap in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html