Linux Input/HID development
 help / color / mirror / Atom feed
* Re: [PATCH 1/2] doc: dt/bindings: input: introduce TI DRV2667 haptic driver description
From: Murphy, Dan @ 2014-08-21 19:14 UTC (permalink / raw)
  To: Sergei Shtylyov, linux-input@vger.kernel.org,
	dmitry.torokhov@gmail.com
  Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
In-Reply-To: <53F642AF.3070200@cogentembedded.com>

Sergei
Thanks for the additional comments

On 08/21/2014 02:04 PM, Sergei Shtylyov wrote:
> Hello.
> 
> On 08/21/2014 10:19 PM, Dan Murphy wrote:
> 
>> DRV2667 is a haptic/vibrator driver for Linear Resonant Actuators.
>> Adding dt binding for this part
> 
>> Signed-off-by: Dan Murphy <dmurphy@ti.com>
>> ---
>>   .../devicetree/bindings/input/ti,drv2667.txt       |   18 ++++++++++++++++++
>>   1 file changed, 18 insertions(+)
>>   create mode 100644 Documentation/devicetree/bindings/input/ti,drv2667.txt
> 
>> diff --git a/Documentation/devicetree/bindings/input/ti,drv2667.txt b/Documentation/devicetree/bindings/input/ti,drv2667.txt
>> new file mode 100644
>> index 0000000..525216d
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/input/ti,drv2667.txt
>> @@ -0,0 +1,18 @@
>> +Texas Instruments - drv2667 Haptics driver
>> +
>> +The drv2667 uses serial control bus communicates through I2C protocols
>> +
>> +Required properties:
>> +	- compatible - "ti,drv2667" - DRV2667
>> +	- reg -  I2C slave address
>> +	- vbat-supply - Required supply regulator
>> +
>> +Example:
>> +
>> +drv2667: drv2667@59 {
> 
>     The ePAPR standard [1] has something to say on this matter:

What is this reference?  Did not know this existed so wanted to read up on it.

I can change it to haptics or vibrator

> 
> "The name of a node should be somewhat generic, reflecting the function of the 
> device and not its precise programming model."
> 
>> +		compatible = "ti,drv2667";
> 
>     Indented too much to the right.

One tab to many.  Got it

> 
>> +		reg = <0x59>;
> 
>     Still no "vbat-supply"... :-/
> 

Still have not sent in v2 of the patch yet.  Waiting on other comments.

>> +};
> [...]
> 
> WBR, Sergei
> 
> 


-- 
------------------
Dan Murphy

^ permalink raw reply

* Re: [PATCH 1/2] doc: dt/bindings: input: introduce TI DRV2667 haptic driver description
From: Sergei Shtylyov @ 2014-08-21 19:04 UTC (permalink / raw)
  To: Dan Murphy, linux-input, dmitry.torokhov
  Cc: devicetree, linux-kernel, linux-arm-kernel
In-Reply-To: <1408645143-25690-2-git-send-email-dmurphy@ti.com>

Hello.

On 08/21/2014 10:19 PM, Dan Murphy wrote:

> DRV2667 is a haptic/vibrator driver for Linear Resonant Actuators.
> Adding dt binding for this part

> Signed-off-by: Dan Murphy <dmurphy@ti.com>
> ---
>   .../devicetree/bindings/input/ti,drv2667.txt       |   18 ++++++++++++++++++
>   1 file changed, 18 insertions(+)
>   create mode 100644 Documentation/devicetree/bindings/input/ti,drv2667.txt

> diff --git a/Documentation/devicetree/bindings/input/ti,drv2667.txt b/Documentation/devicetree/bindings/input/ti,drv2667.txt
> new file mode 100644
> index 0000000..525216d
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/input/ti,drv2667.txt
> @@ -0,0 +1,18 @@
> +Texas Instruments - drv2667 Haptics driver
> +
> +The drv2667 uses serial control bus communicates through I2C protocols
> +
> +Required properties:
> +	- compatible - "ti,drv2667" - DRV2667
> +	- reg -  I2C slave address
> +	- vbat-supply - Required supply regulator
> +
> +Example:
> +
> +drv2667: drv2667@59 {

    The ePAPR standard [1] has something to say on this matter:

"The name of a node should be somewhat generic, reflecting the function of the 
device and not its precise programming model."

> +		compatible = "ti,drv2667";

    Indented too much to the right.

> +		reg = <0x59>;

    Still no "vbat-supply"... :-/

> +};
[...]

WBR, Sergei

^ permalink raw reply

* Re: [PATCH V2 2/2] Input: misc: introduce palmas-pwrbutton
From: Nishanth Menon @ 2014-08-21 19:01 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Murphy, Dan, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
	linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org
In-Reply-To: <20140821180300.GA5854@core.coreip.homeip.net>

On 08/21/2014 01:03 PM, Dmitry Torokhov wrote:

I believe I have taken care of other concerns on v2, but..Arrgh.. I
did not reply to this comment..
> BTW, I do not think you need to use of_node_get/put here, it's not going anywhere.
It has been mentioned as a good practice to ensure we use get_put in
to ensure reference count is appropriately maintained. So, I have'nt
changed that in v3.

-- 
Regards,
Nishanth Menon

^ permalink raw reply

* [PATCH V3 2/2] Input: misc: introduce palmas-pwrbutton
From: Nishanth Menon @ 2014-08-21 18:52 UTC (permalink / raw)
  To: Dmitry Torokhov, Dmitry Torokhov
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-input-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Dan Murphy,
	Nishanth Menon
In-Reply-To: <1408392810-16011-1-git-send-email-nm-l0cyMroinI0@public.gmane.org>

Many palmas family of PMICs have support for interrupt based power
button. This allows the device to notify the processor of external
push button events over the shared palmas interrupt. However, this
event is generated only during a "press" operation. Software is
supposed to poll(sigh!) for detecting a release event.

The PMIC also supports ability to power off independent of the
software decisions when the button is pressed for a long duration if
the PMIC is appropriately configured on the platform.

Even though the function is similar to twl4030_pwrbutton, it is
substantially different in operation to belong to a new driver of it's
own.

Based on original work done by Girish S Ghongdemath <girishsg-l0cyMroinI0@public.gmane.org>

Signed-off-by: Nishanth Menon <nm-l0cyMroinI0@public.gmane.org>
---

I am not re-posting patch #1/2 as it is already available in
https://patchwork.kernel.org/patch/4758681/ without any comments. Do
let me know if we want it reposted.

Changes since V2:
 - Integrated review comments of v2 (improvement in dt parse, header
   cleanups, no more managed resource usage)

V2: https://patchwork.kernel.org/patch/4758711/
V1: https://patchwork.kernel.org/patch/4739041/

 drivers/input/misc/Kconfig            |   10 +
 drivers/input/misc/Makefile           |    1 +
 drivers/input/misc/palmas-pwrbutton.c |  368 +++++++++++++++++++++++++++++++++
 3 files changed, 379 insertions(+)
 create mode 100644 drivers/input/misc/palmas-pwrbutton.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 2ff4425..0224dcf 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -451,6 +451,16 @@ config HP_SDC_RTC
 	  Say Y here if you want to support the built-in real time clock
 	  of the HP SDC controller.
 
+config INPUT_PALMAS_PWRBUTTON
+	tristate "Palmas Power button Driver"
+	depends on MFD_PALMAS
+	help
+	  Say Y here if you want to enable power key reporting via the
+	  Palmas family of PMICs.
+
+	  To compile this driver as a module, choose M here. The module will
+	  be called palmas_pwrbutton.
+
 config INPUT_PCF50633_PMU
 	tristate "PCF50633 PMU events"
 	depends on MFD_PCF50633
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 4955ad3..e3d5efb 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_INPUT_MAX8997_HAPTIC)	+= max8997_haptic.o
 obj-$(CONFIG_INPUT_MC13783_PWRBUTTON)	+= mc13783-pwrbutton.o
 obj-$(CONFIG_INPUT_MMA8450)		+= mma8450.o
 obj-$(CONFIG_INPUT_MPU3050)		+= mpu3050.o
+obj-$(CONFIG_INPUT_PALMAS_PWRBUTTON)	+= palmas-pwrbutton.o
 obj-$(CONFIG_INPUT_PCAP)		+= pcap_keys.o
 obj-$(CONFIG_INPUT_PCF50633_PMU)	+= pcf50633-input.o
 obj-$(CONFIG_INPUT_PCF8574)		+= pcf8574_keypad.o
diff --git a/drivers/input/misc/palmas-pwrbutton.c b/drivers/input/misc/palmas-pwrbutton.c
new file mode 100644
index 0000000..4d48108
--- /dev/null
+++ b/drivers/input/misc/palmas-pwrbutton.c
@@ -0,0 +1,368 @@
+/*
+ * Texas Instruments' Palmas Power Button Input Driver
+ *
+ * Copyright (C) 2012-2014 Texas Instruments Incorporated - http://www.ti.com/
+ *	Girish S Ghongdemath
+ *	Nishanth Menon
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/mfd/palmas.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#define PALMAS_LPK_TIME_MASK		0x0c
+#define PALMAS_PWRON_DEBOUNCE_MASK	0x03
+#define PALMAS_PWR_KEY_PRESS		0x01
+#define PALMAS_PWR_KEY_Q_TIME_MS	20
+
+/**
+ * struct palmas_pwron - Palmas power on data
+ * @palmas:		pointer to palmas device
+ * @input_dev:		pointer to input device
+ * @irq:		irq that we are hooked on to
+ * @input_work:		work for detecting release of key
+ * @current_state:	key current state
+ * @key_recheck_ms:	duration for recheck of key (in milli-seconds)
+ */
+struct palmas_pwron {
+	struct palmas *palmas;
+	struct input_dev *input_dev;
+	int irq;
+	struct delayed_work input_work;
+	int current_state;
+	u32 key_recheck_ms;
+};
+
+/**
+ * struct palmas_pwron_config - configuration of palmas power on
+ * @long_press_time_val:	value for long press h/w shutdown event
+ * @pwron_debounce_val:		value for debounce of power button
+ */
+struct palmas_pwron_config {
+	u8 long_press_time_val;
+	u8 pwron_debounce_val;
+};
+
+/**
+ * palmas_get_pwr_state() - read button state
+ * @pwron: pointer to pwron struct
+ *
+ * Return: 0 for no press, PALMAS_PWR_KEY_PRESS for keypress
+ * and on error, appropriate error value.
+ */
+static int palmas_get_pwr_state(struct palmas_pwron *pwron)
+{
+	struct input_dev *input_dev = pwron->input_dev;
+	struct device *dev = input_dev->dev.parent;
+	unsigned int reg = 0;
+	int ret;
+
+	ret = palmas_read(pwron->palmas, PALMAS_INTERRUPT_BASE,
+			  PALMAS_INT1_LINE_STATE, &reg);
+	if (ret) {
+		dev_err(dev, "%s:Cannot read palmas PWRON status(%d)\n",
+			__func__, ret);
+		return ret;
+	}
+
+	/* PWRON line state is BIT(1) of the register */
+	return reg & BIT(1) ? 0 : PALMAS_PWR_KEY_PRESS;
+}
+
+/**
+ * palmas_power_button_work() - Detects the button release event
+ * @work:	work item to detect button release
+ */
+static void palmas_power_button_work(struct work_struct *work)
+{
+	struct palmas_pwron *pwron = container_of((struct delayed_work *)work,
+						  struct palmas_pwron,
+						  input_work);
+	struct input_dev *input_dev = pwron->input_dev;
+	int next_state;
+
+	next_state = palmas_get_pwr_state(pwron);
+	if (next_state < 0)
+		return;
+
+	/*
+	 * If the state did not change then schedule a work item to check the
+	 * status of the power button line
+	 */
+	if (next_state == pwron->current_state) {
+		schedule_delayed_work(&pwron->input_work,
+				      msecs_to_jiffies(pwron->key_recheck_ms));
+		return;
+	}
+
+	pwron->current_state = next_state;
+	input_report_key(input_dev, KEY_POWER, pwron->current_state);
+	input_sync(input_dev);
+}
+
+/**
+ * pwron_irq() - button press isr
+ * @irq:		irq
+ * @palmas_pwron:	pwron struct
+ *
+ * Return: IRQ_HANDLED
+ */
+static irqreturn_t pwron_irq(int irq, void *palmas_pwron)
+{
+	struct palmas_pwron *pwron = palmas_pwron;
+	struct input_dev *input_dev = pwron->input_dev;
+
+	pwron->current_state = PALMAS_PWR_KEY_PRESS;
+
+	input_report_key(input_dev, KEY_POWER, pwron->current_state);
+	pm_wakeup_event(input_dev->dev.parent, 0);
+	input_sync(input_dev);
+
+	mod_delayed_work(system_wq, &pwron->input_work,
+			 msecs_to_jiffies(pwron->key_recheck_ms));
+
+	return IRQ_HANDLED;
+}
+
+/**
+ * palmas_pwron_params_ofinit() - device tree parameter parser
+ * @dev:	palmas button device
+ * @config:	configuration params that this fills up
+ */
+static void palmas_pwron_params_ofinit(struct device *dev,
+				       struct palmas_pwron_config *config)
+{
+	struct device_node *np;
+	u32 val;
+	int i, ret;
+	u8 lpk_times[] = { 6, 8, 10, 12 };
+	int pwr_on_deb_ms[] = { 15, 100, 500, 1000 };
+
+	/* Default config parameters */
+	config->long_press_time_val = ARRAY_SIZE(lpk_times) - 1;
+
+	/* Handle cases where device node based configuration is not present */
+	if (!of_have_populated_dt())
+		return;
+	np = of_node_get(dev->of_node);
+	if (!np)
+		return;
+
+	ret = of_property_read_u32(np, "ti,palmas-long-press-seconds", &val);
+	if (!ret) {
+		for (i = 0; i < ARRAY_SIZE(lpk_times); i++) {
+			if (val <= lpk_times[i]) {
+				config->long_press_time_val = i;
+				break;
+			}
+		}
+	}
+
+	ret = of_property_read_u32(np, "ti,palmas-pwron-debounce-milli-seconds",
+				   &val);
+	if (!ret) {
+		for (i = 0; i < ARRAY_SIZE(pwr_on_deb_ms); i++) {
+			if (val <= pwr_on_deb_ms[i]) {
+				config->pwron_debounce_val = i;
+				break;
+			}
+		}
+	}
+
+	dev_info(dev, "h/w controlled shutdown duration=%d seconds\n",
+		 lpk_times[config->long_press_time_val]);
+
+	of_node_put(np);
+}
+
+/**
+ * palmas_pwron_probe() - probe
+ * @pdev:	platform device for the button
+ *
+ * Return: 0 for successful probe else appropriate error
+ */
+static int palmas_pwron_probe(struct platform_device *pdev)
+{
+	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
+	struct device *dev = &pdev->dev;
+	struct input_dev *input_dev;
+	struct palmas_pwron *pwron;
+	int irq, ret, val;
+	struct palmas_pwron_config config = { 0 };
+
+	palmas_pwron_params_ofinit(dev, &config);
+
+	pwron = kzalloc(sizeof(*pwron), GFP_KERNEL);
+	if (!pwron)
+		return -ENOMEM;
+
+	input_dev = input_allocate_device();
+	if (!input_dev) {
+		dev_err(dev, "Can't allocate power button\n");
+		ret = -ENOMEM;
+		goto exit_pwron;
+	}
+
+	/*
+	 * Setup default hardware shutdown option (long key press)
+	 * and debounce.
+	 */
+	val = config.long_press_time_val << __ffs(PALMAS_LPK_TIME_MASK);
+	val |= config.pwron_debounce_val << __ffs(PALMAS_PWRON_DEBOUNCE_MASK);
+	ret = palmas_update_bits(palmas, PALMAS_PMU_CONTROL_BASE,
+				 PALMAS_LONG_PRESS_KEY,
+				 PALMAS_LPK_TIME_MASK |
+				 PALMAS_PWRON_DEBOUNCE_MASK, val);
+	if (ret < 0) {
+		dev_err(dev, "LONG_PRESS_KEY_UPDATE failed!\n");
+		goto exit_input_dev;
+	}
+
+	input_dev->evbit[0] = BIT_MASK(EV_KEY);
+	input_dev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
+	input_dev->name = "palmas_pwron";
+	input_dev->phys = "palmas_pwron/input0";
+	input_dev->dev.parent = dev;
+
+	pwron->palmas = palmas;
+	pwron->input_dev = input_dev;
+
+	INIT_DELAYED_WORK(&pwron->input_work, palmas_power_button_work);
+
+	irq = platform_get_irq(pdev, 0);
+	ret = request_threaded_irq(irq, NULL, pwron_irq,
+				   IRQF_TRIGGER_HIGH |
+				   IRQF_TRIGGER_LOW, dev_name(dev), pwron);
+	if (ret < 0) {
+		dev_err(dev, "Can't get IRQ for pwron: %d\n", ret);
+		goto exit_input_dev;
+	}
+
+	device_init_wakeup(dev, true);
+
+	ret = input_register_device(input_dev);
+	if (ret) {
+		free_irq(irq, pwron);
+		cancel_delayed_work_sync(&pwron->input_work);
+		dev_dbg(dev, "Can't register power button: %d\n", ret);
+		goto exit_free_irq;
+	}
+	pwron->irq = irq;
+
+	pwron->key_recheck_ms = PALMAS_PWR_KEY_Q_TIME_MS;
+
+	platform_set_drvdata(pdev, pwron);
+
+	return 0;
+
+exit_free_irq:
+	free_irq(irq, pwron);
+exit_input_dev:
+	input_free_device(input_dev);
+exit_pwron:
+	kfree(pwron);
+
+	return ret;
+}
+
+/**
+ * palmas_pwron_remove() - Cleanup on removal
+ * @pdev:	platform device for the button
+ *
+ * Return: 0
+ */
+static int palmas_pwron_remove(struct platform_device *pdev)
+{
+	struct palmas_pwron *pwron = platform_get_drvdata(pdev);
+
+	free_irq(pwron->irq, pwron);
+	cancel_delayed_work_sync(&pwron->input_work);
+	input_unregister_device(pwron->input_dev);
+	input_free_device(pwron->input_dev);
+	kfree(pwron);
+
+	return 0;
+}
+
+/**
+ * palmas_pwron_suspend() - suspend handler
+ * @dev:	power button device
+ *
+ * Cancel all pending work items for the power button, setup irq for wakeup
+ *
+ * Return: 0
+ */
+static int palmas_pwron_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct palmas_pwron *pwron = platform_get_drvdata(pdev);
+
+	cancel_delayed_work_sync(&pwron->input_work);
+
+	if (device_may_wakeup(dev))
+		enable_irq_wake(pwron->irq);
+
+	return 0;
+}
+
+/**
+ * palmas_pwron_resume() - resume handler
+ * @dev:	power button device
+ *
+ * Just disable the wakeup capability of irq here.
+ *
+ * Return: 0
+ */
+static int palmas_pwron_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct palmas_pwron *pwron = platform_get_drvdata(pdev);
+
+	if (device_may_wakeup(dev))
+		disable_irq_wake(pwron->irq);
+
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(palmas_pwron_pm,
+			 palmas_pwron_suspend, palmas_pwron_resume);
+
+#ifdef CONFIG_OF
+static struct of_device_id of_palmas_pwr_match[] = {
+	{.compatible = "ti,palmas-pwrbutton"},
+	{},
+};
+
+MODULE_DEVICE_TABLE(of, of_palmas_pwr_match);
+#endif
+
+static struct platform_driver palmas_pwron_driver = {
+	.probe = palmas_pwron_probe,
+	.remove = palmas_pwron_remove,
+	.driver = {
+		   .name = "palmas_pwrbutton",
+		   .owner = THIS_MODULE,
+		   .of_match_table = of_match_ptr(of_palmas_pwr_match),
+		   .pm = &palmas_pwron_pm,
+	},
+};
+module_platform_driver(palmas_pwron_driver);
+
+MODULE_ALIAS("platform:palmas-pwrbutton");
+MODULE_DESCRIPTION("Palmas Power Button");
+MODULE_LICENSE("GPL V2");
+MODULE_AUTHOR("Texas Instruments Inc.");
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related

* Re: USB reset xhci_hcd for ELAN touchscreen
From: Jiri Kosina @ 2014-08-21 18:38 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Greg KH, Alan Stern, Bjørn Mork, Sarah Sharp,
	Drew Von Spreecken, linux-usb, Mathias Nyman, linux-input
In-Reply-To: <20140821105407.GF24090@localhost>

On Thu, 21 Aug 2014, Johan Hovold wrote:

> > It's not really super-nice, but if no other way around it has been found 
> > to be possible in USB core, I am willing to take this.
> 
> Agreed, it's not that nice, but I'm not aware of any other way to
> prevent the device firmware from disconnecting.
> 
> Autosuspend still seems to work, so it would not cause much overhead
> for people not actually using the touchscreen (as long as autosuspend
> is enabled) either.

