RE: [PATCH v3 2/4] input: Cypress PS/2 Trackpad psmouse driver

2012-12-04 Thread Dudley Du
Hi Henrik, Kamal,

Thanks for your review.
And I add some comments in below.

Thanks.
Dudley Du
d...@cypress.com

> Hi Henrik-
>
> Thanks again for your review.  The forthcoming PATCH v4 includes the majority 
> of your change requests, except where noted below (and considering my email 
> "Subject: SEMI_MT vs. simulated mt")...
>
>
> On Mon, 2012-12-03 at 08:45 +0100, Henrik Rydberg wrote:
>
> > > + /*
> > > +  * send extension command 0xE8 or 0xF3,
> > > +  * if send extension command failed,
> > > +  * try to send recovery command to make
> > > +  * trackpad device return to ready wait command state.
> > > +  * It alwasy success based on this recovery commands.
> >
> > -EPARSE
>
> I don't understand the meaning of that comment either.  Perhaps the original 
> author Dudley Du can explain it.

Since all trackpad specific commands are sent as extension command,
the format of extension command series is "0xE8 dd 0xE8 cc 0xE8 bb 0xE8".
And as we know, it may fail when sending the extension command series,
So this comment just want to indicates that if some unknown error occurred when 
sending the extension command,
this code will send recovery command to make trackpad firmware go back to ready 
state,
so same command can be tried to be re-sent.
Sorry for the bad comments causing confusion.

> > > +static int cypress_read_vital_statistics(struct psmouse *psmouse)
> >
> > Why do you call this statistics?
>
> Perhaps "cypress_read_tp_metrics" would be a better name.  Any thoughts on 
> this, Dudley?
>
>
> > > +/*
> > > + * reset trackpad device to standard relative mode.
> > > + * This is also the defalut mode when trackpad powered on.
> > > + */
> > > +static void cypress_reset(struct psmouse *psmouse) {
> > > + struct cytp_data *cytp = psmouse->private;
> > > +
> > > + psmouse_reset(psmouse);
> > > +
> > > + CYTP_SET_MODE_BIT(CYTP_BIT_STANDARD_REL);
> > > + CYTP_SET_PACKET_SIZE(3);
> > > +
> > > + cytp->prev_contact_cnt = 0;
> > > +}
> >
> > I suppose it is, but is it necessary to reset to default mode?
>
> I left this unchanged, as I think you and Dmitry agreed.
>
>
> > > +
> > > +static int cypress_set_input_params(struct input_dev *input,
> > > + struct cytp_data *cytp)
> > > +{
> > > + int ret;
> > > +
> > > + if (cytp->mode & CYTP_BIT_ABS_MASK) {
> >
> > It seems the device will always operate in this mode, so please simplify.
>
> I #ifdef'd out the unused relative-mode code, as opposed to deleting it.
> Will that be acceptable?

I think relative-mode code should be reserved,
since for some unknown reason, trackpad may failed in absolution mode,
and in order to make trackpad device kept on usable,
we may set it to relative-mode,
so in this situation, the relative-mode code should be exist.


> > > + /* Remove HSCROLL bit */
> > > + if (report_data->contact_cnt == 4)
> > > + header_byte &= ~(ABS_HSCROLL_BIT);
> >
> > Why conditionally?
>
> Dudley, can you answer this?  I left this (and all the scroll code) unchanged.

Yes, this condition should be reserved.
Because ABS_HSCROLL_BIT is will reused to indicate finger numbers when finger 
number is bigger than 3.
And when the contact_cnt is 4, the ABS_HSCROLL_BIT is set to indicate 4 fingers 
touched, not HSCROLL BIT set.
But it will be confused with the flag of HSCROLL bit with one finger touched.
So we must clear this bit when contact_cnt is 4.


> > > +#if 0
> > > + /* FIXME: cypress_reconnect() never works...
> > > +  * just let psmouse re-init() us for now.
> > > +  */
> > > + psmouse->reconnect = cypress_reconnect; #endif
> >
> > This needs to be removed or fixed, of course.
>
> Per Dudley, this does work in his disconnect/reconnect scenario, so I 
> re-enabled it.  We will continue to investigate why it fails
> (harmlessly) in my suspend/resume scenario.


> > > + int tp_max_abs_x;  /* Max X absolution units can be reported. */
> > > + int tp_max_abs_y;  /* Max Y absolution units can be reported. */
> >
> > I do not think we are seeking absolution here. :-)
>
> Ha!  Speak for yourself, Henrik!  ;-)  I'm starting to feel like maybe I 
> should be seeking absolution here!
>
>
>  -Kamal

This message and any attachments may contain Cypress (or its subsidiaries) 
confidential information. If it has been received in error, please advise the 
sender and immediately delete this message.


Re: [PATCH v3 2/4] input: Cypress PS/2 Trackpad psmouse driver

2012-12-04 Thread Kamal Mostafa
Hi Henrik-

Thanks again for your review.  The forthcoming PATCH v4 includes the
majority of your change requests, except where noted below (and
considering my email "Subject: SEMI_MT vs. simulated mt")...


On Mon, 2012-12-03 at 08:45 +0100, Henrik Rydberg wrote:

> > +   /*
> > +* send extension command 0xE8 or 0xF3,
> > +* if send extension command failed,
> > +* try to send recovery command to make
> > +* trackpad device return to ready wait command state.
> > +* It alwasy success based on this recovery commands.
> 
> -EPARSE

I don't understand the meaning of that comment either.  Perhaps the
original author Dudley Du can explain it.


> > +static int cypress_read_vital_statistics(struct psmouse *psmouse)
> 
> Why do you call this statistics?

Perhaps "cypress_read_tp_metrics" would be a better name.  Any thoughts
on this, Dudley?


> > +/*
> > + * reset trackpad device to standard relative mode.
> > + * This is also the defalut mode when trackpad powered on.
> > + */
> > +static void cypress_reset(struct psmouse *psmouse)
> > +{
> > +   struct cytp_data *cytp = psmouse->private;
> > +
> > +   psmouse_reset(psmouse);
> > +
> > +   CYTP_SET_MODE_BIT(CYTP_BIT_STANDARD_REL);
> > +   CYTP_SET_PACKET_SIZE(3);
> > +
> > +   cytp->prev_contact_cnt = 0;
> > +}
> 
> I suppose it is, but is it necessary to reset to default mode?

I left this unchanged, as I think you and Dmitry agreed.


> > +
> > +static int cypress_set_input_params(struct input_dev *input,
> > +   struct cytp_data *cytp)
> > +{
> > +   int ret;
> > +
> > +   if (cytp->mode & CYTP_BIT_ABS_MASK) {
> 
> It seems the device will always operate in this mode, so please simplify.

I #ifdef'd out the unused relative-mode code, as opposed to deleting it.
Will that be acceptable?


> > +   /* Remove HSCROLL bit */
> > +   if (report_data->contact_cnt == 4)
> > +   header_byte &= ~(ABS_HSCROLL_BIT);
> 
> Why conditionally?

Dudley, can you answer this?  I left this (and all the scroll code)
unchanged.


> > +#if 0
> > +   /* FIXME: cypress_reconnect() never works...
> > +* just let psmouse re-init() us for now.
> > +*/
> > +   psmouse->reconnect = cypress_reconnect;
> > +#endif
> 
> This needs to be removed or fixed, of course.

Per Dudley, this does work in his disconnect/reconnect scenario, so I
re-enabled it.  We will continue to investigate why it fails
(harmlessly) in my suspend/resume scenario.


> > +   int tp_max_abs_x;  /* Max X absolution units can be reported. */
> > +   int tp_max_abs_y;  /* Max Y absolution units can be reported. */
> 
> I do not think we are seeking absolution here. :-)

Ha!  Speak for yourself, Henrik!  ;-)  I'm starting to feel like maybe I
should be seeking absolution here!


 -Kamal


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 2/4] input: Cypress PS/2 Trackpad psmouse driver

2012-12-03 Thread Dmitry Torokhov
On Mon, Dec 03, 2012 at 08:45:20AM +0100, Henrik Rydberg wrote:
> > +/*
> > + * reset trackpad device to standard relative mode.
> > + * This is also the defalut mode when trackpad powered on.
> > + */
> > +static void cypress_reset(struct psmouse *psmouse)
> > +{
> > +   struct cytp_data *cytp = psmouse->private;
> > +
> > +   psmouse_reset(psmouse);
> > +
> > +   CYTP_SET_MODE_BIT(CYTP_BIT_STANDARD_REL);
> > +   CYTP_SET_PACKET_SIZE(3);
> > +
> > +   cytp->prev_contact_cnt = 0;
> > +}
> 
> I suppose it is, but is it necessary to reset to default mode?

It most likely is, as quite a few BIOSes get very upset and refuse to
shutdown/suspend/resume if they find mouse (touchpad) in state other
than bog-standard PS/2 mode. So psmouse_reset() is needed, the rest is
not so much as the device supposed to be inactive from this point on.

Thanks.

-- 
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 2/4] input: Cypress PS/2 Trackpad psmouse driver

2012-12-02 Thread Henrik Rydberg
Hi Kamal,

> From: Cypress Semiconductor Corporation 
> 
> Input/mouse driver for Cypress PS/2 Trackpad.
> 
> Original code contributed by Cypress Semiconductor Corporation,
> modified by Kamal Mostafa and Kyle Fazzari.
> 
> BugLink: http://launchpad.net/bugs/978807
> 
> Signed-off-by: Kamal Mostafa 
> Signed-off-by: Kyle Fazzari 
> Signed-off-by: Mario Limonciello 
> Signed-off-by: Tim Gardner 
> Acked-by: Herton Krzesinski 
> ---
>  drivers/input/mouse/cypress_ps2.c |  830 
> +
>  drivers/input/mouse/cypress_ps2.h |  219 ++
>  2 files changed, 1049 insertions(+)
>  create mode 100644 drivers/input/mouse/cypress_ps2.c
>  create mode 100644 drivers/input/mouse/cypress_ps2.h

Thanks for the patch, it seems to improve nicely. Please find comments inline.

> 
> diff --git a/drivers/input/mouse/cypress_ps2.c 
> b/drivers/input/mouse/cypress_ps2.c
> new file mode 100644
> index 000..472342a
> --- /dev/null
> +++ b/drivers/input/mouse/cypress_ps2.c
> @@ -0,0 +1,830 @@
> +/*
> + * Cypress Trackpad PS/2 mouse driver
> + *
> + * Copyright (c) 2012 Cypress Semiconductor Corporation.
> + *
> + * Additional contributors include:
> + *   Kamal Mostafa 
> + *   Kyle Fazzari 
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License version 2 as published 
> by
> + * the Free Software Foundation.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "cypress_ps2.h"
> +
> +#define CYTP_DBG_DUMP 0  /* set to 1 for more verbose debug dump 
> */
> +
> +#define cytp_dbg(fmt, ...)  \
> + do {  \
> + if (cytp)  \
> + psmouse_dbg(psmouse, pr_fmt(fmt), ##__VA_ARGS__);  \
> + } while (0)

Where is cytp defined?

> +
> +#if CYTP_DBG_DUMP
> +# define cytp_dbg_dump cytp_dbg
> +#else
> +# define cytp_dbg_dump(fmt, ...)
> +#endif
> +
> +
> +/* p is a pointer points to the buffer containing Cypress Keys. */
> +#define IS_CYPRESS_KEY(p) ((p[0] == CYPRESS_KEY_1) && (p[1] == 
> CYPRESS_KEY_2))

If you use a function instead, you do not need to explain the type.

> +#define CYTP_SET_PACKET_SIZE(n) { psmouse->pktsize = cytp->pkt_size = (n); }

More magic cytp argument stuff, please reformulate this.

> +#define CYTP_SET_MODE_BIT(x)  \
> + do {  \
> + if ((x) & CYTP_BIT_ABS_REL_MASK)  \
> + cytp->mode = (cytp->mode & ~CYTP_BIT_ABS_REL_MASK);  \
> + cytp->mode |= (x);  \
> + } while (0)

Given the generic name, this function does something completely
unexpected. Also, branching on bit manipulations seems odd.

> +#define CYTP_CLEAR_MODE_BIT(x)   { cytp->mode &= ~(x); }

Seems unnecessary to define here for a single instance in the code.

> +
> +#define CYTP_SUPPORT_ABS

Stale code?

> +
> +static unsigned char cytp_rate[] = {10, 20, 40, 60, 100, 200};
> +static unsigned char cytp_resolution[] = {0x00, 0x01, 0x02, 0x03};

const, please.

> +
> +static int cypress_ps2_sendbyte(struct psmouse *psmouse, int value)
> +{
> + struct cytp_data *cytp = psmouse->private;
> + struct ps2dev *ps2dev = &psmouse->ps2dev;
> +
> + if (ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT) < 0) {
> + cytp_dbg("send command 0x%02x failed, resp 0x%02x\n",
> +  value & 0xff, ps2dev->nak);
> + if (ps2dev->nak == CYTP_PS2_RETRY)
> + return CYTP_PS2_RETRY;
> + else
> + return CYTP_PS2_ERROR;
> + }
> +
> + cytp_dbg("send command 0x%02x success, resp 0xfa\n", value & 0xff);
> +
> + return 0;
> +}
> +
> +static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd,
> +unsigned char data)
> +{
> + struct ps2dev *ps2dev = &psmouse->ps2dev;
> + int tries = CYTP_PS2_CMD_TRIES;
> + int rc;
> +
> + ps2_begin_command(ps2dev);
> +
> + do {
> + /*
> +  * send extension command 0xE8 or 0xF3,
> +  * if send extension command failed,
> +  * try to send recovery command to make
> +  * trackpad device return to ready wait command state.
> +  * It alwasy success based on this recovery commands.

-EPARSE

> +  */
> + rc = cypress_ps2_sendbyte(psmouse, cmd & 0xff);
> + if (rc == CYTP_PS2_RETRY) {
> + rc = cypress_ps2_sendbyte(psmouse, 0x00);
> + if (rc == CYTP_PS2_RETRY)
> + rc = cypress_ps2_sendbyte(psmouse, 0x0a);
> + }
> + if (rc == CYTP_PS2_ERROR)
> + continue;
> +
> + rc = cypress_ps2_sendbyte(psmouse, data);
> + if (rc == CYTP_PS2_RETRY)
> + rc = cypress_ps2_sendbyte(psmouse, data);
> + if (rc == CY

RE: [PATCH v3 2/4] input: Cypress PS/2 Trackpad psmouse driver

2012-12-02 Thread Dudley Du
Hi Henrik,

Okay, agree.
Thanks.

Best Wishes,
Dudley Du
d...@cypress.com

-Original Message-
From: Henrik Rydberg [mailto:rydb...@euromail.se]
Sent: Monday, December 03, 2012 2:31 PM
To: Dudley Du
Cc: Kamal Mostafa; linux-in...@vger.kernel.org; linux-kernel@vger.kernel.org; 
Dmitry Torokhov; David Solda; Troy Abercrombia; customercare; Kyle Fazzari; 
Mario Limonciello; Tim Gardner; Herton Krzesinski; d...@cyress.com
Subject: Re: [PATCH v3 2/4] input: Cypress PS/2 Trackpad psmouse driver

Hi Dudley,

> Another question is that new interface input_mt_assign_slots() is
> introduced since 3.7-rc7 or later, So we could not support the kernel 
> releases that earlier than 3.7-rc7 with this driver.

The patch is a submission to mainline, so of course it should be in sync with 
mainline.

Thanks.
Henrik

This message and any attachments may contain Cypress (or its subsidiaries) 
confidential information. If it has been received in error, please advise the 
sender and immediately delete this message.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 2/4] input: Cypress PS/2 Trackpad psmouse driver

2012-12-02 Thread Henrik Rydberg
Hi Dudley,

> Another question is that new interface input_mt_assign_slots() is introduced 
> since 3.7-rc7 or later,
> So we could not support the kernel releases that earlier than 3.7-rc7 with 
> this driver.

The patch is a submission to mainline, so of course it should be in sync with 
mainline.

Thanks.
Henrik
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH v3 2/4] input: Cypress PS/2 Trackpad psmouse driver

2012-12-02 Thread Dudley Du
Hi Kamal,

Another question is that new interface input_mt_assign_slots() is introduced 
since 3.7-rc7 or later,
So we could not support the kernel releases that earlier than 3.7-rc7 with this 
driver.

So my idea is that in order to keep compatible with earlier kernel release,
Let's use our old method to calculate the slots, not using latest interface 
input_mt_assign_slots() here.

What's your idea about it?

Thanks.

Best Wishes,
Dudley Du
d...@cypress.com


-Original Message-
From: Dudley Du
Sent: Monday, December 03, 2012 11:21 AM
To: 'Kamal Mostafa'; linux-in...@vger.kernel.org; linux-kernel@vger.kernel.org; 
Dmitry Torokhov; Henrik Rydberg
Cc: David Solda; Troy Abercrombia; customercare; Kyle Fazzari; Mario 
Limonciello; Tim Gardner; Herton Krzesinski; 'd...@cyress.com'
Subject: RE: [PATCH v3 2/4] input: Cypress PS/2 Trackpad psmouse driver

Hi Kamal,

I'm the writer of this driver.
Thanks for help upstream this driver.

I noticed that you marked out the reconnect function for it never work at all.
But in my test, it seems work fine.
I do the test steps as below:
1. load this driver with Cypress trackpad. Cursor moving on system; 2. directly 
unplug the trackpad from system; 3. reconnect the trackpad device to PC again; 
4. moving finger on trackpad to check cursor still working on the system.
And also, I checked the debug message through dmesg, it makes sure that the 
reconnection function is called, and also the driver and trackpad still working 
fine.

So I want to know what situation is in your test to this function, could you 
help describe your test steps to me, so we can figure out this issue.

Thanks.

Best Wishes,
Dudley Du
d...@cyrpess.com



>From: Cypress Semiconductor Corporation 
>
>Input/mouse driver for Cypress PS/2 Trackpad.
>
>Original code contributed by Cypress Semiconductor Corporation,
>modified by Kamal Mostafa and Kyle Fazzari.
>
>BugLink: http://launchpad.net/bugs/978807
>
>Signed-off-by: Kamal Mostafa 
>Signed-off-by: Kyle Fazzari 
>Signed-off-by: Mario Limonciello 
>Signed-off-by: Tim Gardner 
>Acked-by: Herton Krzesinski 
>---
> drivers/input/mouse/cypress_ps2.c |  830
>+
> drivers/input/mouse/cypress_ps2.h |  219 ++
> 2 files changed, 1049 insertions(+)
> create mode 100644 drivers/input/mouse/cypress_ps2.c  create mode
>100644 drivers/input/mouse/cypress_ps2.h
>
>diff --git a/drivers/input/mouse/cypress_ps2.c
>b/drivers/input/mouse/cypress_ps2.c
>new file mode 100644
>index 000..472342a
>--- /dev/null
>+++ b/drivers/input/mouse/cypress_ps2.c
>@@ -0,0 +1,830 @@
>+/*
>+ * Cypress Trackpad PS/2 mouse driver
>+ *
>+ * Copyright (c) 2012 Cypress Semiconductor Corporation.
>+ *
>+ * Additional contributors include:
>+ *   Kamal Mostafa 
>+ *   Kyle Fazzari 
>+ *
>+ * This program is free software; you can redistribute it and/or
>+modify it
>+ * under the terms of the GNU General Public License version 2 as
>+published by
>+ * the Free Software Foundation.
>+ */
>+
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+
>+#include "cypress_ps2.h"
>+
>+#define CYTP_DBG_DUMP 0   /* set to 1 for more verbose debug dump 
>*/
>+
>+#define cytp_dbg(fmt, ...)  \
>+  do {  \
>+  if (cytp)  \
>+  psmouse_dbg(psmouse, pr_fmt(fmt), ##__VA_ARGS__);  \
>+  } while (0)
>+
>+#if CYTP_DBG_DUMP
>+# define cytp_dbg_dump cytp_dbg
>+#else
>+# define cytp_dbg_dump(fmt, ...)
>+#endif
>+
>+
>+/* p is a pointer points to the buffer containing Cypress Keys. */
>+#define IS_CYPRESS_KEY(p) ((p[0] == CYPRESS_KEY_1) && (p[1] ==
>+CYPRESS_KEY_2)) #define CYTP_SET_PACKET_SIZE(n) { psmouse->pktsize =
>+cytp->pkt_size = (n); } #define CYTP_SET_MODE_BIT(x)  \
>+  do {  \
>+  if ((x) & CYTP_BIT_ABS_REL_MASK)  \
>+  cytp->mode = (cytp->mode & ~CYTP_BIT_ABS_REL_MASK);  \
>+  cytp->mode |= (x);  \
>+  } while (0)
>+#define CYTP_CLEAR_MODE_BIT(x){ cytp->mode &= ~(x); }
>+
>+#define CYTP_SUPPORT_ABS
>+
>+static unsigned char cytp_rate[] = {10, 20, 40, 60, 100, 200}; static
>+unsigned char cytp_resolution[] = {0x00, 0x01, 0x02, 0x03};
>+
>+static int cypress_ps2_sendbyte(struct psmouse *psmouse, int value) {
>+  struct cytp_data *cytp = psmouse->private;
>+  struct ps2dev *ps2dev = &psmouse->ps2dev;
>+
>+  if (ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT) < 0) {
>+  cytp_dbg("send command 0x%02x failed, resp 0x%02x\n",
>+ 

RE: [PATCH v3 2/4] input: Cypress PS/2 Trackpad psmouse driver

2012-12-02 Thread Dudley Du
Hi Kamal,

I'm the writer of this driver.
Thanks for help upstream this driver.

I noticed that you marked out the reconnect function for it never work at all.
But in my test, it seems work fine.
I do the test steps as below:
1. load this driver with Cypress trackpad. Cursor moving on system;
2. directly unplug the trackpad from system;
3. reconnect the trackpad device to PC again;
4. moving finger on trackpad to check cursor still working on the system.
And also, I checked the debug message through dmesg, it makes sure that the 
reconnection function is called, and also the driver and trackpad still working 
fine.

So I want to know what situation is in your test to this function,
could you help describe your test steps to me, so we can figure out this issue.

Thanks.

Best Wishes,
Dudley Du
d...@cyrpess.com



>From: Cypress Semiconductor Corporation 
>
>Input/mouse driver for Cypress PS/2 Trackpad.
>
>Original code contributed by Cypress Semiconductor Corporation,
>modified by Kamal Mostafa and Kyle Fazzari.
>
>BugLink: http://launchpad.net/bugs/978807
>
>Signed-off-by: Kamal Mostafa 
>Signed-off-by: Kyle Fazzari 
>Signed-off-by: Mario Limonciello 
>Signed-off-by: Tim Gardner 
>Acked-by: Herton Krzesinski 
>---
> drivers/input/mouse/cypress_ps2.c |  830 +
> drivers/input/mouse/cypress_ps2.h |  219 ++
> 2 files changed, 1049 insertions(+)
> create mode 100644 drivers/input/mouse/cypress_ps2.c
> create mode 100644 drivers/input/mouse/cypress_ps2.h
>
>diff --git a/drivers/input/mouse/cypress_ps2.c 
>b/drivers/input/mouse/cypress_ps2.c
>new file mode 100644
>index 000..472342a
>--- /dev/null
>+++ b/drivers/input/mouse/cypress_ps2.c
>@@ -0,0 +1,830 @@
>+/*
>+ * Cypress Trackpad PS/2 mouse driver
>+ *
>+ * Copyright (c) 2012 Cypress Semiconductor Corporation.
>+ *
>+ * Additional contributors include:
>+ *   Kamal Mostafa 
>+ *   Kyle Fazzari 
>+ *
>+ * This program is free software; you can redistribute it and/or modify it
>+ * under the terms of the GNU General Public License version 2 as published by
>+ * the Free Software Foundation.
>+ */
>+
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+
>+#include "cypress_ps2.h"
>+
>+#define CYTP_DBG_DUMP 0   /* set to 1 for more verbose debug dump 
>*/
>+
>+#define cytp_dbg(fmt, ...)  \
>+  do {  \
>+  if (cytp)  \
>+  psmouse_dbg(psmouse, pr_fmt(fmt), ##__VA_ARGS__);  \
>+  } while (0)
>+
>+#if CYTP_DBG_DUMP
>+# define cytp_dbg_dump cytp_dbg
>+#else
>+# define cytp_dbg_dump(fmt, ...)
>+#endif
>+
>+
>+/* p is a pointer points to the buffer containing Cypress Keys. */
>+#define IS_CYPRESS_KEY(p) ((p[0] == CYPRESS_KEY_1) && (p[1] == CYPRESS_KEY_2))
>+#define CYTP_SET_PACKET_SIZE(n) { psmouse->pktsize = cytp->pkt_size = (n); }
>+#define CYTP_SET_MODE_BIT(x)  \
>+  do {  \
>+  if ((x) & CYTP_BIT_ABS_REL_MASK)  \
>+  cytp->mode = (cytp->mode & ~CYTP_BIT_ABS_REL_MASK);  \
>+  cytp->mode |= (x);  \
>+  } while (0)
>+#define CYTP_CLEAR_MODE_BIT(x){ cytp->mode &= ~(x); }
>+
>+#define CYTP_SUPPORT_ABS
>+
>+static unsigned char cytp_rate[] = {10, 20, 40, 60, 100, 200};
>+static unsigned char cytp_resolution[] = {0x00, 0x01, 0x02, 0x03};
>+
>+static int cypress_ps2_sendbyte(struct psmouse *psmouse, int value)
>+{
>+  struct cytp_data *cytp = psmouse->private;
>+  struct ps2dev *ps2dev = &psmouse->ps2dev;
>+
>+  if (ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT) < 0) {
>+  cytp_dbg("send command 0x%02x failed, resp 0x%02x\n",
>+   value & 0xff, ps2dev->nak);
>+  if (ps2dev->nak == CYTP_PS2_RETRY)
>+  return CYTP_PS2_RETRY;
>+  else
>+  return CYTP_PS2_ERROR;
>+  }
>+
>+  cytp_dbg("send command 0x%02x success, resp 0xfa\n", value & 0xff);
>+
>+  return 0;
>+}
>+
>+static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd,
>+ unsigned char data)
>+{
>+  struct ps2dev *ps2dev = &psmouse->ps2dev;
>+  int tries = CYTP_PS2_CMD_TRIES;
>+  int rc;
>+
>+  ps2_begin_command(ps2dev);
>+
>+  do {
>+  /*
>+   * send extension command 0xE8 or 0xF3,
>+   * if send extension command failed,
>+   * try to send recovery command to make
>+   * trackpad device return to ready wait command state.
>+   * It alwasy success based on this recovery commands.
>+   */
>+  rc = cypress_ps2_sendbyte(psmouse, cmd & 0xff);
>+  if (rc == CYTP_PS2_RETRY) {
>+  rc = cypress_ps2_sendbyte(psmouse, 0x00);
>+  if (rc == CYTP_PS2_RETRY)
>+  rc = cypress_ps2_sendbyte(psmouse, 0x0a);
>+  }
>+  if (rc == CYT

[PATCH v3 2/4] input: Cypress PS/2 Trackpad psmouse driver

2012-11-29 Thread Kamal Mostafa
From: Cypress Semiconductor Corporation 

Input/mouse driver for Cypress PS/2 Trackpad.

Original code contributed by Cypress Semiconductor Corporation,
modified by Kamal Mostafa and Kyle Fazzari.

BugLink: http://launchpad.net/bugs/978807

Signed-off-by: Kamal Mostafa 
Signed-off-by: Kyle Fazzari 
Signed-off-by: Mario Limonciello 
Signed-off-by: Tim Gardner 
Acked-by: Herton Krzesinski 
---
 drivers/input/mouse/cypress_ps2.c |  830 +
 drivers/input/mouse/cypress_ps2.h |  219 ++
 2 files changed, 1049 insertions(+)
 create mode 100644 drivers/input/mouse/cypress_ps2.c
 create mode 100644 drivers/input/mouse/cypress_ps2.h

diff --git a/drivers/input/mouse/cypress_ps2.c 
b/drivers/input/mouse/cypress_ps2.c
new file mode 100644
index 000..472342a
--- /dev/null
+++ b/drivers/input/mouse/cypress_ps2.c
@@ -0,0 +1,830 @@
+/*
+ * Cypress Trackpad PS/2 mouse driver
+ *
+ * Copyright (c) 2012 Cypress Semiconductor Corporation.
+ *
+ * Additional contributors include:
+ *   Kamal Mostafa 
+ *   Kyle Fazzari 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "cypress_ps2.h"
+
+#define CYTP_DBG_DUMP 0/* set to 1 for more verbose debug dump 
*/
+
+#define cytp_dbg(fmt, ...)  \
+   do {  \
+   if (cytp)  \
+   psmouse_dbg(psmouse, pr_fmt(fmt), ##__VA_ARGS__);  \
+   } while (0)
+
+#if CYTP_DBG_DUMP
+# define cytp_dbg_dump cytp_dbg
+#else
+# define cytp_dbg_dump(fmt, ...)
+#endif
+
+
+/* p is a pointer points to the buffer containing Cypress Keys. */
+#define IS_CYPRESS_KEY(p) ((p[0] == CYPRESS_KEY_1) && (p[1] == CYPRESS_KEY_2))
+#define CYTP_SET_PACKET_SIZE(n) { psmouse->pktsize = cytp->pkt_size = (n); }
+#define CYTP_SET_MODE_BIT(x)  \
+   do {  \
+   if ((x) & CYTP_BIT_ABS_REL_MASK)  \
+   cytp->mode = (cytp->mode & ~CYTP_BIT_ABS_REL_MASK);  \
+   cytp->mode |= (x);  \
+   } while (0)
+#define CYTP_CLEAR_MODE_BIT(x) { cytp->mode &= ~(x); }
+
+#define CYTP_SUPPORT_ABS
+
+static unsigned char cytp_rate[] = {10, 20, 40, 60, 100, 200};
+static unsigned char cytp_resolution[] = {0x00, 0x01, 0x02, 0x03};
+
+static int cypress_ps2_sendbyte(struct psmouse *psmouse, int value)
+{
+   struct cytp_data *cytp = psmouse->private;
+   struct ps2dev *ps2dev = &psmouse->ps2dev;
+
+   if (ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT) < 0) {
+   cytp_dbg("send command 0x%02x failed, resp 0x%02x\n",
+value & 0xff, ps2dev->nak);
+   if (ps2dev->nak == CYTP_PS2_RETRY)
+   return CYTP_PS2_RETRY;
+   else
+   return CYTP_PS2_ERROR;
+   }
+
+   cytp_dbg("send command 0x%02x success, resp 0xfa\n", value & 0xff);
+
+   return 0;
+}
+
+static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd,
+  unsigned char data)
+{
+   struct ps2dev *ps2dev = &psmouse->ps2dev;
+   int tries = CYTP_PS2_CMD_TRIES;
+   int rc;
+
+   ps2_begin_command(ps2dev);
+
+   do {
+   /*
+* send extension command 0xE8 or 0xF3,
+* if send extension command failed,
+* try to send recovery command to make
+* trackpad device return to ready wait command state.
+* It alwasy success based on this recovery commands.
+*/
+   rc = cypress_ps2_sendbyte(psmouse, cmd & 0xff);
+   if (rc == CYTP_PS2_RETRY) {
+   rc = cypress_ps2_sendbyte(psmouse, 0x00);
+   if (rc == CYTP_PS2_RETRY)
+   rc = cypress_ps2_sendbyte(psmouse, 0x0a);
+   }
+   if (rc == CYTP_PS2_ERROR)
+   continue;
+
+   rc = cypress_ps2_sendbyte(psmouse, data);
+   if (rc == CYTP_PS2_RETRY)
+   rc = cypress_ps2_sendbyte(psmouse, data);
+   if (rc == CYTP_PS2_ERROR)
+   continue;
+   else
+   break;
+   } while (--tries > 0);
+
+   ps2_end_command(ps2dev);
+
+   return rc;
+}
+
+static int cypress_ps2_read_cmd_status(struct psmouse *psmouse,
+  unsigned char cmd,
+  unsigned char *param)
+{
+   int i;
+   int rc;
+   struct ps2dev *ps2dev = &psmouse->ps2dev;
+   struct cytp_data *cytp = psmouse->private;
+   enum psmouse_state old_state;
+   unsigned char old_pktsize;
+
+   ps2_begin_command(&psmouse->ps2dev);
+
+   old_state = psmouse->state;
+