Re: [PATCH v2 1/1] Input: add driver for Cypress APA I2C Trackpad

2012-12-08 Thread Henrik Rydberg
Hi Benson,

> I have applied your patch, but I found I still need this line in my
> driver, otherwise, there are no ABS type event supported. Should the
> core set this bit as well since it's certainly going to be dealing
> with ABS data?
> 
> __set_bit(EV_ABS, input->evbit);

Yes, that would make sense, I will look into it.

> Otherwise, it works great on my Chromebook trackpad here.

Great,
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 v2 1/1] Input: add driver for Cypress APA I2C Trackpad

2012-12-08 Thread Henrik Rydberg
Hi Benson,

 I have applied your patch, but I found I still need this line in my
 driver, otherwise, there are no ABS type event supported. Should the
 core set this bit as well since it's certainly going to be dealing
 with ABS data?
 
 __set_bit(EV_ABS, input-evbit);

Yes, that would make sense, I will look into it.

 Otherwise, it works great on my Chromebook trackpad here.

Great,
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 v2 1/1] Input: add driver for Cypress APA I2C Trackpad

2012-12-07 Thread Benson Leung
Hi Henrik,

I have applied your patch, but I found I still need this line in my
driver, otherwise, there are no ABS type event supported. Should the
core set this bit as well since it's certainly going to be dealing
with ABS data?

__set_bit(EV_ABS, input->evbit);

Otherwise, it works great on my Chromebook trackpad here.

Thanks a bunch,
Benson

