input: misc: Add PixArt PAJ7620 gesture sensor
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
v2 cover input: misc: Add PixArt PAJ7620 gesture sensor
This series adds support for the PixArt PAJ7620 gesture sensor.
Following review feedback on v1, the driver has been moved from IIO to the Input subsystem as gestures are user-interaction events. The bindings have been updated to include mandatory power supplies and GPIO controller properties.
Changes in v2:
- Moved driver from drivers/iio/light to drivers/input/misc
- Updated DT bindings to include mandatory vdd, vbus, and vled supplies
- Added Runtime PM support with autosuspend logic
- Combined bindings and driver into a single series
Harpreet Saini (2):
dt-bindings: input: Add PixArt PAJ7620 gesture sensor
input: misc: Add PixArt PAJ7620 gesture sensor driver
.../bindings/input/pixart,paj7620.yaml | 70 ++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + drivers/input/misc/Kconfig | 12 + drivers/input/misc/Makefile | 1 + drivers/input/misc/paj7620.c | 350 ++++++++++++++++++ 5 files changed, 435 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/pixart,paj7620.yaml create mode 100644 drivers/input/misc/paj7620.c
Signature · 1 line
2.43.0
PATCH v2 1/2 dt-bindings: input: Add PixArt PAJ7620 gesture sensor
--- .../bindings/input/pixart,paj7620.yaml | 70 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + 2 files changed, 72 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/pixart,paj7620.yaml
Documentation/devicetree/bindings/input/pixart,paj7620.yaml new file +70 -0
@@ -0,0 +1,70 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org +$schema: http://devicetree.org + +title: PixArt PAJ7620 Gesture Sensor + +maintainers: + - Harpreet Saini <[email protected]> + +description: | + The PixArt PAJ7620 is a gesture recognition sensor with an integrated + infrared LED and CMOS array. It communicates over an I2C interface and + provides gesture data via a dedicated interrupt pin. + +properties: + compatible: + const: pixart,paj7620 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vdd-supply: + description: Main power supply. + + vbus-supply: + description: I/O and I2C bus power supply. + + vled-supply: + description: Power for the integrated IR LED. + + # Added per reviewer request for completeness + gpio-controller: true + + "#gpio-cells": + const: 2 + +required: + - compatible + - reg + - interrupts + - vdd-supply + - vbus-supply + - vled-supply + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + i2c { + #address-cells = <1>; + #size-cells = <0>; + + gesture@73 { + compatible = "pixart,paj7620"; + reg = <0x73>; + interrupt-parent = <&gpio>; + interrupts = <4 IRQ_TYPE_EDGE_FALLING>; + vdd-supply = <®_3v3>; + vbus-supply = <®_1v8>; + vled-supply = <®_3v3>; + gpio-controller; + #gpio-cells = <2>; + }; + };
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -1273,6 +1273,8 @@ patternProperties: description: Pine64 "^pineriver,.*": description: Shenzhen PineRiver Designs Co., Ltd. + "^pixart,.*": + description: PixArt Imaging Inc. "^pixcir,.*": description: PIXCIR MICROELECTRONICS Co., Ltd "^plantower,.*":
Signature · 1 line
2.43.0
Re: [PATCH v2 1/2] dt-bindings: input: Add PixArt PAJ7620 gesture sensor
Quoted 7 lines · Harpreet Saini
Signed-off-by Harpreet Saini <[email protected]>--- .../bindings/input/pixart,paj7620.yaml | 70 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + 2 files changed, 72 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/pixart,paj7620.yaml
Comments from v1 apply. Respond to the instead of ignoring.
Documentation/devicetree/bindings/input/pixart,paj7620.yaml line 5
Quoted 11 lines
Documentation/devicetree/bindings/input/pixart,paj7620.yaml new file +5
-0@@ -0,0 +1,70 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org +$schema: http://devicetree.org
There is no such syntax. Don't invent own coding style.
Best regards,
Krzysztof
PATCH v2 2/2 input: misc: Add PixArt PAJ7620 gesture sensor driver
In reply to Harpreet SainiThis driver adds support for the PixArt PAJ7620 gesture sensor. It implements hand gesture recognition (up, down, left, right, etc.) and reports them as standard input key events. The driver includes power management support via Runtime PM.
--- drivers/input/misc/Kconfig | 12 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/paj7620.c | 350 +++++++++++++++++++++++++++++++++++ 3 files changed, 363 insertions(+) create mode 100644 drivers/input/misc/paj7620.c
drivers/input/misc/Kconfig +12 -0
@@ -453,6 +453,18 @@ config INPUT_KXTJ9 To compile this driver as a module, choose M here: the module will be called kxtj9. +config INPUT_PAJ7620 + tristate "PixArt PAJ7620 Gesture Sensor" + depends on I2C + select REGMAP_I2C + help + Say Y here if you want to support the PixArt PAJ7620 gesture + sensor. This sensor supports 9 hand gestures and communicates + over the I2C bus. + + To compile this driver as a module, choose M here: the + module will be called paj7620. + config INPUT_POWERMATE tristate "Griffin PowerMate and Contour Jog support" depends on USB_ARCH_HAS_HCD
drivers/input/misc/Makefile +1 -0
@@ -67,6 +67,7 @@ obj-$(CONFIG_INPUT_PF1550_ONKEY) += pf1550-onkey.o obj-$(CONFIG_INPUT_PM8941_PWRKEY) += pm8941-pwrkey.o obj-$(CONFIG_INPUT_PM8XXX_VIBRATOR) += pm8xxx-vibrator.o obj-$(CONFIG_INPUT_PMIC8XXX_PWRKEY) += pmic8xxx-pwrkey.o +obj-$(CONFIG_INPUT_PAJ7620) += paj7620.o obj-$(CONFIG_INPUT_POWERMATE) += powermate.o obj-$(CONFIG_INPUT_PWM_BEEPER) += pwm-beeper.o obj-$(CONFIG_INPUT_PWM_VIBRA) += pwm-vibra.o
drivers/input/misc/paj7620.c new file +350 -0
350 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v2 2/2] input: misc: Add PixArt PAJ7620 gesture sensor driver
Quoted 28 lines · Harpreet Saini
drivers/input/misc/paj7620.c new file +28
-0+ +static int paj7620_init (struct paj7620_data *data) +{ +int state =0 , ret, i; + +/* 1. Wake-up sequence: Read register 0x00 until it returns 0x20 */ +for (i =0 ; i <10 ; i++) { + ret =regmap_read (data->regmap,0x00 , &state); +if (ret >=0 && state ==0x20 ) +break ; +usleep_range (1000 ,2000 ); + } + +if (state !=0x20 ) { +dev_err (&data->client->dev,"Sensor wake-up failed (0x%02x)\n" , state); +return -ENODEV ; + } + +/* 2. Blast full register array into PAJ7620 instantly */ + ret =regmap_multi_reg_write (data->regmap, Init_Register, +ARRAY_SIZE (Init_Register)); +if (ret <0 ) { +dev_err (&data->client->dev,"Multi-reg write failed (%d)\n" , ret); +return ret; + } + + ret =regmap_write (data->regmap,PAJ7620_REG_BANK_SEL ,0x00 ); +if (ret <0 )
drivers/input/misc/paj7620.c line 161
Quoted 10 lines
drivers/input/misc/paj7620.c new file +10
-0+return ret; + + ret =regmap_multi_reg_write (data->regmap, Init_Gesture_Array, +ARRAY_SIZE (Init_Gesture_Array)); +if (ret <0 ) { +dev_err (&data->client->dev,"Multi-reg write failed (%d)\n" , ret); +return ret; + } + +dev_info (&data->client->dev,"Gesture Sensor Registers Initialized\n" );
Drop, driver should be silent.
...
Quoted 8 lines
drivers/input/misc/paj7620.c new file +8
-0+ data->client = client; +i2c_set_clientdata (client, data); + + data->supplies[0 ].supply ="vdd" ; + data->supplies[1 ].supply ="vbus" ; + data->supplies[2 ].supply ="vled" ; + + ret =devm_regulator_bulk_get (&client->dev,ARRAY_SIZE (data->supplies), data->supplies);
drivers/input/misc/paj7620.c line 260
Quoted 10 lines
drivers/input/misc/paj7620.c new file +10
-0+if (ret) +return dev_err_probe (&client->dev, ret,"Failed to get regulators\n" ); + + ret =regulator_bulk_enable (ARRAY_SIZE (data->supplies), data->supplies); +if (ret) +return ret; + + data->regmap =devm_regmap_init_i2c (client, &paj7620_reg_config); +if (IS_ERR (data->regmap)) +return PTR_ERR (data->regmap);
Leaking regulator enable.
drivers/input/misc/paj7620.c line 268
Quoted 8 lines
drivers/input/misc/paj7620.c new file +8
-0+ + ret =paj7620_init (data); +if (ret) + goto err_reg; + + data->idev =devm_input_allocate_device (&client->dev); +if (!data->idev) { + ret = -ENOMEM ; goto err_reg;
Messed syntax/wrapped lines.
And you must not print error msg on ENOMEM error.
Quoted 21 lines
drivers/input/misc/paj7620.c new file +21
-0+ } + + data->idev->name ="PAJ7620 Gesture Sensor" ; + data->idev->id.bustype =BUS_I2C ; + +input_set_capability (data->idev,EV_KEY ,KEY_UP ); +input_set_capability (data->idev,EV_KEY ,KEY_DOWN ); +input_set_capability (data->idev,EV_KEY ,KEY_LEFT ); +input_set_capability (data->idev,EV_KEY ,KEY_RIGHT ); +input_set_capability (data->idev,EV_KEY ,KEY_ENTER ); +input_set_capability (data->idev,EV_KEY ,KEY_BACK ); +input_set_capability (data->idev,EV_KEY ,KEY_NEXT ); +input_set_capability (data->idev,EV_KEY ,KEY_PREVIOUS ); +input_set_capability (data->idev,EV_KEY ,KEY_MENU ); + + ret =input_register_device (data->idev); +if (ret) + goto err_reg; + +pm_runtime_set_active (&client->dev); +pm_runtime_enable (&client->dev);
drivers/input/misc/paj7620.c line 299
Quoted 10 lines
drivers/input/misc/paj7620.c new file +10
-0+pm_runtime_set_autosuspend_delay (&client->dev,2000 ); +pm_runtime_use_autosuspend (&client->dev); + + ret =devm_request_threaded_irq (&client->dev, client->irq,NULL , + paj7620_irq_thread,IRQF_ONESHOT , +"paj7620" , data); +if (ret) + goto err_reg; + +dev_info (&client->dev,"Gesture Sensor Initialized\n" );
Pointless message, drop. Driver should be silent on success.
drivers/input/misc/paj7620.c line 303
Quoted 4 lines
drivers/input/misc/paj7620.c new file +4
-0+return 0 ; + +err_reg: +dev_err_probe (&client->dev, ret,"%s: failed with error %d\n" , __func__, ret);
No, move it to individual errors, but only where applicable. For example devm_request_threaded_irq() must not have it.
Neither devm_input_allocate_device.
Quoted 50 lines
drivers/input/misc/paj7620.c new file +47
-0+if (pm_runtime_enabled (&client->dev)) { +pm_runtime_disable (&client->dev); +pm_runtime_dont_use_autosuspend (&client->dev); + } +regulator_bulk_disable (ARRAY_SIZE (data->supplies), data->supplies); +return ret; +} + +static void paj7620_remove (struct i2c_client *client) +{ +int ret; +struct paj7620_data *data =i2c_get_clientdata (client); + +pm_runtime_get_sync (&client->dev); +pm_runtime_disable (&client->dev); +pm_runtime_dont_use_autosuspend (&client->dev); +pm_runtime_put_noidle (&client->dev); + + ret =paj7620_power_down (data); +if (ret) +dev_err (&data->client->dev,"Sensor power down failed\n" ); + + ret =regulator_bulk_disable (ARRAY_SIZE (data->supplies), data->supplies); +if (ret) +dev_err (&data->client->dev,"Sensor regulator disable failed\n" ); +} + +static const struct of_device_id paj7620_of_match[] = { + { .compatible ="pixart,paj7620" }, + { } +}; +MODULE_DEVICE_TABLE (of, paj7620_of_match); + +static struct i2c_driver paj7620_driver = { + .driver = { + .name ="paj7620" , + .of_match_table = paj7620_of_match, + .pm = &paj7620_pm_ops, + }, + .probe = paj7620_probe, + .remove = paj7620_remove, +}; +module_i2c_driver (paj7620_driver); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Harpreet Saini" ); +MODULE_DESCRIPTION ("PAJ7620 Gesture Input Driver" );Signature · 1 line
2.43.0
Dmitry Torokhov
maintainerRe: [PATCH v2 2/2] input: misc: Add PixArt PAJ7620 gesture sensor driver
In reply to Harpreet SainiHi Harpreet,
Quoted 4 lines · Harpreet Saini
This driver adds support for the PixArt PAJ7620 gesture sensor. It implements hand gesture recognition (up, down, left, right, etc.) and reports them as standard input key events. The driver includes power management support via Runtime PM.
Sashiko has identified a number of valid concerns, please address them.
Also consider:
- moving powering up and down the chip into open()/close() for input device
- getting keymap from device properties and allowing adjusting it from userspace vi EVIOCSKEYCODE
- no capitals in type names
- use 'error' instead of 'ret' for variables holding only error code or 0.
Thanks.
Signature · 1 line
Dmitry