* Re: [PATCH] Input: atmel_mxt_ts: Add of node type to the i2c table
From: Sjoerd Simons @ 2014-09-09 10:54 UTC (permalink / raw)
To: Nick Dyer
Cc: Javier Martinez Canillas, Dmitry Torokhov, linux-input,
linux-kernel, linux-samsung-soc, Lee Jones
In-Reply-To: <540ED671.5020103@itdev.co.uk>
[-- Attachment #1: Type: text/plain, Size: 1297 bytes --]
On Tue, 2014-09-09 at 11:29 +0100, Nick Dyer wrote:
> On 09/09/14 11:21, Javier Martinez Canillas wrote:
> > On 09/09/2014 09:52 AM, Sjoerd Simons wrote:
> >> For i2c devices in OF the modalias exposed to userspace is i2c:<node
> >> type>, for the Maxtouch driver this is i2c:maxtouch.
> >>
> >> Add maxtouch to the i2c id table such that userspace can correctly
> >> load the module for the device and drop the OF table as it's not
> >> needed for i2c devices.
> > I see that Lee is working to allow the I2C subsystem to not need an I2C ID
> > table to match [0]. I'll let Lee to comment what the future plans are and if
> > his series are going to solve your issue since I'm not that familiar with the
> > I2C core.
>
> I can see the benefit of not having the duplication. Am I correct that
> you're saying that it might make more sense to remove the i2c ids rather
> than the OF table, if Lee's changes are accepted?
You would still need the i2C table for non-OF platforms ofcourse.
I'm not sure what happens with the modalias as exposed to userspace with
Lee's patchset, if that gets changed to prefer an of: type instead of
the current i2c: prefixed ones this patch (at that point) isn't needed.
--
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
Collabora Ltd.
[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 6170 bytes --]
^ permalink raw reply
* [PATCH] Input:wm971x: Fix typo in module param description of wm971[23].c
From: Masanari Iida @ 2014-09-09 11:02 UTC (permalink / raw)
To: linux-kernel, dmitry.torokhov, broonie, linux-input, lrg, rdunlap
Cc: Masanari Iida
This patch fix spelling typo in module parameter
description of wm9712.c and wm9713.c
Signed-off-by: Masanari Iida <standby24x7@gmail.com>
---
drivers/input/touchscreen/wm9712.c | 2 +-
drivers/input/touchscreen/wm9713.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/input/touchscreen/wm9712.c b/drivers/input/touchscreen/wm9712.c
index 16b5211..705ffa1 100644
--- a/drivers/input/touchscreen/wm9712.c
+++ b/drivers/input/touchscreen/wm9712.c
@@ -41,7 +41,7 @@
*/
static int rpu = 8;
module_param(rpu, int, 0);
-MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect.");
+MODULE_PARM_DESC(rpu, "Set internal pull up resistor for pen detect.");
/*
* Set current used for pressure measurement.
diff --git a/drivers/input/touchscreen/wm9713.c b/drivers/input/touchscreen/wm9713.c
index 7405353..572a5a6 100644
--- a/drivers/input/touchscreen/wm9713.c
+++ b/drivers/input/touchscreen/wm9713.c
@@ -41,7 +41,7 @@
*/
static int rpu = 8;
module_param(rpu, int, 0);
-MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect.");
+MODULE_PARM_DESC(rpu, "Set internal pull up resistor for pen detect.");
/*
* Set current used for pressure measurement.
--
2.1.0.60.g85f0837
^ permalink raw reply related
* Re: [PATCH] Input: atmel_mxt_ts: Add of node type to the i2c table
From: Nick Dyer @ 2014-09-09 12:36 UTC (permalink / raw)
To: Sjoerd Simons, Dmitry Torokhov
Cc: linux-input, linux-kernel, linux-samsung-soc,
Javier Martinez Canillas
In-Reply-To: <1410249158-18192-1-git-send-email-sjoerd.simons@collabora.co.uk>
On 09/09/14 08:52, Sjoerd Simons wrote:
> For i2c devices in OF the modalias exposed to userspace is i2c:<node
> type>, for the Maxtouch driver this is i2c:maxtouch.
>
> Add maxtouch to the i2c id table such that userspace can correctly
> load the module for the device and drop the OF table as it's not
> needed for i2c devices.
>
> Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
I've tested this and it does work. In fact, it seems that you can use
compatible = "i2c:atmel,maxtouch";
because the "atmel," is ignored in the matching.
Before I could ack this patch, we will need to update this dts file:
arch/arm/boot/dts/s5pv210-goni.dts
and this documentation file:
Documentation/devicetree/bindings/input/atmel,maxtouch.txt
thanks!
^ permalink raw reply
* Re: [PATCH] HID: rmi: check sanity of the incoming report
From: Benjamin Tissoires @ 2014-09-09 14:06 UTC (permalink / raw)
To: Andrew Duggan; +Cc: Jiri Kosina, linux-input, linux-kernel
In-Reply-To: <540E4C3A.3000408@synaptics.com>
On Sep 08 2014 or thereabouts, Andrew Duggan wrote:
> On 09/05/2014 06:57 AM, Benjamin Tissoires wrote:
> >In the Dell XPS 13 9333, it appears that sometimes the bus get confused
> >and corrupts the incoming data. It fills the input report with the
> >sentinel value "ff". Synaptics told us that such behavior does not comes
> >from the touchpad itself, so we filter out such reports here.
> >
> >Unfortunately, we can not simply discard the incoming data because they
> >may contain useful information. Most of the time, the misbehavior is
> >quite near the end of the report, so we can still use the valid part of
> >it.
> >
> >Fixes:
> >https://bugzilla.redhat.com/show_bug.cgi?id=1123584
> >
> >Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> >---
> > drivers/hid/hid-rmi.c | 31 ++++++++++++++++++++++++++-----
> > 1 file changed, 26 insertions(+), 5 deletions(-)
> >
> >diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c
> >index 8389e81..db92c3b 100644
> >--- a/drivers/hid/hid-rmi.c
> >+++ b/drivers/hid/hid-rmi.c
> >@@ -320,9 +320,6 @@ static int rmi_f11_input_event(struct hid_device *hdev, u8 irq, u8 *data,
> > int offset;
> > int i;
> >- if (size < hdata->f11.report_size)
> >- return 0;
> >-
> > if (!(irq & hdata->f11.irq_mask))
> > return 0;
> >@@ -332,9 +329,13 @@ static int rmi_f11_input_event(struct hid_device *hdev, u8 irq, u8 *data,
> > int fs_bit_position = (i & 0x3) << 1;
> > int finger_state = (data[fs_byte_position] >> fs_bit_position) &
> > 0x03;
> >+ int position = offset + 5 * i;
> >+
> >+ if (position + 5 > size)
> >+ /* partial report, go on with what we received */
> >+ break;
> >- rmi_f11_process_touch(hdata, i, finger_state,
> >- &data[offset + 5 * i]);
> >+ rmi_f11_process_touch(hdata, i, finger_state, &data[position]);
> > }
> > input_mt_sync_frame(hdata->input);
> > input_sync(hdata->input);
> >@@ -412,9 +413,29 @@ static int rmi_read_data_event(struct hid_device *hdev, u8 *data, int size)
> > return 1;
> > }
> >+static int rmi_check_sanity(struct hid_device *hdev, u8 *data, int size)
> >+{
> >+ int valid_size = size;
> >+ /*
> >+ * On the Dell XPS 13 9333, the bus sometimes get confused and fills
> >+ * the report with a sentinel value "ff". Synaptics told us that such
> >+ * behavior does not comes from the touchpad itself, so we filter out
> >+ * such reports here.
> >+ */
> >+
> >+ while ((data[valid_size - 1] == 0xff) && valid_size > 0)
> >+ valid_size--;
> >+
> >+ return valid_size;
> >+}
> >+
> > static int rmi_raw_event(struct hid_device *hdev,
> > struct hid_report *report, u8 *data, int size)
> > {
> >+ size = rmi_check_sanity(hdev, data, size);
> >+ if (size < 2)
> >+ return 0;
> >+
> > switch (data[0]) {
> > case RMI_READ_DATA_REPORT_ID:
> > return rmi_read_data_event(hdev, data, size);
> I think there should also be a check in rmi_f30_input_event to make sure
> that the F30 data is also valid. The F30 data is at the end of the HID
> report so if the F30 interrupt bit is set, but the value in the report is FF
> then there might be some unintended button events. I think checking that
> size > 0 would be sufficient to make sure the F30 data is valid.
Yeah :(
Actually, I am missing too checks in f11 and f30. If the size is <= 0,
then bail out before doing anything.
>
> Other then that, the sanity check and validation in rmi_f11_input_event look
> good to me.
>
> Andrew
^ permalink raw reply
* Re: [PATCH] HID: rmi: check sanity of the incoming report
From: Benjamin Tissoires @ 2014-09-09 14:11 UTC (permalink / raw)
To: Jiri Kosina; +Cc: Andrew Duggan, linux-input, linux-kernel
In-Reply-To: <alpine.LNX.2.00.1409081012160.5523@pobox.suse.cz>
On Sep 08 2014 or thereabouts, Jiri Kosina wrote:
> On Fri, 5 Sep 2014, Benjamin Tissoires wrote:
>
> > In the Dell XPS 13 9333, it appears that sometimes the bus get confused
> > and corrupts the incoming data. It fills the input report with the
> > sentinel value "ff". Synaptics told us that such behavior does not comes
> > from the touchpad itself, so we filter out such reports here.
> >
> > Unfortunately, we can not simply discard the incoming data because they
> > may contain useful information. Most of the time, the misbehavior is
> > quite near the end of the report, so we can still use the valid part of
> > it.
> >
> > Fixes:
> > https://bugzilla.redhat.com/show_bug.cgi?id=1123584
> >
> > Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> > ---
> > drivers/hid/hid-rmi.c | 31 ++++++++++++++++++++++++++-----
> > 1 file changed, 26 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c
> > index 8389e81..db92c3b 100644
> > --- a/drivers/hid/hid-rmi.c
> > +++ b/drivers/hid/hid-rmi.c
> > @@ -320,9 +320,6 @@ static int rmi_f11_input_event(struct hid_device *hdev, u8 irq, u8 *data,
> > int offset;
> > int i;
> >
> > - if (size < hdata->f11.report_size)
> > - return 0;
> > -
> > if (!(irq & hdata->f11.irq_mask))
> > return 0;
> >
> > @@ -332,9 +329,13 @@ static int rmi_f11_input_event(struct hid_device *hdev, u8 irq, u8 *data,
> > int fs_bit_position = (i & 0x3) << 1;
> > int finger_state = (data[fs_byte_position] >> fs_bit_position) &
> > 0x03;
> > + int position = offset + 5 * i;
> > +
> > + if (position + 5 > size)
> > + /* partial report, go on with what we received */
> > + break;
>
> Do you perhaps want to warn the user here, so that he knows that things
> are getting a little bit hairy? Or is this happening so often that it
> makes no sense to warn about it?
>
I wanted to check on that yesterday, but I have been side tracked quite
a lot. So:
I think there might be too much messages to unconditionally notify the
user here. I do not see a better way than limiting the number to 10 or
so before giving up the notifications. Ideally, I would love to notify
the user when useful information is lost, but I did not came up with a
solution quickly.
On the other hand, not having the coordinates is not that much of a
problem I think. But, missing a f30 message (button event) is much more
of a problem, and I think we should notify the user there unconditionally
because there will be stuck pointers if the failure happens during a
release.
v2 should be on its way something like next week unless somebody else
wants to take over.
Cheers,
Benjamin
^ permalink raw reply
* [PATCH 2/2] Input: atmel_mxt_ts - fix double free of input device
From: nick.dyer @ 2014-09-09 14:50 UTC (permalink / raw)
To: Dmitry Torokhov, Stephen Warren
Cc: Yufeng Shen, Daniel Kurtz, Henrik Rydberg, Joonyoung Shim,
Alan Bowens, linux-input, linux-kernel, Peter Meerwald,
Benson Leung, Olof Johansson, Sekhar Nori, Nick Dyer
In-Reply-To: <1410274249-3469-1-git-send-email-nick.dyer@itdev.co.uk>
From: Stephen Warren <swarren@wwwdotorg.org>
[reworked after comments by Dmitry Torokhov. Move free of input device into
separate function. Only call in paths that require it. Move mxt_initialize
after sysfs init, because otherwise an error in the sysfs init may interfere
with the async return from the firmware loader. Add guards for sysfs
functions. ]
Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 40 ++++++++++++++++++++++----------
1 file changed, 28 insertions(+), 12 deletions(-)
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index d954b81..65153c4 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -1379,11 +1379,16 @@ static int mxt_get_info(struct mxt_data *data)
return 0;
}
-static void mxt_free_object_table(struct mxt_data *data)
+static void mxt_free_input_device(struct mxt_data *data)
{
- input_unregister_device(data->input_dev);
- data->input_dev = NULL;
+ if (data->input_dev) {
+ input_unregister_device(data->input_dev);
+ data->input_dev = NULL;
+ }
+}
+static void mxt_free_object_table(struct mxt_data *data)
+{
kfree(data->object_table);
data->object_table = NULL;
kfree(data->msg_buf);
@@ -1828,6 +1833,10 @@ static ssize_t mxt_fw_version_show(struct device *dev,
{
struct mxt_data *data = dev_get_drvdata(dev);
struct mxt_info *info = &data->info;
+
+ if (!data->object_table)
+ return -EINVAL;
+
return scnprintf(buf, PAGE_SIZE, "%u.%u.%02X\n",
info->version >> 4, info->version & 0xf, info->build);
}
@@ -1838,6 +1847,10 @@ static ssize_t mxt_hw_version_show(struct device *dev,
{
struct mxt_data *data = dev_get_drvdata(dev);
struct mxt_info *info = &data->info;
+
+ if (!data->object_table)
+ return -EINVAL;
+
return scnprintf(buf, PAGE_SIZE, "%u.%u\n",
info->family_id, info->variant_id);
}
@@ -1870,6 +1883,9 @@ static ssize_t mxt_object_show(struct device *dev,
int error;
u8 *obuf;
+ if (!data->object_table)
+ return -EINVAL;
+
/* Pre-allocate buffer large enough to hold max sized object. */
obuf = kmalloc(256, GFP_KERNEL);
if (!obuf)
@@ -1962,11 +1978,13 @@ static int mxt_load_fw(struct device *dev, const char *fn)
ret = mxt_lookup_bootloader_address(data, 0);
if (ret)
goto release_firmware;
+
+ mxt_free_input_device(data);
+ mxt_free_object_table(data);
} else {
enable_irq(data->irq);
}
- mxt_free_object_table(data);
reinit_completion(&data->bl_completion);
ret = mxt_check_bootloader(data, MXT_WAITING_BOOTLOAD_CMD, false);
@@ -2201,21 +2219,19 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
disable_irq(client->irq);
- error = mxt_initialize(data);
- if (error)
- goto err_free_irq;
-
error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group);
if (error) {
dev_err(&client->dev, "Failure %d creating sysfs group\n",
error);
- goto err_free_object;
+ goto err_free_irq;
}
+ error = mxt_initialize(data);
+ if (error)
+ goto err_free_irq;
+
return 0;
-err_free_object:
- mxt_free_object_table(data);
err_free_irq:
free_irq(client->irq, data);
err_free_mem:
@@ -2229,7 +2245,7 @@ static int mxt_remove(struct i2c_client *client)
sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
free_irq(data->irq, data);
- input_unregister_device(data->input_dev);
+ mxt_free_input_device(data);
mxt_free_object_table(data);
kfree(data);
--
1.9.1
^ permalink raw reply related
* atmel_mxt_ts fixes
From: nick.dyer @ 2014-09-09 14:50 UTC (permalink / raw)
To: Dmitry Torokhov, Stephen Warren
Cc: Yufeng Shen, Daniel Kurtz, Henrik Rydberg, Joonyoung Shim,
Alan Bowens, linux-input, linux-kernel, Peter Meerwald,
Benson Leung, Olof Johansson, Sekhar Nori
Hi Dmitry/Stephen-
I have tested and reworked the fix for the double free issue in atmel_mxt_ts
that Stephen identified. A lot more entertaining than I thought at first. Also
a minor change to reduce the verbosity of a warning message.
cheers
Nick
^ permalink raw reply
* [PATCH 1/2] Input: atmel_mxt_ts - downgrade warning about empty interrupts
From: nick.dyer @ 2014-09-09 14:50 UTC (permalink / raw)
To: Dmitry Torokhov, Stephen Warren
Cc: Yufeng Shen, Daniel Kurtz, Henrik Rydberg, Joonyoung Shim,
Alan Bowens, linux-input, linux-kernel, Peter Meerwald,
Benson Leung, Olof Johansson, Sekhar Nori, Nick Dyer
In-Reply-To: <1410274249-3469-1-git-send-email-nick.dyer@itdev.co.uk>
From: Nick Dyer <nick.dyer@itdev.co.uk>
In the case where the CHG/interrupt line mode is not configured correctly,
this warning is output to dmesg output for each interrupt. Downgrade the
message to debug.
Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index db178ed..d954b81 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -837,7 +837,12 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data)
count = data->msg_buf[0];
if (count == 0) {
- dev_warn(dev, "Interrupt triggered but zero messages\n");
+ /*
+ * This condition is caused by the CHG line being configured
+ * in Mode 0. It results in unnecessary I2C operations but it
+ * is benign.
+ */
+ dev_dbg(dev, "Interrupt triggered but zero messages\n");
return IRQ_NONE;
} else if (count > data->max_reportid) {
dev_err(dev, "T44 count %d exceeded max report id\n", count);
--
1.9.1
^ permalink raw reply related
* Re: [PATCH] Input: synaptics - add support for ForcePads
From: Dmitry Torokhov @ 2014-09-09 17:06 UTC (permalink / raw)
To: Hans de Goede
Cc: linux-input, Benjamin Tissoires, Christopher Heiny, linux-kernel,
Andrew Duggan
In-Reply-To: <540EAFD1.2040307@redhat.com>
On Tue, Sep 09, 2014 at 09:44:17AM +0200, Hans de Goede wrote:
> Hi,
>
> On 09/08/2014 06:55 PM, Dmitry Torokhov wrote:
> > ForcePads are found on HP EliteBook 1040 laptops. They lack any kind of
> > physical buttons, instead they generate primary button click when user
> > presses somewhat hard on the surface of the touchpad. Unfortunately they
> > also report primary button click whenever there are 2 or more contacts
> > on the pad, messing up all multi-finger gestures (2-finger scrolling,
> > multi-finger tapping, etc). To cope with this behavior we introduce a
> > delay (currently 50 msecs) in reporting primary press in case more
> > contacts appear.
> >
> > For now we are using DMI matching to detect ForcePads, hopefully we'll
> > be able to figure a better way down the road.
>
> What about using the pnp-id, in my experience with the recent lenovo
> laptops that tends to be more reliable.
Not sure. So far I only know of HP 1040 having it. FWIW:
dtor@dtor-glaptop:~$ cat /sys/bus/pnp/drivers/i8042\ aux/00\:07/id
SYN300d
SYN0100
SYN0002
PNP0f13
I think if we see generalities we can switch over later. I hope
Chris/Andrew will come with a capability bit though :)
>
> Christopher, Andrew (added to the CC), can one of you tell us if there
> is a capability bit to detect this, and if not can you perhaps provide
> a list of pnp-ids of devices which behave like this ?
>
> > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> > ---
> > drivers/input/mouse/synaptics.c | 80 ++++++++++++++++++++++++++++++++---------
> > drivers/input/mouse/synaptics.h | 5 +++
> > 2 files changed, 69 insertions(+), 16 deletions(-)
> >
> > diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
> > index e8573c6..5de1bb6 100644
> > --- a/drivers/input/mouse/synaptics.c
> > +++ b/drivers/input/mouse/synaptics.c
> > @@ -618,6 +618,8 @@ static void synaptics_parse_agm(const unsigned char buf[],
> > priv->agm_pending = true;
> > }
> >
> > +static bool is_forcepad;
> > +
> > static int synaptics_parse_hw_state(const unsigned char buf[],
> > struct synaptics_data *priv,
> > struct synaptics_hw_state *hw)
> > @@ -629,10 +631,58 @@ static int synaptics_parse_hw_state(const unsigned char buf[],
> > ((buf[0] & 0x04) >> 1) |
> > ((buf[3] & 0x04) >> 2));
> >
> > + if ((SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
> > + SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) &&
> > + hw->w == 2) {
> > + synaptics_parse_agm(buf, priv, hw);
> > + return 1;
> > + }
> > +
> > + hw->x = (((buf[3] & 0x10) << 8) |
> > + ((buf[1] & 0x0f) << 8) |
> > + buf[4]);
> > + hw->y = (((buf[3] & 0x20) << 7) |
> > + ((buf[1] & 0xf0) << 4) |
> > + buf[5]);
> > + hw->z = buf[2];
> > +
> > hw->left = (buf[0] & 0x01) ? 1 : 0;
> > hw->right = (buf[0] & 0x02) ? 1 : 0;
> >
>
> Moving this up means that on clickpads the button will no longer
> be checked + set for hw->w == 2 packets. That seems like an unintended
> side effect.
I guess we can call it a side effect, but it is fine - we parse AGM and
stash the data, then when 2nd packet comes we parse and act upon it. In
the old code we'd parse x, y, z, in AGM etc. and then have it
overwritten with the data from the 2nd packet, here we do not bother.
> If this is intended then this should probably be in its own
> patch.
It does not make sense on its own as ForcePad support needs to know
values of Z and W when deciding how to handle primary click, otherwise
the old code was just fine.
>
> > - if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
> > + if (is_forcepad) {
> > + /* XXX is there a proper capability bit for this? */
> > + /*
> > + * ForcePads, like Clickpads, use middle button
> > + * bits to report primary button clicks.
> > + * Unfortunately they report primary button not only
> > + * when user presses on the pad above certain threshold,
> > + * but also when there are more than one finger on the
> > + * touchpad, which interferes with out multi-finger
> > + * gestures.
> > + */
> > + if (hw->z == 0) {
> > + /* No contacts */
> > + priv->press = priv->report_press = false;
> > + } else if (hw->w >= 4 && ((buf[0] ^ buf[3]) & 0x01)) {
> > + /*
> > + * Single-finger touch with pressure above
> > + * the threshold.
> > + */
> > + if (!priv->press) {
> > + priv->press_start = jiffies;
> > + priv->press = true;
> > + } else if (time_after(jiffies,
> > + priv->press_start +
> > + msecs_to_jiffies(50))) {
> > + priv->report_press = true;
> > + }
>
> You're not setting a timer here, instead relying on there to be further events,
> that is probably ok, but maybe put a comment to that extent here ?
I can, any suggestion on what you want me to say? "If single point
contact held pressure long enough start reporting primary click"?
Thanks.
--
Dmitry
^ permalink raw reply
* Re: [PATCH v2] Input: serport: Add compat_ioctl routine to support 32bit inputattach in 64bit systems
From: Dmitry Torokhov @ 2014-09-09 18:14 UTC (permalink / raw)
To: John Sung; +Cc: linux-input, linux-kernel
In-Reply-To: <1410240028-9377-1-git-send-email-penmount.touch@gmail.com>
Hi John,
On Tue, Sep 09, 2014 at 01:20:28PM +0800, John Sung wrote:
> When running a 32-bit inputattach utility in a 64-bit system, there will be error code "inputattach: can't set device type". This is caused by the serport device driver not supporting compat_ioctl, so that SPIOCSTYPE ioctl fails.
>
> Changes in v2:
> (1) Codes of the compat_ioctl are protected by #ifdef CONFIG_COMPAT.
> (2) Add a new function serport_set_type() for common codes used by serport_ldisc_ioctl() and serport_ldisc_compat_ioctl().
>
> Signed-off-by: John Sung <penmount.touch@gmail.com>
> ---
> drivers/input/serio/serport.c | 57 +++++++++++++++++++++++++++++++++--------
> 1 file changed, 46 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
> index 0cb7ef5..1decaa2 100644
> --- a/drivers/input/serio/serport.c
> +++ b/drivers/input/serio/serport.c
> @@ -22,6 +22,10 @@
> #include <linux/serio.h>
> #include <linux/tty.h>
>
> +#ifdef CONFIG_COMPAT
> +#include <linux/compat.h>
> +#endif
> +
> MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
> MODULE_DESCRIPTION("Input device TTY line discipline");
> MODULE_LICENSE("GPL");
> @@ -40,6 +44,30 @@ struct serport {
> unsigned long flags;
> };
>
> +#ifdef CONFIG_COMPAT
> +#define SPIOCSTYPE32 (_IOW('q', 0x01, compat_ulong_t))
> +#endif
> +
> +/*
> + * serport_set_type() is called by serport_ldisc_ioctl() and
> + * serport_ldisc_compat_ioctl() to set up the serio_device_id values
> + */
> +
> +static int serport_set_type(struct tty_struct *tty, unsigned long arg)
> +{
> + struct serport *serport = (struct serport *) tty->disc_data;
> + unsigned long type;
> +
> + if (get_user(type, (unsigned long __user *) arg))
> + return -EFAULT;
I of not think we can do this. Kernel with try to fetch 64 bits from
where userland put only 32. It probbaly works on little-endian
architectures by chance, but won't on big endian.
Does the version of the patch below work for you?
Thanks.
--
Dmitry
Input: serport - add compat handling for SPIOCSTYPE ioctl
From: John Sung <penmount.touch@gmail.com>
When running a 32-bit inputattach utility in a 64-bit system, there will be
error code "inputattach: can't set device type". This is caused by the
serport device driver not supporting compat_ioctl, so that SPIOCSTYPE ioctl
fails.
Signed-off-by: John Sung <penmount.touch@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/serio/serport.c | 45 +++++++++++++++++++++++++++++++++++------
1 file changed, 38 insertions(+), 7 deletions(-)
diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
index 0cb7ef5..69175b8 100644
--- a/drivers/input/serio/serport.c
+++ b/drivers/input/serio/serport.c
@@ -21,6 +21,7 @@
#include <linux/init.h>
#include <linux/serio.h>
#include <linux/tty.h>
+#include <linux/compat.h>
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
MODULE_DESCRIPTION("Input device TTY line discipline");
@@ -198,28 +199,55 @@ static ssize_t serport_ldisc_read(struct tty_struct * tty, struct file * file, u
return 0;
}
+static void serport_set_type(struct tty_struct *tty, unsigned long type)
+{
+ struct serport *serport = tty->disc_data;
+
+ serport->id.proto = type & 0x000000ff;
+ serport->id.id = (type & 0x0000ff00) >> 8;
+ serport->id.extra = (type & 0x00ff0000) >> 16;
+}
+
/*
* serport_ldisc_ioctl() allows to set the port protocol, and device ID
*/
-static int serport_ldisc_ioctl(struct tty_struct * tty, struct file * file, unsigned int cmd, unsigned long arg)
+static int serport_ldisc_ioctl(struct tty_struct *tty, struct file *file,
+ unsigned int cmd, unsigned long arg)
{
- struct serport *serport = (struct serport*) tty->disc_data;
- unsigned long type;
-
if (cmd == SPIOCSTYPE) {
+ unsigned long type;
+
if (get_user(type, (unsigned long __user *) arg))
return -EFAULT;
- serport->id.proto = type & 0x000000ff;
- serport->id.id = (type & 0x0000ff00) >> 8;
- serport->id.extra = (type & 0x00ff0000) >> 16;
+ serport_set_type(tty, type);
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
+#ifdef CONFIG_COMPAT
+#define COMPAT_SPIOCSTYPE _IOW('q', 0x01, compat_ulong_t)
+static long serport_ldisc_compat_ioctl(struct tty_struct *tty,
+ struct file *file,
+ unsigned int cmd, unsigned long arg)
+{
+ if (cmd == COMPAT_SPIOCSTYPE) {
+ void __user *uarg = compat_ptr(arg);
+ compat_ulong_t compat_type;
+
+ if (get_user(compat_type, (compat_ulong_t __user *)uarg))
+ return -EFAULT;
+ serport_set_type(tty, compat_type);
return 0;
}
return -EINVAL;
}
+#endif
static void serport_ldisc_write_wakeup(struct tty_struct * tty)
{
@@ -243,6 +271,9 @@ static struct tty_ldisc_ops serport_ldisc = {
.close = serport_ldisc_close,
.read = serport_ldisc_read,
.ioctl = serport_ldisc_ioctl,
+#ifdef CONFIG_COMPAT
+ .compat_ioctl = serport_ldisc_compat_ioctl,
+#endif
.receive_buf = serport_ldisc_receive,
.write_wakeup = serport_ldisc_write_wakeup
};
^ permalink raw reply related
* Re: [PATCH] Input:wm971x: Fix typo in module param description of wm971[23].c
From: Dmitry Torokhov @ 2014-09-09 18:23 UTC (permalink / raw)
To: Masanari Iida; +Cc: linux-kernel, broonie, linux-input, lrg, rdunlap
In-Reply-To: <1410260568-13955-1-git-send-email-standby24x7@gmail.com>
On Tue, Sep 09, 2014 at 08:02:48PM +0900, Masanari Iida wrote:
> This patch fix spelling typo in module parameter
> description of wm9712.c and wm9713.c
>
> Signed-off-by: Masanari Iida <standby24x7@gmail.com>
Applied, thank you.
> ---
> drivers/input/touchscreen/wm9712.c | 2 +-
> drivers/input/touchscreen/wm9713.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/touchscreen/wm9712.c b/drivers/input/touchscreen/wm9712.c
> index 16b5211..705ffa1 100644
> --- a/drivers/input/touchscreen/wm9712.c
> +++ b/drivers/input/touchscreen/wm9712.c
> @@ -41,7 +41,7 @@
> */
> static int rpu = 8;
> module_param(rpu, int, 0);
> -MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect.");
> +MODULE_PARM_DESC(rpu, "Set internal pull up resistor for pen detect.");
>
> /*
> * Set current used for pressure measurement.
> diff --git a/drivers/input/touchscreen/wm9713.c b/drivers/input/touchscreen/wm9713.c
> index 7405353..572a5a6 100644
> --- a/drivers/input/touchscreen/wm9713.c
> +++ b/drivers/input/touchscreen/wm9713.c
> @@ -41,7 +41,7 @@
> */
> static int rpu = 8;
> module_param(rpu, int, 0);
> -MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect.");
> +MODULE_PARM_DESC(rpu, "Set internal pull up resistor for pen detect.");
>
> /*
> * Set current used for pressure measurement.
> --
> 2.1.0.60.g85f0837
>
--
Dmitry
^ permalink raw reply
* Re: [PATCH] Input: synaptics - add support for ForcePads
From: Hans de Goede @ 2014-09-09 19:29 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: linux-input, Benjamin Tissoires, Christopher Heiny, linux-kernel,
Andrew Duggan
In-Reply-To: <20140909170636.GA28774@core.coreip.homeip.net>
Hi,
On 09/09/2014 07:06 PM, Dmitry Torokhov wrote:
> On Tue, Sep 09, 2014 at 09:44:17AM +0200, Hans de Goede wrote:
>> Hi,
>>
>> On 09/08/2014 06:55 PM, Dmitry Torokhov wrote:
>>> ForcePads are found on HP EliteBook 1040 laptops. They lack any kind of
>>> physical buttons, instead they generate primary button click when user
>>> presses somewhat hard on the surface of the touchpad. Unfortunately they
>>> also report primary button click whenever there are 2 or more contacts
>>> on the pad, messing up all multi-finger gestures (2-finger scrolling,
>>> multi-finger tapping, etc). To cope with this behavior we introduce a
>>> delay (currently 50 msecs) in reporting primary press in case more
>>> contacts appear.
>>>
>>> For now we are using DMI matching to detect ForcePads, hopefully we'll
>>> be able to figure a better way down the road.
>>
>> What about using the pnp-id, in my experience with the recent lenovo
>> laptops that tends to be more reliable.
>
> Not sure. So far I only know of HP 1040 having it. FWIW:
>
> dtor@dtor-glaptop:~$ cat /sys/bus/pnp/drivers/i8042\ aux/00\:07/id
> SYN300d
> SYN0100
> SYN0002
> PNP0f13
Hmm, those look pretty generic. Maybe the 300d is specific.
> I think if we see generalities we can switch over later. I hope
> Chris/Andrew will come with a capability bit though :)
>
>>
>> Christopher, Andrew (added to the CC), can one of you tell us if there
>> is a capability bit to detect this, and if not can you perhaps provide
>> a list of pnp-ids of devices which behave like this ?
>>
>>> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>>> ---
>>> drivers/input/mouse/synaptics.c | 80 ++++++++++++++++++++++++++++++++---------
>>> drivers/input/mouse/synaptics.h | 5 +++
>>> 2 files changed, 69 insertions(+), 16 deletions(-)
>>>
>>> diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
>>> index e8573c6..5de1bb6 100644
>>> --- a/drivers/input/mouse/synaptics.c
>>> +++ b/drivers/input/mouse/synaptics.c
>>> @@ -618,6 +618,8 @@ static void synaptics_parse_agm(const unsigned char buf[],
>>> priv->agm_pending = true;
>>> }
>>>
>>> +static bool is_forcepad;
>>> +
>>> static int synaptics_parse_hw_state(const unsigned char buf[],
>>> struct synaptics_data *priv,
>>> struct synaptics_hw_state *hw)
>>> @@ -629,10 +631,58 @@ static int synaptics_parse_hw_state(const unsigned char buf[],
>>> ((buf[0] & 0x04) >> 1) |
>>> ((buf[3] & 0x04) >> 2));
>>>
>>> + if ((SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
>>> + SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) &&
>>> + hw->w == 2) {
>>> + synaptics_parse_agm(buf, priv, hw);
>>> + return 1;
>>> + }
>>> +
>>> + hw->x = (((buf[3] & 0x10) << 8) |
>>> + ((buf[1] & 0x0f) << 8) |
>>> + buf[4]);
>>> + hw->y = (((buf[3] & 0x20) << 7) |
>>> + ((buf[1] & 0xf0) << 4) |
>>> + buf[5]);
>>> + hw->z = buf[2];
>>> +
>>> hw->left = (buf[0] & 0x01) ? 1 : 0;
>>> hw->right = (buf[0] & 0x02) ? 1 : 0;
>>>
>>
>> Moving this up means that on clickpads the button will no longer
>> be checked + set for hw->w == 2 packets. That seems like an unintended
>> side effect.
>
> I guess we can call it a side effect, but it is fine - we parse AGM and
> stash the data, then when 2nd packet comes we parse and act upon it. In
> the old code we'd parse x, y, z, in AGM etc. and then have it
> overwritten with the data from the 2nd packet, here we do not bother.
>
>> If this is intended then this should probably be in its own
>> patch.
>
> It does not make sense on its own as ForcePad support needs to know
> values of Z and W when deciding how to handle primary click, otherwise
> the old code was just fine.
Ok.
>
>>
>>> - if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
>>> + if (is_forcepad) {
>>> + /* XXX is there a proper capability bit for this? */
>>> + /*
>>> + * ForcePads, like Clickpads, use middle button
>>> + * bits to report primary button clicks.
>>> + * Unfortunately they report primary button not only
>>> + * when user presses on the pad above certain threshold,
>>> + * but also when there are more than one finger on the
>>> + * touchpad, which interferes with out multi-finger
>>> + * gestures.
>>> + */
>>> + if (hw->z == 0) {
>>> + /* No contacts */
>>> + priv->press = priv->report_press = false;
>>> + } else if (hw->w >= 4 && ((buf[0] ^ buf[3]) & 0x01)) {
>>> + /*
>>> + * Single-finger touch with pressure above
>>> + * the threshold.
>>> + */
>>> + if (!priv->press) {
>>> + priv->press_start = jiffies;
>>> + priv->press = true;
>>> + } else if (time_after(jiffies,
>>> + priv->press_start +
>>> + msecs_to_jiffies(50))) {
>>> + priv->report_press = true;
>>> + }
>>
>> You're not setting a timer here, instead relying on there to be further events,
>> that is probably ok, but maybe put a comment to that extent here ?
>
> I can, any suggestion on what you want me to say? "If single point
> contact held pressure long enough start reporting primary click"?
What I mean is that this will not work if the finger is held perfectly still,
at least AFAIK no more packets will be send in that case, but maybe that is
me thinking too much in userspace terms where no evdev events will be
generated in that case. If the touchpad will continue repeating events with
exact the same location + pressure, then there is nothing to worry about
and you can ignore my request for a comment.
Regards,
Hans
^ permalink raw reply
* Re: [PATCH] Input: matrix_keypad - make driver useable with GPIO drivers requiring threaded irqs
From: Dmitry Torokhov @ 2014-09-09 21:42 UTC (permalink / raw)
To: Lothar Waßmann; +Cc: linux-input, linux-kernel, Paul Gortmaker
In-Reply-To: <1410251584-5031-1-git-send-email-LW@KARO-electronics.de>
On Tue, Sep 09, 2014 at 10:33:04AM +0200, Lothar Waßmann wrote:
> When trying to use the matrix-keypad driver with GPIO drivers that
> require nested irq handlers (e.g. I2C GPIO adapters like PCA9554),
> request_irq() fails because the GPIO driver requires a threaded
> interrupt handler.
>
> Use request_any_context_irq() to be able to use any GPIO driver as
> keypad driver.
>
> Signed-off-by: Lothar Waßmann <LW@KARO-electronics.de>
Applied, thank you.
> ---
> drivers/input/keyboard/matrix_keypad.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
> index 8d2e19e..e651fa6 100644
> --- a/drivers/input/keyboard/matrix_keypad.c
> +++ b/drivers/input/keyboard/matrix_keypad.c
> @@ -332,23 +332,24 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,
> }
>
> if (pdata->clustered_irq > 0) {
> - err = request_irq(pdata->clustered_irq,
> + err = request_any_context_irq(pdata->clustered_irq,
> matrix_keypad_interrupt,
> pdata->clustered_irq_flags,
> "matrix-keypad", keypad);
> - if (err) {
> + if (err < 0) {
> dev_err(&pdev->dev,
> "Unable to acquire clustered interrupt\n");
> goto err_free_rows;
> }
> } else {
> for (i = 0; i < pdata->num_row_gpios; i++) {
> - err = request_irq(gpio_to_irq(pdata->row_gpios[i]),
> + err = request_any_context_irq(
> + gpio_to_irq(pdata->row_gpios[i]),
> matrix_keypad_interrupt,
> IRQF_TRIGGER_RISING |
> IRQF_TRIGGER_FALLING,
> "matrix-keypad", keypad);
> - if (err) {
> + if (err < 0) {
> dev_err(&pdev->dev,
> "Unable to acquire interrupt for GPIO line %i\n",
> pdata->row_gpios[i]);
> --
> 1.7.10.4
>
--
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply
* Re: [PATCH] Input: synaptics - add support for ForcePads
From: Andrew Duggan @ 2014-09-09 22:07 UTC (permalink / raw)
To: Dmitry Torokhov, Hans de Goede
Cc: linux-input, Benjamin Tissoires, Christopher Heiny, linux-kernel
In-Reply-To: <20140909170636.GA28774@core.coreip.homeip.net>
On 09/09/2014 10:06 AM, Dmitry Torokhov wrote:
> On Tue, Sep 09, 2014 at 09:44:17AM +0200, Hans de Goede wrote:
>> Hi,
>>
>> On 09/08/2014 06:55 PM, Dmitry Torokhov wrote:
>>> ForcePads are found on HP EliteBook 1040 laptops. They lack any kind of
>>> physical buttons, instead they generate primary button click when user
>>> presses somewhat hard on the surface of the touchpad. Unfortunately they
>>> also report primary button click whenever there are 2 or more contacts
>>> on the pad, messing up all multi-finger gestures (2-finger scrolling,
>>> multi-finger tapping, etc). To cope with this behavior we introduce a
>>> delay (currently 50 msecs) in reporting primary press in case more
>>> contacts appear.
>>>
>>> For now we are using DMI matching to detect ForcePads, hopefully we'll
>>> be able to figure a better way down the road.
>> What about using the pnp-id, in my experience with the recent lenovo
>> laptops that tends to be more reliable.
> Not sure. So far I only know of HP 1040 having it. FWIW:
>
> dtor@dtor-glaptop:~$ cat /sys/bus/pnp/drivers/i8042\ aux/00\:07/id
> SYN300d
> SYN0100
> SYN0002
> PNP0f13
>
> I think if we see generalities we can switch over later. I hope
> Chris/Andrew will come with a capability bit though :)
The ForcePad capabilities bit is 1 << 15.
>
>> Christopher, Andrew (added to the CC), can one of you tell us if there
>> is a capability bit to detect this, and if not can you perhaps provide
>> a list of pnp-ids of devices which behave like this ?
>>
>>> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>>> ---
>>> drivers/input/mouse/synaptics.c | 80 ++++++++++++++++++++++++++++++++---------
>>> drivers/input/mouse/synaptics.h | 5 +++
>>> 2 files changed, 69 insertions(+), 16 deletions(-)
>>>
>>> diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
>>> index e8573c6..5de1bb6 100644
>>> --- a/drivers/input/mouse/synaptics.c
>>> +++ b/drivers/input/mouse/synaptics.c
>>> @@ -618,6 +618,8 @@ static void synaptics_parse_agm(const unsigned char buf[],
>>> priv->agm_pending = true;
>>> }
>>>
>>> +static bool is_forcepad;
>>> +
>>> static int synaptics_parse_hw_state(const unsigned char buf[],
>>> struct synaptics_data *priv,
>>> struct synaptics_hw_state *hw)
>>> @@ -629,10 +631,58 @@ static int synaptics_parse_hw_state(const unsigned char buf[],
>>> ((buf[0] & 0x04) >> 1) |
>>> ((buf[3] & 0x04) >> 2));
>>>
>>> + if ((SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
>>> + SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) &&
>>> + hw->w == 2) {
>>> + synaptics_parse_agm(buf, priv, hw);
>>> + return 1;
>>> + }
>>> +
>>> + hw->x = (((buf[3] & 0x10) << 8) |
>>> + ((buf[1] & 0x0f) << 8) |
>>> + buf[4]);
>>> + hw->y = (((buf[3] & 0x20) << 7) |
>>> + ((buf[1] & 0xf0) << 4) |
>>> + buf[5]);
>>> + hw->z = buf[2];
>>> +
>>> hw->left = (buf[0] & 0x01) ? 1 : 0;
>>> hw->right = (buf[0] & 0x02) ? 1 : 0;
>>>
>> Moving this up means that on clickpads the button will no longer
>> be checked + set for hw->w == 2 packets. That seems like an unintended
>> side effect.
> I guess we can call it a side effect, but it is fine - we parse AGM and
> stash the data, then when 2nd packet comes we parse and act upon it. In
> the old code we'd parse x, y, z, in AGM etc. and then have it
> overwritten with the data from the 2nd packet, here we do not bother.
>
>> If this is intended then this should probably be in its own
>> patch.
> It does not make sense on its own as ForcePad support needs to know
> values of Z and W when deciding how to handle primary click, otherwise
> the old code was just fine.
>
>>> - if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
>>> + if (is_forcepad) {
>>> + /* XXX is there a proper capability bit for this? */
>>> + /*
>>> + * ForcePads, like Clickpads, use middle button
>>> + * bits to report primary button clicks.
>>> + * Unfortunately they report primary button not only
>>> + * when user presses on the pad above certain threshold,
>>> + * but also when there are more than one finger on the
>>> + * touchpad, which interferes with out multi-finger
>>> + * gestures.
>>> + */
>>> + if (hw->z == 0) {
>>> + /* No contacts */
>>> + priv->press = priv->report_press = false;
>>> + } else if (hw->w >= 4 && ((buf[0] ^ buf[3]) & 0x01)) {
>>> + /*
>>> + * Single-finger touch with pressure above
>>> + * the threshold.
>>> + */
>>> + if (!priv->press) {
>>> + priv->press_start = jiffies;
>>> + priv->press = true;
>>> + } else if (time_after(jiffies,
>>> + priv->press_start +
>>> + msecs_to_jiffies(50))) {
>>> + priv->report_press = true;
>>> + }
>> You're not setting a timer here, instead relying on there to be further events,
>> that is probably ok, but maybe put a comment to that extent here ?
> I can, any suggestion on what you want me to say? "If single point
> contact held pressure long enough start reporting primary click"?
>
> Thanks.
>
^ permalink raw reply
* Re: [PATCH] Input: synaptics - add support for ForcePads
From: Dmitry Torokhov @ 2014-09-09 22:57 UTC (permalink / raw)
To: Andrew Duggan
Cc: Hans de Goede, linux-input, Benjamin Tissoires, Christopher Heiny,
linux-kernel
In-Reply-To: <540F7A19.3070704@synaptics.com>
On Tue, Sep 09, 2014 at 03:07:21PM -0700, Andrew Duggan wrote:
> On 09/09/2014 10:06 AM, Dmitry Torokhov wrote:
> >On Tue, Sep 09, 2014 at 09:44:17AM +0200, Hans de Goede wrote:
> >>Hi,
> >>
> >>On 09/08/2014 06:55 PM, Dmitry Torokhov wrote:
> >>>ForcePads are found on HP EliteBook 1040 laptops. They lack any kind of
> >>>physical buttons, instead they generate primary button click when user
> >>>presses somewhat hard on the surface of the touchpad. Unfortunately they
> >>>also report primary button click whenever there are 2 or more contacts
> >>>on the pad, messing up all multi-finger gestures (2-finger scrolling,
> >>>multi-finger tapping, etc). To cope with this behavior we introduce a
> >>>delay (currently 50 msecs) in reporting primary press in case more
> >>>contacts appear.
> >>>
> >>>For now we are using DMI matching to detect ForcePads, hopefully we'll
> >>>be able to figure a better way down the road.
> >>What about using the pnp-id, in my experience with the recent lenovo
> >>laptops that tends to be more reliable.
> >Not sure. So far I only know of HP 1040 having it. FWIW:
> >
> >dtor@dtor-glaptop:~$ cat /sys/bus/pnp/drivers/i8042\ aux/00\:07/id
> >SYN300d
> >SYN0100
> >SYN0002
> >PNP0f13
> >
> >I think if we see generalities we can switch over later. I hope
> >Chris/Andrew will come with a capability bit though :)
>
> The ForcePad capabilities bit is 1 << 15.
Awesome, thanks!
Then I guess the patch below is what we'll be needing for these devices.
Thanks.
--
Dmitry
Input: synaptics - add support for ForcePads
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
ForcePads are found on HP EliteBook 1040 laptops. They lack any kind of
physical buttons, instead they generate primary button click when user
presses somewhat hard on the surface of the touchpad. Unfortunately they
also report primary button click whenever there are 2 or more contacts
on the pad, messing up all multi-finger gestures (2-finger scrolling,
multi-finger tapping, etc). To cope with this behavior we introduce a
delay (currently 50 msecs) in reporting primary press in case more
contacts appear.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/mouse/synaptics.c | 68 ++++++++++++++++++++++++++++++---------
drivers/input/mouse/synaptics.h | 11 ++++++
2 files changed, 63 insertions(+), 16 deletions(-)
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index e8573c6..fd23181 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -629,10 +629,61 @@ static int synaptics_parse_hw_state(const unsigned char buf[],
((buf[0] & 0x04) >> 1) |
((buf[3] & 0x04) >> 2));
+ if ((SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
+ SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) &&
+ hw->w == 2) {
+ synaptics_parse_agm(buf, priv, hw);
+ return 1;
+ }
+
+ hw->x = (((buf[3] & 0x10) << 8) |
+ ((buf[1] & 0x0f) << 8) |
+ buf[4]);
+ hw->y = (((buf[3] & 0x20) << 7) |
+ ((buf[1] & 0xf0) << 4) |
+ buf[5]);
+ hw->z = buf[2];
+
hw->left = (buf[0] & 0x01) ? 1 : 0;
hw->right = (buf[0] & 0x02) ? 1 : 0;
- if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
+ if (SYN_CAP_FORCEPAD(priv->ext_cap_0c)) {
+ /*
+ * ForcePads, like Clickpads, use middle button
+ * bits to report primary button clicks.
+ * Unfortunately they report primary button not
+ * only when user presses on the pad above certain
+ * threshold, but also when there are more than one
+ * finger on the touchpad, which interferes with
+ * out multi-finger gestures.
+ */
+ if (hw->z == 0) {
+ /* No contacts */
+ priv->press = priv->report_press = false;
+ } else if (hw->w >= 4 && ((buf[0] ^ buf[3]) & 0x01)) {
+ /*
+ * Single-finger touch with pressure above
+ * the threshold. If pressure stays long
+ * enough, we'll start reporting primary
+ * button. We rely on the device continuing
+ * sending data even if finger does not
+ * move.
+ */
+ if (!priv->press) {
+ priv->press_start = jiffies;
+ priv->press = true;
+ } else if (time_after(jiffies,
+ priv->press_start +
+ msecs_to_jiffies(50))) {
+ priv->report_press = true;
+ }
+ } else {
+ priv->press = false;
+ }
+
+ hw->left = priv->report_press;
+
+ } else if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
/*
* Clickpad's button is transmitted as middle button,
* however, since it is primary button, we will report
@@ -651,21 +702,6 @@ static int synaptics_parse_hw_state(const unsigned char buf[],
hw->down = ((buf[0] ^ buf[3]) & 0x02) ? 1 : 0;
}
- if ((SYN_CAP_ADV_GESTURE(priv->ext_cap_0c) ||
- SYN_CAP_IMAGE_SENSOR(priv->ext_cap_0c)) &&
- hw->w == 2) {
- synaptics_parse_agm(buf, priv, hw);
- return 1;
- }
-
- hw->x = (((buf[3] & 0x10) << 8) |
- ((buf[1] & 0x0f) << 8) |
- buf[4]);
- hw->y = (((buf[3] & 0x20) << 7) |
- ((buf[1] & 0xf0) << 4) |
- buf[5]);
- hw->z = buf[2];
-
if (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) &&
((buf[0] ^ buf[3]) & 0x02)) {
switch (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) & ~0x01) {
diff --git a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h
index e594af0..fb2e076 100644
--- a/drivers/input/mouse/synaptics.h
+++ b/drivers/input/mouse/synaptics.h
@@ -78,6 +78,11 @@
* 2 0x08 image sensor image sensor tracks 5 fingers, but only
* reports 2.
* 2 0x20 report min query 0x0f gives min coord reported
+ * 2 0x80 forcepad forcepad is a variant of clickpad that
+ * does not have physical buttons but rather
+ * uses pressure above certain threshold to
+ * report primary clicks. Forcepads also have
+ * clickpad bit set.
*/
#define SYN_CAP_CLICKPAD(ex0c) ((ex0c) & 0x100000) /* 1-button ClickPad */
#define SYN_CAP_CLICKPAD2BTN(ex0c) ((ex0c) & 0x000100) /* 2-button ClickPad */
@@ -86,6 +91,7 @@
#define SYN_CAP_ADV_GESTURE(ex0c) ((ex0c) & 0x080000)
#define SYN_CAP_REDUCED_FILTERING(ex0c) ((ex0c) & 0x000400)
#define SYN_CAP_IMAGE_SENSOR(ex0c) ((ex0c) & 0x000800)
+#define SYN_CAP_FORCEPAD(ex0c) ((ex0c) & 0x008000)
/* synaptics modes query bits */
#define SYN_MODE_ABSOLUTE(m) ((m) & (1 << 7))
@@ -177,6 +183,11 @@ struct synaptics_data {
*/
struct synaptics_hw_state agm;
bool agm_pending; /* new AGM packet received */
+
+ /* ForcePad handling */
+ unsigned long press_start;
+ bool press;
+ bool report_press;
};
void synaptics_module_init(void);
^ permalink raw reply related
* Re: [PATCH] Input: synaptics - add support for ForcePads
From: Hans de Goede @ 2014-09-09 23:07 UTC (permalink / raw)
To: Dmitry Torokhov, Andrew Duggan
Cc: linux-input, Benjamin Tissoires, Christopher Heiny, linux-kernel
In-Reply-To: <20140909225725.GA18901@core.coreip.homeip.net>
Hi,
On 09/10/2014 12:57 AM, Dmitry Torokhov wrote:
> On Tue, Sep 09, 2014 at 03:07:21PM -0700, Andrew Duggan wrote:
>> On 09/09/2014 10:06 AM, Dmitry Torokhov wrote:
>>> On Tue, Sep 09, 2014 at 09:44:17AM +0200, Hans de Goede wrote:
>>>> Hi,
>>>>
>>>> On 09/08/2014 06:55 PM, Dmitry Torokhov wrote:
>>>>> ForcePads are found on HP EliteBook 1040 laptops. They lack any kind of
>>>>> physical buttons, instead they generate primary button click when user
>>>>> presses somewhat hard on the surface of the touchpad. Unfortunately they
>>>>> also report primary button click whenever there are 2 or more contacts
>>>>> on the pad, messing up all multi-finger gestures (2-finger scrolling,
>>>>> multi-finger tapping, etc). To cope with this behavior we introduce a
>>>>> delay (currently 50 msecs) in reporting primary press in case more
>>>>> contacts appear.
>>>>>
>>>>> For now we are using DMI matching to detect ForcePads, hopefully we'll
>>>>> be able to figure a better way down the road.
>>>> What about using the pnp-id, in my experience with the recent lenovo
>>>> laptops that tends to be more reliable.
>>> Not sure. So far I only know of HP 1040 having it. FWIW:
>>>
>>> dtor@dtor-glaptop:~$ cat /sys/bus/pnp/drivers/i8042\ aux/00\:07/id
>>> SYN300d
>>> SYN0100
>>> SYN0002
>>> PNP0f13
>>>
>>> I think if we see generalities we can switch over later. I hope
>>> Chris/Andrew will come with a capability bit though :)
>>
>> The ForcePad capabilities bit is 1 << 15.
>
> Awesome, thanks!
>
> Then I guess the patch below is what we'll be needing for these devices.
Yep, the patch looks good to me.
Regards,
Hans
^ permalink raw reply
* Re: [PATCH] Input: synaptics - add support for ForcePads
From: Dmitry Torokhov @ 2014-09-09 23:15 UTC (permalink / raw)
To: Hans de Goede
Cc: Andrew Duggan, linux-input, Benjamin Tissoires, Christopher Heiny,
linux-kernel
In-Reply-To: <540F8816.5080908@redhat.com>
On Wed, Sep 10, 2014 at 01:07:02AM +0200, Hans de Goede wrote:
> Hi,
>
> On 09/10/2014 12:57 AM, Dmitry Torokhov wrote:
> > On Tue, Sep 09, 2014 at 03:07:21PM -0700, Andrew Duggan wrote:
> >> On 09/09/2014 10:06 AM, Dmitry Torokhov wrote:
> >>> On Tue, Sep 09, 2014 at 09:44:17AM +0200, Hans de Goede wrote:
> >>>> Hi,
> >>>>
> >>>> On 09/08/2014 06:55 PM, Dmitry Torokhov wrote:
> >>>>> ForcePads are found on HP EliteBook 1040 laptops. They lack any kind of
> >>>>> physical buttons, instead they generate primary button click when user
> >>>>> presses somewhat hard on the surface of the touchpad. Unfortunately they
> >>>>> also report primary button click whenever there are 2 or more contacts
> >>>>> on the pad, messing up all multi-finger gestures (2-finger scrolling,
> >>>>> multi-finger tapping, etc). To cope with this behavior we introduce a
> >>>>> delay (currently 50 msecs) in reporting primary press in case more
> >>>>> contacts appear.
> >>>>>
> >>>>> For now we are using DMI matching to detect ForcePads, hopefully we'll
> >>>>> be able to figure a better way down the road.
> >>>> What about using the pnp-id, in my experience with the recent lenovo
> >>>> laptops that tends to be more reliable.
> >>> Not sure. So far I only know of HP 1040 having it. FWIW:
> >>>
> >>> dtor@dtor-glaptop:~$ cat /sys/bus/pnp/drivers/i8042\ aux/00\:07/id
> >>> SYN300d
> >>> SYN0100
> >>> SYN0002
> >>> PNP0f13
> >>>
> >>> I think if we see generalities we can switch over later. I hope
> >>> Chris/Andrew will come with a capability bit though :)
> >>
> >> The ForcePad capabilities bit is 1 << 15.
> >
> > Awesome, thanks!
> >
> > Then I guess the patch below is what we'll be needing for these devices.
>
> Yep, the patch looks good to me.
Thanks, I'll put you down as reviewed-by then.
--
Dmitry
^ permalink raw reply
* Re: [PATCH 1/2] Input: atmel_mxt_ts - downgrade warning about empty interrupts
From: Dmitry Torokhov @ 2014-09-09 23:40 UTC (permalink / raw)
To: nick.dyer
Cc: Stephen Warren, Yufeng Shen, Daniel Kurtz, Henrik Rydberg,
Joonyoung Shim, Alan Bowens, linux-input, linux-kernel,
Peter Meerwald, Benson Leung, Olof Johansson, Sekhar Nori
In-Reply-To: <1410274249-3469-2-git-send-email-nick.dyer@itdev.co.uk>
On Tue, Sep 09, 2014 at 03:50:48PM +0100, nick.dyer@itdev.co.uk wrote:
> From: Nick Dyer <nick.dyer@itdev.co.uk>
>
> In the case where the CHG/interrupt line mode is not configured correctly,
> this warning is output to dmesg output for each interrupt. Downgrade the
> message to debug.
>
> Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Applied, thank you.
> ---
> drivers/input/touchscreen/atmel_mxt_ts.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
> index db178ed..d954b81 100644
> --- a/drivers/input/touchscreen/atmel_mxt_ts.c
> +++ b/drivers/input/touchscreen/atmel_mxt_ts.c
> @@ -837,7 +837,12 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data)
> count = data->msg_buf[0];
>
> if (count == 0) {
> - dev_warn(dev, "Interrupt triggered but zero messages\n");
> + /*
> + * This condition is caused by the CHG line being configured
> + * in Mode 0. It results in unnecessary I2C operations but it
> + * is benign.
> + */
> + dev_dbg(dev, "Interrupt triggered but zero messages\n");
> return IRQ_NONE;
> } else if (count > data->max_reportid) {
> dev_err(dev, "T44 count %d exceeded max report id\n", count);
> --
> 1.9.1
>
--
Dmitry
^ permalink raw reply
* Re: [PATCH 2/2] Input: atmel_mxt_ts - fix double free of input device
From: Dmitry Torokhov @ 2014-09-09 23:49 UTC (permalink / raw)
To: nick.dyer
Cc: Stephen Warren, Yufeng Shen, Daniel Kurtz, Henrik Rydberg,
Joonyoung Shim, Alan Bowens, linux-input, linux-kernel,
Peter Meerwald, Benson Leung, Olof Johansson, Sekhar Nori
In-Reply-To: <1410274249-3469-3-git-send-email-nick.dyer@itdev.co.uk>
On Tue, Sep 09, 2014 at 03:50:49PM +0100, nick.dyer@itdev.co.uk wrote:
> From: Stephen Warren <swarren@wwwdotorg.org>
>
> [reworked after comments by Dmitry Torokhov. Move free of input device into
> separate function. Only call in paths that require it. Move mxt_initialize
> after sysfs init, because otherwise an error in the sysfs init may interfere
> with the async return from the firmware loader. Add guards for sysfs
> functions. ]
Ugh... there is still problem with asycn firmware loading: you need to
make sure it is done before you try to unbind the dveice. I also do not
see what stops several firmware update requests to happen
simultaneously. Once you add proper handling for that you can use the
same lock in sysfs read methods.
Another option is wait a bit and see what's the outcome of async probing
discussion on LKML is and maybe we can stop using
request_firmware_nowait() in probe path but rather have device core fire
off probe asynchronously.
I'd rather have fix for input device freeing be separate from
sysfs/firmware/config loading changes.
Thanks.
--
Dmitry
^ permalink raw reply
* [PATCH v6 01/13] input: cyapa: re-architecture driver to support
From: Dudley Du @ 2014-09-10 4:34 UTC (permalink / raw)
To: dmitry.torokhov, rydberg; +Cc: bleung, patrikf, linux-input, linux-kernel
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 | 1120 +++++++++++++++---------------------------
drivers/input/mouse/cyapa.h | 275 +++++++++++
3 files changed, 682 insertions(+), 717 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..3edd23e 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,461 +14,301 @@
* 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)"
+#define CYAPA_ADAPTER_FUNC_NONE 0
+#define CYAPA_ADAPTER_FUNC_I2C 1
+#define CYAPA_ADAPTER_FUNC_SMBUS 2
+#define CYAPA_ADAPTER_FUNC_BOTH 3
-/* 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
+#define CYAPA_DEBUGFS_READ_FW "read_fw"
+#define CYAPA_DEBUGFS_RAW_DATA "raw_data"
+#define CYAPA_FW_NAME "cyapa.bin"
-/* report data start reg offset address. */
-#define DATA_REG_START_OFFSET 0x0000
+const char unique_str[] = "CYTRA";
-#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)
+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);
+}
-/*
- * 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
+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);
+}
-/*
- * Bootloader Error Register
+/* 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;
+ struct i2c_client *client = cyapa->client;
+ struct i2c_msg msgs[] = {
+ {
+ .addr = client->addr,
+ .flags = 0,
+ .len = 1,
+ .buf = ®,
+ },
+ {
+ .addr = client->addr,
+ .flags = I2C_M_RD,
+ .len = len,
+ .buf = values,
+ },
+ };
+
+ ret = i2c_transfer(client->adapter, msgs, 2);
+
+ if (ret != ARRAY_SIZE(msgs))
+ return ret < 0 ? ret : -EIO;
+
+ return 0;
+}
+
+/**
+ * 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
*
- * 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
+ * Return negative errno code on error; return zero when success.
*/
-#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)
+ssize_t cyapa_i2c_write(struct cyapa *cyapa, u8 reg,
+ size_t len, const void *values)
+{
+ int ret;
+ struct i2c_client *client = cyapa->client;
+ char data[32], *buf;
-/*
- * 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,
-};
+ if (len > 31)
+ buf = kzalloc(len + 1, GFP_KERNEL);
+ else
+ buf = data;
+ buf[0] = reg;
+ memcpy(&buf[1], values, len);
+ ret = i2c_master_send(client, buf, len + 1);
-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;
+ if (buf != data)
+ kfree(buf);
+ return (ret == (len + 1)) ? 0 : ((ret < 0) ? ret : -EIO);
+}
+
+void cyapa_default_irq_handler(struct cyapa *cyapa)
+{
/*
- * 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
+ * Do redetecting when device states is still unknown and
+ * interrupt envent is received from device.
*/
- u8 finger_btn;
- /* CYAPA reports up to 5 touches per packet. */
- struct cyapa_touch touches[5];
-} __packed;
+ async_schedule(cyapa_detect_async, cyapa);
+}
+
+const struct cyapa_dev_ops cyapa_default_ops = {
+ .irq_handler = cyapa_default_irq_handler
+};
+
+
+static u8 cyapa_check_adapter_functionality(struct i2c_client *client)
+{
+ u8 ret = CYAPA_ADAPTER_FUNC_NONE;
-/* The main device structure */
-struct cyapa {
- enum cyapa_state state;
+ if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+ ret |= CYAPA_ADAPTER_FUNC_I2C;
+ if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA |
+ I2C_FUNC_SMBUS_BLOCK_DATA |
+ I2C_FUNC_SMBUS_I2C_BLOCK))
+ ret |= CYAPA_ADAPTER_FUNC_SMBUS;
+ return ret;
+}
- struct i2c_client *client;
+static int cyapa_create_input_dev(struct cyapa *cyapa)
+{
+ struct device *dev = &cyapa->client->dev;
+ int ret;
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 };
+ if (!cyapa->physical_size_x || !cyapa->physical_size_y)
+ return -EINVAL;
-struct cyapa_cmd_len {
- u8 cmd;
- u8 len;
-};
+ input = cyapa->input = input_allocate_device();
+ if (!input) {
+ dev_err(dev, "allocate memory for input device failed\n");
+ return -ENOMEM;
+ }
-#define CYAPA_ADAPTER_FUNC_NONE 0
-#define CYAPA_ADAPTER_FUNC_I2C 1
-#define CYAPA_ADAPTER_FUNC_SMBUS 2
-#define CYAPA_ADAPTER_FUNC_BOTH 3
+ input->name = CYAPA_NAME;
+ input->phys = cyapa->phys;
+ input->id.bustype = BUS_I2C;
+ input->id.version = 1;
+ input->id.product = 0; /* Means any product in eventcomm. */
+ input->dev.parent = &cyapa->client->dev;
-/*
- * 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 }
-};
+ input_set_drvdata(input, cyapa);
-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 },
-};
+ __set_bit(EV_ABS, input->evbit);
-static 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);
-}
+ /* 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, 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);
+ }
-static 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);
+ input_abs_set_res(input, ABS_MT_POSITION_X,
+ cyapa->max_abs_x / cyapa->physical_size_x);
+ input_abs_set_res(input, ABS_MT_POSITION_Y,
+ cyapa->max_abs_y / cyapa->physical_size_y);
+
+ if (cyapa->btn_capability & CAPABILITY_LEFT_BTN_MASK)
+ __set_bit(BTN_LEFT, input->keybit);
+ if (cyapa->btn_capability & CAPABILITY_MIDDLE_BTN_MASK)
+ __set_bit(BTN_MIDDLE, input->keybit);
+ if (cyapa->btn_capability & CAPABILITY_RIGHT_BTN_MASK)
+ __set_bit(BTN_RIGHT, input->keybit);
+
+ if (cyapa->btn_capability == CAPABILITY_LEFT_BTN_MASK)
+ __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
+
+ /* 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) {
+ dev_err(dev, "allocate memory for MT slots failed, %d\n", ret);
+ goto err_free_device;
+ }
+
+ /* Register the device in input subsystem */
+ ret = input_register_device(input);
+ if (ret) {
+ dev_err(dev, "input device register failed, %d\n", ret);
+ goto err_free_device;
+ }
+ return 0;
+
+err_free_device:
+ input_free_device(input);
+ cyapa->input = NULL;
+ return ret;
}
/*
- * 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
+ * Check if device is operational.
*
- * Returns negative errno, else the number of bytes written.
+ * An operational device is responding, has exited bootloader, and has
+ * firmware supported by this driver.
*
- * 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.
+ * 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 ssize_t cyapa_smbus_read_block(struct cyapa *cyapa, u8 cmd, size_t len,
- u8 *values)
+static int cyapa_check_is_operational(struct cyapa *cyapa)
{
- ssize_t ret;
- u8 index;
- u8 smbus_cmd;
- u8 *buf;
- struct i2c_client *client = cyapa->client;
+ int ret;
- if (!(SMBUS_BYTE_BLOCK_CMD_MASK & cmd))
- return -EINVAL;
+ ret = cyapa_poll_state(cyapa, 4000);
+ if (ret)
+ return ret;
- 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;
+ switch (cyapa->gen) {
+ default:
+ cyapa->ops = &cyapa_default_ops;
+ cyapa->gen = CYAPA_GEN_UNKNOWN;
+ break;
}
- 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;
- }
+ if (cyapa->ops->operational_check)
+ ret = cyapa->ops->operational_check(cyapa);
+ else
+ ret = -EBUSY;
-out:
- return ret > 0 ? len : ret;
+ return 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)
+static irqreturn_t cyapa_irq(int irq, void *dev_id)
{
- u8 cmd;
+ 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 (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);
-}
+ 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);
-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);
+ 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)
{
- 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;
+ return -ENODEV;
}
/*
@@ -485,7 +325,7 @@ error:
* -ETIMEDOUT if device never responds (too many -EAGAIN)
* < 0 other errors
*/
-static int cyapa_poll_state(struct cyapa *cyapa, unsigned int timeout)
+int cyapa_poll_state(struct cyapa *cyapa, unsigned int timeout)
{
int ret;
int tries = timeout / 100;
@@ -495,332 +335,127 @@ static int cyapa_poll_state(struct cyapa *cyapa, unsigned int timeout)
msleep(100);
ret = cyapa_get_state(cyapa);
}
- return (ret == -EAGAIN || ret == -ETIMEDOUT) ? -ETIMEDOUT : ret;
-}
-
-static int cyapa_bl_deactivate(struct cyapa *cyapa)
-{
- int ret;
- ret = cyapa_i2c_reg_write_block(cyapa, 0, sizeof(bl_deactivate),
- bl_deactivate);
- if (ret < 0)
- return ret;
-
- /* 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;
+ return (ret == -EAGAIN || ret == -ETIMEDOUT) ? -ETIMEDOUT : ret;
}
-/*
- * 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)
+static void cyapa_detect(struct cyapa *cyapa)
{
+ struct device *dev = &cyapa->client->dev;
+ char *envp[2] = {"ERROR=1", NULL};
int ret;
- ret = cyapa_i2c_reg_write_block(cyapa, 0, sizeof(bl_exit), bl_exit);
- if (ret < 0)
- return 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);
- /*
- * 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.
- */
- ret = cyapa_poll_state(cyapa, 2000);
- if (ret < 0)
- return ret;
- if (cyapa->state != CYAPA_STATE_OP)
- return -EAGAIN;
+ if (ret) {
+ kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
+ return;
+ }
- return 0;
+ 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);
+ }
+ }
}
/*
- * Set device power mode
- *
+ * Sysfs Interface.
*/
-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)
+static u16 clamp_pwr_cmd_sleep_time(u16 sleep_time)
{
- 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];
+ if (sleep_time < 20)
+ sleep_time = 20; /* minimal sleep time. */
+ else if (sleep_time > 1000)
+ sleep_time = 1000; /* maximal sleep time. */
- return 0;
+ return sleep_time;
}
/*
- * Check if device is operational.
+ * cyapa_sleep_time_to_pwr_cmd and cyapa_pwr_cmd_to_sleep_time
*
- * An operational device is responding, has exited bootloader, and has
- * firmware supported by this driver.
+ * 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.
*
- * 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
+ * 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;
*/
-static int cyapa_check_is_operational(struct cyapa *cyapa)
+u8 cyapa_sleep_time_to_pwr_cmd(u16 sleep_time)
{
- 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;
+ sleep_time = clamp_pwr_cmd_sleep_time(sleep_time);
- default:
- return -EIO;
- }
- return 0;
+ if (sleep_time < 100)
+ return ((sleep_time / 10) << 2) & PWR_MODE_MASK;
+ return ((sleep_time / 20 + 5) << 2) & PWR_MODE_MASK;
}
-static irqreturn_t cyapa_irq(int irq, void *dev_id)
+u16 cyapa_pwr_cmd_to_sleep_time(u8 pwr_mode)
{
- 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;
+ u8 encoded_time = pwr_mode >> 2;
- 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;
+ return (encoded_time < 10) ? encoded_time * 10
+ : (encoded_time - 5) * 20;
+}
- 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;
- }
+void cyapa_detect_async(void *data, async_cookie_t cookie)
+{
+ struct cyapa *cyapa = (struct cyapa *)data;
- 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);
+ mutex_lock(&cyapa->state_sync_lock);
+ if (cyapa->removed) {
+ mutex_unlock(&cyapa->state_sync_lock);
+ return;
}
- 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);
+ /* Keep synchronized with sys interface process threads. */
+ cyapa_detect(cyapa);
-out:
- return IRQ_HANDLED;
+ mutex_unlock(&cyapa->state_sync_lock);
}
-static u8 cyapa_check_adapter_functionality(struct i2c_client *client)
+static void cyapa_detect_and_start(void *data, async_cookie_t cookie)
{
- u8 ret = CYAPA_ADAPTER_FUNC_NONE;
-
- if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
- ret |= CYAPA_ADAPTER_FUNC_I2C;
- if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA |
- I2C_FUNC_SMBUS_BLOCK_DATA |
- I2C_FUNC_SMBUS_I2C_BLOCK))
- ret |= CYAPA_ADAPTER_FUNC_SMBUS;
- return ret;
+ cyapa_detect_async(data, cookie);
}
-static int cyapa_create_input_dev(struct cyapa *cyapa)
+static int cyapa_tp_modules_init(struct cyapa *cyapa)
{
- struct device *dev = &cyapa->client->dev;
- int ret;
- struct input_dev *input;
-
- if (!cyapa->physical_size_x || !cyapa->physical_size_y)
- return -EINVAL;
-
- input = cyapa->input = input_allocate_device();
- if (!input) {
- dev_err(dev, "allocate memory for input device failed\n");
- return -ENOMEM;
- }
-
- input->name = CYAPA_NAME;
- input->phys = cyapa->phys;
- input->id.bustype = BUS_I2C;
- input->id.version = 1;
- 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 */
- 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_abs_set_res(input, ABS_MT_POSITION_X,
- cyapa->max_abs_x / cyapa->physical_size_x);
- input_abs_set_res(input, ABS_MT_POSITION_Y,
- cyapa->max_abs_y / cyapa->physical_size_y);
-
- if (cyapa->btn_capability & CAPABILITY_LEFT_BTN_MASK)
- __set_bit(BTN_LEFT, input->keybit);
- if (cyapa->btn_capability & CAPABILITY_MIDDLE_BTN_MASK)
- __set_bit(BTN_MIDDLE, input->keybit);
- if (cyapa->btn_capability & CAPABILITY_RIGHT_BTN_MASK)
- __set_bit(BTN_RIGHT, input->keybit);
-
- if (cyapa->btn_capability == CAPABILITY_LEFT_BTN_MASK)
- __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
-
- /* 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) {
- dev_err(dev, "allocate memory for MT slots failed, %d\n", ret);
- goto err_free_device;
- }
-
- /* Register the device in input subsystem */
- ret = input_register_device(input);
- if (ret) {
- dev_err(dev, "input device register failed, %d\n", ret);
- goto err_free_device;
- }
return 0;
+}
-err_free_device:
- input_free_device(input);
- cyapa->input = NULL;
- return ret;
+static int cyapa_tp_modules_uninit(struct cyapa *cyapa)
+{
+ return 0;
}
static int cyapa_probe(struct i2c_client *client,
@@ -830,6 +465,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 +473,41 @@ 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");
+ if (!cyapa)
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 +518,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;
@@ -897,9 +538,18 @@ static int cyapa_remove(struct i2c_client *client)
{
struct cyapa *cyapa = i2c_get_clientdata(client);
+ /* Make sure asynchronous thread run nothing when removing. */
+ mutex_lock(&cyapa->state_sync_lock);
+ cyapa->removed = true;
+ mutex_unlock(&cyapa->state_sync_lock);
+
free_irq(cyapa->irq, cyapa);
+
input_unregister_device(cyapa->input);
- cyapa_set_power_mode(cyapa, PWR_MODE_OFF);
+ if (cyapa->ops->set_power_mode)
+ cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0);
+ cyapa_tp_modules_uninit(cyapa);
+ i2c_set_clientdata(client, NULL);
kfree(cyapa);
return 0;
@@ -912,17 +562,28 @@ static int cyapa_suspend(struct device *dev)
u8 power_mode;
struct cyapa *cyapa = dev_get_drvdata(dev);
+ cyapa->suspended = true;
+ /*
+ * Disable IRQ to avoid the command response interrupt cause system
+ * suspending process interrupted and failed.
+ * Because the gen5 devices will always assert interrupt to host after
+ * executed the set power mode command.
+ */
disable_irq(cyapa->irq);
/*
* Set trackpad device to idle mode if wakeup is allowed,
* otherwise turn off.
*/
- power_mode = device_may_wakeup(dev) ? PWR_MODE_IDLE
+ power_mode = device_may_wakeup(dev) ? cyapa->suspend_power_mode
: PWR_MODE_OFF;
- ret = cyapa_set_power_mode(cyapa, power_mode);
- if (ret < 0)
- dev_err(dev, "set power mode failed, %d\n", ret);
+ if (cyapa->ops->set_power_mode) {
+ ret = cyapa->ops->set_power_mode(cyapa, power_mode,
+ cyapa->suspend_sleep_time);
+ if (ret < 0)
+ dev_err(dev, "suspend set power mode failed, %d\n",
+ ret);
+ }
if (device_may_wakeup(dev))
cyapa->irq_wake = (enable_irq_wake(cyapa->irq) == 0);
@@ -936,17 +597,25 @@ static int cyapa_resume(struct device *dev)
if (device_may_wakeup(dev) && cyapa->irq_wake)
disable_irq_wake(cyapa->irq);
+ enable_irq(cyapa->irq);
+ cyapa->suspended = false;
- ret = cyapa_set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE);
- if (ret)
- dev_warn(dev, "resume active power failed, %d\n", ret);
+ if (cyapa->ops->set_power_mode) {
+ ret = cyapa->ops->set_power_mode(cyapa,
+ PWR_MODE_FULL_ACTIVE, 0);
+ if (ret)
+ dev_warn(dev, "resume active power failed, %d\n", ret);
+ }
+
+ async_schedule(cyapa_detect_async, cyapa);
- enable_irq(cyapa->irq);
return 0;
}
#endif /* CONFIG_PM_SLEEP */
-static SIMPLE_DEV_PM_OPS(cyapa_pm_ops, cyapa_suspend, cyapa_resume);
+static const struct dev_pm_ops cyapa_pm_ops = {
+ SET_SYSTEM_SLEEP_PM_OPS(cyapa_suspend, cyapa_resume)
+};
static const struct i2c_device_id cyapa_id_table[] = {
{ "cyapa", 0 },
@@ -966,7 +635,26 @@ static struct i2c_driver cyapa_driver = {
.id_table = cyapa_id_table,
};
-module_i2c_driver(cyapa_driver);
+static int __init cyapa_init(void)
+{
+ int ret;
+
+ ret = i2c_add_driver(&cyapa_driver);
+ if (ret) {
+ pr_err("cyapa driver register FAILED.\n");
+ return ret;
+ }
+
+ return ret;
+}
+
+static void __exit cyapa_exit(void)
+{
+ i2c_del_driver(&cyapa_driver);
+}
+
+module_init(cyapa_init);
+module_exit(cyapa_exit);
MODULE_DESCRIPTION("Cypress APA I2C Trackpad Driver");
MODULE_AUTHOR("Dudley Du <dudl@cypress.com>");
diff --git a/drivers/input/mouse/cyapa.h b/drivers/input/mouse/cyapa.h
new file mode 100644
index 0000000..636fea9
--- /dev/null
+++ b/drivers/input/mouse/cyapa.h
@@ -0,0 +1,275 @@
+/*
+ * Cypress APA trackpad with I2C interface
+ *
+ * Author: Dudley Du <dudl@cypress.com>
+ *
+ * Copyright (C) 2014 Cypress Semiconductor, Inc.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file COPYING in the main directory of this archive for
+ * more details.
+ */
+
+#ifndef _CYAPA_H
+#define _CYAPA_H
+
+#include <linux/async.h>
+#include <linux/firmware.h>
+
+/* APA trackpad firmware generation number. */
+#define CYAPA_GEN_UNKNOWN 0x00 /* unknown protocol. */
+#define CYAPA_GEN3 0x03 /* support MT-protocol B with tracking ID. */
+#define CYAPA_GEN5 0x05 /* support TrueTouch GEN5 trackpad device. */
+
+#define CYAPA_NAME "Cypress APA Trackpad (cyapa)"
+
+/*
+ * 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
+
+/* 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
+#define CYAPA_CMD_MAX_BASELINE 0x0d
+#define CYAPA_CMD_MIN_BASELINE 0x0e
+
+#define BL_HEAD_OFFSET 0x00
+#define BL_DATA_OFFSET 0x10
+
+#define BL_STATUS_SIZE 3 /* Length of gen3 bootloader status registers */
+#define CYAPA_REG_MAP_SIZE 256
+
+/*
+ * Gen3 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)
+
+/*
+ * Write-only command file register used to issue commands and
+ * parameters to the bootloader.
+ * The default value read from it is always 0x00.
+ */
+#define REG_BL_FILE 0x00
+#define BL_FILE 0x00
+
+/*
+ * Bootloader Status Register
+ *
+ * bit 7: Busy
+ * bit 6 - 5: Reserved
+ * bit 4: Bootloader running
+ * bit 3 - 2: Reserved
+ * bit 1: Watchdog Reset
+ * bit 0: Checksum valid
+ */
+#define REG_BL_STATUS 0x01
+#define BL_STATUS_REV_6_5 0x60
+#define BL_STATUS_BUSY 0x80
+#define BL_STATUS_RUNNING 0x10
+#define BL_STATUS_REV_3_2 0x0c
+#define BL_STATUS_WATCHDOG 0x02
+#define BL_STATUS_CSUM_VALID 0x01
+#define BL_STATUS_REV_MASK (BL_STATUS_WATCHDOG | BL_STATUS_REV_3_2 | \
+ BL_STATUS_REV_6_5)
+
+/*
+ * 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_ERROR_RESERVED 0x03
+#define BL_ERROR_NO_ERR_IDLE 0x00
+#define BL_ERROR_NO_ERR_ACTIVE (BL_ERROR_BOOTLOADING)
+
+#define CAPABILITY_BTN_SHIFT 3
+#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 PWR_MODE_MASK 0xfc
+#define PWR_MODE_FULL_ACTIVE (0x3f << 2)
+#define PWR_MODE_IDLE (0x03 << 2) /* Default rt suspend scanrate: 30ms */
+#define PWR_MODE_SLEEP (0x05 << 2) /* Default suspend scanrate: 50ms */
+#define PWR_MODE_BTN_ONLY (0x01 << 2)
+#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_BTN_ONLY (0x01 << 2)
+#define PWR_STATUS_OFF (0x00 << 2)
+
+#define AUTOSUSPEND_DELAY 2000 /* unit : ms */
+
+#define BTN_ONLY_MODE_NAME "buttononly"
+#define OFF_MODE_NAME "off"
+
+/* The touch.id is used as the MT slot id, thus max MT slot is 15 */
+#define CYAPA_MAX_MT_SLOTS 15
+
+struct cyapa;
+
+typedef bool (*cb_sort)(struct cyapa *, u8 *, int);
+
+struct cyapa_dev_ops {
+ int (*initialize)(struct cyapa *cyapa);
+ int (*uninitialize)(struct cyapa *cyapa);
+
+ int (*state_parse)(struct cyapa *cyapa, u8 *reg_status, int len);
+ int (*operational_check)(struct cyapa *cyapa);
+
+ void (*irq_handler)(struct cyapa *);
+ bool (*irq_cmd_handler)(struct cyapa *);
+ int (*sort_empty_output_data)(struct cyapa *,
+ u8 *, int *, cb_sort);
+
+ int (*set_power_mode)(struct cyapa *, u8, u16);
+};
+
+enum cyapa_state {
+ CYAPA_STATE_OP,
+ CYAPA_STATE_BL_IDLE,
+ CYAPA_STATE_BL_ACTIVE,
+ CYAPA_STATE_GEN5_BL,
+ CYAPA_STATE_GEN5_APP,
+ CYAPA_STATE_BL_BUSY,
+ CYAPA_STATE_NO_DEVICE,
+};
+
+/* The main device structure */
+struct cyapa {
+ enum cyapa_state state;
+ u8 status[BL_STATUS_SIZE];
+
+ 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;
+
+ /* power mode settings */
+ u8 suspend_power_mode;
+ u16 suspend_sleep_time;
+#ifdef CONFIG_PM_RUNTIME
+ u8 runtime_suspend_power_mode;
+ u16 runtime_suspend_sleep_time;
+#endif /* CONFIG_PM_RUNTIME */
+ bool suspended;
+
+ /* Read from query data region. */
+ char product_id[16];
+ u8 fw_maj_ver; /* Firmware major version. */
+ u8 fw_min_ver; /* Firmware minor version. */
+ u8 btn_capability;
+ u8 gen;
+ int max_abs_x;
+ int max_abs_y;
+ int physical_size_x;
+ int physical_size_y;
+
+ /* Used in ttsp and truetouch based trackpad devices. */
+ u8 x_origin; /* X Axis Origin: 0 = left side; 1 = rigth side. */
+ u8 y_origin; /* Y Axis Origin: 0 = top; 1 = bottom. */
+ int electrodes_x; /* Number of electrodes on the X Axis*/
+ int electrodes_y; /* Number of electrodes on the Y Axis*/
+ int electrodes_rx; /* Number of Rx electrodes */
+ int max_z;
+
+ /*
+ * Used to synchronize the access or update the device state.
+ * And since update firmware and read firmware image process will take
+ * quite long time, maybe more than 10 seconds, so use mutex_lock
+ * to sync and wait other interface and detecting are done or ready.
+ */
+ struct mutex state_sync_lock;
+ bool removed;
+
+ const struct cyapa_dev_ops *ops;
+};
+
+
+ssize_t cyapa_i2c_reg_read_block(struct cyapa *cyapa, u8 reg, size_t len,
+ u8 *values);
+ssize_t cyapa_i2c_reg_write_block(struct cyapa *cyapa, u8 reg,
+ size_t len, const u8 *values);
+ssize_t cyapa_smbus_read_block(struct cyapa *cyapa, u8 cmd, size_t len,
+ u8 *values);
+
+s32 cyapa_read_byte(struct cyapa *cyapa, u8 cmd_idx);
+s32 cyapa_write_byte(struct cyapa *cyapa, u8 cmd_idx, u8 value);
+ssize_t cyapa_read_block(struct cyapa *cyapa, u8 cmd_idx, u8 *values);
+
+ssize_t cyapa_i2c_read(struct cyapa *cyapa, u8 reg, size_t len, u8 *values);
+ssize_t cyapa_i2c_write(struct cyapa *cyapa, u8 reg,
+ size_t len, const void *values);
+
+int cyapa_poll_state(struct cyapa *cyapa, unsigned int timeout);
+void cyapa_detect_async(void *data, async_cookie_t cookie);
+
+u8 cyapa_sleep_time_to_pwr_cmd(u16 sleep_time);
+u16 cyapa_pwr_cmd_to_sleep_time(u8 pwr_mode);
+
+
+extern const char unique_str[];
+
+#endif
--
1.9.1
^ permalink raw reply related
* [PATCH v6 02/13] input: cyapa: add cyapa driver power management interfaces support
From: Dudley Du @ 2014-09-10 4:34 UTC (permalink / raw)
To: dmitry.torokhov, rydberg; +Cc: bleung, patrikf, linux-input, linux-kernel
Add suspend_scanrate_ms power management interfaces in device's
power group, so users or applications can control the power management
strategy of trackpad device as their requirements.
TEST=test on Chromebooks.
Signed-off-by: Dudley Du <dudl@cypress.com>
---
drivers/input/mouse/cyapa.c | 85 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)
diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index 3edd23e..d61ccbc 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -427,6 +427,82 @@ u16 cyapa_pwr_cmd_to_sleep_time(u8 pwr_mode)
: (encoded_time - 5) * 20;
}
+#ifdef CONFIG_PM_SLEEP
+static ssize_t cyapa_show_suspend_scanrate(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct cyapa *cyapa = dev_get_drvdata(dev);
+ u8 pwr_cmd = cyapa->suspend_power_mode;
+ u16 sleep_time;
+ int len;
+
+ mutex_lock(&cyapa->state_sync_lock);
+ pwr_cmd = cyapa->suspend_power_mode;
+ sleep_time = cyapa->suspend_sleep_time;
+ mutex_unlock(&cyapa->state_sync_lock);
+
+ if (pwr_cmd == PWR_MODE_BTN_ONLY)
+ len = scnprintf(buf, PAGE_SIZE, "%s\n", BTN_ONLY_MODE_NAME);
+ else if (pwr_cmd == PWR_MODE_OFF)
+ len = scnprintf(buf, PAGE_SIZE, "%s\n", OFF_MODE_NAME);
+ else {
+ if (cyapa->gen == CYAPA_GEN3)
+ sleep_time = cyapa_pwr_cmd_to_sleep_time(pwr_cmd);
+ len = scnprintf(buf, PAGE_SIZE, "%u\n", sleep_time);
+ }
+
+ return len;
+}
+
+static u16 cyapa_clamp_sleep_time(u16 sleep_time)
+{
+ if (sleep_time > 1000)
+ sleep_time = 1000;
+ return sleep_time;
+}
+
+static ssize_t cyapa_update_suspend_scanrate(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct cyapa *cyapa = dev_get_drvdata(dev);
+ u16 sleep_time;
+
+ mutex_lock(&cyapa->state_sync_lock);
+
+ if (sysfs_streq(buf, BTN_ONLY_MODE_NAME))
+ cyapa->suspend_power_mode = PWR_MODE_BTN_ONLY;
+ else if (sysfs_streq(buf, OFF_MODE_NAME))
+ cyapa->suspend_power_mode = PWR_MODE_OFF;
+ else if (!kstrtou16(buf, 10, &sleep_time)) {
+ cyapa->suspend_sleep_time = cyapa_clamp_sleep_time(sleep_time);
+ cyapa->suspend_power_mode =
+ cyapa_sleep_time_to_pwr_cmd(cyapa->suspend_sleep_time);
+ } else
+ count = 0;
+
+ mutex_unlock(&cyapa->state_sync_lock);
+ if (!count)
+ dev_err(dev, "invalid suspend scanrate ms parameters\n");
+ return count ? count : -EINVAL;
+}
+
+static DEVICE_ATTR(suspend_scanrate_ms, S_IRUGO|S_IWUSR,
+ cyapa_show_suspend_scanrate,
+ cyapa_update_suspend_scanrate);
+
+static struct attribute *cyapa_power_wakeup_entries[] = {
+ &dev_attr_suspend_scanrate_ms.attr,
+ NULL,
+};
+
+static const struct attribute_group cyapa_power_wakeup_group = {
+ .name = power_group_name,
+ .attrs = cyapa_power_wakeup_entries,
+};
+#endif /* CONFIG_PM_SLEEP */
+
void cyapa_detect_async(void *data, async_cookie_t cookie)
{
struct cyapa *cyapa = (struct cyapa *)data;
@@ -521,6 +597,12 @@ static int cyapa_probe(struct i2c_client *client,
goto err_uninit_tp_modules;
}
+#ifdef CONFIG_PM_SLEEP
+ if (device_can_wakeup(dev) &&
+ sysfs_merge_group(&client->dev.kobj, &cyapa_power_wakeup_group))
+ dev_warn(dev, "error creating wakeup power entries.\n");
+#endif /* CONFIG_PM_SLEEP */
+
async_schedule(cyapa_detect_and_start, cyapa);
return 0;
@@ -543,6 +625,9 @@ static int cyapa_remove(struct i2c_client *client)
cyapa->removed = true;
mutex_unlock(&cyapa->state_sync_lock);
+#ifdef CONFIG_PM_SLEEP
+ sysfs_unmerge_group(&client->dev.kobj, &cyapa_power_wakeup_group);
+#endif
free_irq(cyapa->irq, cyapa);
input_unregister_device(cyapa->input);
--
1.9.1
^ permalink raw reply related
* [PATCH v6 03/13] input: cyapa: add cyapa driver runtime power management interfaces support
From: Dudley Du @ 2014-09-10 4:34 UTC (permalink / raw)
To: dmitry.torokhov, rydberg; +Cc: bleung, patrikf, linux-input, linux-kernel
Add runtime_suspend_scanrate_ms power management interfaces in device's
power group, so users or applications can control the runtime power
management strategy of trackpad device as their requirements.
TEST=test on Chromebooks.
Signed-off-by: Dudley Du <dudl@cypress.com>
---
drivers/input/mouse/cyapa.c | 142 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 142 insertions(+)
diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index d61ccbc..eb3a5a8 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -271,9 +271,16 @@ static int cyapa_check_is_operational(struct cyapa *cyapa)
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;
bool cont;
+ pm_runtime_get_sync(dev);
+ pm_runtime_mark_last_busy(dev);
+
+ if (device_may_wakeup(dev))
+ pm_wakeup_event(dev, 0);
+
/* Interrupt event maybe cuased by host command to trackpad device. */
cont = true;
if (cyapa->ops->irq_cmd_handler)
@@ -297,6 +304,8 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
mutex_unlock(&cyapa->state_sync_lock);
}
+
+ pm_runtime_put_sync_autosuspend(dev);
out:
return IRQ_HANDLED;
}
@@ -503,6 +512,86 @@ static const struct attribute_group cyapa_power_wakeup_group = {
};
#endif /* CONFIG_PM_SLEEP */
+#ifdef CONFIG_PM_RUNTIME
+static ssize_t cyapa_show_rt_suspend_scanrate(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct cyapa *cyapa = dev_get_drvdata(dev);
+ u8 pwr_cmd;
+ u16 sleep_time;
+
+ mutex_lock(&cyapa->state_sync_lock);
+ pwr_cmd = cyapa->runtime_suspend_power_mode;
+ sleep_time = cyapa->runtime_suspend_sleep_time;
+ mutex_unlock(&cyapa->state_sync_lock);
+
+ if (cyapa->gen == CYAPA_GEN3)
+ return scnprintf(buf, PAGE_SIZE, "%u\n",
+ cyapa_pwr_cmd_to_sleep_time(pwr_cmd));
+ return scnprintf(buf, PAGE_SIZE, "%u\n", sleep_time);
+}
+
+static ssize_t cyapa_update_rt_suspend_scanrate(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct cyapa *cyapa = dev_get_drvdata(dev);
+ u16 time;
+
+ if (buf == NULL || count == 0 || kstrtou16(buf, 10, &time)) {
+ dev_err(dev, "invalid runtime suspend scanrate ms parameter\n");
+ return -EINVAL;
+ }
+
+ /*
+ * When the suspend scanrate is changed, pm_runtime_get to resume
+ * a potentially suspended device, update to the new pwr_cmd
+ * and then pm_runtime_put to suspend into the new power mode.
+ */
+ pm_runtime_get_sync(dev);
+ mutex_lock(&cyapa->state_sync_lock);
+ cyapa->runtime_suspend_sleep_time = cyapa_clamp_sleep_time(time);
+ cyapa->runtime_suspend_power_mode =
+ cyapa_sleep_time_to_pwr_cmd(cyapa->runtime_suspend_sleep_time);
+ mutex_unlock(&cyapa->state_sync_lock);
+ pm_runtime_put_sync_autosuspend(dev);
+
+ return count;
+}
+
+static DEVICE_ATTR(runtime_suspend_scanrate_ms, S_IRUGO|S_IWUSR,
+ cyapa_show_rt_suspend_scanrate,
+ cyapa_update_rt_suspend_scanrate);
+
+static struct attribute *cyapa_power_runtime_entries[] = {
+ &dev_attr_runtime_suspend_scanrate_ms.attr,
+ NULL,
+};
+
+static const struct attribute_group cyapa_power_runtime_group = {
+ .name = power_group_name,
+ .attrs = cyapa_power_runtime_entries,
+};
+
+static void cyapa_start_runtime(struct cyapa *cyapa)
+{
+ struct device *dev = &cyapa->client->dev;
+
+ cyapa->runtime_suspend_power_mode = PWR_MODE_IDLE;
+ cyapa->runtime_suspend_sleep_time =
+ cyapa_pwr_cmd_to_sleep_time(cyapa->runtime_suspend_power_mode);
+ if (sysfs_merge_group(&dev->kobj, &cyapa_power_runtime_group))
+ dev_warn(dev, "error creating wakeup runtime entries.\n");
+ pm_runtime_set_active(dev);
+ pm_runtime_use_autosuspend(dev);
+ pm_runtime_set_autosuspend_delay(dev, AUTOSUSPEND_DELAY);
+ pm_runtime_enable(dev);
+}
+#else
+static void cyapa_start_runtime(struct cyapa *cyapa) {}
+#endif /* CONFIG_PM_RUNTIME */
+
void cyapa_detect_async(void *data, async_cookie_t cookie)
{
struct cyapa *cyapa = (struct cyapa *)data;
@@ -521,7 +610,11 @@ void cyapa_detect_async(void *data, async_cookie_t cookie)
static void cyapa_detect_and_start(void *data, async_cookie_t cookie)
{
+ struct cyapa *cyapa = data;
+
cyapa_detect_async(data, cookie);
+
+ cyapa_start_runtime(cyapa);
}
static int cyapa_tp_modules_init(struct cyapa *cyapa)
@@ -625,9 +718,16 @@ static int cyapa_remove(struct i2c_client *client)
cyapa->removed = true;
mutex_unlock(&cyapa->state_sync_lock);
+ pm_runtime_disable(&client->dev);
+
#ifdef CONFIG_PM_SLEEP
sysfs_unmerge_group(&client->dev.kobj, &cyapa_power_wakeup_group);
#endif
+
+#ifdef CONFIG_PM_RUNTIME
+ sysfs_unmerge_group(&client->dev.kobj, &cyapa_power_runtime_group);
+#endif
+
free_irq(cyapa->irq, cyapa);
input_unregister_device(cyapa->input);
@@ -694,12 +794,54 @@ static int cyapa_resume(struct device *dev)
async_schedule(cyapa_detect_async, cyapa);
+ /* Update runtime power management to reflect active state. */
+ pm_runtime_disable(dev);
+ pm_runtime_set_active(dev);
+ pm_runtime_enable(dev);
return 0;
}
#endif /* CONFIG_PM_SLEEP */
+#ifdef CONFIG_PM_RUNTIME
+static int cyapa_runtime_suspend(struct device *dev)
+{
+ int ret;
+ struct cyapa *cyapa = dev_get_drvdata(dev);
+
+ if (cyapa->ops->set_power_mode) {
+ /* Set trackpad device to idle mode. */
+ ret = cyapa->ops->set_power_mode(cyapa,
+ cyapa->runtime_suspend_power_mode,
+ cyapa->runtime_suspend_sleep_time);
+ if (ret)
+ dev_err(dev, "runtime suspend failed, %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int cyapa_runtime_resume(struct device *dev)
+{
+ int ret;
+ struct cyapa *cyapa = dev_get_drvdata(dev);
+
+ if (cyapa->ops->set_power_mode) {
+ /* Resume to full active mode. */
+ ret = cyapa->ops->set_power_mode(cyapa,
+ PWR_MODE_FULL_ACTIVE, 0);
+ if (ret)
+ dev_err(dev, "runtime resume failed, %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+#endif /* CONFIG_PM_RUNTIME */
+
static const struct dev_pm_ops cyapa_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(cyapa_suspend, cyapa_resume)
+ SET_RUNTIME_PM_OPS(cyapa_runtime_suspend, cyapa_runtime_resume, NULL)
};
static const struct i2c_device_id cyapa_id_table[] = {
--
1.9.1
^ permalink raw reply related
* [PATCH v6 04/13] input: cyapa: add cyapa key function interfaces in sysfs system
From: Dudley Du @ 2014-09-10 4:34 UTC (permalink / raw)
To: dmitry.torokhov, rydberg; +Cc: bleung, patrikf, linux-input, linux-kernel
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 | 192 ++++++++++++++++++++++++++++++++++++++++++++
drivers/input/mouse/cyapa.h | 27 +++++++
2 files changed, 219 insertions(+)
diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index eb3a5a8..1e45fd5 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -391,6 +391,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 = -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.
*/
@@ -592,6 +664,122 @@ 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);
+ char fw_name[64];
+ int ret;
+
+ if (count > 64) {
+ dev_err(dev, "File name too long\n");
+ return -EINVAL;
+ }
+
+ memcpy(fw_name, buf, count);
+ if (fw_name[count - 1] == '\n')
+ fw_name[count - 1] = '\0';
+ else
+ fw_name[count] = '\0';
+
+ 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 supported.\n");
+ ret = -ENOTSUPP;
+ } 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 supported.\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;
@@ -690,6 +878,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))
@@ -719,6 +910,7 @@ static int cyapa_remove(struct i2c_client *client)
mutex_unlock(&cyapa->state_sync_lock);
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 636fea9..b61a71b 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);
@@ -244,6 +260,17 @@ struct cyapa {
struct mutex state_sync_lock;
bool removed;
+ /* 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.9.1
^ permalink raw reply related
* [PATCH v6 05/13] input: cyapa: add read firmware image and raw data interfaces in debugfs system
From: Dudley Du @ 2014-09-10 4:34 UTC (permalink / raw)
To: dmitry.torokhov, rydberg; +Cc: bleung, patrikf, linux-input, linux-kernel
Add read_fw and raw_data debugfs interfaces for easier issues location
and collection when report by user.
TEST=test on Chromebooks.
Signed-off-by: Dudley Du <dudl@cypress.com>
---
drivers/input/mouse/cyapa.c | 221 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 221 insertions(+)
diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index 1e45fd5..b3b19b3 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -39,6 +39,8 @@
const char unique_str[] = "CYTRA";
+/* Global root node of the cyapa debugfs directory. */
+static struct dentry *cyapa_debugfs_root;
ssize_t cyapa_i2c_reg_read_block(struct cyapa *cyapa, u8 reg, size_t len,
@@ -464,6 +466,205 @@ done:
}
/*
+ **************************************************************
+ * debugfs interface
+ **************************************************************
+*/
+static int cyapa_debugfs_open(struct inode *inode, struct file *file)
+{
+ struct cyapa *cyapa = inode->i_private;
+ int ret;
+
+ if (!cyapa)
+ return -ENODEV;
+
+ ret = mutex_lock_interruptible(&cyapa->debugfs_mutex);
+ if (ret)
+ return ret;
+
+ if (!get_device(&cyapa->client->dev)) {
+ ret = -ENODEV;
+ goto out;
+ }
+
+ file->private_data = cyapa;
+
+ if (cyapa->fw_image) {
+ ret = 0;
+ goto out;
+ }
+
+ mutex_lock(&cyapa->state_sync_lock);
+ /*
+ * If firmware hasn't been read yet, read it all in one pass.
+ * Subsequent opens will reuse the data in this same buffer.
+ */
+ if (cyapa->ops->read_fw)
+ ret = cyapa->ops->read_fw(cyapa);
+ else
+ ret = -EPERM;
+ mutex_unlock(&cyapa->state_sync_lock);
+
+ /* Redetect trackpad device states. */
+ cyapa_detect_async(cyapa, 0);
+
+out:
+ mutex_unlock(&cyapa->debugfs_mutex);
+ return ret;
+}
+
+static int cyapa_debugfs_release(struct inode *inode, struct file *file)
+{
+ struct cyapa *cyapa = file->private_data;
+ int ret;
+
+ if (!cyapa)
+ return 0;
+
+ ret = mutex_lock_interruptible(&cyapa->debugfs_mutex);
+ if (ret)
+ return ret;
+ file->private_data = NULL;
+ put_device(&cyapa->client->dev);
+ mutex_unlock(&cyapa->debugfs_mutex);
+
+ return 0;
+}
+
+/* Return some bytes from the buffered firmware image, starting from *ppos */
+static ssize_t cyapa_debugfs_read_fw(struct file *file, char __user *buffer,
+ size_t count, loff_t *ppos)
+{
+ struct cyapa *cyapa = file->private_data;
+
+ if (!cyapa->fw_image)
+ return -EINVAL;
+
+ if (*ppos >= cyapa->fw_image_size)
+ return 0;
+
+ if (count + *ppos > cyapa->fw_image_size)
+ count = cyapa->fw_image_size - *ppos;
+
+ if (copy_to_user(buffer, &cyapa->fw_image[*ppos], count))
+ return -EFAULT;
+
+ *ppos += count;
+ return count;
+}
+
+static const struct file_operations cyapa_read_fw_fops = {
+ .open = cyapa_debugfs_open,
+ .release = cyapa_debugfs_release,
+ .read = cyapa_debugfs_read_fw
+};
+
+static int cyapa_debugfs_raw_data_open(struct inode *inode, struct file *file)
+{
+ struct cyapa *cyapa = inode->i_private;
+ int ret;
+
+ if (!cyapa)
+ return -ENODEV;
+
+ /* Start to be supported after Gen5 trackpad devices. */
+ if (cyapa->gen < CYAPA_GEN5)
+ return -ENOTSUPP;
+
+ ret = mutex_lock_interruptible(&cyapa->debugfs_mutex);
+ if (ret)
+ return ret;
+
+ if (!get_device(&cyapa->client->dev)) {
+ ret = -ENODEV;
+ goto out;
+ }
+
+ file->private_data = cyapa;
+
+ mutex_lock(&cyapa->state_sync_lock);
+ if (cyapa->ops->read_raw_data)
+ ret = cyapa->ops->read_raw_data(cyapa);
+ else
+ ret = -EPERM;
+ mutex_unlock(&cyapa->state_sync_lock);
+out:
+ mutex_unlock(&cyapa->debugfs_mutex);
+ return ret;
+}
+
+static int cyapa_debugfs_raw_data_release(struct inode *inode,
+ struct file *file)
+{
+ struct cyapa *cyapa = file->private_data;
+ int ret;
+
+ if (!cyapa)
+ return 0;
+
+ ret = mutex_lock_interruptible(&cyapa->debugfs_mutex);
+ if (ret)
+ return ret;
+ file->private_data = NULL;
+ put_device(&cyapa->client->dev);
+ mutex_unlock(&cyapa->debugfs_mutex);
+
+ return 0;
+}
+
+/* Always return the sensors' latest raw data from trackpad device. */
+static ssize_t cyapa_debugfs_read_raw_data(struct file *file,
+ char __user *buffer,
+ size_t count, loff_t *ppos)
+{
+ struct cyapa *cyapa = file->private_data;
+
+ if (!cyapa->tp_raw_data)
+ return -EINVAL;
+
+ if (*ppos >= cyapa->tp_raw_data_size)
+ return 0;
+
+ if (count + *ppos > cyapa->tp_raw_data_size)
+ count = cyapa->tp_raw_data_size - *ppos;
+
+ if (copy_to_user(buffer, &cyapa->tp_raw_data[*ppos], count))
+ return -EFAULT;
+
+ *ppos += count;
+ return count;
+}
+
+static const struct file_operations cyapa_read_raw_data_fops = {
+ .open = cyapa_debugfs_raw_data_open,
+ .release = cyapa_debugfs_raw_data_release,
+ .read = cyapa_debugfs_read_raw_data
+};
+
+static int cyapa_debugfs_init(struct cyapa *cyapa)
+{
+ struct device *dev = &cyapa->client->dev;
+
+ if (!cyapa_debugfs_root)
+ return -ENODEV;
+
+ cyapa->dentry_dev = debugfs_create_dir(kobject_name(&dev->kobj),
+ cyapa_debugfs_root);
+
+ if (!cyapa->dentry_dev)
+ return -ENODEV;
+
+ mutex_init(&cyapa->debugfs_mutex);
+
+ debugfs_create_file(CYAPA_DEBUGFS_READ_FW, S_IRUSR, cyapa->dentry_dev,
+ cyapa, &cyapa_read_fw_fops);
+
+ debugfs_create_file(CYAPA_DEBUGFS_RAW_DATA, S_IRUSR, cyapa->dentry_dev,
+ cyapa, &cyapa_read_raw_data_fops);
+ return 0;
+}
+
+/*
* Sysfs Interface.
*/
@@ -881,6 +1082,9 @@ static int cyapa_probe(struct i2c_client *client,
if (sysfs_create_group(&client->dev.kobj, &cyapa_sysfs_group))
dev_warn(dev, "error creating sysfs entries.\n");
+ if (cyapa_debugfs_init(cyapa))
+ dev_warn(dev, "error creating debugfs entries.\n");
+
#ifdef CONFIG_PM_SLEEP
if (device_can_wakeup(dev) &&
sysfs_merge_group(&client->dev.kobj, &cyapa_power_wakeup_group))
@@ -922,6 +1126,16 @@ static int cyapa_remove(struct i2c_client *client)
free_irq(cyapa->irq, cyapa);
+ debugfs_remove_recursive(cyapa->dentry_dev);
+ mutex_destroy(&cyapa->debugfs_mutex);
+
+ kfree(cyapa->fw_image);
+ cyapa->fw_image = NULL;
+ cyapa->fw_image_size = 0;
+ kfree(cyapa->tp_raw_data);
+ cyapa->tp_raw_data = NULL;
+ cyapa->tp_raw_data_size = 0;
+
input_unregister_device(cyapa->input);
if (cyapa->ops->set_power_mode)
cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0);
@@ -1058,6 +1272,11 @@ static int __init cyapa_init(void)
{
int ret;
+ /* Create a global debugfs root for all cyapa devices */
+ cyapa_debugfs_root = debugfs_create_dir("cyapa", NULL);
+ if (cyapa_debugfs_root == ERR_PTR(-ENODEV))
+ cyapa_debugfs_root = NULL;
+
ret = i2c_add_driver(&cyapa_driver);
if (ret) {
pr_err("cyapa driver register FAILED.\n");
@@ -1069,6 +1288,8 @@ static int __init cyapa_init(void)
static void __exit cyapa_exit(void)
{
+ debugfs_remove_recursive(cyapa_debugfs_root);
+
i2c_del_driver(&cyapa_driver);
}
--
1.9.1
^ permalink raw reply related
* [PATCH v6 06/13] input: cyapa: add gen3 trackpad device basic functions support
From: Dudley Du @ 2014-09-10 4:34 UTC (permalink / raw)
To: dmitry.torokhov, rydberg; +Cc: bleung, patrikf, linux-input, linux-kernel
Based on the cyapa core, add the gen3 trackpad device's basic functions
supported, so gen3 trackpad device can work with kernel input system.
The basic function is absolutely same as previous cyapa driver only
support gen3 trackpad device.
TEST=test on Chromebooks.
Signed-off-by: Dudley Du <dudl@cypress.com>
---
drivers/input/mouse/Makefile | 2 +-
drivers/input/mouse/cyapa.c | 96 ++++-
drivers/input/mouse/cyapa.h | 1 +
drivers/input/mouse/cyapa_gen3.c | 783 +++++++++++++++++++++++++++++++++++++++
4 files changed, 880 insertions(+), 2 deletions(-)
create mode 100644 drivers/input/mouse/cyapa_gen3.c
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index 8608eb7..63b42e0 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -35,4 +35,4 @@ 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
+cyapatp-y := cyapa.o cyapa_gen3.o
diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index b3b19b3..7ac2fdf 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -116,6 +116,15 @@ ssize_t cyapa_i2c_write(struct cyapa *cyapa, u8 reg,
void cyapa_default_irq_handler(struct cyapa *cyapa)
{
+ bool cont;
+
+ /* Interrupt triggerred by command response in detecting. */
+ cont = true;
+ if (cyapa_gen3_ops.irq_cmd_handler)
+ cont = cyapa_gen3_ops.irq_cmd_handler(cyapa);
+ if (!cont)
+ return;
+
/*
* Do redetecting when device states is still unknown and
* interrupt envent is received from device.
@@ -255,6 +264,9 @@ static int cyapa_check_is_operational(struct cyapa *cyapa)
return ret;
switch (cyapa->gen) {
+ case CYAPA_GEN3:
+ cyapa->ops = &cyapa_gen3_ops;
+ break;
default:
cyapa->ops = &cyapa_default_ops;
cyapa->gen = CYAPA_GEN_UNKNOWN;
@@ -317,9 +329,85 @@ out:
*/
static int cyapa_get_state(struct cyapa *cyapa)
{
+ int ret;
+ u8 status[BL_STATUS_SIZE];
+ u8 cmd[32];
+ /* The i2c address of gen4 and gen5 trackpad device must be even. */
+ bool even_addr = ((cyapa->client->addr & 0x0001) == 0);
+ bool smbus = false;
+ int retries = 2;
+
cyapa->state = CYAPA_STATE_NO_DEVICE;
- return -ENODEV;
+ /*
+ * 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)) {
+ if (!even_addr)
+ ret = cyapa_read_block(cyapa,
+ CYAPA_CMD_BL_STATUS, status);
+ smbus = true;
+ }
+ if (ret != BL_STATUS_SIZE)
+ goto error;
+
+ /*
+ * Detect trackpad protocol based on characristic registers and bits.
+ */
+ do {
+ cyapa->status[REG_OP_STATUS] = status[REG_OP_STATUS];
+ cyapa->status[REG_BL_STATUS] = status[REG_BL_STATUS];
+ cyapa->status[REG_BL_ERROR] = status[REG_BL_ERROR];
+
+ if (cyapa->gen == CYAPA_GEN_UNKNOWN ||
+ cyapa->gen == CYAPA_GEN3) {
+ ret = cyapa_gen3_ops.state_parse(cyapa,
+ status, BL_STATUS_SIZE);
+ if (ret == 0)
+ goto out_detected;
+ }
+
+ /*
+ * Cannot detect communication protocol based on current
+ * charateristic registers and bits.
+ * So write error command to do further detection.
+ * this method only valid on I2C bus.
+ * for smbus interface, it won't have overwrite issue.
+ */
+ if (!smbus) {
+ cmd[0] = 0x00;
+ cmd[1] = 0x00;
+ ret = cyapa_i2c_write(cyapa, 0, 2, cmd);
+ if (ret)
+ goto error;
+
+ msleep(50);
+
+ ret = cyapa_i2c_read(cyapa, BL_HEAD_OFFSET,
+ BL_STATUS_SIZE, status);
+ if (ret < 0)
+ goto error;
+ }
+ } while (--retries > 0 && !smbus);
+
+ goto error;
+
+out_detected:
+ return 0;
+
+error:
+ return (ret < 0) ? ret : -EAGAIN;
}
/*
@@ -1008,11 +1096,17 @@ static void cyapa_detect_and_start(void *data, async_cookie_t cookie)
static int cyapa_tp_modules_init(struct cyapa *cyapa)
{
+ if (cyapa_gen3_ops.initialize)
+ return cyapa_gen3_ops.initialize(cyapa);
+
return 0;
}
static int cyapa_tp_modules_uninit(struct cyapa *cyapa)
{
+ if (cyapa_gen3_ops.uninitialize)
+ return cyapa_gen3_ops.uninitialize(cyapa);
+
return 0;
}
diff --git a/drivers/input/mouse/cyapa.h b/drivers/input/mouse/cyapa.h
index b61a71b..0b8d023 100644
--- a/drivers/input/mouse/cyapa.h
+++ b/drivers/input/mouse/cyapa.h
@@ -298,5 +298,6 @@ u16 cyapa_pwr_cmd_to_sleep_time(u8 pwr_mode);
extern const char unique_str[];
+extern const struct cyapa_dev_ops cyapa_gen3_ops;
#endif
diff --git a/drivers/input/mouse/cyapa_gen3.c b/drivers/input/mouse/cyapa_gen3.c
new file mode 100644
index 0000000..0f1537c
--- /dev/null
+++ b/drivers/input/mouse/cyapa_gen3.c
@@ -0,0 +1,783 @@
+/*
+ * Cypress APA trackpad with I2C interface
+ *
+ * Author: Dudley Du <dudl@cypress.com>
+ * Further cleanup and restructuring by:
+ * Daniel Kurtz <djkurtz@chromium.org>
+ * Benson Leung <bleung@chromium.org>
+ *
+ * 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
+ * License. See the file COPYING in the main directory of this archive for
+ * more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <linux/input.h>
+#include <linux/input/mt.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include "cyapa.h"
+
+
+#define GEN3_MAX_FINGERS 5
+#define GEN3_FINGER_NUM(x) (((x) >> 4) & 0x07)
+
+#define BLK_HEAD_BYTES 32
+
+/* Macro for register map group offset. */
+#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 CYAPA_OFFSET_SOFT_RESET REG_OFFSET_COMMAND_BASE
+#define OP_RECALIBRATION_MASK 0x80
+#define OP_REPORT_BASELINE_MASK 0x40
+#define REG_OFFSET_MAX_BASELINE 0x0026
+#define REG_OFFSET_MIN_BASELINE 0x0027
+
+#define REG_OFFSET_POWER_MODE (REG_OFFSET_COMMAND_BASE + 1)
+#define SET_POWER_MODE_DELAY 10000 /* unit: us */
+#define SET_POWER_MODE_TRIES 5
+
+/*
+ * 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
+
+#define CYAPA_FW_BLOCK_SIZE 64
+#define CYAPA_FW_READ_SIZE 16
+#define CYAPA_FW_HDR_START 0x0780
+#define CYAPA_FW_HDR_BLOCK_COUNT 2
+#define CYAPA_FW_HDR_BLOCK_START (CYAPA_FW_HDR_START / CYAPA_FW_BLOCK_SIZE)
+#define CYAPA_FW_HDR_SIZE (CYAPA_FW_HDR_BLOCK_COUNT * \
+ CYAPA_FW_BLOCK_SIZE)
+#define CYAPA_FW_DATA_START 0x0800
+#define CYAPA_FW_DATA_BLOCK_COUNT 480
+#define CYAPA_FW_DATA_BLOCK_START (CYAPA_FW_DATA_START / CYAPA_FW_BLOCK_SIZE)
+#define CYAPA_FW_DATA_SIZE (CYAPA_FW_DATA_BLOCK_COUNT * \
+ CYAPA_FW_BLOCK_SIZE)
+#define CYAPA_FW_SIZE (CYAPA_FW_HDR_SIZE + CYAPA_FW_DATA_SIZE)
+#define CYAPA_CMD_LEN 16
+
+#define GEN3_BL_IDLE_FW_MAJ_VER_OFFSET 0x0b
+#define GEN3_BL_IDLE_FW_MIN_VER_OFFSET (GEN3_BL_IDLE_FW_MAJ_VER_OFFSET + 1)
+
+
+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;
+
+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;
+
+static const u8 bl_activate[] = { 0x00, 0xff, 0x38, 0x00, 0x01, 0x02, 0x03,
+ 0x04, 0x05, 0x06, 0x07 };
+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 };
+
+
+ /* for byte read/write command */
+#define CMD_RESET 0
+#define CMD_POWER_MODE 1
+#define CMD_DEV_STATUS 2
+#define CMD_REPORT_MAX_BASELINE 3
+#define CMD_REPORT_MIN_BASELINE 4
+#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)
+#define CYAPA_SMBUS_MAX_BASELINE SMBUS_BYTE_CMD(CMD_REPORT_MAX_BASELINE)
+#define CYAPA_SMBUS_MIN_BASELINE SMBUS_BYTE_CMD(CMD_REPORT_MIN_BASELINE)
+
+ /* 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)
+
+ /* for byte read/write command */
+#define CMD_RESET 0
+#define CMD_POWER_MODE 1
+#define CMD_DEV_STATUS 2
+#define CMD_REPORT_MAX_BASELINE 3
+#define CMD_REPORT_MIN_BASELINE 4
+#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)
+#define CYAPA_SMBUS_MAX_BASELINE SMBUS_BYTE_CMD(CMD_REPORT_MAX_BASELINE)
+#define CYAPA_SMBUS_MIN_BASELINE SMBUS_BYTE_CMD(CMD_REPORT_MIN_BASELINE)
+
+ /* 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)
+
+struct cyapa_cmd_len {
+ u8 cmd;
+ u8 len;
+};
+
+/* maps generic CYAPA_CMD_* code to the I2C equivalent */
+static const struct cyapa_cmd_len cyapa_i2c_cmds[] = {
+ { CYAPA_OFFSET_SOFT_RESET, 1 }, /* CYAPA_CMD_SOFT_RESET */
+ { REG_OFFSET_COMMAND_BASE + 1, 1 }, /* CYAPA_CMD_POWER_MODE */
+ { REG_OFFSET_DATA_BASE, 1 }, /* CYAPA_CMD_DEV_STATUS */
+ { REG_OFFSET_DATA_BASE, sizeof(struct cyapa_reg_data) },
+ /* CYAPA_CMD_GROUP_DATA */
+ { REG_OFFSET_COMMAND_BASE, 0 }, /* CYAPA_CMD_GROUP_CMD */
+ { REG_OFFSET_QUERY_BASE, QUERY_DATA_SIZE }, /* CYAPA_CMD_GROUP_QUERY */
+ { BL_HEAD_OFFSET, 3 }, /* CYAPA_CMD_BL_STATUS */
+ { BL_HEAD_OFFSET, 16 }, /* CYAPA_CMD_BL_HEAD */
+ { BL_HEAD_OFFSET, 16 }, /* CYAPA_CMD_BL_CMD */
+ { BL_DATA_OFFSET, 16 }, /* CYAPA_CMD_BL_DATA */
+ { BL_HEAD_OFFSET, 32 }, /* CYAPA_CMD_BL_ALL */
+ { REG_OFFSET_QUERY_BASE, PRODUCT_ID_SIZE },
+ /* CYAPA_CMD_BLK_PRODUCT_ID */
+ { REG_OFFSET_DATA_BASE, 32 }, /* CYAPA_CMD_BLK_HEAD */
+ { REG_OFFSET_MAX_BASELINE, 1 }, /* CYAPA_CMD_MAX_BASELINE */
+ { REG_OFFSET_MIN_BASELINE, 1 }, /* CYAPA_CMD_MIN_BASELINE */
+};
+
+static const struct cyapa_cmd_len cyapa_smbus_cmds[] = {
+ { CYAPA_SMBUS_RESET, 1 }, /* CYAPA_CMD_SOFT_RESET */
+ { CYAPA_SMBUS_POWER_MODE, 1 }, /* CYAPA_CMD_POWER_MODE */
+ { CYAPA_SMBUS_DEV_STATUS, 1 }, /* CYAPA_CMD_DEV_STATUS */
+ { CYAPA_SMBUS_GROUP_DATA, sizeof(struct cyapa_reg_data) },
+ /* CYAPA_CMD_GROUP_DATA */
+ { CYAPA_SMBUS_GROUP_CMD, 2 }, /* CYAPA_CMD_GROUP_CMD */
+ { CYAPA_SMBUS_GROUP_QUERY, QUERY_DATA_SIZE },
+ /* CYAPA_CMD_GROUP_QUERY */
+ { CYAPA_SMBUS_BL_STATUS, 3 }, /* CYAPA_CMD_BL_STATUS */
+ { CYAPA_SMBUS_BL_HEAD, 16 }, /* CYAPA_CMD_BL_HEAD */
+ { CYAPA_SMBUS_BL_CMD, 16 }, /* CYAPA_CMD_BL_CMD */
+ { CYAPA_SMBUS_BL_DATA, 16 }, /* CYAPA_CMD_BL_DATA */
+ { CYAPA_SMBUS_BL_ALL, 32 }, /* CYAPA_CMD_BL_ALL */
+ { CYAPA_SMBUS_BLK_PRODUCT_ID, PRODUCT_ID_SIZE },
+ /* CYAPA_CMD_BLK_PRODUCT_ID */
+ { CYAPA_SMBUS_BLK_HEAD, 16 }, /* CYAPA_CMD_BLK_HEAD */
+ { CYAPA_SMBUS_MAX_BASELINE, 1 }, /* CYAPA_CMD_MAX_BASELINE */
+ { CYAPA_SMBUS_MIN_BASELINE, 1 }, /* CYAPA_CMD_MIN_BASELINE */
+};
+
+static bool data_reporting_started;
+
+
+/*
+ * 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.
+ */
+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;
+}
+
+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);
+}
+
+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);
+}
+
+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);
+ }
+ cmd = cyapa_i2c_cmds[cmd_idx].cmd;
+ len = cyapa_i2c_cmds[cmd_idx].len;
+ return cyapa_i2c_reg_read_block(cyapa, cmd, len, values);
+}
+
+/*
+ * Determine the Gen3 trackpad device's current operating state.
+ *
+ */
+static int cyapa_gen3_state_parse(struct cyapa *cyapa, u8 *reg_data, int len)
+{
+ /*
+ * Must be in detecting and should not do data reporting.
+ * It will be reenabled when all detecting done and lauched into
+ * applicaiton mode successfully.
+ */
+ data_reporting_started = false;
+ cyapa->state = CYAPA_STATE_NO_DEVICE;
+
+ /* Parse based on Gen3 characteristic registers and bits */
+ if (reg_data[REG_BL_FILE] == BL_FILE &&
+ reg_data[REG_BL_ERROR] == BL_ERROR_NO_ERR_IDLE &&
+ (reg_data[REG_BL_STATUS] ==
+ (BL_STATUS_RUNNING | BL_STATUS_CSUM_VALID) ||
+ reg_data[REG_BL_STATUS] == BL_STATUS_RUNNING)) {
+ /*
+ * Normal state after power on or reset,
+ * REG_BL_STATUS == 0x11, firmware image checksum is valid.
+ * REG_BL_STATUS == 0x10, firmware image checksum is invalid.
+ */
+ cyapa->gen = CYAPA_GEN3;
+ cyapa->state = CYAPA_STATE_BL_IDLE;
+ } else if (reg_data[REG_BL_FILE] == BL_FILE &&
+ (reg_data[REG_BL_STATUS] & BL_STATUS_RUNNING) ==
+ BL_STATUS_RUNNING) {
+ cyapa->gen = CYAPA_GEN3;
+ if (reg_data[REG_BL_STATUS] & BL_STATUS_BUSY) {
+ cyapa->state = CYAPA_STATE_BL_BUSY;
+ } else {
+ if ((reg_data[REG_BL_ERROR] & BL_ERROR_BOOTLOADING) ==
+ BL_ERROR_BOOTLOADING)
+ cyapa->state = CYAPA_STATE_BL_ACTIVE;
+ else
+ cyapa->state = CYAPA_STATE_BL_IDLE;
+ }
+ } else if ((reg_data[REG_OP_STATUS] & OP_STATUS_SRC) &&
+ (reg_data[REG_OP_DATA1] & OP_DATA_VALID)) {
+ /*
+ * Normal state when running in operaitonal mode,
+ * may also not in full power state or
+ * busying in command process.
+ */
+ if (GEN3_FINGER_NUM(reg_data[REG_OP_DATA1]) <=
+ GEN3_MAX_FINGERS) {
+ /* Finger number data is valid. */
+ cyapa->gen = CYAPA_GEN3;
+ cyapa->state = CYAPA_STATE_OP;
+ }
+ } else if (reg_data[REG_OP_STATUS] == 0x0C &&
+ reg_data[REG_OP_DATA1] == 0x08) {
+ /* Op state when first two registers overwritten with 0x00 */
+ cyapa->gen = CYAPA_GEN3;
+ cyapa->state = CYAPA_STATE_OP;
+ } else if (reg_data[REG_BL_STATUS] &
+ (BL_STATUS_RUNNING | BL_STATUS_BUSY)) {
+ cyapa->gen = CYAPA_GEN3;
+ cyapa->state = CYAPA_STATE_BL_BUSY;
+ }
+
+ if (cyapa->gen == CYAPA_GEN3 && (cyapa->state == CYAPA_STATE_OP ||
+ cyapa->state == CYAPA_STATE_BL_IDLE ||
+ cyapa->state == CYAPA_STATE_BL_ACTIVE ||
+ cyapa->state == CYAPA_STATE_BL_BUSY))
+ return 0;
+
+ return -EAGAIN;
+}
+
+static int cyapa_gen3_bl_deactivate(struct cyapa *cyapa)
+{
+ int ret;
+
+ ret = cyapa_i2c_reg_write_block(cyapa, 0, sizeof(bl_deactivate),
+ bl_deactivate);
+ if (ret < 0)
+ return ret;
+
+ /* 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;
+}
+
+/*
+ * 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_gen3_bl_exit(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. If the device power is
+ * running low, this may take even longer.
+ */
+ ret = cyapa_poll_state(cyapa, 4000);
+ if (ret < 0)
+ return ret;
+ if (cyapa->state != CYAPA_STATE_OP)
+ return -EAGAIN;
+
+ return 0;
+}
+
+/*
+ * cyapa_get_wait_time_for_pwr_cmd
+ *
+ * Compute the amount of time we need to wait after updating the touchpad
+ * power mode. The touchpad needs to consume the incoming power mode set
+ * command at the current clock rate.
+ */
+
+static u16 cyapa_get_wait_time_for_pwr_cmd(u8 pwr_mode)
+{
+ switch (pwr_mode) {
+ case PWR_MODE_FULL_ACTIVE: return 20;
+ case PWR_MODE_BTN_ONLY: return 20;
+ case PWR_MODE_OFF: return 20;
+ default: return cyapa_pwr_cmd_to_sleep_time(pwr_mode) + 50;
+ }
+}
+
+/*
+ * Set device power mode
+ *
+ * Write to the field to configure power state. Power states include :
+ * Full : Max scans and report rate.
+ * Idle : Report rate set by user specified time.
+ * ButtonOnly : No scans for fingers. When the button is triggered,
+ * a slave interrupt is asserted to notify host to wake up.
+ * Off : Only awake for i2c commands from host. No function for button
+ * or touch sensors.
+ *
+ * The power_mode command should conform to the following :
+ * Full : 0x3f
+ * Idle : Configurable from 20 to 1000ms. See note below for
+ * cyapa_sleep_time_to_pwr_cmd and cyapa_pwr_cmd_to_sleep_time
+ * ButtonOnly : 0x01
+ * Off : 0x00
+ *
+ * Device power mode can only be set when device is in operational mode.
+ */
+static int cyapa_gen3_set_power_mode(struct cyapa *cyapa, u8 power_mode,
+ u16 always_unused)
+{
+ int ret;
+ u8 power;
+ int tries = SET_POWER_MODE_TRIES;
+ u16 sleep_time;
+
+ always_unused = 0;
+ if (cyapa->state != CYAPA_STATE_OP)
+ return 0;
+
+ while (true) {
+ ret = cyapa_read_byte(cyapa, CYAPA_CMD_POWER_MODE);
+ if (ret >= 0 || --tries < 1)
+ break;
+ usleep_range(SET_POWER_MODE_DELAY, 2 * SET_POWER_MODE_DELAY);
+ }
+ if (ret < 0)
+ return ret;
+
+ /*
+ * Return early if the power mode to set is the same as the current
+ * one.
+ */
+ if ((ret & PWR_MODE_MASK) == power_mode)
+ return 0;
+
+ sleep_time = cyapa_get_wait_time_for_pwr_cmd(ret & PWR_MODE_MASK);
+ power = ret;
+ power &= ~PWR_MODE_MASK;
+ power |= power_mode & PWR_MODE_MASK;
+ while (true) {
+ ret = cyapa_write_byte(cyapa, CYAPA_CMD_POWER_MODE, power);
+ if (!ret || --tries < 1)
+ break;
+ usleep_range(SET_POWER_MODE_DELAY, 2 * SET_POWER_MODE_DELAY);
+ }
+
+ /*
+ * Wait for the newly set power command to go in at the previous
+ * clock speed (scanrate) used by the touchpad firmware. Not
+ * doing so before issuing the next command may result in errors
+ * depending on the command's content.
+ */
+ msleep(sleep_time);
+ return ret;
+}
+
+static int cyapa_gen3_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 != QUERY_DATA_SIZE)
+ return (ret < 0) ? ret : -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->fw_maj_ver = query_data[15];
+ cyapa->fw_min_ver = query_data[16];
+
+ 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];
+
+ cyapa->max_z = 255;
+
+ return 0;
+}
+
+static int cyapa_gen3_bl_query_data(struct cyapa *cyapa)
+{
+ u8 bl_data[CYAPA_CMD_LEN];
+ int ret;
+
+ ret = cyapa_i2c_reg_read_block(cyapa, 0, CYAPA_CMD_LEN, bl_data);
+ if (ret != CYAPA_CMD_LEN)
+ return (ret < 0) ? ret : -EIO;
+
+ /*
+ * This value will be updated again when entered application mode.
+ * If TP failed to enter application mode, this fw version values
+ * can be used as a reference.
+ * This firmware version valid when fw image checksum is valid.
+ */
+ if (bl_data[REG_BL_STATUS] ==
+ (BL_STATUS_RUNNING | BL_STATUS_CSUM_VALID)) {
+ cyapa->fw_maj_ver = bl_data[GEN3_BL_IDLE_FW_MAJ_VER_OFFSET];
+ cyapa->fw_min_ver = bl_data[GEN3_BL_IDLE_FW_MIN_VER_OFFSET];
+ }
+
+ return 0;
+}
+
+/*
+ * 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_gen3_do_operational_check(struct cyapa *cyapa)
+{
+ struct device *dev = &cyapa->client->dev;
+ int ret;
+
+ switch (cyapa->state) {
+ case CYAPA_STATE_BL_ACTIVE:
+ ret = cyapa_gen3_bl_deactivate(cyapa);
+ if (ret) {
+ dev_err(dev, "failed to bl_deactivate. %d\n", ret);
+ return ret;
+ }
+
+ /* Fallthrough state */
+ case CYAPA_STATE_BL_IDLE:
+ /* Try to get firmware version in bootloader mode. */
+ cyapa_gen3_bl_query_data(cyapa);
+
+ ret = cyapa_gen3_bl_exit(cyapa);
+ if (ret) {
+ dev_err(dev, "failed to bl_exit. %d\n", ret);
+ return ret;
+ }
+
+ /* Fallthrough state */
+ case CYAPA_STATE_OP:
+ /*
+ * Reading query data before going back to the full mode
+ * may cause problems, so we set the power mode first here.
+ */
+ ret = cyapa_gen3_set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE, 0);
+ if (ret)
+ dev_err(dev, "%s: set full power mode failed, (%d)\n",
+ __func__, ret);
+ ret = cyapa_gen3_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,
+ strlen(unique_str)) != 0) {
+ dev_err(dev, "unsupported product ID (%s)\n",
+ cyapa->product_id);
+ return -EINVAL;
+ }
+
+ data_reporting_started = true;
+ return 0;
+
+ default:
+ return -EIO;
+ }
+ return 0;
+}
+
+/*
+ * Return false, do not continue process
+ * Return true, continue process.
+ */
+static bool cyapa_gen3_irq_cmd_handler(struct cyapa *cyapa)
+{
+ if (data_reporting_started)
+ return true;
+
+ /*
+ * Driver in detecting or other interface function processing,
+ * so, stop cyapa_gen3_irq_handler to continue process to
+ * avoid unwanted to error detecting and processing.
+ *
+ * And also, avoid the periodicly accerted interrupts to be processed
+ * as touch inputs when gen3 failed to launch into application mode,
+ * which will cause gen3 stays in bootloader mode.
+ */
+ return false;
+}
+
+static void cyapa_gen3_irq_handler(struct cyapa *cyapa)
+{
+ struct input_dev *input = cyapa->input;
+ struct cyapa_reg_data data;
+ int i;
+ int ret;
+ int num_fingers;
+
+ if (!input)
+ return;
+
+ ret = cyapa_read_block(cyapa, CYAPA_CMD_GROUP_DATA, (u8 *)&data);
+ if (ret != sizeof(data)) {
+ async_schedule(cyapa_detect_async, cyapa);
+ return;
+ }
+
+ 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) {
+ async_schedule(cyapa_detect_async, cyapa);
+ return;
+ }
+
+ 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_gen3_ops = {
+ .state_parse = cyapa_gen3_state_parse,
+ .operational_check = cyapa_gen3_do_operational_check,
+
+ .irq_handler = cyapa_gen3_irq_handler,
+ .irq_cmd_handler = cyapa_gen3_irq_cmd_handler,
+
+ .set_power_mode = cyapa_gen3_set_power_mode,
+};
--
1.9.1
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox