input: pmic8xxx-keypad: Add row and column gpio configuration
Subsystems (3)
PATCH v2 2/3 input: pmic8xxx-keypad: Add row and column gpio configuration
In reply to a message not in the archive--- drivers/input/keyboard/pmic8xxx-keypad.c | 74 ++++++++++++++++++++++++++++++ include/linux/input/pmic8xxx-keypad.h | 2 + 2 files changed, 76 insertions(+), 0 deletions(-)
drivers/input/keyboard/pmic8xxx-keypad.c +74 -0
@@ -21,6 +21,7 @@#include <linux/mutex.h> #include <linux/mfd/pm8xxx/core.h> +#include <linux/mfd/pm8xxx/gpio.h> #include <linux/input/pmic8xxx-keypad.h> #define PM8XXX_MAX_ROWS 18
@@ -446,6 +447,64 @@ static int __devinit pmic8xxx_kpd_init(struct pmic8xxx_kp *kp) } +static int __devinit pmic8xxx_kp_config_drv (int gpio_start,int num_gpios) +{ +int rc; +struct pm_gpio kypd_drv = { + .direction =PM_GPIO_DIR_OUT , + .output_buffer =PM_GPIO_OUT_BUF_OPEN_DRAIN , + .output_value =0 , + .pull =PM_GPIO_PULL_NO , + .vin_sel =PM_GPIO_VIN_S3 , + .out_strength =PM_GPIO_STRENGTH_LOW , + .function =PM_GPIO_FUNC_1 , + .inv_int_pol =1 , + }; + +if (gpio_start <0 || num_gpios <0 || + num_gpios > (PM8XXX_MAX_ROWS + gpio_start)) +return -EINVAL ; + +while (num_gpios--) { + rc =pm8xxx_gpio_config (gpio_start++, &kypd_drv); +if (rc) { +pr_err ("%s: FAIL pm8xxx_gpio_config(): rc=%d.\n" , + __func__, rc); +return rc; + } + } + +return 0 ; +} + +static int __devinit pmic8xxx_kp_config_sns (int gpio_start,int num_gpios) +{ +int rc; +struct pm_gpio kypd_sns = { + .direction =PM_GPIO_DIR_IN , + .pull =PM_GPIO_PULL_UP_31P5 , + .vin_sel =PM_GPIO_VIN_S3 , + .out_strength =PM_GPIO_STRENGTH_NO , + .function =PM_GPIO_FUNC_NORMAL , + .inv_int_pol =1 , + }; + +if (gpio_start <0 || num_gpios <0 || + num_gpios > (PM8XXX_MAX_COLS + gpio_start)) +return -EINVAL ; + +while (num_gpios--) { + rc =pm8xxx_gpio_config (gpio_start++, &kypd_sns); +if (rc) { +pr_err ("%s: FAIL pm8xxx_gpio_config(): rc=%d.\n" , + __func__, rc); +return rc; + } + } + +return 0 ; +} +static int pmic8xxx_kp_enable (struct pmic8xxx_kp *kp) {int rc;
@@ -609,6 +668,20 @@ static int __devinit pmic8xxx_kp_probe(struct platform_device *pdev) goto err_get_irq; } + rc =pmic8xxx_kp_config_sns (pdata->cols_gpio_start, + pdata->num_cols); +if (rc <0 ) { +dev_err (&pdev->dev,"unable to configure keypad sense lines\n" ); + goto err_gpio_config; + } + + rc =pmic8xxx_kp_config_drv (pdata->rows_gpio_start, + pdata->num_rows); +if (rc <0 ) { +dev_err (&pdev->dev,"unable to configure keypad drive lines\n" ); + goto err_gpio_config; + } + rc =request_any_context_irq (kp->key_sense_irq, pmic8xxx_kp_irq,IRQF_TRIGGER_RISING ,"pmic-keypad" , kp);if (rc <0 ) {
@@ -645,6 +718,7 @@ err_pmic_reg_read:free_irq (kp->key_stuck_irq,NULL ); err_req_stuck_irq:free_irq (kp->key_sense_irq,NULL ); +err_gpio_config: err_get_irq:input_free_device (kp->input); err_alloc_device:
include/linux/input/pmic8xxx-keypad.h +2 -0
@@ -38,6 +38,8 @@ struct pm8xxx_keypad_platform_data {unsigned int num_cols;unsigned int num_rows; +unsigned int rows_gpio_start; +unsigned int cols_gpio_start;unsigned int debounce_ms;unsigned int scan_delay_ms;
Signature · 1 line
Sent by a consultant of the Qualcomm Innovation Center, Inc.\nThe Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH v2 3/3 input: pmic8xxx_pwrkey: Add support for power key
In reply to a message not in the archiveFrom: Trilok Soni <[email protected]>
Add support for PMIC8XXX power key driven over dedicated KYPD_PWR_N pin. It allows the user to specify the amount of time by which the power key reporting can be delayed.
--- drivers/input/misc/Kconfig | 11 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/pmic8xxx-pwrkey.c | 303 +++++++++++++++++++++++++++++++++ include/linux/input/pmic8xxx-pwrkey.h | 35 ++++ 4 files changed, 350 insertions(+), 0 deletions(-) create mode 100644 drivers/input/misc/pmic8xxx-pwrkey.c create mode 100644 include/linux/input/pmic8xxx-pwrkey.h
drivers/input/misc/Kconfig +11 -0
@@ -330,6 +330,17 @@ config INPUT_PWM_BEEPER To compile this driver as a module, choose M here: the module will be called pwm-beeper. +config INPUT_PMIC8XXX_PWRKEY + tristate "PMIC8XXX power key support" + depends on MFD_PM8XXX + help + Say Y here if you want support for the PMIC8XXX power key. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called pmic8xxx-pwrkey. + config INPUT_GPIO_ROTARY_ENCODER tristate "Rotary encoders connected to GPIO pins" depends on GPIOLIB && GENERIC_GPIO
drivers/input/misc/Makefile +1 -0
@@ -33,6 +33,7 @@ obj-$(CONFIG_INPUT_PCF8574) += pcf8574_keypad.o obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o obj-$(CONFIG_INPUT_POWERMATE) += powermate.o obj-$(CONFIG_INPUT_PWM_BEEPER) += pwm-beeper.o +obj-$(CONFIG_INPUT_PMIC8XXX_PWRKEY) += pmic8xxx-pwrkey.o obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o obj-$(CONFIG_INPUT_GPIO_ROTARY_ENCODER) += rotary_encoder.o obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o
drivers/input/misc/pmic8xxx-pwrkey.c new file +303 -0
303 lines not on this page · raw message
include/linux/input/pmic8xxx-pwrkey.h new file +35 -0
@@ -0,0 +1,35 @@ +/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef __PMIC8XXX_PWRKEY_H__ +#define __PMIC8XXX_PWRKEY_H__ + +#define PM8XXX_PWRKEY_DEV_NAME "pm8xxx-pwrkey" + +/** +* struct pm8xxx_pwrkey_platform_data - platform data for pwrkey driver +* @pull up: power on register control for pull up/down configuration +* @pwrkey_time_ms: time after which power key event should be generated, if +* key is released before then end key is reported. +* Supply zero for only power key reporting. +* @kpd_trigger_delay_us: time delay for power key state change interrupt +* trigger. +* @wakeup: configure power key as wakeup source +*/ +struct pm8xxx_pwrkey_platform_data { +bool pull_up; +u16 pwrkey_time_ms; +u32 kpd_trigger_delay_us; +u32 wakeup; +}; + +#endif /* __PMIC8XXX_PWRKEY_H__ */
Signature · 1 line
Sent by a consultant of the Qualcomm Innovation Center, Inc.\nThe Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Dmitry Torokhov
maintainerQuoted 2 lines · Anirudh Ghayal
Cc Dmitry Torokhov <[email protected]>Signed-off-by Anirudh Ghayal <[email protected]>
Looks reasonable with the following nitpicks:
Quoted 30 lines
--- drivers/input/keyboard/pmic8xxx-keypad.c | 74 ++++++++++++++++++++++++++++++ include/linux/input/pmic8xxx-keypad.h | 2 + 2 files changed, 76 insertions(+), 0 deletions(-)drivers/input/keyboard/pmic8xxx-keypad.c +10
-0@@ -21,6 +21,7 @@#include <linux/mutex.h> #include <linux/mfd/pm8xxx/core.h> +#include <linux/mfd/pm8xxx/gpio.h> #include <linux/input/pmic8xxx-keypad.h> #define PM8XXX_MAX_ROWS 18@@ -446,6 +447,64 @@ static int __devinit pmic8xxx_kpd_init(struct pmic8xxx_kp *kp) } +static int __devinit pmic8xxx_kp_config_drv (int gpio_start,int num_gpios) +{ +int rc; +struct pm_gpio kypd_drv = { + .direction =PM_GPIO_DIR_OUT , + .output_buffer =PM_GPIO_OUT_BUF_OPEN_DRAIN , + .output_value =0 , + .pull =PM_GPIO_PULL_NO , + .vin_sel =PM_GPIO_VIN_S3 ,
drivers/input/keyboard/pmic8xxx-keypad.c static int __devinit pmic8xxx_kpd_init(struct pmic8xxx_kp *kp) · line 468
Quoted 10 lines
drivers/input/keyboard/pmic8xxx-keypad.c +10
-0+ .out_strength = PM_GPIO_STRENGTH_LOW, + .function = PM_GPIO_FUNC_1, + .inv_int_pol = 1, + }; + +if (gpio_start <0 || num_gpios <0 || + num_gpios > (PM8XXX_MAX_ROWS + gpio_start)) +return -EINVAL ; + +while (num_gpios--) {
Personally I prefer "while (x--)" constructs when you really need to count backwards, for example when unwinding in error handling path. I'd prefer more straightforward
for (i = 0; i < num_gpios; i++) {
rc = pm8xxx_gpio_config(gpio_start + i, &kypd_drv);drivers/input/keyboard/pmic8xxx-keypad.c static int __devinit pmic8xxx_kpd_init(struct pmic8xxx_kp *kp) · line 472
Quoted 4 lines
drivers/input/keyboard/pmic8xxx-keypad.c +4
-0+ rc =pm8xxx_gpio_config (gpio_start++, &kypd_drv); +if (rc) { +pr_err ("%s: FAIL pm8xxx_gpio_config(): rc=%d.\n" , + __func__, rc);
Use dev_err() here as well, and probably print the pin number that failed?
Quoted 22 lines
drivers/input/keyboard/pmic8xxx-keypad.c +22
-0+return rc; + } + } + +return 0 ; +} + +static int __devinit pmic8xxx_kp_config_sns (int gpio_start,int num_gpios) +{ +int rc; +struct pm_gpio kypd_sns = { + .direction =PM_GPIO_DIR_IN , + .pull =PM_GPIO_PULL_UP_31P5 , + .vin_sel =PM_GPIO_VIN_S3 , + .out_strength =PM_GPIO_STRENGTH_NO , + .function =PM_GPIO_FUNC_NORMAL , + .inv_int_pol =1 , + }; + +if (gpio_start <0 || num_gpios <0 || + num_gpios > (PM8XXX_MAX_COLS + gpio_start)) +return -EINVAL ;
drivers/input/keyboard/pmic8xxx-keypad.c static int __devinit pmic8xxx_kpd_init(struct pmic8xxx_kp *kp) · line 504
Quoted 10 lines
drivers/input/keyboard/pmic8xxx-keypad.c +10
-0+ +while (num_gpios--) { + rc =pm8xxx_gpio_config (gpio_start++, &kypd_sns); +if (rc) { +pr_err ("%s: FAIL pm8xxx_gpio_config(): rc=%d.\n" , + __func__, rc); +return rc; + } + } +
This function is exactly as the one before. You can fold them together if you pass "struct pm_gpio" as a 3rd argument.
Quoted 40 lines
drivers/input/keyboard/pmic8xxx-keypad.c +18
-0+return 0 ; +} +static int pmic8xxx_kp_enable (struct pmic8xxx_kp *kp) {int rc;@@ -609,6 +668,20 @@ static int __devinit pmic8xxx_kp_probe(struct platform_device *pdev) goto err_get_irq; } + rc =pmic8xxx_kp_config_sns (pdata->cols_gpio_start, + pdata->num_cols); +if (rc <0 ) { +dev_err (&pdev->dev,"unable to configure keypad sense lines\n" ); + goto err_gpio_config; + } + + rc =pmic8xxx_kp_config_drv (pdata->rows_gpio_start, + pdata->num_rows); +if (rc <0 ) { +dev_err (&pdev->dev,"unable to configure keypad drive lines\n" ); + goto err_gpio_config; + } + rc =request_any_context_irq (kp->key_sense_irq, pmic8xxx_kp_irq,IRQF_TRIGGER_RISING ,"pmic-keypad" , kp);if (rc <0 ) {@@ -645,6 +718,7 @@ err_pmic_reg_read:free_irq (kp->key_stuck_irq,NULL ); err_req_stuck_irq:free_irq (kp->key_sense_irq,NULL ); +err_gpio_config: err_get_irq:input_free_device (kp->input); err_alloc_device:include/linux/input/pmic8xxx-keypad.h +0
-0
include/linux/input/pmic8xxx-keypad.h struct pm8xxx_keypad_platform_data { · line 45
Quoted 8 lines
include/linux/input/pmic8xxx-keypad.h +2
-0@@ -38,6 +38,8 @@ struct pm8xxx_keypad_platform_data {unsigned int num_cols;unsigned int num_rows; +unsigned int rows_gpio_start; +unsigned int cols_gpio_start;unsigned int debounce_ms;unsigned int scan_delay_ms;
Thanks.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH V2 3/3] input: pmic8xxx_pwrkey: Add support for power key
In reply to Anirudh GhayalHi Anirudh,
Quoted 15 lines · Anirudh Ghayal
From: Trilok Soni <[email protected]>
Add support for PMIC8XXX power key driven over dedicated
KYPD_PWR_Npin. It allows the user to specify the amount of time by which the power key reporting can be delayed.drivers/input/misc/pmic8xxx-pwrkey.c new file +9
-0+ +static irqreturn_t pwrkey_press_irq (int irq,void *_pwrkey) +{ +struct pmic8xxx_pwrkey *pwrkey = _pwrkey; +const struct pm8xxx_pwrkey_platform_data *pdata = pwrkey->pdata; +unsigned long flags; + +/* no pwrkey time duration, means no screen lock key simulation */ +if (!pwrkey->pdata->pwrkey_time_ms) {
drivers/input/misc/pmic8xxx-pwrkey.c line 79
Quoted 10 lines
drivers/input/misc/pmic8xxx-pwrkey.c new file +10
-0+input_report_key (pwrkey->pwr,KEY_POWER ,1 ); +input_sync (pwrkey->pwr); +return IRQ_HANDLED ; + } + +spin_lock_irqsave (&pwrkey->lock, flags); + +input_report_key (pwrkey->pwr,KEY_SCREENLOCK ,1 ); +input_sync (pwrkey->pwr); +
I am very sorry for misleading Trilok and you earlier but I think this kind of transformation should be done in your userspace framework. Have the driver emit KEY_SCREENLOCK and have userspace initiate device shutdown if it detects that KEY_SCREENLOCK is pressed for longer than X seconds.
Thanks.
Signature · 1 line
Dmitry
Hi Dmitry,
Quoted 42 lines · Dmitry Torokhov
Quoted 2 lines · Anirudh Ghayal
Cc Dmitry Torokhov<[email protected]>Signed-off-by Anirudh Ghayal<[email protected]>Looks reasonable with the following nitpicks:
Quoted 36 lines
--- drivers/input/keyboard/pmic8xxx-keypad.c | 74 ++++++++++++++++++++++++++++++ include/linux/input/pmic8xxx-keypad.h | 2 + 2 files changed, 76 insertions(+), 0 deletions(-)drivers/input/keyboard/pmic8xxx-keypad.c +16
-0@@ -21,6 +21,7 @@#include <linux/mutex.h> #include <linux/mfd/pm8xxx/core.h> +#include <linux/mfd/pm8xxx/gpio.h> #include <linux/input/pmic8xxx-keypad.h> #define PM8XXX_MAX_ROWS 18@@ -446,6 +447,64 @@ static int __devinit pmic8xxx_kpd_init(struct pmic8xxx_kp *kp) } +static int __devinit pmic8xxx_kp_config_drv (int gpio_start,int num_gpios) +{ +int rc; +struct pm_gpio kypd_drv = { + .direction =PM_GPIO_DIR_OUT , + .output_buffer =PM_GPIO_OUT_BUF_OPEN_DRAIN , + .output_value =0 , + .pull =PM_GPIO_PULL_NO , + .vin_sel =PM_GPIO_VIN_S3 , + .out_strength =PM_GPIO_STRENGTH_LOW , + .function =PM_GPIO_FUNC_1 , + .inv_int_pol =1 , + }; + + if (gpio_start< 0 || num_gpios< 0 ||
Quoted 8 lines
drivers/input/keyboard/pmic8xxx-keypad.c static int __devinit pmic8xxx_kpd_init(struct pmic8xxx_kp *kp) · line 468
Quoted 4 lines
drivers/input/keyboard/pmic8xxx-keypad.c +4
-0+ num_gpios> (PM8XXX_MAX_ROWS + gpio_start)) +return -EINVAL ; + +while (num_gpios--) {Personally I prefer "while (x--)" constructs when you really need to count backwards, for example when unwinding in error handling path. I'd prefer more straightforward
Okay.
Quoted 11 lines
for (i = 0; i< num_gpios; i++) { rc = pm8xxx_gpio_config(gpio_start + i,&kypd_drv);drivers/input/keyboard/pmic8xxx-keypad.c static int __devinit pmic8xxx_kpd_init(struct pmic8xxx_kp *kp) · line 472
Quoted 4 lines
drivers/input/keyboard/pmic8xxx-keypad.c +4
-0+ rc =pm8xxx_gpio_config (gpio_start++,&kypd_drv); +if (rc) { +pr_err ("%s: FAIL pm8xxx_gpio_config(): rc=%d.\n" , + __func__, rc);Use
dev_err()here as well, and probably print the pin number that failed?
Okay.
Quoted 28 lines
Quoted 28 lines
drivers/input/keyboard/pmic8xxx-keypad.c +27
-0+return rc; + } + } + +return 0 ; +} + +static int __devinit pmic8xxx_kp_config_sns (int gpio_start,int num_gpios) +{ +int rc; +struct pm_gpio kypd_sns = { + .direction =PM_GPIO_DIR_IN , + .pull =PM_GPIO_PULL_UP_31P5 , + .vin_sel =PM_GPIO_VIN_S3 , + .out_strength =PM_GPIO_STRENGTH_NO , + .function =PM_GPIO_FUNC_NORMAL , + .inv_int_pol =1 , + }; + +if (gpio_start<0 || num_gpios<0 || + num_gpios> (PM8XXX_MAX_COLS + gpio_start)) +return -EINVAL ; + +while (num_gpios--) { + rc =pm8xxx_gpio_config (gpio_start++,&kypd_sns); +if (rc) { + pr_err("%s: FAIL pm8xxx_gpio_config(): rc=%d.\n",
Quoted 8 lines
drivers/input/keyboard/pmic8xxx-keypad.c static int __devinit pmic8xxx_kpd_init(struct pmic8xxx_kp *kp) · line 476
Quoted 5 lines
drivers/input/keyboard/pmic8xxx-keypad.c +5
-0+ __func__, rc); +return rc; + } + } +This function is exactly as the one before. You can fold them together if you pass "struct
pm_gpio" as a 3rd argument.
Agreed, I will do that.
Quoted 47 lines
Quoted 47 lines
drivers/input/keyboard/pmic8xxx-keypad.c +18
-0+return 0 ; +} +static int pmic8xxx_kp_enable (struct pmic8xxx_kp *kp) {int rc;@@ -609,6 +668,20 @@ static int __devinit pmic8xxx_kp_probe(struct platform_device *pdev) goto err_get_irq; } + rc =pmic8xxx_kp_config_sns (pdata->cols_gpio_start, + pdata->num_cols); +if (rc<0 ) { +dev_err (&pdev->dev,"unable to configure keypad sense lines\n" ); + goto err_gpio_config; + } + + rc =pmic8xxx_kp_config_drv (pdata->rows_gpio_start, + pdata->num_rows); +if (rc<0 ) { +dev_err (&pdev->dev,"unable to configure keypad drive lines\n" ); + goto err_gpio_config; + } + rc =request_any_context_irq (kp->key_sense_irq, pmic8xxx_kp_irq,IRQF_TRIGGER_RISING ,"pmic-keypad" , kp);if (rc<0 ) {@@ -645,6 +718,7 @@ err_pmic_reg_read:free_irq (kp->key_stuck_irq,NULL ); err_req_stuck_irq:free_irq (kp->key_sense_irq,NULL ); +err_gpio_config: err_get_irq:input_free_device (kp->input); err_alloc_device:include/linux/input/pmic8xxx-keypad.h +2
-0@@ -38,6 +38,8 @@ struct pm8xxx_keypad_platform_data {unsigned int num_cols;unsigned int num_rows; +unsigned int rows_gpio_start; +unsigned int cols_gpio_start;
Quoted 5 lines
include/linux/input/pmic8xxx-keypad.h struct pm8xxx_keypad_platform_data { · line 45
Quoted 2 lines
include/linux/input/pmic8xxx-keypad.h +0
-0unsigned int debounce_ms;unsigned int scan_delay_ms;Thanks.
Thank you for the comments. I will submit a patch with these changes.
~Anirudh
Re: [PATCH V2 3/3] input: pmic8xxx_pwrkey: Add support for power key
In reply to Dmitry TorokhovHi Dmitry,
Quoted 26 lines · Dmitry Torokhov
Hi Anirudh,
Quoted 23 lines · Anirudh Ghayal
From: Trilok Soni<[email protected]>
Add support for PMIC8XXX power key driven over dedicated
KYPD_PWR_Npin. It allows the user to specify the amount of time by which the power key reporting can be delayed.drivers/input/misc/pmic8xxx-pwrkey.c new file +17
-0+ +static irqreturn_t pwrkey_press_irq (int irq,void *_pwrkey) +{ +struct pmic8xxx_pwrkey *pwrkey = _pwrkey; +const struct pm8xxx_pwrkey_platform_data *pdata = pwrkey->pdata; +unsigned long flags; + +/* no pwrkey time duration, means no screen lock key simulation */ +if (!pwrkey->pdata->pwrkey_time_ms) { +input_report_key (pwrkey->pwr,KEY_POWER ,1 ); +input_sync (pwrkey->pwr); +return IRQ_HANDLED ; + } + +spin_lock_irqsave (&pwrkey->lock, flags); + +input_report_key (pwrkey->pwr,KEY_SCREENLOCK ,1 );
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ input_sync(pwrkey->pwr); +I am very sorry for misleading Trilok and you earlier but I think this kind of transformation should be done in your userspace framework. Have the driver emit
KEY_SCREENLOCKand have userspace initiate device shutdown if it detects thatKEY_SCREENLOCKis pressed for longer than X seconds.
After giving this a further thought, I agree that this handling should be in the userspace. I will submit a new patch with the changes.
Quoted 3 lines
Thanks.
Thank you,
~Anirudh