Okay, good. Will be waiting for your polished patch for this.

[ ... snip ... ]
> > > diff --git a/include/linux/hid.h b/include/linux/hid.h
> > > index 77632cf..13f81ae 100644
> > > --- a/include/linux/hid.h
> > > +++ b/include/linux/hid.h
> > > @@ -286,6 +286,7 @@ struct hid_item {
> > >  #define HID_QUIRK_HIDINPUT_FORCE		0x00000080
> > >  #define HID_QUIRK_NO_EMPTY_INPUT		0x00000100
> > >  #define HID_QUIRK_NO_INIT_INPUT_REPORTS		0x00000200
> > > +#define HID_QUIRK_IN				0x00000400
> > 
> > 0x00000400 has been removed before dynamic quirks started to be possible, 
> > so there is no potential clash, that's fine.
> > 
> > I'd just propose some more descriptive name for the quirk ... how about 
> > something like HID_QUIRK_EARLY_INTERRUPT?
> 
> Yeah, IN was just a working name. How about HID_QUIRK_ALWAYS_POLL or
> similar as it is not just about disconnect before the device is opened,
> but also if there's an event after the device has been closed (e.g.
> stopping X)?

HID_QUIRK_ALWAYS_POLL sounds good.

Thanks,

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply

* Re: [PATCH 1/2] doc: dt/bindings: input: introduce TI DRV2667 haptic driver description
From: Murphy, Dan @ 2014-08-21 18:30 UTC (permalink / raw)
  To: Sergei Shtylyov, linux-input@vger.kernel.org,
	dmitry.torokhov@gmail.com
  Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
In-Reply-To: <53F63A68.1080002@cogentembedded.com>

Sergei

On 08/21/2014 01:29 PM, Sergei Shtylyov wrote:
> Hello.
> 
> On 08/21/2014 10:19 PM, Dan Murphy wrote:
> 
>> DRV2667 is a haptic/vibrator driver for Linear Resonant Actuators.
>> Adding dt binding for this part
> 
>> Signed-off-by: Dan Murphy <dmurphy@ti.com>
>> ---
>>   .../devicetree/bindings/input/ti,drv2667.txt       |   18 ++++++++++++++++++
>>   1 file changed, 18 insertions(+)
>>   create mode 100644 Documentation/devicetree/bindings/input/ti,drv2667.txt
> 
>> diff --git a/Documentation/devicetree/bindings/input/ti,drv2667.txt b/Documentation/devicetree/bindings/input/ti,drv2667.txt
>> new file mode 100644
>> index 0000000..525216d
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/input/ti,drv2667.txt
>> @@ -0,0 +1,18 @@
>> +Texas Instruments - drv2667 Haptics driver
>> +
>> +The drv2667 uses serial control bus communicates through I2C protocols
> 
>     I can't parse that.
> 

Hmmm.. It made sense when I typed it.  Will fix