On Thu, Dec 6, 2012 at 6:59 AM, Henrik Rydberg  wrote:
> Hi Benson,
>
>> This patch introduces a driver for Cypress All Points Addressable
>> I2C Trackpad, including the ones in 2012 Samsung Chromebooks.
>>
>> This device is compatible with MT protocol type B, providing identifiable
>> contacts.
>>
>> Signed-off-by: Dudley Du 
>> Signed-off-by: Daniel Kurtz 
>> Signed-off-by: Benson Leung 
>> ---
>>  Version history :
>> v2 : * Removed firmware update.
>>  * Removed sysfs properties related to firmware update and power mode.
>>  * Folded cyapa_detect into cyapa_probe.
>>  * Added support for middle and right mechanical buttons, if they exist.
>>  * Rearranged disable_irq/enable_irq in suspend and resume to prevent
>>  a power mode change from colliding with a read of tracking data.
>>  * Made cyapa_get_state more reliable.
>>  * Use IRQF_ONESHOT for threaded irq
>>  * Simplified cyapa_set_power_mode.
>>  * Removed extra kernel-doc style comments
>>  * Removed dev_dbg messages.
>>  * Cleaned up unused includes.
>>  * Cleaned up unused #defines
>> v1 : Initial
>> ---
>>  drivers/input/mouse/Kconfig  |   12 +
>>  drivers/input/mouse/Makefile |1 +
>>  drivers/input/mouse/cyapa.c  |  838 
>> ++
>>  3 files changed, 851 insertions(+), 0 deletions(-)
>>  create mode 100644 drivers/input/mouse/cyapa.c
>
> Looking good overall. The patch does not compile in 3.7, and it is
> possible to further simplify the MT handling. The patch below takes
> care of those changes. If it still works for you with this applied, we
> should be fine.
>
> Thanks,
> Henrik
>
> diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
> index 08cf1ce..762fe9c 100644
> --- a/drivers/input/mouse/cyapa.c
> +++ b/drivers/input/mouse/cyapa.c
> @@ -545,7 +545,6 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
> int i;
> int ret;
> int num_fingers;
> -   unsigned int mask;
>
> if (device_may_wakeup(dev))
> pm_wakeup_event(dev, 0);
> @@ -560,14 +559,12 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
> goto irqhandled;
> }
>
> -   mask = 0;
> num_fingers = (data.finger_btn >> 4) & 0x0f;
> for (i = 0; i < num_fingers; i++) {
> const struct cyapa_touch *touch = [i];
> /* Note: touch->id range is 1 to 15; slots are 0 to 14. */
> int slot = touch->id - 1;
>
> -   mask |= (1 << slot);
> input_mt_slot(input, slot);
> input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
> input_report_abs(input, ABS_MT_POSITION_X,
> @@ -577,15 +574,8 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
> input_report_abs(input, ABS_MT_PRESSURE, touch->pressure);
> }
>
> -   /* Invalidate all unreported slots */
> -   for (i = 0; i < CYAPA_MAX_MT_SLOTS; i++) {
> -   if (mask & (1 << i))
> -   continue;
> -   input_mt_slot(input, i);
> -   input_mt_report_slot_state(input, MT_TOOL_FINGER, false);
> -   }
> +   input_mt_sync_frame(input);
>
> -   input_mt_report_pointer_emulation(input, true);
> if (cyapa->btn_capability & CAPABILITY_LEFT_BTN_MASK) {
> input_report_key(input, BTN_LEFT,
>  !!(data.finger_btn & OP_DATA_LEFT_BTN));
> @@ -610,6 +600,9 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)
> 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");
> @@ -625,47 +618,17 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)
>
> input_set_drvdata(input, cyapa);
>
> -   __set_bit(EV_ABS, input->evbit);
> -
> -   /*
> -* set and report not-MT axes to support synaptics X Driver.
> -* When multi-fingers on trackpad, only the first finger touch
> -* will be reported as X/Y axes values.
> -*/
> -   input_set_abs_params(input, ABS_X, 0, cyapa->max_abs_x, 0, 0);
> -   input_set_abs_params(input, ABS_Y, 0, cyapa->max_abs_y, 0, 0);
> -   input_set_abs_params(input, ABS_PRESSURE, 0, 255, 0, 0);
> -
> /* finger position */
> input_set_abs_params(input, ABS_MT_POSITION_X, 0, cyapa->max_abs_x, 0,
> 

Re: [PATCH v2 1/1] Input: add driver for Cypress APA I2C Trackpad

2012-12-07 Thread Benson Leung
Hi Henrik,

I have applied your patch, but I found I still need this line in my
driver, otherwise, there are no ABS type event supported. Should the
core set this bit as well since it's certainly going to be dealing
with ABS data?

__set_bit(EV_ABS, input-evbit);

Otherwise, it works great on my Chromebook trackpad here.

Thanks a bunch,
Benson

On Thu, Dec 6, 2012 at 6:59 AM, Henrik Rydberg rydb...@euromail.se wrote:
 Hi Benson,

 This patch introduces a driver for Cypress All Points Addressable
 I2C Trackpad, including the ones in 2012 Samsung Chromebooks.

 This device is compatible with MT protocol type B, providing identifiable
 contacts.

 Signed-off-by: Dudley Du d...@cypress.com
 Signed-off-by: Daniel Kurtz djku...@chromium.org
 Signed-off-by: Benson Leung ble...@chromium.org
 ---
  Version history :
 v2 : * Removed firmware update.
  * Removed sysfs properties related to firmware update and power mode.
  * Folded cyapa_detect into cyapa_probe.
  * Added support for middle and right mechanical buttons, if they exist.
  * Rearranged disable_irq/enable_irq in suspend and resume to prevent
  a power mode change from colliding with a read of tracking data.
  * Made cyapa_get_state more reliable.
  * Use IRQF_ONESHOT for threaded irq
  * Simplified cyapa_set_power_mode.
  * Removed extra kernel-doc style comments
  * Removed dev_dbg messages.
  * Cleaned up unused includes.
  * Cleaned up unused #defines
 v1 : Initial
 ---
  drivers/input/mouse/Kconfig  |   12 +
  drivers/input/mouse/Makefile |1 +
  drivers/input/mouse/cyapa.c  |  838 
 ++
  3 files changed, 851 insertions(+), 0 deletions(-)
  create mode 100644 drivers/input/mouse/cyapa.c

 Looking good overall. The patch does not compile in 3.7, and it is
 possible to further simplify the MT handling. The patch below takes
 care of those changes. If it still works for you with this applied, we
 should be fine.

 Thanks,
 Henrik

 diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
 index 08cf1ce..762fe9c 100644
 --- a/drivers/input/mouse/cyapa.c
 +++ b/drivers/input/mouse/cyapa.c
 @@ -545,7 +545,6 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
 int i;
 int ret;
 int num_fingers;
 -   unsigned int mask;

 if (device_may_wakeup(dev))
 pm_wakeup_event(dev, 0);
 @@ -560,14 +559,12 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
 goto irqhandled;
 }

 -   mask = 0;
 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;

 -   mask |= (1  slot);
 input_mt_slot(input, slot);
 input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
 input_report_abs(input, ABS_MT_POSITION_X,
 @@ -577,15 +574,8 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
 input_report_abs(input, ABS_MT_PRESSURE, touch-pressure);
 }

 -   /* Invalidate all unreported slots */
 -   for (i = 0; i  CYAPA_MAX_MT_SLOTS; i++) {
 -   if (mask  (1  i))
 -   continue;
 -   input_mt_slot(input, i);
 -   input_mt_report_slot_state(input, MT_TOOL_FINGER, false);
 -   }
 +   input_mt_sync_frame(input);

 -   input_mt_report_pointer_emulation(input, true);
 if (cyapa-btn_capability  CAPABILITY_LEFT_BTN_MASK) {
 input_report_key(input, BTN_LEFT,
  !!(data.finger_btn  OP_DATA_LEFT_BTN));
 @@ -610,6 +600,9 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)
 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);
 @@ -625,47 +618,17 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)

 input_set_drvdata(input, cyapa);

 -   __set_bit(EV_ABS, input-evbit);
 -
 -   /*
 -* set and report not-MT axes to support synaptics X Driver.
 -* When multi-fingers on trackpad, only the first finger touch
 -* will be reported as X/Y axes values.
 -*/
 -   input_set_abs_params(input, ABS_X, 0, cyapa-max_abs_x, 0, 0);
 -   input_set_abs_params(input, ABS_Y, 0, cyapa-max_abs_y, 0, 0);
 -   input_set_abs_params(input, ABS_PRESSURE, 0, 255, 0, 0);
 -
 /* 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, 

Re: [PATCH v2 1/1] Input: add driver for Cypress APA I2C Trackpad

2012-12-06 Thread Henrik Rydberg
Hi Benson,

> This patch introduces a driver for Cypress All Points Addressable
> I2C Trackpad, including the ones in 2012 Samsung Chromebooks.
> 
> This device is compatible with MT protocol type B, providing identifiable
> contacts.
> 
> Signed-off-by: Dudley Du 
> Signed-off-by: Daniel Kurtz 
> Signed-off-by: Benson Leung 
> ---
>  Version history :
> v2 : * Removed firmware update.
>  * Removed sysfs properties related to firmware update and power mode.
>  * Folded cyapa_detect into cyapa_probe.
>  * Added support for middle and right mechanical buttons, if they exist.
>  * Rearranged disable_irq/enable_irq in suspend and resume to prevent
>  a power mode change from colliding with a read of tracking data.
>  * Made cyapa_get_state more reliable.
>  * Use IRQF_ONESHOT for threaded irq
>  * Simplified cyapa_set_power_mode.
>  * Removed extra kernel-doc style comments
>  * Removed dev_dbg messages.
>  * Cleaned up unused includes.
>  * Cleaned up unused #defines
> v1 : Initial
> ---
>  drivers/input/mouse/Kconfig  |   12 +
>  drivers/input/mouse/Makefile |1 +
>  drivers/input/mouse/cyapa.c  |  838 
> ++
>  3 files changed, 851 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/input/mouse/cyapa.c

Looking good overall. The patch does not compile in 3.7, and it is
possible to further simplify the MT handling. The patch below takes
care of those changes. If it still works for you with this applied, we
should be fine.

Thanks,
Henrik

diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index 08cf1ce..762fe9c 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -545,7 +545,6 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
int i;
int ret;
int num_fingers;
-   unsigned int mask;
 
if (device_may_wakeup(dev))
pm_wakeup_event(dev, 0);
@@ -560,14 +559,12 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
goto irqhandled;
}
 
-   mask = 0;
num_fingers = (data.finger_btn >> 4) & 0x0f;
for (i = 0; i < num_fingers; i++) {
const struct cyapa_touch *touch = [i];
/* Note: touch->id range is 1 to 15; slots are 0 to 14. */
int slot = touch->id - 1;
 
-   mask |= (1 << slot);
input_mt_slot(input, slot);
input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
input_report_abs(input, ABS_MT_POSITION_X,
@@ -577,15 +574,8 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
input_report_abs(input, ABS_MT_PRESSURE, touch->pressure);
}
 
-   /* Invalidate all unreported slots */
-   for (i = 0; i < CYAPA_MAX_MT_SLOTS; i++) {
-   if (mask & (1 << i))
-   continue;
-   input_mt_slot(input, i);
-   input_mt_report_slot_state(input, MT_TOOL_FINGER, false);
-   }
+   input_mt_sync_frame(input);
 
-   input_mt_report_pointer_emulation(input, true);
if (cyapa->btn_capability & CAPABILITY_LEFT_BTN_MASK) {
input_report_key(input, BTN_LEFT,
 !!(data.finger_btn & OP_DATA_LEFT_BTN));
@@ -610,6 +600,9 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)
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");
@@ -625,47 +618,17 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)
 
input_set_drvdata(input, cyapa);
 
-   __set_bit(EV_ABS, input->evbit);
-
-   /*
-* set and report not-MT axes to support synaptics X Driver.
-* When multi-fingers on trackpad, only the first finger touch
-* will be reported as X/Y axes values.
-*/
-   input_set_abs_params(input, ABS_X, 0, cyapa->max_abs_x, 0, 0);
-   input_set_abs_params(input, ABS_Y, 0, cyapa->max_abs_y, 0, 0);
-   input_set_abs_params(input, ABS_PRESSURE, 0, 255, 0, 0);
-
/* 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);
-   ret = input_mt_init_slots(input, CYAPA_MAX_MT_SLOTS);
-   if (ret < 0) {
-   dev_err(dev, "allocate memory for MT slots failed, %d\n", ret);
-   goto err_free_device;
-   }
-
-   if (cyapa->physical_size_x && cyapa->physical_size_y) {
-   input_abs_set_res(input, ABS_X,
-   cyapa->max_abs_x / 

Re: [PATCH v2 1/1] Input: add driver for Cypress APA I2C Trackpad

2012-12-06 Thread Jean Delvare
On Wed, 5 Dec 2012 23:48:17 -0800, Dmitry Torokhov wrote:
> Hi Benson,
> 
> On Wed, Dec 05, 2012 at 04:48:19PM -0800, Benson Leung wrote:
> > This patch introduces a driver for Cypress All Points Addressable
> > I2C Trackpad, including the ones in 2012 Samsung Chromebooks.
> > 
> > This device is compatible with MT protocol type B, providing identifiable
> > contacts.
> > 
> > Signed-off-by: Dudley Du 
> > Signed-off-by: Daniel Kurtz 
> > Signed-off-by: Benson Leung 
> > ---
> >  Version history :
> > v2 : * Removed firmware update.
> >  * Removed sysfs properties related to firmware update and power mode.
> >  * Folded cyapa_detect into cyapa_probe.
> >  * Added support for middle and right mechanical buttons, if they exist.
> >  * Rearranged disable_irq/enable_irq in suspend and resume to prevent
> >  a power mode change from colliding with a read of tracking data.
> >  * Made cyapa_get_state more reliable.
> >  * Use IRQF_ONESHOT for threaded irq
> >  * Simplified cyapa_set_power_mode.
> >  * Removed extra kernel-doc style comments
> >  * Removed dev_dbg messages.
> >  * Cleaned up unused includes.
> >  * Cleaned up unused #defines
> > v1 : Initial
> 
> First of all - this version is excellent compared to the previous ones
> posted. I have just a few quesutions (and of course I'd like Henrik to
> look over MT handlingi and Jean for I2C bits).

I did not find any problem with the I2C bits.

> > (...)
> > +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);
> 
> Does it have to be SMBUS? If it does you need to check the capabilities
> in probe(). 

Using SMBus calls is recommended as it increases portability of the
driver. I2C controllers can do SMBus but SMBus controllers can't do
I2C. Checking the capabilities is needed in both cases anyway, as you
can't assume anything from an i2c_adapter.

-- 
Jean Delvare
--
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 v2 1/1] Input: add driver for Cypress APA I2C Trackpad

2012-12-06 Thread Jean Delvare
On Wed, 5 Dec 2012 23:48:17 -0800, Dmitry Torokhov wrote:
 Hi Benson,
 
 On Wed, Dec 05, 2012 at 04:48:19PM -0800, Benson Leung wrote:
  This patch introduces a driver for Cypress All Points Addressable
  I2C Trackpad, including the ones in 2012 Samsung Chromebooks.
  
  This device is compatible with MT protocol type B, providing identifiable
  contacts.
  
  Signed-off-by: Dudley Du d...@cypress.com
  Signed-off-by: Daniel Kurtz djku...@chromium.org
  Signed-off-by: Benson Leung ble...@chromium.org
  ---
   Version history :
  v2 : * Removed firmware update.
   * Removed sysfs properties related to firmware update and power mode.
   * Folded cyapa_detect into cyapa_probe.
   * Added support for middle and right mechanical buttons, if they exist.
   * Rearranged disable_irq/enable_irq in suspend and resume to prevent
   a power mode change from colliding with a read of tracking data.
   * Made cyapa_get_state more reliable.
   * Use IRQF_ONESHOT for threaded irq
   * Simplified cyapa_set_power_mode.
   * Removed extra kernel-doc style comments
   * Removed dev_dbg messages.
   * Cleaned up unused includes.
   * Cleaned up unused #defines
  v1 : Initial
 
 First of all - this version is excellent compared to the previous ones
 posted. I have just a few quesutions (and of course I'd like Henrik to
 look over MT handlingi and Jean for I2C bits).

I did not find any problem with the I2C bits.

  (...)
  +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);
 
 Does it have to be SMBUS? If it does you need to check the capabilities
 in probe(). 

Using SMBus calls is recommended as it increases portability of the
driver. I2C controllers can do SMBus but SMBus controllers can't do
I2C. Checking the capabilities is needed in both cases anyway, as you
can't assume anything from an i2c_adapter.

-- 
Jean Delvare
--
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 v2 1/1] Input: add driver for Cypress APA I2C Trackpad

2012-12-06 Thread Henrik Rydberg
Hi Benson,

 This patch introduces a driver for Cypress All Points Addressable
 I2C Trackpad, including the ones in 2012 Samsung Chromebooks.
 
 This device is compatible with MT protocol type B, providing identifiable
 contacts.
 
 Signed-off-by: Dudley Du d...@cypress.com
 Signed-off-by: Daniel Kurtz djku...@chromium.org
 Signed-off-by: Benson Leung ble...@chromium.org
 ---
  Version history :
 v2 : * Removed firmware update.
  * Removed sysfs properties related to firmware update and power mode.
  * Folded cyapa_detect into cyapa_probe.
  * Added support for middle and right mechanical buttons, if they exist.
  * Rearranged disable_irq/enable_irq in suspend and resume to prevent
  a power mode change from colliding with a read of tracking data.
  * Made cyapa_get_state more reliable.
  * Use IRQF_ONESHOT for threaded irq
  * Simplified cyapa_set_power_mode.
  * Removed extra kernel-doc style comments
  * Removed dev_dbg messages.
  * Cleaned up unused includes.
  * Cleaned up unused #defines
 v1 : Initial
 ---
  drivers/input/mouse/Kconfig  |   12 +
  drivers/input/mouse/Makefile |1 +
  drivers/input/mouse/cyapa.c  |  838 
 ++
  3 files changed, 851 insertions(+), 0 deletions(-)
  create mode 100644 drivers/input/mouse/cyapa.c

Looking good overall. The patch does not compile in 3.7, and it is
possible to further simplify the MT handling. The patch below takes
care of those changes. If it still works for you with this applied, we
should be fine.

Thanks,
Henrik

diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index 08cf1ce..762fe9c 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -545,7 +545,6 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
int i;
int ret;
int num_fingers;
-   unsigned int mask;
 
if (device_may_wakeup(dev))
pm_wakeup_event(dev, 0);
@@ -560,14 +559,12 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
goto irqhandled;
}
 
-   mask = 0;
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;
 
-   mask |= (1  slot);
input_mt_slot(input, slot);
input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
input_report_abs(input, ABS_MT_POSITION_X,
@@ -577,15 +574,8 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
input_report_abs(input, ABS_MT_PRESSURE, touch-pressure);
}
 
-   /* Invalidate all unreported slots */
-   for (i = 0; i  CYAPA_MAX_MT_SLOTS; i++) {
-   if (mask  (1  i))
-   continue;
-   input_mt_slot(input, i);
-   input_mt_report_slot_state(input, MT_TOOL_FINGER, false);
-   }
+   input_mt_sync_frame(input);
 
-   input_mt_report_pointer_emulation(input, true);
if (cyapa-btn_capability  CAPABILITY_LEFT_BTN_MASK) {
input_report_key(input, BTN_LEFT,
 !!(data.finger_btn  OP_DATA_LEFT_BTN));
@@ -610,6 +600,9 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)
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);
@@ -625,47 +618,17 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)
 
input_set_drvdata(input, cyapa);
 
-   __set_bit(EV_ABS, input-evbit);
-
-   /*
-* set and report not-MT axes to support synaptics X Driver.
-* When multi-fingers on trackpad, only the first finger touch
-* will be reported as X/Y axes values.
-*/
-   input_set_abs_params(input, ABS_X, 0, cyapa-max_abs_x, 0, 0);
-   input_set_abs_params(input, ABS_Y, 0, cyapa-max_abs_y, 0, 0);
-   input_set_abs_params(input, ABS_PRESSURE, 0, 255, 0, 0);
-
/* 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);
-   ret = input_mt_init_slots(input, CYAPA_MAX_MT_SLOTS);
-   if (ret  0) {
-   dev_err(dev, allocate memory for MT slots failed, %d\n, ret);
-   goto err_free_device;
-   }
-
-   if (cyapa-physical_size_x  cyapa-physical_size_y) {
-   input_abs_set_res(input, ABS_X,
-   cyapa-max_abs_x / 

Re: [PATCH v2 1/1] Input: add driver for Cypress APA I2C Trackpad

2012-12-05 Thread Dmitry Torokhov
Hi Benson,

On Wed, Dec 05, 2012 at 04:48:19PM -0800, Benson Leung wrote:
> This patch introduces a driver for Cypress All Points Addressable
> I2C Trackpad, including the ones in 2012 Samsung Chromebooks.
> 
> This device is compatible with MT protocol type B, providing identifiable
> contacts.
> 
> Signed-off-by: Dudley Du 
> Signed-off-by: Daniel Kurtz 
> Signed-off-by: Benson Leung 
> ---
>  Version history :
> v2 : * Removed firmware update.
>  * Removed sysfs properties related to firmware update and power mode.
>  * Folded cyapa_detect into cyapa_probe.
>  * Added support for middle and right mechanical buttons, if they exist.
>  * Rearranged disable_irq/enable_irq in suspend and resume to prevent
>  a power mode change from colliding with a read of tracking data.
>  * Made cyapa_get_state more reliable.
>  * Use IRQF_ONESHOT for threaded irq
>  * Simplified cyapa_set_power_mode.
>  * Removed extra kernel-doc style comments
>  * Removed dev_dbg messages.
>  * Cleaned up unused includes.
>  * Cleaned up unused #defines
> v1 : Initial

First of all - this version is excellent compared to the previous ones
posted. I have just a few quesutions (and of course I'd like Henrik to
look over MT handlingi and Jean for I2C bits).

> ---
>  drivers/input/mouse/Kconfig  |   12 +
>  drivers/input/mouse/Makefile |1 +
>  drivers/input/mouse/cyapa.c  |  838 
> ++
>  3 files changed, 851 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/input/mouse/cyapa.c
> 
> diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
> index cd6268c..23db30a 100644
> --- a/drivers/input/mouse/Kconfig
> +++ b/drivers/input/mouse/Kconfig
> @@ -193,6 +193,18 @@ config MOUSE_BCM5974
> To compile this driver as a module, choose M here: the
> module will be called bcm5974.
>  
> +config MOUSE_CYAPA
> + tristate "Cypress APA I2C Trackpad support"
> + depends on I2C
> + help
> +   This driver adds support for Cypress All Points Addressable (APA)
> +   I2C Trackpads, including the ones used in 2012 Samsung Chromebooks.
> +
> +   Say Y here if you have a Cypress APA I2C Trackpad.
> +
> +   To compile this driver as a module, choose M here: the module will be
> +   called cyapa.
> +
>  config MOUSE_INPORT
>   tristate "InPort/MS/ATIXL busmouse"
>   depends on ISA
> diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
> index 46ba755..10b4773 100644
> --- a/drivers/input/mouse/Makefile
> +++ b/drivers/input/mouse/Makefile
> @@ -8,6 +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_GPIO) += gpio_mouse.o
>  obj-$(CONFIG_MOUSE_INPORT)   += inport.o
>  obj-$(CONFIG_MOUSE_LOGIBM)   += logibm.o
> diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
> new file mode 100644
> index 000..08cf1ce
> --- /dev/null
> +++ b/drivers/input/mouse/cyapa.c
> @@ -0,0 +1,838 @@
> +/*
> + * Cypress APA trackpad with I2C interface
> + *
> + * Author: Dudley Du 
> + * Further cleanup and restructuring by:
> + *   Daniel Kurtz 
> + *   Benson Leung 
> + *
> + * Copyright (C) 2011-2012 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 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/* APA trackpad firmware generation */
> +#define CYAPA_GEN3   0x03   /* support MT-protocol B with tracking ID. */
> +
> +#define CYAPA_NAME   "Cypress APA Trackpad (cyapa)"
> +
> +/* commands for read/write registers of Cypress trackpad */
> +#define CYAPA_CMD_SOFT_RESET   0x00
> +#define CYAPA_CMD_POWER_MODE   0x01
> +#define CYAPA_CMD_DEV_STATUS   0x02
> +#define CYAPA_CMD_GROUP_DATA   0x03
> +#define CYAPA_CMD_GROUP_CMD0x04
> +#define CYAPA_CMD_GROUP_QUERY  0x05
> +#define CYAPA_CMD_BL_STATUS0x06
> +#define CYAPA_CMD_BL_HEAD  0x07
> +#define CYAPA_CMD_BL_CMD   0x08
> +#define CYAPA_CMD_BL_DATA  0x09
> +#define CYAPA_CMD_BL_ALL   0x0a
> +#define CYAPA_CMD_BLK_PRODUCT_ID   0x0b
> +#define CYAPA_CMD_BLK_HEAD 0x0c
> +
> +/* report data start reg offset address. */
> +#define DATA_REG_START_OFFSET  0x
> +
> +#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 

Re: [PATCH v2 1/1] Input: add driver for Cypress APA I2C Trackpad

2012-12-05 Thread Dmitry Torokhov
Hi Benson,

On Wed, Dec 05, 2012 at 04:48:19PM -0800, Benson Leung wrote:
 This patch introduces a driver for Cypress All Points Addressable
 I2C Trackpad, including the ones in 2012 Samsung Chromebooks.
 
 This device is compatible with MT protocol type B, providing identifiable
 contacts.
 
 Signed-off-by: Dudley Du d...@cypress.com
 Signed-off-by: Daniel Kurtz djku...@chromium.org
 Signed-off-by: Benson Leung ble...@chromium.org
 ---
  Version history :
 v2 : * Removed firmware update.
  * Removed sysfs properties related to firmware update and power mode.
  * Folded cyapa_detect into cyapa_probe.
  * Added support for middle and right mechanical buttons, if they exist.
  * Rearranged disable_irq/enable_irq in suspend and resume to prevent
  a power mode change from colliding with a read of tracking data.
  * Made cyapa_get_state more reliable.
  * Use IRQF_ONESHOT for threaded irq
  * Simplified cyapa_set_power_mode.
  * Removed extra kernel-doc style comments
  * Removed dev_dbg messages.
  * Cleaned up unused includes.
  * Cleaned up unused #defines
 v1 : Initial

First of all - this version is excellent compared to the previous ones
posted. I have just a few quesutions (and of course I'd like Henrik to
look over MT handlingi and Jean for I2C bits).

 ---
  drivers/input/mouse/Kconfig  |   12 +
  drivers/input/mouse/Makefile |1 +
  drivers/input/mouse/cyapa.c  |  838 
 ++
  3 files changed, 851 insertions(+), 0 deletions(-)
  create mode 100644 drivers/input/mouse/cyapa.c
 
 diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
 index cd6268c..23db30a 100644
 --- a/drivers/input/mouse/Kconfig
 +++ b/drivers/input/mouse/Kconfig
 @@ -193,6 +193,18 @@ config MOUSE_BCM5974
 To compile this driver as a module, choose M here: the
 module will be called bcm5974.
  
 +config MOUSE_CYAPA
 + tristate Cypress APA I2C Trackpad support
 + depends on I2C
 + help
 +   This driver adds support for Cypress All Points Addressable (APA)
 +   I2C Trackpads, including the ones used in 2012 Samsung Chromebooks.
 +
 +   Say Y here if you have a Cypress APA I2C Trackpad.
 +
 +   To compile this driver as a module, choose M here: the module will be
 +   called cyapa.
 +
  config MOUSE_INPORT
   tristate InPort/MS/ATIXL busmouse
   depends on ISA
 diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
 index 46ba755..10b4773 100644
 --- a/drivers/input/mouse/Makefile
 +++ b/drivers/input/mouse/Makefile
 @@ -8,6 +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_GPIO) += gpio_mouse.o
  obj-$(CONFIG_MOUSE_INPORT)   += inport.o
  obj-$(CONFIG_MOUSE_LOGIBM)   += logibm.o
 diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
 new file mode 100644
 index 000..08cf1ce
 --- /dev/null
 +++ b/drivers/input/mouse/cyapa.c
 @@ -0,0 +1,838 @@
 +/*
 + * Cypress APA trackpad with I2C interface
 + *
 + * Author: Dudley Du d...@cypress.com
 + * Further cleanup and restructuring by:
 + *   Daniel Kurtz djku...@chromium.org
 + *   Benson Leung ble...@chromium.org
 + *
 + * Copyright (C) 2011-2012 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/interrupt.h
 +#include linux/module.h
 +#include linux/slab.h
 +
 +/* APA trackpad firmware generation */
 +#define CYAPA_GEN3   0x03   /* support MT-protocol B with tracking ID. */
 +
 +#define CYAPA_NAME   Cypress APA Trackpad (cyapa)
 +
 +/* commands for read/write registers of Cypress trackpad */
 +#define CYAPA_CMD_SOFT_RESET   0x00
 +#define CYAPA_CMD_POWER_MODE   0x01
 +#define CYAPA_CMD_DEV_STATUS   0x02
 +#define CYAPA_CMD_GROUP_DATA   0x03
 +#define CYAPA_CMD_GROUP_CMD0x04
 +#define CYAPA_CMD_GROUP_QUERY  0x05
 +#define CYAPA_CMD_BL_STATUS0x06
 +#define CYAPA_CMD_BL_HEAD  0x07
 +#define CYAPA_CMD_BL_CMD   0x08
 +#define CYAPA_CMD_BL_DATA  0x09
 +#define CYAPA_CMD_BL_ALL   0x0a
 +#define CYAPA_CMD_BLK_PRODUCT_ID   0x0b
 +#define CYAPA_CMD_BLK_HEAD 0x0c
 +
 +/* report data start reg offset address. */
 +#define DATA_REG_START_OFFSET  0x
 +
 +#define BL_HEAD_OFFSET 0x00
 +#define BL_DATA_OFFSET 0x10
 +
 +/*
 + * Operational Device Status Register
 + *
 + * bit 7: Valid interrupt source
 + * bit 6 - 4: Reserved
 + *