>> +
>> +Required properties:
>> +	- compatible - "ti,drv2667" - DRV2667
>> +	- reg -  I2C slave address
>> +	- vbat-supply - Required supply regulator
>> +
>> +Example:
>> +
>> +drv2667: drv2667@59 {
>> +		compatible = "ti,drv2667";
>> +		reg = <0x59>;
> 
>     You say "vbat-supply" is mandatory, yet you don't have it in your example?

I will add this as well.

> 
> WBR, Sergei
> 
> 


-- 
------------------
Dan Murphy

^ permalink raw reply

* Re: [PATCH 1/2] doc: dt/bindings: input: introduce TI DRV2667 haptic driver description
From: Sergei Shtylyov @ 2014-08-21 18:28 UTC (permalink / raw)
  To: Dan Murphy, linux-input, dmitry.torokhov
  Cc: devicetree, linux-kernel, linux-arm-kernel
In-Reply-To: <1408645143-25690-2-git-send-email-dmurphy@ti.com>

Hello.

On 08/21/2014 10:19 PM, Dan Murphy wrote:

> DRV2667 is a haptic/vibrator driver for Linear Resonant Actuators.
> Adding dt binding for this part

> Signed-off-by: Dan Murphy <dmurphy@ti.com>
> ---
>   .../devicetree/bindings/input/ti,drv2667.txt       |   18 ++++++++++++++++++
>   1 file changed, 18 insertions(+)
>   create mode 100644 Documentation/devicetree/bindings/input/ti,drv2667.txt

> diff --git a/Documentation/devicetree/bindings/input/ti,drv2667.txt b/Documentation/devicetree/bindings/input/ti,drv2667.txt
> new file mode 100644
> index 0000000..525216d
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/input/ti,drv2667.txt
> @@ -0,0 +1,18 @@
> +Texas Instruments - drv2667 Haptics driver
> +
> +The drv2667 uses serial control bus communicates through I2C protocols

    I can't parse that.

> +
> +Required properties:
> +	- compatible - "ti,drv2667" - DRV2667
> +	- reg -  I2C slave address
> +	- vbat-supply - Required supply regulator
> +
> +Example:
> +
> +drv2667: drv2667@59 {
> +		compatible = "ti,drv2667";
> +		reg = <0x59>;

    You say "vbat-supply" is mandatory, yet you don't have it in your example?

WBR, Sergei

^ permalink raw reply

* Re: [PATCH v4 4/14] input: cyapa: add cyapa key function interfaces in sysfs system
From: Dmitry Torokhov @ 2014-08-21 18:28 UTC (permalink / raw)
  To: Dudley Du
  Cc: Rafael J. Wysocki, Benson Leung, Patrik Fimml, linux-input,
	linux-kernel, Dudley Du
In-Reply-To: <53c77269.a7c8440a.7a5b.4c20@mx.google.com>

On Thu, Jul 17, 2014 at 02:51:04PM +0800, Dudley Du wrote:
> Add key basic function interfaces in cyapa driver in sysfs system,
> these interfaces are commonly used in pre- and after production, and
> for trackpad device state checking, manage and firmware image updating.
> These interfaces including firmware_version and product_id interfaces
> for reading firmware version and trackpad device product id values,
> and including update_fw interface to command firmware image update
> process. Also including baseline and calibrate interfaces, so can
> read and check the trackpad device states. If the baseline values are
> invalid, then can use calibrate interface to recover it.
> TEST=test on Chromebooks.
> 
> Signed-off-by: Dudley Du <dudl@cypress.com>
> ---
>  drivers/input/mouse/cyapa.c |  190 +++++++++++++++++++++++++++++++++++++++++++
>  drivers/input/mouse/cyapa.h |   27 ++++++
>  2 files changed, 217 insertions(+)
> 
> diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
> index 6a2783b..53c9d59 100644
> --- a/drivers/input/mouse/cyapa.c
> +++ b/drivers/input/mouse/cyapa.c
> @@ -388,6 +388,78 @@ static void cyapa_detect(struct cyapa *cyapa)
>  	}
>  }
>  
> +static int cyapa_firmware(struct cyapa *cyapa, const char *fw_name)
> +{
> +	struct device *dev = &cyapa->client->dev;
> +	int ret;
> +	const struct firmware *fw;
> +
> +	ret = request_firmware(&fw, fw_name, dev);
> +	if (ret) {
> +		dev_err(dev, "Could not load firmware from %s, %d\n",
> +			fw_name, ret);
> +		return ret;
> +	}
> +
> +	if (cyapa->ops->check_fw) {
> +		ret = cyapa->ops->check_fw(cyapa, fw);
> +		if (ret) {
> +			dev_err(dev, "Invalid CYAPA firmware image: %s\n",
> +					fw_name);
> +			goto done;
> +		}
> +	} else {
> +		dev_err(dev, "Unknown status, operation forbidden, gen=%d\n",
> +			cyapa->gen);
> +		ret = -ENOTSUPP;

I'd say EIO or EINVAL.

> +		goto done;
> +	}
> +
> +	/*
> +	 * Resume the potentially suspended device because doing FW
> +	 * update on a device not in the FULL mode has a chance to
> +	 * fail.
> +	 */
> +	pm_runtime_get_sync(dev);
> +
> +	if (cyapa->ops->bl_enter) {
> +		ret = cyapa->ops->bl_enter(cyapa);
> +		if (ret)
> +			goto err_detect;
> +	}
> +
> +	if (cyapa->ops->bl_activate) {
> +		ret = cyapa->ops->bl_activate(cyapa);
> +		if (ret)
> +			goto err_detect;
> +	}
> +
> +	if (cyapa->ops->bl_initiate) {
> +		ret = cyapa->ops->bl_initiate(cyapa, fw);
> +		if (ret)
> +			goto err_detect;
> +	}
> +
> +	if (cyapa->ops->update_fw) {
> +		ret = cyapa->ops->update_fw(cyapa, fw);
> +		if (ret)
> +			goto err_detect;
> +	}
> +
> +	if (cyapa->ops->bl_verify_app_integrity) {
> +		ret = cyapa->ops->bl_verify_app_integrity(cyapa);
> +		if (ret)
> +			goto err_detect;
> +	}
> +
> +err_detect:
> +	pm_runtime_put_noidle(dev);
> +
> +done:
> +	release_firmware(fw);
> +	return ret;
> +}
> +
>  /*
>   * Sysfs Interface.
>   */
> @@ -584,6 +656,120 @@ static void cyapa_start_runtime(struct cyapa *cyapa)
>  static void cyapa_start_runtime(struct cyapa *cyapa) {}
>  #endif /* CONFIG_PM_RUNTIME */
>  
> +static ssize_t cyapa_show_fm_ver(struct device *dev,
> +				 struct device_attribute *attr, char *buf)
> +{
> +	int ret;
> +	struct cyapa *cyapa = dev_get_drvdata(dev);
> +
> +	mutex_lock(&cyapa->state_sync_lock);
> +	ret = scnprintf(buf, PAGE_SIZE, "%d.%d\n", cyapa->fw_maj_ver,
> +			 cyapa->fw_min_ver);
> +	mutex_unlock(&cyapa->state_sync_lock);
> +	return ret;
> +}
> +
> +static ssize_t cyapa_show_product_id(struct device *dev,
> +				     struct device_attribute *attr, char *buf)
> +{
> +	int ret;
> +	struct cyapa *cyapa = dev_get_drvdata(dev);
> +
> +	mutex_lock(&cyapa->state_sync_lock);
> +	ret = scnprintf(buf, PAGE_SIZE, "%s\n", cyapa->product_id);
> +	mutex_unlock(&cyapa->state_sync_lock);
> +	return ret;
> +}
> +
> +static ssize_t cyapa_update_fw_store(struct device *dev,
> +				     struct device_attribute *attr,
> +				     const char *buf, size_t count)
> +{
> +	struct cyapa *cyapa = dev_get_drvdata(dev);
> +	const char *fw_name;
> +	int ret;
> +
> +	/* Do not allow paths that step out of /lib/firmware  */
> +	if (strstr(buf, "../") != NULL)
> +		return -EINVAL;

This should go away, it does not help anything.

> +
> +	if (!strncmp(buf, "1", count) || !strncmp(buf, "1\n", count))
> +		fw_name = CYAPA_FW_NAME;
> +	else
> +		fw_name = buf;

I'd rather you either required firmware name to be passed always or settle on
given name. Otherwise why can't I call my firmware file '1'?

> +
> +	mutex_lock(&cyapa->state_sync_lock);
> +
> +	ret = cyapa_firmware(cyapa, fw_name);
> +	if (ret)
> +		dev_err(dev, "firmware update failed, %d\n", ret);
> +	else
> +		dev_dbg(dev, "firmware update succeeded\n");
> +
> +	mutex_unlock(&cyapa->state_sync_lock);
> +
> +	/* Redetect trackpad device states. */
> +	cyapa_detect_async(cyapa, 0);
> +
> +	return ret ? ret : count;
> +}
> +
> +static ssize_t cyapa_calibrate_store(struct device *dev,
> +				     struct device_attribute *attr,
> +				     const char *buf, size_t count)
> +{
> +	struct cyapa *cyapa = dev_get_drvdata(dev);
> +	int ret;
> +
> +	mutex_lock(&cyapa->state_sync_lock);
> +
> +	if (!cyapa->ops->calibrate_store) {
> +		dev_err(dev, "Calibrate operation not permitted.\n");
> +		ret = -ENOTSUPP;

Permitted as in supported or forbidden?

> +	} else
> +		ret = cyapa->ops->calibrate_store(dev, attr, buf, count);
> +
> +	mutex_unlock(&cyapa->state_sync_lock);
> +	return ret < 0 ? ret : count;
> +}
> +
> +static ssize_t cyapa_show_baseline(struct device *dev,
> +				   struct device_attribute *attr, char *buf)
> +{
> +	struct cyapa *cyapa = dev_get_drvdata(dev);
> +	ssize_t ret;
> +
> +	mutex_lock(&cyapa->state_sync_lock);
> +
> +	if (!cyapa->ops->show_baseline) {
> +		dev_err(dev, "Calibrate operation not permitted.\n");
> +		ret = -ENOTSUPP;
> +	} else
> +		ret = cyapa->ops->show_baseline(dev, attr, buf);
> +
> +	mutex_unlock(&cyapa->state_sync_lock);
> +	return ret;
> +}
> +
> +static DEVICE_ATTR(firmware_version, S_IRUGO, cyapa_show_fm_ver, NULL);
> +static DEVICE_ATTR(product_id, S_IRUGO, cyapa_show_product_id, NULL);
> +static DEVICE_ATTR(update_fw, S_IWUSR, NULL, cyapa_update_fw_store);
> +static DEVICE_ATTR(baseline, S_IRUGO, cyapa_show_baseline, NULL);
> +static DEVICE_ATTR(calibrate, S_IWUSR, NULL, cyapa_calibrate_store);
> +
> +static struct attribute *cyapa_sysfs_entries[] = {
> +	&dev_attr_firmware_version.attr,
> +	&dev_attr_product_id.attr,
> +	&dev_attr_update_fw.attr,
> +	&dev_attr_baseline.attr,
> +	&dev_attr_calibrate.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group cyapa_sysfs_group = {
> +	.attrs = cyapa_sysfs_entries,
> +};
> +
>  void cyapa_detect_async(void *data, async_cookie_t cookie)
>  {
>  	struct cyapa *cyapa = (struct cyapa *)data;
> @@ -680,6 +866,9 @@ static int cyapa_probe(struct i2c_client *client,
>  		goto err_uninit_tp_modules;
>  	}
>  
> +	if (sysfs_create_group(&client->dev.kobj, &cyapa_sysfs_group))
> +		dev_warn(dev, "error creating sysfs entries.\n");
> +
>  #ifdef CONFIG_PM_SLEEP
>  	if (device_can_wakeup(dev) &&
>  	    sysfs_merge_group(&client->dev.kobj, &cyapa_power_wakeup_group))
> @@ -704,6 +893,7 @@ static int cyapa_remove(struct i2c_client *client)
>  	struct cyapa *cyapa = i2c_get_clientdata(client);
>  
>  	pm_runtime_disable(&client->dev);
> +	sysfs_remove_group(&client->dev.kobj, &cyapa_sysfs_group);
>  
>  #ifdef CONFIG_PM_SLEEP
>  	sysfs_unmerge_group(&client->dev.kobj, &cyapa_power_wakeup_group);
> diff --git a/drivers/input/mouse/cyapa.h b/drivers/input/mouse/cyapa.h
> index 9c1f0b91..567ab08 100644
> --- a/drivers/input/mouse/cyapa.h
> +++ b/drivers/input/mouse/cyapa.h
> @@ -171,6 +171,22 @@ struct cyapa;
>  typedef bool (*cb_sort)(struct cyapa *, u8 *, int);
>  
>  struct cyapa_dev_ops {
> +	int (*check_fw)(struct cyapa *, const struct firmware *);
> +	int (*bl_enter)(struct cyapa *);
> +	int (*bl_activate)(struct cyapa *);
> +	int (*bl_initiate)(struct cyapa *, const struct firmware *);
> +	int (*update_fw)(struct cyapa *, const struct firmware *);
> +	int (*bl_verify_app_integrity)(struct cyapa *);
> +	int (*bl_deactivate)(struct cyapa *);
> +
> +	ssize_t (*show_baseline)(struct device *,
> +			struct device_attribute *, char *);
> +	ssize_t (*calibrate_store)(struct device *,
> +			struct device_attribute *, const char *, size_t);
> +
> +	int (*read_fw)(struct cyapa *);
> +	int (*read_raw_data)(struct cyapa *);
> +
>  	int (*initialize)(struct cyapa *cyapa);
>  	int (*uninitialize)(struct cyapa *cyapa);
>  
> @@ -243,6 +259,17 @@ struct cyapa {
>  	 */
>  	struct mutex state_sync_lock;
>  
> +	/* Per-instance debugfs root */
> +	struct dentry *dentry_dev;
> +
> +	/* Buffer to store firmware read using debugfs */
> +	struct mutex debugfs_mutex;
> +	u8 *fw_image;
> +	size_t fw_image_size;
> +	/* Buffer to store sensors' raw data */
> +	u8 *tp_raw_data;
> +	size_t tp_raw_data_size;
> +
>  	const struct cyapa_dev_ops *ops;
>  };
>  
> -- 
> 1.7.9.5
> 
> 

Thanks.

-- 
Dmitry

^ permalink raw reply

* Re: [PATCH v4 1/14] input: cyapa: re-architecture driver to support multi-trackpads in one driver
From: Dmitry Torokhov @ 2014-08-21 18:21 UTC (permalink / raw)
  To: Dudley Du
  Cc: Rafael J. Wysocki, Benson Leung, Patrik Fimml, linux-input,
	linux-kernel, Dudley Du
In-Reply-To: <53c7718c.ae67460a.0495.4979@mx.google.com>

On Thu, Jul 17, 2014 at 02:47:24PM +0800, Dudley Du wrote:
> In order to support two different communication protocol based trackpad
> device in one cyapa, the new cyapa driver is re-designed with
> one cyapa driver core and two devices' functions component.
> The cyapa driver core is contained in this patch, it supplies the basic
> function with input and kernel system and also defined the interfaces
> that the devices' functions component needs to apply and support.
> Also, in order to speed up the system boot time, the device states
> detecting and probing process is put into the async thread.
> TEST=test on Chromebooks.
> 
> Signed-off-by: Dudley Du <dudl@cypress.com>
> ---
>  drivers/input/mouse/Makefile |    4 +-
>  drivers/input/mouse/cyapa.c  | 1083 ++++++++++++++----------------------------
>  drivers/input/mouse/cyapa.h  |  275 +++++++++++
>  3 files changed, 646 insertions(+), 716 deletions(-)
>  create mode 100644 drivers/input/mouse/cyapa.h
> 
> diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
> index c25efdb..8608eb7 100644
> --- a/drivers/input/mouse/Makefile
> +++ b/drivers/input/mouse/Makefile
> @@ -8,7 +8,7 @@ obj-$(CONFIG_MOUSE_AMIGA)		+= amimouse.o
>  obj-$(CONFIG_MOUSE_APPLETOUCH)		+= appletouch.o
>  obj-$(CONFIG_MOUSE_ATARI)		+= atarimouse.o
>  obj-$(CONFIG_MOUSE_BCM5974)		+= bcm5974.o
> -obj-$(CONFIG_MOUSE_CYAPA)		+= cyapa.o
> +obj-$(CONFIG_MOUSE_CYAPA)		+= cyapatp.o
>  obj-$(CONFIG_MOUSE_GPIO)		+= gpio_mouse.o
>  obj-$(CONFIG_MOUSE_INPORT)		+= inport.o
>  obj-$(CONFIG_MOUSE_LOGIBM)		+= logibm.o
> @@ -34,3 +34,5 @@ psmouse-$(CONFIG_MOUSE_PS2_SENTELIC)	+= sentelic.o
>  psmouse-$(CONFIG_MOUSE_PS2_TRACKPOINT)	+= trackpoint.o
>  psmouse-$(CONFIG_MOUSE_PS2_TOUCHKIT)	+= touchkit_ps2.o
>  psmouse-$(CONFIG_MOUSE_PS2_CYPRESS)	+= cypress_ps2.o
> +
> +cyapatp-y := cyapa.o
> diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
> index b409c3d..5fc8dbe 100644
> --- a/drivers/input/mouse/cyapa.c
> +++ b/drivers/input/mouse/cyapa.c
> @@ -6,7 +6,7 @@
>   *   Daniel Kurtz <djkurtz@chromium.org>
>   *   Benson Leung <bleung@chromium.org>
>   *
> - * Copyright (C) 2011-2012 Cypress Semiconductor, Inc.
> + * Copyright (C) 2011-2014 Cypress Semiconductor, Inc.
>   * Copyright (C) 2011-2012 Google, Inc.
>   *
>   * This file is subject to the terms and conditions of the GNU General Public
> @@ -14,731 +14,114 @@
>   * more details.
>   */
>  
> +#include <linux/debugfs.h>
>  #include <linux/delay.h>
>  #include <linux/i2c.h>
>  #include <linux/input.h>
>  #include <linux/input/mt.h>
>  #include <linux/interrupt.h>
>  #include <linux/module.h>
> +#include <linux/mutex.h>
>  #include <linux/slab.h>
> +#include <linux/uaccess.h>
> +#include <linux/pm_runtime.h>
> +#include "cyapa.h"
>  
> -/* APA trackpad firmware generation */
> -#define CYAPA_GEN3   0x03   /* support MT-protocol B with tracking ID. */
> -
> -#define CYAPA_NAME   "Cypress APA Trackpad (cyapa)"
> -
> -/* commands for read/write registers of Cypress trackpad */
> -#define CYAPA_CMD_SOFT_RESET       0x00
> -#define CYAPA_CMD_POWER_MODE       0x01
> -#define CYAPA_CMD_DEV_STATUS       0x02
> -#define CYAPA_CMD_GROUP_DATA       0x03
> -#define CYAPA_CMD_GROUP_CMD        0x04
> -#define CYAPA_CMD_GROUP_QUERY      0x05
> -#define CYAPA_CMD_BL_STATUS        0x06
> -#define CYAPA_CMD_BL_HEAD          0x07
> -#define CYAPA_CMD_BL_CMD           0x08
> -#define CYAPA_CMD_BL_DATA          0x09
> -#define CYAPA_CMD_BL_ALL           0x0a
> -#define CYAPA_CMD_BLK_PRODUCT_ID   0x0b
> -#define CYAPA_CMD_BLK_HEAD         0x0c
> -
> -/* report data start reg offset address. */
> -#define DATA_REG_START_OFFSET  0x0000
> -
> -#define BL_HEAD_OFFSET 0x00
> -#define BL_DATA_OFFSET 0x10
> -
> -/*
> - * Operational Device Status Register
> - *
> - * bit 7: Valid interrupt source
> - * bit 6 - 4: Reserved
> - * bit 3 - 2: Power status
> - * bit 1 - 0: Device status
> - */
> -#define REG_OP_STATUS     0x00
> -#define OP_STATUS_SRC     0x80
> -#define OP_STATUS_POWER   0x0c
> -#define OP_STATUS_DEV     0x03
> -#define OP_STATUS_MASK (OP_STATUS_SRC | OP_STATUS_POWER | OP_STATUS_DEV)
> -
> -/*
> - * Operational Finger Count/Button Flags Register
> - *
> - * bit 7 - 4: Number of touched finger
> - * bit 3: Valid data
> - * bit 2: Middle Physical Button
> - * bit 1: Right Physical Button
> - * bit 0: Left physical Button
> - */
> -#define REG_OP_DATA1       0x01
> -#define OP_DATA_VALID      0x08
> -#define OP_DATA_MIDDLE_BTN 0x04
> -#define OP_DATA_RIGHT_BTN  0x02
> -#define OP_DATA_LEFT_BTN   0x01
> -#define OP_DATA_BTN_MASK (OP_DATA_MIDDLE_BTN | OP_DATA_RIGHT_BTN | \
> -			  OP_DATA_LEFT_BTN)
> -
> -/*
> - * Bootloader Status Register
> - *
> - * bit 7: Busy
> - * bit 6 - 5: Reserved
> - * bit 4: Bootloader running
> - * bit 3 - 1: Reserved
> - * bit 0: Checksum valid
> - */
> -#define REG_BL_STATUS        0x01
> -#define BL_STATUS_BUSY       0x80
> -#define BL_STATUS_RUNNING    0x10
> -#define BL_STATUS_DATA_VALID 0x08
> -#define BL_STATUS_CSUM_VALID 0x01
> -
> -/*
> - * Bootloader Error Register
> - *
> - * bit 7: Invalid
> - * bit 6: Invalid security key
> - * bit 5: Bootloading
> - * bit 4: Command checksum
> - * bit 3: Flash protection error
> - * bit 2: Flash checksum error
> - * bit 1 - 0: Reserved
> - */
> -#define REG_BL_ERROR         0x02
> -#define BL_ERROR_INVALID     0x80
> -#define BL_ERROR_INVALID_KEY 0x40
> -#define BL_ERROR_BOOTLOADING 0x20
> -#define BL_ERROR_CMD_CSUM    0x10
> -#define BL_ERROR_FLASH_PROT  0x08
> -#define BL_ERROR_FLASH_CSUM  0x04
> -
> -#define BL_STATUS_SIZE  3  /* length of bootloader status registers */
> -#define BLK_HEAD_BYTES 32
> -
> -#define PRODUCT_ID_SIZE  16
> -#define QUERY_DATA_SIZE  27
> -#define REG_PROTOCOL_GEN_QUERY_OFFSET  20
> -
> -#define REG_OFFSET_DATA_BASE     0x0000
> -#define REG_OFFSET_COMMAND_BASE  0x0028
> -#define REG_OFFSET_QUERY_BASE    0x002a
> -
> -#define CAPABILITY_LEFT_BTN_MASK	(0x01 << 3)
> -#define CAPABILITY_RIGHT_BTN_MASK	(0x01 << 4)
> -#define CAPABILITY_MIDDLE_BTN_MASK	(0x01 << 5)
> -#define CAPABILITY_BTN_MASK  (CAPABILITY_LEFT_BTN_MASK | \
> -			      CAPABILITY_RIGHT_BTN_MASK | \
> -			      CAPABILITY_MIDDLE_BTN_MASK)
> -
> -#define CYAPA_OFFSET_SOFT_RESET  REG_OFFSET_COMMAND_BASE
> -
> -#define REG_OFFSET_POWER_MODE (REG_OFFSET_COMMAND_BASE + 1)
> -
> -#define PWR_MODE_MASK   0xfc
> -#define PWR_MODE_FULL_ACTIVE (0x3f << 2)
> -#define PWR_MODE_IDLE        (0x05 << 2) /* default sleep time is 50 ms. */
> -#define PWR_MODE_OFF         (0x00 << 2)
> -
> -#define PWR_STATUS_MASK      0x0c
> -#define PWR_STATUS_ACTIVE    (0x03 << 2)
> -#define PWR_STATUS_IDLE      (0x02 << 2)
> -#define PWR_STATUS_OFF       (0x00 << 2)
> -
> -/*
> - * CYAPA trackpad device states.
> - * Used in register 0x00, bit1-0, DeviceStatus field.
> - * Other values indicate device is in an abnormal state and must be reset.
> - */
> -#define CYAPA_DEV_NORMAL  0x03
> -#define CYAPA_DEV_BUSY    0x01
> -
> -enum cyapa_state {
> -	CYAPA_STATE_OP,
> -	CYAPA_STATE_BL_IDLE,
> -	CYAPA_STATE_BL_ACTIVE,
> -	CYAPA_STATE_BL_BUSY,
> -	CYAPA_STATE_NO_DEVICE,
> -};
> -
> -
> -struct cyapa_touch {
> -	/*
> -	 * high bits or x/y position value
> -	 * bit 7 - 4: high 4 bits of x position value
> -	 * bit 3 - 0: high 4 bits of y position value
> -	 */
> -	u8 xy_hi;
> -	u8 x_lo;  /* low 8 bits of x position value. */
> -	u8 y_lo;  /* low 8 bits of y position value. */
> -	u8 pressure;
> -	/* id range is 1 - 15.  It is incremented with every new touch. */
> -	u8 id;
> -} __packed;
> -
> -/* The touch.id is used as the MT slot id, thus max MT slot is 15 */
> -#define CYAPA_MAX_MT_SLOTS  15
> -
> -struct cyapa_reg_data {
> -	/*
> -	 * bit 0 - 1: device status
> -	 * bit 3 - 2: power mode
> -	 * bit 6 - 4: reserved
> -	 * bit 7: interrupt valid bit
> -	 */
> -	u8 device_status;
> -	/*
> -	 * bit 7 - 4: number of fingers currently touching pad
> -	 * bit 3: valid data check bit
> -	 * bit 2: middle mechanism button state if exists
> -	 * bit 1: right mechanism button state if exists
> -	 * bit 0: left mechanism button state if exists
> -	 */
> -	u8 finger_btn;
> -	/* CYAPA reports up to 5 touches per packet. */
> -	struct cyapa_touch touches[5];
> -} __packed;
> -
> -/* The main device structure */
> -struct cyapa {
> -	enum cyapa_state state;
> -
> -	struct i2c_client *client;
> -	struct input_dev *input;
> -	char phys[32];	/* device physical location */
> -	int irq;
> -	bool irq_wake;  /* irq wake is enabled */
> -	bool smbus;
> -
> -	/* read from query data region. */
> -	char product_id[16];
> -	u8 btn_capability;
> -	u8 gen;
> -	int max_abs_x;
> -	int max_abs_y;
> -	int physical_size_x;
> -	int physical_size_y;
> -};
> -
> -static const u8 bl_deactivate[] = { 0x00, 0xff, 0x3b, 0x00, 0x01, 0x02, 0x03,
> -		0x04, 0x05, 0x06, 0x07 };
> -static const u8 bl_exit[] = { 0x00, 0xff, 0xa5, 0x00, 0x01, 0x02, 0x03, 0x04,
> -		0x05, 0x06, 0x07 };
> -
> -struct cyapa_cmd_len {
> -	u8 cmd;
> -	u8 len;
> -};
>  
>  #define CYAPA_ADAPTER_FUNC_NONE   0
>  #define CYAPA_ADAPTER_FUNC_I2C    1
>  #define CYAPA_ADAPTER_FUNC_SMBUS  2
>  #define CYAPA_ADAPTER_FUNC_BOTH   3
>  
> -/*
> - * macros for SMBus communication
> - */
> -#define SMBUS_READ   0x01
> -#define SMBUS_WRITE 0x00
> -#define SMBUS_ENCODE_IDX(cmd, idx) ((cmd) | (((idx) & 0x03) << 1))
> -#define SMBUS_ENCODE_RW(cmd, rw) ((cmd) | ((rw) & 0x01))
> -#define SMBUS_BYTE_BLOCK_CMD_MASK 0x80
> -#define SMBUS_GROUP_BLOCK_CMD_MASK 0x40
> -
> - /* for byte read/write command */
> -#define CMD_RESET 0
> -#define CMD_POWER_MODE 1
> -#define CMD_DEV_STATUS 2
> -#define SMBUS_BYTE_CMD(cmd) (((cmd) & 0x3f) << 1)
> -#define CYAPA_SMBUS_RESET SMBUS_BYTE_CMD(CMD_RESET)
> -#define CYAPA_SMBUS_POWER_MODE SMBUS_BYTE_CMD(CMD_POWER_MODE)
> -#define CYAPA_SMBUS_DEV_STATUS SMBUS_BYTE_CMD(CMD_DEV_STATUS)
> -
> - /* for group registers read/write command */
> -#define REG_GROUP_DATA 0
> -#define REG_GROUP_CMD 2
> -#define REG_GROUP_QUERY 3
> -#define SMBUS_GROUP_CMD(grp) (0x80 | (((grp) & 0x07) << 3))
> -#define CYAPA_SMBUS_GROUP_DATA SMBUS_GROUP_CMD(REG_GROUP_DATA)
> -#define CYAPA_SMBUS_GROUP_CMD SMBUS_GROUP_CMD(REG_GROUP_CMD)
> -#define CYAPA_SMBUS_GROUP_QUERY SMBUS_GROUP_CMD(REG_GROUP_QUERY)
> -
> - /* for register block read/write command */
> -#define CMD_BL_STATUS 0
> -#define CMD_BL_HEAD 1
> -#define CMD_BL_CMD 2
> -#define CMD_BL_DATA 3
> -#define CMD_BL_ALL 4
> -#define CMD_BLK_PRODUCT_ID 5
> -#define CMD_BLK_HEAD 6
> -#define SMBUS_BLOCK_CMD(cmd) (0xc0 | (((cmd) & 0x1f) << 1))
> -
> -/* register block read/write command in bootloader mode */
> -#define CYAPA_SMBUS_BL_STATUS SMBUS_BLOCK_CMD(CMD_BL_STATUS)
> -#define CYAPA_SMBUS_BL_HEAD SMBUS_BLOCK_CMD(CMD_BL_HEAD)
> -#define CYAPA_SMBUS_BL_CMD SMBUS_BLOCK_CMD(CMD_BL_CMD)
> -#define CYAPA_SMBUS_BL_DATA SMBUS_BLOCK_CMD(CMD_BL_DATA)
> -#define CYAPA_SMBUS_BL_ALL SMBUS_BLOCK_CMD(CMD_BL_ALL)
> -
> -/* register block read/write command in operational mode */
> -#define CYAPA_SMBUS_BLK_PRODUCT_ID SMBUS_BLOCK_CMD(CMD_BLK_PRODUCT_ID)
> -#define CYAPA_SMBUS_BLK_HEAD SMBUS_BLOCK_CMD(CMD_BLK_HEAD)
> -
> -static const struct cyapa_cmd_len cyapa_i2c_cmds[] = {
> -	{ CYAPA_OFFSET_SOFT_RESET, 1 },
> -	{ REG_OFFSET_COMMAND_BASE + 1, 1 },
> -	{ REG_OFFSET_DATA_BASE, 1 },
> -	{ REG_OFFSET_DATA_BASE, sizeof(struct cyapa_reg_data) },
> -	{ REG_OFFSET_COMMAND_BASE, 0 },
> -	{ REG_OFFSET_QUERY_BASE, QUERY_DATA_SIZE },
> -	{ BL_HEAD_OFFSET, 3 },
> -	{ BL_HEAD_OFFSET, 16 },
> -	{ BL_HEAD_OFFSET, 16 },
> -	{ BL_DATA_OFFSET, 16 },
> -	{ BL_HEAD_OFFSET, 32 },
> -	{ REG_OFFSET_QUERY_BASE, PRODUCT_ID_SIZE },
> -	{ REG_OFFSET_DATA_BASE, 32 }
> -};
> +#define CYAPA_DEBUGFS_READ_FW	"read_fw"
> +#define CYAPA_DEBUGFS_RAW_DATA	"raw_data"
> +#define CYAPA_FW_NAME		"cyapa.bin"
> +
> +const char unique_str[] = "CYTRA";
> +
>  
> -static const struct cyapa_cmd_len cyapa_smbus_cmds[] = {
> -	{ CYAPA_SMBUS_RESET, 1 },
> -	{ CYAPA_SMBUS_POWER_MODE, 1 },
> -	{ CYAPA_SMBUS_DEV_STATUS, 1 },
> -	{ CYAPA_SMBUS_GROUP_DATA, sizeof(struct cyapa_reg_data) },
> -	{ CYAPA_SMBUS_GROUP_CMD, 2 },
> -	{ CYAPA_SMBUS_GROUP_QUERY, QUERY_DATA_SIZE },
> -	{ CYAPA_SMBUS_BL_STATUS, 3 },
> -	{ CYAPA_SMBUS_BL_HEAD, 16 },
> -	{ CYAPA_SMBUS_BL_CMD, 16 },
> -	{ CYAPA_SMBUS_BL_DATA, 16 },
> -	{ CYAPA_SMBUS_BL_ALL, 32 },
> -	{ CYAPA_SMBUS_BLK_PRODUCT_ID, PRODUCT_ID_SIZE },
> -	{ CYAPA_SMBUS_BLK_HEAD, 16 },
> -};
>  
> -static ssize_t cyapa_i2c_reg_read_block(struct cyapa *cyapa, u8 reg, size_t len,
> +ssize_t cyapa_i2c_reg_read_block(struct cyapa *cyapa, u8 reg, size_t len,
>  					u8 *values)
>  {
>  	return i2c_smbus_read_i2c_block_data(cyapa->client, reg, len, values);
>  }
>  
> -static ssize_t cyapa_i2c_reg_write_block(struct cyapa *cyapa, u8 reg,
> +ssize_t cyapa_i2c_reg_write_block(struct cyapa *cyapa, u8 reg,
>  					 size_t len, const u8 *values)
>  {
>  	return i2c_smbus_write_i2c_block_data(cyapa->client, reg, len, values);
>  }
>  
> -/*
> - * cyapa_smbus_read_block - perform smbus block read command
> - * @cyapa  - private data structure of the driver
> - * @cmd    - the properly encoded smbus command
> - * @len    - expected length of smbus command result
> - * @values - buffer to store smbus command result
> - *
> - * Returns negative errno, else the number of bytes written.
> - *
> - * Note:
> - * In trackpad device, the memory block allocated for I2C register map
> - * is 256 bytes, so the max read block for I2C bus is 256 bytes.
> - */
> -static ssize_t cyapa_smbus_read_block(struct cyapa *cyapa, u8 cmd, size_t len,
> -				      u8 *values)
> -{
> -	ssize_t ret;
> -	u8 index;
> -	u8 smbus_cmd;
> -	u8 *buf;
> -	struct i2c_client *client = cyapa->client;
> -
> -	if (!(SMBUS_BYTE_BLOCK_CMD_MASK & cmd))
> -		return -EINVAL;
> -
> -	if (SMBUS_GROUP_BLOCK_CMD_MASK & cmd) {
> -		/* read specific block registers command. */
> -		smbus_cmd = SMBUS_ENCODE_RW(cmd, SMBUS_READ);
> -		ret = i2c_smbus_read_block_data(client, smbus_cmd, values);
> -		goto out;
> -	}
> -
> -	ret = 0;
> -	for (index = 0; index * I2C_SMBUS_BLOCK_MAX < len; index++) {
> -		smbus_cmd = SMBUS_ENCODE_IDX(cmd, index);
> -		smbus_cmd = SMBUS_ENCODE_RW(smbus_cmd, SMBUS_READ);
> -		buf = values + I2C_SMBUS_BLOCK_MAX * index;
> -		ret = i2c_smbus_read_block_data(client, smbus_cmd, buf);
> -		if (ret < 0)
> -			goto out;
> -	}
> -
> -out:
> -	return ret > 0 ? len : ret;
> -}
> -
> -static s32 cyapa_read_byte(struct cyapa *cyapa, u8 cmd_idx)
> -{
> -	u8 cmd;
> -
> -	if (cyapa->smbus) {
> -		cmd = cyapa_smbus_cmds[cmd_idx].cmd;
> -		cmd = SMBUS_ENCODE_RW(cmd, SMBUS_READ);
> -	} else {
> -		cmd = cyapa_i2c_cmds[cmd_idx].cmd;
> -	}
> -	return i2c_smbus_read_byte_data(cyapa->client, cmd);
> -}
> -
> -static s32 cyapa_write_byte(struct cyapa *cyapa, u8 cmd_idx, u8 value)
> -{
> -	u8 cmd;
> -
> -	if (cyapa->smbus) {
> -		cmd = cyapa_smbus_cmds[cmd_idx].cmd;
> -		cmd = SMBUS_ENCODE_RW(cmd, SMBUS_WRITE);
> -	} else {
> -		cmd = cyapa_i2c_cmds[cmd_idx].cmd;
> -	}
> -	return i2c_smbus_write_byte_data(cyapa->client, cmd, value);
> -}
> -
> -static ssize_t cyapa_read_block(struct cyapa *cyapa, u8 cmd_idx, u8 *values)
> -{
> -	u8 cmd;
> -	size_t len;
> -
> -	if (cyapa->smbus) {
> -		cmd = cyapa_smbus_cmds[cmd_idx].cmd;
> -		len = cyapa_smbus_cmds[cmd_idx].len;
> -		return cyapa_smbus_read_block(cyapa, cmd, len, values);
> -	} else {
> -		cmd = cyapa_i2c_cmds[cmd_idx].cmd;
> -		len = cyapa_i2c_cmds[cmd_idx].len;
> -		return cyapa_i2c_reg_read_block(cyapa, cmd, len, values);
> -	}
> -}
> -
> -/*
> - * Query device for its current operating state.
> - *
> - */
> -static int cyapa_get_state(struct cyapa *cyapa)
> +/* Returns 0 on success, else negative errno on failure. */
> +ssize_t cyapa_i2c_read(struct cyapa *cyapa, u8 reg, size_t len,
> +					u8 *values)
>  {
>  	int ret;
> -	u8 status[BL_STATUS_SIZE];
> -
> -	cyapa->state = CYAPA_STATE_NO_DEVICE;
> -
> -	/*
> -	 * Get trackpad status by reading 3 registers starting from 0.
> -	 * If the device is in the bootloader, this will be BL_HEAD.
> -	 * If the device is in operation mode, this will be the DATA regs.
> -	 *
> -	 */
> -	ret = cyapa_i2c_reg_read_block(cyapa, BL_HEAD_OFFSET, BL_STATUS_SIZE,
> -				       status);
> -
> -	/*
> -	 * On smbus systems in OP mode, the i2c_reg_read will fail with
> -	 * -ETIMEDOUT.  In this case, try again using the smbus equivalent
> -	 * command.  This should return a BL_HEAD indicating CYAPA_STATE_OP.
> -	 */
> -	if (cyapa->smbus && (ret == -ETIMEDOUT || ret == -ENXIO))
> -		ret = cyapa_read_block(cyapa, CYAPA_CMD_BL_STATUS, status);
> -
> -	if (ret != BL_STATUS_SIZE)
> -		goto error;
> -
> -	if ((status[REG_OP_STATUS] & OP_STATUS_SRC) == OP_STATUS_SRC) {
> -		switch (status[REG_OP_STATUS] & OP_STATUS_DEV) {
> -		case CYAPA_DEV_NORMAL:
> -		case CYAPA_DEV_BUSY:
> -			cyapa->state = CYAPA_STATE_OP;
> -			break;
> -		default:
> -			ret = -EAGAIN;
> -			goto error;
> -		}
> -	} else {
> -		if (status[REG_BL_STATUS] & BL_STATUS_BUSY)
> -			cyapa->state = CYAPA_STATE_BL_BUSY;
> -		else if (status[REG_BL_ERROR] & BL_ERROR_BOOTLOADING)
> -			cyapa->state = CYAPA_STATE_BL_ACTIVE;
> -		else
> -			cyapa->state = CYAPA_STATE_BL_IDLE;
> -	}
> -
> -	return 0;
> -error:
> -	return (ret < 0) ? ret : -EAGAIN;
> +	struct i2c_client *client = cyapa->client;
> +	struct i2c_msg msgs[] = {
> +		{
> +			.addr = client->addr,
> +			.flags = 0,
> +			.len = 1,
> +			.buf = &reg,
> +		},
> +		{
> +			.addr = client->addr,
> +			.flags = I2C_M_RD,
> +			.len = len,
> +			.buf = values,
> +		},
> +	};
> +
> +	ret = i2c_transfer(client->adapter, msgs, 2);

You need to watch out for partial transfers. It should be:

	if (ret != ARRAY_SIZE(msgs))
		return ret < 0 ? ret : -EIO;

	return 0;

> +
> +	return ret < 0 ? ret : 0;
>  }
>  
> -/*
> - * Poll device for its status in a loop, waiting up to timeout for a response.
> - *
> - * When the device switches state, it usually takes ~300 ms.
> - * However, when running a new firmware image, the device must calibrate its
> - * sensors, which can take as long as 2 seconds.
> +/**
> + * cyapa_i2c_write - Execute i2c block data write operation
> + * @cyapa: Handle to this driver
> + * @ret: Offset of the data to written in the register map
> + * @len: number of bytes to write
> + * @values: Data to be written
>   *
> - * Note: The timeout has granularity of the polling rate, which is 100 ms.
> - *
> - * Returns:
> - *   0 when the device eventually responds with a valid non-busy state.
> - *   -ETIMEDOUT if device never responds (too many -EAGAIN)
> - *   < 0    other errors
> + * Return negative errno code on error; return zero when success.
>   */
> -static int cyapa_poll_state(struct cyapa *cyapa, unsigned int timeout)
> +ssize_t cyapa_i2c_write(struct cyapa *cyapa, u8 reg,
> +					 size_t len, const void *values)
>  {
>  	int ret;
> -	int tries = timeout / 100;
> -
> -	ret = cyapa_get_state(cyapa);
> -	while ((ret || cyapa->state >= CYAPA_STATE_BL_BUSY) && tries--) {
> -		msleep(100);
> -		ret = cyapa_get_state(cyapa);
> -	}
> -	return (ret == -EAGAIN || ret == -ETIMEDOUT) ? -ETIMEDOUT : ret;
> -}
> +	struct i2c_client *client = cyapa->client;
> +	char data[32], *buf;
>  
> -static int cyapa_bl_deactivate(struct cyapa *cyapa)
> -{
> -	int ret;
> +	if (len > 31)
> +		buf = kzalloc(len + 1, GFP_KERNEL);
> +	else
> +		buf = data;
>  
> -	ret = cyapa_i2c_reg_write_block(cyapa, 0, sizeof(bl_deactivate),
> -					bl_deactivate);
> -	if (ret < 0)
> -		return ret;
> +	buf[0] = reg;
> +	memcpy(&buf[1], values, len);
> +	ret = i2c_master_send(client, buf, len + 1);
>  
> -	/* wait for bootloader to switch to idle state; should take < 100ms */
> -	msleep(100);
> -	ret = cyapa_poll_state(cyapa, 500);
> -	if (ret < 0)
> -		return ret;
> -	if (cyapa->state != CYAPA_STATE_BL_IDLE)
> -		return -EAGAIN;
> -	return 0;
> +	if (buf != data)
> +		kfree(buf);
> +	return (ret == (len + 1)) ? 0 : ((ret < 0) ? ret : -EIO);
>  }
>  
> -/*
> - * Exit bootloader
> - *
> - * Send bl_exit command, then wait 50 - 100 ms to let device transition to
> - * operational mode.  If this is the first time the device's firmware is
> - * running, it can take up to 2 seconds to calibrate its sensors.  So, poll
> - * the device's new state for up to 2 seconds.
> - *
> - * Returns:
> - *   -EIO    failure while reading from device
> - *   -EAGAIN device is stuck in bootloader, b/c it has invalid firmware
> - *   0       device is supported and in operational mode
> - */
> -static int cyapa_bl_exit(struct cyapa *cyapa)
> +void cyapa_default_irq_handler(struct cyapa *cyapa)
>  {
> -	int ret;
> -
> -	ret = cyapa_i2c_reg_write_block(cyapa, 0, sizeof(bl_exit), bl_exit);
> -	if (ret < 0)
> -		return ret;
> -
> -	/*
> -	 * Wait for bootloader to exit, and operation mode to start.
> -	 * Normally, this takes at least 50 ms.
> -	 */
> -	usleep_range(50000, 100000);
>  	/*
> -	 * In addition, when a device boots for the first time after being
> -	 * updated to new firmware, it must first calibrate its sensors, which
> -	 * can take up to an additional 2 seconds.
> +	 * Do redetecting when device states is still unknown and
> +	 * interrupt envent is received from device.
>  	 */
> -	ret = cyapa_poll_state(cyapa, 2000);
> -	if (ret < 0)
> -		return ret;
> -	if (cyapa->state != CYAPA_STATE_OP)
> -		return -EAGAIN;
> -
> -	return 0;
> -}
> -
> -/*
> - * Set device power mode
> - *
> - */
> -static int cyapa_set_power_mode(struct cyapa *cyapa, u8 power_mode)
> -{
> -	struct device *dev = &cyapa->client->dev;
> -	int ret;
> -	u8 power;
> -
> -	if (cyapa->state != CYAPA_STATE_OP)
> -		return 0;
> -
> -	ret = cyapa_read_byte(cyapa, CYAPA_CMD_POWER_MODE);
> -	if (ret < 0)
> -		return ret;
> -
> -	power = ret & ~PWR_MODE_MASK;
> -	power |= power_mode & PWR_MODE_MASK;
> -	ret = cyapa_write_byte(cyapa, CYAPA_CMD_POWER_MODE, power);
> -	if (ret < 0)
> -		dev_err(dev, "failed to set power_mode 0x%02x err = %d\n",
> -			power_mode, ret);
> -	return ret;
> -}
> -
> -static int cyapa_get_query_data(struct cyapa *cyapa)
> -{
> -	u8 query_data[QUERY_DATA_SIZE];
> -	int ret;
> -
> -	if (cyapa->state != CYAPA_STATE_OP)
> -		return -EBUSY;
> -
> -	ret = cyapa_read_block(cyapa, CYAPA_CMD_GROUP_QUERY, query_data);
> -	if (ret < 0)
> -		return ret;
> -	if (ret != QUERY_DATA_SIZE)
> -		return -EIO;
> -
> -	memcpy(&cyapa->product_id[0], &query_data[0], 5);
> -	cyapa->product_id[5] = '-';
> -	memcpy(&cyapa->product_id[6], &query_data[5], 6);
> -	cyapa->product_id[12] = '-';
> -	memcpy(&cyapa->product_id[13], &query_data[11], 2);
> -	cyapa->product_id[15] = '\0';
> -
> -	cyapa->btn_capability = query_data[19] & CAPABILITY_BTN_MASK;
> -
> -	cyapa->gen = query_data[20] & 0x0f;
> -
> -	cyapa->max_abs_x = ((query_data[21] & 0xf0) << 4) | query_data[22];
> -	cyapa->max_abs_y = ((query_data[21] & 0x0f) << 8) | query_data[23];
> -
> -	cyapa->physical_size_x =
> -		((query_data[24] & 0xf0) << 4) | query_data[25];
> -	cyapa->physical_size_y =
> -		((query_data[24] & 0x0f) << 8) | query_data[26];
> -
> -	return 0;
> +	async_schedule(cyapa_detect_async, cyapa);

I think I already asked this before - why do we need to try and schedule async
detect from interrupt handler. In what cases we will fail to initialize the
device during normal probing, but then are fine when stray interrupt arrives?

>  }
>  
> -/*
> - * Check if device is operational.
> - *
> - * An operational device is responding, has exited bootloader, and has
> - * firmware supported by this driver.
> - *
> - * Returns:
> - *   -EBUSY  no device or in bootloader
> - *   -EIO    failure while reading from device
> - *   -EAGAIN device is still in bootloader
> - *           if ->state = CYAPA_STATE_BL_IDLE, device has invalid firmware
> - *   -EINVAL device is in operational mode, but not supported by this driver
> - *   0       device is supported
> - */
> -static int cyapa_check_is_operational(struct cyapa *cyapa)
> -{
> -	struct device *dev = &cyapa->client->dev;
> -	static const char unique_str[] = "CYTRA";
> -	int ret;
> -
> -	ret = cyapa_poll_state(cyapa, 2000);
> -	if (ret < 0)
> -		return ret;
> -	switch (cyapa->state) {
> -	case CYAPA_STATE_BL_ACTIVE:
> -		ret = cyapa_bl_deactivate(cyapa);
> -		if (ret)
> -			return ret;
> -
> -	/* Fallthrough state */
> -	case CYAPA_STATE_BL_IDLE:
> -		ret = cyapa_bl_exit(cyapa);
> -		if (ret)
> -			return ret;
> -
> -	/* Fallthrough state */
> -	case CYAPA_STATE_OP:
> -		ret = cyapa_get_query_data(cyapa);
> -		if (ret < 0)
> -			return ret;
> -
> -		/* only support firmware protocol gen3 */
> -		if (cyapa->gen != CYAPA_GEN3) {
> -			dev_err(dev, "unsupported protocol version (%d)",
> -				cyapa->gen);
> -			return -EINVAL;
> -		}
> -
> -		/* only support product ID starting with CYTRA */
> -		if (memcmp(cyapa->product_id, unique_str,
> -			   sizeof(unique_str) - 1) != 0) {
> -			dev_err(dev, "unsupported product ID (%s)\n",
> -				cyapa->product_id);
> -			return -EINVAL;
> -		}
> -		return 0;
> -
> -	default:
> -		return -EIO;
> -	}
> -	return 0;
> -}
> -
> -static irqreturn_t cyapa_irq(int irq, void *dev_id)
> -{
> -	struct cyapa *cyapa = dev_id;
> -	struct device *dev = &cyapa->client->dev;
> -	struct input_dev *input = cyapa->input;
> -	struct cyapa_reg_data data;
> -	int i;
> -	int ret;
> -	int num_fingers;
> -
> -	if (device_may_wakeup(dev))
> -		pm_wakeup_event(dev, 0);
> -
> -	ret = cyapa_read_block(cyapa, CYAPA_CMD_GROUP_DATA, (u8 *)&data);
> -	if (ret != sizeof(data))
> -		goto out;
> -
> -	if ((data.device_status & OP_STATUS_SRC) != OP_STATUS_SRC ||
> -	    (data.device_status & OP_STATUS_DEV) != CYAPA_DEV_NORMAL ||
> -	    (data.finger_btn & OP_DATA_VALID) != OP_DATA_VALID) {
> -		goto out;
> -	}
> -
> -	num_fingers = (data.finger_btn >> 4) & 0x0f;
> -	for (i = 0; i < num_fingers; i++) {
> -		const struct cyapa_touch *touch = &data.touches[i];
> -		/* Note: touch->id range is 1 to 15; slots are 0 to 14. */
> -		int slot = touch->id - 1;
> -
> -		input_mt_slot(input, slot);
> -		input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
> -		input_report_abs(input, ABS_MT_POSITION_X,
> -				 ((touch->xy_hi & 0xf0) << 4) | touch->x_lo);
> -		input_report_abs(input, ABS_MT_POSITION_Y,
> -				 ((touch->xy_hi & 0x0f) << 8) | touch->y_lo);
> -		input_report_abs(input, ABS_MT_PRESSURE, touch->pressure);
> -	}
> -
> -	input_mt_sync_frame(input);
> -
> -	if (cyapa->btn_capability & CAPABILITY_LEFT_BTN_MASK)
> -		input_report_key(input, BTN_LEFT,
> -				 data.finger_btn & OP_DATA_LEFT_BTN);
> -
> -	if (cyapa->btn_capability & CAPABILITY_MIDDLE_BTN_MASK)
> -		input_report_key(input, BTN_MIDDLE,
> -				 data.finger_btn & OP_DATA_MIDDLE_BTN);
> -
> -	if (cyapa->btn_capability & CAPABILITY_RIGHT_BTN_MASK)
> -		input_report_key(input, BTN_RIGHT,
> -				 data.finger_btn & OP_DATA_RIGHT_BTN);
> -
> -	input_sync(input);
> +const struct cyapa_dev_ops cyapa_default_ops = {
> +	.irq_handler = cyapa_default_irq_handler
> +};
>  
> -out:
> -	return IRQ_HANDLED;
> -}
>  
>  static u8 cyapa_check_adapter_functionality(struct i2c_client *client)
>  {
> @@ -772,19 +155,40 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)
>  	input->phys = cyapa->phys;
>  	input->id.bustype = BUS_I2C;
>  	input->id.version = 1;
> -	input->id.product = 0;  /* means any product in eventcomm. */
> +	input->id.product = 0;  /* Means any product in eventcomm. */
>  	input->dev.parent = &cyapa->client->dev;
>  
>  	input_set_drvdata(input, cyapa);
>  
>  	__set_bit(EV_ABS, input->evbit);
>  
> -	/* finger position */
> +	/* Finger position */
>  	input_set_abs_params(input, ABS_MT_POSITION_X, 0, cyapa->max_abs_x, 0,
>  			     0);
>  	input_set_abs_params(input, ABS_MT_POSITION_Y, 0, cyapa->max_abs_y, 0,
>  			     0);
> -	input_set_abs_params(input, ABS_MT_PRESSURE, 0, 255, 0, 0);
> +	input_set_abs_params(input, ABS_MT_PRESSURE, 0, cyapa->max_z, 0, 0);
> +	if (cyapa->gen > CYAPA_GEN3) {
> +		input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
> +		input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255, 0, 0);
> +		/*
> +		 * Orientation is the angle between the vertical axis and
> +		 * the major axis of the contact ellipse.
> +		 * The range is -127 to 127.
> +		 * the positive direction is clockwise form the vertical axis.
> +		 * If the ellipse of contact degenerates into a circle,
> +		 * orientation is reported as 0.
> +		 *
> +		 * Also, for Gen5 trackpad the accurate of this orientation
> +		 * value is value + (-30 ~ 30).
> +		 */
> +		input_set_abs_params(input, ABS_MT_ORIENTATION,
> +				-127, 127, 0, 0);
> +	}
> +	if (cyapa->gen >= CYAPA_GEN5) {
> +		input_set_abs_params(input, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
> +		input_set_abs_params(input, ABS_MT_WIDTH_MINOR, 0, 255, 0, 0);
> +	}
>  
>  	input_abs_set_res(input, ABS_MT_POSITION_X,
>  			  cyapa->max_abs_x / cyapa->physical_size_x);
> @@ -801,7 +205,7 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)
>  	if (cyapa->btn_capability == CAPABILITY_LEFT_BTN_MASK)
>  		__set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
>  
> -	/* handle pointer emulation and unused slots in core */
> +	/* Handle pointer emulation and unused slots in core */
>  	ret = input_mt_init_slots(input, CYAPA_MAX_MT_SLOTS,
>  				  INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED);
>  	if (ret) {
> @@ -823,6 +227,224 @@ err_free_device:
>  	return ret;
>  }
>  
> +/*
> + * Check if device is operational.
> + *
> + * An operational device is responding, has exited bootloader, and has
> + * firmware supported by this driver.
> + *
> + * Returns:
> + *   -EBUSY  no device or in bootloader
> + *   -EIO    failure while reading from device
> + *   -EAGAIN device is still in bootloader
> + *           if ->state = CYAPA_STATE_BL_IDLE, device has invalid firmware
> + *   -EINVAL device is in operational mode, but not supported by this driver
> + *   0       device is supported
> + */
> +static int cyapa_check_is_operational(struct cyapa *cyapa)
> +{
> +	int ret;
> +
> +	ret = cyapa_poll_state(cyapa, 4000);
> +	if (ret)
> +		return ret;
> +
> +	switch (cyapa->gen) {
> +	default:
> +		cyapa->ops = &cyapa_default_ops;
> +		cyapa->gen = CYAPA_GEN_UNKNOWN;
> +		break;
> +	}
> +
> +	if (cyapa->ops->operational_check)
> +		ret = cyapa->ops->operational_check(cyapa);
> +	else
> +		ret = -EBUSY;
> +
> +	return ret;
> +}
> +
> +
> +static irqreturn_t cyapa_irq(int irq, void *dev_id)
> +{
> +	struct cyapa *cyapa = dev_id;
> +	struct input_dev *input = cyapa->input;
> +	bool cont;
> +
> +	/* Interrupt event maybe cuased by host command to trackpad device. */
> +	cont = true;
> +	if (cyapa->ops->irq_cmd_handler)
> +		cont = cyapa->ops->irq_cmd_handler(cyapa);
> +
> +	/* Interrupt event maybe from trackpad device input reporting. */
> +	if (cont && cyapa->ops->irq_handler) {
> +		if (!mutex_trylock(&cyapa->state_sync_lock)) {
> +			if (cyapa->ops->sort_empty_output_data)
> +				cyapa->ops->sort_empty_output_data(cyapa,
> +					NULL, NULL, NULL);
> +			goto out;
> +		}
> +
> +		if (!input) {
> +			if (cyapa->ops->sort_empty_output_data)
> +				cyapa->ops->sort_empty_output_data(cyapa,
> +					NULL, NULL, NULL);
> +		} else
> +			cyapa->ops->irq_handler(cyapa);
> +
> +		mutex_unlock(&cyapa->state_sync_lock);
> +	}
> +out:
> +	return IRQ_HANDLED;
> +}
> +
> +/*
> + * Query device for its current operating state.
> + */
> +static int cyapa_get_state(struct cyapa *cyapa)
> +{
> +	cyapa->state = CYAPA_STATE_NO_DEVICE;
> +
> +	return -ENODEV;
> +}
> +
> +/*
> + * Poll device for its status in a loop, waiting up to timeout for a response.
> + *
> + * When the device switches state, it usually takes ~300 ms.
> + * However, when running a new firmware image, the device must calibrate its
> + * sensors, which can take as long as 2 seconds.
> + *
> + * Note: The timeout has granularity of the polling rate, which is 100 ms.
> + *
> + * Returns:
> + *   0 when the device eventually responds with a valid non-busy state.
> + *   -ETIMEDOUT if device never responds (too many -EAGAIN)
> + *   < 0    other errors
> + */
> +int cyapa_poll_state(struct cyapa *cyapa, unsigned int timeout)
> +{
> +	int ret;
> +	int tries = timeout / 100;
> +
> +	ret = cyapa_get_state(cyapa);
> +	while ((ret || cyapa->state >= CYAPA_STATE_BL_BUSY) && tries--) {
> +		msleep(100);
> +		ret = cyapa_get_state(cyapa);
> +	}
> +
> +	return (ret == -EAGAIN || ret == -ETIMEDOUT) ? -ETIMEDOUT : ret;
> +}
> +
> +static void cyapa_detect(struct cyapa *cyapa)
> +{
> +	struct device *dev = &cyapa->client->dev;
> +	char *envp[2] = {"ERROR=1", NULL};
> +	int ret;
> +
> +	ret = cyapa_check_is_operational(cyapa);
> +	if (ret == -ETIMEDOUT)
> +		dev_err(dev, "no device detected, %d\n", ret);
> +	else if (ret)
> +		dev_err(dev, "device detected, but not operational, %d\n", ret);
> +
> +	if (ret) {
> +		kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
> +		return;
> +	}
> +
> +	if (!cyapa->input) {
> +		ret = cyapa_create_input_dev(cyapa);
> +		if (ret)
> +			dev_err(dev, "create input_dev instance failed, %d\n",
> +				ret);
> +
> +		/*
> +		 * On some systems, a system crash / warm boot does not reset
> +		 * the device's current power mode to FULL_ACTIVE.
> +		 * If such an event happens during suspend, after the device
> +		 * has been put in a low power mode, the device will still be
> +		 * in low power mode on a subsequent boot, since there was
> +		 * never a matching resume().
> +		 * Handle this by always forcing full power here, when a
> +		 * device is first detected to be in operational mode.
> +		 */
> +		if (cyapa->ops->set_power_mode) {
> +			ret = cyapa->ops->set_power_mode(cyapa,
> +					PWR_MODE_FULL_ACTIVE, 0);
> +			if (ret)
> +				dev_warn(dev, "set active power failed, %d\n",
> +						ret);
> +		}
> +	}
> +}
> +
> +/*
> + * Sysfs Interface.
> + */
> +
> +/*
> + * cyapa_sleep_time_to_pwr_cmd and cyapa_pwr_cmd_to_sleep_time
> + *
> + * These are helper functions that convert to and from integer idle
> + * times and register settings to write to the PowerMode register.
> + * The trackpad supports between 20ms to 1000ms scan intervals.
> + * The time will be increased in increments of 10ms from 20ms to 100ms.
> + * From 100ms to 1000ms, time will be increased in increments of 20ms.
> + *
> + * When Idle_Time < 100, the format to convert Idle_Time to Idle_Command is:
> + *   Idle_Command = Idle Time / 10;
> + * When Idle_Time >= 100, the format to convert Idle_Time to Idle_Command is:
> + *   Idle_Command = Idle Time / 20 + 5;
> + */
> +u8 cyapa_sleep_time_to_pwr_cmd(u16 sleep_time)
> +{
> +	if (sleep_time < 20)
> +		sleep_time = 20;     /* minimal sleep time. */
> +	else if (sleep_time > 1000)
> +		sleep_time = 1000;   /* maximal sleep time. */

	clamp_val()

> +
> +	if (sleep_time < 100)
> +		return ((sleep_time / 10) << 2) & PWR_MODE_MASK;
> +	else
> +		return ((sleep_time / 20 + 5) << 2) & PWR_MODE_MASK;
> +}
> +
> +u16 cyapa_pwr_cmd_to_sleep_time(u8 pwr_mode)
> +{
> +	u8 encoded_time = pwr_mode >> 2;
> +
> +	return (encoded_time < 10) ? encoded_time * 10
> +				   : (encoded_time - 5) * 20;
> +}
> +
> +void cyapa_detect_async(void *data, async_cookie_t cookie)
> +{
> +	struct cyapa *cyapa = (struct cyapa *)data;
> +
> +	mutex_lock(&cyapa->state_sync_lock);
> +
> +	/* Keep synchronized with sys interface process threads. */
> +	cyapa_detect(cyapa);
> +
> +	mutex_unlock(&cyapa->state_sync_lock);
> +}
> +
> +static void cyapa_detect_and_start(void *data, async_cookie_t cookie)
> +{
> +	cyapa_detect_async(data, cookie);
> +}
> +
> +static int cyapa_tp_modules_init(struct cyapa *cyapa)
> +{
> +	return 0;
> +}
> +
> +static int cyapa_tp_modules_uninit(struct cyapa *cyapa)
> +{
> +	return 0;
> +}
> +
>  static int cyapa_probe(struct i2c_client *client,
>  		       const struct i2c_device_id *dev_id)
>  {
> @@ -830,6 +452,7 @@ static int cyapa_probe(struct i2c_client *client,
>  	u8 adapter_func;
>  	struct cyapa *cyapa;
>  	struct device *dev = &client->dev;
> +	union i2c_smbus_data dummy;
>  
>  	adapter_func = cyapa_check_adapter_functionality(client);
>  	if (adapter_func == CYAPA_ADAPTER_FUNC_NONE) {
> @@ -837,39 +460,43 @@ static int cyapa_probe(struct i2c_client *client,
>  		return -EIO;
>  	}
>  
> +	/* Make sure there is something at this address */
> +	if (dev->of_node && i2c_smbus_xfer(client->adapter, client->addr, 0,
> +			I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dummy) < 0)
> +		return -ENODEV;
> +
>  	cyapa = kzalloc(sizeof(struct cyapa), GFP_KERNEL);
>  	if (!cyapa) {
>  		dev_err(dev, "allocate memory for cyapa failed\n");
>  		return -ENOMEM;
>  	}
>  
> -	cyapa->gen = CYAPA_GEN3;
>  	cyapa->client = client;
>  	i2c_set_clientdata(client, cyapa);
>  	sprintf(cyapa->phys, "i2c-%d-%04x/input0", client->adapter->nr,
>  		client->addr);
>  
> -	/* i2c isn't supported, use smbus */
> -	if (adapter_func == CYAPA_ADAPTER_FUNC_SMBUS)
> -		cyapa->smbus = true;
> -	cyapa->state = CYAPA_STATE_NO_DEVICE;
> -	ret = cyapa_check_is_operational(cyapa);
> +	ret = cyapa_tp_modules_init(cyapa);
>  	if (ret) {
> -		dev_err(dev, "device not operational, %d\n", ret);
> -		goto err_mem_free;
> +		dev_err(dev, "initialize device modules failed.\n");
> +		goto err_unregister_device;
>  	}
>  
> -	ret = cyapa_create_input_dev(cyapa);
> -	if (ret) {
> -		dev_err(dev, "create input_dev instance failed, %d\n", ret);
> -		goto err_mem_free;
> -	}
> +	cyapa->gen = CYAPA_GEN_UNKNOWN;
> +	cyapa->ops = &cyapa_default_ops;
> +	mutex_init(&cyapa->state_sync_lock);
>  
> -	ret = cyapa_set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE);
> -	if (ret) {
> -		dev_err(dev, "set active power failed, %d\n", ret);
> -		goto err_unregister_device;
> -	}
> +	/* i2c isn't supported, use smbus */
> +	if (adapter_func == CYAPA_ADAPTER_FUNC_SMBUS)
> +		cyapa->smbus = true;
> +	cyapa->state = CYAPA_STATE_NO_DEVICE;
> +	/*
> +	 * Set to hard code default, they will be updated with trackpad set
> +	 * default values after probe and initialized.
> +	 */
> +	cyapa->suspend_power_mode = PWR_MODE_SLEEP;
> +	cyapa->suspend_sleep_time =
> +		cyapa_pwr_cmd_to_sleep_time(cyapa->suspend_power_mode);
>  
>  	cyapa->irq = client->irq;
>  	ret = request_threaded_irq(cyapa->irq,
> @@ -880,14 +507,17 @@ static int cyapa_probe(struct i2c_client *client,
>  				   cyapa);
>  	if (ret) {
>  		dev_err(dev, "IRQ request failed: %d\n, ", ret);
> -		goto err_unregister_device;
> +		goto err_uninit_tp_modules;
>  	}
>  
> +	async_schedule(cyapa_detect_and_start, cyapa);
>  	return 0;
>  
> +err_uninit_tp_modules:
> +	cyapa_tp_modules_uninit(cyapa);
>  err_unregister_device:
>  	input_unregister_device(cyapa->input);
> -err_mem_free:
> +	i2c_set_clientdata(client, NULL);
>  	kfree(cyapa);
>  
>  	return ret;
> @@ -898,8 +528,12 @@ static int cyapa_remove(struct i2c_client *client)
>  	struct cyapa *cyapa = i2c_get_clientdata(client);
>  

You schedule detect asynchronously so you need to make sure it is not running
(and will not be running) when you try to unbind the driver here.

Thanks.


-- 
Dmitry

^ permalink raw reply

* input: drv2667: add support for drv2667 haptic driver
From: Dan Murphy @ 2014-08-21 18:19 UTC (permalink / raw)
  To: linux-input, dmitry.torokhov; +Cc: linux-kernel, devicetree, linux-arm-kernel

Adding support for the TI DRV2667 haptic driver.
This device driver a linear resonant actuator (LRA)
based on user space requests to provide either a
vibration or a haptic tactile response to an input.

This device has the ability to store wave patterns in RAM
and these patterns can be executed based on user input.

For this initial series I added just the basic vibration
pattern along that will continuously execute until
the user indicates to stop.

[PATCH 1/2] doc: dt/bindings: input: introduce TI DRV2667 haptic
[PATCH 2/2] input: misc: Add support for the DRV2667 haptic driver

^ permalink raw reply

* [PATCH 2/2] input: misc: Add support for the DRV2667 haptic driver
From: Dan Murphy @ 2014-08-21 18:19 UTC (permalink / raw)
  To: linux-input, dmitry.torokhov
  Cc: linux-kernel, devicetree, linux-arm-kernel, Dan Murphy
In-Reply-To: <1408645143-25690-1-git-send-email-dmurphy@ti.com>

Adding support for the DRV2667 haptic driver.
This device has the ability to store vibration
patterns in RAM and execute them once the GO bit
is set.

The initial driver sets a basic waveform in the
first waveform sequence and will play the waveform
when the GO bit is set and will continously play
the waveform until the GO bit is unset.

Data sheet is here:
http://www.ti.com/product/drv2667

Signed-off-by: Dan Murphy <dmurphy@ti.com>
---
 drivers/input/misc/Kconfig   |   11 +
 drivers/input/misc/Makefile  |    1 +
 drivers/input/misc/drv2667.c |  500 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 512 insertions(+)
 create mode 100644 drivers/input/misc/drv2667.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 41d0ae6..51891f6 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -687,4 +687,15 @@ config INPUT_DRV260X_HAPTICS
 	  To compile this driver as a module, choose M here: the
 	  module will be called drv260x-haptics.
 
+config INPUT_DRV2667_HAPTICS
+	tristate "TI DRV2667 haptics support"
+	depends on INPUT && I2C
+	select INPUT_FF_MEMLESS
+	select REGMAP_I2C
+	help
+	  Say Y to enable support for the TI DRV2667 haptics driver.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called drv260x-haptics.
+
 endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index cd4bc2d..e0cee17 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_INPUT_DA9052_ONKEY)	+= da9052_onkey.o
 obj-$(CONFIG_INPUT_DA9055_ONKEY)	+= da9055_onkey.o
 obj-$(CONFIG_INPUT_DM355EVM)		+= dm355evm_keys.o
 obj-$(CONFIG_INPUT_DRV260X_HAPTICS)	+= drv260x.o
+obj-$(CONFIG_INPUT_DRV2667_HAPTICS)	+= drv2667.o
 obj-$(CONFIG_INPUT_GP2A)		+= gp2ap002a00f.o
 obj-$(CONFIG_INPUT_GPIO_BEEPER)		+= gpio-beeper.o
 obj-$(CONFIG_INPUT_GPIO_TILT_POLLED)	+= gpio_tilt_polled.o
diff --git a/drivers/input/misc/drv2667.c b/drivers/input/misc/drv2667.c
new file mode 100644
index 0000000..0f43758
--- /dev/null
+++ b/drivers/input/misc/drv2667.c
@@ -0,0 +1,500 @@
+/*
+ * DRV2667 haptics driver family
+ *
+ * Author: Dan Murphy <dmurphy@ti.com>
+ *
+ * Copyright: (C) 2014 Texas Instruments, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License 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.
+ */
+
+#include <linux/i2c.h>
+#include <linux/input.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/regulator/consumer.h>
+
+/* Contol registers */
+#define DRV2667_STATUS	0x00
+#define DRV2667_CTRL_1	0x01
+#define DRV2667_CTRL_2	0x02
+/* Waveform sequencer */
+#define DRV2667_WV_SEQ_0	0x03
+#define DRV2667_WV_SEQ_1	0x04
+#define DRV2667_WV_SEQ_2	0x05
+#define DRV2667_WV_SEQ_3	0x06
+#define DRV2667_WV_SEQ_4	0x07
+#define DRV2667_WV_SEQ_5	0x08
+#define DRV2667_WV_SEQ_6	0x09
+#define DRV2667_WV_SEQ_7	0x0A
+#define DRV2667_FIFO		0x0B
+#define DRV2667_PAGE		0xFF
+#define DRV2667_MAX_REG		DRV2667_PAGE
+
+#define DRV2667_PAGE_0		0x00
+#define DRV2667_PAGE_1		0x01
+#define DRV2667_PAGE_2		0x02
+#define DRV2667_PAGE_3		0x03
+#define DRV2667_PAGE_4		0x04
+#define DRV2667_PAGE_5		0x05
+#define DRV2667_PAGE_6		0x06
+#define DRV2667_PAGE_7		0x07
+#define DRV2667_PAGE_8		0x08
+
+/* RAM fields */
+#define DRV2667_RAM_HDR_SZ	0x0
+/* RAM Header addresses */
+#define DRV2667_RAM_START_HI	0x01
+#define DRV2667_RAM_START_LO	0x02
+#define DRV2667_RAM_STOP_HI		0x03
+#define DRV2667_RAM_STOP_LO		0x04
+#define DRV2667_RAM_REPEAT_CT	0x05
+/* RAM data addresses */
+#define DRV2667_RAM_AMP		0x06
+#define DRV2667_RAM_FREQ	0x07
+#define DRV2667_RAM_DURATION	0x08
+#define DRV2667_RAM_ENVELOPE	0x09
+
+/* Control 1 Register */
+#define DRV2667_25_VPP_GAIN		0x00
+#define DRV2667_50_VPP_GAIN		0x01
+#define DRV2667_75_VPP_GAIN		0x02
+#define DRV2667_100_VPP_GAIN	0x03
+#define DRV2667_DIGITAL_IN		0xfc
+#define DRV2667_ANALOG_IN		(1 << 2)
+
+/* Control 2 Register */
+#define DRV2667_GO			(1 << 0)
+#define DRV2667_STANDBY		(1 << 6)
+#define DRV2667_DEV_RST		(1 << 7)
+
+/* RAM Envelope settings */
+#define DRV2667_NO_ENV			0x00
+#define DRV2667_32_MS_ENV		0x01
+#define DRV2667_64_MS_ENV		0x02
+#define DRV2667_96_MS_ENV		0x03
+#define DRV2667_128_MS_ENV		0x04
+#define DRV2667_160_MS_ENV		0x05
+#define DRV2667_192_MS_ENV		0x06
+#define DRV2667_224_MS_ENV		0x07
+#define DRV2667_256_MS_ENV		0x08
+#define DRV2667_512_MS_ENV		0x09
+#define DRV2667_768_MS_ENV		0x0a
+#define DRV2667_1024_MS_ENV		0x0b
+#define DRV2667_1280_MS_ENV		0x0c
+#define DRV2667_1536_MS_ENV		0x0d
+#define DRV2667_1792_MS_ENV		0x0e
+#define DRV2667_2048_MS_ENV		0x0f
+
+/**
+ * struct drv2667_data -
+ * @input_dev - Pointer to the input device
+ * @client - Pointer to the I2C client
+ * @regmap - Register map of the device
+ * @work - Work item used to off load the enable/disable of the vibration
+ * @regulator - Pointer to the regulator for the IC
+ * @magnitude - Magnitude of the vibration event
+**/
+struct drv2667_data {
+	struct input_dev *input_dev;
+	struct i2c_client *client;
+	struct regmap *regmap;
+	struct work_struct work;
+	struct regulator *regulator;
+	u32 page;
+	u32 magnitude;
+	u32 frequency;
+};
+
+static struct reg_default drv2667_reg_defs[] = {
+	{ DRV2667_STATUS, 0x02 },
+	{ DRV2667_CTRL_1, 0x28 },
+	{ DRV2667_CTRL_2, 0x40 },
+	{ DRV2667_WV_SEQ_0, 0x00 },
+	{ DRV2667_WV_SEQ_1, 0x00 },
+	{ DRV2667_WV_SEQ_2, 0x00 },
+	{ DRV2667_WV_SEQ_3, 0x00 },
+	{ DRV2667_WV_SEQ_4, 0x00 },
+	{ DRV2667_WV_SEQ_5, 0x00 },
+	{ DRV2667_WV_SEQ_6, 0x00 },
+	{ DRV2667_WV_SEQ_7, 0x00 },
+	{ DRV2667_FIFO, 0x00 },
+	{ DRV2667_PAGE, 0x00 },
+};
+
+static int drv2667_set_waveform_freq(struct drv2667_data *haptics)
+{
+	unsigned int read_buf;
+	int freq;
+	int error;
+
+	/* Per the data sheet:
+	 * Sinusoid Frequency (Hz) = 7.8125 x Frequency
+	 */
+	freq = (haptics->frequency * 1000) / 78125;
+	if (freq <= 0) {
+		dev_err(&haptics->client->dev,
+			"ERROR: Frequency calculated to %i\n", freq);
+		return -EINVAL;
+	}
+
+	error = regmap_read(haptics->regmap, DRV2667_PAGE, &read_buf);
+	if (error) {
+		dev_err(&haptics->client->dev,
+			"Failed to read the page number: %d\n", error);
+		return -EIO;
+	}
+
+	if (read_buf == DRV2667_PAGE_0 ||
+		haptics->page != read_buf) {
+		error = regmap_write(haptics->regmap,
+				DRV2667_PAGE, haptics->page);
+		if (error) {
+			dev_err(&haptics->client->dev,
+				"Failed to set the page: %d\n", error);
+			return -EIO;
+		}
+	}
+
+	error = regmap_write(haptics->regmap, DRV2667_RAM_FREQ,	freq);
+	if (error)
+		dev_err(&haptics->client->dev,
+				"Failed to set the frequency: %d\n", error);
+
+	/* Reset back to original page */
+	if (read_buf == DRV2667_PAGE_0 ||
+		haptics->page != read_buf) {
+		error = regmap_write(haptics->regmap, DRV2667_PAGE, read_buf);
+		if (error) {
+			dev_err(&haptics->client->dev,
+					"Failed to set the page: %d\n", error);
+				return -EIO;
+			}
+	}
+
+	return error;
+}
+
+static void drv2667_worker(struct work_struct *work)
+{
+	struct drv2667_data *haptics = container_of(work, struct drv2667_data, work);
+	int error;
+
+	if (haptics->magnitude) {
+		error = regmap_write(haptics->regmap,
+				DRV2667_PAGE, haptics->page);
+		if (error) {
+			dev_err(&haptics->client->dev,
+				"Failed to set the page: %d\n", error);
+			return;
+		}
+
+		error = regmap_write(haptics->regmap, DRV2667_RAM_AMP,
+				haptics->magnitude);
+		if (error) {
+			dev_err(&haptics->client->dev,
+				"Failed to set the amplitude: %d\n", error);
+			return;
+		}
+
+		error = regmap_write(haptics->regmap,
+				DRV2667_PAGE, DRV2667_PAGE_0);
+		if (error) {
+			dev_err(&haptics->client->dev,
+				"Failed to set the page: %d\n", error);
+			return;
+		}
+
+		error = regmap_write(haptics->regmap,
+				DRV2667_CTRL_2, DRV2667_GO);
+		if (error) {
+			dev_err(&haptics->client->dev,
+				"Failed to set the GO bit: %d\n", error);
+		}
+	} else {
+		error = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2,
+				DRV2667_GO, 0);
+		if (error) {
+			dev_err(&haptics->client->dev,
+				"Failed to unset the GO bit: %d\n", error);
+		}
+	}
+}
+
+static int drv2667_haptics_play(struct input_dev *input, void *data,
+				struct ff_effect *effect)
+{
+	struct drv2667_data *haptics = input_get_drvdata(input);
+
+	if (effect->u.rumble.strong_magnitude > 0)
+		haptics->magnitude = effect->u.rumble.strong_magnitude;
+	else if (effect->u.rumble.weak_magnitude > 0)
+		haptics->magnitude = effect->u.rumble.weak_magnitude;
+	else
+		haptics->magnitude = 0;
+
+	schedule_work(&haptics->work);
+
+	return 0;
+}
+
+static void drv2667_close(struct input_dev *input)
+{
+	struct drv2667_data *haptics = input_get_drvdata(input);
+	int error;
+
+	cancel_work_sync(&haptics->work);
+
+	error = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2,
+				DRV2667_STANDBY, 1);
+	if (error)
+		dev_err(&haptics->client->dev,
+			"Failed to enter standby mode: %d\n", error);
+}
+
+static const struct reg_default drv2667_init_regs[] = {
+	{ DRV2667_CTRL_2, 0 },
+	{ DRV2667_CTRL_1, DRV2667_25_VPP_GAIN },
+	{ DRV2667_WV_SEQ_0, 1 },
+	{ DRV2667_WV_SEQ_1, 0 }
+};
+
+static const struct reg_default drv2667_page1_init[] = {
+	{ DRV2667_RAM_HDR_SZ, 0x05 },
+	{ DRV2667_RAM_START_HI, 0x80 },
+	{ DRV2667_RAM_START_LO, 0x06 },
+	{ DRV2667_RAM_STOP_HI, 0x00 },
+	{ DRV2667_RAM_STOP_LO, 0x09 },
+	{ DRV2667_RAM_REPEAT_CT, 0 },
+	{ DRV2667_RAM_DURATION, 0x05 },
+	{ DRV2667_RAM_ENVELOPE, DRV2667_NO_ENV },
+	{ DRV2667_RAM_AMP, 0x60 },
+};
+
+static int drv2667_init(struct drv2667_data *haptics)
+{
+	int error;
+
+	/* Set default haptic frequency to 195Hz on Page 1*/
+	haptics->frequency = 195;
+	haptics->page = DRV2667_PAGE_1;
+
+	error = regmap_register_patch(haptics->regmap,
+				      drv2667_init_regs,
+				      ARRAY_SIZE(drv2667_init_regs));
+	if (error) {
+		dev_err(&haptics->client->dev,
+			"Failed to write init registers: %d\n",
+			error);
+		return error;
+	}
+
+	error = regmap_write(haptics->regmap, DRV2667_PAGE, haptics->page);
+	if (error) {
+		dev_err(&haptics->client->dev, "Failed to set page: %d\n",
+			error);
+		goto error_out;
+	}
+
+	error = drv2667_set_waveform_freq(haptics);
+	if (error)
+		goto error_page;
+
+	error = regmap_register_patch(haptics->regmap,
+				      drv2667_page1_init,
+				      ARRAY_SIZE(drv2667_page1_init));
+	if (error) {
+		dev_err(&haptics->client->dev,
+			"Failed to write page registers: %d\n",
+			error);
+		return error;
+	}
+
+	error = regmap_write(haptics->regmap, DRV2667_PAGE, DRV2667_PAGE_0);
+	return error;
+
+error_page:
+	regmap_write(haptics->regmap, DRV2667_PAGE, DRV2667_PAGE_0);
+error_out:
+	return error;
+}
+
+static const struct regmap_config drv2667_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+
+	.max_register = DRV2667_MAX_REG,
+	.reg_defaults = drv2667_reg_defs,
+	.num_reg_defaults = ARRAY_SIZE(drv2667_reg_defs),
+	.cache_type = REGCACHE_NONE,
+};
+
+static int drv2667_probe(struct i2c_client *client,
+			 const struct i2c_device_id *id)
+{
+	struct drv2667_data *haptics;
+	int error;
+
+	haptics = devm_kzalloc(&client->dev, sizeof(*haptics), GFP_KERNEL);
+	if (!haptics)
+		return -ENOMEM;
+
+	haptics->regulator = devm_regulator_get(&client->dev, "vbat");
+	if (IS_ERR(haptics->regulator)) {
+		error = PTR_ERR(haptics->regulator);
+		dev_err(&client->dev,
+			"unable to get regulator, error: %d\n", error);
+		return error;
+	}
+
+	haptics->input_dev = devm_input_allocate_device(&client->dev);
+	if (!haptics->input_dev) {
+		dev_err(&client->dev, "Failed to allocate input device\n");
+		return -ENOMEM;
+	}
+
+	haptics->input_dev->name = "drv2667:haptics";
+	haptics->input_dev->dev.parent = client->dev.parent;
+	haptics->input_dev->close = drv2667_close;
+	input_set_drvdata(haptics->input_dev, haptics);
+	input_set_capability(haptics->input_dev, EV_FF, FF_RUMBLE);
+
+	error = input_ff_create_memless(haptics->input_dev, NULL,
+					drv2667_haptics_play);
+	if (error) {
+		dev_err(&client->dev, "input_ff_create() failed: %d\n",
+			error);
+		return error;
+	}
+
+	INIT_WORK(&haptics->work, drv2667_worker);
+
+	haptics->client = client;
+	i2c_set_clientdata(client, haptics);
+
+	haptics->regmap = devm_regmap_init_i2c(client, &drv2667_regmap_config);
+	if (IS_ERR(haptics->regmap)) {
+		error = PTR_ERR(haptics->regmap);
+		dev_err(&client->dev, "Failed to allocate register map: %d\n",
+			error);
+		return error;
+	}
+
+	error = drv2667_init(haptics);
+	if (error) {
+		dev_err(&client->dev, "Device init failed: %d\n", error);
+		return error;
+	}
+
+	error = input_register_device(haptics->input_dev);
+	if (error) {
+		dev_err(&client->dev, "couldn't register input device: %d\n",
+			error);
+		return error;
+	}
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int drv2667_suspend(struct device *dev)
+{
+	struct drv2667_data *haptics = dev_get_drvdata(dev);
+	int ret = 0;
+
+	mutex_lock(&haptics->input_dev->mutex);
+
+	if (haptics->input_dev->users) {
+		ret = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2,
+				DRV2667_STANDBY, 1);
+		if (ret) {
+			dev_err(dev, "Failed to set standby mode\n");
+			regulator_disable(haptics->regulator);
+			goto out;
+		}
+
+		ret = regulator_disable(haptics->regulator);
+		if (ret) {
+			dev_err(dev, "Failed to disable regulator\n");
+			regmap_update_bits(haptics->regmap,
+					   DRV2667_CTRL_2,
+					   DRV2667_STANDBY, 0);
+		}
+	}
+out:
+	mutex_unlock(&haptics->input_dev->mutex);
+	return ret;
+}
+
+static int drv2667_resume(struct device *dev)
+{
+	struct drv2667_data *haptics = dev_get_drvdata(dev);
+	int ret = 0;
+
+	mutex_lock(&haptics->input_dev->mutex);
+
+	if (haptics->input_dev->users) {
+		ret = regulator_enable(haptics->regulator);
+		if (ret) {
+			dev_err(dev, "Failed to enable regulator\n");
+			goto out;
+		}
+
+		ret = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2,
+					 DRV2667_STANDBY, 0);
+		if (ret) {
+			dev_err(dev, "Failed to unset standby mode\n");
+			regulator_disable(haptics->regulator);
+			goto out;
+		}
+
+	}
+
+out:
+	mutex_unlock(&haptics->input_dev->mutex);
+	return ret;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(drv2667_pm_ops, drv2667_suspend, drv2667_resume);
+
+static const struct i2c_device_id drv2667_id[] = {
+	{ "drv2667", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, drv2667_id);
+
+#ifdef CONFIG_OF
+static const struct of_device_id drv2667_of_match[] = {
+	{ .compatible = "ti,drv2667", },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, drv2667_of_match);
+#endif
+
+static struct i2c_driver drv2667_driver = {
+	.probe		= drv2667_probe,
+	.driver		= {
+		.name	= "drv2667-haptics",
+		.owner	= THIS_MODULE,
+		.of_match_table = of_match_ptr(drv2667_of_match),
+		.pm	= &drv2667_pm_ops,
+	},
+	.id_table = drv2667_id,
+};
+module_i2c_driver(drv2667_driver);
+
+MODULE_ALIAS("platform:drv2667-haptics");
+MODULE_DESCRIPTION("TI DRV2667 haptics driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Dan Murphy <dmurphy@ti.com>");
-- 
1.7.9.5

^ permalink raw reply related

* [PATCH 1/2] doc: dt/bindings: input: introduce TI DRV2667 haptic driver description
From: Dan Murphy @ 2014-08-21 18:19 UTC (permalink / raw)
  To: linux-input, dmitry.torokhov
  Cc: linux-kernel, devicetree, linux-arm-kernel, Dan Murphy
In-Reply-To: <1408645143-25690-1-git-send-email-dmurphy@ti.com>

DRV2667 is a haptic/vibrator driver for Linear Resonant Actuators.
Adding dt binding for this part

Signed-off-by: Dan Murphy <dmurphy@ti.com>
---
 .../devicetree/bindings/input/ti,drv2667.txt       |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/ti,drv2667.txt

diff --git a/Documentation/devicetree/bindings/input/ti,drv2667.txt b/Documentation/devicetree/bindings/input/ti,drv2667.txt
new file mode 100644
index 0000000..525216d
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/ti,drv2667.txt
@@ -0,0 +1,18 @@
+Texas Instruments - drv2667 Haptics driver
+
+The drv2667 uses serial control bus communicates through I2C protocols
+
+Required properties:
+	- compatible - "ti,drv2667" - DRV2667
+	- reg -  I2C slave address
+	- vbat-supply - Required supply regulator
+
+Example:
+
+drv2667: drv2667@59 {
+		compatible = "ti,drv2667";
+		reg = <0x59>;
+};
+
+For more product information please see the link below:
+http://www.ti.com/product/drv2667
-- 
1.7.9.5

^ permalink raw reply related

* Re: [PATCH RESEND v4 0/2] Input: Support in the elantech driver of the trackpoint present on for instance Lenovo L530
From: Dmitry Torokhov @ 2014-08-21 18:04 UTC (permalink / raw)
  To: Ulrik De Bie; +Cc: linux-input, Hans de Goede, David Herrmann
In-Reply-To: <1408558692-11736-1-git-send-email-ulrik.debie-os@e2big.org>

Hi Ulrik,
On Wed, Aug 20, 2014 at 08:18:10PM +0200, Ulrik De Bie wrote:
> Hi Dmitry,
> 
> I posted these 2 months ago, but haven't seen any comments from you.
> Could you please review these ?

I will try to go over them by the end of this week, if you do not hear from me
please do not hesitate to ping me again.

Thanks.

-- 
Dmitry

^ permalink raw reply

* Re: [PATCH V2 2/2] Input: misc: introduce palmas-pwrbutton
From: Dmitry Torokhov @ 2014-08-21 18:03 UTC (permalink / raw)
  To: Nishanth Menon
  Cc: Murphy, Dan, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
In-Reply-To: <20140821173715.GA23419@kahuna>

On Thu, Aug 21, 2014 at 12:37:15PM -0500, Nishanth Menon wrote:
> On 12:32-20140821, Murphy, Dan wrote:
> > On 08/21/2014 12:19 PM, Menon, Nishanth wrote:
> > > On 08/21/2014 11:59 AM, Murphy, Dan wrote:
> > > [...]
> > > Ooops.. missed answering one addition statement:
> > > 
> > >>> +	of_property_read_u32(np, "ti,palmas-long-press-seconds", &val);
> > >>
> > >> Probably should check the return to make sure the value exists and that is is
> > >> within an expected range.
> > > It is an optional parameter and may not exist in dt. when it does
> > > exist, the logic tries to do a best match (this is the for loop in the
> > > logic just below).
> > > 
> > 
> > The issue is val might be returned as a negative which will then proceed to
> > set the config->long_press_time_val to the lowest time value which then overrides
> > your initial setting of config->long_press_time_val = ARRAY_SIZE(lpk_times) - 1;
> > 
> 
> Does the following as a replacement look OK? if yes, I can incorporate
> as part of v3 of this series.
> /**
>  * palmas_pwron_params_ofinit() - device tree parameter parser
>  * @dev:	palmas button device
>  * @config:	configuration params that this fills up
>  */
> static void palmas_pwron_params_ofinit(struct device *dev,
> 				       struct palmas_pwron_config *config)
> {
> 	struct device_node *np;
> 	u32 val;
> 	int i, ret;
> 	u8 lpk_times[] = { 6, 8, 10, 12 };
> 	int pwr_on_deb_ms[] = { 15, 100, 500, 1000 };
> 
> 	/* Handle cases where device node based configuration is not present */
> 	if (!of_have_populated_dt())
> 		return;
> 	np = of_node_get(dev->of_node);
> 	if (!np)
> 		return;
> 
> 	/* Default config parameters - least debounce, max long key press */
> 	config->pwron_debounce_val = 0;
> 	config->long_press_time_val = ARRAY_SIZE(lpk_times) - 1;
> 
> 	ret = of_property_read_u32(np, "ti,palmas-long-press-seconds", &val);
> 	if (ret)
> 		goto skip_lpk;

Just without gotos please. They are nice in error handling paths and in some
other rare circumstances, but not here.

> 	for (i = 0; i < ARRAY_SIZE(lpk_times); i++) {
> 		if (val <= lpk_times[i]) {
> 			config->long_press_time_val = i;
> 			break;
> 		}
> 	}
> 
> skip_lpk:
> 	ret = of_property_read_u32(np, "ti,palmas-pwron-debounce-milli-seconds",
> 				   &val);
> 	if (ret)
> 		goto skip_debounce;
> 	for (i = 0; i < ARRAY_SIZE(pwr_on_deb_ms); i++) {
> 		if (val <= pwr_on_deb_ms[i]) {
> 			config->pwron_debounce_val = i;
> 			break;
> 		}
> 	}
> 
> skip_debounce:
> 	dev_info(dev, "h/w controlled shutdown duration=%d seconds\n",
> 		 lpk_times[config->long_press_time_val]);
> 
> 	of_node_put(np);

BTW, I do not think you need to use of_node_get/put here, it's not going anywhere.

Thanks.

-- 
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply

* Re: [PATCH V2 2/2] Input: misc: introduce palmas-pwrbutton
From: Murphy, Dan @ 2014-08-21 17:46 UTC (permalink / raw)
  To: Menon, Nishanth
  Cc: Dmitry Torokhov, Dmitry Torokhov, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
	linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org
In-Reply-To: <20140821173715.GA23419@kahuna>

On 08/21/2014 12:37 PM, Menon, Nishanth wrote:
> On 12:32-20140821, Murphy, Dan wrote:
>> On 08/21/2014 12:19 PM, Menon, Nishanth wrote:
>>> On 08/21/2014 11:59 AM, Murphy, Dan wrote:
>>> [...]
>>> Ooops.. missed answering one addition statement:
>>>
>>>>> +	of_property_read_u32(np, "ti,palmas-long-press-seconds", &val);
>>>>
>>>> Probably should check the return to make sure the value exists and that is is
>>>> within an expected range.
>>> It is an optional parameter and may not exist in dt. when it does
>>> exist, the logic tries to do a best match (this is the for loop in the
>>> logic just below).
>>>
>>
>> The issue is val might be returned as a negative which will then proceed to
>> set the config->long_press_time_val to the lowest time value which then overrides
>> your initial setting of config->long_press_time_val = ARRAY_SIZE(lpk_times) - 1;
>>
> 
> Does the following as a replacement look OK? if yes, I can incorporate
> as part of v3 of this series.
> /**
>  * palmas_pwron_params_ofinit() - device tree parameter parser
>  * @dev:	palmas button device
>  * @config:	configuration params that this fills up
>  */
> static void palmas_pwron_params_ofinit(struct device *dev,
> 				       struct palmas_pwron_config *config)
> {
> 	struct device_node *np;
> 	u32 val;
> 	int i, ret;
> 	u8 lpk_times[] = { 6, 8, 10, 12 };
> 	int pwr_on_deb_ms[] = { 15, 100, 500, 1000 };
> 
> 	/* Handle cases where device node based configuration is not present */
> 	if (!of_have_populated_dt())
> 		return;
> 	np = of_node_get(dev->of_node);
> 	if (!np)
> 		return;
> 
> 	/* Default config parameters - least debounce, max long key press */
> 	config->pwron_debounce_val = 0;

And you can drop this as this value is set to zero in the probe when initialized.

> 	config->long_press_time_val = ARRAY_SIZE(lpk_times) - 1;

I would move this up to just before checking the dt.  Then they are defaulted
properly or move these to the probe.  Otherwise defaults are not set.

> 
> 	ret = of_property_read_u32(np, "ti,palmas-long-press-seconds", &val);
> 	if (ret)
> 		goto skip_lpk;
> 	for (i = 0; i < ARRAY_SIZE(lpk_times); i++) {
> 		if (val <= lpk_times[i]) {
> 			config->long_press_time_val = i;
> 			break;
> 		}
> 	}
> 
> skip_lpk:
> 	ret = of_property_read_u32(np, "ti,palmas-pwron-debounce-milli-seconds",
> 				   &val);
> 	if (ret)
> 		goto skip_debounce;
> 	for (i = 0; i < ARRAY_SIZE(pwr_on_deb_ms); i++) {
> 		if (val <= pwr_on_deb_ms[i]) {
> 			config->pwron_debounce_val = i;
> 			break;
> 		}
> 	}
> 
> skip_debounce:
> 	dev_info(dev, "h/w controlled shutdown duration=%d seconds\n",
> 		 lpk_times[config->long_press_time_val]);
> 
> 	of_node_put(np);
> }
> 


-- 
------------------
Dan Murphy

^ permalink raw reply

* Re: [PATCH V2 2/2] Input: misc: introduce palmas-pwrbutton
From: Nishanth Menon @ 2014-08-21 17:37 UTC (permalink / raw)
  To: Murphy, Dan
  Cc: Dmitry Torokhov, Dmitry Torokhov,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
In-Reply-To: <00FC9A978A94B7418C33AFAE8A35ED49DF07A2-l8PMxShYob2IQmiDNMet8wC/G2K4zDHf@public.gmane.org>

On 12:32-20140821, Murphy, Dan wrote:
> On 08/21/2014 12:19 PM, Menon, Nishanth wrote:
> > On 08/21/2014 11:59 AM, Murphy, Dan wrote:
> > [...]
> > Ooops.. missed answering one addition statement:
> > 
> >>> +	of_property_read_u32(np, "ti,palmas-long-press-seconds", &val);
> >>
> >> Probably should check the return to make sure the value exists and that is is
> >> within an expected range.
> > It is an optional parameter and may not exist in dt. when it does
> > exist, the logic tries to do a best match (this is the for loop in the
> > logic just below).
> > 
> 
> The issue is val might be returned as a negative which will then proceed to
> set the config->long_press_time_val to the lowest time value which then overrides
> your initial setting of config->long_press_time_val = ARRAY_SIZE(lpk_times) - 1;
> 

Does the following as a replacement look OK? if yes, I can incorporate
as part of v3 of this series.
/**
 * palmas_pwron_params_ofinit() - device tree parameter parser
 * @dev:	palmas button device
 * @config:	configuration params that this fills up
 */
static void palmas_pwron_params_ofinit(struct device *dev,
				       struct palmas_pwron_config *config)
{
	struct device_node *np;
	u32 val;
	int i, ret;
	u8 lpk_times[] = { 6, 8, 10, 12 };
	int pwr_on_deb_ms[] = { 15, 100, 500, 1000 };

	/* Handle cases where device node based configuration is not present */
	if (!of_have_populated_dt())
		return;
	np = of_node_get(dev->of_node);
	if (!np)
		return;

	/* Default config parameters - least debounce, max long key press */
	config->pwron_debounce_val = 0;
	config->long_press_time_val = ARRAY_SIZE(lpk_times) - 1;

	ret = of_property_read_u32(np, "ti,palmas-long-press-seconds", &val);
	if (ret)
		goto skip_lpk;
	for (i = 0; i < ARRAY_SIZE(lpk_times); i++) {
		if (val <= lpk_times[i]) {
			config->long_press_time_val = i;
			break;
		}
	}

skip_lpk:
	ret = of_property_read_u32(np, "ti,palmas-pwron-debounce-milli-seconds",
				   &val);
	if (ret)
		goto skip_debounce;
	for (i = 0; i < ARRAY_SIZE(pwr_on_deb_ms); i++) {
		if (val <= pwr_on_deb_ms[i]) {
			config->pwron_debounce_val = i;
			break;
		}
	}

skip_debounce:
	dev_info(dev, "h/w controlled shutdown duration=%d seconds\n",
		 lpk_times[config->long_press_time_val]);

	of_node_put(np);
}
-- 
Regards,
Nishanth Menon
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply

* Re: [PATCH V2 2/2] Input: misc: introduce palmas-pwrbutton
From: Murphy, Dan @ 2014-08-21 17:32 UTC (permalink / raw)
  To: Menon, Nishanth, Dmitry Torokhov, Dmitry Torokhov
  Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-input@vger.kernel.org, linux-omap@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
In-Reply-To: <53F62A2B.6010208@ti.com>

On 08/21/2014 12:19 PM, Menon, Nishanth wrote:
> On 08/21/2014 11:59 AM, Murphy, Dan wrote:
> [...]
> Ooops.. missed answering one addition statement:
> 
>>> +	of_property_read_u32(np, "ti,palmas-long-press-seconds", &val);
>>
>> Probably should check the return to make sure the value exists and that is is
>> within an expected range.
> It is an optional parameter and may not exist in dt. when it does
> exist, the logic tries to do a best match (this is the for loop in the
> logic just below).
> 

The issue is val might be returned as a negative which will then proceed to
set the config->long_press_time_val to the lowest time value which then overrides
your initial setting of config->long_press_time_val = ARRAY_SIZE(lpk_times) - 1;

Dan

-- 
------------------
Dan Murphy

^ permalink raw reply

* Re: [PATCH V2 2/2] Input: misc: introduce palmas-pwrbutton
From: Nishanth Menon @ 2014-08-21 17:19 UTC (permalink / raw)
  To: Murphy, Dan, Dmitry Torokhov, Dmitry Torokhov
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
In-Reply-To: <00FC9A978A94B7418C33AFAE8A35ED49DF0662-l8PMxShYob2IQmiDNMet8wC/G2K4zDHf@public.gmane.org>

On 08/21/2014 11:59 AM, Murphy, Dan wrote:
[...]
Ooops.. missed answering one addition statement:

>> +	of_property_read_u32(np, "ti,palmas-long-press-seconds", &val);
> 
> Probably should check the return to make sure the value exists and that is is
> within an expected range.
It is an optional parameter and may not exist in dt. when it does
exist, the logic tries to do a best match (this is the for loop in the
logic just below).

-- 
Regards,
Nishanth Menon
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply

* Re: [PATCH V2 2/2] Input: misc: introduce palmas-pwrbutton
From: Nishanth Menon @ 2014-08-21 17:12 UTC (permalink / raw)
  To: Murphy, Dan, Dmitry Torokhov, Dmitry Torokhov
  Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-input@vger.kernel.org, linux-omap@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
In-Reply-To: <00FC9A978A94B7418C33AFAE8A35ED49DF0662@DFLE09.ent.ti.com>

On 08/21/2014 11:59 AM, Murphy, Dan wrote:
Thanks for the review.
[..]
>> +#include <linux/init.h>
>> +#include <linux/input.h>
>> +#include <linux/interrupt.h>
>> +#include <linux/kernel.h>
>> +#include <linux/mfd/palmas.h>
>> +#include <linux/module.h>
>> +#include <linux/of.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/reboot.h>
> 
> I don't see any reboot calls made do we need this?

Arrgh.. yes. will drop.

[..]

>> +/**
>> + * palmas_pwron_params_ofinit() - device tree parameter parser
>> + * @dev:	palmas button device
>> + * @config:	configuration params that this fills up
>> + */
>> +static void palmas_pwron_params_ofinit(struct device *dev,
>> +				       struct palmas_pwron_config *config)
> 
> Maybe we should change this to return an int so that if the DT is not populated
> then the LPK and debounce is not set but we continue anyway.

Why? these are optional properties, the defaults are 12 seconds for
LPK and 15 ms for debounce. there is no reason for it to return an
error value at this point.

> 
> Is there support for platform data itself?

No platform data support. The driver can function without these
properties - these are not mandatory.

>> +{
>> +	struct device_node *np;
>> +	u32 val;
>> +	int i;
>> +	u8 lpk_times[] = { 6, 8, 10, 12 };
>> +	int pwr_on_deb_ms[] = { 15, 100, 500, 1000 };
>> +
>> +	/* Legacy boot? */
>> +	if (!of_have_populated_dt())
>> +		return;
>> +
>> +	np = of_node_get(dev->of_node);
>> +	/* Mixed boot? */
> 
> Can we expand a little on Mixed boot vs legacy boot?

Are you looking for "device tree + platform boot" ? legacy boot being
"non device tree boot"?
>> +
>> +	val = 0;
> 
> Is this necessary?
> 
>> +	of_property_read_u32(np, "ti,palmas-long-press-seconds", &val);
> 
> Probably should check the return to make sure the value exists and that is is
> within an expected range.  Since this is an optional parameter it may not be
> populated.  And below it sets a preliminary value to the max as the default.
> 
> Maybe the default setting should be set at the beginning of this function so
> that if there is no dt data then at least the values will be defaulted.
> 
>> +	config->long_press_time_val = ARRAY_SIZE(lpk_times) - 1;
>> +	for (i = 0; i < ARRAY_SIZE(lpk_times); i++) {
>> +		if (val <= lpk_times[i]) {
>> +			config->long_press_time_val = i;
>> +			break;
>> +		}
>> +	}
>> +
>> +	val = 0;
> 
> Don't think we need this either if we check the return on the call
> below.

k, I can redo the sequence a little better here.

> 
>> +	of_property_read_u32(np, "ti,palmas-pwron-debounce-milli-seconds",
>> +			     &val);
> 
> 
> Probably should check the return to make sure the value exists and that is is
> within an expected range.

Not necessary.
> 
>> +	config->pwron_debounce_val = 0;
> 
> Should this not have been 0 anyway?

it is, was explicit in this case.
> 
>> +	for (i = 0; i < ARRAY_SIZE(pwr_on_deb_ms); i++) {
>> +		if (val <= pwr_on_deb_ms[i]) {
>> +			config->pwron_debounce_val = i;
>> +			break;
>> +		}
>> +	}
>> +
>> +	dev_info(dev, "h/w controlled shutdown duration=%d seconds\n",
>> +		 lpk_times[config->long_press_time_val]);
>> +
>> +	of_node_put(np);
>> +}
>> +
[...]

-- 
Regards,
Nishanth Menon

^ permalink raw reply

* Re: [PATCH V2 2/2] Input: misc: introduce palmas-pwrbutton
From: Nishanth Menon @ 2014-08-21 17:09 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: dt list, linux-omap, lkml, linux-arm-kernel@lists.infradead.org,
	linux-input
In-Reply-To: <20140821170512.GA3796@core.coreip.homeip.net>

On Thu, Aug 21, 2014 at 12:05 PM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
>
> You can not use free_irq with devm-managed resources. As I mentioned, since you
> need manual unwinding, I'd rather you not use managed resources in the driver
> at all.
ok. will drop all devm_  ops in the next version.

---
Regards,
Nishanth Menon

^ permalink raw reply

* Re: [PATCH V2 2/2] Input: misc: introduce palmas-pwrbutton
From: Dmitry Torokhov @ 2014-08-21 17:05 UTC (permalink / raw)
  To: Nishanth Menon
  Cc: devicetree, linux-kernel, linux-input, linux-omap,
	linux-arm-kernel
In-Reply-To: <1408636935-29515-3-git-send-email-nm@ti.com>

Hi Nishanth,

On Thu, Aug 21, 2014 at 11:02:15AM -0500, Nishanth Menon wrote:
> +
> +	ret = input_register_device(input_dev);
> +	if (ret) {
> +		free_irq(irq, pwron);

You can not use free_irq with devm-managed resources. As I mentioned, since you
need manual unwinding, I'd rather you not use managed resources in the driver
at all.

> +		cancel_delayed_work_sync(&pwron->input_work);
> +		dev_dbg(dev, "Can't register power button: %d\n", ret);
> +		return ret;

Thanks.

-- 
Dmitry

^ permalink raw reply

* Re: [PATCH V2 2/2] Input: misc: introduce palmas-pwrbutton
From: Murphy, Dan @ 2014-08-21 16:59 UTC (permalink / raw)
  To: Menon, Nishanth, Dmitry Torokhov, Dmitry Torokhov
  Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-input@vger.kernel.org, linux-omap@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
In-Reply-To: <1408636935-29515-3-git-send-email-nm@ti.com>

On 08/21/2014 11:04 AM, Menon, Nishanth wrote:
> Many palmas family of PMICs have support for interrupt based power
> button. This allows the device to notify the processor of external
> push button events over the shared palmas interrupt. However, this
> event is generated only during a "press" operation. Software is
> supposed to poll(sigh!) for detecting a release event.
> 
> The PMIC also supports ability to power off independent of the
> software decisions when the button is pressed for a long duration if
> the PMIC is appropriately configured on the platform.
> 
> Even though the function is similar to twl4030_pwrbutton, it is
> substantially different in operation to belong to a new driver of it's
> own.
> 
> Based on original work done by Girish S Ghongdemath <girishsg@ti.com>
> 
> Signed-off-by: Nishanth Menon <nm@ti.com>
> ---
> Changes in v2:
>  - review comments incorporated
>  - debounce programming for TWL variants that actually support it.
> V1: https://patchwork.kernel.org/patch/4739041/
> 
>  drivers/input/misc/Kconfig            |   10 +
>  drivers/input/misc/Makefile           |    1 +
>  drivers/input/misc/palmas-pwrbutton.c |  356 +++++++++++++++++++++++++++++++++
>  3 files changed, 367 insertions(+)
>  create mode 100644 drivers/input/misc/palmas-pwrbutton.c
> 
> diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
> index 2ff4425..0224dcf 100644
> --- a/drivers/input/misc/Kconfig
> +++ b/drivers/input/misc/Kconfig
> @@ -451,6 +451,16 @@ config HP_SDC_RTC
>  	  Say Y here if you want to support the built-in real time clock
>  	  of the HP SDC controller.
>  
> +config INPUT_PALMAS_PWRBUTTON
> +	tristate "Palmas Power button Driver"
> +	depends on MFD_PALMAS
> +	help
> +	  Say Y here if you want to enable power key reporting via the
> +	  Palmas family of PMICs.
> +
> +	  To compile this driver as a module, choose M here. The module will
> +	  be called palmas_pwrbutton.
> +
>  config INPUT_PCF50633_PMU
>  	tristate "PCF50633 PMU events"
>  	depends on MFD_PCF50633
> diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
> index 4955ad3..e3d5efb 100644
> --- a/drivers/input/misc/Makefile
> +++ b/drivers/input/misc/Makefile
> @@ -40,6 +40,7 @@ obj-$(CONFIG_INPUT_MAX8997_HAPTIC)	+= max8997_haptic.o
>  obj-$(CONFIG_INPUT_MC13783_PWRBUTTON)	+= mc13783-pwrbutton.o
>  obj-$(CONFIG_INPUT_MMA8450)		+= mma8450.o
>  obj-$(CONFIG_INPUT_MPU3050)		+= mpu3050.o
> +obj-$(CONFIG_INPUT_PALMAS_PWRBUTTON)	+= palmas-pwrbutton.o
>  obj-$(CONFIG_INPUT_PCAP)		+= pcap_keys.o
>  obj-$(CONFIG_INPUT_PCF50633_PMU)	+= pcf50633-input.o
>  obj-$(CONFIG_INPUT_PCF8574)		+= pcf8574_keypad.o
> diff --git a/drivers/input/misc/palmas-pwrbutton.c b/drivers/input/misc/palmas-pwrbutton.c
> new file mode 100644
> index 0000000..fb8bfc5
> --- /dev/null
> +++ b/drivers/input/misc/palmas-pwrbutton.c
> @@ -0,0 +1,356 @@
> +/*
> + * Texas Instruments' Palmas Power Button Input Driver
> + *
> + * Copyright (C) 2012-2014 Texas Instruments Incorporated - http://www.ti.com/
> + *	Girish S Ghongdemath
> + *	Nishanth Menon
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
> + * kind, whether express or implied; without even the implied warranty
> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +#include <linux/init.h>
> +#include <linux/input.h>
> +#include <linux/interrupt.h>
> +#include <linux/kernel.h>
> +#include <linux/mfd/palmas.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/reboot.h>

I don't see any reboot calls made do we need this?

> +#include <linux/slab.h>
> +
> +#define PALMAS_LPK_TIME_MASK		0x0c
> +#define PALMAS_PWRON_DEBOUNCE_MASK	0x03
> +#define PALMAS_PWR_KEY_PRESS		0x01
> +#define PALMAS_PWR_KEY_Q_TIME_MS	20
> +
> +/**
> + * struct palmas_pwron - Palmas power on data
> + * @palmas:		pointer to palmas device
> + * @input_dev:		pointer to input device
> + * @irq:		irq that we are hooked on to
> + * @input_work:		work for detecting release of key
> + * @current_state:	key current state
> + * @key_recheck_ms:	duration for recheck of key (in milli-seconds)
> + */
> +struct palmas_pwron {
> +	struct palmas *palmas;
> +	struct input_dev *input_dev;
> +	int irq;
> +	struct delayed_work input_work;
> +	int current_state;
> +	u32 key_recheck_ms;
> +};
> +
> +/**
> + * struct palmas_pwron_config - configuration of palmas power on
> + * @long_press_time_val:	value for long press h/w shutdown event
> + * @pwron_debounce_val:		value for debounce of power button
> + */
> +struct palmas_pwron_config {
> +	u8 long_press_time_val;
> +	u8 pwron_debounce_val;
> +};
> +
> +/**
> + * palmas_get_pwr_state() - read button state
> + * @pwron: pointer to pwron struct
> + *
> + * Return: 0 for no press, PALMAS_PWR_KEY_PRESS for keypress
> + * and on error, appropriate error value.
> + */
> +static int palmas_get_pwr_state(struct palmas_pwron *pwron)
> +{
> +	struct input_dev *input_dev = pwron->input_dev;
> +	struct device *dev = input_dev->dev.parent;
> +	unsigned int reg = 0;
> +	int ret;
> +
> +	ret = palmas_read(pwron->palmas, PALMAS_INTERRUPT_BASE,
> +			  PALMAS_INT1_LINE_STATE, &reg);
> +	if (ret) {
> +		dev_err(dev, "%s:Cannot read palmas PWRON status(%d)\n",
> +			__func__, ret);
> +		return ret;
> +	}
> +
> +	/* PWRON line state is BIT(1) of the register */
> +	return reg & BIT(1) ? 0 : PALMAS_PWR_KEY_PRESS;
> +}
> +
> +/**
> + * palmas_power_button_work() - Detects the button release event
> + * @work:	work item to detect button release
> + */
> +static void palmas_power_button_work(struct work_struct *work)
> +{
> +	struct palmas_pwron *pwron = container_of((struct delayed_work *)work,
> +						  struct palmas_pwron,
> +						  input_work);
> +	struct input_dev *input_dev = pwron->input_dev;
> +	int next_state;
> +
> +	next_state = palmas_get_pwr_state(pwron);
> +	if (next_state < 0)
> +		return;
> +
> +	/*
> +	 * If the state did not change then schedule a work item to check the
> +	 * status of the power button line
> +	 */
> +	if (next_state == pwron->current_state) {
> +		schedule_delayed_work(&pwron->input_work,
> +				      msecs_to_jiffies(pwron->key_recheck_ms));
> +		return;
> +	}
> +
> +	pwron->current_state = next_state;
> +	input_report_key(input_dev, KEY_POWER, pwron->current_state);
> +	input_sync(input_dev);
> +}
> +
> +/**
> + * pwron_irq() - button press isr
> + * @irq:		irq
> + * @palmas_pwron:	pwron struct
> + *
> + * Return: IRQ_HANDLED
> + */
> +static irqreturn_t pwron_irq(int irq, void *palmas_pwron)
> +{
> +	struct palmas_pwron *pwron = palmas_pwron;
> +	struct input_dev *input_dev = pwron->input_dev;
> +
> +	pwron->current_state = PALMAS_PWR_KEY_PRESS;
> +
> +	input_report_key(input_dev, KEY_POWER, pwron->current_state);
> +	pm_wakeup_event(input_dev->dev.parent, 0);
> +	input_sync(input_dev);
> +
> +	mod_delayed_work(system_wq, &pwron->input_work,
> +			 msecs_to_jiffies(pwron->key_recheck_ms));
> +
> +	return IRQ_HANDLED;
> +}
> +
> +/**
> + * palmas_pwron_params_ofinit() - device tree parameter parser
> + * @dev:	palmas button device
> + * @config:	configuration params that this fills up
> + */
> +static void palmas_pwron_params_ofinit(struct device *dev,
> +				       struct palmas_pwron_config *config)

Maybe we should change this to return an int so that if the DT is not populated
then the LPK and debounce is not set but we continue anyway.

Is there support for platform data itself?

> +{
> +	struct device_node *np;
> +	u32 val;
> +	int i;
> +	u8 lpk_times[] = { 6, 8, 10, 12 };
> +	int pwr_on_deb_ms[] = { 15, 100, 500, 1000 };
> +
> +	/* Legacy boot? */
> +	if (!of_have_populated_dt())
> +		return;
> +
> +	np = of_node_get(dev->of_node);
> +	/* Mixed boot? */

Can we expand a little on Mixed boot vs legacy boot?

> +	if (!np)
> +		return;
> +
> +	val = 0;

Is this necessary?

> +	of_property_read_u32(np, "ti,palmas-long-press-seconds", &val);

Probably should check the return to make sure the value exists and that is is
within an expected range.  Since this is an optional parameter it may not be
populated.  And below it sets a preliminary value to the max as the default.

Maybe the default setting should be set at the beginning of this function so
that if there is no dt data then at least the values will be defaulted.

> +	config->long_press_time_val = ARRAY_SIZE(lpk_times) - 1;
> +	for (i = 0; i < ARRAY_SIZE(lpk_times); i++) {
> +		if (val <= lpk_times[i]) {
> +			config->long_press_time_val = i;
> +			break;
> +		}
> +	}
> +
> +	val = 0;

Don't think we need this either if we check the return on the call
below.

> +	of_property_read_u32(np, "ti,palmas-pwron-debounce-milli-seconds",
> +			     &val);


Probably should check the return to make sure the value exists and that is is
within an expected range.

> +	config->pwron_debounce_val = 0;

Should this not have been 0 anyway?

> +	for (i = 0; i < ARRAY_SIZE(pwr_on_deb_ms); i++) {
> +		if (val <= pwr_on_deb_ms[i]) {
> +			config->pwron_debounce_val = i;
> +			break;
> +		}
> +	}
> +
> +	dev_info(dev, "h/w controlled shutdown duration=%d seconds\n",
> +		 lpk_times[config->long_press_time_val]);
> +
> +	of_node_put(np);
> +}
> +
> +/**
> + * palmas_pwron_probe() - probe
> + * @pdev:	platform device for the button
> + *
> + * Return: 0 for successful probe else appropriate error
> + */
> +static int palmas_pwron_probe(struct platform_device *pdev)
> +{
> +	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
> +	struct device *dev = &pdev->dev;
> +	struct input_dev *input_dev;
> +	struct palmas_pwron *pwron;
> +	int irq, ret, val;
> +	struct palmas_pwron_config config = { 0 };
> +
> +	palmas_pwron_params_ofinit(dev, &config);
> +
> +	pwron = devm_kzalloc(dev, sizeof(*pwron), GFP_KERNEL);
> +	if (!pwron)
> +		return -ENOMEM;
> +
> +	input_dev = devm_input_allocate_device(dev);
> +	if (!input_dev) {
> +		dev_err(dev, "Can't allocate power button\n");
> +		return -ENOMEM;
> +	}
> +
> +	/*
> +	 * Setup default hardware shutdown option (long key press)
> +	 * and debounce.
> +	 */
> +	val = config.long_press_time_val << __ffs(PALMAS_LPK_TIME_MASK);
> +	val |= config.pwron_debounce_val << __ffs(PALMAS_PWRON_DEBOUNCE_MASK);
> +	ret = palmas_update_bits(palmas, PALMAS_PMU_CONTROL_BASE,
> +				 PALMAS_LONG_PRESS_KEY,
> +				 PALMAS_LPK_TIME_MASK |
> +				 PALMAS_PWRON_DEBOUNCE_MASK, val);
> +	if (ret < 0) {
> +		dev_err(dev, "LONG_PRESS_KEY_UPDATE failed!\n");
> +		return ret;
> +	}
> +
> +	input_dev->evbit[0] = BIT_MASK(EV_KEY);
> +	input_dev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
> +	input_dev->name = "palmas_pwron";
> +	input_dev->phys = "palmas_pwron/input0";
> +	input_dev->dev.parent = dev;
> +
> +	pwron->palmas = palmas;
> +	pwron->input_dev = input_dev;
> +
> +	INIT_DELAYED_WORK(&pwron->input_work, palmas_power_button_work);
> +
> +	irq = platform_get_irq(pdev, 0);
> +	ret = request_threaded_irq(irq, NULL, pwron_irq,
> +				   IRQF_TRIGGER_HIGH |
> +				   IRQF_TRIGGER_LOW, dev_name(dev), pwron);
> +	if (ret < 0) {
> +		dev_err(dev, "Can't get IRQ for pwron: %d\n", ret);
> +		return ret;
> +	}
> +
> +	device_init_wakeup(dev, true);
> +
> +	ret = input_register_device(input_dev);
> +	if (ret) {
> +		free_irq(irq, pwron);
> +		cancel_delayed_work_sync(&pwron->input_work);
> +		dev_dbg(dev, "Can't register power button: %d\n", ret);
> +		return ret;
> +	}
> +	pwron->irq = irq;
> +
> +	pwron->key_recheck_ms = PALMAS_PWR_KEY_Q_TIME_MS;
> +
> +	platform_set_drvdata(pdev, pwron);
> +
> +	return 0;
> +}
> +
> +/**
> + * palmas_pwron_remove() - Cleanup on removal
> + * @pdev:	platform device for the button
> + *
> + * Return: 0
> + */
> +static int palmas_pwron_remove(struct platform_device *pdev)
> +{
> +	struct palmas_pwron *pwron = platform_get_drvdata(pdev);
> +
> +	free_irq(pwron->irq, pwron);
> +	cancel_delayed_work_sync(&pwron->input_work);
> +	input_unregister_device(pwron->input_dev);
> +
> +	return 0;
> +}
> +
> +/**
> + * palmas_pwron_suspend() - suspend handler
> + * @dev:	power button device
> + *
> + * Cancel all pending work items for the power button, setup irq for wakeup
> + *
> + * Return: 0
> + */
> +static int palmas_pwron_suspend(struct device *dev)
> +{
> +	struct platform_device *pdev = to_platform_device(dev);
> +	struct palmas_pwron *pwron = platform_get_drvdata(pdev);
> +
> +	cancel_delayed_work_sync(&pwron->input_work);
> +
> +	if (device_may_wakeup(dev))
> +		enable_irq_wake(pwron->irq);
> +
> +	return 0;
> +}
> +
> +/**
> + * palmas_pwron_resume() - resume handler
> + * @dev:	power button device
> + *
> + * Just disable the wakeup capability of irq here.
> + *
> + * Return: 0
> + */
> +static int palmas_pwron_resume(struct device *dev)
> +{
> +	struct platform_device *pdev = to_platform_device(dev);
> +	struct palmas_pwron *pwron = platform_get_drvdata(pdev);
> +
> +	if (device_may_wakeup(dev))
> +		disable_irq_wake(pwron->irq);
> +
> +	return 0;
> +}
> +
> +static SIMPLE_DEV_PM_OPS(palmas_pwron_pm,
> +			 palmas_pwron_suspend, palmas_pwron_resume);
> +
> +#ifdef CONFIG_OF
> +static struct of_device_id of_palmas_pwr_match[] = {
> +	{.compatible = "ti,palmas-pwrbutton"},
> +	{},
> +};
> +
> +MODULE_DEVICE_TABLE(of, of_palmas_pwr_match);
> +#endif
> +
> +static struct platform_driver palmas_pwron_driver = {
> +	.probe = palmas_pwron_probe,
> +	.remove = palmas_pwron_remove,
> +	.driver = {
> +		   .name = "palmas_pwrbutton",
> +		   .owner = THIS_MODULE,
> +		   .of_match_table = of_match_ptr(of_palmas_pwr_match),
> +		   .pm = &palmas_pwron_pm,
> +	},
> +};
> +module_platform_driver(palmas_pwron_driver);
> +
> +MODULE_ALIAS("platform:palmas-pwrbutton");
> +MODULE_DESCRIPTION("Palmas Power Button");
> +MODULE_LICENSE("GPL V2");
> +MODULE_AUTHOR("Texas Instruments Inc.");
> 


-- 
------------------
Dan Murphy

^ permalink raw reply

* [PATCH V2 1/2] doc: dt/bindings: input: introduce palmas power button description
From: Nishanth Menon @ 2014-08-21 16:02 UTC (permalink / raw)
  To: Dmitry Torokhov, Dmitry Torokhov
  Cc: devicetree, linux-kernel, linux-input, linux-omap,
	linux-arm-kernel, Nishanth Menon
In-Reply-To: <1408636935-29515-1-git-send-email-nm@ti.com>

Many palmas family of PMICs have support for interrupt based power
button. This allows the device to notify the processor of external
push button events over the shared palmas interrupt.

Document the hardware support for the same.

Signed-off-by: Nishanth Menon <nm@ti.com>
---

Changes in v2:
 - Added debounce description for palmas variants like TWL6037 that
   actually allow it.
 - Review comments incorportated.
V1: https://patchwork.kernel.org/patch/4739061/

 .../bindings/input/ti,palmas-pwrbutton.txt         |   36 ++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/ti,palmas-pwrbutton.txt

diff --git a/Documentation/devicetree/bindings/input/ti,palmas-pwrbutton.txt b/Documentation/devicetree/bindings/input/ti,palmas-pwrbutton.txt
new file mode 100644
index 0000000..a3dde8c
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/ti,palmas-pwrbutton.txt
@@ -0,0 +1,36 @@
+Texas Instruments Palmas family power button module
+
+This module is part of the Palmas family of PMICs. For more details
+about the whole chip see:
+Documentation/devicetree/bindings/mfd/palmas.txt.
+
+This module provides a simple power button event via an Interrupt.
+
+Required properties:
+- compatible: should be one of the following
+   - "ti,palmas-pwrbutton": For Palmas compatible power on button
+- interrupt-parent: Parent interrupt device, must be handle of palmas node.
+- interrupts: Interrupt number of power button submodule on device.
+
+Optional Properties:
+
+- ti,palmas-long-press-seconds: Duration in seconds which the power
+  button should be kept pressed for Palmas to power off automatically.
+  NOTE: This depends on OTP support and POWERHOLD signal configuration
+  on platform. Valid values are 6, 8, 10 and 12.
+- ti,palmas-pwron-debounce-milli-seconds: Duration in milliseconds
+  which the power button should be kept pressed for Palmas to register
+  a press for debouncing purposes. NOTE: This depends on specific
+  Palmas variation capability. Valid values are 15, 100, 500 and 1000.
+
+Example:
+
+&palmas {
+	palmas_pwr_button: pwrbutton {
+		compatible = "ti,palmas-pwrbutton";
+		interrupt-parent = <&tps659038>;
+		interrupts = <1 IRQ_TYPE_EDGE_FALLING>;
+		ti,palmas-long-press-seconds = <12>;
+		ti,palmas-pwron-debounce-milli-seconds = <15>;
+	};
+};
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH V2 2/2] Input: misc: introduce palmas-pwrbutton
From: Nishanth Menon @ 2014-08-21 16:02 UTC (permalink / raw)
  To: Dmitry Torokhov, Dmitry Torokhov
  Cc: Nishanth Menon, devicetree, linux-kernel, linux-input, linux-omap,
	linux-arm-kernel
In-Reply-To: <1408636935-29515-1-git-send-email-nm@ti.com>

Many palmas family of PMICs have support for interrupt based power
button. This allows the device to notify the processor of external
push button events over the shared palmas interrupt. However, this
event is generated only during a "press" operation. Software is
supposed to poll(sigh!) for detecting a release event.

The PMIC also supports ability to power off independent of the
software decisions when the button is pressed for a long duration if
the PMIC is appropriately configured on the platform.

Even though the function is similar to twl4030_pwrbutton, it is
substantially different in operation to belong to a new driver of it's
own.

Based on original work done by Girish S Ghongdemath <girishsg@ti.com>

Signed-off-by: Nishanth Menon <nm@ti.com>
---
Changes in v2:
 - review comments incorporated
 - debounce programming for TWL variants that actually support it.
V1: https://patchwork.kernel.org/patch/4739041/

 drivers/input/misc/Kconfig            |   10 +
 drivers/input/misc/Makefile           |    1 +
 drivers/input/misc/palmas-pwrbutton.c |  356 +++++++++++++++++++++++++++++++++
 3 files changed, 367 insertions(+)
 create mode 100644 drivers/input/misc/palmas-pwrbutton.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 2ff4425..0224dcf 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -451,6 +451,16 @@ config HP_SDC_RTC
 	  Say Y here if you want to support the built-in real time clock
 	  of the HP SDC controller.
 
+config INPUT_PALMAS_PWRBUTTON
+	tristate "Palmas Power button Driver"
+	depends on MFD_PALMAS
+	help
+	  Say Y here if you want to enable power key reporting via the
+	  Palmas family of PMICs.
+
+	  To compile this driver as a module, choose M here. The module will
+	  be called palmas_pwrbutton.
+
 config INPUT_PCF50633_PMU
 	tristate "PCF50633 PMU events"
 	depends on MFD_PCF50633
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 4955ad3..e3d5efb 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_INPUT_MAX8997_HAPTIC)	+= max8997_haptic.o
 obj-$(CONFIG_INPUT_MC13783_PWRBUTTON)	+= mc13783-pwrbutton.o
 obj-$(CONFIG_INPUT_MMA8450)		+= mma8450.o
 obj-$(CONFIG_INPUT_MPU3050)		+= mpu3050.o
+obj-$(CONFIG_INPUT_PALMAS_PWRBUTTON)	+= palmas-pwrbutton.o
 obj-$(CONFIG_INPUT_PCAP)		+= pcap_keys.o
 obj-$(CONFIG_INPUT_PCF50633_PMU)	+= pcf50633-input.o
 obj-$(CONFIG_INPUT_PCF8574)		+= pcf8574_keypad.o
diff --git a/drivers/input/misc/palmas-pwrbutton.c b/drivers/input/misc/palmas-pwrbutton.c
new file mode 100644
index 0000000..fb8bfc5
--- /dev/null
+++ b/drivers/input/misc/palmas-pwrbutton.c
@@ -0,0 +1,356 @@
+/*
+ * Texas Instruments' Palmas Power Button Input Driver
+ *
+ * Copyright (C) 2012-2014 Texas Instruments Incorporated - http://www.ti.com/
+ *	Girish S Ghongdemath
+ *	Nishanth Menon
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/mfd/palmas.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/reboot.h>
+#include <linux/slab.h>
+
+#define PALMAS_LPK_TIME_MASK		0x0c
+#define PALMAS_PWRON_DEBOUNCE_MASK	0x03
+#define PALMAS_PWR_KEY_PRESS		0x01
+#define PALMAS_PWR_KEY_Q_TIME_MS	20
+
+/**
+ * struct palmas_pwron - Palmas power on data
+ * @palmas:		pointer to palmas device
+ * @input_dev:		pointer to input device
+ * @irq:		irq that we are hooked on to
+ * @input_work:		work for detecting release of key
+ * @current_state:	key current state
+ * @key_recheck_ms:	duration for recheck of key (in milli-seconds)
+ */
+struct palmas_pwron {
+	struct palmas *palmas;
+	struct input_dev *input_dev;
+	int irq;
+	struct delayed_work input_work;
+	int current_state;
+	u32 key_recheck_ms;
+};
+
+/**
+ * struct palmas_pwron_config - configuration of palmas power on
+ * @long_press_time_val:	value for long press h/w shutdown event
+ * @pwron_debounce_val:		value for debounce of power button
+ */
+struct palmas_pwron_config {
+	u8 long_press_time_val;
+	u8 pwron_debounce_val;
+};
+
+/**
+ * palmas_get_pwr_state() - read button state
+ * @pwron: pointer to pwron struct
+ *
+ * Return: 0 for no press, PALMAS_PWR_KEY_PRESS for keypress
+ * and on error, appropriate error value.
+ */
+static int palmas_get_pwr_state(struct palmas_pwron *pwron)
+{
+	struct input_dev *input_dev = pwron->input_dev;
+	struct device *dev = input_dev->dev.parent;
+	unsigned int reg = 0;
+	int ret;
+
+	ret = palmas_read(pwron->palmas, PALMAS_INTERRUPT_BASE,
+			  PALMAS_INT1_LINE_STATE, &reg);
+	if (ret) {
+		dev_err(dev, "%s:Cannot read palmas PWRON status(%d)\n",
+			__func__, ret);
+		return ret;
+	}
+
+	/* PWRON line state is BIT(1) of the register */
+	return reg & BIT(1) ? 0 : PALMAS_PWR_KEY_PRESS;
+}
+
+/**
+ * palmas_power_button_work() - Detects the button release event
+ * @work:	work item to detect button release
+ */
+static void palmas_power_button_work(struct work_struct *work)
+{
+	struct palmas_pwron *pwron = container_of((struct delayed_work *)work,
+						  struct palmas_pwron,
+						  input_work);
+	struct input_dev *input_dev = pwron->input_dev;
+	int next_state;
+
+	next_state = palmas_get_pwr_state(pwron);
+	if (next_state < 0)
+		return;
+
+	/*
+	 * If the state did not change then schedule a work item to check the
+	 * status of the power button line
+	 */
+	if (next_state == pwron->current_state) {
+		schedule_delayed_work(&pwron->input_work,
+				      msecs_to_jiffies(pwron->key_recheck_ms));
+		return;
+	}
+
+	pwron->current_state = next_state;
+	input_report_key(input_dev, KEY_POWER, pwron->current_state);
+	input_sync(input_dev);
+}
+
+/**
+ * pwron_irq() - button press isr
+ * @irq:		irq
+ * @palmas_pwron:	pwron struct
+ *
+ * Return: IRQ_HANDLED
+ */
+static irqreturn_t pwron_irq(int irq, void *palmas_pwron)
+{
+	struct palmas_pwron *pwron = palmas_pwron;
+	struct input_dev *input_dev = pwron->input_dev;
+
+	pwron->current_state = PALMAS_PWR_KEY_PRESS;
+
+	input_report_key(input_dev, KEY_POWER, pwron->current_state);
+	pm_wakeup_event(input_dev->dev.parent, 0);
+	input_sync(input_dev);
+
+	mod_delayed_work(system_wq, &pwron->input_work,
+			 msecs_to_jiffies(pwron->key_recheck_ms));
+
+	return IRQ_HANDLED;
+}
+
+/**
+ * palmas_pwron_params_ofinit() - device tree parameter parser
+ * @dev:	palmas button device
+ * @config:	configuration params that this fills up
+ */
+static void palmas_pwron_params_ofinit(struct device *dev,
+				       struct palmas_pwron_config *config)
+{
+	struct device_node *np;
+	u32 val;
+	int i;
+	u8 lpk_times[] = { 6, 8, 10, 12 };
+	int pwr_on_deb_ms[] = { 15, 100, 500, 1000 };
+
+	/* Legacy boot? */
+	if (!of_have_populated_dt())
+		return;
+
+	np = of_node_get(dev->of_node);
+	/* Mixed boot? */
+	if (!np)
+		return;
+
+	val = 0;
+	of_property_read_u32(np, "ti,palmas-long-press-seconds", &val);
+	config->long_press_time_val = ARRAY_SIZE(lpk_times) - 1;
+	for (i = 0; i < ARRAY_SIZE(lpk_times); i++) {
+		if (val <= lpk_times[i]) {
+			config->long_press_time_val = i;
+			break;
+		}
+	}
+
+	val = 0;
+	of_property_read_u32(np, "ti,palmas-pwron-debounce-milli-seconds",
+			     &val);
+	config->pwron_debounce_val = 0;
+	for (i = 0; i < ARRAY_SIZE(pwr_on_deb_ms); i++) {
+		if (val <= pwr_on_deb_ms[i]) {
+			config->pwron_debounce_val = i;
+			break;
+		}
+	}
+
+	dev_info(dev, "h/w controlled shutdown duration=%d seconds\n",
+		 lpk_times[config->long_press_time_val]);
+
+	of_node_put(np);
+}
+
+/**
+ * palmas_pwron_probe() - probe
+ * @pdev:	platform device for the button
+ *
+ * Return: 0 for successful probe else appropriate error
+ */
+static int palmas_pwron_probe(struct platform_device *pdev)
+{
+	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
+	struct device *dev = &pdev->dev;
+	struct input_dev *input_dev;
+	struct palmas_pwron *pwron;
+	int irq, ret, val;
+	struct palmas_pwron_config config = { 0 };
+
+	palmas_pwron_params_ofinit(dev, &config);
+
+	pwron = devm_kzalloc(dev, sizeof(*pwron), GFP_KERNEL);
+	if (!pwron)
+		return -ENOMEM;
+
+	input_dev = devm_input_allocate_device(dev);
+	if (!input_dev) {
+		dev_err(dev, "Can't allocate power button\n");
+		return -ENOMEM;
+	}
+
+	/*
+	 * Setup default hardware shutdown option (long key press)
+	 * and debounce.
+	 */
+	val = config.long_press_time_val << __ffs(PALMAS_LPK_TIME_MASK);
+	val |= config.pwron_debounce_val << __ffs(PALMAS_PWRON_DEBOUNCE_MASK);
+	ret = palmas_update_bits(palmas, PALMAS_PMU_CONTROL_BASE,
+				 PALMAS_LONG_PRESS_KEY,
+				 PALMAS_LPK_TIME_MASK |
+				 PALMAS_PWRON_DEBOUNCE_MASK, val);
+	if (ret < 0) {
+		dev_err(dev, "LONG_PRESS_KEY_UPDATE failed!\n");
+		return ret;
+	}
+
+	input_dev->evbit[0] = BIT_MASK(EV_KEY);
+	input_dev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
+	input_dev->name = "palmas_pwron";
+	input_dev->phys = "palmas_pwron/input0";
+	input_dev->dev.parent = dev;
+
+	pwron->palmas = palmas;
+	pwron->input_dev = input_dev;
+
+	INIT_DELAYED_WORK(&pwron->input_work, palmas_power_button_work);
+
+	irq = platform_get_irq(pdev, 0);
+	ret = request_threaded_irq(irq, NULL, pwron_irq,
+				   IRQF_TRIGGER_HIGH |
+				   IRQF_TRIGGER_LOW, dev_name(dev), pwron);
+	if (ret < 0) {
+		dev_err(dev, "Can't get IRQ for pwron: %d\n", ret);
+		return ret;
+	}
+
+	device_init_wakeup(dev, true);
+
+	ret = input_register_device(input_dev);
+	if (ret) {
+		free_irq(irq, pwron);
+		cancel_delayed_work_sync(&pwron->input_work);
+		dev_dbg(dev, "Can't register power button: %d\n", ret);
+		return ret;
+	}
+	pwron->irq = irq;
+
+	pwron->key_recheck_ms = PALMAS_PWR_KEY_Q_TIME_MS;
+
+	platform_set_drvdata(pdev, pwron);
+
+	return 0;
+}
+
+/**
+ * palmas_pwron_remove() - Cleanup on removal
+ * @pdev:	platform device for the button
+ *
+ * Return: 0
+ */
+static int palmas_pwron_remove(struct platform_device *pdev)
+{
+	struct palmas_pwron *pwron = platform_get_drvdata(pdev);
+
+	free_irq(pwron->irq, pwron);
+	cancel_delayed_work_sync(&pwron->input_work);
+	input_unregister_device(pwron->input_dev);
+
+	return 0;
+}
+
+/**
+ * palmas_pwron_suspend() - suspend handler
+ * @dev:	power button device
+ *
+ * Cancel all pending work items for the power button, setup irq for wakeup
+ *
+ * Return: 0
+ */
+static int palmas_pwron_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct palmas_pwron *pwron = platform_get_drvdata(pdev);
+
+	cancel_delayed_work_sync(&pwron->input_work);
+
+	if (device_may_wakeup(dev))
+		enable_irq_wake(pwron->irq);
+
+	return 0;
+}
+
+/**
+ * palmas_pwron_resume() - resume handler
+ * @dev:	power button device
+ *
+ * Just disable the wakeup capability of irq here.
+ *
+ * Return: 0
+ */
+static int palmas_pwron_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct palmas_pwron *pwron = platform_get_drvdata(pdev);
+
+	if (device_may_wakeup(dev))
+		disable_irq_wake(pwron->irq);
+
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(palmas_pwron_pm,
+			 palmas_pwron_suspend, palmas_pwron_resume);
+
+#ifdef CONFIG_OF
+static struct of_device_id of_palmas_pwr_match[] = {
+	{.compatible = "ti,palmas-pwrbutton"},
+	{},
+};
+
+MODULE_DEVICE_TABLE(of, of_palmas_pwr_match);
+#endif
+
+static struct platform_driver palmas_pwron_driver = {
+	.probe = palmas_pwron_probe,
+	.remove = palmas_pwron_remove,
+	.driver = {
+		   .name = "palmas_pwrbutton",
+		   .owner = THIS_MODULE,
+		   .of_match_table = of_match_ptr(of_palmas_pwr_match),
+		   .pm = &palmas_pwron_pm,
+	},
+};
+module_platform_driver(palmas_pwron_driver);
+
+MODULE_ALIAS("platform:palmas-pwrbutton");
+MODULE_DESCRIPTION("Palmas Power Button");
+MODULE_LICENSE("GPL V2");
+MODULE_AUTHOR("Texas Instruments Inc.");
-- 
1.7.9.5

^ permalink raw reply related

* [PATCH V2 0/2] Input: palmas: add support for palmas power button
From: Nishanth Menon @ 2014-08-21 16:02 UTC (permalink / raw)
  To: Dmitry Torokhov, Dmitry Torokhov
  Cc: devicetree, linux-kernel, linux-input, linux-omap,
	linux-arm-kernel, Nishanth Menon
In-Reply-To: <1408392810-16011-1-git-send-email-nm@ti.com>

Many Palmas PMIC variants have support for power button feature. This
feature depends on certain One Time Program (OTP) and board pull
configurations (POWERHOLD signal). However, on many platforms such
as DRA72-evm, OMAP5-uevm, this may be used to generate input events
similar to twl4030-pwrbutton.c

Series is based on v3.17-rc1

V2 of the series incorporating comments from http://marc.info/?l=linux-input&m=140839287431882&w=2

Nishanth Menon (2):
  doc: dt/bindings: input: introduce palmas power button description
  Input: misc: introduce palmas-pwrbutton

 .../bindings/input/ti,palmas-pwrbutton.txt         |   36 ++
 drivers/input/misc/Kconfig                         |   10 +
 drivers/input/misc/Makefile                        |    1 +
 drivers/input/misc/palmas-pwrbutton.c              |  356 ++++++++++++++++++++
 4 files changed, 403 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/ti,palmas-pwrbutton.txt
 create mode 100644 drivers/input/misc/palmas-pwrbutton.c

-- 
1.7.9.5

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox